diff options
Diffstat (limited to 'tests/auto/widgets/util/qscroller/tst_qscroller.cpp')
-rw-r--r-- | tests/auto/widgets/util/qscroller/tst_qscroller.cpp | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp index d2f2a4b887..101b502fc6 100644 --- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp +++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui> #include <QtWidgets> @@ -105,6 +105,7 @@ private slots: void scroll(); void overshoot(); void multipleWindows(); + void mouseEventTimestamp(); private: QPointingDevice *m_touchScreen = QTest::createTouchDevice(); @@ -323,7 +324,6 @@ void tst_QScroller::scrollTo() { QScopedPointer<tst_QScrollerWidget> sw(new tst_QScrollerWidget); sw->show(); - QApplicationPrivate::setActiveWindow(sw.data()); if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data())) QSKIP("Failed to show and activate window"); @@ -355,7 +355,6 @@ void tst_QScroller::scroll() QScroller::grabGesture(sw.data(), QScroller::TouchGesture); sw->setGeometry(100, 100, 400, 300); sw->show(); - QApplicationPrivate::setActiveWindow(sw.data()); if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data())) QSKIP("Failed to show and activate window"); @@ -396,7 +395,6 @@ void tst_QScroller::overshoot() QScroller::grabGesture(sw.data(), QScroller::TouchGesture); sw->setGeometry(100, 100, 400, 300); sw->show(); - QApplicationPrivate::setActiveWindow(sw.data()); if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data())) QSKIP("Failed to show and activate window"); @@ -518,6 +516,66 @@ void tst_QScroller::multipleWindows() #endif } +/*! + This test verifies that mouse events arrive at the target widget + with valid timestamp, even if there is a gesture filtering (and then + replaying a copy of) the event. QTBUG-102010 + + We cannot truly simulate the double click here, as simulated events don't + go through the exact same event machinery as real events, so double clicks + don't get generated by Qt here. But we can verify that the timestamps of + the eventually delivered events are maintained. +*/ +void tst_QScroller::mouseEventTimestamp() +{ +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) + QScopedPointer<tst_QScrollerWidget> sw(new tst_QScrollerWidget()); + sw->scrollArea = QRectF(0, 0, 1000, 1000); + QScroller::grabGesture(sw.data(), QScroller::LeftMouseButtonGesture); + sw->setGeometry(100, 100, 400, 300); + sw->show(); + if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data())) + QSKIP("Failed to show and activate window"); + + QScroller *s1 = QScroller::scroller(sw.data()); + + struct EventFilter : QObject + { + QList<int> timestamps; + protected: + bool eventFilter(QObject *o, QEvent *e) override + { + if (e->isInputEvent()) + timestamps << static_cast<QInputEvent *>(e)->timestamp(); + return QObject::eventFilter(o, e); + } + + } eventFilter; + sw->installEventFilter(&eventFilter); + + const int interval = QGuiApplication::styleHints()->mouseDoubleClickInterval() / 10; + const QPoint point = sw->geometry().center(); + // Simulate double by pressing twice within the double click interval. + // Presses are filtered and then delayed by the scroller/gesture machinery, + // so we first record all events, and then make sure that the relative timestamps + // are maintained also for the replayed or synthesized events. + QTest::mousePress(sw->windowHandle(), Qt::LeftButton, {}, point); + QCOMPARE(s1->state(), QScroller::Pressed); + QTest::mouseRelease(sw->windowHandle(), Qt::LeftButton, {}, point, interval); + QCOMPARE(s1->state(), QScroller::Inactive); + QTest::mousePress(sw->windowHandle(), Qt::LeftButton, {}, point, interval); + QCOMPARE(s1->state(), QScroller::Pressed); + // also filtered and delayed by the scroller + QTest::mouseRelease(sw->windowHandle(), Qt::LeftButton, {}, point, interval); + QCOMPARE(s1->state(), QScroller::Inactive); + int lastTimestamp = -1; + for (int timestamp : std::as_const(eventFilter.timestamps)) { + QCOMPARE_GE(timestamp, lastTimestamp); + lastTimestamp = timestamp + interval; + } +#endif +} + QTEST_MAIN(tst_QScroller) #include "tst_qscroller.moc" |