From 53dcd205c6636c92a626354da6efa7634bd0ea94 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 30 Jul 2021 20:29:01 +0200 Subject: [PATCH] inputmethod: Add a test that simulates client switching --- autotests/integration/inputmethod_test.cpp | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/autotests/integration/inputmethod_test.cpp b/autotests/integration/inputmethod_test.cpp index 5818d8ea3f..30aafe9b2b 100644 --- a/autotests/integration/inputmethod_test.cpp +++ b/autotests/integration/inputmethod_test.cpp @@ -55,6 +55,7 @@ private Q_SLOTS: void testEnableDisableV3(); void testEnableActive(); void testHidePanel(); + void testSwitchFocusedSurfaces(); }; @@ -276,6 +277,57 @@ void InputMethodTest::testHidePanel() } +void InputMethodTest::testSwitchFocusedSurfaces() +{ + QVERIFY(!InputMethod::self()->isActive()); + + QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded); + QSignalSpy clientRemovedSpy(workspace(), &Workspace::clientRemoved); + QVERIFY(clientAddedSpy.isValid()); + + QSignalSpy activateSpy(InputMethod::self(), &InputMethod::activeChanged); + QScopedPointer textInput(Test::waylandTextInputManager()->createTextInput(Test::waylandSeat())); + textInput->showInputPanel(); + QVERIFY(clientAddedSpy.wait(10000)); + + QVector clients; + QVector surfaces; + QVector toplevels; + // We create 3 surfaces + for (int i = 0; i < 3; ++i) { + auto surface = Test::createSurface(); + auto shellSurface = Test::createXdgToplevelSurface(surface); + clients += Test::renderAndWaitForShown(surface, QSize(1280, 1024), Qt::red); + QCOMPARE(workspace()->activeClient(), clients.constLast()); + surfaces += surface; + toplevels += shellSurface; + } + waylandServer()->seat()->setFocusedTextInputSurface(clients.constFirst()->surface()); + + QCOMPARE(clientAddedSpy.count(), 4); + QVERIFY(activateSpy.count() || activateSpy.wait()); + QVERIFY(!InputMethod::self()->isActive()); + textInput->enable(surfaces.last()); + QVERIFY(!InputMethod::self()->isActive()); + waylandServer()->seat()->setFocusedTextInputSurface(clients.first()->surface()); + QVERIFY(!InputMethod::self()->isActive()); + activateSpy.clear(); + waylandServer()->seat()->setFocusedTextInputSurface(clients.last()->surface()); + QVERIFY(activateSpy.count() || activateSpy.wait()); + QVERIFY(InputMethod::self()->isActive()); + + activateSpy.clear(); + waylandServer()->seat()->setFocusedTextInputSurface(clients.first()->surface()); + QVERIFY(activateSpy.count() || activateSpy.wait()); + QVERIFY(!InputMethod::self()->isActive()); + + // Destroy the test client. + for (int i = 0; i < clients.count(); ++i) { + delete toplevels[i]; + QVERIFY(Test::waitForWindowDestroyed(clients[i])); + } +} + WAYLANDTEST_MAIN(InputMethodTest) #include "inputmethod_test.moc"