Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/effects/scripted_effects_test.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 59 | private Q_SLOTS: | |||
---|---|---|---|---|---|
71 | void testFullScreenEffect_data(); | 71 | void testFullScreenEffect_data(); | ||
72 | void testFullScreenEffect(); | 72 | void testFullScreenEffect(); | ||
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(); | ||||
80 | void testRedirect(); | ||||
79 | 81 | | |||
80 | private: | 82 | private: | ||
81 | ScriptedEffect *loadEffect(const QString &name); | 83 | ScriptedEffect *loadEffect(const QString &name); | ||
82 | }; | 84 | }; | ||
83 | 85 | | |||
84 | class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect | 86 | class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect | ||
85 | { | 87 | { | ||
86 | Q_OBJECT | 88 | Q_OBJECT | ||
▲ Show 20 Lines • Show All 527 Lines • ▼ Show 20 Line(s) | 590 | { | |||
614 | effectOutputSpy.clear(); | 616 | effectOutputSpy.clear(); | ||
615 | c->setMinimized(true); | 617 | c->setMinimized(true); | ||
616 | 618 | | |||
617 | QCOMPARE(effectOutputSpy.count(), 1); | 619 | QCOMPARE(effectOutputSpy.count(), 1); | ||
618 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | 620 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | ||
619 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), nullptr); | 621 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), nullptr); | ||
620 | } | 622 | } | ||
621 | 623 | | |||
624 | void ScriptedEffectsTest::testRedirect_data() | ||||
625 | { | ||||
626 | QTest::addColumn<QString>("file"); | ||||
627 | QTest::addColumn<bool>("shouldTerminate"); | ||||
628 | QTest::newRow("animate/DontTerminateAtSource") << "redirectAnimateDontTerminateTest" << true; | ||||
629 | QTest::newRow("animate/TerminateAtSource") << "redirectAnimateTerminateTest" << true; | ||||
630 | QTest::newRow("set/DontTerminate") << "redirectSetDontTerminateTest" << false; | ||||
631 | QTest::newRow("set/Terminate") << "redirectSetTerminateTest" << true; | ||||
632 | } | ||||
633 | | ||||
634 | void ScriptedEffectsTest::testRedirect() | ||||
635 | { | ||||
636 | // this test verifies that redirect() works | ||||
637 | | ||||
638 | // load the test effect | ||||
639 | auto effect = new ScriptedEffectWithDebugSpy; | ||||
640 | QFETCH(QString, file); | ||||
641 | QVERIFY(effect->load(file)); | ||||
642 | | ||||
643 | // create test client | ||||
644 | using namespace KWayland::Client; | ||||
645 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||||
646 | QVERIFY(surface); | ||||
647 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||||
648 | QVERIFY(shellSurface); | ||||
649 | ShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||||
650 | QVERIFY(c); | ||||
651 | QCOMPARE(workspace()->activeClient(), c); | ||||
652 | | ||||
653 | auto around = [] (std::chrono::milliseconds elapsed, | ||||
654 | std::chrono::milliseconds pivot, | ||||
655 | std::chrono::milliseconds margin) { | ||||
656 | return qAbs(elapsed.count() - pivot.count()) < margin.count(); | ||||
657 | }; | ||||
658 | | ||||
659 | // initially, the test animation is at the source position | ||||
660 | | ||||
661 | { | ||||
662 | const AnimationEffect::AniMap state = effect->state(); | ||||
663 | QCOMPARE(state.count(), 1); | ||||
664 | QCOMPARE(state.firstKey(), c->effectWindow()); | ||||
665 | const QList<AniData> animations = state.first().first; | ||||
666 | QCOMPARE(animations.count(), 1); | ||||
667 | QCOMPARE(animations[0].timeLine.direction(), TimeLine::Forward); | ||||
668 | QVERIFY(around(animations[0].timeLine.elapsed(), 0ms, 50ms)); | ||||
669 | } | ||||
670 | | ||||
671 | // minimize the test client after 250ms, when the test effect sees that | ||||
672 | // a window was minimized, it will try to reverse animation for it | ||||
673 | QTest::qWait(250); | ||||
674 | | ||||
675 | QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput); | ||||
676 | QVERIFY(effectOutputSpy.isValid()); | ||||
677 | | ||||
678 | c->setMinimized(true); | ||||
679 | | ||||
680 | QCOMPARE(effectOutputSpy.count(), 1); | ||||
681 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | ||||
682 | | ||||
683 | { | ||||
684 | const AnimationEffect::AniMap state = effect->state(); | ||||
685 | QCOMPARE(state.count(), 1); | ||||
686 | QCOMPARE(state.firstKey(), c->effectWindow()); | ||||
687 | const QList<AniData> animations = state.first().first; | ||||
688 | QCOMPARE(animations.count(), 1); | ||||
689 | QCOMPARE(animations[0].timeLine.direction(), TimeLine::Backward); | ||||
690 | QVERIFY(around(animations[0].timeLine.elapsed(), 1000ms - 250ms, 50ms)); | ||||
691 | } | ||||
692 | | ||||
693 | // wait for the animation to reach the start position, 100ms is an extra | ||||
694 | // safety margin | ||||
695 | QTest::qWait(250 + 100); | ||||
696 | | ||||
697 | QFETCH(bool, shouldTerminate); | ||||
698 | if (shouldTerminate) { | ||||
699 | const AnimationEffect::AniMap state = effect->state(); | ||||
700 | QCOMPARE(state.count(), 0); | ||||
701 | } else { | ||||
702 | const AnimationEffect::AniMap state = effect->state(); | ||||
703 | QCOMPARE(state.count(), 1); | ||||
704 | QCOMPARE(state.firstKey(), c->effectWindow()); | ||||
705 | const QList<AniData> animations = state.first().first; | ||||
706 | QCOMPARE(animations.count(), 1); | ||||
707 | QCOMPARE(animations[0].timeLine.direction(), TimeLine::Backward); | ||||
708 | QCOMPARE(animations[0].timeLine.elapsed(), 1000ms); | ||||
709 | QCOMPARE(animations[0].timeLine.value(), 0.0); | ||||
710 | } | ||||
711 | } | ||||
712 | | ||||
622 | WAYLANDTEST_MAIN(ScriptedEffectsTest) | 713 | WAYLANDTEST_MAIN(ScriptedEffectsTest) | ||
623 | #include "scripted_effects_test.moc" | 714 | #include "scripted_effects_test.moc" |