diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-04-28 10:38:52 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-05-15 17:22:01 +0000 |
commit | 80e5e6976afe4425cc8fd22c010fcf039c5b4b91 (patch) | |
tree | 132f843b11969321d10681f1200fa28a183b1b7a /tests/auto/quick/pointerhandlers | |
parent | 2c6d20245cfaaa8d62874df98beb49c99d0067bc (diff) |
tst_flickableinterop: test buttons with all gesturePolicy values
Change-Id: If3d9e10bb54fc75a7e72bc6367de3e083611a45f
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/quick/pointerhandlers')
4 files changed, 70 insertions, 12 deletions
diff --git a/tests/auto/quick/pointerhandlers/flickableinterop/data/Slider.qml b/tests/auto/quick/pointerhandlers/flickableinterop/data/Slider.qml index 35e7ee2177..d01bcf74ed 100644 --- a/tests/auto/quick/pointerhandlers/flickableinterop/data/Slider.qml +++ b/tests/auto/quick/pointerhandlers/flickableinterop/data/Slider.qml @@ -72,7 +72,7 @@ Item { anchors.horizontalCenterOffset: 1 radius: 5 color: "#4400FFFF" - opacity: dragHandler.active || tapFlash.running ? 1 : 0 + opacity: tap.isPressed || tapFlash.running ? 1 : 0 FlashAnimation on visible { id: tapFlash } diff --git a/tests/auto/quick/pointerhandlers/flickableinterop/data/TapHandlerButton.qml b/tests/auto/quick/pointerhandlers/flickableinterop/data/TapHandlerButton.qml index af9b906861..18a67eb094 100644 --- a/tests/auto/quick/pointerhandlers/flickableinterop/data/TapHandlerButton.qml +++ b/tests/auto/quick/pointerhandlers/flickableinterop/data/TapHandlerButton.qml @@ -95,6 +95,12 @@ Rectangle { x: tap.scenePressPos.x - radius y: tap.scenePressPos.y - radius opacity: 0.25 - Component.onCompleted: parent = root.parent + Component.onCompleted: { + // get on top of all the buttons + var par = root.parent; + while (par.parent) + par = par.parent; + parent = par; + } } } diff --git a/tests/auto/quick/pointerhandlers/flickableinterop/data/flickableWithHandlers.qml b/tests/auto/quick/pointerhandlers/flickableinterop/data/flickableWithHandlers.qml index 7799dd0ec3..833fef0a81 100644 --- a/tests/auto/quick/pointerhandlers/flickableinterop/data/flickableWithHandlers.qml +++ b/tests/auto/quick/pointerhandlers/flickableinterop/data/flickableWithHandlers.qml @@ -66,14 +66,22 @@ Rectangle { Column { spacing: 6 TapHandlerButton { - label: "TapHandler" - objectName: "Button 1" + objectName: "DragThreshold" + label: "DragThreshold" + gesturePolicy: TapHandler.DragThreshold } TapHandlerButton { - label: "TapHandler" - objectName: "Button 2" + objectName: "WithinBounds" + label: "WithinBounds" + gesturePolicy: TapHandler.WithinBounds + } + TapHandlerButton { + objectName: "ReleaseWithinBounds" + label: "ReleaseWithinBounds" + gesturePolicy: TapHandler.ReleaseWithinBounds // the default } } } } } + diff --git a/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp b/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp index 93b6d27f21..c8fe6052fb 100644 --- a/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp +++ b/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp @@ -59,9 +59,13 @@ public: private slots: void initTestCase(); + void touchTapButton_data(); void touchTapButton(); + void touchDragFlickableBehindButton_data(); void touchDragFlickableBehindButton(); + void mouseClickButton_data(); void mouseClickButton(); + void mouseDragFlickableBehindButton_data(); void mouseDragFlickableBehindButton(); void touchDragSlider(); void touchDragFlickableBehindSlider(); @@ -94,6 +98,14 @@ void tst_FlickableInterop::initTestCase() QQmlDataTest::initTestCase(); } +void tst_FlickableInterop::touchTapButton_data() +{ + QTest::addColumn<QString>("buttonName"); + QTest::newRow("DragThreshold") << QStringLiteral("DragThreshold"); + QTest::newRow("WithinBounds") << QStringLiteral("WithinBounds"); + QTest::newRow("ReleaseWithinBounds") << QStringLiteral("ReleaseWithinBounds"); +} + void tst_FlickableInterop::touchTapButton() { const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); @@ -101,7 +113,9 @@ void tst_FlickableInterop::touchTapButton() createView(windowPtr, "flickableWithHandlers.qml"); QQuickView * window = windowPtr.data(); - QQuickItem *button = window->rootObject()->findChild<QQuickItem*>("Button 1"); + QFETCH(QString, buttonName); + + QQuickItem *button = window->rootObject()->findChild<QQuickItem*>(buttonName); QVERIFY(button); QSignalSpy tappedSpy(button, SIGNAL(tapped())); @@ -130,6 +144,14 @@ void tst_FlickableInterop::touchTapButton() QCOMPARE(tappedSpy.count(), 2); } +void tst_FlickableInterop::touchDragFlickableBehindButton_data() +{ + QTest::addColumn<QString>("buttonName"); + QTest::newRow("DragThreshold") << QStringLiteral("DragThreshold"); + QTest::newRow("WithinBounds") << QStringLiteral("WithinBounds"); + QTest::newRow("ReleaseWithinBounds") << QStringLiteral("ReleaseWithinBounds"); +} + void tst_FlickableInterop::touchDragFlickableBehindButton() { const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); @@ -137,14 +159,14 @@ void tst_FlickableInterop::touchDragFlickableBehindButton() createView(windowPtr, "flickableWithHandlers.qml"); QQuickView * window = windowPtr.data(); - QQuickItem *button = window->rootObject()->findChild<QQuickItem*>("Button 1"); + QFETCH(QString, buttonName); + + QQuickItem *button = window->rootObject()->findChild<QQuickItem*>(buttonName); QVERIFY(button); QQuickFlickable *flickable = window->rootObject()->findChild<QQuickFlickable*>(); QVERIFY(flickable); QSignalSpy tappedSpy(button, SIGNAL(tapped())); - // Button is no longer pressed if touchpoint goes beyond dragThreshold, - // because Flickable steals the grab tappedSpy.clear(); QPoint p1 = button->mapToScene(QPointF(20, 20)).toPoint(); QTest::touchEvent(window, touchDevice).press(1, p1, window); @@ -155,6 +177,8 @@ void tst_FlickableInterop::touchDragFlickableBehindButton() QQuickTouchUtils::flush(window); QVERIFY(button->property("pressed").toBool()); int i = 0; + // Start dragging; eventually when the touchpoint goes beyond dragThreshold, + // Button is no longer pressed because Flickable steals the grab for (; i < 100 && !flickable->isMoving(); ++i) { p1 += QPoint(1, 0); QTest::touchEvent(window, touchDevice).move(1, p1, window); @@ -170,6 +194,14 @@ void tst_FlickableInterop::touchDragFlickableBehindButton() QCOMPARE(tappedSpy.count(), 0); } +void tst_FlickableInterop::mouseClickButton_data() +{ + QTest::addColumn<QString>("buttonName"); + QTest::newRow("DragThreshold") << QStringLiteral("DragThreshold"); + QTest::newRow("WithinBounds") << QStringLiteral("WithinBounds"); + QTest::newRow("ReleaseWithinBounds") << QStringLiteral("ReleaseWithinBounds"); +} + void tst_FlickableInterop::mouseClickButton() { const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); @@ -177,7 +209,9 @@ void tst_FlickableInterop::mouseClickButton() createView(windowPtr, "flickableWithHandlers.qml"); QQuickView * window = windowPtr.data(); - QQuickItem *button = window->rootObject()->findChild<QQuickItem*>("Button 1"); + QFETCH(QString, buttonName); + + QQuickItem *button = window->rootObject()->findChild<QQuickItem*>(buttonName); QVERIFY(button); QSignalSpy tappedSpy(button, SIGNAL(tapped())); @@ -201,6 +235,14 @@ void tst_FlickableInterop::mouseClickButton() QCOMPARE(tappedSpy.count(), 2); } +void tst_FlickableInterop::mouseDragFlickableBehindButton_data() +{ + QTest::addColumn<QString>("buttonName"); + QTest::newRow("DragThreshold") << QStringLiteral("DragThreshold"); + QTest::newRow("WithinBounds") << QStringLiteral("WithinBounds"); + QTest::newRow("ReleaseWithinBounds") << QStringLiteral("ReleaseWithinBounds"); +} + void tst_FlickableInterop::mouseDragFlickableBehindButton() { const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); @@ -208,7 +250,9 @@ void tst_FlickableInterop::mouseDragFlickableBehindButton() createView(windowPtr, "flickableWithHandlers.qml"); QQuickView * window = windowPtr.data(); - QQuickItem *button = window->rootObject()->findChild<QQuickItem*>("Button 1"); + QFETCH(QString, buttonName); + + QQuickItem *button = window->rootObject()->findChild<QQuickItem*>(buttonName); QVERIFY(button); QQuickFlickable *flickable = window->rootObject()->findChild<QQuickFlickable*>(); QVERIFY(flickable); |