@@ -350,7 +350,9 @@ Rectangle {
350350 target: fullscreenAppCheck
351351 when: topLevelSurfaceList && topLevelSurfaceList.focusedWindow
352352 property: "checked"
353− value: topLevelSurfaceList.focusedWindow.state == Mir.FullscreenState
353+ value: topLevelSurfaceList &&
354+ topLevelSurfaceList.focusedWindow &&
355+ topLevelSurfaceList.focusedWindow.state == Mir.FullscreenState
354356 }
355357 }
356358 Label {
@@ -378,7 +380,9 @@ Rectangle {
378380 target: chromeAppCheck
379381 when: topLevelSurfaceList && topLevelSurfaceList.focusedWindow !== null && topLevelSurfaceList.focusedWindow.surface !== null
380382 property: "checked"
381− value: topLevelSurfaceList.focusedWindow.surface &&
383+ value: topLevelSurfaceList &&
384+ topLevelSurfaceList.focusedWindow &&
385+ topLevelSurfaceList.focusedWindow.surface &&
382386 topLevelSurfaceList.focusedWindow.surface.shellChrome === Mir.LowChrome
383387 }
384388 }
@@ -596,19 +600,26 @@ Rectangle {
596600 stage = findChild(shell, "stage");
597601 }
598602
599− function loadDesktopShellWithApps() {
603+ function loadDesktopShellWithApps(apps) {
604+
605+ if (apps == undefined) {
606+ apps = 7
607+ }
608+
600609 loadShell("desktop");
601610 waitForRendering(shell)
602611 shell.usageScenario = "desktop"
603612 waitForRendering(shell)
604− var app0 = ApplicationManager.startApplication("unity8-dash")
605− var app1 = ApplicationManager.startApplication("dialer-app")
606− var app2 = ApplicationManager.startApplication("morph-browser")
607− var app3 = ApplicationManager.startApplication("camera-app")
608− var app4 = ApplicationManager.startApplication("facebook-webapp")
609− var app5 = ApplicationManager.startApplication("camera-app")
610− var app6 = ApplicationManager.startApplication("gallery-app")
611− var app7 = ApplicationManager.startApplication("calendar-app")
613+ addApps(apps)
614+ }
615+
616+ function addApps(count) {
617+ // Start apps up to count, but skip unity8-dash since it's the first
618+ // available application and it's treated specially
619+ for (var i = 0; i < count; i++) {
620+ var startingAppId = ApplicationManager.availableApplications[ApplicationManager.count + 1];
621+ var app = ApplicationManager.startApplication(startingAppId)
622+ }
612623 for (var i = 0; i < topLevelSurfaceList.count; ++i) {
613624 waitUntilAppWindowIsFullyLoaded(topLevelSurfaceList.idAt(i));
614625 }
@@ -819,10 +830,6 @@ Rectangle {
819830 }
820831 }
821832
822− function waitUntilDashIsFocused() {
823− tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
824− }
825−
826833 function swipeFromLeftEdge(swipeLength) {
827834 var touchStartX = 2;
828835 var touchStartY = shell.height / 2;
@@ -1291,9 +1298,7 @@ Rectangle {
12911298 }
12921299
12931300 function test_customBackground() {
1294− loadShell("desktop");
1295− shell.usageScenario = "desktop";
1296− waitForRendering(shell);
1301+ loadDesktopShellWithApps(0);
12971302
12981303 var wallpaperResolver = findInvisibleChild(shell, "wallpaperResolver");
12991304 var greeter = findChild(shell, "greeter");
@@ -1306,9 +1311,7 @@ Rectangle {
13061311 }
13071312
13081313 function test_cachedBackground() {
1309− loadShell("desktop");
1310− shell.usageScenario = "desktop";
1311− waitForRendering(shell);
1314+ loadDesktopShellWithApps(0);
13121315
13131316 var greeter = findChild(shell, "greeter");
13141317 verify(!greeter.hasCustomBackground);
@@ -1475,10 +1478,7 @@ Rectangle {
14751478 }
14761479
14771480 function test_terminalShortcut() {
1478− loadShell("desktop");
1479− shell.usageScenario = "desktop";
1480− waitForRendering(shell);
1481− swipeAwayGreeter();
1481+ loadDesktopShellWithApps(0);
14821482
14831483 // not running, should start
14841484 keyClick(Qt.Key_T, Qt.ControlModifier|Qt.AltModifier);
@@ -1612,7 +1612,7 @@ Rectangle {
16121612 }
16131613
16141614 function test_altTabWrapAround() {
1615− loadDesktopShellWithApps();
1615+ loadDesktopShellWithApps(7);
16161616
16171617 var stage = findChild(shell, "stage");
16181618 verify(stage !== null)
@@ -1657,7 +1657,7 @@ Rectangle {
16571657 }
16581658
16591659 function test_altBackTabNavigation() {
1660− loadDesktopShellWithApps();
1660+ loadDesktopShellWithApps(5);
16611661
16621662 var spreadItem = findChild(shell, "spreadItem");
16631663 verify(spreadItem !== null);
@@ -1688,7 +1688,7 @@ Rectangle {
16881688 }
16891689
16901690 function test_highlightFollowsMouse() {
1691− loadDesktopShellWithApps()
1691+ loadDesktopShellWithApps(7)
16921692
16931693 var spreadItem = findChild(shell, "spreadItem");
16941694 verify(spreadItem !== null);
@@ -1716,7 +1716,7 @@ Rectangle {
17161716 }
17171717
17181718 function test_closeFromSpread() {
1719− loadDesktopShellWithApps()
1719+ loadDesktopShellWithApps(4)
17201720
17211721 var appRepeater = findInvisibleChild(shell, "appRepeater");
17221722 verify(appRepeater !== null);
@@ -1766,7 +1766,7 @@ Rectangle {
17661766 }
17671767
17681768 function test_selectFromSpreadWithMouse(data) {
1769− loadDesktopShellWithApps()
1769+ loadDesktopShellWithApps(4)
17701770
17711771 var stage = findChild(shell, "stage");
17721772 var spreadItem = findChild(stage, "spreadItem");
@@ -1805,7 +1805,7 @@ Rectangle {
18051805 }
18061806
18071807 function test_progressiveAutoScrolling() {
1808− loadDesktopShellWithApps()
1808+ loadDesktopShellWithApps(7)
18091809
18101810 var appRepeater = findInvisibleChild(shell, "appRepeater");
18111811 var launcherPanel = findChild(shell, "launcherPanel");
@@ -1836,7 +1836,7 @@ Rectangle {
18361836 // This makes sure the hoverMouseArea is set to invisible AND disabled
18371837 // when not needed. Otherwise it'll eat mouse hover events for the rest of the shell/apps
18381838 function test_hoverMouseAreaDisabledAndInvisible() {
1839− loadDesktopShellWithApps()
1839+ loadDesktopShellWithApps(2)
18401840
18411841 var hoverMouseArea = findChild(shell, "hoverMouseArea");
18421842 tryCompare(hoverMouseArea, "enabled", false)
@@ -1862,7 +1862,7 @@ Rectangle {
18621862 }
18631863
18641864 function test_focusAppFromLauncherExitsSpread(data) {
1865− loadDesktopShellWithApps()
1865+ loadDesktopShellWithApps(2)
18661866 var launcher = findChild(shell, "launcher");
18671867 var stage = findChild(shell, "stage");
18681868 var app1 = findChild(launcher, "launcherDelegate0");
@@ -1895,7 +1895,7 @@ Rectangle {
18951895
18961896 // regression test for http://pad.lv/1443319
18971897 function test_closeMaximizedAndRestart() {
1898− loadDesktopShellWithApps();
1898+ loadDesktopShellWithApps(7);
18991899
19001900 var appRepeater = findChild(shell, "appRepeater")
19011901 var application = topLevelSurfaceList.applicationAt(0);
@@ -1922,7 +1922,7 @@ Rectangle {
19221922 }
19231923
19241924 function test_newAppHasValidGeometry() {
1925− loadDesktopShellWithApps();
1925+ loadDesktopShellWithApps(1);
19261926 var appRepeater = findChild(shell, "appRepeater");
19271927 var appDelegate = appRepeater.itemAt(0);
19281928
@@ -1935,7 +1935,7 @@ Rectangle {
19351935
19361936 // bug http://pad.lv/1431566
19371937 function test_switchToStagedHidesPanelButtons() {
1938− loadDesktopShellWithApps();
1938+ loadDesktopShellWithApps(1);
19391939 var appRepeater = findChild(shell, "appRepeater")
19401940 var appDelegate = appRepeater.itemAt(0);
19411941 var panelButtons = findChild(shell, "panelWindowControlButtons")
@@ -1952,7 +1952,7 @@ Rectangle {
19521952 }
19531953
19541954 function test_lockingGreeterHidesPanelButtons() {
1955− loadDesktopShellWithApps();
1955+ loadDesktopShellWithApps(1);
19561956 var appRepeater = findChild(shell, "appRepeater")
19571957 var appDelegate = appRepeater.itemAt(0);
19581958 var panelButtons = findChild(shell, "panelWindowControlButtons")
@@ -1968,7 +1968,7 @@ Rectangle {
19681968 }
19691969
19701970 function test_cantMoveWindowUnderPanel() {
1971− loadDesktopShellWithApps();
1971+ loadDesktopShellWithApps(1);
19721972 var appRepeater = findChild(shell, "appRepeater")
19731973 var appDelegate = appRepeater.itemAt(0);
19741974
@@ -1979,9 +1979,7 @@ Rectangle {
19791979 }
19801980
19811981 function test_cantResizeWindowUnderPanel() {
1982− loadShell("desktop");
1983− shell.usageScenario = "desktop";
1984− waitForRendering(shell);
1982+ loadDesktopShellWithApps(0);
19851983
19861984 var appSurfaceId = topLevelSurfaceList.nextId;
19871985 var app = ApplicationManager.startApplication("dialer-app")
@@ -2007,7 +2005,7 @@ Rectangle {
20072005 }
20082006
20092007 function test_restoreWindowStateFixesIfUnderPanel() {
2010− loadDesktopShellWithApps();
2008+ loadDesktopShellWithApps(2);
20112009 var appRepeater = findChild(shell, "appRepeater")
20122010 var application = topLevelSurfaceList.applicationAt(0);
20132011 var appDelegate = appRepeater.itemAt(0);
@@ -2185,9 +2183,7 @@ Rectangle {
21852183 }
21862184
21872185 function test_superTabToCycleLauncher(data) {
2188− loadShell("desktop");
2189− shell.usageScenario = "desktop";
2190− waitForRendering(shell);
2186+ loadDesktopShellWithApps(1);
21912187 GSettingsController.setAutohideLauncher(!data.launcherLocked);
21922188 waitForRendering(shell);
21932189
@@ -2273,9 +2269,7 @@ Rectangle {
22732269 }
22742270
22752271 function test_lockedOutLauncherAddsMarginsToMaximized() {
2276− loadShell("desktop");
2277− shell.usageScenario = "desktop";
2278− waitForRendering(shell);
2272+ loadDesktopShellWithApps(1);
22792273 var appContainer = findChild(shell, "appContainer");
22802274 var launcher = findChild(shell, "launcher");
22812275 var launcherPanel = findChild(launcher, "launcherPanel");
@@ -2563,9 +2557,7 @@ Rectangle {
25632557 }
25642558
25652559 function test_dragPanelToRestoreMaximizedWindow(data) {
2566− loadShell("desktop");
2567− shell.usageScenario = "desktop";
2568− waitForRendering(shell);
2560+ loadDesktopShellWithApps(0);
25692561 var panel = findChild(shell, "windowControlArea");
25702562 verify(panel);
25712563
@@ -2644,10 +2636,7 @@ Rectangle {
26442636 }
26452637
26462638 function test_rightEdgePushWithOpenIndicators() {
2647− loadShell("desktop");
2648− shell.usageScenario = "desktop";
2649− waitForRendering(shell);
2650− swipeAwayGreeter();
2639+ loadDesktopShellWithApps(1);
26512640
26522641 var stage = findChild(shell, "stage");
26532642 var cursor = findChild(shell, "cursor");
@@ -2695,10 +2684,7 @@ Rectangle {
26952684 }
26962685
26972686 function test_oskDisplacesWindow(data) {
2698− loadShell("desktop");
2699− shell.usageScenario = "desktop";
2700− waitForRendering(shell);
2701− swipeAwayGreeter();
2687+ loadDesktopShellWithApps(0);
27022688 ensureInputMethodSurface();
27032689 shell.oskEnabled = data.oskEnabled;
27042690
@@ -2905,10 +2891,7 @@ Rectangle {
29052891 }
29062892
29072893 function test_fourFingerTapOpensDrawer(data) {
2908− loadShell("desktop");
2909− shell.usageScenario = "desktop";
2910− waitForRendering(shell);
2911− swipeAwayGreeter();
2894+ loadDesktopShellWithApps(1);
29122895
29132896 var stage = findChild(shell, "stage");
29142897 var drawer = findChild(shell, "drawer")
@@ -2924,10 +2907,7 @@ Rectangle {
29242907 }
29252908
29262909 function test_restoreFromFullscreen() {
2927− loadShell("desktop");
2928− shell.usageScenario = "desktop";
2929− waitForRendering(shell);
2930− swipeAwayGreeter();
2910+ loadDesktopShellWithApps(0);
29312911
29322912 var appSurfaceId = topLevelSurfaceList.nextId;
29332913 var app = ApplicationManager.startApplication("dialer-app")
@@ -2954,10 +2934,7 @@ Rectangle {
29542934
29552935
29562936 function test_closeAppsInSpreadWithQ() {
2957− loadShell("desktop");
2958− shell.usageScenario = "desktop";
2959− waitForRendering(shell);
2960− swipeAwayGreeter();
2937+ loadDesktopShellWithApps(0);
29612938
29622939 var appSurfaceId = topLevelSurfaceList.nextId;
29632940 var app = ApplicationManager.startApplication("unity8-dash")
@@ -3031,10 +3008,7 @@ Rectangle {
30313008 }
30323009
30333010 function test_altTabToMinimizedApp() {
3034− loadShell("desktop");
3035− shell.usageScenario = "desktop";
3036− waitForRendering(shell);
3037− swipeAwayGreeter();
3011+ loadDesktopShellWithApps(0);
30383012
30393013 var appSurfaceId = topLevelSurfaceList.nextId;
30403014 var app = ApplicationManager.startApplication("dialer-app")
@@ -3066,10 +3040,7 @@ Rectangle {
30663040 }
30673041
30683042 function test_touchMenuPosition(data) {
3069− loadShell("desktop");
3070− shell.usageScenario = "desktop";
3071− waitForRendering(shell);
3072− swipeAwayGreeter();
3043+ loadDesktopShellWithApps(0);
30733044
30743045 var panel = findChild(shell, "panel");
30753046 var launcher = testCase.findChild(shell, "launcher");
@@ -3089,10 +3060,7 @@ Rectangle {
30893060 }
30903061
30913062 function test_touchMenuHidesOnLauncherAppDrawer(data) {
3092− loadShell("desktop");
3093− shell.usageScenario = "desktop";
3094− waitForRendering(shell);
3095− swipeAwayGreeter();
3063+ loadDesktopShellWithApps(1);
30963064
30973065 var panel = findChild(shell, "panel");
30983066 var launcher = testCase.findChild(shell, "launcher");
@@ -3114,10 +3082,7 @@ Rectangle {
31143082 }
31153083
31163084 function test_doubleClickPanelRestoresWindow() {
3117− loadShell("desktop");
3118− shell.usageScenario = "desktop";
3119− waitForRendering(shell);
3120− swipeAwayGreeter();
3085+ loadDesktopShellWithApps(0);
31213086
31223087 // start dialer
31233088 var appDelegate = startApplication("dialer-app")
@@ -3138,10 +3103,7 @@ Rectangle {
31383103 }
31393104
31403105 function test_noMenusWithActiveCall() {
3141− loadShell("desktop");
3142− shell.usageScenario = "desktop";
3143− waitForRendering(shell);
3144− swipeAwayGreeter();
3106+ loadDesktopShellWithApps(0);
31453107
31463108 // start music-app, maximize it
31473109 var appDelegate = startApplication("music-app")
@@ -3172,10 +3134,7 @@ Rectangle {
31723134 }
31733135
31743136 function test_enforceFocusOnStageOnAltTab() {
3175− loadShell("desktop");
3176− shell.usageScenario = "desktop";
3177− waitForRendering(shell);
3178− swipeAwayGreeter();
3137+ loadDesktopShellWithApps(0);
31793138
31803139 var appSurfaceId = topLevelSurfaceList.nextId;
31813140 var app = ApplicationManager.startApplication("unity8-dash")
@@ -3215,10 +3174,7 @@ Rectangle {
32153174 }
32163175
32173176 function test_maximizedWindowMenuThenAltTab(data) {
3218− loadShell("desktop");
3219− shell.usageScenario = "desktop";
3220− waitForRendering(shell);
3221− swipeAwayGreeter();
3177+ loadDesktopShellWithApps(0);
32223178
32233179 var appDelegate = startApplication("gmail-webapp");
32243180 var appDelegate2 = startApplication("dialer-app");
@@ -3262,10 +3218,7 @@ Rectangle {
32623218 }
32633219
32643220 function test_launchFromDrawerPutsFocusOnStage() {
3265− loadShell("desktop");
3266− shell.usageScenario = "desktop";
3267− waitForRendering(shell);
3268− swipeAwayGreeter();
3221+ loadDesktopShellWithApps(1);
32693222
32703223 keyClick(Qt.Key_A, Qt.MetaModifier);
32713224 typeString("browser");
@@ -3276,10 +3229,7 @@ Rectangle {
32763229 }
32773230
32783231 function test_maximizedWindowAndMenuInPanel() {
3279− loadShell("desktop");
3280− shell.usageScenario = "desktop";
3281− waitForRendering(shell);
3282− swipeAwayGreeter();
3232+ loadDesktopShellWithApps(0);
32833233
32843234 // start music-app, maximize it
32853235 var appDelegate = startApplication("music-app")