summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2022-03-28 15:16:27 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2022-03-29 17:53:24 +0200
commit7e4c2ac711c0b68133f06ab997a33f8bf7c4f734 (patch)
tree332e59989772c2ebf4869590d6a156b6c0cac569 /src/widgets
parent2ca50df11c08a5e25342104ee9008ef680ab4fb6 (diff)
Query the QWindow in every test iteration in qWFWExposed(QWidget)
Task-number: QTBUG-102030 Change-Id: Ic8aee76570a000709b480ffbe19335518e3f7a7e Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qtestsupport_widgets.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/widgets/kernel/qtestsupport_widgets.cpp b/src/widgets/kernel/qtestsupport_widgets.cpp
index acc69d098c..2dfe9efd3b 100644
--- a/src/widgets/kernel/qtestsupport_widgets.cpp
+++ b/src/widgets/kernel/qtestsupport_widgets.cpp
@@ -47,9 +47,24 @@
#include <QtGui/qtestsupport_gui.h>
#include <QtGui/private/qevent_p.h>
#include <QtGui/private/qeventpoint_p.h>
+#include <private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
QT_BEGIN_NAMESPACE
+template <typename FunctorWindowGetter, typename FunctorPredicate>
+static bool qWaitForWidgetWindow(FunctorWindowGetter windowGetter, FunctorPredicate predicate, int timeout)
+{
+ if (!windowGetter())
+ return false;
+
+ return QTest::qWaitFor([&]() {
+ if (QWindow *window = windowGetter())
+ return predicate(window);
+ return false;
+ }, timeout);
+}
+
/*!
\since 5.0
@@ -61,9 +76,17 @@ QT_BEGIN_NAMESPACE
*/
Q_WIDGETS_EXPORT bool QTest::qWaitForWindowActive(QWidget *widget, int timeout)
{
- if (QWindow *window = widget->window()->windowHandle())
- return QTest::qWaitForWindowActive(window, timeout);
- return false;
+ if (Q_UNLIKELY(!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))) {
+ qWarning() << "qWaitForWindowActive was called on a platform that doesn't support window"
+ << "activation. This means there is an error in the test and it should either"
+ << "check for the WindowActivation platform capability before calling"
+ << "qWaitForWindowActivate, use qWaitForWindowExposed instead, or skip the test."
+ << "Falling back to qWaitForWindowExposed.";
+ return qWaitForWindowExposed(widget, timeout);
+ }
+ return qWaitForWidgetWindow([&]() { return widget->window()->windowHandle(); },
+ [&](QWindow *window) { return window->isActive(); },
+ timeout);
}
/*!
@@ -86,9 +109,9 @@ Q_WIDGETS_EXPORT bool QTest::qWaitForWindowActive(QWidget *widget, int timeout)
*/
Q_WIDGETS_EXPORT bool QTest::qWaitForWindowExposed(QWidget *widget, int timeout)
{
- if (QWindow *window = widget->window()->windowHandle())
- return QTest::qWaitForWindowExposed(window, timeout);
- return false;
+ return qWaitForWidgetWindow([&]() { return widget->window()->windowHandle(); },
+ [&](QWindow *window) { return window->isExposed(); },
+ timeout);
}
namespace QTest {