on bionic help sign in
unity8/tests/qmltests/Wizard/tst_Wizard.qml
508 lines 18 kB history raw
1/*
2 * Copyright 2014,2015 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 */
17import QtQuick 2.4
18import QtTest 1.0
19import AccountsService 0.1
20import MeeGo.QOfono 0.2
21import QMenuModel 0.1
22import Ubuntu.Components 1.3
23import Ubuntu.SystemSettings.SecurityPrivacy 1.0
24import Ubuntu.SystemSettings.TimeDate 1.1
25import Unity.Test 0.1 as UT
26import Wizard 0.1
27import Unity.InputInfo 0.1
28import "../../../qml/Wizard"
30Item {
31 id: root
32 width: units.gu(40)
33 height: units.gu(71)
35 Loader {
36 id: wizardLoader
37 anchors.fill: parent
39 property bool itemDestroyed: false
40 sourceComponent: Component {
41 Wizard {
42 id: wizard
43 anchors.fill: parent
45 Component.onCompleted: {
46 MockInputDeviceBackend.addMockDevice("/test", InputInfo.Keyboard);
47 }
49 Component.onDestruction: {
50 MockInputDeviceBackend.removeDevice("/test");
51 wizardLoader.itemDestroyed = true;
52 }
53 }
54 }
55 }
57 SignalSpy {
58 id: updateSessionLanguageSpy
59 target: System
60 signalName: "updateSessionLocaleCalled"
61 }
63 SignalSpy {
64 id: setSecuritySpy
65 signalName: "setSecurityCalled"
66 }
68 SignalSpy {
69 id: activateLocationSpy
70 signalName: "activated"
71 }
73 SignalSpy {
74 id: activateGPSSpy
75 signalName: "activated"
76 }
78 SignalSpy {
79 id: timezoneSpy
80 signalName: "timeZoneChangedCalled"
81 }
83 SignalSpy {
84 id: kbdLayoutSpy
85 target: AccountsService
86 signalName: "keymapsChanged"
87 }
89 function setup() {
90 AccountsService.hereEnabled = false;
91 AccountsService.hereLicensePath = Qt.resolvedUrl("licenses");
92 i18n.language = "en";
93 MockQOfono.setModems(["sim1"], [false], []);
94 MockQOfono.available = true;
95 MockQOfono.ready = true;
96 System.wizardEnabled = true;
98 updateSessionLanguageSpy.clear();
99 setSecuritySpy.clear();
100 activateLocationSpy.clear();
101 activateGPSSpy.clear();
102 timezoneSpy.clear();
103 kbdLayoutSpy.clear();
105 ActionData.data = {
106 "location-detection-enabled": {
107 'valid': true,
108 'state': false
109 },
110 "gps-detection-enabled": {
111 'valid': true,
112 'state': false
113 }
114 };
115 }
117 Component.onCompleted: {
118 setup();
119 }
121 UT.UnityTestCase {
122 id: wizardTests
123 name: "Wizard"
124 when: windowShown
126 property Item wizard: wizardLoader.status === Loader.Ready ? wizardLoader.item : null
128 function cleanup() {
129 wizardLoader.itemDestroyed = false;
131 wizardLoader.active = false;
133 tryCompare(wizardLoader, "status", Loader.Null);
134 tryCompare(wizardLoader, "item", null);
135 // Loader.status might be Loader.Null and Loader.item might be null but the Loader
136 // item might still be alive. So if we set Loader.active back to true
137 // again right now we will get the very same Shell instance back. So no reload
138 // actually took place. Likely because Loader waits until the next event loop
139 // iteration to do its work. So to ensure the reload, we will wait until the
140 // Shell instance gets destroyed.
141 tryCompare(wizardLoader, "itemDestroyed", true);
143 // reload our test subject to get it in a fresh state once again
144 wizardLoader.active = true;
146 tryCompare(wizardLoader, "status", Loader.Ready);
148 var pages = findChild(wizard, "wizardPages");
149 var security = findInvisibleChild(pages, "securityPrivacy");
150 security.setSecurity("", "", UbuntuSecurityPrivacyPanel.Swipe);
151 setSecuritySpy.target = security;
153 setup();
154 }
156 function waitForPage(name) {
157 var pages = findChild(wizard, "wizardPages");
158 var stack = findChild(pages, "pageStack");
159 // don't simply call tryCompare here, because stack.currentPage will be swapped out itself
160 tryCompareFunction(function() { return stack.currentPage.objectName; }, name, 15000);
161 var contentAnimation = findInvisibleChild(stack.currentPage, "contentAnimation");
162 tryCompareFunction(function() { return contentAnimation.running; }, false);
163 tryCompare(stack.currentPage, "opacity", 1.0);
164 tryCompare(stack.currentPage, "enabled", true);
165 tryCompare(stack.currentPage, "skipValid", true);
166 tryCompare(stack.currentPage, "skip", false);
167 waitForRendering(stack.currentPage);
168 return stack.currentPage;
169 }
171 function goToPage(name, skipSim, skipLocation) {
172 if (skipSim === undefined) {
173 skipSim = false;
174 }
175 if (skipLocation === undefined) {
176 skipLocation = false;
177 }
179 var page = waitForPage("languagePage");
180 if (name === page.objectName) return page;
181 tap(findChild(page, "forwardButton"));
183 if (!skipSim) {
184 page = waitForPage("simPage");
185 if (name === page.objectName) return page;
186 tap(findChild(page, "forwardButton"));
187 }
189 page = waitForPage("keyboardPage");
190 if (name === page.objectName) return page;
191 tap(findChild(page, "forwardButton"));
193 page = waitForPage("wifiPage");
194 if (name === page.objectName) return page;
195 tap(findChild(page, "forwardButton"));
197 if (!skipLocation) {
198 page = waitForPage("locationPage");
199 if (name === page.objectName) return page;
200 tap(findChild(page, "forwardButton"));
201 }
203 page = waitForPage("tzPage");
204 if (name === page.objectName) return page;
205 waitUntilTransitionsEnd(page);
206 var tzList = findChild(page, "tzList");
207 verify(tzList);
208 waitForRendering(tzList);
209 page.selectedTimeZone = "Pacific/Honolulu";
210 tap(findChild(page, "forwardButton"));
212 page = waitForPage("accountPage");
213 if (name === page.objectName) return page;
214 tap(findChild(page, "nameInput"));
215 typeString("foobar");
216 tap(findChild(page, "forwardButton"));
218 page = waitForPage("passwdPage");
219 if (name === page.objectName) return page;
220 tap(findChild(page, "forwardButton"));
222 page = waitForPage("finishedPage");
223 if (name === page.objectName) return page;
224 waitUntilTransitionsEnd(page);
225 tap(findChild(page, "finishButton"));
227 tryCompare(wizard, "shown", false);
228 compare(name, null);
229 return null;
230 }
232 function test_languageChange() {
233 var page = goToPage("languagePage");
234 tap(findChild(page, "languageDelegate_french_(france)")); // should invoke "fr" lang
236 tryCompare(i18n, "language", "fr_FR");
237 tap(findChild(page, "forwardButton"));
238 tryCompare(updateSessionLanguageSpy, "count", 1);
239 compare(updateSessionLanguageSpy.signalArguments[0][0], "fr_FR");
240 }
242 function test_languageNoChange() {
243 var page = goToPage("languagePage");
244 tap(findChild(page, "forwardButton"));
245 compare(updateSessionLanguageSpy.count, 0);
246 }
248 function test_simUnavailableSkip() {
249 MockQOfono.available = false;
250 goToPage("wifiPage", true);
251 }
253 function test_simNoModemsSkip() {
254 MockQOfono.setModems([], [], []);
255 goToPage("wifiPage", true);
256 }
258 function test_simFirstSkip() {
259 MockQOfono.setModems(["a", "b"], [true, false], []);
260 goToPage("wifiPage", true);
261 }
263 function test_simSecondSkip() {
264 MockQOfono.setModems(["a", "b"], [false, true], []);
265 goToPage("wifiPage", true);
266 }
268 function test_simBothSkip() {
269 MockQOfono.setModems(["a", "b"], [true, true], []);
270 goToPage("wifiPage", true);
271 }
273 function enterPasscode(passcode) {
274 for (var i = 0; i < passcode.length; ++i) {
275 var character = passcode.charAt(i);
276 var button = findChild(wizard, "pinPadButton" + character);
277 tap(button);
278 }
279 }
281 function test_passwdSkipIfSet() {
282 var page = goToPage("simPage");
284 // Set password type to non-swipe
285 var pages = findChild(wizard, "wizardPages");
286 var security = findInvisibleChild(pages, "securityPrivacy");
287 security.setSecurity("", "", UbuntuSecurityPrivacyPanel.Passphrase);
288 compare(security.securityType, UbuntuSecurityPrivacyPanel.Passphrase);
290 // Make sure that moving from sim page lands on wifi page
291 tap(findChild(page, "forwardButton"));
292 waitForPage("keyboardPage"); // thus skipping passwdPage
293 }
295 function verifyAnimationsNotRunning(page) {
296 var contentAnimation = findInvisibleChild(page, "contentAnimation");
297 var secondaryAnimation = findInvisibleChild(page, "secondaryAnimation");
298 tryCompare(contentAnimation, "running", false);
299 tryCompare(secondaryAnimation, "running", false);
300 }
302 function test_passwdPasscode() {
303 var page = goToPage("passwdPage");
304 tap(findChild(page, "passwdDelegate1")); // passcode option
305 tap(findChild(page, "forwardButton"));
306 page = waitForPage("passcodeSetPage");
307 verifyAnimationsNotRunning(page);
309 enterPasscode("1111");
310 page = waitForPage("passcodeConfirmPage");
311 verifyAnimationsNotRunning(page);
313 tap(findChild(page, "backButton"));
314 page = waitForPage("passcodeSetPage");
315 verifyAnimationsNotRunning(page);
317 enterPasscode("1111");
318 page = waitForPage("passcodeConfirmPage");
319 verifyAnimationsNotRunning(page);
321 enterPasscode("1112");
322 var error = findChild(page, "wrongNoticeLabel");
323 tryCompareFunction(function() { return error.text !== ""; }, true);
325 enterPasscode("1111");
327 // now finish up
328 page = waitForPage("finishedPage");
329 waitUntilTransitionsEnd(page);
330 tap(findChild(page, "finishButton"));
332 tryCompare(setSecuritySpy, "count", 1);
333 compare(setSecuritySpy.signalArguments[0][0], "");
334 compare(setSecuritySpy.signalArguments[0][1], "1111");
335 compare(setSecuritySpy.signalArguments[0][2], UbuntuSecurityPrivacyPanel.Passcode);
336 }
338 function test_passwdPassphrase() {
339 var page = goToPage("passwdPage");
340 tap(findChild(page, "passwdDelegate0")); // password option
341 tap(findChild(page, "forwardButton"));
342 page = waitForPage("passwdSetPage");
344 var passwdField = findChild(page, "passwordField");
345 verify(passwdField);
346 tap(passwdField);
347 verifyAnimationsNotRunning(page);
348 typeString("aaa");
349 var continueButton = findChild(page, "forwardButton");
350 tryCompare(page, "passwordsMatching", false);
352 tap(passwdField);
353 verifyAnimationsNotRunning(page);
354 passwdField.selectAll(); // overwrite the text
355 typeString("12345678");
356 tryCompare(page, "passwordsMatching", false);
358 var passwd2Field = findChild(page, "password2Field");
359 tap(passwd2Field);
360 verifyAnimationsNotRunning(page);
361 typeString("12345678");
362 tryCompare(continueButton, "enabled", true);
363 tap(continueButton);
365 // now finish up
366 page = waitForPage("finishedPage");
367 waitUntilTransitionsEnd(page);
368 tap(findChild(page, "finishButton"));
370 tryCompare(setSecuritySpy, "count", 1);
371 compare(setSecuritySpy.signalArguments[0][0], "");
372 compare(setSecuritySpy.signalArguments[0][1], "12345678");
373 compare(setSecuritySpy.signalArguments[0][2], UbuntuSecurityPrivacyPanel.Passphrase);
374 }
376 function test_passwdSwipe() {
377 var page = goToPage("passwdPage");
378 tap(findChild(page, "passwdDelegate2")); // swipe option
380 // now finish up
381 tap(findChild(page, "forwardButton"));
382 page = waitForPage("finishedPage");
383 waitUntilTransitionsEnd(page);
384 tap(findChild(page, "finishButton"));
386 tryCompare(setSecuritySpy, "count", 0); // not called for swipe method
387 }
389 function test_locationGpsOnly() {
390 var page = goToPage("locationPage");
391 var gpsCheck = findChild(page, "gpsCheckLabel");
392 var hereCheck = findChild(page, "hereCheckLabel");
393 var nopeCheck = findChild(page, "nopeCheckLabel");
395 var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
396 activateLocationSpy.target = locationActionGroup.location;
397 activateGPSSpy.target = locationActionGroup.gps;
399 tap(gpsCheck);
400 tryCompare(gpsCheck, "checked", true);
401 tryCompare(hereCheck, "checked", false);
402 tryCompare(nopeCheck, "checked", false);
404 tap(findChild(page, "forwardButton"));
405 tryCompare(AccountsService, "hereEnabled", false);
406 tryCompare(activateLocationSpy, "count", 1)
407 tryCompare(activateGPSSpy, "count", 1)
408 }
410 function test_locationNope() {
411 var page = goToPage("locationPage");
412 var gpsCheck = findChild(page, "gpsCheckLabel");
413 var hereCheck = findChild(page, "hereCheckLabel");
414 var nopeCheck = findChild(page, "nopeCheckLabel");
416 var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
417 activateLocationSpy.target = locationActionGroup.location;
418 activateGPSSpy.target = locationActionGroup.gps;
420 tap(nopeCheck);
421 tryCompare(gpsCheck, "checked", false);
422 tryCompare(hereCheck, "checked", false);
423 tryCompare(nopeCheck, "checked", true);
425 tap(findChild(page, "forwardButton"));
426 tryCompare(AccountsService, "hereEnabled", false);
427 tryCompare(activateLocationSpy, "count", 0);
428 tryCompare(activateGPSSpy, "count", 0);
429 }
431 function test_locationHere() {
432 var page = goToPage("locationPage");
433 var gpsCheck = findChild(page, "gpsCheckLabel");
434 var hereCheck = findChild(page, "hereCheckLabel");
435 var nopeCheck = findChild(page, "nopeCheckLabel");
437 var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
438 activateLocationSpy.target = locationActionGroup.location;
439 activateGPSSpy.target = locationActionGroup.gps;
441 // no tap because HERE is the default
442 tryCompare(gpsCheck, "checked", false);
443 tryCompare(hereCheck, "checked", true);
444 tryCompare(nopeCheck, "checked", false);
446 tap(findChild(page, "forwardButton"));
447 tryCompare(AccountsService, "hereEnabled", true);
448 tryCompare(activateLocationSpy, "count", 1);
449 tryCompare(activateGPSSpy, "count", 1);
450 }
452 function test_timezonePage() {
453 var page = goToPage("tzPage");
454 verify(page);
455 timezoneSpy.target = page.tdModule;
457 var tzFilter = findChild(page, "tzFilter");
458 verify(tzFilter);
459 tap(tzFilter);
460 typeString("Belfa");
462 var tzList = findChild(page, "tzList");
463 verify(tzList);
465 // test filtering works and returns some results
466 tryCompareFunction(function() { return tzList.count > 0; }, true);
468 // just tap the first one
469 tap(findChild(page, "tz0"));
471 // go next and verify the (mock) signal got fired
472 tap(findChild(page, "forwardButton"));
473 tryCompare(timezoneSpy, "count", 1);
474 compare(timezoneSpy.signalArguments[0][0], "Europe/London");
475 compare(timezoneSpy.signalArguments[0][1], "Belfast");
476 }
478 function test_accountPage() {
479 var page = goToPage("accountPage");
480 var forwardButton = findChild(page, "forwardButton");
482 tap(findChild(page, "nameInput"));
483 typeString("foobar");
484 }
486 function test_keyboardPage() {
487 var page = goToPage("keyboardPage");
488 var forwardButton = findChild(page, "forwardButton");
490 // change language
491 var langSelector = findChild(page, "langSelector");
492 verify(langSelector);
493 langSelector.selectedIndex = 1; // should be fr_FR
494 print("Selected language:", page.selectedLanguage);
496 // pick some layout
497 var kbdDelegate = findChild(page, "kbdDelegate1");
498 verify(kbdDelegate);
499 mouseClick(kbdDelegate);
500 verify(kbdDelegate.isCurrent);
501 print("Selected keymap:", page.selectedKeymap);
503 // verify the keymapsChanged signal got fired
504 tap(findChild(page, "forwardButton"));
505 tryCompare(kbdLayoutSpy, "count", 1);
506 }
507 }