@@ -42,7 +42,7 @@ Item {
4242 anchors { fill: parent; rightMargin: units.gu(30) }
4343 focus: true
4444 dragAreaWidth: units.gu(2)
45− interactive: true
45+ allowInteractivity: true
4646 shellOrientation: Qt.PortraitOrientation
4747 orientations: Orientations {}
4848 applicationManager: ApplicationManager
@@ -210,7 +210,7 @@ Item {
210210 return [
211211 {tag: "<breakPoint (trigger)", progress: .2, cancel: false, endState: "staged", newFocusedIndex: 1 },
212212 {tag: "<breakPoint (cancel)", progress: .2, cancel: true, endState: "staged", newFocusedIndex: 0 },
213− {tag: ">breakPoint (trigger)", progress: .5, cancel: false, endState: "spread", newFocusedIndex: 0 },
213+ {tag: ">breakPoint (trigger)", progress: .5, cancel: false, endState: "spread", newFocusedIndex: null },
214214 {tag: ">breakPoint (cancel)", progress: .8, cancel: true, endState: "staged", newFocusedIndex: 0 },
215215 ];
216216 }
@@ -225,7 +225,6 @@ Item {
225225 var endY = startY;
226226 var endX = stage.width - (stage.width * data.progress) - stage.dragAreaWidth;
227227
228− var oldFocusedApp = ApplicationManager.get(0);
229228 var newFocusedApp = ApplicationManager.get(data.newFocusedIndex);
230229
231230 touchFlick(stage, startX, startY, endX, endY,
@@ -238,7 +237,7 @@ Item {
238237 touchRelease(stage, endX, endY); }
239238
240239 tryCompare(stage, "state", data.endState);
241− tryCompare(ApplicationManager, "focusedApplicationId", data.endState == "spread" ? oldFocusedApp.appId : newFocusedApp.appId);
240+ tryCompare(ApplicationManager, "focusedApplicationId", data.endState == "spread" ? "" : newFocusedApp.appId);
242241 }
243242
244243 function test_selectAppFromSpread_data() {
@@ -583,5 +582,32 @@ Item {
583582 compare(topLevelSurfaceList.idAt(0), webbrowserSurfaceId);
584583 compare(webbrowserApp.focused, true);
585584 }
585+
586+ /*
587+ Ensure that closing a surface while rootFocus is off focuses the
588+ next available surface when rootFocus is given back.
589+
590+ Regression test for https://github.com/ubports/unity8/issues/234
591+
592+ This cannot be tested in tst_TopLevelWindowModel.cpp, the mocks for
593+ it are not advanced enough.
594+ */
595+ function test_closeFocusedAppWithSpreadOpen()
596+ {
597+ var dashApp = ApplicationManager.findApplication("unity8-dash");
598+ var webbrowserSurfaceId = topLevelSurfaceList.nextId;
599+ var webbrowserApp = ApplicationManager.startApplication("morph-browser");
600+ waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
601+
602+ topLevelSurfaceList.rootFocus = false;
603+
604+ performEdgeSwipeToShowAppSpread();
605+
606+ swipeSurfaceUpwards(webbrowserSurfaceId);
607+ tryCompareFunction(function() { return topLevelSurfaceList.indexForId(webbrowserSurfaceId); }, -1);
608+
609+ topLevelSurfaceList.rootFocus = true;
610+ compare(dashApp.focused, true);
611+ }
586612 }
587613}