aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals@canonical.com>2015-01-09 10:49:47 +0100
committerAlbert Astals Cid <albert.astals@canonical.com>2015-01-09 15:34:13 +0100
commitb40a2a881291b3eaea4b4834a162091537e6a34e (patch)
tree747f9d081a364fbaefb93bda9e38bd2ce14ebfaf /src/imports
parent5607810f4ee67343c82e91c78620a27ebdd6a983 (diff)
Test: make mouse press, release, click and double click default to the center of the item
Most of the times you just want to act on the item not caring the position. This helps for cleaner test code Change-Id: I0e8a4919c503e3fd6dee60e1bd937ac57622279f Reviewed-by: Simon Hausmann <simon.hausmann@digia.com> Reviewed-by: Christopher Adams <chris.adams@jollamobile.com> Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/testlib/TestCase.qml34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 5366748082..8425b0641c 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -934,12 +934,13 @@ Item {
}
/*!
- \qmlmethod TestCase::mousePress(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
+ \qmlmethod TestCase::mousePress(item, x = item.width / 2, y = item.height / 2, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
Simulates pressing a mouse \a button with an optional \a modifier
- on an \a item. The position is defined by \a x and \a y. If \a delay is
- specified, the test will wait for the specified amount of milliseconds
- before the press.
+ on an \a item. The position is defined by \a x and \a y.
+ If \a x or \a y are not defined the position will be the center of \a item.
+ If \a delay is specified, the test will wait for the specified amount of
+ milliseconds before the press.
The position given by \a x and \a y is transformed from the co-ordinate
system of \a item into window co-ordinates and then delivered.
@@ -955,15 +956,20 @@ Item {
modifiers = Qt.NoModifier
if (delay == undefined)
delay = -1
+ if (x === undefined)
+ x = item.width / 2
+ if (y === undefined)
+ y = item.height / 2
if (!qtest_events.mousePress(item, x, y, button, modifiers, delay))
qtest_fail("window not shown", 2)
}
/*!
- \qmlmethod TestCase::mouseRelease(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
+ \qmlmethod TestCase::mouseRelease(item, x = item.width / 2, y = item.height / 2, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
Simulates releasing a mouse \a button with an optional \a modifier
on an \a item. The position of the release is defined by \a x and \a y.
+ If \a x or \a y are not defined the position will be the center of \a item.
If \a delay is specified, the test will wait for the specified amount of
milliseconds before releasing the button.
@@ -981,6 +987,10 @@ Item {
modifiers = Qt.NoModifier
if (delay == undefined)
delay = -1
+ if (x === undefined)
+ x = item.width / 2
+ if (y === undefined)
+ y = item.height / 2
if (!qtest_events.mouseRelease(item, x, y, button, modifiers, delay))
qtest_fail("window not shown", 2)
}
@@ -1035,10 +1045,11 @@ Item {
}
/*!
- \qmlmethod TestCase::mouseClick(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
+ \qmlmethod TestCase::mouseClick(item, x = item.width / 2, y = item.height / 2, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
Simulates clicking a mouse \a button with an optional \a modifier
on an \a item. The position of the click is defined by \a x and \a y.
+ If \a x and \a y are not defined the position will be the center of \a item.
If \a delay is specified, the test will wait for the specified amount of
milliseconds before pressing and before releasing the button.
@@ -1056,15 +1067,20 @@ Item {
modifiers = Qt.NoModifier
if (delay == undefined)
delay = -1
+ if (x === undefined)
+ x = item.width / 2
+ if (y === undefined)
+ y = item.height / 2
if (!qtest_events.mouseClick(item, x, y, button, modifiers, delay))
qtest_fail("window not shown", 2)
}
/*!
- \qmlmethod TestCase::mouseDoubleClick(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
+ \qmlmethod TestCase::mouseDoubleClick(item, x = item.width / 2, y = item.height / 2, button = Qt.LeftButton, modifiers = Qt.NoModifier, delay = -1)
Simulates double-clicking a mouse \a button with an optional \a modifier
on an \a item. The position of the click is defined by \a x and \a y.
+ If \a x and \a y are not defined the position will be the center of \a item.
If \a delay is specified, the test will wait for the specified amount of
milliseconds before pressing and before releasing the button.
@@ -1082,6 +1098,10 @@ Item {
modifiers = Qt.NoModifier
if (delay == undefined)
delay = -1
+ if (x === undefined)
+ x = item.width / 2
+ if (y === undefined)
+ y = item.height / 2
if (!qtest_events.mouseDoubleClick(item, x, y, button, modifiers, delay))
qtest_fail("window not shown", 2)
}