diff --git a/autotests/integration/tabbox_test.cpp b/autotests/integration/tabbox_test.cpp index d1e5b98524..eedd450049 100644 --- a/autotests/integration/tabbox_test.cpp +++ b/autotests/integration/tabbox_test.cpp @@ -45,6 +45,8 @@ private Q_SLOTS: void init(); void cleanup(); + void testMoveForward(); + void testMoveBackward(); void testCapsLock(); }; @@ -147,5 +149,111 @@ void TabBoxTest::testCapsLock() QVERIFY(Test::waitForWindowDestroyed(c1)); } +void TabBoxTest::testMoveForward() +{ + // this test verifies that Alt+tab works correctly moving forward + + // first create three windows + QScopedPointer surface1(Test::createSurface()); + QScopedPointer shellSurface1(Test::createShellSurface(Test::ShellSurfaceType::WlShell, surface1.data())); + auto c1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue); + QVERIFY(c1); + QVERIFY(c1->isActive()); + QScopedPointer surface2(Test::createSurface()); + QScopedPointer shellSurface2(Test::createShellSurface(Test::ShellSurfaceType::XdgShellV5, surface2.data())); + auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::red); + QVERIFY(c2); + QVERIFY(c2->isActive()); + QScopedPointer surface3(Test::createSurface()); + QScopedPointer shellSurface3(Test::createShellSurface(Test::ShellSurfaceType::XdgShellV5, surface3.data())); + auto c3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::red); + QVERIFY(c3); + QVERIFY(c3->isActive()); + + // Setup tabbox signal spies + QSignalSpy tabboxAddedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxAdded); + QVERIFY(tabboxAddedSpy.isValid()); + QSignalSpy tabboxClosedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxClosed); + QVERIFY(tabboxClosedSpy.isValid()); + + // press alt+tab + quint32 timestamp = 0; + kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTALT, timestamp++); + QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier); + kwinApp()->platform()->keyboardKeyPressed(KEY_TAB, timestamp++); + kwinApp()->platform()->keyboardKeyReleased(KEY_TAB, timestamp++); + + QVERIFY(tabboxAddedSpy.wait()); + QVERIFY(TabBox::TabBox::self()->isGrabbed()); + + // release alt + kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTALT, timestamp++); + QCOMPARE(tabboxClosedSpy.count(), 1); + QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false); + QCOMPARE(workspace()->activeClient(), c2); + + surface3.reset(); + QVERIFY(Test::waitForWindowDestroyed(c3)); + surface2.reset(); + QVERIFY(Test::waitForWindowDestroyed(c2)); + surface1.reset(); + QVERIFY(Test::waitForWindowDestroyed(c1)); +} + +void TabBoxTest::testMoveBackward() +{ + // this test verifies that Alt+Shift+tab works correctly moving backward + + // first create three windows + QScopedPointer surface1(Test::createSurface()); + QScopedPointer shellSurface1(Test::createShellSurface(Test::ShellSurfaceType::WlShell, surface1.data())); + auto c1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue); + QVERIFY(c1); + QVERIFY(c1->isActive()); + QScopedPointer surface2(Test::createSurface()); + QScopedPointer shellSurface2(Test::createShellSurface(Test::ShellSurfaceType::XdgShellV5, surface2.data())); + auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::red); + QVERIFY(c2); + QVERIFY(c2->isActive()); + QScopedPointer surface3(Test::createSurface()); + QScopedPointer shellSurface3(Test::createShellSurface(Test::ShellSurfaceType::XdgShellV5, surface3.data())); + auto c3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::red); + QVERIFY(c3); + QVERIFY(c3->isActive()); + + // Setup tabbox signal spies + QSignalSpy tabboxAddedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxAdded); + QVERIFY(tabboxAddedSpy.isValid()); + QSignalSpy tabboxClosedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxClosed); + QVERIFY(tabboxClosedSpy.isValid()); + + // press alt+shift+tab + quint32 timestamp = 0; + kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTALT, timestamp++); + QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier); + kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTSHIFT, timestamp++); + QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier | Qt::ShiftModifier); + kwinApp()->platform()->keyboardKeyPressed(KEY_TAB, timestamp++); + kwinApp()->platform()->keyboardKeyReleased(KEY_TAB, timestamp++); + + QVERIFY(tabboxAddedSpy.wait()); + QVERIFY(TabBox::TabBox::self()->isGrabbed()); + + // release alt + kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTSHIFT, timestamp++); + QCOMPARE(tabboxClosedSpy.count(), 0); + kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTALT, timestamp++); + QCOMPARE(tabboxClosedSpy.count(), 1); + QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false); + QCOMPARE(workspace()->activeClient(), c1); + + surface3.reset(); + QVERIFY(Test::waitForWindowDestroyed(c3)); + surface2.reset(); + QVERIFY(Test::waitForWindowDestroyed(c2)); + surface1.reset(); + QVERIFY(Test::waitForWindowDestroyed(c1)); +} + WAYLANDTEST_MAIN(TabBoxTest) #include "tabbox_test.moc"