diff options
Diffstat (limited to 'tests/auto/quick/qquickflickable')
-rw-r--r-- | tests/auto/quick/qquickflickable/data/nestedStopAtBounds.qml | 37 | ||||
-rw-r--r-- | tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | 71 |
2 files changed, 108 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickflickable/data/nestedStopAtBounds.qml b/tests/auto/quick/qquickflickable/data/nestedStopAtBounds.qml new file mode 100644 index 0000000000..59318e5b95 --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/nestedStopAtBounds.qml @@ -0,0 +1,37 @@ +import QtQuick 2.0 + +Flickable { + id: outer + objectName: "outerFlickable" + width: 400 + height: 400 + contentX: 50 + contentY: 50 + contentWidth: 500 + contentHeight: 500 + flickableDirection: inner.flickableDirection + + Rectangle { + x: 100 + y: 100 + width: 300 + height: 300 + + color: "yellow" + Flickable { + id: inner + objectName: "innerFlickable" + anchors.fill: parent + contentX: 100 + contentY: 100 + contentWidth: 400 + contentHeight: 400 + boundsBehavior: Flickable.StopAtBounds + Rectangle { + anchors.fill: parent + anchors.margins: 100 + color: "blue" + } + } + } +} diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 9645aaaab3..875ade45b8 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -91,6 +91,8 @@ private slots: void cancelOnMouseGrab(); void clickAndDragWhenTransformed(); void flickTwiceUsingTouches(); + void nestedStopAtBounds(); + void nestedStopAtBounds_data(); private: void flickWithTouch(QWindow *window, QTouchDevice *touchDevice); @@ -1308,6 +1310,75 @@ void tst_qquickflickable::flickWithTouch(QWindow *window, QTouchDevice *touchDev QTest::qWait(1); } +void tst_qquickflickable::nestedStopAtBounds_data() +{ + QTest::addColumn<bool>("transpose"); + QTest::addColumn<bool>("invert"); + + QTest::newRow("left") << false << false; + QTest::newRow("right") << false << true; + QTest::newRow("top") << true << false; + QTest::newRow("bottom") << true << true; +} + +void tst_qquickflickable::nestedStopAtBounds() +{ + QFETCH(bool, transpose); + QFETCH(bool, invert); + + QQuickView view; + view.setSource(testFileUrl("nestedStopAtBounds.qml")); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(view.rootObject()); + + QQuickFlickable *outer = qobject_cast<QQuickFlickable*>(view.rootObject()); + QVERIFY(outer); + + QQuickFlickable *inner = outer->findChild<QQuickFlickable*>("innerFlickable"); + QVERIFY(inner); + inner->setFlickableDirection(transpose ? QQuickFlickable::VerticalFlick : QQuickFlickable::HorizontalFlick); + inner->setContentX(invert ? 0 : 100); + inner->setContentY(invert ? 0 : 100); + + const int threshold = qApp->styleHints()->startDragDistance(); + + QPoint position(200, 200); + int &axis = transpose ? position.ry() : position.rx(); + + // drag toward the aligned boundary. Outer flickable dragged. + QTest::mousePress(&view, Qt::LeftButton, 0, position); + QTest::qWait(10); + axis += invert ? threshold * 2 : -threshold * 2; + QTest::mouseMove(&view, position); + axis += invert ? threshold : -threshold; + QTest::mouseMove(&view, position); + QCOMPARE(outer->isDragging(), true); + QCOMPARE(inner->isDragging(), false); + QTest::mouseRelease(&view, Qt::LeftButton, 0, position); + + QVERIFY(!outer->isDragging()); + QTRY_VERIFY(!outer->isMoving()); + + axis = 200; + outer->setContentX(50); + outer->setContentY(50); + + // drag away from the aligned boundary. Inner flickable dragged. + QTest::mousePress(&view, Qt::LeftButton, 0, position); + QTest::qWait(10); + axis += invert ? -threshold * 2 : threshold * 2; + QTest::mouseMove(&view, position); + axis += invert ? -threshold : threshold; + QTest::mouseMove(&view, position); + QCOMPARE(outer->isDragging(), false); + QCOMPARE(inner->isDragging(), true); + QTest::mouseRelease(&view, Qt::LeftButton, 0, position); + + QTRY_VERIFY(!outer->isMoving()); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" |