summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Lefebvre <[email protected]>2025-03-19 13:11:04 +0100
committerFrederic Lefebvre <[email protected]>2025-03-26 12:14:01 +0000
commit7929852c1d39e12b7c586b5c6d257c9df27c01df (patch)
treeb7025526aabb45005195444123b97331812de248
parenta5268131e217915b28bdbaee6c2f2e24eb34cc2d (diff)
Add QTestPrivate::ensurePositionTopLeft() for reliable positioning
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ø <[email protected]> Reviewed-by: Axel Spoerl <[email protected]>
-rw-r--r--src/testlib/qtesthelpers_p.h19
-rw-r--r--tests/auto/gui/kernel/qwindow/CMakeLists.txt1
2 files changed, 20 insertions, 0 deletions
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 <QtGui/QGuiApplication>
#include <QtGui/QScreen>
+#include <QtGui/QWindow>
#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)