@@ -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
@@ -53,6 +54,11 @@ Item {
5354 }
5455 }
5556
57+ TopLevelSurfaceList {
58+ id: topSurfaceList
59+ applicationsModel: ApplicationManager
60+ }
61+
5662 Loader {
5763 id: desktopStageLoader
5864 x: ((root.width - controls.width) - width) / 2
@@ -67,6 +73,7 @@ Item {
6773 DesktopStage {
6874 anchors.fill: parent
6975 background: "../../../qml/graphics/tablet_background.jpg"
76+ focus: true
7077
7178 Component.onCompleted: {
7279 edgeBarrierControls.target = testCase.findChild(this, "edgeBarrierController");
@@ -75,6 +82,8 @@ Item {
7582 desktopStageLoader.itemDestroyed = true;
7683 }
7784 orientations: Orientations {}
85+ applicationManager: ApplicationManager
86+ topLevelSurfaceList: topSurfaceList
7887 }
7988 }
8089 }
@@ -102,7 +111,7 @@ Item {
102111 activeFocusOnPress: false
103112 onClicked: {
104113 if (ApplicationManager.focusedApplicationId) {
105− var surface = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).session.lastSurface;
114+ var surface = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).surfaceList.get(0);
106115 surface.slowToResize = true;
107116 }
108117 }
@@ -136,6 +145,19 @@ Item {
136145
137146 property Item desktopStage: desktopStageLoader.status === Loader.Ready ? desktopStageLoader.item : null
138147
148+ function init() {
149+ // wait until unity8-dash is up and running.
150+ // it's started automatically by ApplicationManager mock implementation
151+ tryCompare(ApplicationManager, "count", 1);
152+ var dashApp = ApplicationManager.findApplication("unity8-dash");
153+ verify(dashApp);
154+ tryCompare(dashApp, "state", ApplicationInfoInterface.Running);
155+
156+ tryCompare(topSurfaceList, "count", 1);
157+ tryCompareFunction(function(){return topSurfaceList.surfaceAt(0) != null;}, true);
158+ compare(MirFocusController.focusedSurface, topSurfaceList.surfaceAt(0));
159+ }
160+
139161 function cleanup() {
140162 desktopStageLoader.itemDestroyed = false;
141163 desktopStageLoader.active = false;
@@ -148,43 +170,71 @@ Item {
148170 // Shell instance gets destroyed.
149171 tryCompare(desktopStageLoader, "itemDestroyed", true);
150172
151− killAllRunningApps();
173+ killApps();
174+
175+ root.resetGeometry();
152176
153177 desktopStageLoader.active = true;
154178 tryCompare(desktopStageLoader, "status", Loader.Ready);
155− root.resetGeometry();
156− }
157179
158− function killAllRunningApps() {
159− while (ApplicationManager.count > 0) {
160− ApplicationManager.stopApplication(ApplicationManager.get(0).appId);
161− }
162− compare(ApplicationManager.count, 0)
163180 }
164181
165− function waitUntilAppSurfaceShowsUp(appId) {
166− var appWindow = findChild(desktopStage, "appWindow_" + appId);
182+ function waitUntilAppSurfaceShowsUp(surfaceId) {
183+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
184+ verify(appDelegate);
185+ var appWindow = findChild(appDelegate, "appWindow");
167186 verify(appWindow);
168187 var appWindowStates = findInvisibleChild(appWindow, "applicationWindowStateGroup");
169188 verify(appWindowStates);
170189 tryCompare(appWindowStates, "state", "surface");
171190 }
172191
192+ /*
193+ Returns the appDelegate of the first surface created by the app with the specified appId
194+ */
173195 function startApplication(appId) {
174− var app = ApplicationManager.findApplication(appId);
175− if (!app) {
196+ try {
197+ var app = ApplicationManager.findApplication(appId);
198+ if (app) {
199+ for (var i = 0; i < topSurfaceList.count; i++) {
200+ if (topSurfaceList.applicationAt(i).appId === appId) {
201+ var appRepeater = findChild(desktopStage, "appRepeater");
202+ verify(appRepeater);
203+ return appRepeater.itemAt(i);
204+ }
205+ }
206+ }
207+
208+ var surfaceId = topSurfaceList.nextId;
176209 app = ApplicationManager.startApplication(appId);
210+ verify(app);
211+ waitUntilAppSurfaceShowsUp(surfaceId);
212+ compare(app.surfaceList.count, 1);
213+
214+ return findChild(desktopStage, "appDelegate_" + surfaceId);
215+ } catch(err) {
216+ throw new Error("startApplication("+appId+") called from line " + util.callerLine(1) + " failed!");
217+ }
218+ }
219+
220+ function maximizeAppDelegate(appDelegate) {
221+ var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
222+ if (!maximizeButton) {
223+ fail("Could not find maximizeWindowButton of appDelegate=" + appDelegate);
224+ }
225+ mouseClick(maximizeButton);
226+
227+ try {
228+ tryCompare(appDelegate, "visuallyMaximized", true);
229+ } catch(err) {
230+ fail("appDelegate.visuallyMaximized !== true");
177231 }
178− verify(app);
179− waitUntilAppSurfaceShowsUp(appId);
180− verify(app.session.lastSurface);
181− return app;
182232 }
183233
184234 function test_appFocusSwitch_data() {
185235 return [
186− {tag: "dash to dialer", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
187− {tag: "dialer to dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
236+ {tag: "dash to dialer", apps: [ "unity8-dash", "dialer-app", "gmail-webapp" ], focusfrom: 0, focusTo: 1 },
237+ {tag: "dialer to dash", apps: [ "unity8-dash", "dialer-app", "gmail-webapp" ], focusfrom: 1, focusTo: 0 },
188238 ]
189239 }
190240
@@ -192,10 +242,10 @@ Item {
192242 data.apps.forEach(startApplication);
193243
194244 ApplicationManager.requestFocusApplication(data.apps[data.focusfrom]);
195− tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.lastSurface, "activeFocus", true);
245+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).surfaceList.get(0), "activeFocus", true);
196246
197247 ApplicationManager.requestFocusApplication(data.apps[data.focusTo]);
198− tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.lastSurface, "activeFocus", true);
248+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).surfaceList.get(0), "activeFocus", true);
199249 }
200250
201251 function test_tappingOnWindowChangesFocusedApp_data() {
@@ -206,21 +256,24 @@ Item {
206256 }
207257
208258 function test_tappingOnWindowChangesFocusedApp(data) {
209− data.apps.forEach(startApplication);
210− var fromAppId = data.apps[data.focusfrom];
211− var toAppId = data.apps[data.focusTo]
259+ var appDelegates = [];
260+ for (var i = 0; i < data.apps.length; i++) {
261+ appDelegates[i] = startApplication(data.apps[i]);
262+ }
263+ var fromDelegate = appDelegates[data.focusfrom];
264+ var toDelegate = appDelegates[data.focusTo];
212265
213− var fromAppWindow = findChild(desktopStage, "appWindow_" + fromAppId);
266+ var fromAppWindow = findChild(fromDelegate, "appWindow");
214267 verify(fromAppWindow);
215268 tap(fromAppWindow);
216− compare(fromAppWindow.application.session.lastSurface.activeFocus, true);
217− compare(ApplicationManager.focusedApplicationId, fromAppId);
269+ compare(fromDelegate.surface.activeFocus, true);
270+ compare(MirFocusController.focusedSurface, fromDelegate.surface);
218271
219− var toAppWindow = findChild(desktopStage, "appWindow_" + toAppId);
272+ var toAppWindow = findChild(toDelegate, "appWindow");
220273 verify(toAppWindow);
221274 tap(toAppWindow);
222− compare(toAppWindow.application.session.lastSurface.activeFocus, true);
223− compare(ApplicationManager.focusedApplicationId, toAppId);
275+ compare(toDelegate.surface.activeFocus, true);
276+ compare(MirFocusController.focusedSurface, toDelegate.surface);
224277 }
225278
226279 function test_clickingOnWindowChangesFocusedApp_data() {
@@ -228,21 +281,24 @@ Item {
228281 }
229282
230283 function test_clickingOnWindowChangesFocusedApp(data) {
231− data.apps.forEach(startApplication);
232− var fromAppId = data.apps[data.focusfrom];
233− var toAppId = data.apps[data.focusTo]
284+ var appDelegates = [];
285+ for (var i = 0; i < data.apps.length; i++) {
286+ appDelegates[i] = startApplication(data.apps[i]);
287+ }
288+ var fromDelegate = appDelegates[data.focusfrom];
289+ var toDelegate = appDelegates[data.focusTo];
234290
235− var fromAppWindow = findChild(desktopStage, "appWindow_" + fromAppId);
291+ var fromAppWindow = findChild(fromDelegate, "appWindow");
236292 verify(fromAppWindow);
237293 mouseClick(fromAppWindow);
238− compare(fromAppWindow.application.session.lastSurface.activeFocus, true);
239− compare(ApplicationManager.focusedApplicationId, fromAppId);
294+ compare(fromDelegate.surface.activeFocus, true);
295+ compare(MirFocusController.focusedSurface, fromDelegate.surface);
240296
241− var toAppWindow = findChild(desktopStage, "appWindow_" + toAppId);
297+ var toAppWindow = findChild(toDelegate, "appWindow");
242298 verify(toAppWindow);
243299 mouseClick(toAppWindow);
244− compare(toAppWindow.application.session.lastSurface.activeFocus, true);
245− compare(ApplicationManager.focusedApplicationId, toAppId);
300+ compare(toDelegate.surface.activeFocus, true);
301+ compare(MirFocusController.focusedSurface, toDelegate.surface);
246302 }
247303
248304 function test_tappingOnDecorationFocusesApplication_data() {
@@ -252,24 +308,49 @@ Item {
252308 ]
253309 }
254310
311+ function findDecoratedWindow(surfaceId) {
312+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
313+ if (!appDelegate) {
314+ console.warn("Could not find appDelegate for surfaceId="+surfaceId);
315+ return null;
316+ }
317+ return findChild(appDelegate, "decoratedWindow");
318+ }
319+
320+ function findWindowDecoration(surfaceId) {
321+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
322+ if (!appDelegate) {
323+ console.warn("Could not find appDelegate for surfaceId="+surfaceId);
324+ return null;
325+ }
326+ return findChild(appDelegate, "appWindowDecoration");
327+ }
328+
255329 function test_tappingOnDecorationFocusesApplication(data) {
256− data.apps.forEach(startApplication);
330+ var appDelegates = [];
331+ for (var i = 0; i < data.apps.length; i++) {
332+ appDelegates[i] = startApplication(data.apps[i]);
333+ }
334+
335+ var fromDelegate = appDelegates[data.focusfrom];
336+ var toDelegate = appDelegates[data.focusTo];
257337
258− var fromAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusfrom]);
338+ var fromAppDecoration = findChild(fromDelegate, "appWindowDecoration");
259339 verify(fromAppDecoration);
260340 tap(fromAppDecoration);
261341
262− var fromApp = ApplicationManager.findApplication(data.apps[data.focusfrom]);
263− verify(fromApp);
264− tryCompare(fromApp.session.lastSurface, "activeFocus", true);
342+ tryCompare(fromDelegate.surface, "activeFocus", true);
265343
266− var toAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusTo]);
344+ var toAppDecoration = findChild(toDelegate, "appWindowDecoration");
267345 verify(toAppDecoration);
346+
347+ // FIXME: Wait a bit before the second tap or the window decoration will say it got double clicked.
348+ // No idea why.
349+ wait(700);
350+
268351 tap(toAppDecoration);
269352
270− var toApp = ApplicationManager.findApplication(data.apps[data.focusTo]);
271− verify(toApp);
272− tryCompare(toApp.session.lastSurface, "activeFocus", true);
353+ tryCompare(toDelegate.surface, "activeFocus", true);
273354 }
274355
275356 function test_clickingOnDecorationFocusesApplication_data() {
@@ -277,159 +358,170 @@ Item {
277358 }
278359
279360 function test_clickingOnDecorationFocusesApplication(data) {
280− data.apps.forEach(startApplication);
361+ var appDelegates = [];
362+ for (var i = 0; i < data.apps.length; i++) {
363+ appDelegates[i] = startApplication(data.apps[i]);
364+ }
365+ var fromDelegate = appDelegates[data.focusfrom];
366+ var toDelegate = appDelegates[data.focusTo];
281367
282− var fromAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusfrom]);
368+ var fromAppDecoration = findChild(fromDelegate, "appWindowDecoration");
283369 verify(fromAppDecoration);
284370 mouseClick(fromAppDecoration);
285− tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.lastSurface, "activeFocus", true);
371+ tryCompare(fromDelegate.surface, "activeFocus", true);
286372
287− var toAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusTo]);
373+ var toAppDecoration = findChild(toDelegate, "appWindowDecoration");
288374 verify(toAppDecoration);
289375 mouseClick(toAppDecoration);
290− tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.lastSurface, "activeFocus", true);
376+ tryCompare(toDelegate.surface, "activeFocus", true);
291377 }
292378
293379 function test_windowMaximize() {
294− var apps = ["unity8-dash", "dialer-app", "camera-app"];
295− apps.forEach(startApplication);
296− var appName = "dialer-app";
297− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
298− verify(appDelegate);
299− ApplicationManager.focusApplication(appName);
380+ var dialerDelegate = startApplication("dialer-app");
381+ startApplication("camera-app");
382+
383+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
384+ dialerDelegate.surface.requestFocus();
385+ tryCompare(dialerDelegate, "focus", true);
386+
300387 keyClick(Qt.Key_Up, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Up shortcut to maximize
301− tryCompare(appDelegate, "maximized", true);
302− tryCompare(appDelegate, "minimized", false);
388+ tryCompare(dialerDelegate, "maximized", true);
389+ tryCompare(dialerDelegate, "minimized", false);
303390 }
304391
305392 function test_windowMaximizeLeft() {
306− var apps = ["unity8-dash", "dialer-app", "camera-app"];
307− apps.forEach(startApplication);
308− var appName = "dialer-app";
309− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
310− verify(appDelegate);
311− ApplicationManager.focusApplication(appName);
393+ var dialerDelegate = startApplication("dialer-app");
394+ startApplication("camera-app");
395+
396+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
397+ dialerDelegate.surface.requestFocus();
398+ tryCompare(dialerDelegate, "focus", true);
399+
312400 keyClick(Qt.Key_Left, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Left shortcut to maximizeLeft
313− tryCompare(appDelegate, "maximized", false);
314− tryCompare(appDelegate, "minimized", false);
315− tryCompare(appDelegate, "maximizedLeft", true);
316− tryCompare(appDelegate, "maximizedRight", false);
401+ tryCompare(dialerDelegate, "maximized", false);
402+ tryCompare(dialerDelegate, "minimized", false);
403+ tryCompare(dialerDelegate, "maximizedLeft", true);
404+ tryCompare(dialerDelegate, "maximizedRight", false);
317405 }
318406
319407 function test_windowMaximizeRight() {
320− var apps = ["unity8-dash", "dialer-app", "camera-app"];
321− apps.forEach(startApplication);
322− var appName = "dialer-app";
323− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
324− verify(appDelegate);
325− ApplicationManager.focusApplication(appName);
408+ var dialerDelegate = startApplication("dialer-app");
409+ startApplication("camera-app");
410+
411+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
412+ dialerDelegate.surface.requestFocus();
413+ tryCompare(dialerDelegate, "focus", true);
414+
326415 keyClick(Qt.Key_Right, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Right shortcut to maximizeRight
327− tryCompare(appDelegate, "maximized", false);
328− tryCompare(appDelegate, "minimized", false);
329− tryCompare(appDelegate, "maximizedLeft", false);
330− tryCompare(appDelegate, "maximizedRight", true);
416+ tryCompare(dialerDelegate, "maximized", false);
417+ tryCompare(dialerDelegate, "minimized", false);
418+ tryCompare(dialerDelegate, "maximizedLeft", false);
419+ tryCompare(dialerDelegate, "maximizedRight", true);
331420 }
332421
333422 function test_windowMinimize() {
334− var apps = ["unity8-dash", "dialer-app", "camera-app"];
335− apps.forEach(startApplication);
336− var appName = "dialer-app";
337− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
338− verify(appDelegate);
339− ApplicationManager.focusApplication(appName);
423+ var dialerDelegate = startApplication("dialer-app");
424+ startApplication("camera-app");
425+
426+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
427+ dialerDelegate.surface.requestFocus();
428+ tryCompare(dialerDelegate, "focus", true);
429+
340430 keyClick(Qt.Key_Down, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Down shortcut to minimize
341− tryCompare(appDelegate, "maximized", false);
342− tryCompare(appDelegate, "minimized", true);
431+ tryCompare(dialerDelegate, "maximized", false);
432+ tryCompare(dialerDelegate, "minimized", true);
343433 verify(ApplicationManager.focusedApplicationId != ""); // verify we don't lose focus when minimizing an app
344434 }
345435
346436 function test_windowMinimizeAll() {
347437 var apps = ["unity8-dash", "dialer-app", "camera-app"];
348438 apps.forEach(startApplication);
349− verify(ApplicationManager.count == 3);
439+ verify(topSurfaceList.count == 3);
350440 keyClick(Qt.Key_D, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+D shortcut to minimize all
351441 tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify no app is focused
352442 }
353443
354444 function test_windowClose() {
355− var apps = ["unity8-dash", "dialer-app", "camera-app"];
356− apps.forEach(startApplication);
357− verify(ApplicationManager.count == 3);
358− var appName = "dialer-app";
359− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
360− verify(appDelegate);
361− ApplicationManager.focusApplication(appName);
445+ var dialerSurfaceId = topSurfaceList.nextId;
446+ var dialerDelegate = startApplication("dialer-app");
447+ verify(topSurfaceList.indexForId(dialerSurfaceId) !== -1);
448+ startApplication("gmail-webapp");
449+ verify(topSurfaceList.count == 3);
450+
451+ mouseClick(dialerDelegate);
452+
453+ var desktopStagePriv = findInvisibleChild(desktopStage, "DesktopStagePrivate");
454+ tryCompare(desktopStagePriv, "focusedAppDelegate", dialerDelegate);
455+
362456 keyClick(Qt.Key_F4, Qt.AltModifier); // Alt+F4 shortcut to close
363− verify(ApplicationManager.count == 2); // verify the app is gone
364− verify(ApplicationManager.findApplication(appName) === null); // and it's not in running apps
457+
458+ // verify the surface is gone
459+ tryCompare(topSurfaceList, "count", 2);
460+ verify(topSurfaceList.indexForId(dialerSurfaceId) === -1);
365461 }
366462
367463 function test_smashCursorKeys() {
368− var apps = ["unity8-dash", "dialer-app", "camera-app"];
464+ var apps = ["dialer-app", "gmail-webapp"];
369465 apps.forEach(startApplication);
370− verify(ApplicationManager.count == 3);
466+ verify(topSurfaceList.count == 3);
371467 keyClick(Qt.Key_D, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+D shortcut to minimize all
372− tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify no app is focused
468+ tryCompare(MirFocusController, "focusedSurface", null); // verify no surface is focused
373469
374470 // now try pressing all 4 arrow keys + ctrl + meta
375471 keyClick(Qt.Key_Up | Qt.Key_Down | Qt.Key_Left | Qt.Key_Right, Qt.MetaModifier|Qt.ControlModifier); // smash it!!!
376− tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify still no app is focused
472+ tryCompare(MirFocusController, "focusedSurface", null); // verify still no surface is focused
377473 }
378474
379475 function test_minimizeApplicationHidesSurface() {
380− var dashApp = startApplication("unity8-dash");
476+ compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
477+ var dashSurface = topSurfaceList.surfaceAt(0);
478+ var dashSurfaceId = topSurfaceList.idAt(0);
381479
382− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
383− verify(dashDelegate);
480+ var decoratedWindow = findDecoratedWindow(dashSurfaceId);
481+ verify(decoratedWindow);
384482
385− findChild(dashDelegate, "decoratedWindow").minimize();
386− tryCompare(dashApp.session.lastSurface, "visible", false);
483+ tryCompare(dashSurface, "visible", true);
484+ decoratedWindow.minimize();
485+ tryCompare(dashSurface, "visible", false);
387486 }
388487
389488 function test_maximizeApplicationHidesSurfacesBehindIt() {
390− var dashApp = startApplication("unity8-dash");
391− var dialerApp = startApplication("dialer-app");
392− var gmailApp = startApplication("gmail-webapp");
489+ var dashDelegate = startApplication("unity8-dash");
490+ var dialerDelegate = startApplication("dialer-app");
491+ var gmailDelegate = startApplication("gmail-webapp");
393492
394− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
395− verify(dashDelegate);
396− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
397− verify(dialerDelegate);
398− var gmailDelegate = findChild(desktopStage, "appDelegate_gmail-webapp");
399− verify(gmailDelegate);
400−
401− // maximize
493+ // maximize without raising
402494 dialerDelegate.maximize();
403495 tryCompare(dialerDelegate, "visuallyMaximized", true);
404496
405− tryCompare(dashApp.session.lastSurface, "visible", false);
406− compare(gmailApp.session.lastSurface.visible, true);
497+ tryCompare(dashDelegate.surface, "visible", false);
498+ compare(gmailDelegate.surface.visible, true);
407499
408− // restore
500+ // restore without raising
409501 dialerDelegate.restoreFromMaximized();
410− compare(dashApp.session.lastSurface.visible, true);
411− compare(gmailApp.session.lastSurface.visible, true);
502+ compare(dashDelegate.surface.visible, true);
503+ compare(gmailDelegate.surface.visible, true);
412504 }
413505
414506 function test_applicationsBecomeVisibleWhenOccludingAppRemoved() {
415− var dashApp = startApplication("unity8-dash");
416− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
417− verify(dashDelegate);
507+ var dashApp = topSurfaceList.applicationAt(0);
418508
419− var dialerApp = startApplication("dialer-app");
420− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
509+ var dialerSurfaceId = topSurfaceList.nextId;
510+ var dialerDelegate = startApplication("dialer-app");
421511 verify(dialerDelegate);
512+ var dialerApp = dialerDelegate.application;
422513
423514 var dialerMaximizeButton = findChild(dialerDelegate, "maximizeWindowButton");
424515 verify(dialerMaximizeButton);
425516 mouseClick(dialerMaximizeButton);
426517
427− var mapApp = startApplication("map");
428− var mapDelegate = findChild(desktopStage, "appDelegate_map");
518+ var mapSurfaceId = topSurfaceList.nextId;
519+ var mapDelegate = startApplication("map");
429520 verify(mapDelegate);
521+ var mapApp = mapDelegate.application;
430522
431− var gmailApp = startApplication("gmail-webapp");
432− var gmailDelegate = findChild(desktopStage, "appDelegate_gmail-webapp");
523+ var gmailSurfaceId = topSurfaceList.nextId;
524+ var gmailDelegate = startApplication("gmail-webapp");
433525 verify(gmailDelegate);
434526
435527 var gmailMaximizeButton = findChild(gmailDelegate, "maximizeWindowButton");
@@ -439,29 +531,27 @@ Item {
439531 tryCompare(dialerDelegate, "visuallyMaximized", true);
440532 tryCompare(gmailDelegate, "visuallyMaximized", true);
441533
442− tryCompare(dashApp.session.lastSurface, "visible", false);
443− tryCompare(dialerApp.session.lastSurface, "visible", false);
444− tryCompare(mapApp.session.lastSurface, "visible", false);
534+ tryCompare(dashApp.surfaceList.get(0), "visible", false);
535+ tryCompare(dialerApp.surfaceList.get(0), "visible", false);
536+ tryCompare(mapApp.surfaceList.get(0), "visible", false);
445537
446538 ApplicationManager.stopApplication("gmail-webapp");
447539
448− compare(mapApp.session.lastSurface.visible, true);
449− tryCompare(dialerApp.session.lastSurface, "visible", true);
450− tryCompare(dashApp.session.lastSurface, "visible", false); // still occluded by maximised dialer
540+ tryCompare(mapApp.surfaceList.get(0), "visible", true);
541+ tryCompare(dialerApp.surfaceList.get(0), "visible", true);
542+ tryCompare(dashApp.surfaceList.get(0), "visible", false); // still occluded by maximised dialer
451543 }
452544
453545 function test_maximisedAppStaysVisibleWhenAppStarts() {
454− var dashApp = startApplication("unity8-dash");
455− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
456− verify(dashDelegate);
546+ var dashDelegate = startApplication("unity8-dash");
547+
457548 // maximize
458549 var dashMaximizeButton = findChild(dashDelegate, "maximizeWindowButton");
459550 verify(dashMaximizeButton);
460551 mouseClick(dashMaximizeButton);
461552 tryCompare(dashDelegate, "visuallyMaximized", true);
462553
463− var dialerApp = startApplication("dialer-app");
464− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
554+ var dialerDelegate = startApplication("dialer-app");
465555 verify(dialerDelegate);
466556
467557 compare(dialerDelegate.visible, true, "Dialer should be visible");
@@ -469,14 +559,11 @@ Item {
469559 }
470560
471561 function test_occlusionWithMultipleMaximized() {
472− var dashApp = startApplication("unity8-dash");
473− var dashAppDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
562+ var dashAppDelegate = startApplication("unity8-dash");
474563
475− var dialerApp = startApplication("dialer-app");
476− var dialerAppDelegate = findChild(desktopStage, "appDelegate_dialer-app");
564+ var dialerAppDelegate = startApplication("dialer-app");
477565
478− var facebookApp = startApplication("facebook-webapp");
479− var facebookAppDelegate = findChild(desktopStage, "appDelegate_facebook-webapp");
566+ var facebookAppDelegate = startApplication("facebook-webapp");
480567
481568 // all of them are in restored state now. all should be visible
482569 tryCompare(dashAppDelegate, "visible", true);
@@ -490,13 +577,13 @@ Item {
490577 tryCompare(facebookAppDelegate, "visible", true);
491578
492579 // Bring dash to front. make sure dash and the maximized facebook are visible, the restored one behind is hidden
493− ApplicationManager.focusApplication("unity8-dash");
580+ dashAppDelegate.focus = true;
494581 tryCompare(dashAppDelegate, "visible", true);
495582 tryCompare(dialerAppDelegate, "visible", false);
496583 tryCompare(facebookAppDelegate, "visible", true);
497584
498585 // Now focus the dialer app. all 3 should be visible again
499− ApplicationManager.focusApplication("dialer-app");
586+ dialerAppDelegate.focus = true;
500587 tryCompare(dashAppDelegate, "visible", true);
501588 tryCompare(dialerAppDelegate, "visible", true);
502589 tryCompare(facebookAppDelegate, "visible", true);
@@ -509,20 +596,15 @@ Item {
509596 }
510597
511598 function test_dropShadow() {
512− // verify the drop shadow is not visible initially
513− verify(PanelState.dropShadow == false);
514−
515599 // start an app, maximize it
516− var facebookApp = startApplication("facebook-webapp");
517− var facebookAppDelegate = findChild(desktopStage, "appDelegate_facebook-webapp");
600+ var facebookAppDelegate = startApplication("facebook-webapp");
518601 facebookAppDelegate.maximize();
519602
520603 // verify the drop shadow is still not visible
521604 verify(PanelState.dropShadow == false);
522605
523606 // start a foreground app, not maximized
524− var dialerApp = startApplication("dialer-app");
525− var dialerAppDelegate = findChild(desktopStage, "appDelegate_dialer-app");
607+ var dialerAppDelegate = startApplication("dialer-app");
526608
527609 // verify the drop shadow becomes visible
528610 verify(PanelState.dropShadow == true);
@@ -531,7 +613,7 @@ Item {
531613 ApplicationManager.stopApplication("facebook-webapp");
532614
533615 // verify the drop shadow is gone
534− verify(PanelState.dropShadow == false);
616+ tryCompare(PanelState, "dropShadow", false);
535617 }
536618 }
537619}