Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/effects/scripted_effects_test.cpp
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <https://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | 20 | | |||
21 | #include "scripting/scriptedeffect.h" | 21 | #include "scripting/scriptedeffect.h" | ||
22 | #include "libkwineffects/anidata_p.h" | 22 | #include "libkwineffects/anidata_p.h" | ||
23 | 23 | | |||
24 | #include "abstract_client.h" | ||||
24 | #include "composite.h" | 25 | #include "composite.h" | ||
25 | #include "cursor.h" | 26 | #include "cursor.h" | ||
26 | #include "deleted.h" | 27 | #include "deleted.h" | ||
27 | #include "effect_builtins.h" | 28 | #include "effect_builtins.h" | ||
28 | #include "effectloader.h" | 29 | #include "effectloader.h" | ||
29 | #include "effects.h" | 30 | #include "effects.h" | ||
30 | #include "kwin_wayland_test.h" | 31 | #include "kwin_wayland_test.h" | ||
31 | #include "platform.h" | 32 | #include "platform.h" | ||
32 | #include "xdgshellclient.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 <QScriptContext> | ||
38 | #include <QScriptEngine> | 38 | #include <QScriptEngine> | ||
39 | #include <QScriptValue> | 39 | #include <QScriptValue> | ||
40 | 40 | | |||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 133 | for (auto it = c.begin(); it != c.end(); ++it) { | |||
138 | break; | 138 | break; | ||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | return (static_cast<EffectsHandlerImpl*>(effects)->isEffectLoaded(name)); | 141 | return (static_cast<EffectsHandlerImpl*>(effects)->isEffectLoaded(name)); | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | void ScriptedEffectsTest::initTestCase() | 144 | void ScriptedEffectsTest::initTestCase() | ||
145 | { | 145 | { | ||
146 | qRegisterMetaType<KWin::XdgShellClient *>(); | | |||
147 | qRegisterMetaType<KWin::AbstractClient*>(); | 146 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
148 | qRegisterMetaType<KWin::Deleted*>(); | 147 | qRegisterMetaType<KWin::Deleted*>(); | ||
149 | qRegisterMetaType<KWin::Effect*>(); | 148 | qRegisterMetaType<KWin::Effect*>(); | ||
150 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 149 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
151 | QVERIFY(workspaceCreatedSpy.isValid()); | 150 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
152 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 151 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
153 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | 152 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||
154 | 153 | | |||
▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Line(s) | 497 | { | |||
506 | QVERIFY(effect->load(QStringLiteral("grabTest"))); | 505 | QVERIFY(effect->load(QStringLiteral("grabTest"))); | ||
507 | 506 | | |||
508 | // create test client | 507 | // create test client | ||
509 | using namespace KWayland::Client; | 508 | using namespace KWayland::Client; | ||
510 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | 509 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
511 | QVERIFY(surface); | 510 | QVERIFY(surface); | ||
512 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | 511 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||
513 | QVERIFY(shellSurface); | 512 | QVERIFY(shellSurface); | ||
514 | XdgShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | 513 | AbstractClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||
515 | QVERIFY(c); | 514 | QVERIFY(c); | ||
516 | QCOMPARE(workspace()->activeClient(), c); | 515 | QCOMPARE(workspace()->activeClient(), c); | ||
517 | 516 | | |||
518 | // the test effect should grab the test client successfully | 517 | // the test effect should grab the test client successfully | ||
519 | QCOMPARE(effectOutputSpy.count(), 1); | 518 | QCOMPARE(effectOutputSpy.count(), 1); | ||
520 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | 519 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | ||
521 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), effect); | 520 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), effect); | ||
522 | } | 521 | } | ||
Show All 16 Lines | 524 | { | |||
539 | QVERIFY(grabber->load(QStringLiteral("grabAlreadyGrabbedWindowTest_grabber"))); | 538 | QVERIFY(grabber->load(QStringLiteral("grabAlreadyGrabbedWindowTest_grabber"))); | ||
540 | 539 | | |||
541 | // create test client | 540 | // create test client | ||
542 | using namespace KWayland::Client; | 541 | using namespace KWayland::Client; | ||
543 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | 542 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
544 | QVERIFY(surface); | 543 | QVERIFY(surface); | ||
545 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | 544 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||
546 | QVERIFY(shellSurface); | 545 | QVERIFY(shellSurface); | ||
547 | XdgShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | 546 | AbstractClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||
548 | QVERIFY(c); | 547 | QVERIFY(c); | ||
549 | QCOMPARE(workspace()->activeClient(), c); | 548 | QCOMPARE(workspace()->activeClient(), c); | ||
550 | 549 | | |||
551 | // effect that initially held the grab should still hold the grab | 550 | // effect that initially held the grab should still hold the grab | ||
552 | QCOMPARE(ownerOutputSpy.count(), 1); | 551 | QCOMPARE(ownerOutputSpy.count(), 1); | ||
553 | QCOMPARE(ownerOutputSpy.first().first(), QStringLiteral("ok")); | 552 | QCOMPARE(ownerOutputSpy.first().first(), QStringLiteral("ok")); | ||
554 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), owner); | 553 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), owner); | ||
555 | 554 | | |||
Show All 20 Lines | 561 | { | |||
576 | QVERIFY(thief->load(QStringLiteral("grabAlreadyGrabbedWindowForcedTest_thief"))); | 575 | QVERIFY(thief->load(QStringLiteral("grabAlreadyGrabbedWindowForcedTest_thief"))); | ||
577 | 576 | | |||
578 | // create test client | 577 | // create test client | ||
579 | using namespace KWayland::Client; | 578 | using namespace KWayland::Client; | ||
580 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | 579 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
581 | QVERIFY(surface); | 580 | QVERIFY(surface); | ||
582 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | 581 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||
583 | QVERIFY(shellSurface); | 582 | QVERIFY(shellSurface); | ||
584 | XdgShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | 583 | AbstractClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||
585 | QVERIFY(c); | 584 | QVERIFY(c); | ||
586 | QCOMPARE(workspace()->activeClient(), c); | 585 | QCOMPARE(workspace()->activeClient(), c); | ||
587 | 586 | | |||
588 | // verify that the owner in fact held the grab | 587 | // verify that the owner in fact held the grab | ||
589 | QCOMPARE(ownerOutputSpy.count(), 1); | 588 | QCOMPARE(ownerOutputSpy.count(), 1); | ||
590 | QCOMPARE(ownerOutputSpy.first().first(), QStringLiteral("ok")); | 589 | QCOMPARE(ownerOutputSpy.first().first(), QStringLiteral("ok")); | ||
591 | 590 | | |||
592 | // effect that grabbed the test client forcefully should now hold the grab | 591 | // effect that grabbed the test client forcefully should now hold the grab | ||
Show All 14 Lines | 598 | { | |||
607 | QVERIFY(effect->load(QStringLiteral("ungrabTest"))); | 606 | QVERIFY(effect->load(QStringLiteral("ungrabTest"))); | ||
608 | 607 | | |||
609 | // create test client | 608 | // create test client | ||
610 | using namespace KWayland::Client; | 609 | using namespace KWayland::Client; | ||
611 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | 610 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
612 | QVERIFY(surface); | 611 | QVERIFY(surface); | ||
613 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | 612 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||
614 | QVERIFY(shellSurface); | 613 | QVERIFY(shellSurface); | ||
615 | XdgShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | 614 | AbstractClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||
616 | QVERIFY(c); | 615 | QVERIFY(c); | ||
617 | QCOMPARE(workspace()->activeClient(), c); | 616 | QCOMPARE(workspace()->activeClient(), c); | ||
618 | 617 | | |||
619 | // the test effect should grab the test client successfully | 618 | // the test effect should grab the test client successfully | ||
620 | QCOMPARE(effectOutputSpy.count(), 1); | 619 | QCOMPARE(effectOutputSpy.count(), 1); | ||
621 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | 620 | QCOMPARE(effectOutputSpy.first().first(), QStringLiteral("ok")); | ||
622 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), effect); | 621 | QCOMPARE(c->effectWindow()->data(WindowAddedGrabRole).value<void *>(), effect); | ||
623 | 622 | | |||
Show All 26 Lines | 643 | { | |||
650 | QVERIFY(effect->load(file)); | 649 | QVERIFY(effect->load(file)); | ||
651 | 650 | | |||
652 | // create test client | 651 | // create test client | ||
653 | using namespace KWayland::Client; | 652 | using namespace KWayland::Client; | ||
654 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | 653 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
655 | QVERIFY(surface); | 654 | QVERIFY(surface); | ||
656 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | 655 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||
657 | QVERIFY(shellSurface); | 656 | QVERIFY(shellSurface); | ||
658 | XdgShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | 657 | AbstractClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||
659 | QVERIFY(c); | 658 | QVERIFY(c); | ||
660 | QCOMPARE(workspace()->activeClient(), c); | 659 | QCOMPARE(workspace()->activeClient(), c); | ||
661 | 660 | | |||
662 | auto around = [] (std::chrono::milliseconds elapsed, | 661 | auto around = [] (std::chrono::milliseconds elapsed, | ||
663 | std::chrono::milliseconds pivot, | 662 | std::chrono::milliseconds pivot, | ||
664 | std::chrono::milliseconds margin) { | 663 | std::chrono::milliseconds margin) { | ||
665 | return qAbs(elapsed.count() - pivot.count()) < margin.count(); | 664 | return qAbs(elapsed.count() - pivot.count()) < margin.count(); | ||
666 | }; | 665 | }; | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 722 | { | |||
728 | QVERIFY(effect->load(QStringLiteral("completeTest"))); | 727 | QVERIFY(effect->load(QStringLiteral("completeTest"))); | ||
729 | 728 | | |||
730 | // create test client | 729 | // create test client | ||
731 | using namespace KWayland::Client; | 730 | using namespace KWayland::Client; | ||
732 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | 731 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
733 | QVERIFY(surface); | 732 | QVERIFY(surface); | ||
734 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | 733 | XdgShellSurface *shellSurface = Test::createXdgShellStableSurface(surface, surface); | ||
735 | QVERIFY(shellSurface); | 734 | QVERIFY(shellSurface); | ||
736 | XdgShellClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | 735 | AbstractClient *c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); | ||
737 | QVERIFY(c); | 736 | QVERIFY(c); | ||
738 | QCOMPARE(workspace()->activeClient(), c); | 737 | QCOMPARE(workspace()->activeClient(), c); | ||
739 | 738 | | |||
740 | auto around = [] (std::chrono::milliseconds elapsed, | 739 | auto around = [] (std::chrono::milliseconds elapsed, | ||
741 | std::chrono::milliseconds pivot, | 740 | std::chrono::milliseconds pivot, | ||
742 | std::chrono::milliseconds margin) { | 741 | std::chrono::milliseconds margin) { | ||
743 | return qAbs(elapsed.count() - pivot.count()) < margin.count(); | 742 | return qAbs(elapsed.count() - pivot.count()) < margin.count(); | ||
744 | }; | 743 | }; | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |