~ci-train-bot/unity8/unity8-ubuntu-zesty-2404

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
/*
 * Copyright 2013-2016 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import QtQuick.Layouts 1.1
import QtTest 1.0
import Unity.Test 0.1
import Ubuntu.Components 1.3
import ".."
import "../../../qml/Launcher"
import Unity.Launcher 0.1
import Utils 0.1 // For EdgeBarrierSettings

/* Nothing is shown at first. If you drag from left edge you will bring up the
   launcher. */
Rectangle {
    id: root
    width: units.gu(140)
    height: units.gu(70)
    color: UbuntuColors.graphite // something neither white nor black

    Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark"

    MouseArea {
        id: clickThroughTester
        anchors.fill: parent
        // SignalSpy does not seem to want to connect to the pressed signal. let's count them ourselves.
        property int pressCount: 0
        onPressed: pressCount++;
    }

    Loader {
        id: launcherLoader
        anchors.fill: parent
        focus: true
        property bool itemDestroyed: false
        sourceComponent: Component {
            Launcher {
                id: launcher
                x: 0
                y: 0
                width: units.gu(40)
                height: root.height

                property string lastSelectedApplication

                onLauncherApplicationSelected: {
                    lastSelectedApplication = appId
                }

                property int showDashHome_count: 0
                onShowDashHome: {
                    showDashHome_count++;
                }

                property int maxPanelX: 0

                Connections {
                    target: testCase.findChild(launcher, "launcherPanel")

                    onXChanged: {
                        if (target.x > launcher.maxPanelX) {
                            launcher.maxPanelX = target.x;
                        }
                    }
                }

                Component.onCompleted: {
                    launcherLoader.itemDestroyed = false;
                    launcherLoader.focus = true
                    edgeBarrierControls.target = testCase.findChild(this, "edgeBarrierController");
                }
                Component.onDestruction: {
                    launcherLoader.itemDestroyed = true;
                }
            }
        }
    }

    Binding {
        target: launcherLoader.item
        property: "lockedVisible"
        value: lockedVisibleCheckBox.checked
    }
    Binding {
        target: launcherLoader.item
        property: "panelWidth"
        value: units.gu(Math.round(widthSlider.value))
    }

    ColumnLayout {
        anchors { bottom: parent.bottom; right: parent.right; margins: units.gu(1) }
        spacing: units.gu(1)
        width: childrenRect.width

        RowLayout {
            CheckBox {
                id: lockedVisibleCheckBox
                checked: false
            }
            Label {
                text: "Launcher always visible"
                AbstractButton {
                    anchors.fill: parent
                    onClicked: lockedVisibleCheckBox.checked = !lockedVisibleCheckBox.checked
                }
            }
        }

        Slider {
            id: widthSlider
            Layout.fillWidth: true
            minimumValue: 6
            maximumValue: 12
            value: 10
        }

        MouseTouchEmulationCheckbox {}

        EdgeBarrierControls {
            id: edgeBarrierControls
            text: "Drag here to pull out launcher"
            onDragged: { launcherLoader.item.pushEdge(amount); }
        }

        Button {
            text: "emit hinting signal"
            onClicked: LauncherModel.emitHint()
            Layout.fillWidth: true
        }

        Button {
            text: "rotate"
            onClicked: launcherLoader.item.inverted = !launcherLoader.item.inverted
            Layout.fillWidth: true
        }

        Button {
            text: "open for kbd navigation"
            onClicked: {
                launcherLoader.item.openForKeyboardNavigation()
                launcherLoader.item.forceActiveFocus();// = true
            }
            Layout.fillWidth: true
        }

        Row {
            spacing: units.gu(1)

            Button {
                text: "35% bar"
                onClicked: LauncherModel.setProgress(LauncherModel.get(parseInt(appIdEntryBar.displayText)).appId, 35)
                Layout.fillWidth: true
            }

            TextArea {
                id: appIdEntryBar
                anchors.verticalCenter: parent.verticalCenter
                width: units.gu(4)
                height: units.gu(4)
                autoSize: true
                text: "2"
                maximumLineCount: 1
            }

            Button {
                text: "no bar"
                onClicked: LauncherModel.setProgress(LauncherModel.get(parseInt(appIdEntryBar.displayText)).appId, -1)
                Layout.fillWidth: true
            }
        }

        Row {
            spacing: units.gu(1)

            Button {
                text: "set alert"
                onClicked: LauncherModel.setAlerting(LauncherModel.get(parseInt(appIdEntryAlert.displayText)).appId, true)
            }

            TextArea {
                id: appIdEntryAlert
                anchors.verticalCenter: parent.verticalCenter
                width: units.gu(5)
                height: units.gu(4)
                autoSize: true
                text: "2"
                maximumLineCount: 1
                Layout.fillWidth: true
            }

            Button {
                text: "unset alert"
                onClicked: LauncherModel.setAlerting(LauncherModel.get(parseInt(appIdEntryAlert.displayText)).appId, false)
            }
        }

        Row {
            spacing: units.gu(1)
            Button {
                text: "Toggle count visible"
                onClicked: {
                    var item = LauncherModel.get(parseInt(appIdEntryCountVisible.displayText))
                    LauncherModel.setCountVisible(item.appId, !item.countVisible)
                }
            }
            TextField {
                id: appIdEntryCountVisible
                text: "0"
            }
        }
    }

    SignalSpy {
        id: signalSpy
        target: LauncherModel
    }

    SignalSpy {
        id: clickThroughSpy
        target: clickThroughTester
    }

    Item {
        id: fakeDismissTimer
        property bool running: false
        signal triggered

        function stop() {
            running = false;
        }

        function restart() {
            running = true;
        }
    }

    UnityTestCase {
        id: testCase
        name: "Launcher"
        when: windowShown

        property Item launcher: launcherLoader.status === Loader.Ready ? launcherLoader.item : null
        function cleanup() {
            signalSpy.clear();
            clickThroughSpy.clear();
            launcherLoader.active = false;
            // Loader.status might be Loader.Null and Loader.item might be null but the Loader
            // item might still be alive. So if we set Loader.active back to true
            // again right now we will get the very same Shell instance back. So no reload
            // actually took place. Likely because Loader waits until the next event loop
            // iteration to do its work. So to ensure the reload, we will wait until the
            // Shell instance gets destroyed.
            tryCompare(launcherLoader, "itemDestroyed", true);
        }

        function initLauncher() {
            launcherLoader.active = true;
            tryCompare(launcherLoader, "itemDestroyed", false);
        }

        function init() {
            initLauncher();
            var panel = findChild(launcher, "launcherPanel");
            verify(!!panel);

            panel.dismissTimer = fakeDismissTimer;

            // Make sure we don't start the test with the mouse hovering the launcher
            mouseMove(root, root.width, root.height / 2);

            var listView = findChild(launcher, "launcherListView");
            // wait for it to settle before doing the flick. Otherwise the flick
            // might fail.
            // On startup that listView is already moving. maybe because of its contents
            // growing while populating it with icons etc.
            tryCompare(listView, "flicking", false);

            tryCompare(listView, "contentY", -listView.topMargin, 5000, "Launcher did not start up with first item unfolded");

            // Now do check that snapping is in fact enabled
            compare(listView.snapMode, ListView.SnapToItem, "Snapping is not enabled");

            removeTimeConstraintsFromSwipeAreas(root);
        }

        function dragLauncher() {
            var startX = launcher.dragAreaWidth/2;
            var startY = launcher.height/2;
            touchFlick(launcher,
                       startX, startY,
                       startX+units.gu(8), startY);
        }

        function dragLauncherIntoView() {
            dragLauncher();

            var panel = findChild(launcher, "launcherPanel");
            verify(!!panel);

            // wait until it gets fully extended
            // a tryCompare doesn't work since
            //    compare(-0.000005917593600024418, 0);
            // is true and in this case we want exactly 0 or will have pain later on
            tryCompareFunction( function(){ return panel.x === 0; }, true );
            tryCompare(launcher, "state", "visible");
        }

        function revealByEdgePush() {
            // Place the mouse against the window/screen edge and push beyond the barrier threshold
            mouseMove(root, 1, root.height / 2);
            launcher.pushEdge(EdgeBarrierSettings.pushThreshold * 1.1);

            var panel = findChild(launcher, "launcherPanel");
            verify(!!panel);

            // wait until it gets fully extended
            tryCompare(panel, "x", 0);
            tryCompare(launcher, "state", "visibleTemporary");
        }

        function waitUntilLauncherDisappears() {
            var panel = findChild(launcher, "launcherPanel");
            tryCompare(panel, "x", -panel.width, 1000);
        }

        function waitForWiggleToStart(appIcon) {
            verify(appIcon != undefined)
            tryCompare(appIcon, "wiggling", true, 1000, "wiggle-anim should not be in stopped state")
        }

        function waitForWiggleToStop(appIcon) {
            verify(appIcon != undefined)
            tryCompare(appIcon, "wiggling", false, 1000, "wiggle-anim should not be in running state")
        }

        function positionLauncherListAtBeginning() {
            var listView = testCase.findChild(launcherLoader.item, "launcherListView");
            var moveAnimation = findInvisibleChild(listView, "moveAnimation")

            listView.moveToIndex(0);

            waitForRendering(listView);
            tryCompare(moveAnimation, "running", false);
        }
        function positionLauncherListAtEnd() {
            var listView = testCase.findChild(launcherLoader.item, "launcherListView");
            var moveAnimation = findInvisibleChild(listView, "moveAnimation")

            listView.moveToIndex(listView.count -1);

            waitForRendering(listView);
            tryCompare(moveAnimation, "running", false);
        }

        function assertFocusOnIndex(index) {
            var launcherPanel = findChild(launcher, "launcherPanel");
            var launcherListView = findChild(launcher, "launcherListView");
            var bfbFocusHighlight = findChild(launcher, "bfbFocusHighlight");

            waitForRendering(launcher);
            tryCompare(launcherPanel, "highlightIndex", index);
            compare(bfbFocusHighlight.visible, index === -1);
            for (var i = 0; i < launcherListView.count; i++) {
                var item = findChild(launcher, "launcherDelegate" + i);
                // Delegates might be destroyed when not visible. We can't check if they paint a focus highlight.
                // Make sure the requested index does have focus. for the others, try best effort to check if they don't
                if (index === i || item) {
                    var focusRing = findChild(item, "focusRing")
                    tryCompare(focusRing, "visible", index === i);
                }
            }
        }

        // Drag from the left edge of the screen rightwards and check that the launcher
        // appears (as if being dragged by the finger/pointer)
        function test_dragLeftEdgeToRevealLauncherAndTapCenterToDismiss() {
            waitUntilLauncherDisappears();

            var panel = findChild(launcher, "launcherPanel")
            verify(!!panel)

            // it starts out hidden just left of the left launcher edge
            compare(panel.x, -panel.width)

            dragLauncherIntoView()

            // tapping on the center of the screen should dismiss the launcher
            mouseClick(launcher, panel.width + units.gu(5), launcher.height / 2)

            // should eventually get fully retracted (hidden)
            tryCompare(panel, "x", -launcher.panelWidth, 2000)
        }

        /* If I click on the icon of an application on the launcher
           Launcher::launcherApplicationSelected signal should be emitted with the
           corresponding desktop file. E.g. clicking on phone icon should yield
           launcherApplicationSelected("[...]dialer-app.desktop") */
        function test_clickingOnAppIconCausesSignalEmission_data() {
            return [
                {tag: "by mouse", mouse: true},
                {tag: "by touch", mouse: false}
            ]
        }

        function test_clickingOnAppIconCausesSignalEmission(data) {
            if (data.mouse) {
                revealByEdgePush();
            } else {
                dragLauncherIntoView();
            }
            launcher.lastSelectedApplication = "";
            launcher.inverted = false;

            positionLauncherListAtBeginning();

            var appIcon = findChild(launcher, "launcherDelegate0");

            verify(!!appIcon);

            if (data.mouse) {
                mouseClick(appIcon);
            } else {
                tap(appIcon);
            }

            tryCompare(launcher, "lastSelectedApplication",
                       appIcon.appId);

            // Tapping on an application icon also dismisses the launcher
            waitUntilLauncherDisappears();
        }

        /* If I click on the dash icon on the launcher
           Launcher::showDashHome signal should be emitted */
        function test_clickingOnDashIconCausesSignalEmission() {
            launcher.showDashHome_count = 0

            dragLauncherIntoView()

            var dashIcon = findChild(launcher, "dashItem")
            verify(!!dashIcon)

            mouseClick(dashIcon)

            tryCompare(launcher, "showDashHome_count", 1)

            // Tapping on the dash icon also dismisses the launcher
            waitUntilLauncherDisappears()
        }

        function test_teaseLauncher_data() {
            return [
                {tag: "available", available: true},
                {tag: "not available", available: false}
            ];
        }

        function test_teaseLauncher(data) {
            launcher.available = data.available;
            launcher.maxPanelX = -launcher.panelWidth;
            launcher.tease();

            if (data.available) {
                // Check if the launcher slides in for units.gu(2). However, as the animation is 200ms
                // and the teaseTimer's timeout too, give it a 2 pixels grace distance
                tryCompareFunction(
                    function(){
                        return launcher.maxPanelX >= -launcher.panelWidth + units.gu(2) - 2;
                    },
                    true)
            } else {
                wait(100)
                compare(launcher.maxPanelX, -launcher.panelWidth, "Launcher moved even if it shouldn't")
            }

            waitUntilLauncherDisappears();
            launcher.available = true;
        }

        function test_hintLauncherOnChange() {
            var launcherPanel = findChild(launcher, "launcherPanel")
            // Make sure we start hidden
            tryCompare(launcherPanel, "x", -launcher.panelWidth)
            // reset our measurement property
            launcher.maxPanelX = -launcher.panelWidth
            // change it
            LauncherModel.move(0, 1)
            LauncherModel.emitHint();

            // make sure it opened fully and hides again without delay
            tryCompare(launcher, "maxPanelX", 0)
            tryCompare(launcherPanel, "x", -launcher.panelWidth, 1000)
        }

        function test_countEmblems() {
            dragLauncherIntoView();
            var launcherListView = findChild(launcher, "launcherListView");
            for (var i = 0; i < launcherListView.count; ++i) {
                launcherListView.moveToIndex(i);
                waitForRendering(launcherListView);
                var delegate = findChild(launcherListView, "launcherDelegate" + i)
                compare(findChild(delegate, "countEmblem").visible, LauncherModel.get(i).countVisible)
                // Intentionally allow type coercion (string/number)
                compare(findChild(delegate, "countLabel").text == LauncherModel.get(i).count, true)
            }
        }

        function test_progressOverlays() {
            dragLauncherIntoView();
            var launcherListView = findChild(launcher, "launcherListView");
            var moveAnimation = findInvisibleChild(launcherListView, "moveAnimation")
            for (var i = 0; i < launcherListView.count; ++i) {
                launcherListView.moveToIndex(i);
                waitForRendering(launcherListView);
                tryCompare(moveAnimation, "running", false);

                var delegate = findChild(launcherListView, "launcherDelegate" + i)
                compare(findChild(delegate, "progressOverlay").visible, LauncherModel.get(i).progress >= 0)
            }
        }

        function test_focusedHighlight() {
            dragLauncherIntoView();
            var launcherListView = findChild(launcher, "launcherListView");
            var moveAnimation = findInvisibleChild(launcherListView, "moveAnimation")

            for (var i = 0; i < launcherListView.count; ++i) {
                launcherListView.moveToIndex(i);
                waitForRendering(launcherListView);
                tryCompare(moveAnimation, "running", false);
                var delegate = findChild(launcherListView, "launcherDelegate" + i)
                compare(findChild(delegate, "focusedHighlight").visible, LauncherModel.get(i).focused)
            }
        }

        function test_clickFlick_data() {
            initLauncher()
            var listView = findChild(launcher, "launcherListView");
            return [
                {tag: "unfolded top", positionViewAtBeginning: true,
                                      clickY: listView.topMargin + units.gu(2),
                                      expectFlick: false},

                {tag: "folded top", positionViewAtBeginning: false,
                                    clickY: listView.topMargin + units.gu(2),
                                    expectFlick: true},

                {tag: "unfolded bottom", positionViewAtBeginning: false,
                                         clickY: listView.height - listView.topMargin - units.gu(1),
                                         expectFlick: false},

                {tag: "folded bottom", positionViewAtBeginning: true,
                                       clickY: listView.height - listView.topMargin - units.gu(1),
                                       expectFlick: true},
            ];
        }

        function test_clickFlick(data) {
            launcher.inverted = false;
            launcher.lastSelectedApplication = "";
            dragLauncherIntoView();
            var listView = findChild(launcher, "launcherListView");
            var moveAnimation = findInvisibleChild(listView, "moveAnimation")

            // flicking is unreliable. sometimes it works, sometimes the
            // list view moves just a tiny bit or not at all, making tests fail.
            // So for stability's sake we just put the listView in the position
            // we want to to actually start doing what this tests intends to check.
            if (data.positionViewAtBeginning) {
                positionLauncherListAtBeginning();
            } else {
                positionLauncherListAtEnd();
            }
            var oldY = listView.contentY;

            mouseClick(listView, listView.width / 2, data.clickY);

            if (data.expectFlick) {
                tryCompare(moveAnimation, "running", true);
            }
            tryCompare(moveAnimation, "running", false);

            if (data.expectFlick) {
                verify(listView.contentY != oldY);
                compare(launcher.lastSelectedApplication, "", "Launcher app clicked signal emitted even though it should only flick");
            } else {
                verify(launcher.lastSelectedApplication != "");
                compare(listView.contentY, oldY, "Launcher was flicked even though it should only launch an app");
            }
        }

        function test_dragndrop_data() {
            return [
                {tag: "startDrag", fullDrag: false, releaseBeforeDrag: false },
                {tag: "fullDrag horizontal", fullDrag: true, releaseBeforeDrag: false, orientation: ListView.Horizontal },
                {tag: "fullDrag vertical", fullDrag: true, releaseBeforeDrag: false, orientation: ListView.Vertical },
                {tag: "startDrag with quicklist open", fullDrag: false, releaseBeforeDrag: true },
                {tag: "fullDrag horizontal with quicklist open", fullDrag: true, releaseBeforeDrag: true, orientation: ListView.Horizontal },
                {tag: "fullDrag vertical with quicklist open", fullDrag: true, releaseBeforeDrag: true, orientation: ListView.Vertical },
            ];
        }

        function test_dragndrop(data) {
            dragLauncherIntoView();
            var draggedItem = findChild(launcher, "launcherDelegate4")
            var item0 = findChild(launcher, "launcherDelegate0")
            var fakeDragItem = findChild(launcher, "fakeDragItem")
            var initialItemHeight = draggedItem.height
            var item4 = LauncherModel.get(4).appId
            var item3 = LauncherModel.get(3).appId

            var listView = findChild(launcher, "launcherListView");
            listView.flick(0, units.gu(200));
            tryCompare(listView, "flicking", false);

            // Initial state
            compare(draggedItem.itemOpacity, 1, "Item's opacity is not 1 at beginning")
            compare(fakeDragItem.visible, false, "FakeDragItem isn't invisible at the beginning")
            tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 0)

            // Doing longpress
            var mouseOnLauncher = launcher.mapFromItem(draggedItem, draggedItem.width / 2, draggedItem.height / 2)
            var currentMouseX = mouseOnLauncher.x
            var currentMouseY = mouseOnLauncher.y
            var newMouseX = currentMouseX
            var newMouseY = currentMouseY
            mousePress(launcher, currentMouseX, currentMouseY)
            // DraggedItem needs to hide and fakeDragItem become visible
            tryCompare(draggedItem, "itemOpacity", 0)
            tryCompare(fakeDragItem, "visible", true)

            if (data.releaseBeforeDrag) {
                mouseRelease(launcher);
                tryCompare(fakeDragItem, "visible", false)

                mousePress(launcher, currentMouseX, currentMouseY);
                // DraggedItem needs to hide and fakeDragItem become visible
                tryCompare(fakeDragItem, "visible", true);
            }

            // Dragging a bit (> 1.5 gu)
            newMouseX -= units.gu(2)
            mouseFlick(launcher, currentMouseX, currentMouseY, newMouseX, newMouseY, false, false, 100)
            currentMouseX = newMouseX

            // Other items need to expand and become 0.6 opaque
            tryCompare(item0, "angle", 0)
            tryCompare(item0, "itemOpacity", 0.6)

            if (data.fullDrag) {
                // Dragging a bit more
                if (data.orientation == ListView.Horizontal) {
                    newMouseX += units.gu(15)
                    mouseFlick(launcher, currentMouseX, currentMouseY, newMouseX, newMouseY, false, false, 100)
                    currentMouseX = newMouseX

                    tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 1)
                    tryCompare(draggedItem, "height", units.gu(1))

                    // Dragging downwards. Item needs to move in the model
                    newMouseY -= initialItemHeight * 1.5
                    mouseFlick(launcher, currentMouseX, currentMouseY, newMouseX, newMouseY, false, false, 100)
                    currentMouseY = newMouseY
                } else if (data.orientation == ListView.Vertical) {
                    newMouseY -= initialItemHeight * 1.5
                    mouseFlick(launcher, currentMouseX, currentMouseY, newMouseX, newMouseY, false, false, 100)
                    currentMouseY = newMouseY

                    tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 1)
                    tryCompare(draggedItem, "height", units.gu(1))
                }

                waitForRendering(draggedItem)
                compare(LauncherModel.get(4).appId, item3)
                compare(LauncherModel.get(3).appId, item4)
            }

            // Releasing and checking if initial values are restored
            mouseRelease(launcher)
            tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 0)
            tryCompare(draggedItem, "itemOpacity", 1)
            tryCompare(fakeDragItem, "visible", false)

            // Click somewhere in the empty space to make it hide in case it isn't
            mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
            waitUntilLauncherDisappears();
        }

        function test_dragndrop_cancel_data() {
            return [
                {tag: "by mouse", mouse: true, releaseBeforeDrag: false},
                {tag: "by touch", mouse: false, releaseBeforeDrag: false},
                {tag: "by mouse with quicklist open", mouse: true, releaseBeforeDrag: true},
                {tag: "by touch with quicklist open", mouse: false, releaseBeforeDrag: true}
            ]
        }

        function test_dragndrop_cancel(data) {
            dragLauncherIntoView();
            var draggedItem = findChild(launcher, "launcherDelegate4")
            var item0 = findChild(launcher, "launcherDelegate0")
            var fakeDragItem = findChild(launcher, "fakeDragItem")

            // Doing longpress
            var currentMouseX = draggedItem.width / 2
            var currentMouseY = draggedItem.height / 2

            if(data.mouse) {
                mousePress(draggedItem, currentMouseX, currentMouseY)
            } else {
                touchPress(draggedItem, currentMouseX, currentMouseY)
            }

            // DraggedItem needs to hide and fakeDragItem become visible
            tryCompare(draggedItem, "itemOpacity", 0)
            tryCompare(fakeDragItem, "visible", true)

            if (data.releaseBeforeDrag) {
                if(data.mouse) {
                    mouseRelease(draggedItem)
                } else {
                    touchRelease(draggedItem)
                }
                tryCompare(fakeDragItem, "visible", false)

                if(data.mouse) {
                    mousePress(draggedItem, currentMouseX, currentMouseY)
                } else {
                    touchPress(draggedItem, currentMouseX, currentMouseY)
                }
                tryCompare(fakeDragItem, "visible", true);
            }

            // Dragging
            currentMouseX -= units.gu(20)

            if(data.mouse) {
                mouseMove(draggedItem, currentMouseX, currentMouseY)
            } else {
                touchMove(draggedItem, currentMouseX, currentMouseY)
            }

            // Make sure we're in the dragging state
            var dndArea = findChild(launcher, "dndArea");
            tryCompare(draggedItem, "dragging", true)
            tryCompare(dndArea, "draggedIndex", 4)

            // Click/Tap somewhere in the middle of the screen to close/hide the launcher
            if(data.mouse) {
                mouseClick(root)
            } else {
                touchRelease(draggedItem)
                tap(root)
            }

            // Make sure the dnd operation has been stopped
            tryCompare(draggedItem, "dragging", false)
            tryCompare(dndArea, "draggedIndex", -1)
            tryCompare(dndArea, "drag.target", undefined)
        }

        function test_dragndrop_with_other_quicklist_open() {
            dragLauncherIntoView();
            var draggedItem = findChild(launcher, "launcherDelegate4")
            var item0 = findChild(launcher, "launcherDelegate0")
            var fakeDragItem = findChild(launcher, "fakeDragItem")
            var initialItemHeight = draggedItem.height
            var item4 = LauncherModel.get(4).appId
            var item3 = LauncherModel.get(3).appId

            var listView = findChild(launcher, "launcherListView");
            listView.flick(0, units.gu(200));
            tryCompare(listView, "flicking", false);

            // Initial state
            compare(draggedItem.itemOpacity, 1, "Item's opacity is not 1 at beginning")
            compare(fakeDragItem.visible, false, "FakeDragItem isn't invisible at the beginning")
            tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 0)

            // Doing longpress
            var mouseOnLauncher = launcher.mapFromItem(draggedItem, draggedItem.width / 2, draggedItem.height / 2)
            var currentMouseX = mouseOnLauncher.x
            var currentMouseY = mouseOnLauncher.y
            var newMouseX = currentMouseX
            var newMouseY = currentMouseY
            mousePress(launcher, currentMouseX, currentMouseY)
            // DraggedItem needs to hide and fakeDragItem become visible
            tryCompare(draggedItem, "itemOpacity", 0)
            tryCompare(fakeDragItem, "visible", true)

            mouseRelease(launcher);
            tryCompare(fakeDragItem, "visible", false)

            // Now let's longpress and drag a different item

            var draggedItem = findChild(launcher, "launcherDelegate3")
            compare(draggedItem.itemOpacity, 1, "Item's opacity is not 1 at beginning")
            tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 0)

            // Doing longpress
            var mouseOnLauncher = launcher.mapFromItem(draggedItem, draggedItem.width / 2, draggedItem.height / 2)
            var currentMouseX = mouseOnLauncher.x
            var currentMouseY = mouseOnLauncher.y
            var newMouseX = currentMouseX
            var newMouseY = currentMouseY
            mousePress(launcher, currentMouseX, currentMouseY)
            // DraggedItem needs to hide and fakeDragItem become visible
            tryCompare(draggedItem, "itemOpacity", 0)
            tryCompare(fakeDragItem, "visible", true)

            // Dragging a bit (> 1.5 gu)
            newMouseX -= units.gu(2)
            mouseFlick(launcher, currentMouseX, currentMouseY, newMouseX, newMouseY, false, false, 100)
            currentMouseX = newMouseX

            // Other items need to expand and become 0.6 opaque
            tryCompare(item0, "angle", 0)
            tryCompare(item0, "itemOpacity", 0.6)

            // Dragging a bit more
            newMouseY += initialItemHeight * 1.5
            mouseFlick(launcher, currentMouseX, currentMouseY, newMouseX, newMouseY, false, false, 100)
            currentMouseY = newMouseY

            tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 1)
            tryCompare(draggedItem, "height", units.gu(1))

            waitForRendering(draggedItem)
            compare(LauncherModel.get(4).appId, item3)
            compare(LauncherModel.get(3).appId, item4)

            // Releasing and checking if initial values are restored
            mouseRelease(launcher)
            tryCompare(findChild(draggedItem, "dropIndicator"), "opacity", 0)
            tryCompare(draggedItem, "itemOpacity", 1)
            tryCompare(fakeDragItem, "visible", false)

            // Click somewhere in the empty space to make it hide in case it isn't
            mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
            waitUntilLauncherDisappears();
        }

        function test_quicklist_dismiss() {
            dragLauncherIntoView();
            var draggedItem = findChild(launcher, "launcherDelegate5")
            var item0 = findChild(launcher, "launcherDelegate0")
            var fakeDragItem = findChild(launcher, "fakeDragItem")
            var quickListShape = findChild(launcher, "quickListShape")

            // Initial state
            compare(quickListShape.visible, false)

            // Doing longpress
            mousePress(draggedItem)
            tryCompare(fakeDragItem, "visible", true) // Wait longpress happening
            tryCompare(quickListShape, "visible", true)

            // Dragging a bit (> 1.5 gu)
            mouseMove(draggedItem, -units.gu(2), draggedItem.height / 2)

            // QuickList needs to be closed when a drag operation starts
            tryCompare(quickListShape, "visible", false)

            mouseRelease(draggedItem);
        }

        function test_launcher_dismiss() {
            dragLauncherIntoView();
            verify(launcher.state == "visible");

            clickThroughTester.pressCount = 0;
            mouseClick(root, root.width / 2, units.gu(1));
            waitUntilLauncherDisappears();
            verify(launcher.state == "");
            compare(clickThroughTester.pressCount, 1);

            // and repeat, as a test for regression in lpbug#1531339
            dragLauncherIntoView();
            verify(launcher.state == "visible");
            clickThroughTester.pressCount = 0;
            mouseClick(root, root.width / 2, units.gu(1));
            waitUntilLauncherDisappears();
            verify(launcher.state == "");
            compare(clickThroughTester.pressCount, 1);
        }

        function test_quicklist_positioning_data() {
            return [
                {tag: "top", flickTo: "top", itemIndex: 0},
                {tag: "bottom", flickTo: "bottom", itemIndex: 9}
            ];
        }

        function test_quicklist_positioning(data) {
            dragLauncherIntoView();
            var quickList = findChild(launcher, "quickList")
            var draggedItem = findChild(launcher, "launcherDelegate" + data.itemIndex)
            var quickListShape = findChild(launcher, "quickListShape")

            // Position launcher to where we need it
            var listView = findChild(launcher, "launcherListView");
            if (data.flickTo == "top") {
                positionLauncherListAtBeginning();
            } else {
                positionLauncherListAtEnd();
            }

            // Doing longpress
            mousePress(draggedItem);
            tryCompare(quickListShape, "opacity", 0.95);
            mouseRelease(draggedItem);

            verify(quickList.y >= units.gu(1));
            verify(quickList.y + quickList.height + units.gu(1) <= launcher.height);
            compare(quickList.width, units.gu(30));

            // Click somewhere in the empty space to dismiss the quicklist
            mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
            tryCompare(quickListShape, "visible", false);

            // Click somewhere in the empty space to dismiss the launcher
            mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
            waitUntilLauncherDisappears();
        }

        function test_quicklist_click_data() {
            return [
                {tag: "non-clickable", index: 1, clickable: false },
                {tag: "clickable", index: 2, clickable: true },
            ];
        }

        function test_quicklist_click(data) {
            dragLauncherIntoView();
            var clickedItem = findChild(launcher, "launcherDelegate5")
            var quickList = findChild(launcher, "quickList")
            var quickListShape = findChild(launcher, "quickListShape")

            // Initial state
            tryCompare(quickListShape, "visible", false)

            // Doing longpress
            mousePress(clickedItem)
            tryCompare(clickedItem, "itemOpacity", 0) // Wait for longpress to happen
            verify(quickListShape.visible, "QuickList must be visible")

            mouseRelease(clickedItem);

            var quickListEntry = findChild(quickList, "quickListEntry" + data.index)

            signalSpy.signalName = "quickListTriggered"

            mouseClick(quickListEntry)

            if (data.clickable) {
                // QuickList needs to be closed when some clickable item is clicked
                tryCompare(quickListShape, "visible", false)

                compare(signalSpy.count, 1, "Quicklist signal wasn't triggered")
                compare(signalSpy.signalArguments[0][0], LauncherModel.get(5).appId)
                compare(signalSpy.signalArguments[0][1], 2)

            } else {

                // QuickList must not be closed when a non-clickable item is clicked
                verify(quickListShape.visible, "QuickList must be visible")

                compare(signalSpy.count, 0, "Quicklist signal must NOT be triggered when clicking a non-clickable item")

                // Click somewhere in the empty space to dismiss the quicklist
                mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
                tryCompare(quickListShape, "visible", false)
            }
        }

        function test_quicklistHideOnLauncherHide() {
            dragLauncherIntoView();
            var clickedItem = findChild(launcher, "launcherDelegate5")
            var quickList = findChild(launcher, "quickList")

            // Initial state
            tryCompare(quickList, "state", "")

            // Doing longpress
            mousePress(clickedItem)
            tryCompare(clickedItem, "itemOpacity", 0) // Wait for longpress to happen
            verify(quickList, "state", "open")

            launcher.hide();

            tryCompare(quickList, "state", "");
        }

        function test_quickListMenuOnRMB() {
            dragLauncherIntoView();
            var clickedItem = findChild(launcher, "launcherDelegate5")
            var quickList = findChild(launcher, "quickList")
            var quickListShape = findChild(launcher, "quickListShape")
            var dndArea = findChild(launcher, "dndArea");

            // Initial state
            tryCompare(quickListShape, "visible", false)

            // Doing RMB click
            mouseClick(clickedItem, clickedItem.width / 2, clickedItem.height / 2, Qt.RightButton)
            tryCompare(quickListShape, "visible", true)
            verify(quickList, "state", "open")
            verify(dndArea, "dragging", false)

            // Click somewhere in the empty space to dismiss the quicklist
            mouseClick(launcher, launcher.width - units.gu(1), units.gu(1));
            tryCompare(quickListShape, "visible", false);
            verify(quickList, "state", "")
        }

        function test_revealByEdgePush() {
            var panel = findChild(launcher, "launcherPanel");
            verify(!!panel);

            revealByEdgePush();
            compare(launcher.state, "visibleTemporary");

            // Now move the mouse away and make sure it hides in less than a second
            mouseMove(root, root.width, root.height / 2)

            // trigger the hide timer
            compare(fakeDismissTimer.running, true);
            fakeDismissTimer.triggered();
            tryCompare(panel, "x", 0);

            tryCompare(launcher, "state", "", 1000, "Launcher didn't hide after moving mouse away from it");
            waitUntilLauncherDisappears();
        }

        function test_progressChangeViaModel() {
            dragLauncherIntoView();
            var item = findChild(launcher, "launcherDelegate0")
            verify(item != undefined)
            LauncherModel.setProgress(LauncherModel.get(0).appId, -1)
            compare(findChild(item, "progressOverlay").visible, false)
            LauncherModel.setProgress(LauncherModel.get(0).appId, 20)
            compare(findChild(item, "progressOverlay").visible, true)
            LauncherModel.setProgress(LauncherModel.get(0).appId, 0)
        }

        function test_alertPeekingIcon() {
            var listView = findChild(launcher, "launcherListView")
            verify(listView != undefined)
            LauncherModel.setAlerting(LauncherModel.get(5).appId, true)
            tryCompare(listView, "peekingIndex", 5, 1000, "Wrong appId set as peeking-index")
            LauncherModel.setAlerting(LauncherModel.get(5).appId, false)
            tryCompare(listView, "peekingIndex", -1, 1000, "peeking-index should be -1")
        }

        function test_alertHidingIcon() {
            var listView = findChild(launcher, "launcherListView")
            verify(listView != undefined)
            var appIcon6 = findChild(launcher, "launcherDelegate6")
            verify(appIcon6 != undefined)
            LauncherModel.setAlerting(LauncherModel.get(6).appId, true)
            waitForWiggleToStart(appIcon6)
            LauncherModel.setAlerting(LauncherModel.get(6).appId, false)
            waitForWiggleToStop(appIcon6)
            tryCompare(appIcon6, "x", 0, 1000, "x-value of appId #6 should not be non-zero")
            waitForRendering(listView)
        }

        function test_alertIgnoreFocusedApp() {
            LauncherModel.setAlerting(LauncherModel.get(0).appId, true)
            compare(LauncherModel.get(0).alerting, false, "Focused app should not have the alert-state set")
        }

        function test_alertOnlyOnePeekingIcon() {
            var listView = findChild(launcher, "launcherListView")
            verify(listView != undefined)
            LauncherModel.setAlerting(LauncherModel.get(3).appId, true)
            LauncherModel.setAlerting(LauncherModel.get(1).appId, true)
            LauncherModel.setAlerting(LauncherModel.get(5).appId, true)
            tryCompare(listView, "peekingIndex", 3, 1000, "Wrong appId set as peeking-index")
            LauncherModel.setAlerting(LauncherModel.get(1).appId, false)
            LauncherModel.setAlerting(LauncherModel.get(3).appId, false)
            LauncherModel.setAlerting(LauncherModel.get(5).appId, false)
            tryCompare(listView, "peekingIndex", -1, 1000, "peeking-index should be -1")
            waitForRendering(listView)
        }

        function test_alertMultipleApps() {
            LauncherModel.setAlerting(LauncherModel.get(1).appId, true)
            LauncherModel.setAlerting(LauncherModel.get(3).appId, true)
            LauncherModel.setAlerting(LauncherModel.get(5).appId, true)
            LauncherModel.setAlerting(LauncherModel.get(7).appId, true)
            compare(LauncherModel.get(1).alerting, true, "Alert-state of appId #1 should not be false")
            compare(LauncherModel.get(3).alerting, true, "Alert-state of appId #3 should not be false")
            compare(LauncherModel.get(5).alerting, true, "Alert-state of appId #5 should not be false")
            compare(LauncherModel.get(7).alerting, true, "Alert-state of appId #7 should not be false")
            LauncherModel.setAlerting(LauncherModel.get(1).appId, false)
            LauncherModel.setAlerting(LauncherModel.get(3).appId, false)
            LauncherModel.setAlerting(LauncherModel.get(5).appId, false)
            LauncherModel.setAlerting(LauncherModel.get(7).appId, false)
            compare(LauncherModel.get(1).alerting, false, "Alert-state of appId #1 should not be true")
            compare(LauncherModel.get(3).alerting, false, "Alert-state of appId #1 should not be true")
            compare(LauncherModel.get(5).alerting, false, "Alert-state of appId #1 should not be true")
            compare(LauncherModel.get(7).alerting, false, "Alert-state of appId #1 should not be true")
        }

        function test_alertMoveIconIntoView() {
            dragLauncherIntoView();
            var appIcon1 = findChild(launcher, "launcherDelegate1");
            var appIcon7 = findChild(launcher, "launcherDelegate7");
            LauncherModel.setAlerting(LauncherModel.get(1).appId, true)
            tryCompare(appIcon1, "angle", 0, 1000, "angle of appId #1 should not be non-zero")
            waitForWiggleToStart(appIcon1)
            LauncherModel.setAlerting(LauncherModel.get(7).appId, true)
            tryCompare(appIcon7, "angle", 0, 1000, "angle of appId #7 should not be non-zero")
            waitForWiggleToStart(appIcon7)
            LauncherModel.setAlerting(LauncherModel.get(1).appId, false)
            waitForWiggleToStop(appIcon1)
            LauncherModel.setAlerting(LauncherModel.get(7).appId, false)
            waitForWiggleToStop(appIcon7)
        }

        function test_alertWigglePeekDrag() {
            var appIcon5 = findChild(launcher, "launcherDelegate5");
            var listView = findChild(launcher, "launcherListView")
            verify(listView != undefined)
            LauncherModel.setAlerting(LauncherModel.get(5).appId, true)
            tryCompare(listView, "peekingIndex", 5, 1000, "Wrong appId set as peeking-index")
            waitForWiggleToStart(appIcon5)
            tryCompare(appIcon5, "wiggling", true, 1000, "appId #6 should not be still")
            dragLauncherIntoView();
            tryCompare(listView, "peekingIndex", -1, 1000, "peeking-index should be -1")
            LauncherModel.setAlerting(LauncherModel.get(5).appId, false)
            waitForWiggleToStop(appIcon5)
            tryCompare(appIcon5, "wiggling", false, 1000, "appId #1 should not be wiggling")
        }

        function test_alertViaCountAndCountVisible() {
            dragLauncherIntoView();
            var appIcon1 = findChild(launcher, "launcherDelegate1")
            var oldCount = LauncherModel.get(1).count
            LauncherModel.setCount(LauncherModel.get(1).appId, 42)
            tryCompare(appIcon1, "wiggling", false, 1000, "appId #1 should be still")
            LauncherModel.setCountVisible(LauncherModel.get(1).appId, 1)
            tryCompare(appIcon1, "wiggling", true, 1000, "appId #1 should not be still")
            LauncherModel.setAlerting(LauncherModel.get(1).appId, false)
            waitForWiggleToStop(appIcon1)
            LauncherModel.setCount(LauncherModel.get(1).appId, 4711)
            tryCompare(appIcon1, "wiggling", true, 1000, "appId #1 should not be still")
            LauncherModel.setAlerting(LauncherModel.get(1).appId, false)
            waitForWiggleToStop(appIcon1)
            LauncherModel.setCountVisible(LauncherModel.get(1).appId, 0)
            LauncherModel.setCount(LauncherModel.get(1).appId, oldCount)
        }

        function test_longpressSuperKeyShowsHints() {
            var shortCutHint0 = findChild(findChild(launcher, "launcherDelegate0"), "shortcutHint");

            tryCompare(shortCutHint0, "visible", false);

            launcher.superPressed = true;
            tryCompare(launcher, "state", "visible");
            tryCompare(shortCutHint0, "visible", true);

            launcher.superPressed = false;
            tryCompare(launcher, "state", "");
            tryCompare(shortCutHint0, "visible", false);
        }

        function test_keyboardNavigation_data() {
            return [
                {tag: "right key", key: Qt.Key_Right},
                {tag: "menu key", key: Qt.Key_Menu}
            ]
        }

        function test_keyboardNavigation(data) {
            var bfbFocusHighlight = findChild(launcher, "bfbFocusHighlight");
            var quickList = findChild(launcher, "quickList");
            var launcherPanel = findChild(launcher, "launcherPanel");
            var launcherListView = findChild(launcher, "launcherListView");
            var last = launcherListView.count - 1;

            compare(bfbFocusHighlight.visible, false);
            launcher.openForKeyboardNavigation();
            tryCompare(launcherPanel, "x", 0);
            waitForRendering(launcher);

            assertFocusOnIndex(-1);

            // Down should go down
            keyClick(Qt.Key_Down);
            assertFocusOnIndex(0);

            // Tab should go down
            keyClick(Qt.Key_Tab);
            assertFocusOnIndex(1);

            // Up should go up
            keyClick(Qt.Key_Up);
            assertFocusOnIndex(0);

            // Backtab should go up
            keyClick(Qt.Key_Backtab);
            assertFocusOnIndex(-1); // BFB

            // The list should wrap around
            keyClick(Qt.Key_Up);
            waitForRendering(launcher);
            assertFocusOnIndex(last);

            keyClick(Qt.Key_Down);
            waitForRendering(launcher);
            keyClick(Qt.Key_Down);
            assertFocusOnIndex(0); // Back to Top

            // Right opens the quicklist
            keyClick(data.key);
            assertFocusOnIndex(0); // Navigating the quicklist... the launcher focus should not move
            tryCompare(quickList, "visible", true);
            tryCompare(quickList, "selectedIndex", 0)

            // Down should move down the quicklist
            keyClick(Qt.Key_Down);
            tryCompare(quickList, "selectedIndex", 1)

            // The quicklist should wrap around too
            keyClick(Qt.Key_Down);
            keyClick(Qt.Key_Down);
            keyClick(Qt.Key_Down);
            tryCompare(quickList, "selectedIndex", 0)

            // Left gets us back to the launcher
            keyClick(Qt.Key_Left);
            assertFocusOnIndex(0);
            tryCompare(quickList, "visible", false);

            // Launcher navigation should still work
            // Go bar to top by wrapping around
            keyClick(Qt.Key_Down);
            assertFocusOnIndex(1);

            keyClick(Qt.Key_Enter);
            assertFocusOnIndex(-2);
        }

        function test_selectQuicklistItemByKeyboard() {
            launcher.openForKeyboardNavigation();
            waitForRendering(launcher);

            signalSpy.signalName = "quickListTriggered"

            keyClick(Qt.Key_Down); // Down to launcher item 0
            keyClick(Qt.Key_Down); // Down to launcher item 1
            keyClick(Qt.Key_Right); // Into quicklist
            keyClick(Qt.Key_Down); // Down to quicklist item 1
            keyClick(Qt.Key_Down); // Down to quicklist item 2
            keyClick(Qt.Key_Enter); // Trigger it

            compare(signalSpy.count, 1, "Quicklist signal wasn't triggered")
            compare(signalSpy.signalArguments[0][0], LauncherModel.get(1).appId)
            compare(signalSpy.signalArguments[0][1], 2)
            assertFocusOnIndex(-2);
        }

        function test_hideNotWorkingWhenLockedOut_data() {
            return [
                {tag: "locked visible", locked: true},
                {tag: "no locked visible", locked: false},
            ]
        }

        function test_hideNotWorkingWhenLockedOut(data) {
            launcher.lockedVisible = data.locked;
            if (data.locked) {
                tryCompare(launcher, "state", "visible");
            } else {
                tryCompare(launcher, "state", "");
            }

            launcher.hide();
            waitForRendering(launcher);
            if (data.locked) {
                verify(launcher.state == "visible");
            } else {
                verify(launcher.state == "");
            }
        }

        function test_cancelKbdNavigationWitMouse_data() {
            return [
                        {tag: "locked out - no quicklist", autohide: false, withQuickList: false },
                        {tag: "locked out - with quicklist", autohide: false, withQuickList: true },
                        {tag: "autohide - no quicklist", autohide: true, withQuickList: false },
                        {tag: "autohide - with quicklist", autohide: true, withQuickList: true },
            ]
        }

        function test_cancelKbdNavigationWitMouse(data) {
            launcher.autohideEnabled = data.autohide;
            launcher.openForKeyboardNavigation();
            waitForRendering(launcher);

            var launcherPanel = findChild(launcher, "launcherPanel");
            tryCompare(launcherPanel, "x", 0);

            var quickList = findChild(launcher, "quickList");

            keyClick(Qt.Key_Down); // Down to launcher item 0
            keyClick(Qt.Key_Down); // Down to launcher item 1

            if (data.withQuickList) {
                keyClick(Qt.Key_Right); // Into quicklist
                tryCompare(quickList, "visible", true)
            }
            waitForRendering(launcher)

            mouseClick(root);

            if (data.autohide) {
                tryCompare(launcher, "state", "");
            } else {
                tryCompare(launcher, "state", "visible");
            }

            assertFocusOnIndex(-2);
        }

        function test_surfaceCountPips() {
            var launcherListView = findChild(launcher, "launcherListView")
            var moveAnimation = findInvisibleChild(launcherListView, "moveAnimation")

            for (var i = 0; i < launcherListView.count; i++) {
                launcherListView.moveToIndex(i);
                waitForRendering(launcherListView);
                tryCompare(moveAnimation, "running", false);

                var delegate = findChild(launcher, "launcherDelegate" + i);
                var surfacePipRepeater = findInvisibleChild(delegate, "surfacePipRepeater");
                compare(surfacePipRepeater.model, Math.min(3, LauncherModel.get(i).surfaceCount))
            }
        }

        function test_preventMouseEventsThru() {
            dragLauncherIntoView();
            var launcherPanel = findChild(launcher, "launcherPanel");
            tryCompare(launcherPanel, "visible", true);

            clickThroughSpy.signalName = "wheel";
            mouseWheel(launcherPanel, launcherPanel.width/2, launcherPanel.height/2, 10, 10);
            tryCompare(clickThroughSpy, "count", 0);

            clickThroughSpy.clear();
            clickThroughSpy.signalName = "clicked";
            mouseWheel(launcherPanel, launcherPanel.width/2, launcherPanel.height/2, Qt.RightButton);
            tryCompare(clickThroughSpy, "count", 0);
        }

        function test_launcherEnabledSetting() {
            launcher.available = true;

            dragLauncherIntoView();
            var launcherPanel = findChild(launcher, "launcherPanel");
            compare(launcherPanel.x, 0);

            launcher.available = true;
        }

        function test_launcherDisabledSetting() {
            launcher.available = false;

            //We don't actually care that it's visible, so juct use dragLauncher() rather than dragLauncherIntoView()
            dragLauncher();
            var launcherPanel = findChild(launcher, "launcherPanel");
            compare(launcherPanel.x, -launcherPanel.width);

            launcher.available = true;
        }
    }
}