@@ -0,0 +1,469 @@
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 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
25+import "../../../qml/Wizard"
36+ property bool itemDestroyed: false
37+ sourceComponent: Component {
41+ background: Qt.resolvedUrl("../../../qml/graphics/phone_background.jpg")
43+ Component.onDestruction: {
44+ wizardLoader.itemDestroyed = true;
51+ id: updateSessionLanguageSpy
53+ signalName: "updateSessionLanguageCalled"
58+ signalName: "setSecurityCalled"
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;
69+ updateSessionLanguageSpy.clear();
70+ setSecuritySpy.clear();
73+ Component.onCompleted: {
74+ Theme.name = "Ubuntu.Components.Themes.SuruGradient";
83+ property Item wizard: wizardLoader.status === Loader.Ready ? wizardLoader.item : null
86+ wizardLoader.itemDestroyed = false;
88+ wizardLoader.active = false;
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);
100+ // reload our test subject to get it in a fresh state once again
101+ wizardLoader.active = true;
103+ tryCompare(wizardLoader, "status", Loader.Ready);
105+ var pages = findChild(wizard, "wizardPages");
106+ var security = findInvisibleChild(pages, "securityPrivacy");
107+ setSecuritySpy.target = security;
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;
123+ function goToPage(name, skipSim, skipLocation) {
124+ if (skipSim === undefined) {
127+ if (skipLocation === undefined) {
128+ skipLocation = false;
131+ var page = waitForPage("languagePage");
132+ if (name === page.objectName) return page;
133+ tap(findChild(page, "forwardButton"));
136+ page = waitForPage("simPage");
137+ if (name === page.objectName) return page;
138+ tap(findChild(page, "forwardButton"));
141+ page = waitForPage("passwdPage");
142+ if (name === page.objectName) return page;
143+ tap(findChild(page, "passwdDelegate0"));
144+ tap(findChild(page, "forwardButton"));
146+ page = waitForPage("wifiPage");
147+ if (name === page.objectName) return page;
148+ tap(findChild(page, "forwardButton"));
150+ if (!skipLocation) {
151+ page = waitForPage("locationPage");
152+ if (name === page.objectName) return page;
153+ tap(findChild(page, "forwardButton"));
156+ page = waitForPage("reportingPage");
157+ if (name === page.objectName) return page;
158+ tap(findChild(page, "forwardButton"));
160+ page = waitForPage("finishedPage");
161+ if (name === page.objectName) return page;
162+ tap(findChild(page, "forwardButton"));
164+ tryCompare(wizard, "shown", false);
165+ compare(name, null);
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");
181+ function test_languageNoChange() {
182+ goToPage("simPage"); // one past language page
183+ compare(updateSessionLanguageSpy.count, 0);
186+ function test_simUnavailableSkip() {
187+ MockQOfono.available = false;
188+ goToPage("passwdPage", true);
191+ function test_simNoModemsSkip() {
192+ MockQOfono.setModems([], []);
193+ goToPage("passwdPage", true);
196+ function test_simFirstSkip() {
197+ MockQOfono.setModems(["a", "b"], [true, false]);
198+ goToPage("passwdPage", true);
201+ function test_simSecondSkip() {
202+ MockQOfono.setModems(["a", "b"], [false, true]);
203+ goToPage("passwdPage", true);
206+ function test_simBothSkip() {
207+ MockQOfono.setModems(["a", "b"], [true, true]);
208+ goToPage("passwdPage", true);
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);
219+ function test_passwdPasscode() {
220+ var page = goToPage("passwdPage");
222+ tap(findChild(page, "forwardButton"));
223+ page = waitForPage("passwdSetPage");
225+ enterPasscode("1111");
226+ page = waitForPage("passwdConfirmPage");
228+ // make sure we go back to 'set' page not 'type' page
229+ tap(findChild(page, "backButton"));
230+ page = waitForPage("passwdSetPage");
232+ enterPasscode("1111");
233+ page = waitForPage("passwdConfirmPage");
235+ enterPasscode("1112");
236+ var error = findChild(page, "wrongNoticeLabel");
237+ tryCompareFunction(function() { return error.text !== ""; }, true);
239+ enterPasscode("1111");
240+ page = waitForPage("wifiPage");
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"));
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);
257+ function test_passwdPassphrase() {
258+ var page = goToPage("passwdPage");
259+ tap(findChild(page, "passwdDelegate2"));
261+ tap(findChild(page, "forwardButton"));
262+ page = waitForPage("passwdSetPage");
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);
272+ tap(continueButton);
273+ page = waitForPage("passwdConfirmPage");
275+ // make sure we go back to 'set' page not 'type' page
276+ var back = findChild(page, "backButton");
278+ page = waitForPage("passwdSetPage");
281+ keyClick(Qt.Key_Enter);
282+ page = waitForPage("passwdConfirmPage");
284+ continueButton = findChild(page, "forwardButton");
286+ tryCompare(continueButton.item, "enabled", false);
287+ keyClick(Qt.Key_Enter);
288+ var error = findChild(page, "wrongNoticeLabel");
289+ tryCompareFunction(function() { return error.text !== ""; }, true);
292+ tap(continueButton);
293+ page = waitForPage("wifiPage");
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"));
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);
310+ function test_passwdSwipe() {
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);
319+ function test_locationSkipNoPath() {
320+ AccountsService.hereLicensePath = "";
321+ goToPage("reportingPage", false, true);
324+ function test_locationSkipNoFiles() {
325+ AccountsService.hereLicensePath = Qt.resolvedUrl("nolicenses");
326+ goToPage("reportingPage", false, true);
329+ function test_locationWaitOnPath() {
330+ AccountsService.hereLicensePath = " "; // means we're still getting the path from dbus
332+ var page = goToPage("wifiPage");
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);
342+ AccountsService.hereLicensePath = "";
343+ waitForPage("reportingPage");
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");
352+ var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
353+ tryCompare(locationActionGroup.location, "state", false);
354+ tryCompare(locationActionGroup.gps, "state", false);
357+ tryCompare(gpsCheck, "checked", true);
358+ tryCompare(hereCheck, "checked", false);
359+ tryCompare(nopeCheck, "checked", false);
361+ tap(findChild(page, "forwardButton"));
362+ tryCompare(AccountsService, "hereEnabled", false);
363+ tryCompare(locationActionGroup.location, "state", true);
364+ tryCompare(locationActionGroup.gps, "state", true);
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");
373+ var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
374+ tryCompare(locationActionGroup.location, "state", false);
375+ tryCompare(locationActionGroup.gps, "state", false);
378+ tryCompare(gpsCheck, "checked", false);
379+ tryCompare(hereCheck, "checked", false);
380+ tryCompare(nopeCheck, "checked", true);
382+ tap(findChild(page, "forwardButton"));
383+ tryCompare(AccountsService, "hereEnabled", false);
384+ tryCompare(locationActionGroup.location, "state", false);
385+ tryCompare(locationActionGroup.gps, "state", false);
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");
394+ var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
395+ tryCompare(locationActionGroup.location, "state", false);
396+ tryCompare(locationActionGroup.gps, "state", false);
398+ // no tap because HERE is the default
399+ tryCompare(gpsCheck, "checked", false);
400+ tryCompare(hereCheck, "checked", true);
401+ tryCompare(nopeCheck, "checked", false);
403+ tap(findChild(page, "forwardButton"));
404+ tryCompare(AccountsService, "hereEnabled", true);
405+ tryCompare(locationActionGroup.location, "state", true);
406+ tryCompare(locationActionGroup.gps, "state", true);
409+ function test_locationHereTerms() {
410+ var page = goToPage("locationPage");
412+ var link = findChild(page, "hereTermsLink");
414+ // Test our language lookup code a bit
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");
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");
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");
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");
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");
449+ // OK, done with languages, back to actual page
451+ var label = findChild(page, "termsLabel");
452+ label.linkActivated(Qt.resolvedUrl("licenses/en_US.html"));
453+ tryCompare(label, "visible", false);
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);
460+ tap(findChild(page, "backButton"));
461+ waitForPage("hereTermsPage"); // confirm we're on same page
462+ tryCompare(webview, "visible", false);
463+ tryCompare(label, "visible", true);
465+ tap(findChild(page, "backButton"));
466+ waitForPage("locationPage");