Debian Codegraph @

tests/unit/test10/tst_lomiritestcase.qml

raw
1 /*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.0
18 import QtTest 1.0
19 import Lomiri.Test 1.0
20 import Lomiri.Components 1.0
21
22 Rectangle {
23 id: root
24 width: 800
25 height: 1000
26
27 Column {
28 anchors.fill: parent
29 MultiPointTouchArea {
30 id: topTouchArea
31 width: parent.width
32 height: 100
33 touchPoints: TouchPoint {
34 // id: point
35 }
36 }
37 MouseArea {
38 id: mouseArea
39 objectName: "myMouseArea"
40 width: parent.width
41 height: 200
42 hoverEnabled: true
43 acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
44 property int testX : 0
45 property int testY : 0
46 property int steps : 0
47
48 onPositionChanged: {
49 testX = mouseX;
50 testY = mouseY;
51 steps++;
52 }
53 }
54 MultiPointTouchArea {
55 id: touchArea
56 width: parent.width
57 height: 100
58 touchPoints: TouchPoint {
59 id: point
60 }
61 }
62
63 Flickable {
64 id: flicker
65 width: parent.width
66 height: 400
67 contentWidth: rect.width
68 contentHeight: rect.height
69 clip: true
70 Rectangle {
71 id: rect
72 color: "blue"
73 width: 1000
74 height: 1000
75 }
76 }
77 TextField {
78 id: textField
79 }
80 }
81
82 LomiriTestCase {
83 name: "TestTheLomiriTestCase"
84 when: windowShown
85
86 function initTestCase() {
87 TestExtras.registerTouchDevice();
88 }
89
90 function init() {
91 mouseArea.steps = 0;
92 }
93 function cleanup() {
94 movementSpy.clear();
95 longPressSpy.clear();
96 touchPressSpy.clear();
97 touchReleaseSpy.clear();
98 touchUpdateSpy.clear();
99 touchPressSpy.target = null;
100 touchReleaseSpy.target = null;
101 touchUpdateSpy.target = null;
102 }
103
104 function test_mouseMoveSlowly() {
105 mouseMoveSlowly(mouseArea,0,0,800,200,10,100);
106 compare(mouseArea.testX,800);
107 compare(mouseArea.testY,200);
108 compare(mouseArea.steps,10);
109 }
110
111 function test_findChild() {
112 var child = findChild(root,"myMouseArea");
113 compare(child!==null,true, "When a child is found, it is returned");
114 compare(child.objectName,"myMouseArea");
115
116 child = findChild(root,"NoSuchChildHere");
117 compare(child===null,true,"When there is no child, function should return null");
118 }
119
120 SignalSpy {
121 id: longPressSpy
122 target: mouseArea
123 signalName: "onPressAndHold"
124 }
125
126 function test_longPress_left() {
127 longPressSpy.clear();
128 mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2);
129 longPressSpy.wait();
130 // cleanup
131 mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2);
132 }
133
134 function test_longPress_right() {
135 longPressSpy.clear();
136 mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.RightButton);
137 longPressSpy.wait();
138 // cleanup
139 mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.RightButton);
140 }
141
142 function test_longPress_middle() {
143 longPressSpy.clear();
144 mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.MiddleButton);
145 longPressSpy.wait();
146 // cleanup
147 mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.MiddleButton);
148 }
149
150 SignalSpy {
151 id: movementSpy
152 target: flicker
153 signalName: "onMovementEnded"
154 }
155
156 function test_flick_default() {
157 flick(flicker, 0, 0, flicker.width, flicker.height);
158 movementSpy.wait();
159 }
160 function test_flick_long() {
161 flick(flicker, 0, 0, flicker.width, flicker.height, -1, 10);
162 movementSpy.wait();
163 }
164 function test_flick_short() {
165 flick(flicker, 0, 0, flicker.width, flicker.height, -1, 1);
166 movementSpy.wait();
167 }
168 function test_flick_pressTimeout() {
169 flick(flicker, 0, 0, flicker.width, flicker.height, 400);
170 movementSpy.wait();
171 }
172 function test_flick_pressTimeout_short() {
173 flick(flicker, flicker.width, flicker.height, -flicker.width, -flicker.height, 400, 1);
174 movementSpy.wait();
175 }
176 function test_flick_pressTimeout_long() {
177 flick(flicker, flicker.width, flicker.height, -flicker.width, -flicker.height, 400, 100);
178 movementSpy.wait();
179 }
180 function test_typeString() {
181 textField.forceActiveFocus();
182 typeString("Hello Lomiri");
183 tryCompare(textField, "text", "Hello Lomiri");
184 }
185
186 SignalSpy {
187 id: touchPressSpy
188 signalName: "onPressed"
189 target: touchArea
190 }
191 SignalSpy {
192 id: touchReleaseSpy
193 signalName: "onReleased"
194 target: touchArea
195 }
196 SignalSpy {
197 id: touchUpdateSpy
198 signalName: "onUpdated"
199 target: touchArea
200 }
201
202 function test_has_property() {
203 verify(TestExtras.hasOwnProperty("touchPresent"), "touchPresent property missing");
204 }
205
206 function test_touchPress_data() {
207 return [
208 {touch: touchArea},
209 {touch: topTouchArea}
210 ];
211 }
212 function test_touchPress(data) {
213 touchPressSpy.target = data.touch;
214 TestExtras.touchPress(0, data.touch, Qt.point(10, 10));
215 touchPressSpy.wait();
216 // cleanup
217 TestExtras.touchRelease(0, data.touch, Qt.point(10, 10));
218 }
219
220 function test_touchRelease_data() {
221 return [
222 {touch: touchArea},
223 {touch: topTouchArea}
224 ];
225 }
226 function test_touchRelease(data) {
227 // prerequisite: do a press so we get a release
228 TestExtras.touchPress(0, data.touch, Qt.point(10, 10));
229
230 touchReleaseSpy.target = data.touch;
231 TestExtras.touchRelease(0, data.touch, Qt.point(10, 10));
232 touchReleaseSpy.wait();
233 }
234
235 function test_touchClick_data() {
236 return [
237 {touch: touchArea},
238 {touch: topTouchArea}
239 ];
240 }
241 function test_touchClick(data) {
242 touchPressSpy.target = data.touch;
243 touchReleaseSpy.target = data.touch;
244 TestExtras.touchClick(0, data.touch, Qt.point(10, 10));
245 touchReleaseSpy.wait();
246 compare(touchPressSpy.count, 1, "Not pressed?");
247 compare(touchReleaseSpy.count, 1, "Not released?");
248 }
249
250 function test_touchDoubleClick_data() {
251 return [
252 {touch: touchArea},
253 {touch: topTouchArea}
254 ];
255 }
256 function test_touchDoubleClick(data) {
257 touchPressSpy.target = data.touch;
258 touchReleaseSpy.target = data.touch;
259 TestExtras.touchDoubleClick(0, data.touch, Qt.point(10, 10));
260 compare(touchPressSpy.count, 2, "Not pressed twice?");
261 compare(touchReleaseSpy.count, 2, "Not released twice?");
262 }
263
264 function test_touchMove_data() {
265 return [
266 {touch: touchArea},
267 {touch: topTouchArea}
268 ];
269 }
270 function test_touchMove(data) {
271 touchUpdateSpy.target = data.touch;
272 TestExtras.touchPress(0, data.touch, Qt.point(0, 0));
273 TestExtras.touchMove(0, data.touch, Qt.point(10, 10));
274 touchUpdateSpy.wait();
275 TestExtras.touchRelease(0, data.touch, Qt.point(10, 10));
276 }
277
278 function test_touchDrag_default_steps_data() {
279 return [
280 {touch: touchArea},
281 {touch: topTouchArea}
282 ];
283 }
284 function test_touchDrag_default_steps(data) {
285 touchPressSpy.target = data.touch;
286 touchReleaseSpy.target = data.touch;
287 touchUpdateSpy.target = data.touch;
288 TestExtras.touchDrag(0, data.touch, Qt.point(0, 0), Qt.point(10, 10));
289 compare(touchPressSpy.count, 1, "Not pressed?");
290 compare(touchReleaseSpy.count, 1, "Not released?");
291 compare(touchUpdateSpy.count, 5, "Not moved?");
292 }
293
294 function test_touchDrag_10_steps_data() {
295 return [
296 {touch: touchArea},
297 {touch: topTouchArea}
298 ];
299 }
300 function test_touchDrag_10_steps(data) {
301 touchPressSpy.target = data.touch;
302 touchReleaseSpy.target = data.touch;
303 touchUpdateSpy.target = data.touch;
304 TestExtras.touchDrag(0, data.touch, Qt.point(0, 0), Qt.point(100, 100), 10);
305 compare(touchPressSpy.count, 1, "Not pressed?");
306 compare(touchReleaseSpy.count, 1, "Not released?");
307 compare(touchUpdateSpy.count, 10, "Not moved?");
308 }
309 }
310 }