@@ -0,0 +1,174 @@
2+ * Copyright (C) 2015 Canonical, Ltd.
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
6+ * the Free Software Foundation; version 3.
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+import Ubuntu.Components 1.1
20+import Ubuntu.Components.ListItems 1.0 as ListItem
21+import Unity.Application 0.1
24+import "../../../qml/Stages"
29+ width: desktopStageLoader.width + controls.width
30+ height: desktopStageLoader.height
33+ id: fakeWindowStateStorage
35+ property var storedGeom: [
36+ ["unity8-dash", Qt.rect(units.gu(2), units.gu(2), units.gu(50), units.gu(50))],
37+ ["webbrowser-app", Qt.rect(units.gu(60), units.gu(2), units.gu(50), units.gu(50))]
40+ function saveGeometry(windowId, geometry) {
41+ for (var i = 0; i < storedGeom.length; ++i) {
42+ if (storedGeom[i][0] === windowId) {
43+ storedGeom[i][1] = geometry;
48+ storedGeom[storedGeom.length] = [windowId, geometry];
50+ function getGeometry(windowId, defaultGeometry) {
51+ for (var i = 0; i < storedGeom.length; ++i) {
52+ if (storedGeom[i][0] === windowId) {
53+ return storedGeom[i][1];
56+ return defaultGeometry;
61+ id: desktopStageLoader
62+ x: ((root.width - controls.width) - width) / 2
63+ y: (root.height - height) / 2
64+ width: units.gu(160*0.9)
65+ height: units.gu(100*0.9)
69+ property bool itemDestroyed: false
70+ sourceComponent: Component {
73+ windowStateStorage: fakeWindowStateStorage
74+ Component.onDestruction: {
75+ desktopStageLoader.itemDestroyed = true;
88+ bottom: parent.bottom
93+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
95+ ApplicationCheckBox {
96+ id: webbrowserCheckBox
97+ appId: "webbrowser-app"
99+ ApplicationCheckBox {
108+ name: "DesktopStage"
111+ property Item desktopStage: desktopStageLoader.status === Loader.Ready ? desktopStageLoader.item : null
116+ function cleanup() {
117+ desktopStageLoader.itemDestroyed = false;
118+ desktopStageLoader.active = false;
120+ tryCompare(desktopStageLoader, "status", Loader.Null);
121+ tryCompare(desktopStageLoader, "item", null);
122+ // Loader.status might be Loader.Null and Loader.item might be null but the Loader
123+ // actually took place. Likely because Loader waits until the next event loop
124+ // iteration to do its work. So to ensure the reload, we will wait until the
125+ // Shell instance gets destroyed.
126+ tryCompare(desktopStageLoader, "itemDestroyed", true);
128+ // kill all (fake) running apps
129+ webbrowserCheckBox.checked = false;
130+ dialerCheckBox.checked = false;
132+ desktopStageLoader.active = true;
133+ tryCompare(desktopStageLoader, "status", Loader.Ready);
136+ function waitUntilAppSurfaceShowsUp(appId) {
137+ var appWindow = findChild(desktopStage, "appWindow_" + appId);
139+ var appWindowStates = findInvisibleChild(appWindow, "applicationWindowStateGroup");
140+ verify(appWindowStates);
141+ tryCompare(appWindowStates, "state", "surface");
144+ function rectsOverlap(aLocal, bLocal) {
146+ var a = aLocal.mapToItem(null, 0, 0, aLocal.width, aLocal.height);
147+ var b = bLocal.mapToItem(null, 0, 0, bLocal.width, bLocal.height);
149+ return !((a.y+a.height) < b.y
150+ || a.y > (b.y+b.height)
151+ || (a.x+a.width) < b.x
152+ || a.x > (b.x+b.width));
155+ function test_tappingOnWindowChangesFocusedApp() {
156+ webbrowserCheckBox.checked = true;
157+ waitUntilAppSurfaceShowsUp(webbrowserCheckBox.appId);
159+ var webbrowserWindow = findChild(desktopStage, "appWindow_" + webbrowserCheckBox.appId);
160+ verify(webbrowserWindow);
161+ var dashWindow = findChild(desktopStage, "appWindow_unity8-dash");
164+ // some sanity check
165+ compare(rectsOverlap(dashWindow, webbrowserWindow), false);
168+ compare(dashWindow.application.session.surface.activeFocus, true);
170+ tap(webbrowserWindow);
171+ compare(webbrowserWindow.application.session.surface.activeFocus, true);