@@ -0,0 +1,226 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import Unity.Test 0.1 as UT
20+import ".."
21+import "../../../qml/Stages"
22+import Ubuntu.Components 0.1
23+import Unity.Application 0.1
24+
25+Item {
26+ width: units.gu(70)
27+ height: units.gu(70)
28+
29+ Rectangle {
30+
31+ }
32+
33+ PhoneStage {
34+ id: phoneStage
35+ anchors { fill: parent; rightMargin: units.gu(30) }
36+ shown: true
37+ dragAreaWidth: units.gu(2)
38+ }
39+
40+ Binding {
41+ target: ApplicationManager
42+ property: "rightMargin"
43+ value: phoneStage.anchors.rightMargin
44+ }
45+
46+ Rectangle {
47+ anchors { fill: parent; leftMargin: phoneStage.width }
48+// color: "blue"
49+
50+ Column {
51+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
52+ spacing: units.gu(1)
53+ Button {
54+ anchors { left: parent.left; right: parent.right }
55+ text: "Add App"
56+ onClicked: {
57+ testCase.addApps();
58+ }
59+ }
60+ Button {
61+ anchors { left: parent.left; right: parent.right }
62+ text: "Add App"
63+ }
64+ }
65+ }
66+
67+ UT.UnityTestCase {
68+ id: testCase
69+ name: "PhoneStage"
70+ when: windowShown
71+
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.
81+// wait(1000)
82+ waitForRendering(phoneStage)
83+ }
84+ }
85+
86+ function test_shortFlick() {
87+ addApps(2)
88+ var startX = phoneStage.width - units.gu(1);
89+ var startY = phoneStage.height / 2;
90+ var endX = phoneStage.width / 2;
91+ var endY = startY;
92+
93+ var activeApp = ApplicationManager.get(0);
94+ var inactiveApp = ApplicationManager.get(1);
95+
96+ touchFlick(phoneStage, startX, startY, endX, endY,
97+ true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
98+
99+ tryCompare(ApplicationManager, "focusedApplicationId", inactiveApp.appId)
100+
101+ touchFlick(phoneStage, startX, startY, endX, endY,
102+ true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
103+
104+ tryCompare(ApplicationManager, "focusedApplicationId", activeApp.appId)
105+
106+ tryCompare(phoneStage, "painting", false);
107+ }
108+
109+ function test_enterSpread_data() {
110+ return [
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 },
119+ ];
120+ }
121+
122+ function test_enterSpread(data) {
123+ addApps(5)
124+
125+ var spreadView = findChild(phoneStage, "spreadView");
126+
127+ var startX = phoneStage.width;
128+ var startY = phoneStage.height / 2;
129+ var endY = startY;
130+ var endX = spreadView.width - (spreadView.width * spreadView[data.positionMarker]) - data.offset - phoneStage.dragAreaWidth;
131+
132+ var oldFocusedApp = ApplicationManager.get(0);
133+ var newFocusedApp = ApplicationManager.get(data.newFocusedIndex);
134+
135+ touchFlick(phoneStage, startX, startY, endX, endY,
136+ true /* beginTouch */, false /* endTouch */, units.gu(10), 50);
137+
138+ tryCompare(spreadView, "stage", data.endStage)
139+
140+ if (!data.linear) {
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);
145+ }
146+
147+ touchRelease(phoneStage, endX, endY);
148+
149+ tryCompare(spreadView, "stage", data.targetStage)
150+
151+ if (data.targetStage == 2) {
152+ var app2 = findChild(spreadView, "appDelegate2");
153+ mouseClick(app2, units.gu(1), units.gu(1));
154+ }
155+
156+ tryCompare(phoneStage, "painting", false);
157+ tryCompare(ApplicationManager, "focusedApplicationId", newFocusedApp.appId);
158+
159+ }
160+
161+ function test_selectAppFromSpread_data() {
162+ var appsToTest = 6;
163+ var apps = new Array();
164+ for (var i = 0; i < appsToTest; i++) {
165+ var item = new Object();
166+ item.tag = "App " + i;
167+ item.index = i;
168+ item.total = appsToTest;
169+ apps.push(item)
170+ }
171+ return apps;
172+ }
173+
174+ function test_selectAppFromSpread(data) {
175+ addApps(data.total)
176+
177+ var spreadView = findChild(phoneStage, "spreadView");
178+
179+// waitForRendering(phoneStage)
180+
181+ var startX = phoneStage.width;
182+ var startY = phoneStage.height / 2;
183+ var endY = startY;
184+ var endX = spreadView.width - (spreadView.width * spreadView.positionMarker3) - 1 - phoneStage.dragAreaWidth;
185+
186+ touchFlick(phoneStage, startX, startY, endX, endY,
187+ true /* beginTouch */, true /* endTouch */, units.gu(10), 50);
188+
189+ tryCompare(spreadView, "stage", 2);
190+
191+ var tile = findChild(spreadView, "appDelegate" + data.index);
192+ var appId = ApplicationManager.get(data.index).appId;
193+
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);
200+ }
201+
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);
206+ }
207+
208+ function test_animateAppStartup() {
209+ compare(phoneStage.painting, false);
210+ addApps(2);
211+ tryCompare(phoneStage, "painting", true);
212+ tryCompare(phoneStage, "painting", false);
213+ addApps(1);
214+ tryCompare(phoneStage, "painting", true);
215+ tryCompare(phoneStage, "painting", false);
216+ }
217+
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)
223+ }
224+ }
225+ }
226+}