summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/kernel/qwindow/tst_qwindow.cpp')
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp84
1 files changed, 75 insertions, 9 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 3dc2886b80..ae5bf55b72 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -70,6 +70,7 @@ private slots:
void activateAndClose();
void mouseEventSequence();
void windowModality();
+ void inputReentrancy();
void initTestCase()
{
@@ -141,11 +142,14 @@ private:
void tst_QWindow::eventOrderOnShow()
{
- QRect geometry(80, 80, 40, 40);
+ // Some platforms enforce minimum widths for windows, which can cause extra resize
+ // events, so set the width to suitably large value to avoid those.
+ QRect geometry(80, 80, 300, 40);
Window window;
window.setGeometry(geometry);
window.show();
+ QCoreApplication::processEvents();
QTRY_COMPARE(window.received(QEvent::Show), 1);
QTRY_COMPARE(window.received(QEvent::Resize), 1);
@@ -157,12 +161,15 @@ void tst_QWindow::eventOrderOnShow()
void tst_QWindow::positioning()
{
- QRect geometry(80, 80, 40, 40);
+ // Some platforms enforce minimum widths for windows, which can cause extra resize
+ // events, so set the width to suitably large value to avoid those.
+ QRect geometry(80, 80, 300, 40);
Window window;
window.setGeometry(geometry);
QCOMPARE(window.geometry(), geometry);
window.show();
+ QCoreApplication::processEvents();
QTRY_COMPARE(window.received(QEvent::Resize), 1);
QTRY_VERIFY(window.received(QEvent::Expose) > 0);
@@ -176,12 +183,11 @@ void tst_QWindow::positioning()
QPoint originalFramePos = window.framePos();
window.setWindowState(Qt::WindowFullScreen);
-#ifdef Q_OS_WIN
- QEXPECT_FAIL("", "QTBUG-24904 - Too many resize events on setting window state", Continue);
-#endif
+ QCoreApplication::processEvents();
QTRY_COMPARE(window.received(QEvent::Resize), 2);
window.setWindowState(Qt::WindowNoState);
+ QCoreApplication::processEvents();
QTRY_COMPARE(window.received(QEvent::Resize), 3);
QTRY_COMPARE(originalPos, window.pos());
@@ -218,12 +224,14 @@ void tst_QWindow::isExposed()
window.setGeometry(geometry);
QCOMPARE(window.geometry(), geometry);
window.show();
+ QCoreApplication::processEvents();
QTRY_VERIFY(window.received(QEvent::Expose) > 0);
QTRY_VERIFY(window.isExposed());
window.hide();
+ QCoreApplication::processEvents();
#ifdef Q_OS_MAC
QEXPECT_FAIL("", "This test fails on Mac OS X, see QTBUG-23059", Abort);
#endif
@@ -235,8 +243,11 @@ void tst_QWindow::isExposed()
void tst_QWindow::isActive()
{
Window window;
- window.setGeometry(80, 80, 40, 40);
+ // Some platforms enforce minimum widths for windows, which can cause extra resize
+ // events, so set the width to suitably large value to avoid those.
+ window.setGeometry(80, 80, 300, 40);
window.show();
+ QCoreApplication::processEvents();
QTRY_VERIFY(window.isExposed());
QTRY_COMPARE(window.received(QEvent::Resize), 1);
@@ -256,6 +267,7 @@ void tst_QWindow::isActive()
QVERIFY(child.isActive());
// parent shouldn't receive new resize events from child being shown
+ QCoreApplication::processEvents();
QTRY_COMPARE(window.received(QEvent::Resize), 1);
QTRY_COMPARE(window.received(QEvent::FocusIn), 1);
QTRY_COMPARE(window.received(QEvent::FocusOut), 1);
@@ -266,12 +278,13 @@ void tst_QWindow::isActive()
Window dialog;
dialog.setTransientParent(&window);
- dialog.setGeometry(110, 110, 30, 30);
+ dialog.setGeometry(110, 110, 300, 30);
dialog.show();
dialog.requestActivateWindow();
QTRY_VERIFY(dialog.isExposed());
+ QCoreApplication::processEvents();
QTRY_COMPARE(dialog.received(QEvent::Resize), 1);
QTRY_VERIFY(QGuiApplication::focusWindow() == &dialog);
QVERIFY(dialog.isActive());
@@ -285,6 +298,7 @@ void tst_QWindow::isActive()
window.requestActivateWindow();
QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+ QCoreApplication::processEvents();
QTRY_COMPARE(dialog.received(QEvent::FocusOut), 1);
QTRY_COMPARE(window.received(QEvent::FocusIn), 2);
@@ -314,6 +328,8 @@ public:
mouseSequenceSignature += 'p';
mousePressButton = event->button();
mousePressScreenPos = event->screenPos();
+ if (spinLoopWhenPressed)
+ QCoreApplication::processEvents();
}
}
void mouseReleaseEvent(QMouseEvent *event) {
@@ -329,6 +345,7 @@ public:
if (ignoreMouse) {
event->ignore();
} else {
+ ++mouseMovedCount;
mouseMoveButton = event->button();
mouseMoveScreenPos = event->screenPos();
}
@@ -352,6 +369,8 @@ public:
switch (points.at(i).state()) {
case Qt::TouchPointPressed:
++touchPressedCount;
+ if (spinLoopWhenPressed)
+ QCoreApplication::processEvents();
break;
case Qt::TouchPointReleased:
++touchReleasedCount;
@@ -365,7 +384,7 @@ public:
}
}
void resetCounters() {
- mousePressedCount = mouseReleasedCount = mouseDoubleClickedCount = 0;
+ mousePressedCount = mouseReleasedCount = mouseMovedCount = mouseDoubleClickedCount = 0;
mouseSequenceSignature = QString();
touchPressedCount = touchReleasedCount = touchMovedCount = 0;
}
@@ -374,18 +393,21 @@ public:
keyPressCode = keyReleaseCode = 0;
mousePressButton = mouseReleaseButton = mouseMoveButton = 0;
ignoreMouse = ignoreTouch = false;
+ spinLoopWhenPressed = false;
resetCounters();
}
int keyPressCode, keyReleaseCode;
int mousePressButton, mouseReleaseButton, mouseMoveButton;
- int mousePressedCount, mouseReleasedCount, mouseDoubleClickedCount;
+ int mousePressedCount, mouseReleasedCount, mouseMovedCount, mouseDoubleClickedCount;
QString mouseSequenceSignature;
QPointF mousePressScreenPos, mouseMoveScreenPos;
int touchPressedCount, touchReleasedCount, touchMovedCount;
QEvent::Type touchEventType;
bool ignoreMouse, ignoreTouch;
+
+ bool spinLoopWhenPressed;
};
void tst_QWindow::testInputEvents()
@@ -839,5 +861,49 @@ void tst_QWindow::windowModality()
QCOMPARE(spy.count(), 3);
}
+void tst_QWindow::inputReentrancy()
+{
+ InputTestWindow window;
+ window.spinLoopWhenPressed = true;
+
+ window.setGeometry(80, 80, 40, 40);
+ window.show();
+ QTest::qWaitForWindowShown(&window);
+
+ // Queue three events.
+ QPointF local(12, 34);
+ QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton);
+ local += QPointF(2, 2);
+ QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton);
+ QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::NoButton);
+ // Process them. However, the event handler for the press will also call
+ // processEvents() so the move and release will be delivered before returning
+ // from mousePressEvent(). The point is that no events should get lost.
+ QCoreApplication::processEvents();
+ QCOMPARE(window.mousePressButton, int(Qt::LeftButton));
+ QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton));
+ QCOMPARE(window.mousePressedCount, 1);
+ QCOMPARE(window.mouseMovedCount, 1);
+ QCOMPARE(window.mouseReleasedCount, 1);
+
+ // Now the same for touch.
+ QList<QWindowSystemInterface::TouchPoint> points;
+ QWindowSystemInterface::TouchPoint tp1;
+ tp1.id = 1;
+ tp1.state = Qt::TouchPointPressed;
+ tp1.area = QRectF(10, 10, 4, 4);
+ points << tp1;
+ QWindowSystemInterface::handleTouchEvent(&window, touchDevice, points);
+ points[0].state = Qt::TouchPointMoved;
+ points[0].area = QRectF(20, 20, 8, 8);
+ QWindowSystemInterface::handleTouchEvent(&window, touchDevice, points);
+ points[0].state = Qt::TouchPointReleased;
+ QWindowSystemInterface::handleTouchEvent(&window, touchDevice, points);
+ QCoreApplication::processEvents();
+ QCOMPARE(window.touchPressedCount, 1);
+ QCOMPARE(window.touchMovedCount, 1);
+ QCOMPARE(window.touchReleasedCount, 1);
+}
+
#include <tst_qwindow.moc>
QTEST_MAIN(tst_QWindow)