@@ -0,0 +1,469 @@
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.3
18+import QtTest 1.0
19+import AccountsService 0.1
20+import MeeGo.QOfono 0.2
21+import Ubuntu.Components 1.1
22+import Ubuntu.SystemSettings.SecurityPrivacy 1.0
23+import Unity.Test 0.1 as UT
24+import Wizard 0.1
25+import "../../../qml/Wizard"
26+
27+Item {
28+ id: root
29+ width: units.gu(40)
30+ height: units.gu(71)
31+
32+ Loader {
33+ id: wizardLoader
34+ anchors.fill: parent
35+
36+ property bool itemDestroyed: false
37+ sourceComponent: Component {
38+ Wizard {
39+ id: wizard
40+ anchors.fill: parent
41+ background: Qt.resolvedUrl("../../../qml/graphics/phone_background.jpg")
42+
43+ Component.onDestruction: {
44+ wizardLoader.itemDestroyed = true;
45+ }
46+ }
47+ }
48+ }
49+
50+ SignalSpy {
51+ id: updateSessionLanguageSpy
52+ target: System
53+ signalName: "updateSessionLanguageCalled"
54+ }
55+
56+ SignalSpy {
57+ id: setSecuritySpy
58+ signalName: "setSecurityCalled"
59+ }
60+
61+ function setup() {
62+ AccountsService.hereEnabled = false;
63+ AccountsService.hereLicensePath = Qt.resolvedUrl("licenses");
64+ i18n.language = "en";
65+ MockQOfono.setModems(["sim1"], [false]);
66+ MockQOfono.available = true;
67+ System.wizardEnabled = true;
68+
69+ updateSessionLanguageSpy.clear();
70+ setSecuritySpy.clear();
71+ }
72+
73+ Component.onCompleted: {
74+ Theme.name = "Ubuntu.Components.Themes.SuruGradient";
75+ setup();
76+ }
77+
78+ UT.UnityTestCase {
79+ id: wizardTests
80+ name: "Wizard"
81+ when: windowShown
82+
83+ property Item wizard: wizardLoader.status === Loader.Ready ? wizardLoader.item : null
84+
85+ function cleanup() {
86+ wizardLoader.itemDestroyed = false;
87+
88+ wizardLoader.active = false;
89+
90+ tryCompare(wizardLoader, "status", Loader.Null);
91+ tryCompare(wizardLoader, "item", null);
92+ // Loader.status might be Loader.Null and Loader.item might be null but the Loader
93+ // item might still be alive. So if we set Loader.active back to true
94+ // again right now we will get the very same Shell instance back. So no reload
95+ // actually took place. Likely because Loader waits until the next event loop
96+ // iteration to do its work. So to ensure the reload, we will wait until the
97+ // Shell instance gets destroyed.
98+ tryCompare(wizardLoader, "itemDestroyed", true);
99+
100+ // reload our test subject to get it in a fresh state once again
101+ wizardLoader.active = true;
102+
103+ tryCompare(wizardLoader, "status", Loader.Ready);
104+
105+ var pages = findChild(wizard, "wizardPages");
106+ var security = findInvisibleChild(pages, "securityPrivacy");
107+ setSecuritySpy.target = security;
108+
109+ setup();
110+ }
111+
112+ function waitForPage(name) {
113+ var pages = findChild(wizard, "wizardPages");
114+ var stack = findChild(pages, "pageStack");
115+ // don't simply call tryCompare here, because stack.currentPage will be swapped out itself
116+ tryCompareFunction(function() { return stack.currentPage.objectName; }, name);
117+ tryCompare(stack.currentPage, "opacity", 1.0);
118+ tryCompare(stack.currentPage, "enabled", true);
119+ waitForRendering(stack.currentPage);
120+ return stack.currentPage;
121+ }
122+
123+ function goToPage(name, skipSim, skipLocation) {
124+ if (skipSim === undefined) {
125+ skipSim = false;
126+ }
127+ if (skipLocation === undefined) {
128+ skipLocation = false;
129+ }
130+
131+ var page = waitForPage("languagePage");
132+ if (name === page.objectName) return page;
133+ tap(findChild(page, "forwardButton"));
134+
135+ if (!skipSim) {
136+ page = waitForPage("simPage");
137+ if (name === page.objectName) return page;
138+ tap(findChild(page, "forwardButton"));
139+ }
140+
141+ page = waitForPage("passwdPage");
142+ if (name === page.objectName) return page;
143+ tap(findChild(page, "passwdDelegate0"));
144+ tap(findChild(page, "forwardButton"));
145+
146+ page = waitForPage("wifiPage");
147+ if (name === page.objectName) return page;
148+ tap(findChild(page, "forwardButton"));
149+
150+ if (!skipLocation) {
151+ page = waitForPage("locationPage");
152+ if (name === page.objectName) return page;
153+ tap(findChild(page, "forwardButton"));
154+ }
155+
156+ page = waitForPage("reportingPage");
157+ if (name === page.objectName) return page;
158+ tap(findChild(page, "forwardButton"));
159+
160+ page = waitForPage("finishedPage");
161+ if (name === page.objectName) return page;
162+ tap(findChild(page, "forwardButton"));
163+
164+ tryCompare(wizard, "shown", false);
165+ compare(name, null);
166+ return null;
167+ }
168+
169+ function test_languageChange() {
170+ var page = goToPage("languagePage");
171+ tap(findChild(page, "languageCombo"));
172+ waitForRendering(findChild(page, "languageDelegate1"));
173+ wait(100); // still needs more time to finish drawing(?) or else we sometimes fail
174+ tap(findChild(page, "languageDelegate1"));
175+ tryCompare(i18n, "language", "fr");
176+ tap(findChild(page, "forwardButton"));
177+ tryCompare(updateSessionLanguageSpy, "count", 1);
178+ compare(updateSessionLanguageSpy.signalArguments[0][0], "fr");
179+ }
180+
181+ function test_languageNoChange() {
182+ goToPage("simPage"); // one past language page
183+ compare(updateSessionLanguageSpy.count, 0);
184+ }
185+
186+ function test_simUnavailableSkip() {
187+ MockQOfono.available = false;
188+ goToPage("passwdPage", true);
189+ }
190+
191+ function test_simNoModemsSkip() {
192+ MockQOfono.setModems([], []);
193+ goToPage("passwdPage", true);
194+ }
195+
196+ function test_simFirstSkip() {
197+ MockQOfono.setModems(["a", "b"], [true, false]);
198+ goToPage("passwdPage", true);
199+ }
200+
201+ function test_simSecondSkip() {
202+ MockQOfono.setModems(["a", "b"], [false, true]);
203+ goToPage("passwdPage", true);
204+ }
205+
206+ function test_simBothSkip() {
207+ MockQOfono.setModems(["a", "b"], [true, true]);
208+ goToPage("passwdPage", true);
209+ }
210+
211+ function enterPasscode(passcode) {
212+ for (var i = 0; i < passcode.length; ++i) {
213+ var character = passcode.charAt(i);
214+ var button = findChild(wizard, "pinPadButton" + character);
215+ tap(button);
216+ }
217+ }
218+
219+ function test_passwdPasscode() {
220+ var page = goToPage("passwdPage");
221+
222+ tap(findChild(page, "forwardButton"));
223+ page = waitForPage("passwdSetPage");
224+
225+ enterPasscode("1111");
226+ page = waitForPage("passwdConfirmPage");
227+
228+ // make sure we go back to 'set' page not 'type' page
229+ tap(findChild(page, "backButton"));
230+ page = waitForPage("passwdSetPage");
231+
232+ enterPasscode("1111");
233+ page = waitForPage("passwdConfirmPage");
234+
235+ enterPasscode("1112");
236+ var error = findChild(page, "wrongNoticeLabel");
237+ tryCompareFunction(function() { return error.text !== ""; }, true);
238+
239+ enterPasscode("1111");
240+ page = waitForPage("wifiPage");
241+
242+ // now finish up
243+ tap(findChild(page, "forwardButton"));
244+ page = waitForPage("locationPage");
245+ tap(findChild(page, "forwardButton"));
246+ page = waitForPage("reportingPage");
247+ tap(findChild(page, "forwardButton"));
248+ page = waitForPage("finishedPage");
249+ tap(findChild(page, "forwardButton"));
250+
251+ tryCompare(setSecuritySpy, "count", 1);
252+ compare(setSecuritySpy.signalArguments[0][0], "");
253+ compare(setSecuritySpy.signalArguments[0][1], "1111");
254+ compare(setSecuritySpy.signalArguments[0][2], UbuntuSecurityPrivacyPanel.Passcode);
255+ }
256+
257+ function test_passwdPassphrase() {
258+ var page = goToPage("passwdPage");
259+ tap(findChild(page, "passwdDelegate2"));
260+
261+ tap(findChild(page, "forwardButton"));
262+ page = waitForPage("passwdSetPage");
263+
264+ typeString("aaa");
265+ var continueButton = findChild(page, "forwardButton");
266+ tryCompare(continueButton.item, "enabled", false);
267+ keyClick(Qt.Key_Enter);
268+ var error = findChild(page, "wrongNoticeLabel");
269+ tryCompareFunction(function() { return error.text !== ""; }, true);
270+
271+ typeString("aaaa");
272+ tap(continueButton);
273+ page = waitForPage("passwdConfirmPage");
274+
275+ // make sure we go back to 'set' page not 'type' page
276+ var back = findChild(page, "backButton");
277+ tap(back);
278+ page = waitForPage("passwdSetPage");
279+
280+ typeString("aaaa");
281+ keyClick(Qt.Key_Enter);
282+ page = waitForPage("passwdConfirmPage");
283+
284+ continueButton = findChild(page, "forwardButton");
285+ typeString("aaab");
286+ tryCompare(continueButton.item, "enabled", false);
287+ keyClick(Qt.Key_Enter);
288+ var error = findChild(page, "wrongNoticeLabel");
289+ tryCompareFunction(function() { return error.text !== ""; }, true);
290+
291+ typeString("aaaa");
292+ tap(continueButton);
293+ page = waitForPage("wifiPage");
294+
295+ // now finish up
296+ tap(findChild(page, "forwardButton"));
297+ page = waitForPage("locationPage");
298+ tap(findChild(page, "forwardButton"));
299+ page = waitForPage("reportingPage");
300+ tap(findChild(page, "forwardButton"));
301+ page = waitForPage("finishedPage");
302+ tap(findChild(page, "forwardButton"));
303+
304+ tryCompare(setSecuritySpy, "count", 1);
305+ compare(setSecuritySpy.signalArguments[0][0], "");
306+ compare(setSecuritySpy.signalArguments[0][1], "aaaa");
307+ compare(setSecuritySpy.signalArguments[0][2], UbuntuSecurityPrivacyPanel.Passphrase);
308+ }
309+
310+ function test_passwdSwipe() {
311+ goToPage(null);
312+
313+ tryCompare(setSecuritySpy, "count", 1);
314+ compare(setSecuritySpy.signalArguments[0][0], "");
315+ compare(setSecuritySpy.signalArguments[0][1], "");
316+ compare(setSecuritySpy.signalArguments[0][2], UbuntuSecurityPrivacyPanel.Swipe);
317+ }
318+
319+ function test_locationSkipNoPath() {
320+ AccountsService.hereLicensePath = "";
321+ goToPage("reportingPage", false, true);
322+ }
323+
324+ function test_locationSkipNoFiles() {
325+ AccountsService.hereLicensePath = Qt.resolvedUrl("nolicenses");
326+ goToPage("reportingPage", false, true);
327+ }
328+
329+ function test_locationWaitOnPath() {
330+ AccountsService.hereLicensePath = " "; // means we're still getting the path from dbus
331+
332+ var page = goToPage("wifiPage");
333+
334+ var pages = findChild(wizard, "wizardPages");
335+ var stack = findChild(pages, "pageStack");
336+ tap(findChild(page, "forwardButton"));
337+ // don't simply call tryCompare here, because stack.currentPage will be swapped out itself
338+ tryCompareFunction(function() { return stack.currentPage.objectName; }, "locationPage");
339+ compare(stack.currentPage.enabled, false);
340+ compare(stack.currentPage.skipValid, false);
341+
342+ AccountsService.hereLicensePath = "";
343+ waitForPage("reportingPage");
344+ }
345+
346+ function test_locationGpsOnly() {
347+ var page = goToPage("locationPage");
348+ var gpsCheck = findChild(page, "gpsCheck");
349+ var hereCheck = findChild(page, "hereCheck");
350+ var nopeCheck = findChild(page, "nopeCheck");
351+
352+ var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
353+ tryCompare(locationActionGroup.location, "state", false);
354+ tryCompare(locationActionGroup.gps, "state", false);
355+
356+ tap(gpsCheck);
357+ tryCompare(gpsCheck, "checked", true);
358+ tryCompare(hereCheck, "checked", false);
359+ tryCompare(nopeCheck, "checked", false);
360+
361+ tap(findChild(page, "forwardButton"));
362+ tryCompare(AccountsService, "hereEnabled", false);
363+ tryCompare(locationActionGroup.location, "state", true);
364+ tryCompare(locationActionGroup.gps, "state", true);
365+ }
366+
367+ function test_locationNope() {
368+ var page = goToPage("locationPage");
369+ var gpsCheck = findChild(page, "gpsCheck");
370+ var hereCheck = findChild(page, "hereCheck");
371+ var nopeCheck = findChild(page, "nopeCheck");
372+
373+ var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
374+ tryCompare(locationActionGroup.location, "state", false);
375+ tryCompare(locationActionGroup.gps, "state", false);
376+
377+ tap(nopeCheck);
378+ tryCompare(gpsCheck, "checked", false);
379+ tryCompare(hereCheck, "checked", false);
380+ tryCompare(nopeCheck, "checked", true);
381+
382+ tap(findChild(page, "forwardButton"));
383+ tryCompare(AccountsService, "hereEnabled", false);
384+ tryCompare(locationActionGroup.location, "state", false);
385+ tryCompare(locationActionGroup.gps, "state", false);
386+ }
387+
388+ function test_locationHere() {
389+ var page = goToPage("locationPage");
390+ var gpsCheck = findChild(page, "gpsCheck");
391+ var hereCheck = findChild(page, "hereCheck");
392+ var nopeCheck = findChild(page, "nopeCheck");
393+
394+ var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
395+ tryCompare(locationActionGroup.location, "state", false);
396+ tryCompare(locationActionGroup.gps, "state", false);
397+
398+ // no tap because HERE is the default
399+ tryCompare(gpsCheck, "checked", false);
400+ tryCompare(hereCheck, "checked", true);
401+ tryCompare(nopeCheck, "checked", false);
402+
403+ tap(findChild(page, "forwardButton"));
404+ tryCompare(AccountsService, "hereEnabled", true);
405+ tryCompare(locationActionGroup.location, "state", true);
406+ tryCompare(locationActionGroup.gps, "state", true);
407+ }
408+
409+ function test_locationHereTerms() {
410+ var page = goToPage("locationPage");
411+
412+ var link = findChild(page, "hereTermsLink");
413+
414+ // Test our language lookup code a bit
415+
416+ i18n.language = "fr_FR.UTF-8";
417+ link.linkActivated("not-used");
418+ page = waitForPage("hereTermsPage");
419+ tryCompare(findChild(page, "termsLabel"), "text", "fr_FR\n");
420+ tap(findChild(page, "backButton"));
421+ waitForPage("locationPage");
422+
423+ i18n.language = "fr_CA";
424+ link.linkActivated("not-used");
425+ page = waitForPage("hereTermsPage");
426+ tryCompare(findChild(page, "termsLabel"), "text", "fr_CA\n");
427+ tap(findChild(page, "backButton"));
428+ waitForPage("locationPage");
429+
430+ i18n.language = "fr_US";
431+ link.linkActivated("not-used");
432+ page = waitForPage("hereTermsPage");
433+ tryCompare(findChild(page, "termsLabel"), "text", "fr_FR\n");
434+ tap(findChild(page, "backButton"));
435+ waitForPage("locationPage");
436+
437+ i18n.language = "fr.utf8";
438+ link.linkActivated("not-used");
439+ page = waitForPage("hereTermsPage");
440+ tryCompare(findChild(page, "termsLabel"), "text", "fr_FR\n");
441+ tap(findChild(page, "backButton"));
442+ waitForPage("locationPage");
443+
444+ i18n.language = "es"; // will not be found
445+ link.linkActivated("not-used");
446+ page = waitForPage("hereTermsPage");
447+ tryCompare(findChild(page, "termsLabel"), "text", "en_US\n");
448+
449+ // OK, done with languages, back to actual page
450+
451+ var label = findChild(page, "termsLabel");
452+ label.linkActivated(Qt.resolvedUrl("licenses/en_US.html"));
453+ tryCompare(label, "visible", false);
454+
455+ var webview = findChild(page, "webview");
456+ tryCompare(webview, "visible", true);
457+ tryCompare(webview, "url", Qt.resolvedUrl("licenses/en_US.html"));
458+ tryCompare(webview, "loadProgress", 100);
459+
460+ tap(findChild(page, "backButton"));
461+ waitForPage("hereTermsPage"); // confirm we're on same page
462+ tryCompare(webview, "visible", false);
463+ tryCompare(label, "visible", true);
464+
465+ tap(findChild(page, "backButton"));
466+ waitForPage("locationPage");
467+ }
468+ }
469+}