From 54f9fe5d41bc4a66d03c9846c1990958518d8623 Mon Sep 17 00:00:00 2001 From: Daniel d'Andrada Date: Tue, 18 Dec 2012 09:47:57 -0200 Subject: [PATCH] Flickable: Test case for flicking twice using touches When you flick twice in rapid succession, in the same direction, the expected behavior is for flickable to be moving quite fast in the direction of the flicks. This test check for a bug where when you flick using touch events instead of mouse ones, the second flick causes Flickable to immediately halt. Change-Id: I430515d82499b904a1d2e23402b753873490a2d9 Reviewed-by: Andras Becsi --- tests/auto/quick/qquickflickable/data/longList.qml | 22 ++++++ .../quick/qquickflickable/tst_qquickflickable.cpp | 70 ++++++++++++++++++++ 2 files changed, 92 insertions(+), 0 deletions(-) create mode 100644 tests/auto/quick/qquickflickable/data/longList.qml diff --git a/tests/auto/quick/qquickflickable/data/longList.qml b/tests/auto/quick/qquickflickable/data/longList.qml new file mode 100644 index 0000000..424f289 --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/longList.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 + +Flickable { + id: flick + + width: 200 + height: 480 + + contentHeight: 100 * 100 + + Grid { + columns: 1 + Repeater { + model: 100 + Rectangle { + width: flick.width + height: 100 + color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1) + } + } + } +} diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 66071e6..6a85b4d 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -53,6 +53,8 @@ #include "../shared/viewtestutil.h" #include "../shared/visualtestutil.h" +#include + using namespace QQuickViewTestUtil; using namespace QQuickVisualTestUtil; @@ -88,8 +90,10 @@ private slots: void margins(); void cancelOnMouseGrab(); void clickAndDragWhenTransformed(); + void flickTwiceUsingTouches(); private: + void flickWithTouch(QWindow *window, QTouchDevice *touchDevice); QQmlEngine engine; }; @@ -1241,6 +1245,72 @@ void tst_qquickflickable::clickAndDragWhenTransformed() delete view; } +void tst_qquickflickable::flickTwiceUsingTouches() +{ + QTouchDevice *touchDevice = new QTouchDevice; + touchDevice->setName("Fake Touchscreen"); + touchDevice->setType(QTouchDevice::TouchScreen); + touchDevice->setCapabilities(QTouchDevice::Position); + QWindowSystemInterface::registerTouchDevice(touchDevice); + + QQuickView *window = new QQuickView; + window->setSource(testFileUrl("longList.qml")); + window->show(); + window->requestActivate(); + QTest::qWaitForWindowActive(window); + QVERIFY(window->rootObject() != 0); + + QQuickFlickable *flickable = qobject_cast(window->rootObject()); + QVERIFY(flickable != 0); + + QCOMPARE(flickable->contentY(), 0.0f); + flickWithTouch(window, touchDevice); + + qreal contentYAfterFirstFlick = flickable->contentY(); + qDebug() << "contentYAfterFirstFlick " << contentYAfterFirstFlick; + QVERIFY(contentYAfterFirstFlick > 50.0f); + + flickWithTouch(window, touchDevice); + + // In the original bug, that second flick would cause Flickable to halt immediately + qreal contentYAfterSecondFlick = flickable->contentY(); + qDebug() << "contentYAfterSecondFlick " << contentYAfterSecondFlick; + QVERIFY(contentYAfterSecondFlick > (contentYAfterFirstFlick + 80.0f)); + + delete window; +} + +void tst_qquickflickable::flickWithTouch(QWindow *window, QTouchDevice *touchDevice) +{ + QTest::touchEvent(window, touchDevice) + .press(0, QPoint(100, 400), window); + QTest::qWait(1); + QTest::touchEvent(window, touchDevice) + .move(0, QPoint(100, 380), window); + QTest::qWait(1); + QTest::touchEvent(window, touchDevice) + .move(0, QPoint(100, 360), window); + QTest::qWait(1); + QTest::touchEvent(window, touchDevice) + .move(0, QPoint(100, 340), window); + QTest::qWait(1); + QTest::touchEvent(window, touchDevice) + .move(0, QPoint(100, 320), window); + QTest::qWait(1); + QTest::touchEvent(window, touchDevice) + .move(0, QPoint(100, 300), window); + QTest::qWait(1); + QTest::touchEvent(window, touchDevice) + .move(0, QPoint(100, 280), window); + QTest::qWait(1); + QTest::touchEvent(window, touchDevice) + .move(0, QPoint(100, 260), window); + QTest::qWait(1); + QTest::touchEvent(window, touchDevice) + .release(0, QPoint(100, 240), window); + QTest::qWait(1); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" -- 1.7.2.5