summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-09-22 11:43:57 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-04-14 20:13:41 +0200
commit79ac43053798763828d51c79f6368465b1db1c87 (patch)
treef133e264cb4cdc176d57d7f7543b40a985a5f856 /tests/auto/gui/kernel
parentd71dc36f473d4fecc0648ff915de0dcd2fb85184 (diff)
Test for QWindow getting enter/leave events when secondary window shows/hides
Equivalent to the test added to the QWidget test case, but since QtWidgets code contains logic to both synthesize and compress/filter enter/leave events, we can only verify that the QWindow does get the events. The test is very flaky on Windows, so blacklisting it right away. Change-Id: Ic1da9439f60f619a76a3653a23fef8e9ebc0e75d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qwindow/BLACKLIST3
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp82
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST
index 328d3f51b1..b56a310c06 100644
--- a/tests/auto/gui/kernel/qwindow/BLACKLIST
+++ b/tests/auto/gui/kernel/qwindow/BLACKLIST
@@ -23,3 +23,6 @@ android
android
[modalWindowModallity]
android
+[enterLeaveOnWindowShowHide]
+windows-10
+windows-11
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 1cac1820d9..b092ebe623 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -89,6 +89,10 @@ private slots:
void qobject_castOnDestruction();
void touchToMouseTranslationByPopup();
void stateChangeSignal();
+#ifndef QT_NO_CURSOR
+ void enterLeaveOnWindowShowHide_data();
+ void enterLeaveOnWindowShowHide();
+#endif
private:
QPoint m_availableTopLeft;
@@ -2876,6 +2880,84 @@ void tst_QWindow::stateChangeSignal()
CHECK_SIGNAL(Qt::WindowMinimized);
}
+#ifndef QT_NO_CURSOR
+void tst_QWindow::enterLeaveOnWindowShowHide_data()
+{
+ QTest::addColumn<Qt::WindowType>("windowType");
+ QTest::addRow("dialog") << Qt::Dialog;
+ QTest::addRow("popup") << Qt::Popup;
+}
+
+/*!
+ Verify that we get enter and leave events if the window under the mouse
+ opens and closes a modal dialog or popup. QWindow might get multiple
+ events in a row, as the various QPA plugins need to use different techniques
+ to synthesize events if the native platform doesn't provide them for us.
+*/
+void tst_QWindow::enterLeaveOnWindowShowHide()
+{
+ QFETCH(Qt::WindowType, windowType);
+
+ class Window : public QWindow
+ {
+ public:
+ int numEnterEvents = 0;
+ int numLeaveEvents = 0;
+ QPoint enterPosition;
+ protected:
+ bool event(QEvent *e) override
+ {
+ switch (e->type()) {
+ case QEvent::Enter:
+ ++numEnterEvents;
+ enterPosition = static_cast<QEnterEvent*>(e)->position().toPoint();
+ break;
+ case QEvent::Leave:
+ ++numLeaveEvents;
+ break;
+ default:
+ break;
+ }
+ return QWindow::event(e);
+ }
+ };
+
+ int expectedEnter = 0;
+ int expectedLeave = 0;
+
+ Window window;
+ const QRect screenGeometry = window.screen()->availableGeometry();
+ const QPoint cursorPos = screenGeometry.topLeft() + QPoint(50, 50);
+ window.setGeometry(QRect(cursorPos - QPoint(50, 50), screenGeometry.size() / 4));
+ QCursor::setPos(cursorPos);
+
+ if (!QTest::qWaitFor([&]{ return window.geometry().contains(QCursor::pos()); }))
+ QSKIP("We can't move the cursor");
+
+ window.show();
+ window.requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+
+ ++expectedEnter;
+ QTRY_COMPARE_WITH_TIMEOUT(window.numEnterEvents, expectedEnter, 250);
+ QCOMPARE(window.enterPosition, window.mapFromGlobal(QCursor::pos()));
+
+ QWindow secondary;
+ secondary.setFlag(windowType);
+ secondary.setModality(Qt::WindowModal);
+ secondary.setTransientParent(&window);
+ secondary.setPosition(cursorPos + QPoint(50, 50));
+ secondary.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&secondary));
+ ++expectedLeave;
+ QTRY_VERIFY(window.numLeaveEvents >= expectedLeave);
+ secondary.close();
+ ++expectedEnter;
+ QTRY_VERIFY(window.numEnterEvents >= expectedEnter);
+ QCOMPARE(window.enterPosition, window.mapFromGlobal(QCursor::pos()));
+}
+#endif
+
#include <tst_qwindow.moc>
QTEST_MAIN(tst_QWindow)