Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/effects/scripted_effects_test.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 57 | private Q_SLOTS: | |||
---|---|---|---|---|---|
65 | void testAnimations_data(); | 65 | void testAnimations_data(); | ||
66 | void testAnimations(); | 66 | void testAnimations(); | ||
67 | void testScreenEdge(); | 67 | void testScreenEdge(); | ||
68 | void testScreenEdgeTouch(); | 68 | void testScreenEdgeTouch(); | ||
69 | void testFullScreenEffect_data(); | 69 | void testFullScreenEffect_data(); | ||
70 | void testFullScreenEffect(); | 70 | void testFullScreenEffect(); | ||
71 | void testKeepAlive_data(); | 71 | void testKeepAlive_data(); | ||
72 | void testKeepAlive(); | 72 | void testKeepAlive(); | ||
73 | void testGrab(); | ||||
74 | void testGrabAlreadyGrabbedWindow(); | ||||
75 | void testGrabAlreadyGrabbedWindowForced(); | ||||
76 | void testUngrab(); | ||||
73 | 77 | | |||
74 | private: | 78 | private: | ||
75 | ScriptedEffect *loadEffect(const QString &name); | 79 | ScriptedEffect *loadEffect(const QString &name); | ||
76 | }; | 80 | }; | ||
77 | 81 | | |||
78 | class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect | 82 | class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect | ||
79 | { | 83 | { | ||
80 | Q_OBJECT | 84 | Q_OBJECT | ||
▲ Show 20 Lines • Show All 396 Lines • ▼ Show 20 Line(s) | 479 | } else { | |||
477 | // removed immediately | 481 | // removed immediately | ||
478 | QSignalSpy deletedRemovedSpy(workspace(), &Workspace::deletedRemoved); | 482 | QSignalSpy deletedRemovedSpy(workspace(), &Workspace::deletedRemoved); | ||
479 | QVERIFY(deletedRemovedSpy.isValid()); | 483 | QVERIFY(deletedRemovedSpy.isValid()); | ||
480 | QVERIFY(deletedRemovedSpy.count() == 1 || deletedRemovedSpy.wait(100)); // 100ms is less than duration of the animation | 484 | QVERIFY(deletedRemovedSpy.count() == 1 || deletedRemovedSpy.wait(100)); // 100ms is less than duration of the animation | ||
481 | QCOMPARE(effect->state().count(), 0); | 485 | QCOMPARE(effect->state().count(), 0); | ||
482 | } | 486 | } | ||
483 | } | 487 | } | ||
484 | 488 | | |||
489 | void ScriptedEffectsTest::testGrab() | ||||
490 | { | ||||
491 | // this test verifies that scripted effects can grab windows that are | ||||
492 | // not already grabbed | ||||
493 | | ||||
494 | // load the test effect | ||||
495 | auto effect = new ScriptedEffectWithDebugSpy; | ||||
496 | QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput); | ||||
497 | QVERIFY(effectOutputSpy.isValid()); | ||||
498 | QVERIFY(effect->load(QStringLiteral("grabTest"))); | ||||
499 | | ||||
500 | // create test client | ||||
501 | using namespace KWayland::Client; | ||||
502 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||||
503 | QVERIFY(surface); | ||||
504 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||||
505 | QVERIFY(shellSurface); | ||||
506 | ShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||||
507 | QVERIFY(c); | ||||
508 | QCOMPARE(workspace()->activeClient(), c); | ||||
509 | | ||||
510 | // the test effect should grab the test client successfully | ||||
511 | QCOMPARE(effectOutputSpy.count(), 1); | ||||
512 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | ||||
513 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), effect); | ||||
514 | } | ||||
515 | | ||||
516 | void ScriptedEffectsTest::testGrabAlreadyGrabbedWindow() | ||||
517 | { | ||||
518 | // this test verifies that scripted effects cannot grab already grabbed | ||||
519 | // windows (unless force is set to true of course) | ||||
520 | | ||||
521 | // load effect that will hold the window grab | ||||
522 | auto owner = new ScriptedEffectWithDebugSpy; | ||||
523 | QSignalSpy ownerOutputSpy(owner, &ScriptedEffectWithDebugSpy::testOutput); | ||||
524 | QVERIFY(ownerOutputSpy.isValid()); | ||||
525 | QVERIFY(owner->load(QStringLiteral("grabAlreadyGrabbedWindowTest_owner"))); | ||||
526 | | ||||
527 | // load effect that will try to grab already grabbed window | ||||
528 | auto grabber = new ScriptedEffectWithDebugSpy; | ||||
529 | QSignalSpy grabberOutputSpy(grabber, &ScriptedEffectWithDebugSpy::testOutput); | ||||
530 | QVERIFY(grabberOutputSpy.isValid()); | ||||
531 | QVERIFY(grabber->load(QStringLiteral("grabAlreadyGrabbedWindowTest_grabber"))); | ||||
532 | | ||||
533 | // create test client | ||||
534 | using namespace KWayland::Client; | ||||
535 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||||
536 | QVERIFY(surface); | ||||
537 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||||
538 | QVERIFY(shellSurface); | ||||
539 | ShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||||
540 | QVERIFY(c); | ||||
541 | QCOMPARE(workspace()->activeClient(), c); | ||||
542 | | ||||
543 | // effect that initially held the grab should still hold the grab | ||||
544 | QCOMPARE(ownerOutputSpy.count(), 1); | ||||
545 | QCOMPARE(ownerOutputSpy.first().first(), QStringLiteral("ok")); | ||||
546 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), owner); | ||||
547 | | ||||
548 | // effect that tried to grab already grabbed window should fail miserably | ||||
549 | QCOMPARE(grabberOutputSpy.count(), 1); | ||||
550 | QCOMPARE(grabberOutputSpy.first().first(), QStringLiteral("fail")); | ||||
551 | } | ||||
552 | | ||||
553 | void ScriptedEffectsTest::testGrabAlreadyGrabbedWindowForced() | ||||
554 | { | ||||
555 | // this test verifies that scripted effects can steal window grabs when | ||||
556 | // they forcefully try to grab windows | ||||
557 | | ||||
558 | // load effect that initially will be holding the window grab | ||||
559 | auto owner = new ScriptedEffectWithDebugSpy; | ||||
560 | QSignalSpy ownerOutputSpy(owner, &ScriptedEffectWithDebugSpy::testOutput); | ||||
561 | QVERIFY(ownerOutputSpy.isValid()); | ||||
562 | QVERIFY(owner->load(QStringLiteral("grabAlreadyGrabbedWindowForcedTest_owner"))); | ||||
563 | | ||||
564 | // load effect that will try to steal the window grab | ||||
565 | auto thief = new ScriptedEffectWithDebugSpy; | ||||
566 | QSignalSpy thiefOutputSpy(thief, &ScriptedEffectWithDebugSpy::testOutput); | ||||
567 | QVERIFY(thiefOutputSpy.isValid()); | ||||
568 | QVERIFY(thief->load(QStringLiteral("grabAlreadyGrabbedWindowForcedTest_thief"))); | ||||
569 | | ||||
570 | // create test client | ||||
571 | using namespace KWayland::Client; | ||||
572 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||||
573 | QVERIFY(surface); | ||||
574 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||||
575 | QVERIFY(shellSurface); | ||||
576 | ShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||||
577 | QVERIFY(c); | ||||
578 | QCOMPARE(workspace()->activeClient(), c); | ||||
579 | | ||||
580 | // verify that the owner in fact held the grab | ||||
581 | QCOMPARE(ownerOutputSpy.count(), 1); | ||||
582 | QCOMPARE(ownerOutputSpy.first().first(), QStringLiteral("ok")); | ||||
583 | | ||||
584 | // effect that grabbed the test client forcefully should now hold the grab | ||||
585 | QCOMPARE(thiefOutputSpy.count(), 1); | ||||
586 | QCOMPARE(thiefOutputSpy.first().first(), QStringLiteral("ok")); | ||||
587 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), thief); | ||||
588 | } | ||||
589 | | ||||
590 | void ScriptedEffectsTest::testUngrab() | ||||
591 | { | ||||
592 | // this test verifies that scripted effects can ungrab windows that they | ||||
593 | // are previously grabbed | ||||
594 | | ||||
595 | // load the test effect | ||||
596 | auto effect = new ScriptedEffectWithDebugSpy; | ||||
597 | QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput); | ||||
598 | QVERIFY(effectOutputSpy.isValid()); | ||||
599 | QVERIFY(effect->load(QStringLiteral("ungrabTest"))); | ||||
600 | | ||||
601 | // create test client | ||||
602 | using namespace KWayland::Client; | ||||
603 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||||
604 | QVERIFY(surface); | ||||
605 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||||
606 | QVERIFY(shellSurface); | ||||
607 | ShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||||
608 | QVERIFY(c); | ||||
609 | QCOMPARE(workspace()->activeClient(), c); | ||||
610 | | ||||
611 | // the test effect should grab the test client successfully | ||||
612 | QCOMPARE(effectOutputSpy.count(), 1); | ||||
613 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | ||||
614 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), effect); | ||||
615 | | ||||
616 | // when the test effect sees that a window was minimized, it will try to ungrab it | ||||
617 | effectOutputSpy.clear(); | ||||
618 | c->setMinimized(true); | ||||
619 | | ||||
620 | QCOMPARE(effectOutputSpy.count(), 1); | ||||
621 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | ||||
622 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), nullptr); | ||||
623 | } | ||||
624 | | ||||
485 | WAYLANDTEST_MAIN(ScriptedEffectsTest) | 625 | WAYLANDTEST_MAIN(ScriptedEffectsTest) | ||
486 | #include "scripted_effects_test.moc" | 626 | #include "scripted_effects_test.moc" |