From 9b9bd00c2bc48529dacbe1789ac8a699a4cdc94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Lefebvre?= Date: Wed, 19 Mar 2025 13:11:04 +0100 Subject: [PATCH] Add QTestPrivate::ensurePositionTopLeft() for reliable positioning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement ensurePositionTopLeft() to set a window's position to the available top-left corner and verify that it is correctly positioned. Incorrect updates to window.position and window.framePosition have been identified as one of the main sources of flakiness on Opensuse. This test function addresses this issue and improves test reliablity. Task-number: QTQAINFRA-7050 Change-Id: I946f74c7d2c1db9cfe4fec7db272e12876b3ed43 Reviewed-by: Tor Arne Vestbø Reviewed-by: Axel Spoerl (cherry picked from commit 7929852c1d39e12b7c586b5c6d257c9df27c01df) Reviewed-by: Marc Mutz --- src/testlib/qtesthelpers_p.h | 19 +++++++++++++++++++ tests/auto/gui/kernel/qwindow/CMakeLists.txt | 1 + 2 files changed, 20 insertions(+) diff --git a/src/testlib/qtesthelpers_p.h b/src/testlib/qtesthelpers_p.h index efe28c4f004..100ad8c2f9b 100644 --- a/src/testlib/qtesthelpers_p.h +++ b/src/testlib/qtesthelpers_p.h @@ -24,6 +24,7 @@ #ifdef QT_GUI_LIB #include #include +#include #endif #ifdef QT_WIDGETS_LIB @@ -91,6 +92,24 @@ static inline void androidCompatibleShow(QWidget *widget) } #endif // QT_WIDGETS_LIB +#ifdef QT_GUI_LIB +bool ensurePositionTopLeft(QWindow *window) +{ + const QPoint availableTopLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); + window->setFramePosition(availableTopLeft); + bool positionCorrect = true; + + if (!window->flags().testFlag(Qt::FramelessWindowHint)) + positionCorrect = QTest::qWaitFor([&]{ return window->framePosition() != window->position() ;}); + + const bool positionUpdated = QTest::qWaitFor([&]{ return window->framePosition() == availableTopLeft ;}); + if (!positionUpdated) + positionCorrect = false; + + return positionCorrect; +} +#endif + #ifdef QT_NETWORK_LIB inline bool isSecureTransportBlockingTest() { diff --git a/tests/auto/gui/kernel/qwindow/CMakeLists.txt b/tests/auto/gui/kernel/qwindow/CMakeLists.txt index 5824989ac34..8fa49f1e5dc 100644 --- a/tests/auto/gui/kernel/qwindow/CMakeLists.txt +++ b/tests/auto/gui/kernel/qwindow/CMakeLists.txt @@ -18,6 +18,7 @@ qt_internal_add_test(tst_qwindow Qt::CorePrivate Qt::Gui Qt::GuiPrivate + Qt::TestPrivate ) if(APPLE OR WIN32 OR QT_FEATURE_xcb)