Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/effects/scripted_effects_test.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 59 | private Q_SLOTS: | |||
---|---|---|---|---|---|
73 | void testKeepAlive_data(); | 73 | void testKeepAlive_data(); | ||
74 | void testKeepAlive(); | 74 | void testKeepAlive(); | ||
75 | void testGrab(); | 75 | void testGrab(); | ||
76 | void testGrabAlreadyGrabbedWindow(); | 76 | void testGrabAlreadyGrabbedWindow(); | ||
77 | void testGrabAlreadyGrabbedWindowForced(); | 77 | void testGrabAlreadyGrabbedWindowForced(); | ||
78 | void testUngrab(); | 78 | void testUngrab(); | ||
79 | void testRedirect_data(); | 79 | void testRedirect_data(); | ||
80 | void testRedirect(); | 80 | void testRedirect(); | ||
81 | void testComplete(); | ||||
81 | 82 | | |||
82 | private: | 83 | private: | ||
83 | ScriptedEffect *loadEffect(const QString &name); | 84 | ScriptedEffect *loadEffect(const QString &name); | ||
84 | }; | 85 | }; | ||
85 | 86 | | |||
86 | class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect | 87 | class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect | ||
87 | { | 88 | { | ||
88 | Q_OBJECT | 89 | Q_OBJECT | ||
▲ Show 20 Lines • Show All 616 Lines • ▼ Show 20 Line(s) | 702 | } else { | |||
705 | const QList<AniData> animations = state.first().first; | 706 | const QList<AniData> animations = state.first().first; | ||
706 | QCOMPARE(animations.count(), 1); | 707 | QCOMPARE(animations.count(), 1); | ||
707 | QCOMPARE(animations[0].timeLine.direction(), TimeLine::Backward); | 708 | QCOMPARE(animations[0].timeLine.direction(), TimeLine::Backward); | ||
708 | QCOMPARE(animations[0].timeLine.elapsed(), 1000ms); | 709 | QCOMPARE(animations[0].timeLine.elapsed(), 1000ms); | ||
709 | QCOMPARE(animations[0].timeLine.value(), 0.0); | 710 | QCOMPARE(animations[0].timeLine.value(), 0.0); | ||
710 | } | 711 | } | ||
711 | } | 712 | } | ||
712 | 713 | | |||
714 | void ScriptedEffectsTest::testComplete() | ||||
715 | { | ||||
716 | // this verifies that complete works | ||||
717 | | ||||
718 | // load the test effect | ||||
719 | auto effect = new ScriptedEffectWithDebugSpy; | ||||
720 | QVERIFY(effect->load(QStringLiteral("completeTest"))); | ||||
721 | | ||||
722 | // create test client | ||||
723 | using namespace KWayland::Client; | ||||
724 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||||
725 | QVERIFY(surface); | ||||
726 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||||
727 | QVERIFY(shellSurface); | ||||
728 | ShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||||
729 | QVERIFY(c); | ||||
730 | QCOMPARE(workspace()->activeClient(), c); | ||||
731 | | ||||
732 | auto around = [] (std::chrono::milliseconds elapsed, | ||||
733 | std::chrono::milliseconds pivot, | ||||
734 | std::chrono::milliseconds margin) { | ||||
735 | return qAbs(elapsed.count() - pivot.count()) < margin.count(); | ||||
736 | }; | ||||
737 | | ||||
738 | // initially, the test animation should be at the start position | ||||
739 | { | ||||
740 | const AnimationEffect::AniMap state = effect->state(); | ||||
741 | QCOMPARE(state.count(), 1); | ||||
742 | QCOMPARE(state.firstKey(), c->effectWindow()); | ||||
743 | const QList<AniData> animations = state.first().first; | ||||
744 | QCOMPARE(animations.count(), 1); | ||||
745 | QVERIFY(around(animations[0].timeLine.elapsed(), 0ms, 50ms)); | ||||
746 | QVERIFY(!animations[0].timeLine.done()); | ||||
747 | } | ||||
748 | | ||||
749 | // wait for 250ms | ||||
750 | QTest::qWait(250); | ||||
751 | | ||||
752 | { | ||||
753 | const AnimationEffect::AniMap state = effect->state(); | ||||
754 | QCOMPARE(state.count(), 1); | ||||
755 | QCOMPARE(state.firstKey(), c->effectWindow()); | ||||
756 | const QList<AniData> animations = state.first().first; | ||||
757 | QCOMPARE(animations.count(), 1); | ||||
758 | QVERIFY(around(animations[0].timeLine.elapsed(), 250ms, 50ms)); | ||||
759 | QVERIFY(!animations[0].timeLine.done()); | ||||
760 | } | ||||
761 | | ||||
762 | // minimize the test client, when the test effect sees that a window was | ||||
763 | // minimized, it will try to complete animation for it | ||||
764 | QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput); | ||||
765 | QVERIFY(effectOutputSpy.isValid()); | ||||
766 | | ||||
767 | c->setMinimized(true); | ||||
768 | | ||||
769 | QCOMPARE(effectOutputSpy.count(), 1); | ||||
770 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | ||||
771 | | ||||
772 | { | ||||
773 | const AnimationEffect::AniMap state = effect->state(); | ||||
774 | QCOMPARE(state.count(), 1); | ||||
775 | QCOMPARE(state.firstKey(), c->effectWindow()); | ||||
776 | const QList<AniData> animations = state.first().first; | ||||
777 | QCOMPARE(animations.count(), 1); | ||||
778 | QCOMPARE(animations[0].timeLine.elapsed(), 1000ms); | ||||
779 | QVERIFY(animations[0].timeLine.done()); | ||||
780 | } | ||||
781 | } | ||||
782 | | ||||
713 | WAYLANDTEST_MAIN(ScriptedEffectsTest) | 783 | WAYLANDTEST_MAIN(ScriptedEffectsTest) | ||
714 | #include "scripted_effects_test.moc" | 784 | #include "scripted_effects_test.moc" |