@@ -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
@@ -68,6 +74,7 @@ Item {
6874 color: "white"
6975 anchors.fill: parent
7076 background: "../../../qml/graphics/tablet_background.jpg"
77+ focus: true
7178
7279 Component.onCompleted: {
7380 edgeBarrierControls.target = testCase.findChild(this, "edgeBarrierController");
@@ -76,6 +83,8 @@ Item {
7683 desktopStageLoader.itemDestroyed = true;
7784 }
7885 orientations: Orientations {}
86+ applicationManager: ApplicationManager
87+ topLevelSurfaceList: topSurfaceList
7988 }
8089 }
8190 }
@@ -103,7 +112,7 @@ Item {
103112 activeFocusOnPress: false
104113 onClicked: {
105114 if (ApplicationManager.focusedApplicationId) {
106− var surface = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).session.lastSurface;
115+ var surface = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).surfaceList.get(0);
107116 surface.slowToResize = true;
108117 }
109118 }
@@ -137,6 +146,19 @@ Item {
137146
138147 property Item desktopStage: desktopStageLoader.status === Loader.Ready ? desktopStageLoader.item : null
139148
149+ function init() {
150+ // wait until unity8-dash is up and running.
151+ // it's started automatically by ApplicationManager mock implementation
152+ tryCompare(ApplicationManager, "count", 1);
153+ var dashApp = ApplicationManager.findApplication("unity8-dash");
154+ verify(dashApp);
155+ tryCompare(dashApp, "state", ApplicationInfoInterface.Running);
156+
157+ tryCompare(topSurfaceList, "count", 1);
158+ tryCompareFunction(function(){return topSurfaceList.surfaceAt(0) != null;}, true);
159+ compare(MirFocusController.focusedSurface, topSurfaceList.surfaceAt(0));
160+ }
161+
140162 function cleanup() {
141163 desktopStageLoader.itemDestroyed = false;
142164 desktopStageLoader.active = false;
@@ -149,43 +171,71 @@ Item {
149171 // Shell instance gets destroyed.
150172 tryCompare(desktopStageLoader, "itemDestroyed", true);
151173
152− killAllRunningApps();
174+ killApps();
175+
176+ root.resetGeometry();
153177
154178 desktopStageLoader.active = true;
155179 tryCompare(desktopStageLoader, "status", Loader.Ready);
156− root.resetGeometry();
157− }
158180
159− function killAllRunningApps() {
160− while (ApplicationManager.count > 0) {
161− ApplicationManager.stopApplication(ApplicationManager.get(0).appId);
162− }
163− compare(ApplicationManager.count, 0)
164181 }
165182
166− function waitUntilAppSurfaceShowsUp(appId) {
167− var appWindow = findChild(desktopStage, "appWindow_" + appId);
183+ function waitUntilAppSurfaceShowsUp(surfaceId) {
184+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
185+ verify(appDelegate);
186+ var appWindow = findChild(appDelegate, "appWindow");
168187 verify(appWindow);
169188 var appWindowStates = findInvisibleChild(appWindow, "applicationWindowStateGroup");
170189 verify(appWindowStates);
171190 tryCompare(appWindowStates, "state", "surface");
172191 }
173192
193+ /*
194+ Returns the appDelegate of the first surface created by the app with the specified appId
195+ */
174196 function startApplication(appId) {
175− var app = ApplicationManager.findApplication(appId);
176− if (!app) {
197+ try {
198+ var app = ApplicationManager.findApplication(appId);
199+ if (app) {
200+ for (var i = 0; i < topSurfaceList.count; i++) {
201+ if (topSurfaceList.applicationAt(i).appId === appId) {
202+ var appRepeater = findChild(desktopStage, "appRepeater");
203+ verify(appRepeater);
204+ return appRepeater.itemAt(i);
205+ }
206+ }
207+ }
208+
209+ var surfaceId = topSurfaceList.nextId;
177210 app = ApplicationManager.startApplication(appId);
211+ verify(app);
212+ waitUntilAppSurfaceShowsUp(surfaceId);
213+ compare(app.surfaceList.count, 1);
214+
215+ return findChild(desktopStage, "appDelegate_" + surfaceId);
216+ } catch(err) {
217+ throw new Error("startApplication("+appId+") called from line " + util.callerLine(1) + " failed!");
218+ }
219+ }
220+
221+ function maximizeAppDelegate(appDelegate) {
222+ var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
223+ if (!maximizeButton) {
224+ fail("Could not find maximizeWindowButton of appDelegate=" + appDelegate);
225+ }
226+ mouseClick(maximizeButton);
227+
228+ try {
229+ tryCompare(appDelegate, "visuallyMaximized", true);
230+ } catch(err) {
231+ fail("appDelegate.visuallyMaximized !== true");
178232 }
179− verify(app);
180− waitUntilAppSurfaceShowsUp(appId);
181− verify(app.session.lastSurface);
182− return app;
183233 }
184234
185235 function test_appFocusSwitch_data() {
186236 return [
187− {tag: "dash to dialer", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
188− {tag: "dialer to dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
237+ {tag: "dash to dialer", apps: [ "unity8-dash", "dialer-app", "gmail-webapp" ], focusfrom: 0, focusTo: 1 },
238+ {tag: "dialer to dash", apps: [ "unity8-dash", "dialer-app", "gmail-webapp" ], focusfrom: 1, focusTo: 0 },
189239 ]
190240 }
191241
@@ -193,10 +243,10 @@ Item {
193243 data.apps.forEach(startApplication);
194244
195245 ApplicationManager.requestFocusApplication(data.apps[data.focusfrom]);
196− tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.lastSurface, "activeFocus", true);
246+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).surfaceList.get(0), "activeFocus", true);
197247
198248 ApplicationManager.requestFocusApplication(data.apps[data.focusTo]);
199− tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.lastSurface, "activeFocus", true);
249+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).surfaceList.get(0), "activeFocus", true);
200250 }
201251
202252 function test_tappingOnWindowChangesFocusedApp_data() {
@@ -207,21 +257,24 @@ Item {
207257 }
208258
209259 function test_tappingOnWindowChangesFocusedApp(data) {
210− data.apps.forEach(startApplication);
211− var fromAppId = data.apps[data.focusfrom];
212− var toAppId = data.apps[data.focusTo]
260+ var appDelegates = [];
261+ for (var i = 0; i < data.apps.length; i++) {
262+ appDelegates[i] = startApplication(data.apps[i]);
263+ }
264+ var fromDelegate = appDelegates[data.focusfrom];
265+ var toDelegate = appDelegates[data.focusTo];
213266
214− var fromAppWindow = findChild(desktopStage, "appWindow_" + fromAppId);
267+ var fromAppWindow = findChild(fromDelegate, "appWindow");
215268 verify(fromAppWindow);
216269 tap(fromAppWindow);
217− compare(fromAppWindow.application.session.lastSurface.activeFocus, true);
218− compare(ApplicationManager.focusedApplicationId, fromAppId);
270+ compare(fromDelegate.surface.activeFocus, true);
271+ compare(MirFocusController.focusedSurface, fromDelegate.surface);
219272
220− var toAppWindow = findChild(desktopStage, "appWindow_" + toAppId);
273+ var toAppWindow = findChild(toDelegate, "appWindow");
221274 verify(toAppWindow);
222275 tap(toAppWindow);
223− compare(toAppWindow.application.session.lastSurface.activeFocus, true);
224− compare(ApplicationManager.focusedApplicationId, toAppId);
276+ compare(toDelegate.surface.activeFocus, true);
277+ compare(MirFocusController.focusedSurface, toDelegate.surface);
225278 }
226279
227280 function test_clickingOnWindowChangesFocusedApp_data() {
@@ -229,21 +282,24 @@ Item {
229282 }
230283
231284 function test_clickingOnWindowChangesFocusedApp(data) {
232− data.apps.forEach(startApplication);
233− var fromAppId = data.apps[data.focusfrom];
234− var toAppId = data.apps[data.focusTo]
285+ var appDelegates = [];
286+ for (var i = 0; i < data.apps.length; i++) {
287+ appDelegates[i] = startApplication(data.apps[i]);
288+ }
289+ var fromDelegate = appDelegates[data.focusfrom];
290+ var toDelegate = appDelegates[data.focusTo];
235291
236− var fromAppWindow = findChild(desktopStage, "appWindow_" + fromAppId);
292+ var fromAppWindow = findChild(fromDelegate, "appWindow");
237293 verify(fromAppWindow);
238294 mouseClick(fromAppWindow);
239− compare(fromAppWindow.application.session.lastSurface.activeFocus, true);
240− compare(ApplicationManager.focusedApplicationId, fromAppId);
295+ compare(fromDelegate.surface.activeFocus, true);
296+ compare(MirFocusController.focusedSurface, fromDelegate.surface);
241297
242− var toAppWindow = findChild(desktopStage, "appWindow_" + toAppId);
298+ var toAppWindow = findChild(toDelegate, "appWindow");
243299 verify(toAppWindow);
244300 mouseClick(toAppWindow);
245− compare(toAppWindow.application.session.lastSurface.activeFocus, true);
246− compare(ApplicationManager.focusedApplicationId, toAppId);
301+ compare(toDelegate.surface.activeFocus, true);
302+ compare(MirFocusController.focusedSurface, toDelegate.surface);
247303 }
248304
249305 function test_tappingOnDecorationFocusesApplication_data() {
@@ -253,24 +309,49 @@ Item {
253309 ]
254310 }
255311
312+ function findDecoratedWindow(surfaceId) {
313+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
314+ if (!appDelegate) {
315+ console.warn("Could not find appDelegate for surfaceId="+surfaceId);
316+ return null;
317+ }
318+ return findChild(appDelegate, "decoratedWindow");
319+ }
320+
321+ function findWindowDecoration(surfaceId) {
322+ var appDelegate = findChild(desktopStage, "appDelegate_" + surfaceId);
323+ if (!appDelegate) {
324+ console.warn("Could not find appDelegate for surfaceId="+surfaceId);
325+ return null;
326+ }
327+ return findChild(appDelegate, "appWindowDecoration");
328+ }
329+
256330 function test_tappingOnDecorationFocusesApplication(data) {
257− data.apps.forEach(startApplication);
331+ var appDelegates = [];
332+ for (var i = 0; i < data.apps.length; i++) {
333+ appDelegates[i] = startApplication(data.apps[i]);
334+ }
335+
336+ var fromDelegate = appDelegates[data.focusfrom];
337+ var toDelegate = appDelegates[data.focusTo];
258338
259− var fromAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusfrom]);
339+ var fromAppDecoration = findChild(fromDelegate, "appWindowDecoration");
260340 verify(fromAppDecoration);
261341 tap(fromAppDecoration);
262342
263− var fromApp = ApplicationManager.findApplication(data.apps[data.focusfrom]);
264− verify(fromApp);
265− tryCompare(fromApp.session.lastSurface, "activeFocus", true);
343+ tryCompare(fromDelegate.surface, "activeFocus", true);
266344
267− var toAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusTo]);
345+ var toAppDecoration = findChild(toDelegate, "appWindowDecoration");
268346 verify(toAppDecoration);
347+
348+ // FIXME: Wait a bit before the second tap or the window decoration will say it got double clicked.
349+ // No idea why.
350+ wait(700);
351+
269352 tap(toAppDecoration);
270353
271− var toApp = ApplicationManager.findApplication(data.apps[data.focusTo]);
272− verify(toApp);
273− tryCompare(toApp.session.lastSurface, "activeFocus", true);
354+ tryCompare(toDelegate.surface, "activeFocus", true);
274355 }
275356
276357 function test_clickingOnDecorationFocusesApplication_data() {
@@ -278,159 +359,170 @@ Item {
278359 }
279360
280361 function test_clickingOnDecorationFocusesApplication(data) {
281− data.apps.forEach(startApplication);
362+ var appDelegates = [];
363+ for (var i = 0; i < data.apps.length; i++) {
364+ appDelegates[i] = startApplication(data.apps[i]);
365+ }
366+ var fromDelegate = appDelegates[data.focusfrom];
367+ var toDelegate = appDelegates[data.focusTo];
282368
283− var fromAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusfrom]);
369+ var fromAppDecoration = findChild(fromDelegate, "appWindowDecoration");
284370 verify(fromAppDecoration);
285371 mouseClick(fromAppDecoration);
286− tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.lastSurface, "activeFocus", true);
372+ tryCompare(fromDelegate.surface, "activeFocus", true);
287373
288− var toAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusTo]);
374+ var toAppDecoration = findChild(toDelegate, "appWindowDecoration");
289375 verify(toAppDecoration);
290376 mouseClick(toAppDecoration);
291− tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.lastSurface, "activeFocus", true);
377+ tryCompare(toDelegate.surface, "activeFocus", true);
292378 }
293379
294380 function test_windowMaximize() {
295− var apps = ["unity8-dash", "dialer-app", "camera-app"];
296− apps.forEach(startApplication);
297− var appName = "dialer-app";
298− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
299− verify(appDelegate);
300− ApplicationManager.focusApplication(appName);
381+ var dialerDelegate = startApplication("dialer-app");
382+ startApplication("camera-app");
383+
384+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
385+ dialerDelegate.surface.requestFocus();
386+ tryCompare(dialerDelegate, "focus", true);
387+
301388 keyClick(Qt.Key_Up, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Up shortcut to maximize
302− tryCompare(appDelegate, "maximized", true);
303− tryCompare(appDelegate, "minimized", false);
389+ tryCompare(dialerDelegate, "maximized", true);
390+ tryCompare(dialerDelegate, "minimized", false);
304391 }
305392
306393 function test_windowMaximizeLeft() {
307− var apps = ["unity8-dash", "dialer-app", "camera-app"];
308− apps.forEach(startApplication);
309− var appName = "dialer-app";
310− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
311− verify(appDelegate);
312− ApplicationManager.focusApplication(appName);
394+ var dialerDelegate = startApplication("dialer-app");
395+ startApplication("camera-app");
396+
397+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
398+ dialerDelegate.surface.requestFocus();
399+ tryCompare(dialerDelegate, "focus", true);
400+
313401 keyClick(Qt.Key_Left, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Left shortcut to maximizeLeft
314− tryCompare(appDelegate, "maximized", false);
315− tryCompare(appDelegate, "minimized", false);
316− tryCompare(appDelegate, "maximizedLeft", true);
317− tryCompare(appDelegate, "maximizedRight", false);
402+ tryCompare(dialerDelegate, "maximized", false);
403+ tryCompare(dialerDelegate, "minimized", false);
404+ tryCompare(dialerDelegate, "maximizedLeft", true);
405+ tryCompare(dialerDelegate, "maximizedRight", false);
318406 }
319407
320408 function test_windowMaximizeRight() {
321− var apps = ["unity8-dash", "dialer-app", "camera-app"];
322− apps.forEach(startApplication);
323− var appName = "dialer-app";
324− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
325− verify(appDelegate);
326− ApplicationManager.focusApplication(appName);
409+ var dialerDelegate = startApplication("dialer-app");
410+ startApplication("camera-app");
411+
412+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
413+ dialerDelegate.surface.requestFocus();
414+ tryCompare(dialerDelegate, "focus", true);
415+
327416 keyClick(Qt.Key_Right, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Right shortcut to maximizeRight
328− tryCompare(appDelegate, "maximized", false);
329− tryCompare(appDelegate, "minimized", false);
330− tryCompare(appDelegate, "maximizedLeft", false);
331− tryCompare(appDelegate, "maximizedRight", true);
417+ tryCompare(dialerDelegate, "maximized", false);
418+ tryCompare(dialerDelegate, "minimized", false);
419+ tryCompare(dialerDelegate, "maximizedLeft", false);
420+ tryCompare(dialerDelegate, "maximizedRight", true);
332421 }
333422
334423 function test_windowMinimize() {
335− var apps = ["unity8-dash", "dialer-app", "camera-app"];
336− apps.forEach(startApplication);
337− var appName = "dialer-app";
338− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
339− verify(appDelegate);
340− ApplicationManager.focusApplication(appName);
424+ var dialerDelegate = startApplication("dialer-app");
425+ startApplication("camera-app");
426+
427+ tryCompareFunction(function(){ return dialerDelegate.surface !== null; }, true);
428+ dialerDelegate.surface.requestFocus();
429+ tryCompare(dialerDelegate, "focus", true);
430+
341431 keyClick(Qt.Key_Down, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+Down shortcut to minimize
342− tryCompare(appDelegate, "maximized", false);
343− tryCompare(appDelegate, "minimized", true);
432+ tryCompare(dialerDelegate, "maximized", false);
433+ tryCompare(dialerDelegate, "minimized", true);
344434 verify(ApplicationManager.focusedApplicationId != ""); // verify we don't lose focus when minimizing an app
345435 }
346436
347437 function test_windowMinimizeAll() {
348438 var apps = ["unity8-dash", "dialer-app", "camera-app"];
349439 apps.forEach(startApplication);
350− verify(ApplicationManager.count == 3);
440+ verify(topSurfaceList.count == 3);
351441 keyClick(Qt.Key_D, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+D shortcut to minimize all
352442 tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify no app is focused
353443 }
354444
355445 function test_windowClose() {
356− var apps = ["unity8-dash", "dialer-app", "camera-app"];
357− apps.forEach(startApplication);
358− verify(ApplicationManager.count == 3);
359− var appName = "dialer-app";
360− var appDelegate = findChild(desktopStage, "appDelegate_" + appName);
361− verify(appDelegate);
362− ApplicationManager.focusApplication(appName);
446+ var dialerSurfaceId = topSurfaceList.nextId;
447+ var dialerDelegate = startApplication("dialer-app");
448+ verify(topSurfaceList.indexForId(dialerSurfaceId) !== -1);
449+ startApplication("gmail-webapp");
450+ verify(topSurfaceList.count == 3);
451+
452+ mouseClick(dialerDelegate);
453+
454+ var desktopStagePriv = findInvisibleChild(desktopStage, "DesktopStagePrivate");
455+ tryCompare(desktopStagePriv, "focusedAppDelegate", dialerDelegate);
456+
363457 keyClick(Qt.Key_F4, Qt.AltModifier); // Alt+F4 shortcut to close
364− verify(ApplicationManager.count == 2); // verify the app is gone
365− verify(ApplicationManager.findApplication(appName) === null); // and it's not in running apps
458+
459+ // verify the surface is gone
460+ tryCompare(topSurfaceList, "count", 2);
461+ verify(topSurfaceList.indexForId(dialerSurfaceId) === -1);
366462 }
367463
368464 function test_smashCursorKeys() {
369− var apps = ["unity8-dash", "dialer-app", "camera-app"];
465+ var apps = ["dialer-app", "gmail-webapp"];
370466 apps.forEach(startApplication);
371− verify(ApplicationManager.count == 3);
467+ verify(topSurfaceList.count == 3);
372468 keyClick(Qt.Key_D, Qt.MetaModifier|Qt.ControlModifier); // Ctrl+Super+D shortcut to minimize all
373− tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify no app is focused
469+ tryCompare(MirFocusController, "focusedSurface", null); // verify no surface is focused
374470
375471 // now try pressing all 4 arrow keys + ctrl + meta
376472 keyClick(Qt.Key_Up | Qt.Key_Down | Qt.Key_Left | Qt.Key_Right, Qt.MetaModifier|Qt.ControlModifier); // smash it!!!
377− tryCompare(ApplicationManager, "focusedApplicationId", ""); // verify still no app is focused
473+ tryCompare(MirFocusController, "focusedSurface", null); // verify still no surface is focused
378474 }
379475
380476 function test_minimizeApplicationHidesSurface() {
381− var dashApp = startApplication("unity8-dash");
477+ compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
478+ var dashSurface = topSurfaceList.surfaceAt(0);
479+ var dashSurfaceId = topSurfaceList.idAt(0);
382480
383− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
384− verify(dashDelegate);
481+ var decoratedWindow = findDecoratedWindow(dashSurfaceId);
482+ verify(decoratedWindow);
385483
386− findChild(dashDelegate, "decoratedWindow").minimize();
387− tryCompare(dashApp.session.lastSurface, "visible", false);
484+ tryCompare(dashSurface, "visible", true);
485+ decoratedWindow.minimize();
486+ tryCompare(dashSurface, "visible", false);
388487 }
389488
390489 function test_maximizeApplicationHidesSurfacesBehindIt() {
391− var dashApp = startApplication("unity8-dash");
392− var dialerApp = startApplication("dialer-app");
393− var gmailApp = startApplication("gmail-webapp");
490+ var dashDelegate = startApplication("unity8-dash");
491+ var dialerDelegate = startApplication("dialer-app");
492+ var gmailDelegate = startApplication("gmail-webapp");
394493
395− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
396− verify(dashDelegate);
397− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
398− verify(dialerDelegate);
399− var gmailDelegate = findChild(desktopStage, "appDelegate_gmail-webapp");
400− verify(gmailDelegate);
401−
402− // maximize
494+ // maximize without raising
403495 dialerDelegate.maximize();
404496 tryCompare(dialerDelegate, "visuallyMaximized", true);
405497
406− tryCompare(dashApp.session.lastSurface, "visible", false);
407− compare(gmailApp.session.lastSurface.visible, true);
498+ tryCompare(dashDelegate.surface, "visible", false);
499+ compare(gmailDelegate.surface.visible, true);
408500
409− // restore
501+ // restore without raising
410502 dialerDelegate.restoreFromMaximized();
411− compare(dashApp.session.lastSurface.visible, true);
412− compare(gmailApp.session.lastSurface.visible, true);
503+ compare(dashDelegate.surface.visible, true);
504+ compare(gmailDelegate.surface.visible, true);
413505 }
414506
415507 function test_applicationsBecomeVisibleWhenOccludingAppRemoved() {
416− var dashApp = startApplication("unity8-dash");
417− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
418− verify(dashDelegate);
508+ var dashApp = topSurfaceList.applicationAt(0);
419509
420− var dialerApp = startApplication("dialer-app");
421− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
510+ var dialerSurfaceId = topSurfaceList.nextId;
511+ var dialerDelegate = startApplication("dialer-app");
422512 verify(dialerDelegate);
513+ var dialerApp = dialerDelegate.application;
423514
424515 var dialerMaximizeButton = findChild(dialerDelegate, "maximizeWindowButton");
425516 verify(dialerMaximizeButton);
426517 mouseClick(dialerMaximizeButton);
427518
428− var mapApp = startApplication("map");
429− var mapDelegate = findChild(desktopStage, "appDelegate_map");
519+ var mapSurfaceId = topSurfaceList.nextId;
520+ var mapDelegate = startApplication("map");
430521 verify(mapDelegate);
522+ var mapApp = mapDelegate.application;
431523
432− var gmailApp = startApplication("gmail-webapp");
433− var gmailDelegate = findChild(desktopStage, "appDelegate_gmail-webapp");
524+ var gmailSurfaceId = topSurfaceList.nextId;
525+ var gmailDelegate = startApplication("gmail-webapp");
434526 verify(gmailDelegate);
435527
436528 var gmailMaximizeButton = findChild(gmailDelegate, "maximizeWindowButton");
@@ -440,29 +532,27 @@ Item {
440532 tryCompare(dialerDelegate, "visuallyMaximized", true);
441533 tryCompare(gmailDelegate, "visuallyMaximized", true);
442534
443− tryCompare(dashApp.session.lastSurface, "visible", false);
444− tryCompare(dialerApp.session.lastSurface, "visible", false);
445− tryCompare(mapApp.session.lastSurface, "visible", false);
535+ tryCompare(dashApp.surfaceList.get(0), "visible", false);
536+ tryCompare(dialerApp.surfaceList.get(0), "visible", false);
537+ tryCompare(mapApp.surfaceList.get(0), "visible", false);
446538
447539 ApplicationManager.stopApplication("gmail-webapp");
448540
449− compare(mapApp.session.lastSurface.visible, true);
450− tryCompare(dialerApp.session.lastSurface, "visible", true);
451− tryCompare(dashApp.session.lastSurface, "visible", false); // still occluded by maximised dialer
541+ tryCompare(mapApp.surfaceList.get(0), "visible", true);
542+ tryCompare(dialerApp.surfaceList.get(0), "visible", true);
543+ tryCompare(dashApp.surfaceList.get(0), "visible", false); // still occluded by maximised dialer
452544 }
453545
454546 function test_maximisedAppStaysVisibleWhenAppStarts() {
455− var dashApp = startApplication("unity8-dash");
456− var dashDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
457− verify(dashDelegate);
547+ var dashDelegate = startApplication("unity8-dash");
548+
458549 // maximize
459550 var dashMaximizeButton = findChild(dashDelegate, "maximizeWindowButton");
460551 verify(dashMaximizeButton);
461552 mouseClick(dashMaximizeButton);
462553 tryCompare(dashDelegate, "visuallyMaximized", true);
463554
464− var dialerApp = startApplication("dialer-app");
465− var dialerDelegate = findChild(desktopStage, "appDelegate_dialer-app");
555+ var dialerDelegate = startApplication("dialer-app");
466556 verify(dialerDelegate);
467557
468558 compare(dialerDelegate.visible, true, "Dialer should be visible");
@@ -470,14 +560,11 @@ Item {
470560 }
471561
472562 function test_occlusionWithMultipleMaximized() {
473− var dashApp = startApplication("unity8-dash");
474− var dashAppDelegate = findChild(desktopStage, "appDelegate_unity8-dash");
563+ var dashAppDelegate = startApplication("unity8-dash");
475564
476− var dialerApp = startApplication("dialer-app");
477− var dialerAppDelegate = findChild(desktopStage, "appDelegate_dialer-app");
565+ var dialerAppDelegate = startApplication("dialer-app");
478566
479− var facebookApp = startApplication("facebook-webapp");
480− var facebookAppDelegate = findChild(desktopStage, "appDelegate_facebook-webapp");
567+ var facebookAppDelegate = startApplication("facebook-webapp");
481568
482569 // all of them are in restored state now. all should be visible
483570 tryCompare(dashAppDelegate, "visible", true);
@@ -491,13 +578,13 @@ Item {
491578 tryCompare(facebookAppDelegate, "visible", true);
492579
493580 // Bring dash to front. make sure dash and the maximized facebook are visible, the restored one behind is hidden
494− ApplicationManager.focusApplication("unity8-dash");
581+ dashAppDelegate.focus = true;
495582 tryCompare(dashAppDelegate, "visible", true);
496583 tryCompare(dialerAppDelegate, "visible", false);
497584 tryCompare(facebookAppDelegate, "visible", true);
498585
499586 // Now focus the dialer app. all 3 should be visible again
500− ApplicationManager.focusApplication("dialer-app");
587+ dialerAppDelegate.focus = true;
501588 tryCompare(dashAppDelegate, "visible", true);
502589 tryCompare(dialerAppDelegate, "visible", true);
503590 tryCompare(facebookAppDelegate, "visible", true);
@@ -510,20 +597,15 @@ Item {
510597 }
511598
512599 function test_dropShadow() {
513− // verify the drop shadow is not visible initially
514− verify(PanelState.dropShadow == false);
515−
516600 // start an app, maximize it
517− var facebookApp = startApplication("facebook-webapp");
518− var facebookAppDelegate = findChild(desktopStage, "appDelegate_facebook-webapp");
601+ var facebookAppDelegate = startApplication("facebook-webapp");
519602 facebookAppDelegate.maximize();
520603
521604 // verify the drop shadow is still not visible
522605 verify(PanelState.dropShadow == false);
523606
524607 // start a foreground app, not maximized
525− var dialerApp = startApplication("dialer-app");
526− var dialerAppDelegate = findChild(desktopStage, "appDelegate_dialer-app");
608+ var dialerAppDelegate = startApplication("dialer-app");
527609
528610 // verify the drop shadow becomes visible
529611 verify(PanelState.dropShadow == true);
@@ -532,7 +614,7 @@ Item {
532614 ApplicationManager.stopApplication("facebook-webapp");
533615
534616 // verify the drop shadow is gone
535− verify(PanelState.dropShadow == false);
617+ tryCompare(PanelState, "dropShadow", false);
536618 }
537619 }
538620}