diff --git a/autotests/integration/decoration_input_test.cpp b/autotests/integration/decoration_input_test.cpp index 56939db35e..25b5c17bf3 100644 --- a/autotests/integration/decoration_input_test.cpp +++ b/autotests/integration/decoration_input_test.cpp @@ -92,8 +92,6 @@ AbstractClient *DecorationInputTest::showWindow() #define COMPARE(actual, expected) \ if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ return nullptr; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - VERIFY(clientAddedSpy.isValid()); Surface *surface = Test::createSurface(Test::waylandCompositor()); VERIFY(surface); @@ -107,13 +105,9 @@ AbstractClient *DecorationInputTest::showWindow() VERIFY(decoSpy.wait()); COMPARE(deco->mode(), ServerSideDecoration::Mode::Server); // let's render - Test::render(surface, QSize(500, 50), Qt::blue); - - Test::flushWaylandConnection(); - VERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); + auto c = Test::renderAndWaitForShown(surface, QSize(500, 50), Qt::blue); VERIFY(c); - COMPARE(clientAddedSpy.first().first().value(), c); + COMPARE(workspace()->activeClient(), c); #undef VERIFY #undef COMPARE diff --git a/autotests/integration/dont_crash_cancel_animation.cpp b/autotests/integration/dont_crash_cancel_animation.cpp index 09342201e5..be32d92a5d 100644 --- a/autotests/integration/dont_crash_cancel_animation.cpp +++ b/autotests/integration/dont_crash_cancel_animation.cpp @@ -52,10 +52,6 @@ private Q_SLOTS: void init(); void cleanup(); void testScript(); - -private: - void unlock(); - AbstractClient *showWindow(); }; void DontCrashCancelAnimationFromAnimationEndedTest::initTestCase() @@ -101,21 +97,14 @@ void DontCrashCancelAnimationFromAnimationEndedTest::testScript() using namespace KWayland::Client; // create a window - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - Surface *surface = Test::createSurface(Test::waylandCompositor()); QVERIFY(surface); ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); // let's render - Test::render(surface, QSize(100, 50), Qt::blue); - - Test::flushWaylandConnection(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); + auto c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); // make sure we animate QTest::qWait(200); diff --git a/autotests/integration/dont_crash_no_border.cpp b/autotests/integration/dont_crash_no_border.cpp index 653cf0c21f..e8e99cceb0 100644 --- a/autotests/integration/dont_crash_no_border.cpp +++ b/autotests/integration/dont_crash_no_border.cpp @@ -98,8 +98,6 @@ void DontCrashNoBorder::testCreateWindow() { // create a window and ensure that this doesn't crash using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -113,13 +111,9 @@ void DontCrashNoBorder::testCreateWindow() QVERIFY(decoSpy.wait()); QCOMPARE(deco->mode(), ServerSideDecoration::Mode::Server); // let's render - Test::render(surface.data(), QSize(500, 50), Qt::blue); - - Test::flushWaylandConnection(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(500, 50), Qt::blue); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); QVERIFY(!c->isDecorated()); } diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index 2dda319414..320efafa91 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -45,6 +45,8 @@ class Surface; namespace KWin { +class ShellClient; + class WaylandTestApplication : public Application { Q_OBJECT @@ -116,6 +118,17 @@ KWayland::Client::ShellSurface *createShellSurface(KWayland::Client::Surface *su * The @p surface gets damaged and committed, thus it's rendered. **/ void render(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format = QImage::Format_ARGB32); + +/** + * Waits till a new ShellClient is shown and returns the created ShellClient. + * If no ShellClient gets shown during @p timeout @c null is returned. + **/ +ShellClient *waitForWaylandWindowShown(int timeout = 5000); + +/** + * Combination of @link{render} and @link{waitForWaylandWindowShown}. + **/ +ShellClient *renderAndWaitForShown(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format = QImage::Format_ARGB32, int timeout = 5000); } } diff --git a/autotests/integration/lockscreen.cpp b/autotests/integration/lockscreen.cpp index 0fff8b3886..80f906a42e 100644 --- a/autotests/integration/lockscreen.cpp +++ b/autotests/integration/lockscreen.cpp @@ -161,21 +161,16 @@ AbstractClient *LockScreenTest::showWindow() #define COMPARE(actual, expected) \ if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ return nullptr; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - VERIFY(clientAddedSpy.isValid()); Surface *surface = Test::createSurface(m_compositor); VERIFY(surface); ShellSurface *shellSurface = Test::createShellSurface(surface, surface); VERIFY(shellSurface); // let's render - Test::render(surface, QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); - m_connection->flush(); - VERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); VERIFY(c); - COMPARE(clientAddedSpy.first().first().value(), c); + COMPARE(workspace()->activeClient(), c); #undef VERIFY #undef COMPARE diff --git a/autotests/integration/maximize_test.cpp b/autotests/integration/maximize_test.cpp index b375318c88..defec25442 100644 --- a/autotests/integration/maximize_test.cpp +++ b/autotests/integration/maximize_test.cpp @@ -87,20 +87,15 @@ void TestMaximized::cleanup() void TestMaximized::testMaximizedPassedToDeco() { // this test verifies that when a ShellClient gets maximized the Decoration receives the signal - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); QScopedPointer surface(Test::createSurface()); QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QScopedPointer ssd(Test::waylandServerSideDecoration()->create(surface.data())); - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); QSignalSpy sizeChangedSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangedSpy.isValid()); - QVERIFY(clientAddedSpy.isEmpty()); - QVERIFY(clientAddedSpy.wait()); - auto client = clientAddedSpy.first().first().value(); QVERIFY(client); QVERIFY(client->isDecorated()); auto decoration = client->decoration(); @@ -147,9 +142,6 @@ void TestMaximized::testMaximizedPassedToDeco() void TestMaximized::testInitiallyMaximized() { // this test verifies that a window created as maximized, will be maximized - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QScopedPointer shellSurface(Test::createShellSurface(surface.data())); @@ -161,11 +153,7 @@ void TestMaximized::testInitiallyMaximized() QCOMPARE(shellSurface->size(), QSize(1280, 1024)); // now let's render in an incorrect size - Test::render(surface.data(), QSize(100, 50), Qt::blue); - - QVERIFY(clientAddedSpy.isEmpty()); - QVERIFY(clientAddedSpy.wait()); - auto client = clientAddedSpy.first().first().value(); + auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); QVERIFY(client); QCOMPARE(client->geometry(), QRect(0, 0, 100, 50)); QEXPECT_FAIL("", "Should go out of maximzied", Continue); diff --git a/autotests/integration/move_resize_window_test.cpp b/autotests/integration/move_resize_window_test.cpp index ed27a41543..c1db4501be 100644 --- a/autotests/integration/move_resize_window_test.cpp +++ b/autotests/integration/move_resize_window_test.cpp @@ -105,9 +105,6 @@ void MoveResizeWindowTest::testMove() { using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -116,13 +113,10 @@ void MoveResizeWindowTest::testMove() QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); QCOMPARE(c->geometry(), QRect(0, 0, 100, 50)); QSignalSpy geometryChangedSpy(c, &AbstractClient::geometryChanged); QVERIFY(geometryChangedSpy.isValid()); @@ -203,9 +197,6 @@ void MoveResizeWindowTest::testPackTo() { using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -214,13 +205,10 @@ void MoveResizeWindowTest::testPackTo() QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); QCOMPARE(c->geometry(), QRect(0, 0, 100, 50)); // let's place it centered @@ -247,9 +235,6 @@ void MoveResizeWindowTest::testPackAgainstClient() { using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface1(Test::createSurface()); QVERIFY(!surface1.isNull()); QScopedPointer surface2(Test::createSurface()); @@ -267,17 +252,13 @@ void MoveResizeWindowTest::testPackAgainstClient() QVERIFY(!shellSurface3.isNull()); QScopedPointer shellSurface4(Test::createShellSurface(surface4.data())); QVERIFY(!shellSurface4.isNull()); - auto renderWindow = [this, &clientAddedSpy] (Surface *surface, const QString &methodCall, const QRect &expectedGeometry) { + auto renderWindow = [this] (Surface *surface, const QString &methodCall, const QRect &expectedGeometry) { // let's render - Test::render(surface, QSize(10, 10), Qt::blue); + auto c = Test::renderAndWaitForShown(surface, QSize(10, 10), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); QCOMPARE(c->geometry().size(), QSize(10, 10)); - clientAddedSpy.clear(); // let's place it centered Placement::self()->placeCentered(c, QRect(0, 0, 1280, 1024)); QCOMPARE(c->geometry(), QRect(635, 507, 10, 10)); @@ -293,13 +274,10 @@ void MoveResizeWindowTest::testPackAgainstClient() QVERIFY(!surface.isNull()); QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); // let's place it centered Placement::self()->placeCentered(c, QRect(0, 0, 1280, 1024)); QCOMPARE(c->geometry(), QRect(590, 487, 100, 50)); @@ -323,8 +301,6 @@ void MoveResizeWindowTest::testGrowShrink_data() void MoveResizeWindowTest::testGrowShrink() { using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); // block geometry helper QScopedPointer surface1(Test::createSurface()); @@ -332,9 +308,7 @@ void MoveResizeWindowTest::testGrowShrink() QScopedPointer shellSurface1(Test::createShellSurface(surface1.data())); QVERIFY(!shellSurface1.isNull()); Test::render(surface1.data(), QSize(650, 514), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - clientAddedSpy.clear(); + QVERIFY(Test::waitForWaylandWindowShown()); workspace()->slotWindowPackRight(); workspace()->slotWindowPackDown(); @@ -346,13 +320,10 @@ void MoveResizeWindowTest::testGrowShrink() QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); // let's place it centered Placement::self()->placeCentered(c, QRect(0, 0, 1280, 1024)); @@ -391,9 +362,6 @@ void MoveResizeWindowTest::testPointerMoveEnd() // this test verifies that moving a window through pointer only ends if all buttons are released using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -402,12 +370,10 @@ void MoveResizeWindowTest::testPointerMoveEnd() QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); + QCOMPARE(c, workspace()->activeClient()); QVERIFY(!c->isMove()); // let's trigger the left button @@ -448,9 +414,6 @@ void MoveResizeWindowTest::testPlasmaShellSurfaceMovable() { // this test verifies that certain window types from PlasmaShellSurface are not moveable or resizable using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -462,11 +425,8 @@ void MoveResizeWindowTest::testPlasmaShellSurfaceMovable() QFETCH(KWayland::Client::PlasmaShellSurface::Role, role); plasmaSurface->setRole(role); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = clientAddedSpy.first().first().value(); QVERIFY(c); QTEST(c->isMovable(), "movable"); QTEST(c->isMovableAcrossScreens(), "movableAcrossScreens"); diff --git a/autotests/integration/plasma_surface_test.cpp b/autotests/integration/plasma_surface_test.cpp index e2554f972e..9be38f7a62 100644 --- a/autotests/integration/plasma_surface_test.cpp +++ b/autotests/integration/plasma_surface_test.cpp @@ -103,15 +103,10 @@ void PlasmaSurfaceTest::testRoleOnAllDesktops() QScopedPointer plasmaSurface(m_plasmaShell->createSurface(surface.data())); QVERIFY(!plasmaSurface.isNull()); - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - // now render to map the window - Test::render(surface.data(), QSize(100, 50), Qt::blue); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); + AbstractClient *c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); // currently the role is not yet set, so the window should not be on all desktops QCOMPARE(c->isOnAllDesktops(), false); @@ -135,7 +130,7 @@ void PlasmaSurfaceTest::testRoleOnAllDesktops() QScopedPointer shellSurface2(Test::createShellSurface(surface2.data())); QVERIFY(!shellSurface2.isNull()); Test::render(surface2.data(), QSize(100, 50), Qt::blue); - QVERIFY(clientAddedSpy.wait()); + QVERIFY(Test::waitForWaylandWindowShown()); QVERIFY(workspace()->activeClient() != c); c = workspace()->activeClient(); @@ -173,14 +168,9 @@ void PlasmaSurfaceTest::testAcceptsFocus() QFETCH(PlasmaShellSurface::Role, role); plasmaSurface->setRole(role); - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - // now render to map the window - Test::render(surface.data(), QSize(100, 50), Qt::blue); - QVERIFY(clientAddedSpy.wait()); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - auto c = clientAddedSpy.first().first().value(); QVERIFY(c); QTEST(c->wantsInput(), "wantsInput"); QTEST(c->isActive(), "active"); diff --git a/autotests/integration/quick_tiling_test.cpp b/autotests/integration/quick_tiling_test.cpp index 7e8e51fbfb..c1fd7e54bf 100644 --- a/autotests/integration/quick_tiling_test.cpp +++ b/autotests/integration/quick_tiling_test.cpp @@ -131,9 +131,6 @@ void QuickTilingTest::testQuickTiling() { using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -142,13 +139,10 @@ void QuickTilingTest::testQuickTiling() QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); QCOMPARE(c->geometry(), QRect(0, 0, 100, 50)); QCOMPARE(c->quickTileMode(), AbstractClient::QuickTileNone); QSignalSpy quickTileChangedSpy(c, &AbstractClient::quickTileModeChanged); @@ -205,9 +199,6 @@ void QuickTilingTest::testQuickMaximizing() { using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -216,13 +207,10 @@ void QuickTilingTest::testQuickMaximizing() QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); QCOMPARE(c->geometry(), QRect(0, 0, 100, 50)); QCOMPARE(c->quickTileMode(), AbstractClient::QuickTileNone); QCOMPARE(c->maximizeMode(), MaximizeRestore); @@ -313,9 +301,6 @@ void QuickTilingTest::testQuickTilingKeyboardMove() { using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -324,13 +309,10 @@ void QuickTilingTest::testQuickTilingKeyboardMove() QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); QCOMPARE(c->geometry(), QRect(0, 0, 100, 50)); QCOMPARE(c->quickTileMode(), AbstractClient::QuickTileNone); QCOMPARE(c->maximizeMode(), MaximizeRestore); @@ -390,9 +372,6 @@ void QuickTilingTest::testQuickTilingPointerMove() { using namespace KWayland::Client; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); @@ -401,13 +380,10 @@ void QuickTilingTest::testQuickTilingPointerMove() QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - Test::render(surface.data(), QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); - QVERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); QVERIFY(c); - QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(workspace()->activeClient(), c); QCOMPARE(c->geometry(), QRect(0, 0, 100, 50)); QCOMPARE(c->quickTileMode(), AbstractClient::QuickTileNone); QCOMPARE(c->maximizeMode(), MaximizeRestore); diff --git a/autotests/integration/struts_test.cpp b/autotests/integration/struts_test.cpp index 2dd4f588d4..ffaca22be8 100644 --- a/autotests/integration/struts_test.cpp +++ b/autotests/integration/struts_test.cpp @@ -155,8 +155,6 @@ void StrutsTest::testWaylandStruts() QFETCH(QVector, windowGeometries); // create the panels - QSignalSpy windowCreatedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(windowCreatedSpy.isValid()); QHash clients; for (auto it = windowGeometries.constBegin(), end = windowGeometries.constEnd(); it != end; it++) { const QRect windowGeometry = *it; @@ -168,17 +166,13 @@ void StrutsTest::testWaylandStruts() plasmaSurface->setRole(PlasmaShellSurface::Role::Panel); // map the window - Test::render(surface, windowGeometry.size(), Qt::red, QImage::Format_RGB32); + auto c = Test::renderAndWaitForShown(surface, windowGeometry.size(), Qt::red, QImage::Format_RGB32); - QVERIFY(windowCreatedSpy.wait()); - QCOMPARE(windowCreatedSpy.count(), 1); - auto c = windowCreatedSpy.first().first().value(); QVERIFY(c); QVERIFY(!c->isActive()); QCOMPARE(c->geometry(), windowGeometry); QVERIFY(c->isDock()); QVERIFY(c->hasStrut()); - windowCreatedSpy.clear(); clients.insert(surface, c); } @@ -224,21 +218,13 @@ void StrutsTest::testMoveWaylandPanel() plasmaSurface->setPosition(windowGeometry.topLeft()); plasmaSurface->setRole(PlasmaShellSurface::Role::Panel); - QSignalSpy windowCreatedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(windowCreatedSpy.isValid()); - // map the window - Test::render(surface.data(), windowGeometry.size(), Qt::red, QImage::Format_RGB32); - - QVERIFY(windowCreatedSpy.wait()); - QCOMPARE(windowCreatedSpy.count(), 1); - auto c = windowCreatedSpy.first().first().value(); + auto c = Test::renderAndWaitForShown(surface.data(), windowGeometry.size(), Qt::red, QImage::Format_RGB32); QVERIFY(c); QVERIFY(!c->isActive()); QCOMPARE(c->geometry(), windowGeometry); QVERIFY(c->isDock()); QVERIFY(c->hasStrut()); - windowCreatedSpy.clear(); QCOMPARE(workspace()->clientArea(PlacementArea, 0, 1), QRect(0, 0, 1280, 1000)); QCOMPARE(workspace()->clientArea(MaximizeArea, 0, 1), QRect(0, 0, 1280, 1000)); QCOMPARE(workspace()->clientArea(PlacementArea, 1, 1), QRect(1280, 0, 1280, 1024)); @@ -276,22 +262,13 @@ void StrutsTest::testWaylandMobilePanel() plasmaSurface->setPosition(windowGeometry.topLeft()); plasmaSurface->setRole(PlasmaShellSurface::Role::Panel); - QSignalSpy windowCreatedSpy(waylandServer(), &WaylandServer::shellClientAdded); - QVERIFY(windowCreatedSpy.isValid()); - // map the first panel - Test::render(surface.data(), windowGeometry.size(), Qt::red, QImage::Format_RGB32); - - QVERIFY(windowCreatedSpy.wait()); - QCOMPARE(windowCreatedSpy.count(), 1); - - auto c = windowCreatedSpy.first().first().value(); + auto c = Test::renderAndWaitForShown(surface.data(), windowGeometry.size(), Qt::red, QImage::Format_RGB32); QVERIFY(c); QVERIFY(!c->isActive()); QCOMPARE(c->geometry(), windowGeometry); QVERIFY(c->isDock()); QVERIFY(c->hasStrut()); - windowCreatedSpy.clear(); QCOMPARE(workspace()->clientArea(PlacementArea, 0, 1), QRect(0, 60, 1280, 964)); QCOMPARE(workspace()->clientArea(MaximizeArea, 0, 1), QRect(0, 60, 1280, 964)); @@ -308,18 +285,13 @@ void StrutsTest::testWaylandMobilePanel() plasmaSurface2->setPosition(windowGeometry2.topLeft()); plasmaSurface2->setRole(PlasmaShellSurface::Role::Panel); - Test::render(surface2.data(), windowGeometry2.size(), Qt::blue, QImage::Format_RGB32); + auto c1 = Test::renderAndWaitForShown(surface2.data(), windowGeometry2.size(), Qt::blue, QImage::Format_RGB32); - QVERIFY(windowCreatedSpy.wait()); - QCOMPARE(windowCreatedSpy.count(), 1); - - auto c1 = windowCreatedSpy.first().first().value(); QVERIFY(c1); QVERIFY(!c1->isActive()); QCOMPARE(c1->geometry(), windowGeometry2); QVERIFY(c1->isDock()); QVERIFY(c1->hasStrut()); - windowCreatedSpy.clear(); QCOMPARE(workspace()->clientArea(PlacementArea, 0, 1), QRect(0, 60, 1280, 814)); QCOMPARE(workspace()->clientArea(MaximizeArea, 0, 1), QRect(0, 60, 1280, 814)); diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index 465f150bad..417debb4d9 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "kwin_wayland_test.h" +#include "shell_client.h" +#include "wayland_server.h" #include #include @@ -244,6 +246,32 @@ void render(Surface *surface, const QSize &size, const QColor &color, const QIma surface->commit(Surface::CommitFlag::None); } +ShellClient *waitForWaylandWindowShown(int timeout) +{ + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + if (!clientAddedSpy.isValid()) { + return nullptr; + } + if (!clientAddedSpy.wait(timeout)) { + return nullptr; + } + return clientAddedSpy.first().first().value(); +} + +ShellClient *renderAndWaitForShown(Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format, int timeout) +{ + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + if (!clientAddedSpy.isValid()) { + return nullptr; + } + render(surface, size, color, format); + flushWaylandConnection(); + if (!clientAddedSpy.wait(timeout)) { + return nullptr; + } + return clientAddedSpy.first().first().value(); +} + void flushWaylandConnection() { if (s_waylandConnection.connection) { diff --git a/autotests/integration/touch_input_test.cpp b/autotests/integration/touch_input_test.cpp index 66ead44bfb..2862fe6f42 100644 --- a/autotests/integration/touch_input_test.cpp +++ b/autotests/integration/touch_input_test.cpp @@ -100,21 +100,16 @@ AbstractClient *TouchInputTest::showWindow() #define COMPARE(actual, expected) \ if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ return nullptr; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - VERIFY(clientAddedSpy.isValid()); Surface *surface = Test::createSurface(Test::waylandCompositor()); VERIFY(surface); ShellSurface *shellSurface = Test::createShellSurface(surface, surface); VERIFY(shellSurface); // let's render - Test::render(surface, QSize(100, 50), Qt::blue); + auto c = Test::renderAndWaitForShown(surface, QSize(100, 50), Qt::blue); - Test::flushWaylandConnection(); - VERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); VERIFY(c); - COMPARE(clientAddedSpy.first().first().value(), c); + COMPARE(workspace()->activeClient(), c); #undef VERIFY #undef COMPARE diff --git a/autotests/integration/transient_placement.cpp b/autotests/integration/transient_placement.cpp index 79a2a7b886..412cae24c0 100644 --- a/autotests/integration/transient_placement.cpp +++ b/autotests/integration/transient_placement.cpp @@ -106,8 +106,6 @@ AbstractClient *TransientPlacementTest::showWindow(const QSize &size, bool decor #define COMPARE(actual, expected) \ if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ return nullptr; - QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); - VERIFY(clientAddedSpy.isValid()); Surface *surface = Test::createSurface(Test::waylandCompositor()); VERIFY(surface); @@ -126,13 +124,10 @@ AbstractClient *TransientPlacementTest::showWindow(const QSize &size, bool decor COMPARE(deco->mode(), ServerSideDecoration::Mode::Server); } // let's render - Test::render(surface, size, Qt::blue); + auto c = Test::renderAndWaitForShown(surface, size, Qt::blue); - Test::flushWaylandConnection(); - VERIFY(clientAddedSpy.wait()); - AbstractClient *c = workspace()->activeClient(); VERIFY(c); - COMPARE(clientAddedSpy.first().first().value(), c); + COMPARE(workspace()->activeClient(), c); #undef VERIFY #undef COMPARE