Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/scripting/cursor_test.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #include "kwin_wayland_test.h" | ||||
21 | #include "cursor.h" | ||||
22 | #include "effectloader.h" | ||||
23 | #include "platform.h" | ||||
24 | #include "wayland_server.h" | ||||
25 | #include "workspace.h" | ||||
26 | #include "scripting/scripting.h" | ||||
27 | #include "effect_builtins.h" | ||||
28 | #include "workspace.h" | ||||
29 | | ||||
30 | #include <KConfigGroup> | ||||
31 | | ||||
32 | using namespace KWin; | ||||
33 | | ||||
34 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_scripting_cursor-0"); | ||||
35 | | ||||
36 | class CursorTest : public QObject | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | private Q_SLOTS: | ||||
40 | void initTestCase(); | ||||
41 | void init(); | ||||
42 | | ||||
43 | void testCursor(); | ||||
44 | }; | ||||
45 | | ||||
46 | void CursorTest::initTestCase() | ||||
47 | { | ||||
48 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||||
49 | QVERIFY(workspaceCreatedSpy.isValid()); | ||||
50 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||||
51 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||||
52 | | ||||
53 | // empty config to have defaults | ||||
54 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | ||||
55 | | ||||
56 | // disable all effects to prevent them grabbing edges | ||||
57 | KConfigGroup plugins(config, QStringLiteral("Plugins")); | ||||
58 | ScriptedEffectLoader loader; | ||||
59 | const auto builtinNames = BuiltInEffects::availableEffectNames() << loader.listOfKnownEffects(); | ||||
60 | for (QString name : builtinNames) { | ||||
61 | plugins.writeEntry(name + QStringLiteral("Enabled"), false); | ||||
62 | } | ||||
63 | | ||||
64 | config->sync(); | ||||
65 | kwinApp()->setConfig(config); | ||||
66 | | ||||
67 | kwinApp()->start(); | ||||
68 | QVERIFY(workspaceCreatedSpy.wait()); | ||||
69 | QVERIFY(Scripting::self()); | ||||
70 | } | ||||
71 | | ||||
72 | void CursorTest::init() | ||||
73 | { | ||||
74 | KWin::Cursor::setPos(10, 10); | ||||
75 | if (workspace()->showingDesktop()) { | ||||
76 | workspace()->slotToggleShowDesktop(); | ||||
77 | } | ||||
78 | QVERIFY(!workspace()->showingDesktop()); | ||||
79 | } | ||||
80 | | ||||
81 | | ||||
82 | void CursorTest::testCursor() | ||||
83 | { | ||||
84 | const QString scriptToLoad = QFINDTESTDATA("./scripts/cursortest.qml"); | ||||
85 | QVERIFY(!scriptToLoad.isEmpty()); | ||||
86 | QVERIFY(Scripting::self()->loadDeclarativeScript(scriptToLoad) != -1); | ||||
87 | QVERIFY(Scripting::self()->isScriptLoaded(scriptToLoad)); | ||||
88 | | ||||
89 | auto s = Scripting::self()->findScript(scriptToLoad); | ||||
90 | QSignalSpy runningChangedSpy(s, &AbstractScript::runningChanged); | ||||
91 | s->run(); | ||||
92 | QTRY_COMPARE(runningChangedSpy.count(), 1); | ||||
93 | | ||||
94 | QSignalSpy showDesktopSpy(workspace(), &Workspace::showingDesktopChanged); | ||||
95 | QVERIFY(showDesktopSpy.isValid()); | ||||
96 | | ||||
97 | //moving the cursor should work, but we don't do anything here | ||||
98 | KWin::Cursor::setPos(400, 200); | ||||
99 | QVERIFY(!workspace()->showingDesktop()); | ||||
100 | | ||||
101 | //move mouse to the "magic location" that will make the script toggle desktop | ||||
102 | KWin::Cursor::setPos(500, 400); | ||||
103 | QVERIFY(workspace()->showingDesktop()); | ||||
104 | | ||||
105 | //cleanup | ||||
106 | workspace()->slotToggleShowDesktop(); | ||||
107 | } | ||||
108 | | ||||
109 | WAYLANDTEST_MAIN(CursorTest) | ||||
110 | #include "cursor_test.moc" |