@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2013,2014 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.1
2020import Ubuntu.Components.ListItems 1.0 as ListItem
2121import Unity.Application 0.1
2222import Unity.Test 0.1
23+import Utils 0.1
2324
2425import "../../../qml/Stages"
2526
@@ -29,31 +30,18 @@ Rectangle {
2930 width: desktopStageLoader.width + controls.width
3031 height: desktopStageLoader.height
3132
32− QtObject {
33− id: fakeWindowStateStorage
34−
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))]
38− ]
33+ Binding {
34+ target: MouseTouchAdaptor
35+ property: "enabled"
36+ value: false
37+ }
3938
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;
44− return;
45− }
46− }
47− // if new
48− storedGeom[storedGeom.length] = [windowId, geometry];
49− }
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];
54− }
55− }
56− return defaultGeometry;
39+ Component.onCompleted: {
40+ // ensures apps which are tested decorations are in view.
41+ WindowStateStorage.geometry = {
42+ 'unity8-dash': Qt.rect(0, units.gu(3), units.gu(50), units.gu(40)),
43+ 'dialer-app': Qt.rect(units.gu(51), units.gu(3), units.gu(50), units.gu(40)),
44+ 'camera-app': Qt.rect(0, units.gu(44), units.gu(50), units.gu(40)),
5745 }
5846 }
5947
@@ -70,7 +58,6 @@ Rectangle {
7058 sourceComponent: Component {
7159 DesktopStage {
7260 anchors.fill: parent
73− windowStateStorage: fakeWindowStateStorage
7461 Component.onDestruction: {
7562 desktopStageLoader.itemDestroyed = true;
7663 }
@@ -145,57 +132,59 @@ Rectangle {
145132 tryCompare(appWindowStates, "state", "surface");
146133 }
147134
148− function rectsIntersect(aLocal, bLocal) {
149−
150− var a = aLocal.mapToItem(null, 0, 0, aLocal.width, aLocal.height);
151− var b = bLocal.mapToItem(null, 0, 0, bLocal.width, bLocal.height);
152−
153− return !((a.y+a.height) < b.y
154− || a.y > (b.y+b.height)
155− || (a.x+a.width) < b.x
156− || a.x > (b.x+b.width));
135+ function startApplication(appId) {
136+ var app = ApplicationManager.findApplication(appId);
137+ if (!app) {
138+ app = ApplicationManager.startApplication(appId);
139+ }
140+ verify(app);
141+ waitUntilAppSurfaceShowsUp(appId);
142+ verify(app.session.surface);
143+ return app;
157144 }
158145
159− function test_tappingOnWindowChangesFocusedApp() {
160− ApplicationManager.startApplication("webbrowser-app");
161− waitUntilAppSurfaceShowsUp("webbrowser-app");
162−
163− var webbrowserWindow = findChild(desktopStage, "appWindow_webbrowser-app");
164− verify(webbrowserWindow);
165− var dashWindow = findChild(desktopStage, "appWindow_unity8-dash");
166− verify(dashWindow);
146+ function test_appFocusSwitch_data() {
147+ return [
148+ {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
149+ {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
150+ ]
151+ }
167152
168− // some sanity check
169− compare(rectsIntersect(dashWindow, webbrowserWindow), false);
153+ function test_appFocusSwitch(data) {
154+ var i;
155+ for (i = 0; i < data.apps.length; i++) {
156+ startApplication(data.apps[i]);
157+ }
170158
171− tap(dashWindow);
172− compare(dashWindow.application.session.surface.activeFocus, true);
159+ ApplicationManager.requestFocusApplication(data.apps[data.focusfrom]);
160+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.surface, "activeFocus", true);
173161
174− tap(webbrowserWindow);
175− compare(webbrowserWindow.application.session.surface.activeFocus, true);
162+ ApplicationManager.requestFocusApplication(data.apps[data.focusTo]);
163+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.surface, "activeFocus", true);
176164 }
177165
178− function test_tappingOnWindowTitleChangesFocusedApp() {
179− ApplicationManager.startApplication("webbrowser-app");
180− waitUntilAppSurfaceShowsUp("webbrowser-app");
181−
182− var webbrowserWindow = findChild(desktopStage, "decoratedWindow_webbrowser-app");
183− verify(webbrowserWindow);
184− var webbrowserWindowTitle = findChild(webbrowserWindow, "windowDecorationTitle");
185− verify(webbrowserWindowTitle);
186− var dashWindow = findChild(desktopStage, "decoratedWindow_unity8-dash");
187− verify(dashWindow);
188− var dashWindowTitle = findChild(dashWindow, "windowDecorationTitle");
189− verify(dashWindowTitle);
166+ function test_decorationPressFocusesApplication_data() {
167+ return [
168+ {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
169+ {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
170+ ]
171+ }
190172
191− // some sanity check
192− compare(rectsIntersect(dashWindow, webbrowserWindow), false);
173+ function test_decorationPressFocusesApplication(data) {
174+ var i;
175+ for (i = 0; i < data.apps.length; i++) {
176+ startApplication(data.apps[i]);
177+ }
193178
194− tap(dashWindowTitle);
195− compare(dashWindow.application.session.surface.activeFocus, true);
179+ var fromAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusfrom]);
180+ verify(fromAppDecoration);
181+ mouseClick(fromAppDecoration);
182+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.surface, "activeFocus", true);
196183
197− tap(webbrowserWindowTitle);
198− compare(webbrowserWindow.application.session.surface.activeFocus, true);
184+ var toAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusTo]);
185+ verify(toAppDecoration);
186+ mouseClick(toAppDecoration);
187+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.surface, "activeFocus", true);
199188 }
200189 }
201190}