Merge lp:~zsombi/ubuntu-ui-toolkit/ubuntutestcase-extras into lp:ubuntu-ui-toolkit

Proposed by Zsombor Egri on 2014-04-08
Status: Superseded
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/ubuntutestcase-extras
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 275 lines (+181/-18)
5 files modified
components.api (+2/-0)
modules/Ubuntu/Test/UbuntuTestCase.qml (+69/-1)
modules/Ubuntu/Test/deployment.pri (+6/-1)
tests/unit/runtest.sh (+1/-1)
tests/unit_x11/tst_test/tst_ubuntutestcase.qml (+103/-15)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/ubuntutestcase-extras
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2014-04-08
Tim Peeters 2014-04-08 Pending
Review via email: mp+214675@code.launchpad.net

This proposal has been superseded by a proposal from 2014-04-09.

Commit message

deployment of UbuntuTestCase.qml fixed; Additional functions added.

To post a comment you must log in.
Tim Peeters (tpeeters) wrote :

12 + The function simulates a flick event over an \item. The flick is executed
13 + between \a from and \to points (built using Qt.point()) with a given \a speed

I think \item should be \a item and \to should be \a to.

1002. By Zsombor Egri on 2014-04-08

doc fix

Tim Peeters (tpeeters) wrote :

Why is poinCount = 5 needed? Does a single mouseMove not work as a flick?

Tim Peeters (tpeeters) wrote :

This code can be written a bit nicer:
39 + for (var i = 0; i < pointCount; i++) {
40 + mouseMove(item, from.x + (i + 1) * dx / pointCount, from.y + (i + 1) * dy / pointCount, speed);
41 + }

var dx = (to.x - from.x) / pointCount;
var dy = (to.y - from.y) / pointCount;

for (var i = 1; i <= pointCount; i++) {
  mouseMove(item, from.x + i*dx, from.y + i*dy, speed);
}

Zsombor Egri (zsombi) wrote :

> Why is poinCount = 5 needed? Does a single mouseMove not work as a flick?

No, it doesn't. I took the function btw from the tst_textarea_in_flickable.qml, and that's how we did there. One mouse move only takes a small move, and may not even be recognized.

1003. By Zsombor Egri on 2014-04-08

test cases added to guard added features

Zsombor Egri (zsombi) wrote :

> This code can be written a bit nicer:
> 39 + for (var i = 0; i < pointCount; i++) {
> 40 + mouseMove(item, from.x + (i + 1) * dx / pointCount, from.y + (i + 1)
> * dy / pointCount, speed);
> 41 + }
>
>
> var dx = (to.x - from.x) / pointCount;
> var dy = (to.y - from.y) / pointCount;
>
> for (var i = 1; i <= pointCount; i++) {
> mouseMove(item, from.x + i*dx, from.y + i*dy, speed);
> }

Yep, used. I copied the code as was in the test. I modified the API and implementation to be closer to mouseXXX() functions. Please check it once more.

1004. By Zsombor Egri on 2014-04-08

cleanup

Zsombor Egri (zsombi) wrote :

> > Why is poinCount = 5 needed? Does a single mouseMove not work as a flick?
>
> No, it doesn't. I took the function btw from the
> tst_textarea_in_flickable.qml, and that's how we did there. One mouse move
> only takes a small move, and may not even be recognized.

So: we need at least two mouse moves to trigger a flick on a Flickable. I defaulted the implementation to 5 points (as in mouseDrag() function) and it can be altered by the steps parameter - the bigger the steps number is the longer the flick will be.

1005. By Zsombor Egri on 2014-04-08

api file updated

PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1006. By Zsombor Egri on 2014-04-09

review comments addressed

1007. By Zsombor Egri on 2014-04-09

typo fix

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components.api'
2--- components.api 2014-03-14 16:11:00 +0000
3+++ components.api 2014-04-08 16:54:23 +0000
4@@ -592,6 +592,8 @@
5 function findChild(obj,objectName)
6 function findInvisibleChild(obj,objectName)
7 function mouseMoveSlowly(item,x,y,dx,dy,steps,stepdelay)
8+ function flick(item, x, y, dx, dy, pressTimeout, steps, button, modifiers, delay)
9+ function mouseLongPress(item, x, y, button, modifiers, delay)
10 function tryCompareFunction(func, expectedResult, timeout)
11 plugins.qmltypes
12 name: "InverseMouseAreaType"
13
14=== modified file 'modules/Ubuntu/Test/UbuntuTestCase.qml'
15--- modules/Ubuntu/Test/UbuntuTestCase.qml 2014-02-25 12:36:27 +0000
16+++ modules/Ubuntu/Test/UbuntuTestCase.qml 2014-04-08 16:54:23 +0000
17@@ -87,7 +87,75 @@
18 }
19 }
20
21- /*!
22+ /*!
23+ \qmlmethod UbuntuTestCase::flick(item, x, y, dx, dy, pressTimeout = -1, steps = -1, button = Qt.LeftButton, modifiers = Qt.NoModifiers, delay = -1)
24+
25+ The function produces a flick event when executed on Flickables. When used
26+ on other components it provides the same functionality as \l mouseDrag()
27+ function. The optional \a pressTimeout parameter can be used to introduce
28+ a small delay between the mouse press and the first mouse move.
29+
30+ The default flick velocity is built up using 5 move points. This can be altered
31+ by setting a positive value to \a steps parameter. The bigger the number the
32+ longer the flick will be.
33+
34+ \note The function can be used to select a text in a TextField or TextArea by
35+ specifying at least 400 millisecods to \a pressTimeout.
36+ */
37+ function flick(item, x, y, dx, dy, pressTimeout, steps, button, modifiers, delay) {
38+ if (item === undefined || item.x === undefined || item.y === undefined)
39+ return
40+ if (button === undefined)
41+ button = Qt.LeftButton
42+ if (modifiers === undefined)
43+ modifiers = Qt.NoModifier
44+ var from = Qt.point(x, y);
45+ var to = Qt.point(x + dx, y + dy);
46+ if (steps === undefined || steps <= 0)
47+ steps = 4;
48+ // make sure we have at least two move steps so the flick will be sensed
49+ steps += 1;
50+ if (delay === undefined)
51+ delay = -1;
52+
53+ var ddx = (to.x - from.x) / steps;
54+ var ddy = (to.y - from.y) / steps;
55+
56+ mousePress(item, from.x, from.y, button, modifiers, delay);
57+ if (pressTimeout !== undefined && pressTimeout > 0) {
58+ wait(pressTimeout);
59+ }
60+ for (var i = 1; i <= steps; i++) {
61+ // mouse moves are all processed immediately, without delay in between events
62+ mouseMove(item, from.x + i * ddx, from.y + i * ddy, -1, button);
63+ }
64+ mouseRelease(item, to.x, to.y, button, modifiers, delay);
65+ // empty event buffer
66+ wait(200);
67+ }
68+
69+ /*!
70+ \qmlmethod UbuntuTestCase::mouseLongPress(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifiers, delay = -1)
71+
72+ Simulates a long press on a mouse \a button with an optional \a modifier
73+ on an \a item. The position is defined by \a x and \a y. If \a delay is
74+ specified, the test will wait the specified amount of milliseconds before
75+ the press.
76+
77+ The position given by \a x and \a y is transformed from the co-ordinate
78+ system of \a item into window co-ordinates and then delivered.
79+ If \a item is obscured by another item, or a child of \a item occupies
80+ that position, then the event will be delivered to the other item instead.
81+
82+ \sa mouseRelease(), mouseClick(), mouseDoubleClick(), mouseMove(), mouseDrag(), mouseWheel()
83+ */
84+ function mouseLongPress(item, x, y, button, modifiers, delay) {
85+ mousePress(item, x, y, button, modifiers, delay);
86+ // the delay is taken from QQuickMouseArea
87+ wait(800);
88+ }
89+
90+ /*!
91 Keeps executing a given parameter-less function until it returns the given
92 expected result or the timemout is reached (in which case a test failure
93 is generated)
94
95=== modified file 'modules/Ubuntu/Test/deployment.pri'
96--- modules/Ubuntu/Test/deployment.pri 2014-01-17 12:30:05 +0000
97+++ modules/Ubuntu/Test/deployment.pri 2014-04-08 16:54:23 +0000
98@@ -7,9 +7,14 @@
99 # make found deployables visible in Qt Creator
100 OTHER_FILES += $$QMLDIR_FILE
101
102+QML_FILES = $$system(ls *.qml)
103+JS_FILES = $$system(ls *.js)
104+
105 # define deployment for found deployables
106 qmldir_file.path = $$installPath
107 qmldir_file.files = $$QMLDIR_FILE
108+qml_files.path = $$installPath
109+qml_files.files = $$QML_FILES
110 js_files.path = $$installPath
111 js_files.files = $$JS_FILES
112
113@@ -20,4 +25,4 @@
114 # https://bugreports.qt-project.org/browse/QTBUG-36243
115 plugins_qmltypes.extra = $$[QT_INSTALL_BINS]/qmlplugindump -notrelocatable Ubuntu.Test 0.1 ../../ 2>/dev/null > $(INSTALL_ROOT)/$$installPath/plugins.qmltypes
116
117-INSTALLS += qmldir_file plugins_qmltypes
118+INSTALLS += qmldir_file plugins_qmltypes qml_files js_files
119
120=== modified file 'tests/unit/runtest.sh'
121--- tests/unit/runtest.sh 2014-03-31 18:26:46 +0000
122+++ tests/unit/runtest.sh 2014-04-08 16:54:23 +0000
123@@ -33,7 +33,7 @@
124 if [ $_TARGET != $_TESTFILE ]; then
125 _CMD="$_CMD -input $_TESTFILE"
126 fi
127- _CMD="$_CMD -maxwarnings 4"
128+ _CMD="$_CMD -maxwarnings 40"
129 }
130
131 function execute_test_cmd {
132
133=== modified file 'tests/unit_x11/tst_test/tst_ubuntutestcase.qml'
134--- tests/unit_x11/tst_test/tst_ubuntutestcase.qml 2014-02-13 10:27:14 +0000
135+++ tests/unit_x11/tst_test/tst_ubuntutestcase.qml 2014-04-08 16:54:23 +0000
136@@ -23,30 +23,57 @@
137 width: 800
138 height: 600
139
140- MouseArea {
141- id: mouseArea
142- objectName: "myMouseArea"
143- anchors.fill: parent
144- hoverEnabled: true
145- property int testX : 0
146- property int testY : 0
147- property int steps : 0
148+ Column {
149+ anchors.fill: parent
150+ MouseArea {
151+ id: mouseArea
152+ objectName: "myMouseArea"
153+ width: parent.width
154+ height: 300
155+ hoverEnabled: true
156+ acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
157+ property int testX : 0
158+ property int testY : 0
159+ property int steps : 0
160
161- onPositionChanged: {
162- testX = mouseX;
163- testY = mouseY;
164- steps++;
165- }
166+ onPositionChanged: {
167+ testX = mouseX;
168+ testY = mouseY;
169+ steps++;
170+ }
171+ }
172+ Flickable {
173+ id: flicker
174+ width: parent.width
175+ height: 400
176+ contentWidth: rect.width
177+ contentHeight: rect.height
178+ clip: true
179+ Rectangle {
180+ id: rect
181+ color: "blue"
182+ width: 1000
183+ height: 1000
184+ }
185+ }
186 }
187
188 UbuntuTestCase {
189 name: "TestTheUbuntuTestCase"
190 when: windowShown
191
192+ function init() {
193+ mouseArea.steps = 0;
194+ }
195+ function cleanup() {
196+ movementSpy.clear();
197+ longPressSpy.clear();
198+ }
199+
200 function test_mouseMoveSlowly() {
201- mouseMoveSlowly(root,0,0,800,600,10,100);
202+ mouseMoveSlowly(root,0,0,800,300,10,100);
203 compare(mouseArea.testX,800);
204- compare(mouseArea.testY,600);
205+ compare(mouseArea.testY,300);
206 compare(mouseArea.steps,10);
207 }
208
209@@ -58,5 +85,66 @@
210 child = findChild(root,"NoSuchChildHere");
211 compare(child===null,true,"When there is no child, function should return null");
212 }
213+
214+ SignalSpy {
215+ id: longPressSpy
216+ target: mouseArea
217+ signalName: "onPressAndHold"
218+ }
219+
220+ function test_longPress_left() {
221+ longPressSpy.clear();
222+ mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2);
223+ longPressSpy.wait();
224+ // cleanup
225+ mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2);
226+ }
227+
228+ function test_longPress_right() {
229+ longPressSpy.clear();
230+ mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.RightButton);
231+ longPressSpy.wait();
232+ // cleanup
233+ mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.RightButton);
234+ }
235+
236+ function test_longPress_middle() {
237+ longPressSpy.clear();
238+ mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.MiddleButton);
239+ longPressSpy.wait();
240+ // cleanup
241+ mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.MiddleButton);
242+ }
243+
244+ SignalSpy {
245+ id: movementSpy
246+ target: flicker
247+ signalName: "onMovementEnded"
248+ }
249+
250+ function test_flick_default() {
251+ flick(flicker, 0, 0, flicker.width, flicker.height);
252+ movementSpy.wait();
253+ }
254+ function test_flick_long() {
255+ flick(flicker, 0, 0, flicker.width, flicker.height, -1, 10);
256+ movementSpy.wait();
257+ }
258+ function test_flick_short() {
259+ flick(flicker, 0, 0, flicker.width, flicker.height, -1, 1);
260+ movementSpy.wait();
261+ }
262+ function test_flick_pressTimeout() {
263+ flick(flicker, 0, 0, flicker.width, flicker.height, 400);
264+ movementSpy.wait();
265+ }
266+ function test_flick_pressTimeout_short() {
267+ flick(flicker, flicker.width, flicker.height, -flicker.width, -flicker.height, 400, 1);
268+ movementSpy.wait();
269+ }
270+ function test_flick_pressTimeout_long() {
271+ flick(flicker, flicker.width, flicker.height, -flicker.width, -flicker.height, 400, 100);
272+ movementSpy.wait();
273+ }
274 }
275 }

Subscribers

People subscribed via source and target branches

to status/vote changes: