on xenial help sign in
Made tst_Launcher tests pass again took the opportunity to recfactor it a bit
commitd78e2d157e3ad46d5ec83f38e2a48594846057f0 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateThu 2 Oct 2014, 09:47 (12 years ago) parentfb0fb45
3 files changed+96−101
libs/UbuntuGestures/TouchRegistry.h+2−3 tests/qmltests/Launcher/tst_Launcher.qml+88−96 tests/utils/modules/Unity/Test/testutil.cpp+6−2
libs/UbuntuGestures/TouchRegistry.h+2−3
@@ -92,6 +92,8 @@ class UBUNTUGESTURES_EXPORT TouchRegistry : public QObject
9292 Q_OBJECT
9393public:
9494 TouchRegistry(QObject *parent = nullptr);
95+ // Useful for tests, where you should feed a fake timer
96+ TouchRegistry(QObject *parent, UbuntuGestures::AbstractTimerFactory *timerFactory);
9597
9698 virtual ~TouchRegistry();
9799
@@ -128,9 +130,6 @@ private Q_SLOTS:
128130 void rejectCandidateOwnerForTouch(int id, QQuickItem *candidate);
129131
130132private:
131− // Useful for tests, where you should feed a fake timer
132− TouchRegistry(QObject *parent, UbuntuGestures::AbstractTimerFactory *timerFactory);
133−
134133 class CandidateInfo {
135134 public:
136135 bool undecided;
tests/qmltests/Launcher/tst_Launcher.qml+88−96
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013-2014 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -28,25 +28,49 @@ Item {
2828 width: units.gu(50)
2929 height: units.gu(55)
3030
31− Launcher {
32− id: launcher
33− x: 0
34− y: 0
35− width: units.gu(40)
36− height: parent.height
31+ Loader {
32+ id: launcherLoader
33+ anchors.fill: parent
34+ property bool itemDestroyed: false
35+ sourceComponent: Component {
36+ Launcher {
37+ id: launcher
38+ x: 0
39+ y: 0
40+ width: units.gu(40)
41+ height: root.height
42+
43+ property string lastSelectedApplication
44+
45+ onLauncherApplicationSelected: {
46+ lastSelectedApplication = appId
47+ }
3748
38− property string lastSelectedApplication
49+ property int showDashHome_count: 0
50+ onShowDashHome: {
51+ showDashHome_count++;
52+ }
3953
40− onLauncherApplicationSelected: {
41− lastSelectedApplication = appId
42− }
54+ property int maxPanelX: 0
4355
44− property int showDashHome_count: 0
45− onShowDashHome: {
46− showDashHome_count++;
47− }
56+ Connections {
57+ target: testCase.findChild(launcher, "launcherPanel")
4858
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+ }
5074 }
5175
5276 SignalSpy {
@@ -54,19 +78,40 @@ Item {
5478 target: LauncherModel
5579 }
5680
57− Connections {
58− target: testCase.findChild(launcher, "launcherPanel")
81+ UT.UnityTestCase {
82+ id: testCase
83+ name: "Launcher"
84+ when: windowShown
5985
60− onXChanged: {
61− if (target.x > launcher.maxPanelX) {
62− launcher.maxPanelX = target.x;
63− }
86+ property Item launcher: launcherLoader.status === Loader.Ready ? launcherLoader.item : null
87+ function cleanup() {
88+ launcherLoader.active = false;
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;
6497 }
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);
66105
67− UT.UnityTestCase {
68− id: revealer
69− when: windowShown
106+ // Make sure noone changed the height of the window. The issue this test case
107+ // is verifying only happens on certain heights of the Launcher
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+ }
70115
71116 function dragLauncherIntoView() {
72117 var startX = launcher.dragAreaWidth/2;
@@ -87,22 +132,11 @@ Item {
87132 var panel = findChild(launcher, "launcherPanel");
88133 tryCompare(panel, "x", -panel.width, 1000);
89134 }
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− }
101135
102136 // Drag from the left edge of the screen rightwards and check that the launcher
103137 // appears (as if being dragged by the finger/pointer)
104138 function test_dragLeftEdgeToRevealLauncherAndTapCenterToDismiss() {
105− revealer.waitUntilLauncherDisappears();
139+ waitUntilLauncherDisappears();
106140
107141 var panel = findChild(launcher, "launcherPanel")
108142 verify(panel != undefined)
@@ -110,7 +144,7 @@ Item {
110144 // it starts out hidden just left of the left launcher edge
111145 compare(panel.x, -panel.width)
112146
113− revealer.dragLauncherIntoView()
147+ dragLauncherIntoView()
114148
115149 // tapping on the center of the screen should dismiss the launcher
116150 mouseClick(launcher, launcher.width/2, launcher.height/2)
@@ -124,7 +158,7 @@ Item {
124158 corresponding desktop file. E.g. clicking on phone icon should yield
125159 launcherApplicationSelected("[...]dialer-app.desktop") */
126160 function test_clickingOnAppIconCausesSignalEmission() {
127− revealer.dragLauncherIntoView();
161+ dragLauncherIntoView();
128162 launcher.lastSelectedApplication = ""
129163
130164 var listView = findChild(launcher, "launcherListView");
@@ -140,7 +174,7 @@ Item {
140174 "dialer-app")
141175
142176 // Tapping on an application icon also dismisses the launcher
143− revealer.waitUntilLauncherDisappears()
177+ waitUntilLauncherDisappears()
144178 }
145179
146180 /* If I click on the dash icon on the launcher
@@ -148,7 +182,7 @@ Item {
148182 function test_clickingOnDashIconCausesSignalEmission() {
149183 launcher.showDashHome_count = 0
150184
151− revealer.dragLauncherIntoView()
185+ dragLauncherIntoView()
152186
153187 var dashIcon = findChild(launcher, "dashItem")
154188 verify(dashIcon != undefined)
@@ -158,7 +192,7 @@ Item {
158192 tryCompare(launcher, "showDashHome_count", 1)
159193
160194 // Tapping on the dash icon also dismisses the launcher
161− revealer.waitUntilLauncherDisappears()
195+ waitUntilLauncherDisappears()
162196 }
163197
164198 function test_teaseLauncher_data() {
@@ -185,12 +219,12 @@ Item {
185219 wait(100)
186220 compare(launcher.maxPanelX, -launcher.panelWidth, "Launcher moved even if it shouldn't")
187221 }
188− revealer.waitUntilLauncherDisappears();
222+ waitUntilLauncherDisappears();
189223 launcher.available = true;
190224 }
191225
192226 function test_countEmblems() {
193− revealer.dragLauncherIntoView();
227+ dragLauncherIntoView();
194228 var launcherListView = findChild(launcher, "launcherListView");
195229 for (var i = 0; i < launcherListView.count; ++i) {
196230 var delegate = findChild(launcherListView, "launcherDelegate" + i)
@@ -201,7 +235,7 @@ Item {
201235 }
202236
203237 function test_progressOverlays() {
204− revealer.dragLauncherIntoView();
238+ dragLauncherIntoView();
205239 var launcherListView = findChild(launcher, "launcherListView");
206240 for (var i = 0; i < launcherListView.count; ++i) {
207241 var delegate = findChild(launcherListView, "launcherDelegate" + i)
@@ -210,18 +244,13 @@ Item {
210244 }
211245
212246 function test_focusedHighlight() {
213− revealer.dragLauncherIntoView();
247+ dragLauncherIntoView();
214248 var launcherListView = findChild(launcher, "launcherListView");
215249 for (var i = 0; i < launcherListView.count; ++i) {
216250 var delegate = findChild(launcherListView, "launcherDelegate" + i)
217251 compare(findChild(delegate, "focusedHighlight").visible, LauncherModel.get(i).focused)
218252 }
219253 }
220− }
221−
222− UT.UnityTestCase {
223− id: clickFlickTestCase
224− when: windowShown && testCase.completed
225254
226255 function test_clickFlick_data() {
227256 var listView = findChild(launcher, "launcherListView");
@@ -235,7 +264,7 @@ Item {
235264
236265 function test_clickFlick(data) {
237266 launcher.lastSelectedApplication = "";
238− revealer.dragLauncherIntoView();
267+ dragLauncherIntoView();
239268 var listView = findChild(launcher, "launcherListView");
240269
241270 listView.flick(0, data.flickSpeed);
@@ -253,44 +282,7 @@ Item {
253282 verify(launcher.lastSelectedApplication != "");
254283 compare(listView.contentY, oldY, "Launcher was flicked even though it should only launch an app");
255284 }
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();
263285 }
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
294286
295287 function test_dragndrop_data() {
296288 return [
@@ -301,7 +293,7 @@ Item {
301293 }
302294
303295 function test_dragndrop(data) {
304− revealer.dragLauncherIntoView();
296+ dragLauncherIntoView();
305297 var draggedItem = findChild(launcher, "launcherDelegate4")
306298 var item0 = findChild(launcher, "launcherDelegate0")
307299 var fakeDragItem = findChild(launcher, "fakeDragItem")
@@ -366,11 +358,11 @@ Item {
366358
367359 // Click somewhere in the empty space to make it hide in case it isn't
368360 mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
369− revealer.waitUntilLauncherDisappears();
361+ waitUntilLauncherDisappears();
370362 }
371363
372364 function test_quicklist_dismiss() {
373− revealer.dragLauncherIntoView();
365+ dragLauncherIntoView();
374366 var draggedItem = findChild(launcher, "launcherDelegate5")
375367 var item0 = findChild(launcher, "launcherDelegate0")
376368 var fakeDragItem = findChild(launcher, "fakeDragItem")
@@ -401,7 +393,7 @@ Item {
401393 }
402394
403395 function test_quicklist_positioning(data) {
404− revealer.dragLauncherIntoView();
396+ dragLauncherIntoView();
405397 var quickList = findChild(launcher, "quickList")
406398 var draggedItem = findChild(launcher, "launcherDelegate" + data.itemIndex)
407399 var quickListShape = findChild(launcher, "quickListShape")
@@ -428,7 +420,7 @@ Item {
428420
429421 // Click somewhere in the empty space to dismiss the launcher
430422 mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
431− revealer.waitUntilLauncherDisappears()
423+ waitUntilLauncherDisappears()
432424 }
433425
434426 function test_quicklist_click_data() {
@@ -439,7 +431,7 @@ Item {
439431 }
440432
441433 function test_quicklist_click(data) {
442− revealer.dragLauncherIntoView();
434+ dragLauncherIntoView();
443435 var clickedItem = findChild(launcher, "launcherDelegate5")
444436 var quickList = findChild(launcher, "quickList")
445437 var quickListShape = findChild(launcher, "quickListShape")
tests/utils/modules/Unity/Test/testutil.cpp+6−2
@@ -23,6 +23,9 @@
2323
2424// UbuntuGestures lib
2525#include <TouchRegistry.h>
26+#include <Timer.h>
27+
28+using namespace UbuntuGestures;
2629
2730TestUtil::TestUtil(QObject *parent)
2831 : QObject(parent)
@@ -85,8 +88,9 @@ void TestUtil::ensureTouchRegistryInstalled()
8588
8689 TouchRegistry *touchRegistry;
8790 if (TouchRegistry::instance() == nullptr) {
88− touchRegistry = new TouchRegistry;
89− touchRegistry->setParent(this);
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)
93+ touchRegistry = new TouchRegistry(this, new FakeTimerFactory);
9094 } else {
9195 touchRegistry = TouchRegistry::instance();
9296 if (touchRegistry->parent() != this) {