Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/effects/scripted_effects_test.cpp
Show All 28 Lines | |||||
29 | #include "effects.h" | 29 | #include "effects.h" | ||
30 | #include "kwin_wayland_test.h" | 30 | #include "kwin_wayland_test.h" | ||
31 | #include "platform.h" | 31 | #include "platform.h" | ||
32 | #include "shell_client.h" | 32 | #include "shell_client.h" | ||
33 | #include "virtualdesktops.h" | 33 | #include "virtualdesktops.h" | ||
34 | #include "wayland_server.h" | 34 | #include "wayland_server.h" | ||
35 | #include "workspace.h" | 35 | #include "workspace.h" | ||
36 | 36 | | |||
37 | #include <QScriptContext> | 37 | #include <QJSValue> | ||
38 | #include <QScriptEngine> | 38 | #include <QQmlEngine> | ||
39 | #include <QScriptValue> | | |||
40 | 39 | | |||
41 | #include <KConfigGroup> | 40 | #include <KConfigGroup> | ||
42 | #include <KGlobalAccel> | 41 | #include <KGlobalAccel> | ||
43 | 42 | | |||
44 | #include <KWayland/Client/compositor.h> | 43 | #include <KWayland/Client/compositor.h> | ||
45 | #include <KWayland/Client/connection_thread.h> | 44 | #include <KWayland/Client/connection_thread.h> | ||
46 | #include <KWayland/Client/registry.h> | 45 | #include <KWayland/Client/registry.h> | ||
47 | #include <KWayland/Client/slide.h> | 46 | #include <KWayland/Client/slide.h> | ||
Show All 21 Lines | |||||
69 | private: | 68 | private: | ||
70 | ScriptedEffect *loadEffect(const QString &name); | 69 | ScriptedEffect *loadEffect(const QString &name); | ||
71 | }; | 70 | }; | ||
72 | 71 | | |||
73 | class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect | 72 | class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect | ||
74 | { | 73 | { | ||
75 | Q_OBJECT | 74 | Q_OBJECT | ||
76 | public: | 75 | public: | ||
77 | ScriptedEffectWithDebugSpy(); | | |||
78 | bool load(const QString &name); | 76 | bool load(const QString &name); | ||
79 | using AnimationEffect::state; | 77 | using AnimationEffect::state; | ||
78 | Q_INVOKABLE void sendTestResponse(const QString &out); //proxies triggers out from the tests | ||||
79 | QList<QAction*> actions(); //returns any QActions owned by the ScriptEngine | ||||
80 | signals: | 80 | signals: | ||
81 | void testOutput(const QString &data); | 81 | void testOutput(const QString &data); | ||
82 | }; | 82 | }; | ||
83 | 83 | | |||
84 | QScriptValue kwinEffectScriptTestOut(QScriptContext *context, QScriptEngine *engine) | 84 | void ScriptedEffectWithDebugSpy::sendTestResponse(const QString &out) | ||
85 | { | 85 | { | ||
86 | auto *script = qobject_cast<ScriptedEffectWithDebugSpy*>(context->callee().data().toQObject()); | 86 | emit testOutput(out); | ||
87 | QString result; | | |||
88 | for (int i = 0; i < context->argumentCount(); ++i) { | | |||
89 | if (i > 0) { | | |||
90 | result.append(QLatin1Char(' ')); | | |||
91 | } | | |||
92 | result.append(context->argument(i).toString()); | | |||
93 | } | | |||
94 | emit script->testOutput(result); | | |||
95 | | ||||
96 | return engine->undefinedValue(); | | |||
97 | } | 87 | } | ||
98 | 88 | | |||
99 | ScriptedEffectWithDebugSpy::ScriptedEffectWithDebugSpy() | 89 | QList<QAction*> ScriptedEffectWithDebugSpy::actions() | ||
100 | : ScriptedEffect() | | |||
101 | { | 90 | { | ||
102 | QScriptValue testHookFunc = engine()->newFunction(kwinEffectScriptTestOut); | 91 | return findChildren<QAction*>(QString(), Qt::FindDirectChildrenOnly); | ||
103 | testHookFunc.setData(engine()->newQObject(this)); | | |||
104 | engine()->globalObject().setProperty(QStringLiteral("sendTestResponse"), testHookFunc); | | |||
105 | } | 92 | } | ||
106 | 93 | | |||
107 | bool ScriptedEffectWithDebugSpy::load(const QString &name) | 94 | bool ScriptedEffectWithDebugSpy::load(const QString &name) | ||
108 | { | 95 | { | ||
96 | auto selfContext = engine()->newQObject(this); | ||||
97 | QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); | ||||
109 | const QString path = QFINDTESTDATA("./scripts/" + name + ".js"); | 98 | const QString path = QFINDTESTDATA("./scripts/" + name + ".js"); | ||
99 | engine()->globalObject().setProperty("sendTestResponse", selfContext.property("sendTestResponse")); | ||||
110 | if (!init(name, path)) { | 100 | if (!init(name, path)) { | ||
111 | return false; | 101 | return false; | ||
112 | } | 102 | } | ||
113 | 103 | | |||
114 | // inject our newly created effect to be registered with the EffectsHandlerImpl::loaded_effects | 104 | // inject our newly created effect to be registered with the EffectsHandlerImpl::loaded_effects | ||
115 | // this is private API so some horrible code is used to find the internal effectloader | 105 | // this is private API so some horrible code is used to find the internal effectloader | ||
116 | // and register ourselves | 106 | // and register ourselves | ||
117 | auto c = effects->children(); | 107 | auto c = effects->children(); | ||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | |||||
230 | } | 220 | } | ||
231 | 221 | | |||
232 | void ScriptedEffectsTest::testShortcuts() | 222 | void ScriptedEffectsTest::testShortcuts() | ||
233 | { | 223 | { | ||
234 | // this tests method registerShortcut | 224 | // this tests method registerShortcut | ||
235 | auto *effect = new ScriptedEffectWithDebugSpy; // cleaned up in ::clean | 225 | auto *effect = new ScriptedEffectWithDebugSpy; // cleaned up in ::clean | ||
236 | QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput); | 226 | QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput); | ||
237 | QVERIFY(effect->load("shortcutsTest")); | 227 | QVERIFY(effect->load("shortcutsTest")); | ||
238 | QCOMPARE(effect->shortcutCallbacks().count(), 1); | 228 | QCOMPARE(effect->actions().count(), 1); | ||
239 | QAction *action = effect->shortcutCallbacks().keys()[0]; | 229 | auto action = effect->actions()[0]; | ||
240 | QCOMPARE(action->objectName(), "testShortcut"); | 230 | QCOMPARE(action->objectName(), "testShortcut"); | ||
241 | QCOMPARE(action->text(), "Test Shortcut"); | 231 | QCOMPARE(action->text(), "Test Shortcut"); | ||
242 | QCOMPARE(KGlobalAccel::self()->shortcut(action).first(), QKeySequence("Meta+Shift+Y")); | 232 | QCOMPARE(KGlobalAccel::self()->shortcut(action).first(), QKeySequence("Meta+Shift+Y")); | ||
243 | action->trigger(); | 233 | action->trigger(); | ||
244 | QCOMPARE(effectOutputSpy[0].first(), "shortcutTriggered"); | 234 | QCOMPARE(effectOutputSpy[0].first(), "shortcutTriggered"); | ||
245 | } | 235 | } | ||
246 | 236 | | |||
247 | void ScriptedEffectsTest::testAnimations_data() | 237 | void ScriptedEffectsTest::testAnimations_data() | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | |||||
339 | } | 329 | } | ||
340 | 330 | | |||
341 | void ScriptedEffectsTest::testScreenEdgeTouch() | 331 | void ScriptedEffectsTest::testScreenEdgeTouch() | ||
342 | { | 332 | { | ||
343 | // this test checks registerTouchScreenEdge functions | 333 | // this test checks registerTouchScreenEdge functions | ||
344 | auto *effect = new ScriptedEffectWithDebugSpy; // cleaned up in ::clean | 334 | auto *effect = new ScriptedEffectWithDebugSpy; // cleaned up in ::clean | ||
345 | QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput); | 335 | QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput); | ||
346 | QVERIFY(effect->load("screenEdgeTouchTest")); | 336 | QVERIFY(effect->load("screenEdgeTouchTest")); | ||
347 | auto actions = effect->findChildren<QAction*>(QString(), Qt::FindDirectChildrenOnly); | 337 | effect->actions()[0]->trigger(); | ||
348 | actions[0]->trigger(); | | |||
349 | QCOMPARE(effectOutputSpy.count(), 1); | 338 | QCOMPARE(effectOutputSpy.count(), 1); | ||
350 | } | 339 | } | ||
351 | 340 | | |||
352 | WAYLANDTEST_MAIN(ScriptedEffectsTest) | 341 | WAYLANDTEST_MAIN(ScriptedEffectsTest) | ||
353 | #include "scripted_effects_test.moc" | 342 | #include "scripted_effects_test.moc" |