@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@ import Ubuntu.Components 1.3
2020import Ubuntu.Components.ListItems 1.3
2121import Unity.Application 0.1
2222import Unity.Test 0.1
23+import WindowManager 0.1
2324import Utils 0.1
2425
2526import ".." // For EdgeBarrierControls
@@ -56,6 +57,11 @@ Item {
5657 }
5758 }
5859
60+ TopLevelSurfaceList {
61+ id: topSurfaceList
62+ applicationsModel: ApplicationManager
63+ }
64+
5965 Loader {
6066 id: desktopStageLoader
6167 x: ((root.width - controls.width) - width) / 2
@@ -70,6 +76,7 @@ Item {
7076 DesktopStage {
7177 anchors.fill: parent
7278 background: "../../../qml/graphics/tablet_background.jpg"
79+ focus: true
7380
7481 Component.onCompleted: {
7582 edgeBarrierControls.target = testCase.findChild(this, "edgeBarrierController");
@@ -78,6 +85,8 @@ Item {
7885 desktopStageLoader.itemDestroyed = true;
7986 }
8087 orientations: Orientations {}
88+ applicationManager: ApplicationManager
89+ topLevelSurfaceList: topSurfaceList
8190 }
8291 }
8392 }
@@ -104,7 +113,7 @@ Item {
104113 activeFocusOnPress: false
105114 onClicked: {
106115 if (ApplicationManager.focusedApplicationId) {
107− var surface = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).session.lastSurface;
116+ var surface = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).surfaceList.get(0);
108117 surface.slowToResize = true;
109118 }
110119 }
@@ -138,6 +147,19 @@ Item {
138147
139148 property Item desktopStage: desktopStageLoader.status === Loader.Ready ? desktopStageLoader.item : null
140149
150+ function init() {
151+ // wait until unity8-dash is up and running.
152+ // it's started automatically by ApplicationManager mock implementation
153+ tryCompare(ApplicationManager, "count", 1);
154+ var dashApp = ApplicationManager.findApplication("unity8-dash");
155+ verify(dashApp);
156+ tryCompare(dashApp, "state", ApplicationInfoInterface.Running);
157+
158+ tryCompare(topSurfaceList, "count", 1);
159+ tryCompareFunction(function(){return topSurfaceList.surfaceAt(0) != null;}, true);
160+ compare(MirFocusController.focusedSurface, topSurfaceList.surfaceAt(0));
161+ }
162+
141163 function cleanup() {
142164 desktopStageLoader.itemDestroyed = false;
143165 desktopStageLoader.active = false;
@@ -150,43 +172,71 @@ Item {
150172 // Shell instance gets destroyed.
151173 tryCompare(desktopStageLoader, "itemDestroyed", true);
152174
153− killAllRunningApps();
175+ killApps();
176+
177+ root.resetGeometry();
154178
155179 desktopStageLoader.active = true;
156180 tryCompare(desktopStageLoader, "status", Loader.Ready);
157− root.resetGeometry();
158− }
159181
160− function killAllRunningApps() {
161− while (ApplicationManager.count > 0) {
162− ApplicationManager.stopApplication(ApplicationManager.get(0).appId);
163− }
164− compare(ApplicationManager.count, 0)
165182 }
166183
167− function waitUntilAppSurfaceShowsUp(appId) {
168− var appWindow = findChild(desktopStage, "appWindow_" + appId);
184+ function waitUntilAppSurfaceShowsUp(surfaceId) {
185+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
186+ verify(appDelegate);
187+ var appWindow = findChild(appDelegate, "appWindow");
169188 verify(appWindow);
170189 var appWindowStates = findInvisibleChild(appWindow, "applicationWindowStateGroup");
171190 verify(appWindowStates);
172191 tryCompare(appWindowStates, "state", "surface");
173192 }
174193
194+ /*
195+ Returns the appDelegate of the first surface created by the app with the specified appId
196+ */
175197 function startApplication(appId) {
176− var app = ApplicationManager.findApplication(appId);
177− if (!app) {
198+ try {
199+ var app = ApplicationManager.findApplication(appId);
200+ if (app) {
201+ for (var i = 0; i < topSurfaceList.count; i++) {
202+ if (topSurfaceList.applicationAt(i).appId === appId) {
203+ var appRepeater = findChild(desktopStage, "appRepeater");
204+ verify(appRepeater);
205+ return appRepeater.itemAt(i);
206+ }
207+ }
208+ }
209+
210+ var surfaceId = topSurfaceList.nextId;
178211 app = ApplicationManager.startApplication(appId);
212+ verify(app);
213+ waitUntilAppSurfaceShowsUp(surfaceId);
214+ compare(app.surfaceList.count, 1);
215+
216+ return findChild(desktopStage, "appDelegate_" + surfaceId);
217+ } catch(err) {
218+ throw new Error("startApplication("+appId+") called from line " + util.callerLine(1) + " failed!");
219+ }
220+ }
221+
222+ function maximizeAppDelegate(appDelegate) {
223+ var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
224+ if (!maximizeButton) {
225+ fail("Could not find maximizeWindowButton of appDelegate=" + appDelegate);
226+ }
227+ mouseClick(maximizeButton);
228+
229+ try {
230+ tryCompare(appDelegate, "visuallyMaximized", true);
231+ } catch(err) {
232+ fail("appDelegate.visuallyMaximized !== true");
179233 }
180− verify(app);
181− waitUntilAppSurfaceShowsUp(appId);
182− verify(app.session.lastSurface);
183− return app;
184234 }
185235
186236 function test_appFocusSwitch_data() {
187237 return [
188− {tag: "dash to dialer", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
189− {tag: "dialer to dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
238+ {tag: "dash to dialer", apps: [ "unity8-dash", "dialer-app", "gmail-webapp" ], focusfrom: 0, focusTo: 1 },
239+ {tag: "dialer to dash", apps: [ "unity8-dash", "dialer-app", "gmail-webapp" ], focusfrom: 1, focusTo: 0 },
190240 ]
191241 }
192242
@@ -194,10 +244,10 @@ Item {
194244 data.apps.forEach(startApplication);
195245
196246 ApplicationManager.requestFocusApplication(data.apps[data.focusfrom]);
197− tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.lastSurface, "activeFocus", true);
247+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).surfaceList.get(0), "activeFocus", true);
198248
199249 ApplicationManager.requestFocusApplication(data.apps[data.focusTo]);
200− tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.lastSurface, "activeFocus", true);
250+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).surfaceList.get(0), "activeFocus", true);
201251 }
202252
203253 function test_tappingOnWindowChangesFocusedApp_data() {
@@ -208,21 +258,24 @@ Item {
208258 }
209259
210260 function test_tappingOnWindowChangesFocusedApp(data) {
211− data.apps.forEach(startApplication);
212− var fromAppId = data.apps[data.focusfrom];
213− var toAppId = data.apps[data.focusTo]
261+ var appDelegates = [];
262+ for (var i = 0; i < data.apps.length; i++) {
263+ appDelegates[i] = startApplication(data.apps[i]);
264+ }
265+ var fromDelegate = appDelegates[data.focusfrom];
266+ var toDelegate = appDelegates[data.focusTo];
214267
215− var fromAppWindow = findChild(desktopStage, "appWindow_" + fromAppId);
268+ var fromAppWindow = findChild(fromDelegate, "appWindow");
216269 verify(fromAppWindow);
217270 tap(fromAppWindow);
218− compare(fromAppWindow.application.session.lastSurface.activeFocus, true);
219− compare(ApplicationManager.focusedApplicationId, fromAppId);
271+ compare(fromDelegate.surface.activeFocus, true);
272+ compare(MirFocusController.focusedSurface, fromDelegate.surface);
220273
221− var toAppWindow = findChild(desktopStage, "appWindow_" + toAppId);
274+ var toAppWindow = findChild(toDelegate, "appWindow");
222275 verify(toAppWindow);
223276 tap(toAppWindow);
224− compare(toAppWindow.application.session.lastSurface.activeFocus, true);
225− compare(ApplicationManager.focusedApplicationId, toAppId);
277+ compare(toDelegate.surface.activeFocus, true);
278+ compare(MirFocusController.focusedSurface, toDelegate.surface);
226279 }
227280
228281 function test_clickingOnWindowChangesFocusedApp_data() {
@@ -230,21 +283,24 @@ Item {
230283 }
231284
232285 function test_clickingOnWindowChangesFocusedApp(data) {
233− data.apps.forEach(startApplication);
234− var fromAppId = data.apps[data.focusfrom];
235− var toAppId = data.apps[data.focusTo]
286+ var appDelegates = [];
287+ for (var i = 0; i < data.apps.length; i++) {
288+ appDelegates[i] = startApplication(data.apps[i]);
289+ }
290+ var fromDelegate = appDelegates[data.focusfrom];
291+ var toDelegate = appDelegates[data.focusTo];
236292
237− var fromAppWindow = findChild(desktopStage, "appWindow_" + fromAppId);
293+ var fromAppWindow = findChild(fromDelegate, "appWindow");
238294 verify(fromAppWindow);
239295 mouseClick(fromAppWindow);
240− compare(fromAppWindow.application.session.lastSurface.activeFocus, true);
241− compare(ApplicationManager.focusedApplicationId, fromAppId);
296+ compare(fromDelegate.surface.activeFocus, true);
297+ compare(MirFocusController.focusedSurface, fromDelegate.surface);
242298
243− var toAppWindow = findChild(desktopStage, "appWindow_" + toAppId);
299+ var toAppWindow = findChild(toDelegate, "appWindow");
244300 verify(toAppWindow);
245301 mouseClick(toAppWindow);
246− compare(toAppWindow.application.session.lastSurface.activeFocus, true);
247− compare(ApplicationManager.focusedApplicationId, toAppId);
302+ compare(toDelegate.surface.activeFocus, true);
303+ compare(MirFocusController.focusedSurface, toDelegate.surface);
248304 }
249305
250306 function test_tappingOnDecorationFocusesApplication_data() {
@@ -254,24 +310,49 @@ Item {
254310 ]
255311 }
256312
313+ function findDecoratedWindow(surfaceId) {
314+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
315+ if (!appDelegate) {
316+ console.warn("Could not find appDelegate for surfaceId="+surfaceId);
317+ return null;
318+ }
319+ return findChild(appDelegate, "decoratedWindow");
320+ }
321+
322+ function findWindowDecoration(surfaceId) {
323+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
324+ if (!appDelegate) {
325+ console.warn("Could not find appDelegate for surfaceId="+surfaceId);
326+ return null;
327+ }
328+ return findChild(appDelegate, "appWindowDecoration");
329+ }
330+
257331 function test_tappingOnDecorationFocusesApplication(data) {
258− data.apps.forEach(startApplication);
332+ var appDelegates = [];
333+ for (var i = 0; i < data.apps.length; i++) {
334+ appDelegates[i] = startApplication(data.apps[i]);
335+ }
259336
260− var fromAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusfrom]);
337+ var fromDelegate = appDelegates[data.focusfrom];
338+ var toDelegate = appDelegates[data.focusTo];
339+
340+ var fromAppDecoration = findChild(fromDelegate, "appWindowDecoration");
261341 verify(fromAppDecoration);
262342 tap(fromAppDecoration);
263343
264− var fromApp = ApplicationManager.findApplication(data.apps[data.focusfrom]);
265− verify(fromApp);
266− tryCompare(fromApp.session.lastSurface, "activeFocus", true);
344+ tryCompare(fromDelegate.surface, "activeFocus", true);
267345
268− var toAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusTo]);
346+ var toAppDecoration = findChild(toDelegate, "appWindowDecoration");
269347 verify(toAppDecoration);
348+
349+ // FIXME: Wait a bit before the second tap or the window decoration will say it got double clicked.
350+ // No idea why.
351+ wait(700);
352+
270353 tap(toAppDecoration);
271354
272− var toApp = ApplicationManager.findApplication(data.apps[data.focusTo]);
273− verify(toApp);
274− tryCompare(toApp.session.lastSurface, "activeFocus", true);
355+ tryCompare(toDelegate.surface, "activeFocus", true);
275356 }
276357
277358 function test_clickingOnDecorationFocusesApplication_data() {
@@ -279,159 +360,170 @@ Item {
279360 }
280361
281362 function test_clickingOnDecorationFocusesApplication(data) {
282− data.apps.forEach(startApplication);
363+ var appDelegates = [];
364+ for (var i = 0; i < data.apps.length; i++) {
365+ appDelegates[i] = startApplication(data.apps[i]);
366+ }
367+ var fromDelegate = appDelegates[data.focusfrom];
368+ var toDelegate = appDelegates[data.focusTo];
283369
284− var fromAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusfrom]);
370+ var fromAppDecoration = findChild(fromDelegate, "appWindowDecoration");
285371 verify(fromAppDecoration);
286372 mouseClick(fromAppDecoration);
287− tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.lastSurface, "activeFocus", true);
373+ tryCompare(fromDelegate.surface, "activeFocus", true);
288374
289− var toAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusTo]);
375+ var toAppDecoration = findChild(toDelegate, "appWindowDecoration");
290376 verify(toAppDecoration);
291377 mouseClick(toAppDecoration);
292− tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.lastSurface, "activeFocus", true);
378+ tryCompare(toDelegate.surface, "activeFocus", true);
293379 }
294380
295381 function test_windowMaximize() {
296− var apps = ["unity8-dash", "dialer-app", "camera-app"];
297− apps.forEach(startApplication);
298− var appName = "dialer-app";
299− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
300− verify(appDelegate);
301− ApplicationManager.focusApplication(appName);
382+ var dialerDelegate = startApplication("dialer-app");
383+ startApplication("camera-app");
384+
385+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
386+ dialerDelegate.surface.requestFocus();
387+ tryCompare(dialerDelegate, "focus", true);
388+
302389 keyClick(Qt.Key_Up, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Up shortcut to maximize
303− tryCompare(appDelegate, "maximized", true);
304− tryCompare(appDelegate, "minimized", false);
390+ tryCompare(dialerDelegate, "maximized", true);
391+ tryCompare(dialerDelegate, "minimized", false);
305392 }
306393
307394 function test_windowMaximizeLeft() {
308− var apps = ["unity8-dash", "dialer-app", "camera-app"];
309− apps.forEach(startApplication);
310− var appName = "dialer-app";
311− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
312− verify(appDelegate);
313− ApplicationManager.focusApplication(appName);
395+ var dialerDelegate = startApplication("dialer-app");
396+ startApplication("camera-app");
397+
398+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
399+ dialerDelegate.surface.requestFocus();
400+ tryCompare(dialerDelegate, "focus", true);
401+
314402 keyClick(Qt.Key_Left, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Left shortcut to maximizeLeft
315− tryCompare(appDelegate, "maximized", false);
316− tryCompare(appDelegate, "minimized", false);
317− tryCompare(appDelegate, "maximizedLeft", true);
318− tryCompare(appDelegate, "maximizedRight", false);
403+ tryCompare(dialerDelegate, "maximized", false);
404+ tryCompare(dialerDelegate, "minimized", false);
405+ tryCompare(dialerDelegate, "maximizedLeft", true);
406+ tryCompare(dialerDelegate, "maximizedRight", false);
319407 }
320408
321409 function test_windowMaximizeRight() {
322− var apps = ["unity8-dash", "dialer-app", "camera-app"];
323− apps.forEach(startApplication);
324− var appName = "dialer-app";
325− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
326− verify(appDelegate);
327− ApplicationManager.focusApplication(appName);
410+ var dialerDelegate = startApplication("dialer-app");
411+ startApplication("camera-app");
412+
413+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
414+ dialerDelegate.surface.requestFocus();
415+ tryCompare(dialerDelegate, "focus", true);
416+
328417 keyClick(Qt.Key_Right, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Right shortcut to maximizeRight
329− tryCompare(appDelegate, "maximized", false);
330− tryCompare(appDelegate, "minimized", false);
331− tryCompare(appDelegate, "maximizedLeft", false);
332− tryCompare(appDelegate, "maximizedRight", true);
418+ tryCompare(dialerDelegate, "maximized", false);
419+ tryCompare(dialerDelegate, "minimized", false);
420+ tryCompare(dialerDelegate, "maximizedLeft", false);
421+ tryCompare(dialerDelegate, "maximizedRight", true);
333422 }
334423
335424 function test_windowMinimize() {
336− var apps = ["unity8-dash", "dialer-app", "camera-app"];
337− apps.forEach(startApplication);
338− var appName = "dialer-app";
339− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
340− verify(appDelegate);
341− ApplicationManager.focusApplication(appName);
425+ var dialerDelegate = startApplication("dialer-app");
426+ startApplication("camera-app");
427+
428+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
429+ dialerDelegate.surface.requestFocus();
430+ tryCompare(dialerDelegate, "focus", true);
431+
342432 keyClick(Qt.Key_Down, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Down shortcut to minimize
343− tryCompare(appDelegate, "maximized", false);
344− tryCompare(appDelegate, "minimized", true);
433+ tryCompare(dialerDelegate, "maximized", false);
434+ tryCompare(dialerDelegate, "minimized", true);
345435 verify(ApplicationManager.focusedApplicationId != ""); // verify we don't lose focus when minimizing an app
346436 }
347437
348438 function test_windowMinimizeAll() {
349439 var apps = ["unity8-dash", "dialer-app", "camera-app"];
350440 apps.forEach(startApplication);
351− verify(ApplicationManager.count == 3);
441+ verify(topSurfaceList.count == 3);
352442 keyClick(Qt.Key_D, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+D shortcut to minimize all
353443 tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify no app is focused
354444 }
355445
356446 function test_windowClose() {
357− var apps = ["unity8-dash", "dialer-app", "camera-app"];
358− apps.forEach(startApplication);
359− verify(ApplicationManager.count == 3);
360− var appName = "dialer-app";
361− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
362− verify(appDelegate);
363− ApplicationManager.focusApplication(appName);
447+ var dialerSurfaceId = topSurfaceList.nextId;
448+ var dialerDelegate = startApplication("dialer-app");
449+ verify(topSurfaceList.indexForId(dialerSurfaceId) !== -1);
450+ startApplication("gmail-webapp");
451+ verify(topSurfaceList.count == 3);
452+
453+ mouseClick(dialerDelegate);
454+
455+ var desktopStagePriv = findInvisibleChild(desktopStage, "DesktopStagePrivate");
456+ tryCompare(desktopStagePriv, "focusedAppDelegate", dialerDelegate);
457+
364458 keyClick(Qt.Key_F4, Qt.AltModifier); // Alt+F4 shortcut to close
365− verify(ApplicationManager.count == 2); // verify the app is gone
366− verify(ApplicationManager.findApplication(appName) === null); // and it's not in running apps
459+
460+ // verify the surface is gone
461+ tryCompare(topSurfaceList, "count", 2);
462+ verify(topSurfaceList.indexForId(dialerSurfaceId) === -1);
367463 }
368464
369465 function test_smashCursorKeys() {
370− var apps = ["unity8-dash", "dialer-app", "camera-app"];
466+ var apps = ["dialer-app", "gmail-webapp"];
371467 apps.forEach(startApplication);
372− verify(ApplicationManager.count == 3);
468+ verify(topSurfaceList.count == 3);
373469 keyClick(Qt.Key_D, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+D shortcut to minimize all
374− tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify no app is focused
470+ tryCompare(MirFocusController, "focusedSurface", null); // verify no surface is focused
375471
376472 // now try pressing all 4 arrow keys + ctrl + meta
377473 keyClick(Qt.Key_Up | Qt.Key_Down | Qt.Key_Left | Qt.Key_Right, Qt.MetaModifier|Qt.ControlModifier); // smash it!!!
378− tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify still no app is focused
474+ tryCompare(MirFocusController, "focusedSurface", null); // verify still no surface is focused
379475 }
380476
381477 function test_minimizeApplicationHidesSurface() {
382− var dashApp = startApplication("unity8-dash");
478+ compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
479+ var dashSurface = topSurfaceList.surfaceAt(0);
480+ var dashSurfaceId = topSurfaceList.idAt(0);
383481
384− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
385− verify(dashDelegate);
482+ var decoratedWindow = findDecoratedWindow(dashSurfaceId);
483+ verify(decoratedWindow);
386484
387− findChild(dashDelegate, "decoratedWindow").minimize();
388− tryCompare(dashApp.session.lastSurface, "visible", false);
485+ tryCompare(dashSurface, "visible", true);
486+ decoratedWindow.minimize();
487+ tryCompare(dashSurface, "visible", false);
389488 }
390489
391490 function test_maximizeApplicationHidesSurfacesBehindIt() {
392− var dashApp = startApplication("unity8-dash");
393− var dialerApp = startApplication("dialer-app");
394− var gmailApp = startApplication("gmail-webapp");
395−
396− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
397− verify(dashDelegate);
398− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
399− verify(dialerDelegate);
400− var gmailDelegate = findChild(desktopStage, "appDelegate_gmail-webapp");
401− verify(gmailDelegate);
491+ var dashDelegate = startApplication("unity8-dash");
492+ var dialerDelegate = startApplication("dialer-app");
493+ var gmailDelegate = startApplication("gmail-webapp");
402494
403− // maximize
495+ // maximize without raising
404496 dialerDelegate.maximize();
405497 tryCompare(dialerDelegate, "visuallyMaximized", true);
406498
407− tryCompare(dashApp.session.lastSurface, "visible", false);
408− compare(gmailApp.session.lastSurface.visible, true);
499+ tryCompare(dashDelegate.surface, "visible", false);
500+ compare(gmailDelegate.surface.visible, true);
409501
410− // restore
502+ // restore without raising
411503 dialerDelegate.restoreFromMaximized();
412− compare(dashApp.session.lastSurface.visible, true);
413− compare(gmailApp.session.lastSurface.visible, true);
504+ compare(dashDelegate.surface.visible, true);
505+ compare(gmailDelegate.surface.visible, true);
414506 }
415507
416508 function test_applicationsBecomeVisibleWhenOccludingAppRemoved() {
417− var dashApp = startApplication("unity8-dash");
418− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
419− verify(dashDelegate);
509+ var dashApp = topSurfaceList.applicationAt(0);
420510
421− var dialerApp = startApplication("dialer-app");
422− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
511+ var dialerSurfaceId = topSurfaceList.nextId;
512+ var dialerDelegate = startApplication("dialer-app");
423513 verify(dialerDelegate);
514+ var dialerApp = dialerDelegate.application;
424515
425516 var dialerMaximizeButton = findChild(dialerDelegate, "maximizeWindowButton");
426517 verify(dialerMaximizeButton);
427518 mouseClick(dialerMaximizeButton);
428519
429− var mapApp = startApplication("map");
430− var mapDelegate = findChild(desktopStage, "appDelegate_map");
520+ var mapSurfaceId = topSurfaceList.nextId;
521+ var mapDelegate = startApplication("map");
431522 verify(mapDelegate);
523+ var mapApp = mapDelegate.application;
432524
433− var gmailApp = startApplication("gmail-webapp");
434− var gmailDelegate = findChild(desktopStage, "appDelegate_gmail-webapp");
525+ var gmailSurfaceId = topSurfaceList.nextId;
526+ var gmailDelegate = startApplication("gmail-webapp");
435527 verify(gmailDelegate);
436528
437529 var gmailMaximizeButton = findChild(gmailDelegate, "maximizeWindowButton");
@@ -441,29 +533,27 @@ Item {
441533 tryCompare(dialerDelegate, "visuallyMaximized", true);
442534 tryCompare(gmailDelegate, "visuallyMaximized", true);
443535
444− tryCompare(dashApp.session.lastSurface, "visible", false);
445− tryCompare(dialerApp.session.lastSurface, "visible", false);
446− tryCompare(mapApp.session.lastSurface, "visible", false);
536+ tryCompare(dashApp.surfaceList.get(0), "visible", false);
537+ tryCompare(dialerApp.surfaceList.get(0), "visible", false);
538+ tryCompare(mapApp.surfaceList.get(0), "visible", false);
447539
448540 ApplicationManager.stopApplication("gmail-webapp");
449541
450− compare(mapApp.session.lastSurface.visible, true);
451− tryCompare(dialerApp.session.lastSurface, "visible", true);
452− tryCompare(dashApp.session.lastSurface, "visible", false); // still occluded by maximised dialer
542+ tryCompare(mapApp.surfaceList.get(0), "visible", true);
543+ tryCompare(dialerApp.surfaceList.get(0), "visible", true);
544+ tryCompare(dashApp.surfaceList.get(0), "visible", false); // still occluded by maximised dialer
453545 }
454546
455547 function test_maximisedAppStaysVisibleWhenAppStarts() {
456− var dashApp = startApplication("unity8-dash");
457− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
458− verify(dashDelegate);
548+ var dashDelegate = startApplication("unity8-dash");
549+
459550 // maximize
460551 var dashMaximizeButton = findChild(dashDelegate, "maximizeWindowButton");
461552 verify(dashMaximizeButton);
462553 mouseClick(dashMaximizeButton);
463554 tryCompare(dashDelegate, "visuallyMaximized", true);
464555
465− var dialerApp = startApplication("dialer-app");
466− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
556+ var dialerDelegate = startApplication("dialer-app");
467557 verify(dialerDelegate);
468558
469559 compare(dialerDelegate.visible, true, "Dialer should be visible");
@@ -471,14 +561,11 @@ Item {
471561 }
472562
473563 function test_occlusionWithMultipleMaximized() {
474− var dashApp = startApplication("unity8-dash");
475− var dashAppDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
564+ var dashAppDelegate = startApplication("unity8-dash");
476565
477− var dialerApp = startApplication("dialer-app");
478− var dialerAppDelegate = findChild(desktopStage, "appDelegate_dialer-app");
566+ var dialerAppDelegate = startApplication("dialer-app");
479567
480− var facebookApp = startApplication("facebook-webapp");
481− var facebookAppDelegate = findChild(desktopStage, "appDelegate_facebook-webapp");
568+ var facebookAppDelegate = startApplication("facebook-webapp");
482569
483570 // all of them are in restored state now. all should be visible
484571 tryCompare(dashAppDelegate, "visible", true);
@@ -492,13 +579,13 @@ Item {
492579 tryCompare(facebookAppDelegate, "visible", true);
493580
494581 // Bring dash to front. make sure dash and the maximized facebook are visible, the restored one behind is hidden
495− ApplicationManager.focusApplication("unity8-dash");
582+ dashAppDelegate.focus = true;
496583 tryCompare(dashAppDelegate, "visible", true);
497584 tryCompare(dialerAppDelegate, "visible", false);
498585 tryCompare(facebookAppDelegate, "visible", true);
499586
500587 // Now focus the dialer app. all 3 should be visible again
501− ApplicationManager.focusApplication("dialer-app");
588+ dialerAppDelegate.focus = true;
502589 tryCompare(dashAppDelegate, "visible", true);
503590 tryCompare(dialerAppDelegate, "visible", true);
504591 tryCompare(facebookAppDelegate, "visible", true);
@@ -511,20 +598,15 @@ Item {
511598 }
512599
513600 function test_dropShadow() {
514− // verify the drop shadow is not visible initially
515− verify(PanelState.dropShadow == false);
516−
517601 // start an app, maximize it
518− var facebookApp = startApplication("facebook-webapp");
519− var facebookAppDelegate = findChild(desktopStage, "appDelegate_facebook-webapp");
602+ var facebookAppDelegate = startApplication("facebook-webapp");
520603 facebookAppDelegate.maximize();
521604
522605 // verify the drop shadow is still not visible
523606 verify(PanelState.dropShadow == false);
524607
525608 // start a foreground app, not maximized
526− var dialerApp = startApplication("dialer-app");
527− var dialerAppDelegate = findChild(desktopStage, "appDelegate_dialer-app");
609+ var dialerAppDelegate = startApplication("dialer-app");
528610
529611 // verify the drop shadow becomes visible
530612 verify(PanelState.dropShadow == true);
@@ -533,7 +615,7 @@ Item {
533615 ApplicationManager.stopApplication("facebook-webapp");
534616
535617 // verify the drop shadow is gone
536− verify(PanelState.dropShadow == false);
618+ tryCompare(PanelState, "dropShadow", false);
537619 }
538620
539621 function test_threeFingerTapShowsWindowControls_data() {