@@ -0,0 +1,287 @@
1+/*
2+ * Copyright (C) 2013,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 AccountsService 0.1
20+import LightDM 0.1 as LightDM
21+import Ubuntu.Components 1.1
22+import Unity.Application 0.1
23+import Unity.Test 0.1 as UT
24+
25+import "../../../qml"
26+
27+Item {
28+ id: root
29+ width: shellLoader.width + buttons.width
30+ height: shellLoader.height
31+
32+ QtObject {
33+ id: applicationArguments
34+
35+ function hasGeometry() {
36+ return false;
37+ }
38+
39+ function width() {
40+ return 0;
41+ }
42+
43+ function height() {
44+ return 0;
45+ }
46+ }
47+
48+ Row {
49+ spacing: 0
50+ anchors.fill: parent
51+
52+ Loader {
53+ id: shellLoader
54+
55+ width: units.gu(40)
56+ height: units.gu(71)
57+
58+ property bool itemDestroyed: false
59+ sourceComponent: Component {
60+ Shell {
61+ property string indicatorProfile: "phone"
62+
63+ Component.onDestruction: {
64+ shellLoader.itemDestroyed = true;
65+ }
66+ }
67+ }
68+ }
69+
70+ Rectangle {
71+ id: buttons
72+ color: "white"
73+ width: units.gu(30)
74+ height: shellLoader.height
75+
76+ Column {
77+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
78+ spacing: units.gu(1)
79+ Row {
80+ anchors { left: parent.left; right: parent.right }
81+ Button {
82+ text: "Restart Tutorial"
83+ onClicked: {
84+ if (shellLoader.status !== Loader.Ready)
85+ return;
86+
87+ AccountsService.demoEdges = false;
88+ AccountsService.demoEdges = true;
89+ }
90+ }
91+ }
92+ }
93+ }
94+ }
95+
96+ UT.UnityTestCase {
97+ id: testCase
98+ name: "Tutorial"
99+ when: windowShown
100+
101+ property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
102+ property real halfWidth: shell ? shell.width / 2 : 0
103+ property real halfHeight: shell ? shell.height / 2 : 0
104+
105+ function init() {
106+ swipeAwayGreeter();
107+ AccountsService.demoEdges = false;
108+ AccountsService.demoEdges = true;
109+
110+ var tutorial = findChild(shell, "tutorial");
111+ tutorial.readingDelay = 1;
112+ }
113+
114+ function cleanup() {
115+ shellLoader.itemDestroyed = false;
116+
117+ shellLoader.active = false;
118+
119+ tryCompare(shellLoader, "status", Loader.Null);
120+ tryCompare(shellLoader, "item", null);
121+ // Loader.status might be Loader.Null and Loader.item might be null but the Loader
122+ // item might still be alive. So if we set Loader.active back to true
123+ // again right now we will get the very same Shell instance back. So no reload
124+ // actually took place. Likely because Loader waits until the next event loop
125+ // iteration to do its work. So to ensure the reload, we will wait until the
126+ // Shell instance gets destroyed.
127+ tryCompare(shellLoader, "itemDestroyed", true);
128+
129+ // kill all (fake) running apps
130+ killApps();
131+
132+ // reload our test subject to get it in a fresh state once again
133+ shellLoader.active = true;
134+
135+ tryCompare(shellLoader, "status", Loader.Ready);
136+ removeTimeConstraintsFromDirectionalDragAreas(shellLoader.item);
137+ }
138+
139+ function killApps() {
140+ while (ApplicationManager.count > 1) {
141+ var appIndex = ApplicationManager.get(0).appId == "unity8-dash" ? 1 : 0
142+ ApplicationManager.stopApplication(ApplicationManager.get(appIndex).appId);
143+ }
144+ compare(ApplicationManager.count, 1)
145+ }
146+
147+ function swipeAwayGreeter() {
148+ var greeter = findChild(shell, "greeter");
149+ tryCompare(greeter, "showProgress", 1);
150+
151+ touchFlick(shell, halfWidth, halfHeight, shell.width, halfHeight);
152+
153+ // wait until the animation has finished
154+ tryCompare(greeter, "showProgress", 0);
155+ waitForRendering(greeter);
156+ }
157+
158+ function waitForPage(name) {
159+ tryCompareFunction(function() { return findChild(shell, name) !== null; }, true);
160+ return findChild(shell, name);
161+ }
162+
163+ function checkTopEdge() {
164+ touchFlick(shell, halfWidth, 0, halfWidth, halfHeight);
165+
166+ var panel = findChild(shell, "panel");
167+ tryCompare(panel.indicators, "fullyClosed", true);
168+ }
169+
170+ function checkLeftEdge() {
171+ touchFlick(shell, 0, halfHeight, halfWidth, halfHeight);
172+
173+ var launcher = findChild(shell, "launcher");
174+ tryCompare(launcher, "state", "");
175+ }
176+
177+ function checkRightEdge() {
178+ touchFlick(shell, shell.width, halfHeight, halfWidth, halfHeight);
179+
180+ var stage = findChild(shell, "stage");
181+ var spreadView = findChild(stage, "spreadView");
182+ tryCompare(spreadView, "phase", 0);
183+ }
184+
185+ function checkBottomEdge() {
186+ // Can't actually check effect of swipe, since dash isn't really loaded
187+ var applicationsDisplayLoader = findChild(shell, "applicationsDisplayLoader");
188+ tryCompare(applicationsDisplayLoader.item, "interactive", false);
189+ }
190+
191+ function checkFinished() {
192+ tryCompare(AccountsService, "demoEdges", false);
193+
194+ var tutorial = findChild(shell, "tutorial");
195+ tryCompare(tutorial, "running", false);
196+
197+ var launcher = findChild(shell, "launcher");
198+ tryCompare(launcher, "shown", false);
199+ }
200+
201+ function goToPage(name) {
202+ var page = waitForPage("tutorialIntro");
203+ if (name === "tutorialIntro") return page;
204+ // Intro page will pass by itself
205+
206+ page = waitForPage("tutorialTop");
207+ checkLeftEdge();
208+ checkRightEdge();
209+ checkBottomEdge();
210+ if (name === "tutorialTop") return page;
211+ touchFlick(shell, halfWidth, 0, halfWidth, shell.height);
212+
213+ page = waitForPage("tutorialTopFinish");
214+ checkLeftEdge();
215+ checkRightEdge();
216+ checkBottomEdge();
217+ if (name === "tutorialTopFinish") return page;
218+ touchFlick(shell, halfWidth, shell.height, halfWidth, 0);
219+
220+ page = waitForPage("tutorialLeft");
221+ checkTopEdge();
222+ checkRightEdge();
223+ checkBottomEdge();
224+ if (name === "tutorialLeft") return page;
225+ touchFlick(shell, 0, halfHeight, halfWidth, halfHeight, true, false);
226+
227+ page = waitForPage("tutorialLeftFinish");
228+ if (name === "tutorialLeftFinish") return page;
229+ touchFlick(shell, halfWidth, halfHeight, halfWidth, halfHeight, false, true);
230+
231+ checkFinished();
232+ return null;
233+ }
234+
235+ function test_skippable() {
236+ var top = goToPage("tutorialTop");
237+
238+ var skipLabel = findChild(top, "skipLabel");
239+ tap(skipLabel);
240+
241+ checkFinished();
242+ }
243+
244+ function test_walkthrough() {
245+ goToPage(null);
246+ }
247+
248+ function test_launcherShortDrags() {
249+ // goToPage does a full launcher pull. But here we want to test
250+ // just barely pulling the launcher out and letting go (i.e. not
251+ // triggering the "progress" property of Launcher).
252+
253+ var left = goToPage("tutorialLeft");
254+
255+ // Make sure we don't do anything if we don't pull the launcher
256+ // out much.
257+ var launcher = findChild(shell, "launcher");
258+ touchFlick(shell, 0, halfHeight, launcher.panelWidth * 0.6, halfHeight);
259+ tryCompare(launcher, "state", ""); // should remain hidden
260+ tryCompare(left, "shown", true); // and we should still be on left
261+
262+ // Now drag out but not past launcher itself
263+ touchFlick(shell, 0, halfHeight, launcher.panelWidth * 0.9, halfHeight);
264+
265+ // That actually finishes the launcher tutorial (drag is already
266+ // over, it would be silly to show LeftFinish page that asks for a
267+ // drag release)
268+ checkFinished();
269+ }
270+
271+ function test_launcherDragBack() {
272+ // goToPage does a full launcher pull. But here we test pulling
273+ // all the way out, then dragging back into place.
274+
275+ goToPage("tutorialLeftFinish");
276+ touchFlick(shell, halfWidth, halfHeight, 0, halfHeight, false, true);
277+
278+ checkFinished();
279+ }
280+
281+ function test_interrupted() {
282+ goToPage("tutorialTop");
283+ ApplicationManager.startApplication("dialer-app");
284+ checkFinished();
285+ }
286+ }
287+}