Merge lp:~zsombi/ubuntu-ui-toolkit/ubuntutestcase-extras into lp:ubuntu-ui-toolkit/staging
- ubuntutestcase-extras
- Merge into staging
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Tim Peeters | ||||
Approved revision: | 1007 | ||||
Merged at revision: | 1002 | ||||
Proposed branch: | lp:~zsombi/ubuntu-ui-toolkit/ubuntutestcase-extras | ||||
Merge into: | lp:ubuntu-ui-toolkit/staging | ||||
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 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Tim Peeters | Approve | ||
Review via email: mp+214927@code.launchpad.net |
This proposal supersedes a proposal from 2014-04-08.
Commit message
Flick and mouse long press simulation added to UbuntuTestCase.
Description of the change
Tim Peeters (tpeeters) wrote : Posted in a previous version of this proposal | # |
Tim Peeters (tpeeters) wrote : Posted in a previous version of this proposal | # |
Why is poinCount = 5 needed? Does a single mouseMove not work as a flick?
Tim Peeters (tpeeters) wrote : Posted in a previous version of this proposal | # |
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 : Posted in a previous version of this proposal | # |
> 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_
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:1001
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Zsombor Egri (zsombi) wrote : Posted in a previous version of this proposal | # |
> 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.
Zsombor Egri (zsombi) wrote : Posted in a previous version of this proposal | # |
> > 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_
> 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.
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:1002
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:1005
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Tim Peeters (tpeeters) wrote : | # |
53 + var ddx = (to.x - from.x) / steps;
54 + var ddy = (to.y - from.y) / steps;
You don't need to compute "to" anymore. Just use ddx = dx / steps.
Tim Peeters (tpeeters) wrote : | # |
"from" is also not needed. You can use x and y.
You only use "to" here:
64 + mouseRelease(item, to.x, to.y, button, modifiers, delay);
but there you can easily say x+dx, y+dy.
Tim Peeters (tpeeters) wrote : | # |
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.
Can you add something like this?
"When a negative value is given, the default of 5 move points will be used."
Tim Peeters (tpeeters) wrote : | # |
also for the pressTimeout. "Setting a negative value will disable the press timeout."
Tim Peeters (tpeeters) wrote : | # |
First MR ready to go in staging :)
PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
1 | === modified file 'components.api' | |||
2 | --- components.api 2014-03-14 16:11:00 +0000 | |||
3 | +++ components.api 2014-04-09 12:37:48 +0000 | |||
4 | @@ -592,6 +592,8 @@ | |||
5 | 592 | function findChild(obj,objectName) | 592 | function findChild(obj,objectName) |
6 | 593 | function findInvisibleChild(obj,objectName) | 593 | function findInvisibleChild(obj,objectName) |
7 | 594 | function mouseMoveSlowly(item,x,y,dx,dy,steps,stepdelay) | 594 | function mouseMoveSlowly(item,x,y,dx,dy,steps,stepdelay) |
8 | 595 | function flick(item, x, y, dx, dy, pressTimeout, steps, button, modifiers, delay) | ||
9 | 596 | function mouseLongPress(item, x, y, button, modifiers, delay) | ||
10 | 595 | function tryCompareFunction(func, expectedResult, timeout) | 597 | function tryCompareFunction(func, expectedResult, timeout) |
11 | 596 | plugins.qmltypes | 598 | plugins.qmltypes |
12 | 597 | name: "InverseMouseAreaType" | 599 | name: "InverseMouseAreaType" |
13 | 598 | 600 | ||
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-09 12:37:48 +0000 | |||
17 | @@ -87,7 +87,75 @@ | |||
18 | 87 | } | 87 | } |
19 | 88 | } | 88 | } |
20 | 89 | 89 | ||
22 | 90 | /*! | 90 | /*! |
23 | 91 | \qmlmethod UbuntuTestCase::flick(item, x, y, dx, dy, pressTimeout = -1, steps = -1, button = Qt.LeftButton, modifiers = Qt.NoModifiers, delay = -1) | ||
24 | 92 | |||
25 | 93 | The function produces a flick event when executed on Flickables. When used | ||
26 | 94 | on other components it provides the same functionality as \l mouseDrag() | ||
27 | 95 | function. The optional \a pressTimeout parameter can be used to introduce | ||
28 | 96 | a small delay between the mouse press and the first mouse move. Setting a | ||
29 | 97 | negative or zero value will disable the timeout. | ||
30 | 98 | |||
31 | 99 | The default flick velocity is built up using 5 move points. This can be altered | ||
32 | 100 | by setting a positive value to \a steps parameter. The bigger the number the | ||
33 | 101 | longer the flick will be. When a negative or zero value is given, the default | ||
34 | 102 | of 5 move points will be used. | ||
35 | 103 | |||
36 | 104 | \note The function can be used to select a text in a TextField or TextArea by | ||
37 | 105 | specifying at least 400 millisecods to \a pressTimeout. | ||
38 | 106 | */ | ||
39 | 107 | function flick(item, x, y, dx, dy, pressTimeout, steps, button, modifiers, delay) { | ||
40 | 108 | if (item === undefined || item.x === undefined || item.y === undefined) | ||
41 | 109 | return | ||
42 | 110 | if (button === undefined) | ||
43 | 111 | button = Qt.LeftButton | ||
44 | 112 | if (modifiers === undefined) | ||
45 | 113 | modifiers = Qt.NoModifier | ||
46 | 114 | if (steps === undefined || steps <= 0) | ||
47 | 115 | steps = 4; | ||
48 | 116 | // make sure we have at least two move steps so the flick will be sensed | ||
49 | 117 | steps += 1; | ||
50 | 118 | if (delay === undefined) | ||
51 | 119 | delay = -1; | ||
52 | 120 | |||
53 | 121 | var ddx = dx / steps; | ||
54 | 122 | var ddy = dy / steps; | ||
55 | 123 | |||
56 | 124 | mousePress(item, x, y, button, modifiers, delay); | ||
57 | 125 | if (pressTimeout !== undefined && pressTimeout > 0) { | ||
58 | 126 | wait(pressTimeout); | ||
59 | 127 | } | ||
60 | 128 | for (var i = 1; i <= steps; i++) { | ||
61 | 129 | // mouse moves are all processed immediately, without delay in between events | ||
62 | 130 | mouseMove(item, x + i * ddx, y + i * ddy, -1, button); | ||
63 | 131 | } | ||
64 | 132 | mouseRelease(item, x + dx, y + dy, button, modifiers, delay); | ||
65 | 133 | // empty event buffer | ||
66 | 134 | wait(200); | ||
67 | 135 | } | ||
68 | 136 | |||
69 | 137 | /*! | ||
70 | 138 | \qmlmethod UbuntuTestCase::mouseLongPress(item, x, y, button = Qt.LeftButton, modifiers = Qt.NoModifiers, delay = -1) | ||
71 | 139 | |||
72 | 140 | Simulates a long press on a mouse \a button with an optional \a modifier | ||
73 | 141 | on an \a item. The position is defined by \a x and \a y. If \a delay is | ||
74 | 142 | specified, the test will wait the specified amount of milliseconds before | ||
75 | 143 | the press. | ||
76 | 144 | |||
77 | 145 | The position given by \a x and \a y is transformed from the co-ordinate | ||
78 | 146 | system of \a item into window co-ordinates and then delivered. | ||
79 | 147 | If \a item is obscured by another item, or a child of \a item occupies | ||
80 | 148 | that position, then the event will be delivered to the other item instead. | ||
81 | 149 | |||
82 | 150 | \sa mouseRelease(), mouseClick(), mouseDoubleClick(), mouseMove(), mouseDrag(), mouseWheel() | ||
83 | 151 | */ | ||
84 | 152 | function mouseLongPress(item, x, y, button, modifiers, delay) { | ||
85 | 153 | mousePress(item, x, y, button, modifiers, delay); | ||
86 | 154 | // the delay is taken from QQuickMouseArea | ||
87 | 155 | wait(800); | ||
88 | 156 | } | ||
89 | 157 | |||
90 | 158 | /*! | ||
91 | 91 | Keeps executing a given parameter-less function until it returns the given | 159 | Keeps executing a given parameter-less function until it returns the given |
92 | 92 | expected result or the timemout is reached (in which case a test failure | 160 | expected result or the timemout is reached (in which case a test failure |
93 | 93 | is generated) | 161 | is generated) |
94 | 94 | 162 | ||
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-09 12:37:48 +0000 | |||
98 | @@ -7,9 +7,14 @@ | |||
99 | 7 | # make found deployables visible in Qt Creator | 7 | # make found deployables visible in Qt Creator |
100 | 8 | OTHER_FILES += $$QMLDIR_FILE | 8 | OTHER_FILES += $$QMLDIR_FILE |
101 | 9 | 9 | ||
102 | 10 | QML_FILES = $$system(ls *.qml) | ||
103 | 11 | JS_FILES = $$system(ls *.js) | ||
104 | 12 | |||
105 | 10 | # define deployment for found deployables | 13 | # define deployment for found deployables |
106 | 11 | qmldir_file.path = $$installPath | 14 | qmldir_file.path = $$installPath |
107 | 12 | qmldir_file.files = $$QMLDIR_FILE | 15 | qmldir_file.files = $$QMLDIR_FILE |
108 | 16 | qml_files.path = $$installPath | ||
109 | 17 | qml_files.files = $$QML_FILES | ||
110 | 13 | js_files.path = $$installPath | 18 | js_files.path = $$installPath |
111 | 14 | js_files.files = $$JS_FILES | 19 | js_files.files = $$JS_FILES |
112 | 15 | 20 | ||
113 | @@ -20,4 +25,4 @@ | |||
114 | 20 | # https://bugreports.qt-project.org/browse/QTBUG-36243 | 25 | # https://bugreports.qt-project.org/browse/QTBUG-36243 |
115 | 21 | plugins_qmltypes.extra = $$[QT_INSTALL_BINS]/qmlplugindump -notrelocatable Ubuntu.Test 0.1 ../../ 2>/dev/null > $(INSTALL_ROOT)/$$installPath/plugins.qmltypes | 26 | plugins_qmltypes.extra = $$[QT_INSTALL_BINS]/qmlplugindump -notrelocatable Ubuntu.Test 0.1 ../../ 2>/dev/null > $(INSTALL_ROOT)/$$installPath/plugins.qmltypes |
116 | 22 | 27 | ||
118 | 23 | INSTALLS += qmldir_file plugins_qmltypes | 28 | INSTALLS += qmldir_file plugins_qmltypes qml_files js_files |
119 | 24 | 29 | ||
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-09 12:37:48 +0000 | |||
123 | @@ -33,7 +33,7 @@ | |||
124 | 33 | if [ $_TARGET != $_TESTFILE ]; then | 33 | if [ $_TARGET != $_TESTFILE ]; then |
125 | 34 | _CMD="$_CMD -input $_TESTFILE" | 34 | _CMD="$_CMD -input $_TESTFILE" |
126 | 35 | fi | 35 | fi |
128 | 36 | _CMD="$_CMD -maxwarnings 4" | 36 | _CMD="$_CMD -maxwarnings 40" |
129 | 37 | } | 37 | } |
130 | 38 | 38 | ||
131 | 39 | function execute_test_cmd { | 39 | function execute_test_cmd { |
132 | 40 | 40 | ||
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-09 12:37:48 +0000 | |||
136 | @@ -23,30 +23,57 @@ | |||
137 | 23 | width: 800 | 23 | width: 800 |
138 | 24 | height: 600 | 24 | height: 600 |
139 | 25 | 25 | ||
148 | 26 | MouseArea { | 26 | Column { |
149 | 27 | id: mouseArea | 27 | anchors.fill: parent |
150 | 28 | objectName: "myMouseArea" | 28 | MouseArea { |
151 | 29 | anchors.fill: parent | 29 | id: mouseArea |
152 | 30 | hoverEnabled: true | 30 | objectName: "myMouseArea" |
153 | 31 | property int testX : 0 | 31 | width: parent.width |
154 | 32 | property int testY : 0 | 32 | height: 300 |
155 | 33 | property int steps : 0 | 33 | hoverEnabled: true |
156 | 34 | acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton | ||
157 | 35 | property int testX : 0 | ||
158 | 36 | property int testY : 0 | ||
159 | 37 | property int steps : 0 | ||
160 | 34 | 38 | ||
166 | 35 | onPositionChanged: { | 39 | onPositionChanged: { |
167 | 36 | testX = mouseX; | 40 | testX = mouseX; |
168 | 37 | testY = mouseY; | 41 | testY = mouseY; |
169 | 38 | steps++; | 42 | steps++; |
170 | 39 | } | 43 | } |
171 | 44 | } | ||
172 | 45 | Flickable { | ||
173 | 46 | id: flicker | ||
174 | 47 | width: parent.width | ||
175 | 48 | height: 400 | ||
176 | 49 | contentWidth: rect.width | ||
177 | 50 | contentHeight: rect.height | ||
178 | 51 | clip: true | ||
179 | 52 | Rectangle { | ||
180 | 53 | id: rect | ||
181 | 54 | color: "blue" | ||
182 | 55 | width: 1000 | ||
183 | 56 | height: 1000 | ||
184 | 57 | } | ||
185 | 58 | } | ||
186 | 40 | } | 59 | } |
187 | 41 | 60 | ||
188 | 42 | UbuntuTestCase { | 61 | UbuntuTestCase { |
189 | 43 | name: "TestTheUbuntuTestCase" | 62 | name: "TestTheUbuntuTestCase" |
190 | 44 | when: windowShown | 63 | when: windowShown |
191 | 45 | 64 | ||
192 | 65 | function init() { | ||
193 | 66 | mouseArea.steps = 0; | ||
194 | 67 | } | ||
195 | 68 | function cleanup() { | ||
196 | 69 | movementSpy.clear(); | ||
197 | 70 | longPressSpy.clear(); | ||
198 | 71 | } | ||
199 | 72 | |||
200 | 46 | function test_mouseMoveSlowly() { | 73 | function test_mouseMoveSlowly() { |
202 | 47 | mouseMoveSlowly(root,0,0,800,600,10,100); | 74 | mouseMoveSlowly(root,0,0,800,300,10,100); |
203 | 48 | compare(mouseArea.testX,800); | 75 | compare(mouseArea.testX,800); |
205 | 49 | compare(mouseArea.testY,600); | 76 | compare(mouseArea.testY,300); |
206 | 50 | compare(mouseArea.steps,10); | 77 | compare(mouseArea.steps,10); |
207 | 51 | } | 78 | } |
208 | 52 | 79 | ||
209 | @@ -58,5 +85,66 @@ | |||
210 | 58 | child = findChild(root,"NoSuchChildHere"); | 85 | child = findChild(root,"NoSuchChildHere"); |
211 | 59 | compare(child===null,true,"When there is no child, function should return null"); | 86 | compare(child===null,true,"When there is no child, function should return null"); |
212 | 60 | } | 87 | } |
213 | 88 | |||
214 | 89 | SignalSpy { | ||
215 | 90 | id: longPressSpy | ||
216 | 91 | target: mouseArea | ||
217 | 92 | signalName: "onPressAndHold" | ||
218 | 93 | } | ||
219 | 94 | |||
220 | 95 | function test_longPress_left() { | ||
221 | 96 | longPressSpy.clear(); | ||
222 | 97 | mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2); | ||
223 | 98 | longPressSpy.wait(); | ||
224 | 99 | // cleanup | ||
225 | 100 | mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2); | ||
226 | 101 | } | ||
227 | 102 | |||
228 | 103 | function test_longPress_right() { | ||
229 | 104 | longPressSpy.clear(); | ||
230 | 105 | mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.RightButton); | ||
231 | 106 | longPressSpy.wait(); | ||
232 | 107 | // cleanup | ||
233 | 108 | mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.RightButton); | ||
234 | 109 | } | ||
235 | 110 | |||
236 | 111 | function test_longPress_middle() { | ||
237 | 112 | longPressSpy.clear(); | ||
238 | 113 | mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.MiddleButton); | ||
239 | 114 | longPressSpy.wait(); | ||
240 | 115 | // cleanup | ||
241 | 116 | mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.MiddleButton); | ||
242 | 117 | } | ||
243 | 118 | |||
244 | 119 | SignalSpy { | ||
245 | 120 | id: movementSpy | ||
246 | 121 | target: flicker | ||
247 | 122 | signalName: "onMovementEnded" | ||
248 | 123 | } | ||
249 | 124 | |||
250 | 125 | function test_flick_default() { | ||
251 | 126 | flick(flicker, 0, 0, flicker.width, flicker.height); | ||
252 | 127 | movementSpy.wait(); | ||
253 | 128 | } | ||
254 | 129 | function test_flick_long() { | ||
255 | 130 | flick(flicker, 0, 0, flicker.width, flicker.height, -1, 10); | ||
256 | 131 | movementSpy.wait(); | ||
257 | 132 | } | ||
258 | 133 | function test_flick_short() { | ||
259 | 134 | flick(flicker, 0, 0, flicker.width, flicker.height, -1, 1); | ||
260 | 135 | movementSpy.wait(); | ||
261 | 136 | } | ||
262 | 137 | function test_flick_pressTimeout() { | ||
263 | 138 | flick(flicker, 0, 0, flicker.width, flicker.height, 400); | ||
264 | 139 | movementSpy.wait(); | ||
265 | 140 | } | ||
266 | 141 | function test_flick_pressTimeout_short() { | ||
267 | 142 | flick(flicker, flicker.width, flicker.height, -flicker.width, -flicker.height, 400, 1); | ||
268 | 143 | movementSpy.wait(); | ||
269 | 144 | } | ||
270 | 145 | function test_flick_pressTimeout_long() { | ||
271 | 146 | flick(flicker, flicker.width, flicker.height, -flicker.width, -flicker.height, 400, 100); | ||
272 | 147 | movementSpy.wait(); | ||
273 | 148 | } | ||
274 | 61 | } | 149 | } |
275 | 62 | } | 150 | } |
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.