@@ -0,0 +1,226 @@
2+ * Copyright 2014 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 Unity.Test 0.1 as UT
21+import "../../../qml/Stages"
22+import Ubuntu.Components 0.1
23+import Unity.Application 0.1
35+ anchors { fill: parent; rightMargin: units.gu(30) }
37+ dragAreaWidth: units.gu(2)
41+ target: ApplicationManager
42+ property: "rightMargin"
43+ value: phoneStage.anchors.rightMargin
47+ anchors { fill: parent; leftMargin: phoneStage.width }
51+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
54+ anchors { left: parent.left; right: parent.right }
61+ anchors { left: parent.left; right: parent.right }
72+ function addApps(count) {
73+ if (count == undefined) count = 1;
74+ for (var i = 0; i < count; i++) {
75+ var app = ApplicationManager.startApplication(ApplicationManager.availableApplications()[ApplicationManager.count])
76+ tryCompare(app, "state", ApplicationInfoInterface.Running)
77+ // Fixme: Right now there is a timeout in the PhoneStage that displays a white splash
78+ // screen rectangle when an app starts. This is because we don't yet have a way of
79+ // knowing when an app has finished launching. That workaround and this wait() should
80+ // go away at some point and the app's state only changing to Running when ready for real.
82+ waitForRendering(phoneStage)
86+ function test_shortFlick() {
88+ var startX = phoneStage.width - units.gu(1);
89+ var startY = phoneStage.height / 2;
90+ var endX = phoneStage.width / 2;
93+ var activeApp = ApplicationManager.get(0);
94+ var inactiveApp = ApplicationManager.get(1);
96+ touchFlick(phoneStage, startX, startY, endX, endY,
97+ true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
99+ tryCompare(ApplicationManager, "focusedApplicationId", inactiveApp.appId)
101+ touchFlick(phoneStage, startX, startY, endX, endY,
102+ true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
104+ tryCompare(ApplicationManager, "focusedApplicationId", activeApp.appId)
106+ tryCompare(phoneStage, "painting", false);
109+ function test_enterSpread_data() {
111+ {tag: "<position1 (linear movement)", positionMarker: "positionMarker1", linear: true, offset: -1, endStage: 0, targetStage: 0, newFocusedIndex: 1 },
112+ {tag: "<position1 (non-linear movement)", positionMarker: "positionMarker1", linear: false, offset: -1, endStage: 0, targetStage: 0, newFocusedIndex: 0 },
113+ {tag: ">position1", positionMarker: "positionMarker1", linear: true, offset: +1, endStage: 0, targetStage: 0, newFocusedIndex: 1 },
114+ {tag: "<position2 (linear)", positionMarker: "positionMarker2", linear: true, offset: -1, endStage: 0, targetStage: 0, newFocusedIndex: 1 },
115+ {tag: "<position2 (non-linear)", positionMarker: "positionMarker2", linear: false, offset: -1, endStage: 0, targetStage: 0, newFocusedIndex: 1 },
116+ {tag: ">position2", positionMarker: "positionMarker2", linear: true, offset: +1, endStage: 1, targetStage: 0, newFocusedIndex: 1 },
117+ {tag: "<position3", positionMarker: "positionMarker3", linear: true, offset: -1, endStage: 1, targetStage: 0, newFocusedIndex: 1 },
118+ {tag: ">position3", positionMarker: "positionMarker3", linear: true, offset: +1, endStage: 2, targetStage: 2, newFocusedIndex: 2 },
122+ function test_enterSpread(data) {
125+ var spreadView = findChild(phoneStage, "spreadView");
127+ var startX = phoneStage.width;
128+ var startY = phoneStage.height / 2;
130+ var endX = spreadView.width - (spreadView.width * spreadView[data.positionMarker]) - data.offset - phoneStage.dragAreaWidth;
132+ var oldFocusedApp = ApplicationManager.get(0);
133+ var newFocusedApp = ApplicationManager.get(data.newFocusedIndex);
135+ touchFlick(phoneStage, startX, startY, endX, endY,
136+ true /* beginTouch */, false /* endTouch */, units.gu(10), 50);
138+ tryCompare(spreadView, "stage", data.endStage)
141+ touchFlick(phoneStage, endX, endY, endX + units.gu(.5), endY,
142+ false /* beginTouch */, false /* endTouch */, units.gu(10), 50);
143+ touchFlick(phoneStage, endY + units.gu(.5), endY, endX, endY,
144+ false /* beginTouch */, false /* endTouch */, units.gu(10), 50);
147+ touchRelease(phoneStage, endX, endY);
149+ tryCompare(spreadView, "stage", data.targetStage)
151+ if (data.targetStage == 2) {
152+ var app2 = findChild(spreadView, "appDelegate2");
153+ mouseClick(app2, units.gu(1), units.gu(1));
156+ tryCompare(phoneStage, "painting", false);
157+ tryCompare(ApplicationManager, "focusedApplicationId", newFocusedApp.appId);
161+ function test_selectAppFromSpread_data() {
163+ var apps = new Array();
164+ for (var i = 0; i < appsToTest; i++) {
165+ var item = new Object();
166+ item.tag = "App " + i;
168+ item.total = appsToTest;
174+ function test_selectAppFromSpread(data) {
177+ var spreadView = findChild(phoneStage, "spreadView");
179+// waitForRendering(phoneStage)
181+ var startX = phoneStage.width;
182+ var startY = phoneStage.height / 2;
184+ var endX = spreadView.width - (spreadView.width * spreadView.positionMarker3) - 1 - phoneStage.dragAreaWidth;
186+ touchFlick(phoneStage, startX, startY, endX, endY,
187+ true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
189+ tryCompare(spreadView, "stage", 2);
191+ var tile = findChild(spreadView, "appDelegate" + data.index);
192+ var appId = ApplicationManager.get(data.index).appId;
194+ if (tile.mapToItem(spreadView).x > spreadView.width) {
195+ // Item is not visible... Need to flick the spread
196+ touchFlick(phoneStage, startX - units.gu(1), startY, endX, endY, true, true, units.gu(10), 50)
197+ tryCompare(spreadView, "flicking", false);
198+ tryCompare(spreadView, "moving", false);
199+// waitForRendering(phoneStage);
202+ console.log("clicking app", data.index, "(", appId, ")")
203+ mouseClick(spreadView, tile.mapToItem(spreadView).x + units.gu(1), spreadView.height / 2)
204+ tryCompare(ApplicationManager, "focusedApplicationId", appId);
205+ tryCompare(spreadView, "stage", 0);
208+ function test_animateAppStartup() {
209+ compare(phoneStage.painting, false);
211+ tryCompare(phoneStage, "painting", true);
212+ tryCompare(phoneStage, "painting", false);
214+ tryCompare(phoneStage, "painting", true);
215+ tryCompare(phoneStage, "painting", false);
218+ function cleanup() {
219+ while (ApplicationManager.count > 0) {
220+ var oldCount = ApplicationManager.count;
221+ ApplicationManager.stopApplication(ApplicationManager.get(0).appId)
222+ tryCompare(ApplicationManager, "count", oldCount - 1)