~mzanetti/unity8/fix_snap_decision_test

« back to all changes in this revision

Viewing changes to tests/qmltests/Launcher/tst_Launcher.qml

  • Committer: Michael Zanetti
  • Date: 2014-10-14 09:42:10 UTC
  • mfrom: (1314.1.51 unity8)
  • Revision ID: michael.zanetti@canonical.com-20141014094210-b131g3rb77u2f5p2
merge trunk, update test to work with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2013 Canonical Ltd.
 
2
 * Copyright 2013-2014 Canonical Ltd.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
28
28
    width: units.gu(50)
29
29
    height: units.gu(55)
30
30
 
31
 
    Launcher {
32
 
        id: launcher
33
 
        x: 0
34
 
        y: 0
35
 
        width: units.gu(40)
36
 
        height: parent.height
37
 
 
38
 
        property string lastSelectedApplication
39
 
 
40
 
        onLauncherApplicationSelected: {
41
 
            lastSelectedApplication = appId
42
 
        }
43
 
 
44
 
        property int showDashHome_count: 0
45
 
        onShowDashHome: {
46
 
            showDashHome_count++;
47
 
        }
48
 
 
49
 
        property int maxPanelX: 0
 
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
                }
 
48
 
 
49
                property int showDashHome_count: 0
 
50
                onShowDashHome: {
 
51
                    showDashHome_count++;
 
52
                }
 
53
 
 
54
                property int maxPanelX: 0
 
55
 
 
56
                Connections {
 
57
                    target: testCase.findChild(launcher, "launcherPanel")
 
58
 
 
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
76
    SignalSpy {
54
78
        target: LauncherModel
55
79
    }
56
80
 
57
 
    Connections {
58
 
        target: testCase.findChild(launcher, "launcherPanel")
59
 
 
60
 
        onXChanged: {
61
 
            if (target.x > launcher.maxPanelX) {
62
 
                launcher.maxPanelX = target.x;
63
 
            }
64
 
        }
65
 
    }
66
 
 
67
81
    UT.UnityTestCase {
68
 
        id: revealer
 
82
        id: testCase
 
83
        name: "Launcher"
69
84
        when: windowShown
70
85
 
 
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;
 
97
        }
 
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);
 
105
 
 
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
 
 
115
            // Tests can be run in a reaaaaally slow environment or machine. Thus ensure
 
116
            // the dismissTimer doesn't time out inadvertently.
 
117
            var dismissTimer = findInvisibleChild(launcher, "dismissTimer");
 
118
            dismissTimer.interval = 60 * 60 * 1000; // one hour
 
119
        }
 
120
 
71
121
        function dragLauncherIntoView() {
72
122
            var startX = launcher.dragAreaWidth/2;
73
123
            var startY = launcher.height/2;
87
137
            var panel = findChild(launcher, "launcherPanel");
88
138
            tryCompare(panel, "x", -panel.width, 1000);
89
139
        }
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
140
 
102
141
        // Drag from the left edge of the screen rightwards and check that the launcher
103
142
        // appears (as if being dragged by the finger/pointer)
104
143
        function test_dragLeftEdgeToRevealLauncherAndTapCenterToDismiss() {
105
 
            revealer.waitUntilLauncherDisappears();
 
144
            waitUntilLauncherDisappears();
106
145
 
107
146
            var panel = findChild(launcher, "launcherPanel")
108
147
            verify(panel != undefined)
110
149
            // it starts out hidden just left of the left launcher edge
111
150
            compare(panel.x, -panel.width)
112
151
 
113
 
            revealer.dragLauncherIntoView()
 
152
            dragLauncherIntoView()
114
153
 
115
154
            // tapping on the center of the screen should dismiss the launcher
116
155
            mouseClick(launcher, launcher.width/2, launcher.height/2)
124
163
           corresponding desktop file. E.g. clicking on phone icon should yield
125
164
           launcherApplicationSelected("[...]dialer-app.desktop") */
126
165
        function test_clickingOnAppIconCausesSignalEmission() {
127
 
            revealer.dragLauncherIntoView();
 
166
            dragLauncherIntoView();
128
167
            launcher.lastSelectedApplication = ""
129
168
 
130
169
            var listView = findChild(launcher, "launcherListView");
140
179
                       "dialer-app")
141
180
 
142
181
            // Tapping on an application icon also dismisses the launcher
143
 
            revealer.waitUntilLauncherDisappears()
 
182
            waitUntilLauncherDisappears()
144
183
        }
145
184
 
146
185
        /* If I click on the dash icon on the launcher
148
187
        function test_clickingOnDashIconCausesSignalEmission() {
149
188
            launcher.showDashHome_count = 0
150
189
 
151
 
            revealer.dragLauncherIntoView()
 
190
            dragLauncherIntoView()
152
191
 
153
192
            var dashIcon = findChild(launcher, "dashItem")
154
193
            verify(dashIcon != undefined)
158
197
            tryCompare(launcher, "showDashHome_count", 1)
159
198
 
160
199
            // Tapping on the dash icon also dismisses the launcher
161
 
            revealer.waitUntilLauncherDisappears()
 
200
            waitUntilLauncherDisappears()
162
201
        }
163
202
 
164
203
        function test_teaseLauncher_data() {
185
224
                wait(100)
186
225
                compare(launcher.maxPanelX, -launcher.panelWidth, "Launcher moved even if it shouldn't")
187
226
            }
188
 
            revealer.waitUntilLauncherDisappears();
 
227
            waitUntilLauncherDisappears();
189
228
            launcher.available = true;
190
229
        }
191
230
 
192
231
        function test_countEmblems() {
193
 
            revealer.dragLauncherIntoView();
 
232
            dragLauncherIntoView();
194
233
            var launcherListView = findChild(launcher, "launcherListView");
195
234
            for (var i = 0; i < launcherListView.count; ++i) {
196
235
                var delegate = findChild(launcherListView, "launcherDelegate" + i)
201
240
        }
202
241
 
203
242
        function test_progressOverlays() {
204
 
            revealer.dragLauncherIntoView();
 
243
            dragLauncherIntoView();
205
244
            var launcherListView = findChild(launcher, "launcherListView");
206
245
            for (var i = 0; i < launcherListView.count; ++i) {
207
246
                var delegate = findChild(launcherListView, "launcherDelegate" + i)
210
249
        }
211
250
 
212
251
        function test_focusedHighlight() {
213
 
            revealer.dragLauncherIntoView();
 
252
            dragLauncherIntoView();
214
253
            var launcherListView = findChild(launcher, "launcherListView");
215
254
            for (var i = 0; i < launcherListView.count; ++i) {
216
255
                var delegate = findChild(launcherListView, "launcherDelegate" + i)
217
256
                compare(findChild(delegate, "focusedHighlight").visible, LauncherModel.get(i).focused)
218
257
            }
219
258
        }
220
 
    }
221
 
 
222
 
    UT.UnityTestCase {
223
 
        id: clickFlickTestCase
224
 
        when: windowShown && testCase.completed
225
259
 
226
260
        function test_clickFlick_data() {
227
261
            var listView = findChild(launcher, "launcherListView");
228
262
            return [
229
 
                {tag: "unfolded top", flickSpeed: units.gu(200), clickY: listView.topMargin + units.gu(2), expectFlick: false},
230
 
                {tag: "folded top", flickSpeed: -units.gu(200), clickY: listView.topMargin + units.gu(2), expectFlick: true},
231
 
                {tag: "unfolded bottom", flickSpeed: -units.gu(200), clickY: listView.height - listView.topMargin - units.gu(1), expectFlick: false},
232
 
                {tag: "folded bottom", flickSpeed: units.gu(200), clickY: listView.height - listView.topMargin - units.gu(1), expectFlick: true},
 
263
                {tag: "unfolded top", positionViewAtBeginning: false,
 
264
                                      clickY: listView.topMargin + units.gu(2),
 
265
                                      expectFlick: false},
 
266
 
 
267
                {tag: "folded top", positionViewAtBeginning: true,
 
268
                                    clickY: listView.topMargin + units.gu(2),
 
269
                                    expectFlick: true},
 
270
 
 
271
                {tag: "unfolded bottom", positionViewAtBeginning: true,
 
272
                                         clickY: listView.height - listView.topMargin - units.gu(1),
 
273
                                         expectFlick: false},
 
274
 
 
275
                {tag: "folded bottom", positionViewAtBeginning: false,
 
276
                                       clickY: listView.height - listView.topMargin - units.gu(1),
 
277
                                       expectFlick: true},
233
278
            ];
234
279
        }
235
280
 
236
281
        function test_clickFlick(data) {
237
282
            launcher.lastSelectedApplication = "";
238
 
            revealer.dragLauncherIntoView();
 
283
            dragLauncherIntoView();
239
284
            var listView = findChild(launcher, "launcherListView");
240
285
 
241
 
            listView.flick(0, data.flickSpeed);
 
286
            // flicking is unreliable. sometimes it works, sometimes the
 
287
            // list view moves just a tiny bit or not at all, making tests fail.
 
288
            // So for stability's sake we just put the listView in the position
 
289
            // we want to to actually start doing what this tests intends to check.
 
290
            if (data.positionViewAtBeginning) {
 
291
                listView.positionViewAtBeginning();
 
292
            } else {
 
293
                listView.positionViewAtEnd();
 
294
            }
242
295
            tryCompare(listView, "flicking", false);
243
296
 
244
297
            var oldY = listView.contentY;
253
306
                verify(launcher.lastSelectedApplication != "");
254
307
                compare(listView.contentY, oldY, "Launcher was flicked even though it should only launch an app");
255
308
            }
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
 
        }
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
 
309
        }
294
310
 
295
311
        function test_dragndrop_data() {
296
312
            return [
301
317
        }
302
318
 
303
319
        function test_dragndrop(data) {
304
 
            revealer.dragLauncherIntoView();
 
320
            dragLauncherIntoView();
305
321
            var draggedItem = findChild(launcher, "launcherDelegate4")
306
322
            var item0 = findChild(launcher, "launcherDelegate0")
307
323
            var fakeDragItem = findChild(launcher, "fakeDragItem")
366
382
 
367
383
            // Click somewhere in the empty space to make it hide in case it isn't
368
384
            mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
369
 
            revealer.waitUntilLauncherDisappears();
 
385
            waitUntilLauncherDisappears();
370
386
        }
371
387
 
372
388
        function test_quicklist_dismiss() {
373
 
            revealer.dragLauncherIntoView();
 
389
            dragLauncherIntoView();
374
390
            var draggedItem = findChild(launcher, "launcherDelegate5")
375
391
            var item0 = findChild(launcher, "launcherDelegate0")
376
392
            var fakeDragItem = findChild(launcher, "fakeDragItem")
401
417
        }
402
418
 
403
419
        function test_quicklist_positioning(data) {
404
 
            revealer.dragLauncherIntoView();
 
420
            dragLauncherIntoView();
405
421
            var quickList = findChild(launcher, "quickList")
406
422
            var draggedItem = findChild(launcher, "launcherDelegate" + data.itemIndex)
407
423
            var quickListShape = findChild(launcher, "quickListShape")
428
444
 
429
445
            // Click somewhere in the empty space to dismiss the launcher
430
446
            mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
431
 
            revealer.waitUntilLauncherDisappears()
 
447
            waitUntilLauncherDisappears()
432
448
        }
433
449
 
434
450
        function test_quicklist_click_data() {
439
455
        }
440
456
 
441
457
        function test_quicklist_click(data) {
442
 
            revealer.dragLauncherIntoView();
 
458
            dragLauncherIntoView();
443
459
            var clickedItem = findChild(launcher, "launcherDelegate5")
444
460
            var quickList = findChild(launcher, "quickList")
445
461
            var quickListShape = findChild(launcher, "quickListShape")