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.cpp99
1 files changed, 69 insertions, 30 deletions
diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp
index e3789ab645..a328b0c8d7 100644
--- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp
+++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the $MODULE$ of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui>
#include <QtWidgets>
@@ -33,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
@@ -128,6 +105,7 @@ private slots:
void scroll();
void overshoot();
void multipleWindows();
+ void mouseEventTimestamp();
private:
QPointingDevice *m_touchScreen = QTest::createTouchDevice();
@@ -346,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");
@@ -378,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");
@@ -419,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");
@@ -541,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"