@@ -1,5 +1,5 @@
2− * Copyright (C) 2013-2015 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -185,6 +185,17 @@ Rectangle {
189+ text: "Show Launcher"
190+ activeFocusOnPress: false
192+ if (shellLoader.status !== Loader.Ready)
195+ var launcher = testCase.findChild(shellLoader.item, "launcher");
196+ launcher.state = "visible";
188 ListItem.ItemSelector {
199 ListItem.ItemSelector {
189 anchors { left: parent.left; right: parent.right }
200 anchors { left: parent.left; right: parent.right }
190 activeFocusOnPress: false
201 activeFocusOnPress: false
@@ -381,12 +392,6 @@ Rectangle {
381 signalName: "actionInvoked"
392 signalName: "actionInvoked"
386− target: ApplicationManager
387− signalName: "applicationRemoved"
390 Telephony.CallEntry {
395 Telephony.CallEntry {
391 id: phoneCall
396 id: phoneCall
392 phoneNumber: "+447812221111"
397 phoneNumber: "+447812221111"
@@ -412,6 +417,7 @@ Rectangle {
412 when: windowShown
417 when: windowShown
414 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
419 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
420+ property QtObject topLevelSurfaceList: null
416 function init() {
422 function init() {
417 if (shellLoader.active) {
423 if (shellLoader.active) {
@@ -449,6 +455,9 @@ Rectangle {
449 panel.dismissTimer = fakeDismissTimer;
455 panel.dismissTimer = fakeDismissTimer;
451 waitForGreeterToStabilize();
457 waitForGreeterToStabilize();
459+ topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
460+ verify(topLevelSurfaceList);
454 function loadDesktopShellWithApps() {
463 function loadDesktopShellWithApps() {
@@ -463,7 +472,9 @@ Rectangle {
463 var app5 = ApplicationManager.startApplication("camera-app")
472 var app5 = ApplicationManager.startApplication("camera-app")
464 var app6 = ApplicationManager.startApplication("gallery-app")
473 var app6 = ApplicationManager.startApplication("gallery-app")
465 var app7 = ApplicationManager.startApplication("calendar-app")
474 var app7 = ApplicationManager.startApplication("calendar-app")
475+ for (var i = 0; i < topLevelSurfaceList.count; ++i) {
466− waitUntilAppWindowIsFullyLoaded(app7);
476+ waitUntilAppWindowIsFullyLoaded(topLevelSurfaceList.idAt(i));
469 function waitForGreeterToStabilize() {
480 function waitForGreeterToStabilize() {
@@ -503,7 +514,7 @@ Rectangle {
503 Wizard.System.wizardEnabled = false;
514 Wizard.System.wizardEnabled = false;
505 // kill all (fake) running apps
516 // kill all (fake) running apps
506− killApps(ApplicationManager);
517+ killApps();
508 unlockAllModemsSpy.clear()
519 unlockAllModemsSpy.clear()
509 LightDM.Greeter.authenticate(""); // reset greeter
520 LightDM.Greeter.authenticate(""); // reset greeter
@@ -511,14 +522,10 @@ Rectangle {
511 sessionSpy.clear();
522 sessionSpy.clear();
513 GSettingsController.setLifecycleExemptAppids([]);
524 GSettingsController.setLifecycleExemptAppids([]);
516− function killApps() {
526+ // there should be only unity8-dash window over there
517− while (ApplicationManager.count > 1) {
527+ tryCompare(ApplicationManager, "count", 1);
518− var appIndex = ApplicationManager.get(0).appId == "unity8-dash" ? 1 : 0
519− ApplicationManager.stopApplication(ApplicationManager.get(appIndex).appId);
521− compare(ApplicationManager.count, 1)
528+ compare(ApplicationManager.get(0).appId, "unity8-dash");
524 function test_snapDecisionDismissalReturnsFocus() {
531 function test_snapDecisionDismissalReturnsFocus() {
@@ -527,10 +534,13 @@ Rectangle {
527 var notifications = findChild(shell, "notificationList");
534 var notifications = findChild(shell, "notificationList");
528 var app = ApplicationManager.startApplication("camera-app");
535 var app = ApplicationManager.startApplication("camera-app");
529 var stage = findChild(shell, "stage")
536 var stage = findChild(shell, "stage")
530− // Open an application and focus
537+ // Open an application
531 waitUntilApplicationWindowIsFullyVisible(app);
538 waitUntilApplicationWindowIsFullyVisible(app);
532− ApplicationManager.focusApplication(app);
539+
540+ var appSurface = app.surfaceList.get(0);
533− tryCompare(app.session.lastSurface, "activeFocus", true);
543+ tryCompare(appSurface, "activeFocus", true);
535 notifications.model = mockNotificationsModel;
545 notifications.model = mockNotificationsModel;
@@ -552,7 +562,7 @@ Rectangle {
552 waitForRendering(notification);
562 waitForRendering(notification);
554 // Make sure activeFocus went away from the app window
564 // Make sure activeFocus went away from the app window
555− tryCompare(app.session.lastSurface, "activeFocus", false);
565+ tryCompare(appSurface, "activeFocus", false);
556 tryCompare(stage, "interactive", false);
566 tryCompare(stage, "interactive", false);
558 // Clicking the button should dismiss the notification and return focus
568 // Clicking the button should dismiss the notification and return focus
@@ -560,7 +570,7 @@ Rectangle {
560 mouseClick(buttonAccept);
570 mouseClick(buttonAccept);
562 // Make sure we're back to normal
572 // Make sure we're back to normal
563− tryCompare(app.session.lastSurface, "activeFocus", true);
573+ tryCompare(appSurface, "activeFocus", true);
564 compare(stage.interactive, true, "Stages not interactive again after modal notification has closed");
574 compare(stage.interactive, true, "Stages not interactive again after modal notification has closed");
@@ -644,9 +654,12 @@ Rectangle {
644 var launcher = findChild(shell, "launcherPanel");
654 var launcher = findChild(shell, "launcherPanel");
645 tryCompare(launcher, "x", data.launcherHides ? -launcher.width : 0)
655 tryCompare(launcher, "x", data.launcherHides ? -launcher.width : 0)
657+ //FIXME: This check fails. Don't understand the rationale behind it.
647 // Make sure the helper for sliding out the launcher wasn't touched. We want to fade it out here.
659 // Make sure the helper for sliding out the launcher wasn't touched. We want to fade it out here.
648 var animateTimer = findInvisibleChild(shell, "animateTimer");
660 var animateTimer = findInvisibleChild(shell, "animateTimer");
649 compare(animateTimer.nextState, "visible");
661 compare(animateTimer.nextState, "visible");
652 function test_tabletLeftEdgeDrag_data() {
665 function test_tabletLeftEdgeDrag_data() {
@@ -873,10 +886,22 @@ Rectangle {
873 tryCompare(item, "visible", false);
886 tryCompare(item, "visible", false);
889+ function findAppWindowForSurfaceId(surfaceId) {
890+ // for PhoneStage and TabletStage
891+ var delegate = findChild(shell, "spreadDelegate_" + surfaceId);
894+ delegate = findChild(shell, "appDelegate_" + surfaceId);
897+ var appWindow = findChild(delegate, "appWindow");
876 // Wait until the ApplicationWindow for the given Application object is fully loaded
901 // Wait until the ApplicationWindow for the given Application object is fully loaded
877 // (ie, the real surface has replaced the splash screen)
902 // (ie, the real surface has replaced the splash screen)
878− function waitUntilAppWindowIsFullyLoaded(app) {
903+ function waitUntilAppWindowIsFullyLoaded(surfaceId) {
879− var appWindow = findChild(shell, "appWindow_" + app.appId);
904+ var appWindow = findAppWindowForSurfaceId(surfaceId);
880 var appWindowStateGroup = findInvisibleChild(appWindow, "applicationWindowStateGroup");
905 var appWindowStateGroup = findInvisibleChild(appWindow, "applicationWindowStateGroup");
881 tryCompareFunction(function() { return appWindowStateGroup.state === "surface" }, true);
906 tryCompareFunction(function() { return appWindowStateGroup.state === "surface" }, true);
882 waitUntilTransitionsEnd(appWindowStateGroup);
907 waitUntilTransitionsEnd(appWindowStateGroup);
@@ -885,10 +910,13 @@ Rectangle {
885 function test_surfaceLosesActiveFocusWhilePanelIsOpen() {
910 function test_surfaceLosesActiveFocusWhilePanelIsOpen() {
886 loadShell("phone");
911 loadShell("phone");
887 swipeAwayGreeter();
912 swipeAwayGreeter();
913+ var appSurfaceId = topLevelSurfaceList.nextId;
888 var app = ApplicationManager.startApplication("dialer-app");
914 var app = ApplicationManager.startApplication("dialer-app");
889− waitUntilAppWindowIsFullyLoaded(app);
915+ waitUntilAppWindowIsFullyLoaded(appSurfaceId);
916+ var appSurface = app.surfaceList.get(0);
891− tryCompare(app.session.lastSurface, "activeFocus", true);
919+ tryCompare(appSurface, "activeFocus", true);
893 // Drag the indicators panel half-open
921 // Drag the indicators panel half-open
894 var touchX = shell.width / 2;
922 var touchX = shell.width / 2;
@@ -899,7 +927,7 @@ Rectangle {
899 true /* beginTouch */, false /* endTouch */);
927 true /* beginTouch */, false /* endTouch */);
900 verify(indicators.partiallyOpened);
928 verify(indicators.partiallyOpened);
902− tryCompare(app.session.lastSurface, "activeFocus", false);
930+ tryCompare(appSurface, "activeFocus", false);
904 // And finish getting it open
932 // And finish getting it open
905 touchFlick(indicators,
933 touchFlick(indicators,
@@ -908,11 +936,11 @@ Rectangle {
908 false /* beginTouch */, true /* endTouch */);
936 false /* beginTouch */, true /* endTouch */);
909 tryCompare(indicators, "fullyOpened", true);
937 tryCompare(indicators, "fullyOpened", true);
911− tryCompare(app.session.lastSurface, "activeFocus", false);
939+ tryCompare(appSurface, "activeFocus", false);
913 dragToCloseIndicatorsPanel();
941 dragToCloseIndicatorsPanel();
915− tryCompare(app.session.lastSurface, "activeFocus", true);
943+ tryCompare(appSurface, "activeFocus", true);
918 function test_launchedAppHasActiveFocus_data() {
946 function test_launchedAppHasActiveFocus_data() {
@@ -928,54 +956,44 @@ Rectangle {
928 shell.usageScenario = data.usageScenario;
956 shell.usageScenario = data.usageScenario;
929 swipeAwayGreeter();
957 swipeAwayGreeter();
959+ var webAppSurfaceId = topLevelSurfaceList.nextId;
931 var webApp = ApplicationManager.startApplication("webbrowser-app");
960 var webApp = ApplicationManager.startApplication("webbrowser-app");
932 verify(webApp);
961 verify(webApp);
933− waitUntilAppSurfaceShowsUp("webbrowser-app")
962+ waitUntilAppWindowIsFullyLoaded(webAppSurfaceId);
935− verify(webApp.session.lastSurface);
964+ var webAppSurface = webApp.surfaceList.get(topLevelSurfaceList.indexForId(webAppSurfaceId));
965+ verify(webAppSurface);
937− tryCompare(webApp.session.lastSurface, "activeFocus", true);
967+ tryCompare(webAppSurface, "activeFocus", true);
940 function test_launchedAppKeepsActiveFocusOnUsageModeChange() {
970 function test_launchedAppKeepsActiveFocusOnUsageModeChange() {
941 loadShell("tablet");
971 loadShell("tablet");
942 swipeAwayGreeter();
972 swipeAwayGreeter();
974+ var webAppSurfaceId = topLevelSurfaceList.nextId;
944 var webApp = ApplicationManager.startApplication("webbrowser-app");
975 var webApp = ApplicationManager.startApplication("webbrowser-app");
945 verify(webApp);
976 verify(webApp);
946− waitUntilAppSurfaceShowsUp("webbrowser-app")
977+ waitUntilAppWindowIsFullyLoaded(webAppSurfaceId);
948− verify(webApp.session.lastSurface);
979+ var webAppSurface = webApp.surfaceList.get(topLevelSurfaceList.indexForId(webAppSurfaceId));
980+ verify(webAppSurface);
950− tryCompare(webApp.session.lastSurface, "activeFocus", true);
982+ tryCompare(webAppSurface, "activeFocus", true);
952 shell.usageScenario = "desktop";
984 shell.usageScenario = "desktop";
954 // check that the desktop stage and window have been loaded
986 // check that the desktop stage and window have been loaded
955− {
987+ waitUntilAppWindowIsFullyLoaded(webAppSurfaceId);
956− var desktopWindow = findChild(shell, "appWindow_webbrowser-app");
957− verify(desktopWindow);
960− tryCompare(webApp.session.lastSurface, "activeFocus", true);
989+ tryCompare(webAppSurface, "activeFocus", true);
962 shell.usageScenario = "tablet";
991 shell.usageScenario = "tablet";
964 // check that the tablet stage and app surface delegate have been loaded
993 // check that the tablet stage and app surface delegate have been loaded
965− {
994+ waitUntilAppWindowIsFullyLoaded(webAppSurfaceId);
966− var desktopWindow = findChild(shell, "tabletSpreadDelegate_webbrowser-app");
967− verify(desktopWindow);
970− tryCompare(webApp.session.lastSurface, "activeFocus", true);
973− function waitUntilAppSurfaceShowsUp(appId) {
996+ tryCompare(webAppSurface, "activeFocus", true);
974− var appWindow = findChild(shell, "appWindow_" + appId);
976− var appWindowStates = findInvisibleChild(appWindow, "applicationWindowStateGroup");
977− verify(appWindowStates);
978− tryCompare(appWindowStates, "state", "surface");
981 function dragToCloseIndicatorsPanel() {
999 function dragToCloseIndicatorsPanel() {
@@ -1026,7 +1044,7 @@ Rectangle {
1028 function waitUntilApplicationWindowIsFullyVisible() {
1046 function waitUntilApplicationWindowIsFullyVisible() {
1029− var appDelegate = findChild(shell, "appDelegate0")
1047+ var appDelegate = findChild(shell, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
1030 var surfaceContainer = findChild(appDelegate, "surfaceContainer");
1048 var surfaceContainer = findChild(appDelegate, "surfaceContainer");
1031 tryCompareFunction(function() { return surfaceContainer.surface !== null; }, true);
1049 tryCompareFunction(function() { return surfaceContainer.surface !== null; }, true);
@@ -1088,8 +1106,7 @@ Rectangle {
1088 var greeter = findChild(shell, "greeter");
1106 var greeter = findChild(shell, "greeter");
1090 var app = ApplicationManager.startApplication("dialer-app");
1108 var app = ApplicationManager.startApplication("dialer-app");
1091− // wait until the app is fully loaded (ie, real surface replaces splash screen)
1109+ waitUntilApplicationWindowIsFullyVisible(app);
1092− tryCompareFunction(function() { return app.session !== null && app.session.lastSurface !== null }, true);
1094 // Minimize the application we just launched
1111 // Minimize the application we just launched
1095 swipeFromLeftEdge(shell.width * 0.75);
1112 swipeFromLeftEdge(shell.width * 0.75);
@@ -1150,13 +1167,15 @@ Rectangle {
1150 swipeAwayGreeter();
1167 swipeAwayGreeter();
1151 var panel = findChild(shell, "panel");
1168 var panel = findChild(shell, "panel");
1152 compare(panel.fullscreenMode, false);
1169 compare(panel.fullscreenMode, false);
1153− ApplicationManager.startApplication("camera-app");
1170+ var cameraApp = ApplicationManager.startApplication("camera-app");
1171+ waitUntilApplicationWindowIsFullyVisible(cameraApp);
1154 tryCompare(panel, "fullscreenMode", true);
1172 tryCompare(panel, "fullscreenMode", true);
1155− ApplicationManager.startApplication("dialer-app");
1173+ var dialerApp = ApplicationManager.startApplication("dialer-app");
1174+ waitUntilApplicationWindowIsFullyVisible(dialerApp);
1156 tryCompare(panel, "fullscreenMode", false);
1175 tryCompare(panel, "fullscreenMode", false);
1157− ApplicationManager.requestFocusApplication("camera-app");
1176+ ApplicationManager.requestFocusApplication(cameraApp.appId);
1158 tryCompare(panel, "fullscreenMode", true);
1177 tryCompare(panel, "fullscreenMode", true);
1159− ApplicationManager.requestFocusApplication("dialer-app");
1178+ ApplicationManager.requestFocusApplication(dialerApp.appId);
1160 tryCompare(panel, "fullscreenMode", false);
1179 tryCompare(panel, "fullscreenMode", false);
@@ -1227,24 +1246,32 @@ Rectangle {
1227 var tutorial = findChild(shell, "tutorial");
1246 var tutorial = findChild(shell, "tutorial");
1228 tryCompare(wizard, "active", true);
1247 tryCompare(wizard, "active", true);
1229 tryCompare(tutorial, "running", true);
1248 tryCompare(tutorial, "running", true);
1230− tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
1249+ tryCompareFunction(function() { return topLevelSurfaceList.applicationAt(0).appId; }, "unity8-dash");
1232− // Make sure we stay running when nothing focused (can happen for
1251+ // Make sure we stay running when there's no top level window (can happen for
1233 // a moment when we restart the dash after switching language)
1252 // a moment when we restart the dash after switching language)
1234− ApplicationManager.stopApplication("unity8-dash");
1253+ var dashApplication = ApplicationManager.findApplication("unity8-dash");
1235− tryCompare(ApplicationManager, "focusedApplicationId", "");
1254+ ApplicationManager.stopApplication(dashApplication.appId);
1255+ // wait until all zombie surfaces are gone. As MirSurfaceItems hold references over them.
1256+ // They won't be gone until those surface items are destroyed.
1257+ tryCompareFunction(function() { return dashApplication.surfaceList.count }, 0);
1259+ tryCompare(topLevelSurfaceList, "count", 0);
1236 compare(wizard.shown, true);
1260 compare(wizard.shown, true);
1237 compare(tutorial.running, true);
1261 compare(tutorial.running, true);
1239− // And make sure we stay running when dash focused again
1263+ // And make sure we stay running when dash comes back again
1264+ var dashSurfaceId = topLevelSurfaceList.nextId;
1240− ApplicationManager.startApplication("unity8-dash");
1265+ ApplicationManager.startApplication(dashApplication.appId);
1241− tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
1266+ waitUntilAppWindowIsFullyLoaded(dashSurfaceId);
1242 compare(wizard.shown, true);
1267 compare(wizard.shown, true);
1243 compare(tutorial.running, true);
1268 compare(tutorial.running, true);
1245− // And make sure we stop when something else is focused
1270+ // And make sure we stop when some other surface shows app
1271+ var gallerySurfaceId = topLevelSurfaceList.nextId;
1246− ApplicationManager.startApplication("gallery-app");
1272+ var galleryApp = ApplicationManager.startApplication("gallery-app");
1247− tryCompare(ApplicationManager, "focusedApplicationId", "gallery-app");
1273+ waitUntilAppWindowIsFullyLoaded(gallerySurfaceId);
1274+ tryCompareFunction(function() { return topLevelSurfaceList.applicationAt(0).appId; }, "gallery-app");
1248 compare(wizard.shown, false);
1275 compare(wizard.shown, false);
1249 compare(tutorial.running, false);
1276 compare(tutorial.running, false);
1250 tryCompare(AccountsService, "demoEdges", false);
1277 tryCompare(AccountsService, "demoEdges", false);
@@ -1269,7 +1296,7 @@ Rectangle {
1269 function test_tapOnRightEdgeReachesApplicationSurface() {
1296 function test_tapOnRightEdgeReachesApplicationSurface() {
1270 loadShell("phone");
1297 loadShell("phone");
1271 swipeAwayGreeter();
1298 swipeAwayGreeter();
1272− var topmostSpreadDelegate = findChild(shell, "appDelegate0");
1299+ var topmostSpreadDelegate = findChild(shell, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
1273 verify(topmostSpreadDelegate);
1300 verify(topmostSpreadDelegate);
1275 waitUntilFocusedApplicationIsShowingItsSurface();
1302 waitUntilFocusedApplicationIsShowingItsSurface();
@@ -1298,7 +1325,7 @@ Rectangle {
1298 function test_rightEdgeDragDoesNotReachApplicationSurface() {
1325 function test_rightEdgeDragDoesNotReachApplicationSurface() {
1299 loadShell("phone");
1326 loadShell("phone");
1300 swipeAwayGreeter();
1327 swipeAwayGreeter();
1301− var topmostSpreadDelegate = findChild(shell, "appDelegate0");
1328+ var topmostSpreadDelegate = findChild(shell, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
1302 var topmostSurfaceItem = findChild(topmostSpreadDelegate, "surfaceItem");
1329 var topmostSurfaceItem = findChild(topmostSpreadDelegate, "surfaceItem");
1303 var rightEdgeDragArea = findChild(shell, "spreadDragArea");
1330 var rightEdgeDragArea = findChild(shell, "spreadDragArea");
@@ -1318,7 +1345,7 @@ Rectangle {
1319 function waitUntilFocusedApplicationIsShowingItsSurface()
1346 function waitUntilFocusedApplicationIsShowingItsSurface()
1321− var spreadDelegate = findChild(shell, "appDelegate0");
1348+ var spreadDelegate = findChild(shell, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
1322 var appState = findInvisibleChild(spreadDelegate, "applicationWindowStateGroup");
1349 var appState = findInvisibleChild(spreadDelegate, "applicationWindowStateGroup");
1323 tryCompare(appState, "state", "surface");
1350 tryCompare(appState, "state", "surface");
1324 var transitions = appState.transitions;
1351 var transitions = appState.transitions;
@@ -1467,11 +1494,13 @@ Rectangle {
1467 loadShell("tablet");
1494 loadShell("tablet");
1468 shell.usageScenario = "desktop";
1495 shell.usageScenario = "desktop";
1497+ var webBrowserSurfaceId = topLevelSurfaceList.nextId;
1470 var webBrowserApp = ApplicationManager.startApplication("webbrowser-app");
1498 var webBrowserApp = ApplicationManager.startApplication("webbrowser-app");
1471− waitUntilAppWindowIsFullyLoaded(webBrowserApp);
1499+ waitUntilAppWindowIsFullyLoaded(webBrowserSurfaceId);
1501+ var gallerySurfaceId = topLevelSurfaceList.nextId;
1473 var galleryApp = ApplicationManager.startApplication("gallery-app");
1502 var galleryApp = ApplicationManager.startApplication("gallery-app");
1474− waitUntilAppWindowIsFullyLoaded(galleryApp);
1503+ waitUntilAppWindowIsFullyLoaded(gallerySurfaceId);
1476 ApplicationManager.requestFocusApplication("unity8-dash");
1505 ApplicationManager.requestFocusApplication("unity8-dash");
1477 tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
1506 tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
@@ -1489,11 +1518,13 @@ Rectangle {
1489 loadShell("tablet");
1518 loadShell("tablet");
1490 shell.usageScenario = "tablet";
1519 shell.usageScenario = "tablet";
1521+ var webBrowserSurfaceId = topLevelSurfaceList.nextId;
1492 var webBrowserApp = ApplicationManager.startApplication("webbrowser-app");
1522 var webBrowserApp = ApplicationManager.startApplication("webbrowser-app");
1493− waitUntilAppWindowIsFullyLoaded(webBrowserApp);
1523+ waitUntilAppWindowIsFullyLoaded(webBrowserSurfaceId);
1525+ var gallerySurfaceId = topLevelSurfaceList.nextId;
1495 var galleryApp = ApplicationManager.startApplication("gallery-app");
1526 var galleryApp = ApplicationManager.startApplication("gallery-app");
1496− waitUntilAppWindowIsFullyLoaded(galleryApp);
1527+ waitUntilAppWindowIsFullyLoaded(gallerySurfaceId);
1498 ApplicationManager.requestFocusApplication("unity8-dash");
1529 ApplicationManager.requestFocusApplication("unity8-dash");
1499 tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
1530 tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
@@ -1523,17 +1554,26 @@ Rectangle {
1523 var desktopStage = findChild(shell, "stage");
1554 var desktopStage = findChild(shell, "stage");
1524 verify(desktopStage != null)
1555 verify(desktopStage != null)
1557+ var app1SurfaceId = topLevelSurfaceList.nextId;
1526 var app1 = ApplicationManager.startApplication("dialer-app")
1558 var app1 = ApplicationManager.startApplication("dialer-app")
1527− waitUntilAppWindowIsFullyLoaded(app1);
1559+ waitUntilAppWindowIsFullyLoaded(app1SurfaceId);
1561+ var app2SurfaceId = topLevelSurfaceList.nextId;
1528 var app2 = ApplicationManager.startApplication("webbrowser-app")
1562 var app2 = ApplicationManager.startApplication("webbrowser-app")
1529− waitUntilAppWindowIsFullyLoaded(app2);
1563+ waitUntilAppWindowIsFullyLoaded(app2SurfaceId);
1564+ var app2Surface = app2.surfaceList.get(0);
1565+ verify(app2Surface);
1567+ var app3SurfaceId = topLevelSurfaceList.nextId;
1530 var app3 = ApplicationManager.startApplication("camera-app")
1568 var app3 = ApplicationManager.startApplication("camera-app")
1531− waitUntilAppWindowIsFullyLoaded(app3);
1569+ waitUntilAppWindowIsFullyLoaded(app3SurfaceId);
1570+ var app3Surface = app3.surfaceList.get(0);
1571+ verify(app3Surface);
1533 // Do a quick alt-tab and see if focus changes
1573 // Do a quick alt-tab and see if focus changes
1534− tryCompare(app3.session.lastSurface, "activeFocus", true)
1574+ tryCompare(app3Surface, "activeFocus", true)
1535 keyClick(Qt.Key_Tab, Qt.AltModifier)
1575 keyClick(Qt.Key_Tab, Qt.AltModifier)
1536− tryCompare(app2.session.lastSurface, "activeFocus", true)
1576+ tryCompare(app2Surface, "activeFocus", true)
1538 // Press Alt+Tab
1578 // Press Alt+Tab
1539 keyPress(Qt.Key_Alt);
1579 keyPress(Qt.Key_Alt);
@@ -1541,7 +1581,7 @@ Rectangle {
1541 keyRelease(Qt.Key_Alt)
1581 keyRelease(Qt.Key_Alt)
1543 // Focus should have switched back now
1583 // Focus should have switched back now
1544− tryCompare(app3.session.lastSurface, "activeFocus", true)
1584+ tryCompare(app3Surface, "activeFocus", true)
1547 function test_altTabWrapAround() {
1587 function test_altTabWrapAround() {
@@ -1590,7 +1630,9 @@ Rectangle {
1590 tryCompare(desktopSpread, "state", "")
1630 tryCompare(desktopSpread, "state", "")
1592 // Make sure that after wrapping around once, we have the same one focused as at the beginning
1632 // Make sure that after wrapping around once, we have the same one focused as at the beginning
1593− tryCompare(focused.session.lastSurface, "activeFocus", true)
1633+ var focusedAppSurface = focused.surfaceList.get(0);
1634+ verify(focusedAppSurface);
1635+ tryCompare(focusedAppSurface, "activeFocus", true)
1596 function test_altBackTabNavigation() {
1638 function test_altBackTabNavigation() {
@@ -1624,7 +1666,7 @@ Rectangle {
1624 keyRelease(Qt.Key_Alt);
1666 keyRelease(Qt.Key_Alt);
1627− function test_highlightFollowsMouse() {
1669+ function otest_highlightFollowsMouse() {
1628 loadDesktopShellWithApps()
1670 loadDesktopShellWithApps()
1630 var spreadRepeater = findInvisibleChild(shell, "spreadRepeater");
1672 var spreadRepeater = findInvisibleChild(shell, "spreadRepeater");
@@ -1661,9 +1703,7 @@ Rectangle {
1661 keyPress(Qt.Key_Alt)
1703 keyPress(Qt.Key_Alt)
1662 keyClick(Qt.Key_Tab);
1704 keyClick(Qt.Key_Tab);
1664− appRemovedSpy.clear();
1706+ var surfaceId = topLevelSurfaceList.idAt(2);
1666− var closedAppId = ApplicationManager.get(2).appId;
1667 var spreadDelegate2 = spreadRepeater.itemAt(2);
1707 var spreadDelegate2 = spreadRepeater.itemAt(2);
1668 var closeMouseArea = findChild(spreadDelegate2, "closeMouseArea");
1708 var closeMouseArea = findChild(spreadDelegate2, "closeMouseArea");
@@ -1678,12 +1718,14 @@ Rectangle {
1679 tryCompare(closeMouseArea, "enabled", true)
1719 tryCompare(closeMouseArea, "enabled", true)
1721+ var countBeforeClickingCloseButton = topLevelSurfaceList.count;
1722+ verify(topLevelSurfaceList.indexForId(surfaceId) === 2);
1681 // Close the app using the close button
1724 // Close the app using the close button
1682 mouseClick(closeMouseArea, closeMouseArea.width / 2, closeMouseArea.height / 2)
1725 mouseClick(closeMouseArea, closeMouseArea.width / 2, closeMouseArea.height / 2)
1684− // Verify applicationRemoved has been emitted correctly
1727+ tryCompare(topLevelSurfaceList, "count", countBeforeClickingCloseButton - 1);
1685− tryCompare(appRemovedSpy, "count", 1)
1728+ verify(topLevelSurfaceList.indexForId(surfaceId) === -1);
1686− compare(appRemovedSpy.signalArguments[0][0], closedAppId);
1688 keyRelease(Qt.Key_Alt);
1730 keyRelease(Qt.Key_Alt);
@@ -1708,7 +1750,7 @@ Rectangle {
1708 keyPress(Qt.Key_Alt)
1750 keyPress(Qt.Key_Alt)
1709 keyClick(Qt.Key_Tab);
1751 keyClick(Qt.Key_Tab);
1711− var focusAppId = ApplicationManager.get(2).appId;
1753+ var surface = topLevelSurfaceList.surfaceAt(2);
1712 var spreadDelegate2 = spreadRepeater.itemAt(2);
1754 var spreadDelegate2 = spreadRepeater.itemAt(2);
1713 var clippedSpreadDelegate = findChild(spreadDelegate2, "clippedSpreadDelegate");
1755 var clippedSpreadDelegate = findChild(spreadDelegate2, "clippedSpreadDelegate");
@@ -1730,7 +1772,7 @@ Rectangle {
1731 // Verify that we left the spread and app2 is the focused one now
1773 // Verify that we left the spread and app2 is the focused one now
1732 tryCompare(stage, "state", "");
1774 tryCompare(stage, "state", "");
1733− tryCompare(ApplicationManager, "focusedApplicationId", focusAppId);
1775+ tryCompare(surface, "focused", true);
1735 keyRelease(Qt.Key_Alt);
1777 keyRelease(Qt.Key_Alt);
@@ -1794,7 +1836,7 @@ Rectangle {
1794 function test_workspacePreviewsHighlightedApp() {
1836 function test_workspacePreviewsHighlightedApp() {
1795 loadDesktopShellWithApps()
1837 loadDesktopShellWithApps()
1797− var targetZ = ApplicationManager.count + 1;
1839+ var targetZ = topLevelSurfaceList.count + 1;
1799 var spreadRepeater = findInvisibleChild(shell, "spreadRepeater");
1841 var spreadRepeater = findInvisibleChild(shell, "spreadRepeater");
1800 verify(spreadRepeater !== null);
1842 verify(spreadRepeater !== null);
@@ -1870,7 +1912,8 @@ Rectangle {
1870 loadDesktopShellWithApps();
1912 loadDesktopShellWithApps();
1872 var appRepeater = findChild(shell, "appRepeater")
1914 var appRepeater = findChild(shell, "appRepeater")
1873− var appId = ApplicationManager.get(0).appId;
1915+ var application = topLevelSurfaceList.applicationAt(0);
1916+ var surfaceId = topLevelSurfaceList.idAt(0);
1874 var appDelegate = appRepeater.itemAt(0);
1917 var appDelegate = appRepeater.itemAt(0);
1875 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
1918 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
@@ -1881,17 +1924,20 @@ Rectangle {
1881 tryCompare(appDelegate, "state", "maximized");
1924 tryCompare(appDelegate, "state", "maximized");
1882 tryCompare(PanelState, "buttonsVisible", true)
1925 tryCompare(PanelState, "buttonsVisible", true)
1884− ApplicationManager.stopApplication(appId);
1927+ ApplicationManager.stopApplication(application.appId);
1885 tryCompare(PanelState, "buttonsVisible", false)
1928 tryCompare(PanelState, "buttonsVisible", false)
1930+ // wait until all zombie surfaces are gone. As MirSurfaceItems hold references over them.
1931+ // They won't be gone until those surface items are destroyed.
1932+ tryCompareFunction(function() { return application.surfaceList.count }, 0);
1887− ApplicationManager.startApplication(appId);
1934+ ApplicationManager.startApplication(application.appId);
1888 tryCompare(PanelState, "buttonsVisible", true)
1935 tryCompare(PanelState, "buttonsVisible", true)
1891 function test_newAppHasValidGeometry() {
1938 function test_newAppHasValidGeometry() {
1892 loadDesktopShellWithApps();
1939 loadDesktopShellWithApps();
1893 var appRepeater = findChild(shell, "appRepeater");
1940 var appRepeater = findChild(shell, "appRepeater");
1894− var appId = ApplicationManager.get(0).appId;
1895 var appDelegate = appRepeater.itemAt(0);
1941 var appDelegate = appRepeater.itemAt(0);
1897 var resizeArea = findChild(appDelegate, "windowResizeArea");
1943 var resizeArea = findChild(appDelegate, "windowResizeArea");
@@ -1908,7 +1954,6 @@ Rectangle {
1908 function test_switchToStagedHidesPanelButtons() {
1954 function test_switchToStagedHidesPanelButtons() {
1909 loadDesktopShellWithApps();
1955 loadDesktopShellWithApps();
1910 var appRepeater = findChild(shell, "appRepeater")
1956 var appRepeater = findChild(shell, "appRepeater")
1911− var appId = ApplicationManager.get(0).appId;
1912 var appDelegate = appRepeater.itemAt(0);
1957 var appDelegate = appRepeater.itemAt(0);
1913 var panelButtons = findChild(shell, "panelWindowControlButtons")
1958 var panelButtons = findChild(shell, "panelWindowControlButtons")
@@ -1925,7 +1970,6 @@ Rectangle {
1925 function test_lockingGreeterHidesPanelButtons() {
1970 function test_lockingGreeterHidesPanelButtons() {
1926 loadDesktopShellWithApps();
1971 loadDesktopShellWithApps();
1927 var appRepeater = findChild(shell, "appRepeater")
1972 var appRepeater = findChild(shell, "appRepeater")
1928− var appId = ApplicationManager.get(0).appId;
1929 var appDelegate = appRepeater.itemAt(0);
1973 var appDelegate = appRepeater.itemAt(0);
1930 var panelButtons = findChild(shell, "panelWindowControlButtons")
1974 var panelButtons = findChild(shell, "panelWindowControlButtons")
@@ -1955,12 +1999,15 @@ Rectangle {
1955 shell.usageScenario = "desktop";
1999 shell.usageScenario = "desktop";
1956 waitForRendering(shell);
2000 waitForRendering(shell);
2002+ var appSurfaceId = topLevelSurfaceList.nextId;
1958 var app = ApplicationManager.startApplication("dialer-app")
2003 var app = ApplicationManager.startApplication("dialer-app")
1959− waitUntilAppWindowIsFullyLoaded(app);
2004+ waitUntilAppWindowIsFullyLoaded(appSurfaceId);
1961 var appContainer = findChild(shell, "appContainer");
2006 var appContainer = findChild(shell, "appContainer");
2007+ verify(appContainer);
1962− var appDelegate = findChild(appContainer, "appDelegate_dialer-app");
2008+ var appDelegate = findChild(appContainer, "appDelegate_" + appSurfaceId);
2009+ verify(appDelegate);
1963− var decoration = findChild(appDelegate, "appWindowDecoration_dialer-app");
2010+ var decoration = findChild(appDelegate, "appWindowDecoration");
1964 verify(decoration);
2011 verify(decoration);
1966 // move it away from launcher and panel
2013 // move it away from launcher and panel
@@ -1978,18 +2025,22 @@ Rectangle {
1978 function test_restoreWindowStateFixesIfUnderPanel() {
2025 function test_restoreWindowStateFixesIfUnderPanel() {
1979 loadDesktopShellWithApps();
2026 loadDesktopShellWithApps();
1980 var appRepeater = findChild(shell, "appRepeater")
2027 var appRepeater = findChild(shell, "appRepeater")
1981− var appId = ApplicationManager.get(0).appId;
2028+ var application = topLevelSurfaceList.applicationAt(0);
1982 var appDelegate = appRepeater.itemAt(0);
2029 var appDelegate = appRepeater.itemAt(0);
1984 // Move it under the panel programmatically (might happen later with an alt+drag)
2031 // Move it under the panel programmatically (might happen later with an alt+drag)
1985 appDelegate.y = -units.gu(10)
2032 appDelegate.y = -units.gu(10)
1987− ApplicationManager.stopApplication(appId)
2034+ ApplicationManager.stopApplication(application.appId);
2035+ // wait until all zombie surfaces are gone. As MirSurfaceItems hold references over them.
2036+ // They won't be gone until those surface items are destroyed.
2037+ tryCompareFunction(function() { return application.surfaceList.count }, 0);
1988− ApplicationManager.startApplication(appId)
2039+ ApplicationManager.startApplication(application.appId);
1989 waitForRendering(shell)
2040 waitForRendering(shell)
1991 // Make sure the newly started one is at index 0 again
2042 // Make sure the newly started one is at index 0 again
1992− tryCompare(ApplicationManager.get(0), "appId", appId);
2043+ tryCompare(topLevelSurfaceList.applicationAt(0), "appId", application.appId);
1994 appDelegate = appRepeater.itemAt(0);
2045 appDelegate = appRepeater.itemAt(0);
1995 compare(appDelegate.y >= PanelState.panelHeight, true);
2046 compare(appDelegate.y >= PanelState.panelHeight, true);
@@ -2008,16 +2059,22 @@ Rectangle {
2009 // Add two main stage apps, the second in order to suspend the first.
2060 // Add two main stage apps, the second in order to suspend the first.
2010 // LibreOffice has isTouchApp set to false by our mocks.
2061 // LibreOffice has isTouchApp set to false by our mocks.
2062+ var app1SurfaceId = topLevelSurfaceList.nextId;
2011 var app1 = ApplicationManager.startApplication("libreoffice");
2063 var app1 = ApplicationManager.startApplication("libreoffice");
2012− waitUntilAppWindowIsFullyLoaded(app1);
2064+ waitUntilAppWindowIsFullyLoaded(app1SurfaceId);
2065+ var app2SurfaceId = topLevelSurfaceList.nextId;
2013 var app2 = ApplicationManager.startApplication("gallery-app");
2066 var app2 = ApplicationManager.startApplication("gallery-app");
2014− waitUntilAppWindowIsFullyLoaded(app2);
2067+ waitUntilAppWindowIsFullyLoaded(app2SurfaceId);
2016 // Sanity checking
2069 // Sanity checking
2017 compare(app1.stage, ApplicationInfoInterface.MainStage);
2070 compare(app1.stage, ApplicationInfoInterface.MainStage);
2018 compare(app2.stage, ApplicationInfoInterface.MainStage);
2071 compare(app2.stage, ApplicationInfoInterface.MainStage);
2019 verify(!app1.isTouchApp);
2072 verify(!app1.isTouchApp);
2074+ var app1Surface = app1.surfaceList.get(0);
2075+ verify(app1Surface);
2020− verify(!app1.session.lastSurface.activeFocus);
2077+ verify(!app1Surface.activeFocus);
2022 // Make sure app1 is exempt with a requested suspend
2079 // Make sure app1 is exempt with a requested suspend
2023 verify(app1.exemptFromLifecycle);
2080 verify(app1.exemptFromLifecycle);
@@ -2038,15 +2095,21 @@ Rectangle {
2038 GSettingsController.setLifecycleExemptAppids(["webbrowser-app"]);
2095 GSettingsController.setLifecycleExemptAppids(["webbrowser-app"]);
2040 // Add two main stage apps, the second in order to suspend the first
2097 // Add two main stage apps, the second in order to suspend the first
2098+ var app1SurfaceId = topLevelSurfaceList.nextId;
2041 var app1 = ApplicationManager.startApplication("webbrowser-app");
2099 var app1 = ApplicationManager.startApplication("webbrowser-app");
2042− waitUntilAppWindowIsFullyLoaded(app1);
2100+ waitUntilAppWindowIsFullyLoaded(app1SurfaceId);
2101+ var app2SurfaceId = topLevelSurfaceList.nextId;
2043 var app2 = ApplicationManager.startApplication("gallery-app");
2102 var app2 = ApplicationManager.startApplication("gallery-app");
2044− waitUntilAppWindowIsFullyLoaded(app2);
2103+ waitUntilAppWindowIsFullyLoaded(app2SurfaceId);
2046 // Sanity checking
2105 // Sanity checking
2047 compare(app1.stage, ApplicationInfoInterface.MainStage);
2106 compare(app1.stage, ApplicationInfoInterface.MainStage);
2048 compare(app2.stage, ApplicationInfoInterface.MainStage);
2107 compare(app2.stage, ApplicationInfoInterface.MainStage);
2109+ var app1Surface = app1.surfaceList.get(0);
2110+ verify(app1Surface);
2049− verify(!app1.session.lastSurface.activeFocus);
2112+ verify(!app1Surface.activeFocus);
2051 // Make sure app1 is exempt with a requested suspend
2114 // Make sure app1 is exempt with a requested suspend
2052 verify(app1.exemptFromLifecycle);
2115 verify(app1.exemptFromLifecycle);
@@ -2205,9 +2268,10 @@ Rectangle {
2205 var appContainer = findChild(shell, "appContainer");
2268 var appContainer = findChild(shell, "appContainer");
2206 var launcher = findChild(shell, "launcher");
2269 var launcher = findChild(shell, "launcher");
2271+ var appSurfaceId = topLevelSurfaceList.nextId;
2208 var app = ApplicationManager.startApplication("music-app");
2272 var app = ApplicationManager.startApplication("music-app");
2209− waitUntilAppWindowIsFullyLoaded(app);
2273+ waitUntilAppWindowIsFullyLoaded(appSurfaceId);
2210− var appDelegate = findChild(appContainer, "appDelegate_music-app");
2274+ var appDelegate = findChild(appContainer, "appDelegate_" + appSurfaceId);
2211 appDelegate.maximize();
2275 appDelegate.maximize();
2212 tryCompare(appDelegate, "visuallyMaximized", true);
2276 tryCompare(appDelegate, "visuallyMaximized", true);
2213 waitForRendering(shell);
2277 waitForRendering(shell);
@@ -2235,8 +2299,9 @@ Rectangle {
2236 tryCompare(launcher, "lockedVisible", true);
2300 tryCompare(launcher, "lockedVisible", true);
2302+ var cameraSurfaceId = topLevelSurfaceList.nextId;
2238 var cameraApp = ApplicationManager.startApplication("camera-app");
2303 var cameraApp = ApplicationManager.startApplication("camera-app");
2239− waitUntilAppWindowIsFullyLoaded(cameraApp);
2304+ waitUntilAppWindowIsFullyLoaded(cameraSurfaceId);
2241 tryCompare(launcher, "lockedVisible", false);
2306 tryCompare(launcher, "lockedVisible", false);
@@ -2257,8 +2322,9 @@ Rectangle {
2257 swipeAwayGreeter();
2322 swipeAwayGreeter();
2259 // Let's open a fullscreen app
2324 // Let's open a fullscreen app
2325+ var appSurfaceId = topLevelSurfaceList.nextId;
2260 var app = ApplicationManager.startApplication("camera-app");
2326 var app = ApplicationManager.startApplication("camera-app");
2261− waitUntilAppWindowIsFullyLoaded(app);
2327+ waitUntilAppWindowIsFullyLoaded(appSurfaceId);
2263 var appRepeater = findChild(shell, data.repeaterName);
2329 var appRepeater = findChild(shell, data.repeaterName);
2264 var topmostAppDelegate = appRepeater.itemAt(0);
2330 var topmostAppDelegate = appRepeater.itemAt(0);