diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-05-02 13:44:17 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-05-02 20:50:51 +0000 |
commit | 4ab5b4de70a91e26c1736fa5757a4124b15bab3c (patch) | |
tree | 1d0985dbf0b6fc3986318af35600e0697a96d93e /tests/auto | |
parent | fe86b0fda7bcce099a0bca08e6925e89efc634c4 (diff) |
Drawer: fix drag-over-threshold calculation
Don't steal a horizontal drag if a flickable has been dragged a long
distance vertically, and then later the flick happens to exceed the
horizontal drag threshold.
Change-Id: Idf39997aa20cc41da561f182119199f30c63ba32
Task-number: QTBUG-60521
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/drawer/data/flickable.qml (renamed from tests/auto/drawer/data/flicking.qml) | 0 | ||||
-rw-r--r-- | tests/auto/drawer/tst_drawer.cpp | 65 |
2 files changed, 45 insertions, 20 deletions
diff --git a/tests/auto/drawer/data/flicking.qml b/tests/auto/drawer/data/flickable.qml index 62256afd..62256afd 100644 --- a/tests/auto/drawer/data/flicking.qml +++ b/tests/auto/drawer/data/flickable.qml diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index 37f00050..a7ebaa9e 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -91,7 +91,8 @@ private slots: void interactive_data(); void interactive(); - void flicking(); + void flickable_data(); + void flickable(); private: struct TouchDeviceDeleter @@ -889,9 +890,25 @@ void tst_Drawer::interactive() QCOMPARE(aboutToHideSpy.count(), 0); } -void tst_Drawer::flicking() +void tst_Drawer::flickable_data() { - QQuickApplicationHelper helper(this, QStringLiteral("flicking.qml")); + QTest::addColumn<bool>("mouse"); + QTest::addColumn<QPoint>("from"); + QTest::addColumn<QPoint>("to"); + + QTest::newRow("mouse,straight") << true << QPoint(200, 200) << QPoint(200, 100); + QTest::newRow("mouse,diagonal") << true << QPoint(200, 200) << QPoint(250, 100); + QTest::newRow("touch,straight") << false << QPoint(200, 200) << QPoint(200, 100); + QTest::newRow("touch,diagonal") << false << QPoint(200, 200) << QPoint(250, 100); +} + +void tst_Drawer::flickable() +{ + QFETCH(bool, mouse); + QFETCH(QPoint, from); + QFETCH(QPoint, to); + + QQuickApplicationHelper helper(this, QStringLiteral("flickable.qml")); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -908,23 +925,31 @@ void tst_Drawer::flicking() drawer->open(); QVERIFY(drawerOpenedSpy.wait()); - // mouse - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); - for (int y = 200; y > 100; y -= 10) - QTest::mouseMove(window, QPoint(200, y), 1); - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 100)); - QVERIFY(flickable->isFlicking()); - - // reset - flickable->setContentY(0); - QVERIFY(!flickable->isFlicking()); - - // touch - QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(200, 200)); - for (int y = 200; y > 100; y -= 10) - QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(200, y)); - QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(200, 100)); - QVERIFY(flickable->isFlicking()); + if (mouse) + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, from); + else + QTest::touchEvent(window, touchDevice.data()).press(0, from); + + static const int steps = 10; + for (int i = 0; i < steps; ++i) { + int x = i * qAbs(from.x() - to.x()) / steps; + int y = i * qAbs(from.y() - to.y()) / steps; + + if (mouse) + QTest::mouseMove(window, QPoint(x, y)); + else + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(x, y)); + QTest::qWait(1); // avoid infinite velocity + } + + QVERIFY(flickable->isDragging()); + + if (mouse) + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, to); + else + QTest::touchEvent(window, touchDevice.data()).release(0, to); + + QVERIFY(!flickable->isDragging()); } QTEST_MAIN(tst_Drawer) |