aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qmltest
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2019-10-30 16:19:32 +0100
committerMitch Curtis <mitch.curtis@qt.io>2019-11-14 13:57:01 +0100
commit02ffe50af41526f604ae61d41bf2150037d67473 (patch)
tree43f1aec0c61f43c6961e051f96f2b3a3599403c8 /tests/auto/qmltest
parent35fdf3a7b77a79806d0b5d9632b5066e3618adf5 (diff)
mouseDrag(): never drag along an axis that wasn't requested
mouseDrag() should not drag along an axis if the distance passed in for that axis was 0. Doing so can interfere with tests for an item that e.g. handles horizontal flicks which is within e.g. a Flickable that handles vertical flicks. This was seen with SwipeDelegate auto tests, where the delegates handles horizontal swipes within a vertical ListView. Change-Id: I8fee567d59c53bdc4cbfe1d42ae0592e324bd2f6 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/qmltest')
-rw-r--r--tests/auto/qmltest/events/tst_drag.qml132
1 files changed, 132 insertions, 0 deletions
diff --git a/tests/auto/qmltest/events/tst_drag.qml b/tests/auto/qmltest/events/tst_drag.qml
index ae77247a41..2653848adc 100644
--- a/tests/auto/qmltest/events/tst_drag.qml
+++ b/tests/auto/qmltest/events/tst_drag.qml
@@ -113,6 +113,43 @@ Rectangle{
}
}
+ Component {
+ id: nestedFlickableComponent
+
+ Flickable {
+ objectName: "outerFlickable"
+ width: parent.width
+ height: parent.height
+ contentWidth: 400
+ contentHeight: 400
+
+ property alias innerFlickable: innerFlickable
+
+ Flickable {
+ id: innerFlickable
+ objectName: "innerFlickable"
+ width: parent.width
+ height: parent.height
+ contentWidth: 400
+ contentHeight: 400
+
+ Rectangle {
+ width: 400
+ height: 400
+ gradient: Gradient {
+ GradientStop { position: 0; color: "salmon" }
+ GradientStop { position: 0; color: "navajowhite" }
+ }
+ }
+ }
+ }
+ }
+
+ Component {
+ id: signalSpyComponent
+ SignalSpy {}
+ }
+
TestCase {
name:"mouserelease"
when:windowShown
@@ -163,5 +200,100 @@ Rectangle{
compare(spyX.count, 0)
compare(spyY.count, 1)
}
+
+ function test_dragAxis_data() {
+ return [
+ { tag: "horizontal" },
+ { tag: "vertical" }
+ ]
+ }
+
+ // mouseDrag() should not drag along an axis if the distance passed in for
+ // that axis was 0. Doing so can interfere with tests for an item that e.g.
+ // handles horizontal flicks which is within e.g. a Flickable that handles
+ // vertical flicks.
+ function test_dragAxis(data) {
+ let horizontal = data.tag === "horizontal"
+
+ let outerFlickable = createTemporaryObject(nestedFlickableComponent, root)
+ verify(outerFlickable)
+ // We want the outer flickable to use the opposite flick direction of the inner one,
+ // as the inner one has the direction that we're interested in testing.
+ outerFlickable.flickableDirection = horizontal ? Flickable.VerticalFlick : Flickable.HorizontalFlick
+
+ let innerFlickable = outerFlickable.innerFlickable
+ verify(innerFlickable)
+ let horizontalFlickable = null
+ let verticalFlickable = null
+ if (horizontal) {
+ innerFlickable.flickableDirection = Flickable.HorizontalFlick
+ horizontalFlickable = innerFlickable
+ verticalFlickable = outerFlickable
+ } else {
+ innerFlickable.flickableDirection = Flickable.VerticalFlick
+ horizontalFlickable = outerFlickable
+ verticalFlickable = innerFlickable
+ }
+
+ let movingHorizontallySpy = createTemporaryObject(signalSpyComponent, root,
+ { target: horizontalFlickable, signalName: "movingHorizontallyChanged" })
+ verify(movingHorizontallySpy)
+ verify(movingHorizontallySpy.valid)
+
+ let movingVerticallySpy = createTemporaryObject(signalSpyComponent, root,
+ { target: verticalFlickable, signalName: "movingVerticallyChanged" })
+ verify(movingVerticallySpy)
+ verify(movingVerticallySpy.valid)
+
+ let flickingHorizontallySpy = createTemporaryObject(signalSpyComponent, root,
+ { target: horizontalFlickable, signalName: "flickingHorizontallyChanged" })
+ verify(flickingHorizontallySpy)
+ verify(flickingHorizontallySpy.valid)
+
+ let flickingVerticallySpy = createTemporaryObject(signalSpyComponent, root,
+ { target: verticalFlickable, signalName: "flickingVerticallyChanged" })
+ verify(flickingVerticallySpy)
+ verify(flickingVerticallySpy.valid)
+
+ let contentXSpy = createTemporaryObject(signalSpyComponent, root,
+ { target: horizontalFlickable, signalName: "contentXChanged" })
+ verify(contentXSpy)
+ verify(contentXSpy.valid)
+
+ let contentYSpy = createTemporaryObject(signalSpyComponent, root,
+ { target: verticalFlickable, signalName: "contentYChanged" })
+ verify(contentYSpy)
+ verify(contentYSpy.valid)
+
+ // Dragging only horizontally should not result in movement on the Y axis, and vice versa.
+ let horizontalDragDistance = horizontal ? innerFlickable.width - 10 : 0
+ let verticalDragDistance = horizontal ? 0 : innerFlickable.height - 10
+ mouseDrag(innerFlickable, 10, 10, horizontalDragDistance, verticalDragDistance)
+
+ // Wait for it to stop moving.
+ if (horizontal) {
+ tryCompare(horizontalFlickable, "movingHorizontally", false)
+ tryCompare(horizontalFlickable, "flickingHorizontally", false)
+ } else {
+ tryCompare(verticalFlickable, "movingVertically", false)
+ tryCompare(verticalFlickable, "flickingVertically", false)
+ }
+
+ // 2 because it should change to true then false.
+ compare(movingHorizontallySpy.count, horizontal ? 2 : 0)
+ compare(movingVerticallySpy.count, horizontal ? 0 : 2)
+ compare(flickingHorizontallySpy.count, horizontal ? 2 : 0)
+ compare(flickingVerticallySpy.count, horizontal ? 0 : 2)
+
+ if (horizontal)
+ verify(contentXSpy.count > 0)
+ else
+ compare(contentXSpy.count, 0)
+
+ if (horizontal)
+ compare(contentYSpy.count, 0)
+ else
+ verify(contentYSpy.count > 0)
+ }
}
}