on xenial help sign in
Made tst_Launcher tests pass again took the opportunity to recfactor it a bit
d78e2d1Daniel d'Andrada
libs/UbuntuGestures/TouchRegistry.h+2−3
@@ -92,6 +92,8 @@ class UBUNTUGESTURES_EXPORT TouchRegistry : public QObject
92 Q_OBJECT
92 Q_OBJECT
93public:
93public:
94 TouchRegistry(QObject *parent = nullptr);
94 TouchRegistry(QObject *parent = nullptr);
95+ // Useful for tests, where you should feed a fake timer
96+ TouchRegistry(QObject *parent, UbuntuGestures::AbstractTimerFactory *timerFactory);
95
97
96 virtual ~TouchRegistry();
98 virtual ~TouchRegistry();
97
99
@@ -128,9 +130,6 @@ private Q_SLOTS:
128 void rejectCandidateOwnerForTouch(int id, QQuickItem *candidate);
130 void rejectCandidateOwnerForTouch(int id, QQuickItem *candidate);
129
131
130private:
132private:
131− // Useful for tests, where you should feed a fake timer
132− TouchRegistry(QObject *parent, UbuntuGestures::AbstractTimerFactory *timerFactory);
133−
134 class CandidateInfo {
133 class CandidateInfo {
135 public:
134 public:
136 bool undecided;
135 bool undecided;
tests/qmltests/Launcher/tst_Launcher.qml+88−96
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013-2014 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -28,25 +28,49 @@ Item {
28 width: units.gu(50)
28 width: units.gu(50)
29 height: units.gu(55)
29 height: units.gu(55)
30
30
31+ Loader {
32+ id: launcherLoader
33+ anchors.fill: parent
34+ property bool itemDestroyed: false
35+ sourceComponent: Component {
31− Launcher {
36+ Launcher {
32− id: launcher
37+ id: launcher
33− x: 0
38+ x: 0
34− y: 0
39+ y: 0
35− width: units.gu(40)
40+ width: units.gu(40)
36− height: parent.height
41+ height: root.height
42+
43+ property string lastSelectedApplication
44+
45+ onLauncherApplicationSelected: {
46+ lastSelectedApplication = appId
47+ }
37
48
38− property string lastSelectedApplication
49+ property int showDashHome_count: 0
50+ onShowDashHome: {
51+ showDashHome_count++;
52+ }
39
53
40− onLauncherApplicationSelected: {
54+ property int maxPanelX: 0
41− lastSelectedApplication = appId
42− }
43
55
44− property int showDashHome_count: 0
56+ Connections {
45− onShowDashHome: {
57+ target: testCase.findChild(launcher, "launcherPanel")
46− showDashHome_count++;
47− }
48
58
49− property int maxPanelX: 0
59+ onXChanged: {
60+ if (target.x > launcher.maxPanelX) {
61+ launcher.maxPanelX = target.x;
62+ }
63+ }
64+ }
65+
66+ Component.onCompleted: {
67+ launcherLoader.itemDestroyed = false;
68+ }
69+ Component.onDestruction: {
70+ launcherLoader.itemDestroyed = true;
71+ }
72+ }
73+ }
50 }
74 }
51
75
52 SignalSpy {
76 SignalSpy {
@@ -54,19 +78,40 @@ Item {
54 target: LauncherModel
78 target: LauncherModel
55 }
79 }
56
80
57− Connections {
81+ UT.UnityTestCase {
58− target: testCase.findChild(launcher, "launcherPanel")
82+ id: testCase
83+ name: "Launcher"
84+ when: windowShown
59
85
60− onXChanged: {
86+ property Item launcher: launcherLoader.status === Loader.Ready ? launcherLoader.item : null
61− if (target.x > launcher.maxPanelX) {
87+ function cleanup() {
62− launcher.maxPanelX = target.x;
88+ launcherLoader.active = false;
63− }
89+ // Loader.status might be Loader.Null and Loader.item might be null but the Loader
90+ // item might still be alive. So if we set Loader.active back to true
91+ // again right now we will get the very same Shell instance back. So no reload
92+ // actually took place. Likely because Loader waits until the next event loop
93+ // iteration to do its work. So to ensure the reload, we will wait until the
94+ // Shell instance gets destroyed.
95+ tryCompare(launcherLoader, "itemDestroyed", true);
96+ launcherLoader.active = true;
64 }
97 }
65− }
98+ function init() {
99+ var listView = findChild(launcher, "launcherListView");
100+ // wait for it to settle before doing the flick. Otherwise the flick
101+ // might fail.
102+ // On startup that listView is already moving. maybe because of its contents
103+ // growing while populating it with icons etc.
104+ tryCompare(listView, "flicking", false);
66
105
67− UT.UnityTestCase {
106+ // Make sure noone changed the height of the window. The issue this test case
68− id: revealer
107+ // is verifying only happens on certain heights of the Launcher
69− when: windowShown
108+ compare(root.height, units.gu(55));
109+
110+ compare(listView.contentY, -listView.topMargin, "Launcher did not start up with first item unfolded");
111+
112+ // Now do check that snapping is in fact enabled
113+ compare(listView.snapMode, ListView.SnapToItem, "Snapping is not enabled");
114+ }
70
115
71 function dragLauncherIntoView() {
116 function dragLauncherIntoView() {
72 var startX = launcher.dragAreaWidth/2;
117 var startX = launcher.dragAreaWidth/2;
@@ -87,22 +132,11 @@ Item {
87 var panel = findChild(launcher, "launcherPanel");
132 var panel = findChild(launcher, "launcherPanel");
88 tryCompare(panel, "x", -panel.width, 1000);
133 tryCompare(panel, "x", -panel.width, 1000);
89 }
134 }
90− }
91−
92− UT.UnityTestCase {
93− id: testCase
94− name: "Launcher"
95− when: windowShown && initTestCase.completed
96−
97− function cleanup() {
98− mouseClick(root, root.width / 2, root.height / 2);
99− revealer.waitUntilLauncherDisappears();
100− }
101
135
102 // Drag from the left edge of the screen rightwards and check that the launcher
136 // Drag from the left edge of the screen rightwards and check that the launcher
103 // appears (as if being dragged by the finger/pointer)
137 // appears (as if being dragged by the finger/pointer)
104 function test_dragLeftEdgeToRevealLauncherAndTapCenterToDismiss() {
138 function test_dragLeftEdgeToRevealLauncherAndTapCenterToDismiss() {
105− revealer.waitUntilLauncherDisappears();
139+ waitUntilLauncherDisappears();
106
140
107 var panel = findChild(launcher, "launcherPanel")
141 var panel = findChild(launcher, "launcherPanel")
108 verify(panel != undefined)
142 verify(panel != undefined)
@@ -110,7 +144,7 @@ Item {
110 // it starts out hidden just left of the left launcher edge
144 // it starts out hidden just left of the left launcher edge
111 compare(panel.x, -panel.width)
145 compare(panel.x, -panel.width)
112
146
113− revealer.dragLauncherIntoView()
147+ dragLauncherIntoView()
114
148
115 // tapping on the center of the screen should dismiss the launcher
149 // tapping on the center of the screen should dismiss the launcher
116 mouseClick(launcher, launcher.width/2, launcher.height/2)
150 mouseClick(launcher, launcher.width/2, launcher.height/2)
@@ -124,7 +158,7 @@ Item {
124 corresponding desktop file. E.g. clicking on phone icon should yield
158 corresponding desktop file. E.g. clicking on phone icon should yield
125 launcherApplicationSelected("[...]dialer-app.desktop") */
159 launcherApplicationSelected("[...]dialer-app.desktop") */
126 function test_clickingOnAppIconCausesSignalEmission() {
160 function test_clickingOnAppIconCausesSignalEmission() {
127− revealer.dragLauncherIntoView();
161+ dragLauncherIntoView();
128 launcher.lastSelectedApplication = ""
162 launcher.lastSelectedApplication = ""
129
163
130 var listView = findChild(launcher, "launcherListView");
164 var listView = findChild(launcher, "launcherListView");
@@ -140,7 +174,7 @@ Item {
140 "dialer-app")
174 "dialer-app")
141
175
142 // Tapping on an application icon also dismisses the launcher
176 // Tapping on an application icon also dismisses the launcher
143− revealer.waitUntilLauncherDisappears()
177+ waitUntilLauncherDisappears()
144 }
178 }
145
179
146 /* If I click on the dash icon on the launcher
180 /* If I click on the dash icon on the launcher
@@ -148,7 +182,7 @@ Item {
148 function test_clickingOnDashIconCausesSignalEmission() {
182 function test_clickingOnDashIconCausesSignalEmission() {
149 launcher.showDashHome_count = 0
183 launcher.showDashHome_count = 0
150
184
151− revealer.dragLauncherIntoView()
185+ dragLauncherIntoView()
152
186
153 var dashIcon = findChild(launcher, "dashItem")
187 var dashIcon = findChild(launcher, "dashItem")
154 verify(dashIcon != undefined)
188 verify(dashIcon != undefined)
@@ -158,7 +192,7 @@ Item {
158 tryCompare(launcher, "showDashHome_count", 1)
192 tryCompare(launcher, "showDashHome_count", 1)
159
193
160 // Tapping on the dash icon also dismisses the launcher
194 // Tapping on the dash icon also dismisses the launcher
161− revealer.waitUntilLauncherDisappears()
195+ waitUntilLauncherDisappears()
162 }
196 }
163
197
164 function test_teaseLauncher_data() {
198 function test_teaseLauncher_data() {
@@ -185,12 +219,12 @@ Item {
185 wait(100)
219 wait(100)
186 compare(launcher.maxPanelX, -launcher.panelWidth, "Launcher moved even if it shouldn't")
220 compare(launcher.maxPanelX, -launcher.panelWidth, "Launcher moved even if it shouldn't")
187 }
221 }
188− revealer.waitUntilLauncherDisappears();
222+ waitUntilLauncherDisappears();
189 launcher.available = true;
223 launcher.available = true;
190 }
224 }
191
225
192 function test_countEmblems() {
226 function test_countEmblems() {
193− revealer.dragLauncherIntoView();
227+ dragLauncherIntoView();
194 var launcherListView = findChild(launcher, "launcherListView");
228 var launcherListView = findChild(launcher, "launcherListView");
195 for (var i = 0; i < launcherListView.count; ++i) {
229 for (var i = 0; i < launcherListView.count; ++i) {
196 var delegate = findChild(launcherListView, "launcherDelegate" + i)
230 var delegate = findChild(launcherListView, "launcherDelegate" + i)
@@ -201,7 +235,7 @@ Item {
201 }
235 }
202
236
203 function test_progressOverlays() {
237 function test_progressOverlays() {
204− revealer.dragLauncherIntoView();
238+ dragLauncherIntoView();
205 var launcherListView = findChild(launcher, "launcherListView");
239 var launcherListView = findChild(launcher, "launcherListView");
206 for (var i = 0; i < launcherListView.count; ++i) {
240 for (var i = 0; i < launcherListView.count; ++i) {
207 var delegate = findChild(launcherListView, "launcherDelegate" + i)
241 var delegate = findChild(launcherListView, "launcherDelegate" + i)
@@ -210,18 +244,13 @@ Item {
210 }
244 }
211
245
212 function test_focusedHighlight() {
246 function test_focusedHighlight() {
213− revealer.dragLauncherIntoView();
247+ dragLauncherIntoView();
214 var launcherListView = findChild(launcher, "launcherListView");
248 var launcherListView = findChild(launcher, "launcherListView");
215 for (var i = 0; i < launcherListView.count; ++i) {
249 for (var i = 0; i < launcherListView.count; ++i) {
216 var delegate = findChild(launcherListView, "launcherDelegate" + i)
250 var delegate = findChild(launcherListView, "launcherDelegate" + i)
217 compare(findChild(delegate, "focusedHighlight").visible, LauncherModel.get(i).focused)
251 compare(findChild(delegate, "focusedHighlight").visible, LauncherModel.get(i).focused)
218 }
252 }
219 }
253 }
220− }
221−
222− UT.UnityTestCase {
223− id: clickFlickTestCase
224− when: windowShown && testCase.completed
225
254
226 function test_clickFlick_data() {
255 function test_clickFlick_data() {
227 var listView = findChild(launcher, "launcherListView");
256 var listView = findChild(launcher, "launcherListView");
@@ -235,7 +264,7 @@ Item {
235
264
236 function test_clickFlick(data) {
265 function test_clickFlick(data) {
237 launcher.lastSelectedApplication = "";
266 launcher.lastSelectedApplication = "";
238− revealer.dragLauncherIntoView();
267+ dragLauncherIntoView();
239 var listView = findChild(launcher, "launcherListView");
268 var listView = findChild(launcher, "launcherListView");
240
269
241 listView.flick(0, data.flickSpeed);
270 listView.flick(0, data.flickSpeed);
@@ -253,44 +282,7 @@ Item {
253 verify(launcher.lastSelectedApplication != "");
282 verify(launcher.lastSelectedApplication != "");
254 compare(listView.contentY, oldY, "Launcher was flicked even though it should only launch an app");
283 compare(listView.contentY, oldY, "Launcher was flicked even though it should only launch an app");
255 }
284 }
256−
257− // Restore position on top
258− listView.flick(0, units.gu(200));
259− tryCompare(listView, "flicking", false)
260− // Click somewhere in the empty space to make it hide in case it isn't
261− mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
262− revealer.waitUntilLauncherDisappears();
263 }
285 }
264− }
265−
266− UT.UnityTestCase {
267− id: initTestCase
268− name: "LauncherInit"
269− when: windowShown
270−
271− function initTestCase() {
272− var listView = findChild(launcher, "launcherListView");
273− tryCompare(listView, "flicking", false)
274− }
275−
276− function test_initFirstUnfolded() {
277−
278− // Make sure noone changed the height of the window. The issue this test case
279− // is verifying only happens on certain heights of the Launcher
280− compare(root.height, units.gu(55));
281−
282− var listView = findChild(launcher, "launcherListView");
283− compare(listView.contentY, -listView.topMargin, "Launcher did not start up with first item unfolded");
284−
285− // Now do check that snapping is in fact enabled
286− compare(listView.snapMode, ListView.SnapToItem, "Snapping is not enabled");
287− }
288− }
289−
290− UT.UnityTestCase {
291− id: dndTestCase
292− name: "Drag and Drop"
293− when: windowShown && initTestCase.completed
294
286
295 function test_dragndrop_data() {
287 function test_dragndrop_data() {
296 return [
288 return [
@@ -301,7 +293,7 @@ Item {
301 }
293 }
302
294
303 function test_dragndrop(data) {
295 function test_dragndrop(data) {
304− revealer.dragLauncherIntoView();
296+ dragLauncherIntoView();
305 var draggedItem = findChild(launcher, "launcherDelegate4")
297 var draggedItem = findChild(launcher, "launcherDelegate4")
306 var item0 = findChild(launcher, "launcherDelegate0")
298 var item0 = findChild(launcher, "launcherDelegate0")
307 var fakeDragItem = findChild(launcher, "fakeDragItem")
299 var fakeDragItem = findChild(launcher, "fakeDragItem")
@@ -366,11 +358,11 @@ Item {
366
358
367 // Click somewhere in the empty space to make it hide in case it isn't
359 // Click somewhere in the empty space to make it hide in case it isn't
368 mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
360 mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
369− revealer.waitUntilLauncherDisappears();
361+ waitUntilLauncherDisappears();
370 }
362 }
371
363
372 function test_quicklist_dismiss() {
364 function test_quicklist_dismiss() {
373− revealer.dragLauncherIntoView();
365+ dragLauncherIntoView();
374 var draggedItem = findChild(launcher, "launcherDelegate5")
366 var draggedItem = findChild(launcher, "launcherDelegate5")
375 var item0 = findChild(launcher, "launcherDelegate0")
367 var item0 = findChild(launcher, "launcherDelegate0")
376 var fakeDragItem = findChild(launcher, "fakeDragItem")
368 var fakeDragItem = findChild(launcher, "fakeDragItem")
@@ -401,7 +393,7 @@ Item {
401 }
393 }
402
394
403 function test_quicklist_positioning(data) {
395 function test_quicklist_positioning(data) {
404− revealer.dragLauncherIntoView();
396+ dragLauncherIntoView();
405 var quickList = findChild(launcher, "quickList")
397 var quickList = findChild(launcher, "quickList")
406 var draggedItem = findChild(launcher, "launcherDelegate" + data.itemIndex)
398 var draggedItem = findChild(launcher, "launcherDelegate" + data.itemIndex)
407 var quickListShape = findChild(launcher, "quickListShape")
399 var quickListShape = findChild(launcher, "quickListShape")
@@ -428,7 +420,7 @@ Item {
428
420
429 // Click somewhere in the empty space to dismiss the launcher
421 // Click somewhere in the empty space to dismiss the launcher
430 mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
422 mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
431− revealer.waitUntilLauncherDisappears()
423+ waitUntilLauncherDisappears()
432 }
424 }
433
425
434 function test_quicklist_click_data() {
426 function test_quicklist_click_data() {
@@ -439,7 +431,7 @@ Item {
439 }
431 }
440
432
441 function test_quicklist_click(data) {
433 function test_quicklist_click(data) {
442− revealer.dragLauncherIntoView();
434+ dragLauncherIntoView();
443 var clickedItem = findChild(launcher, "launcherDelegate5")
435 var clickedItem = findChild(launcher, "launcherDelegate5")
444 var quickList = findChild(launcher, "quickList")
436 var quickList = findChild(launcher, "quickList")
445 var quickListShape = findChild(launcher, "quickListShape")
437 var quickListShape = findChild(launcher, "quickListShape")
tests/utils/modules/Unity/Test/testutil.cpp+6−2
@@ -23,6 +23,9 @@
23
23
24// UbuntuGestures lib
24// UbuntuGestures lib
25#include <TouchRegistry.h>
25#include <TouchRegistry.h>
26+#include <Timer.h>
27+
28+using namespace UbuntuGestures;
26
29
27TestUtil::TestUtil(QObject *parent)
30TestUtil::TestUtil(QObject *parent)
28 : QObject(parent)
31 : QObject(parent)
@@ -85,8 +88,9 @@ void TestUtil::ensureTouchRegistryInstalled()
85
88
86 TouchRegistry *touchRegistry;
89 TouchRegistry *touchRegistry;
87 if (TouchRegistry::instance() == nullptr) {
90 if (TouchRegistry::instance() == nullptr) {
91+ // Tests can be *very* slow to run and we don't want things timing out because
92+ // of that. So give it fake timers to use (they will never time out)
88− touchRegistry = new TouchRegistry;
93+ touchRegistry = new TouchRegistry(this, new FakeTimerFactory);
89− touchRegistry->setParent(this);
90 } else {
94 } else {
91 touchRegistry = TouchRegistry::instance();
95 touchRegistry = TouchRegistry::instance();
92 if (touchRegistry->parent() != this) {
96 if (touchRegistry->parent() != this) {