summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/util/qscroller/tst_qscroller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/util/qscroller/tst_qscroller.cpp')
-rw-r--r--tests/auto/widgets/util/qscroller/tst_qscroller.cpp72
1 files changed, 68 insertions, 4 deletions
diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp
index 491d5d48e3..a328b0c8d7 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>
@@ -8,6 +8,8 @@
#include <QtGui/private/qeventpoint_p.h>
#include <qpa/qwindowsysteminterface.h>
+#include <QtWidgets/private/qapplication_p.h>
+
// #include <QDebug>
class tst_QScrollerWidget : public QWidget
@@ -103,6 +105,7 @@ private slots:
void scroll();
void overshoot();
void multipleWindows();
+ void mouseEventTimestamp();
private:
QPointingDevice *m_touchScreen = QTest::createTouchDevice();
@@ -321,7 +324,7 @@ void tst_QScroller::scrollTo()
{
QScopedPointer<tst_QScrollerWidget> sw(new tst_QScrollerWidget);
sw->show();
- QApplication::setActiveWindow(sw.data());
+ QApplicationPrivate::setActiveWindow(sw.data());
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
QSKIP("Failed to show and activate window");
@@ -353,7 +356,7 @@ void tst_QScroller::scroll()
QScroller::grabGesture(sw.data(), QScroller::TouchGesture);
sw->setGeometry(100, 100, 400, 300);
sw->show();
- QApplication::setActiveWindow(sw.data());
+ QApplicationPrivate::setActiveWindow(sw.data());
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
QSKIP("Failed to show and activate window");
@@ -394,7 +397,7 @@ void tst_QScroller::overshoot()
QScroller::grabGesture(sw.data(), QScroller::TouchGesture);
sw->setGeometry(100, 100, 400, 300);
sw->show();
- QApplication::setActiveWindow(sw.data());
+ QApplicationPrivate::setActiveWindow(sw.data());
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
QSKIP("Failed to show and activate window");
@@ -516,6 +519,67 @@ 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();
+ QApplicationPrivate::setActiveWindow(sw.data());
+ 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"