@@ -1,5 +1,5 @@
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2013,2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@ import Ubuntu.Components 1.1
20import Ubuntu.Components.ListItems 1.0 as ListItem
20import Ubuntu.Components.ListItems 1.0 as ListItem
21import Unity.Application 0.1
21import Unity.Application 0.1
22import Unity.Test 0.1
22import Unity.Test 0.1
24import "../../../qml/Stages"
25import "../../../qml/Stages"
@@ -29,31 +30,18 @@ Rectangle {
29 width: desktopStageLoader.width + controls.width
30 width: desktopStageLoader.width + controls.width
30 height: desktopStageLoader.height
31 height: desktopStageLoader.height
32− QtObject {
33+ Binding {
33− id: fakeWindowStateStorage
34+ target: MouseTouchAdaptor
35− property var storedGeom: [
35+ property: "enabled"
36− ["unity8-dash", Qt.rect(units.gu(2), units.gu(2), units.gu(50), units.gu(50))],
36+ value: false
37− ["webbrowser-app", Qt.rect(units.gu(60), units.gu(2), units.gu(50), units.gu(50))]
37+ }
40− function saveGeometry(windowId, geometry) {
39+ Component.onCompleted: {
41− for (var i = 0; i < storedGeom.length; ++i) {
40+ // ensures apps which are tested decorations are in view.
42− if (storedGeom[i][0] === windowId) {
41+ WindowStateStorage.geometry = {
43− storedGeom[i][1] = geometry;
42+ 'unity8-dash': Qt.rect(0, units.gu(3), units.gu(50), units.gu(40)),
44− return;
43+ 'dialer-app': Qt.rect(units.gu(51), units.gu(3), units.gu(50), units.gu(40)),
45− }
44+ 'camera-app': Qt.rect(0, units.gu(44), units.gu(50), units.gu(40)),
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;
@@ -70,7 +58,6 @@ Rectangle {
70 sourceComponent: Component {
58 sourceComponent: Component {
71 DesktopStage {
59 DesktopStage {
72 anchors.fill: parent
60 anchors.fill: parent
73− windowStateStorage: fakeWindowStateStorage
74 Component.onDestruction: {
61 Component.onDestruction: {
75 desktopStageLoader.itemDestroyed = true;
62 desktopStageLoader.itemDestroyed = true;
@@ -145,57 +132,59 @@ Rectangle {
145 tryCompare(appWindowStates, "state", "surface");
132 tryCompare(appWindowStates, "state", "surface");
148− function rectsIntersect(aLocal, bLocal) {
135+ function startApplication(appId) {
149−
136+ var app = ApplicationManager.findApplication(appId);
150− var a = aLocal.mapToItem(null, 0, 0, aLocal.width, aLocal.height);
137+ if (!app) {
151− var b = bLocal.mapToItem(null, 0, 0, bLocal.width, bLocal.height);
138+ app = ApplicationManager.startApplication(appId);
141+ waitUntilAppSurfaceShowsUp(appId);
142+ verify(app.session.surface);
153− return !((a.y+a.height) < b.y
143+ return app;
154− || a.y > (b.y+b.height)
155− || (a.x+a.width) < b.x
156− || a.x > (b.x+b.width));
159− function test_tappingOnWindowChangesFocusedApp() {
146+ function test_appFocusSwitch_data() {
160− ApplicationManager.startApplication("webbrowser-app");
147+ return [
161− waitUntilAppSurfaceShowsUp("webbrowser-app");
148+ {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
162−
149+ {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
163− var webbrowserWindow = findChild(desktopStage, "appWindow_webbrowser-app");
150+ ]
164− verify(webbrowserWindow);
151+ }
165− var dashWindow = findChild(desktopStage, "appWindow_unity8-dash");
168− // some sanity check
153+ function test_appFocusSwitch(data) {
169− compare(rectsIntersect(dashWindow, webbrowserWindow), false);
154+ var i;
155+ for (i = 0; i < data.apps.length; i++) {
156+ startApplication(data.apps[i]);
171− tap(dashWindow);
159+ ApplicationManager.requestFocusApplication(data.apps[data.focusfrom]);
172− compare(dashWindow.application.session.surface.activeFocus, true);
160+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.surface, "activeFocus", true);
174− tap(webbrowserWindow);
162+ ApplicationManager.requestFocusApplication(data.apps[data.focusTo]);
175− compare(webbrowserWindow.application.session.surface.activeFocus, true);
163+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.surface, "activeFocus", true);
178− function test_tappingOnWindowTitleChangesFocusedApp() {
166+ function test_decorationPressFocusesApplication_data() {
179− ApplicationManager.startApplication("webbrowser-app");
167+ return [
180− waitUntilAppSurfaceShowsUp("webbrowser-app");
168+ {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 0, focusTo: 1 },
181−
169+ {tag: "dash", apps: [ "unity8-dash", "dialer-app", "camera-app" ], focusfrom: 1, focusTo: 0 },
182− var webbrowserWindow = findChild(desktopStage, "decoratedWindow_webbrowser-app");
170+ ]
183− verify(webbrowserWindow);
171+ }
184− var webbrowserWindowTitle = findChild(webbrowserWindow, "windowDecorationTitle");
185− verify(webbrowserWindowTitle);
186− var dashWindow = findChild(desktopStage, "decoratedWindow_unity8-dash");
188− var dashWindowTitle = findChild(dashWindow, "windowDecorationTitle");
189− verify(dashWindowTitle);
191− // some sanity check
173+ function test_decorationPressFocusesApplication(data) {
192− compare(rectsIntersect(dashWindow, webbrowserWindow), false);
174+ var i;
175+ for (i = 0; i < data.apps.length; i++) {
176+ startApplication(data.apps[i]);
194− tap(dashWindowTitle);
179+ var fromAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusfrom]);
195− compare(dashWindow.application.session.surface.activeFocus, true);
180+ verify(fromAppDecoration);
181+ mouseClick(fromAppDecoration);
182+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusfrom]).session.surface, "activeFocus", true);
197− tap(webbrowserWindowTitle);
184+ var toAppDecoration = findChild(desktopStage, "appWindowDecoration_" + data.apps[data.focusTo]);
198− compare(webbrowserWindow.application.session.surface.activeFocus, true);
185+ verify(toAppDecoration);
186+ mouseClick(toAppDecoration);
187+ tryCompare(ApplicationManager.findApplication(data.apps[data.focusTo]).session.surface, "activeFocus", true);