~gerboland/unity8/initialSurfaceGeometry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/*
 * Copyright 2014 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.3
import QtTest 1.0
import AccountsService 0.1
import MeeGo.QOfono 0.2
import Ubuntu.Components 1.1
import Ubuntu.SystemSettings.SecurityPrivacy 1.0
import Unity.Test 0.1 as UT
import Wizard 0.1
import "../../../qml/Wizard"

Item {
    id: root
    width: units.gu(40)
    height: units.gu(71)

    Loader {
        id: wizardLoader
        anchors.fill: parent

        property bool itemDestroyed: false
        sourceComponent: Component {
            Wizard {
                id: wizard
                anchors.fill: parent
                background: Qt.resolvedUrl("../../../qml/graphics/phone_background.jpg")

                Component.onDestruction: {
                    wizardLoader.itemDestroyed = true;
                }
            }
        }
    }

    SignalSpy {
        id: updateSessionLanguageSpy
        target: System
        signalName: "updateSessionLanguageCalled"
    }

    SignalSpy {
        id: setSecuritySpy
        signalName: "setSecurityCalled"
    }

    function setup() {
        AccountsService.hereEnabled = false;
        AccountsService.hereLicensePath = Qt.resolvedUrl("licenses");
        i18n.language = "en";
        MockQOfono.setModems(["sim1"], [false]);
        MockQOfono.available = true;
        System.wizardEnabled = true;

        updateSessionLanguageSpy.clear();
        setSecuritySpy.clear();
    }

    Component.onCompleted: {
        Theme.name = "Ubuntu.Components.Themes.SuruGradient";
        setup();
    }

    UT.UnityTestCase {
        id: wizardTests
        name: "Wizard"
        when: windowShown

        property Item wizard: wizardLoader.status === Loader.Ready ? wizardLoader.item : null

        function cleanup() {
            wizardLoader.itemDestroyed = false;

            wizardLoader.active = false;

            tryCompare(wizardLoader, "status", Loader.Null);
            tryCompare(wizardLoader, "item", null);
            // Loader.status might be Loader.Null and Loader.item might be null but the Loader
            // item might still be alive. So if we set Loader.active back to true
            // again right now we will get the very same Shell instance back. So no reload
            // actually took place. Likely because Loader waits until the next event loop
            // iteration to do its work. So to ensure the reload, we will wait until the
            // Shell instance gets destroyed.
            tryCompare(wizardLoader, "itemDestroyed", true);

            // reload our test subject to get it in a fresh state once again
            wizardLoader.active = true;

            tryCompare(wizardLoader, "status", Loader.Ready);

            var pages = findChild(wizard, "wizardPages");
            var security = findInvisibleChild(pages, "securityPrivacy");
            setSecuritySpy.target = security;

            setup();
        }

        function waitForPage(name) {
            var pages = findChild(wizard, "wizardPages");
            var stack = findChild(pages, "pageStack");
            // don't simply call tryCompare here, because stack.currentPage will be swapped out itself
            tryCompareFunction(function() { return stack.currentPage.objectName; }, name);
            tryCompare(stack.currentPage, "opacity", 1.0);
            tryCompare(stack.currentPage, "enabled", true);
            waitForRendering(stack.currentPage);
            return stack.currentPage;
        }

        function goToPage(name, skipSim, skipLocation) {
            if (skipSim === undefined) {
                skipSim = false;
            }
            if (skipLocation === undefined) {
                skipLocation = false;
            }

            var page = waitForPage("languagePage");
            if (name === page.objectName) return page;
            tap(findChild(page, "forwardButton"));

            if (!skipSim) {
                page = waitForPage("simPage");
                if (name === page.objectName) return page;
                tap(findChild(page, "forwardButton"));
            }

            page = waitForPage("passwdPage");
            if (name === page.objectName) return page;
            tap(findChild(page, "passwdDelegate0"));
            tap(findChild(page, "forwardButton"));

            page = waitForPage("wifiPage");
            if (name === page.objectName) return page;
            tap(findChild(page, "forwardButton"));

            if (!skipLocation) {
                page = waitForPage("locationPage");
                if (name === page.objectName) return page;
                tap(findChild(page, "forwardButton"));
            }

            page = waitForPage("reportingPage");
            if (name === page.objectName) return page;
            tap(findChild(page, "forwardButton"));

            page = waitForPage("finishedPage");
            if (name === page.objectName) return page;
            tap(findChild(page, "forwardButton"));

            tryCompare(wizard, "shown", false);
            compare(name, null);
            return null;
        }

        function test_languageChange() {
            var page = goToPage("languagePage");
            tap(findChild(page, "languageCombo"));
            waitForRendering(findChild(page, "languageDelegate1"));

            // For some reason, the delegate *sometimes* (like 1 in 10 maybe)
            // needs more time before it can process a tap() call.  I can't
            // find a rhyme or reason, its properties all seem the same in
            // cases where it works and does not.  This failure to receive a
            // tap() call below does *not* happen when running in xvfb, so
            // jenkins is unaffected (and we don't have to worry about 100 not
            // being enough time in its slow environment).  This wait() call is
            // just to help local runs not trip up.
            wait(100);
            tap(findChild(page, "languageDelegate1"));

            tryCompare(i18n, "language", "fr");
            tap(findChild(page, "forwardButton"));
            tryCompare(updateSessionLanguageSpy, "count", 1);
            compare(updateSessionLanguageSpy.signalArguments[0][0], "fr");
        }

        function test_languageNoChange() {
            goToPage("simPage"); // one past language page
            compare(updateSessionLanguageSpy.count, 0);
        }

        function test_simUnavailableSkip() {
            MockQOfono.available = false;
            goToPage("passwdPage", true);
        }

        function test_simNoModemsSkip() {
            MockQOfono.setModems([], []);
            goToPage("passwdPage", true);
        }

        function test_simFirstSkip() {
            MockQOfono.setModems(["a", "b"], [true, false]);
            goToPage("passwdPage", true);
        }

        function test_simSecondSkip() {
            MockQOfono.setModems(["a", "b"], [false, true]);
            goToPage("passwdPage", true);
        }

        function test_simBothSkip() {
            MockQOfono.setModems(["a", "b"], [true, true]);
            goToPage("passwdPage", true);
        }

        function enterPasscode(passcode) {
            for (var i = 0; i < passcode.length; ++i) {
                var character = passcode.charAt(i);
                var button = findChild(wizard, "pinPadButton" + character);
                tap(button);
            }
        }

        function test_passwdPasscode() {
            var page = goToPage("passwdPage");

            tap(findChild(page, "forwardButton"));
            page = waitForPage("passwdSetPage");

            enterPasscode("1111");
            page = waitForPage("passwdConfirmPage");

            // make sure we go back to 'set' page not 'type' page
            tap(findChild(page, "backButton"));
            page = waitForPage("passwdSetPage");

            enterPasscode("1111");
            page = waitForPage("passwdConfirmPage");

            enterPasscode("1112");
            var error = findChild(page, "wrongNoticeLabel");
            tryCompareFunction(function() { return error.text !== ""; }, true);

            enterPasscode("1111");
            page = waitForPage("wifiPage");

            // now finish up
            tap(findChild(page, "forwardButton"));
            page = waitForPage("locationPage");
            tap(findChild(page, "forwardButton"));
            page = waitForPage("reportingPage");
            tap(findChild(page, "forwardButton"));
            page = waitForPage("finishedPage");
            tap(findChild(page, "forwardButton"));

            tryCompare(setSecuritySpy, "count", 1);
            compare(setSecuritySpy.signalArguments[0][0], "");
            compare(setSecuritySpy.signalArguments[0][1], "1111");
            compare(setSecuritySpy.signalArguments[0][2], UbuntuSecurityPrivacyPanel.Passcode);
        }

        function test_passwdPassphrase() {
            var page = goToPage("passwdPage");
            tap(findChild(page, "passwdDelegate2"));

            tap(findChild(page, "forwardButton"));
            page = waitForPage("passwdSetPage");

            typeString("aaa");
            var continueButton = findChild(page, "forwardButton");
            tryCompare(continueButton.item, "enabled", false);
            keyClick(Qt.Key_Enter);
            var error = findChild(page, "wrongNoticeLabel");
            tryCompareFunction(function() { return error.text !== ""; }, true);

            typeString("aaaa");
            tap(continueButton);
            page = waitForPage("passwdConfirmPage");

            // make sure we go back to 'set' page not 'type' page
            var back = findChild(page, "backButton");
            tap(back);
            page = waitForPage("passwdSetPage");

            typeString("aaaa");
            keyClick(Qt.Key_Enter);
            page = waitForPage("passwdConfirmPage");

            continueButton = findChild(page, "forwardButton");
            typeString("aaab");
            tryCompare(continueButton.item, "enabled", false);
            keyClick(Qt.Key_Enter);
            var error = findChild(page, "wrongNoticeLabel");
            tryCompareFunction(function() { return error.text !== ""; }, true);

            typeString("aaaa");
            tap(continueButton);
            page = waitForPage("wifiPage");

            // now finish up
            tap(findChild(page, "forwardButton"));
            page = waitForPage("locationPage");
            tap(findChild(page, "forwardButton"));
            page = waitForPage("reportingPage");
            tap(findChild(page, "forwardButton"));
            page = waitForPage("finishedPage");
            tap(findChild(page, "forwardButton"));

            tryCompare(setSecuritySpy, "count", 1);
            compare(setSecuritySpy.signalArguments[0][0], "");
            compare(setSecuritySpy.signalArguments[0][1], "aaaa");
            compare(setSecuritySpy.signalArguments[0][2], UbuntuSecurityPrivacyPanel.Passphrase);
        }

        function test_passwdSwipe() {
            goToPage(null);

            tryCompare(setSecuritySpy, "count", 1);
            compare(setSecuritySpy.signalArguments[0][0], "");
            compare(setSecuritySpy.signalArguments[0][1], "");
            compare(setSecuritySpy.signalArguments[0][2], UbuntuSecurityPrivacyPanel.Swipe);
        }

        function test_locationSkipNoPath() {
            AccountsService.hereLicensePath = "";
            goToPage("reportingPage", false, true);
        }

        function test_locationSkipNoFiles() {
            AccountsService.hereLicensePath = Qt.resolvedUrl("nolicenses");
            goToPage("reportingPage", false, true);
        }

        function test_locationWaitOnPath() {
            AccountsService.hereLicensePath = " "; // means we're still getting the path from dbus

            var page = goToPage("wifiPage");

            var pages = findChild(wizard, "wizardPages");
            var stack = findChild(pages, "pageStack");
            tap(findChild(page, "forwardButton"));
            // don't simply call tryCompare here, because stack.currentPage will be swapped out itself
            tryCompareFunction(function() { return stack.currentPage.objectName; }, "locationPage");
            compare(stack.currentPage.enabled, false);
            compare(stack.currentPage.skipValid, false);

            AccountsService.hereLicensePath = "";
            waitForPage("reportingPage");
        }

        function test_locationGpsOnly() {
            var page = goToPage("locationPage");
            var gpsCheck = findChild(page, "gpsCheck");
            var hereCheck = findChild(page, "hereCheck");
            var nopeCheck = findChild(page, "nopeCheck");

            var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
            tryCompare(locationActionGroup.location, "state", false);
            tryCompare(locationActionGroup.gps, "state", false);

            tap(gpsCheck);
            tryCompare(gpsCheck, "checked", true);
            tryCompare(hereCheck, "checked", false);
            tryCompare(nopeCheck, "checked", false);

            tap(findChild(page, "forwardButton"));
            tryCompare(AccountsService, "hereEnabled", false);
            tryCompare(locationActionGroup.location, "state", true);
            tryCompare(locationActionGroup.gps, "state", true);
        }

        function test_locationNope() {
            var page = goToPage("locationPage");
            var gpsCheck = findChild(page, "gpsCheck");
            var hereCheck = findChild(page, "hereCheck");
            var nopeCheck = findChild(page, "nopeCheck");

            var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
            tryCompare(locationActionGroup.location, "state", false);
            tryCompare(locationActionGroup.gps, "state", false);

            tap(nopeCheck);
            tryCompare(gpsCheck, "checked", false);
            tryCompare(hereCheck, "checked", false);
            tryCompare(nopeCheck, "checked", true);

            tap(findChild(page, "forwardButton"));
            tryCompare(AccountsService, "hereEnabled", false);
            tryCompare(locationActionGroup.location, "state", false);
            tryCompare(locationActionGroup.gps, "state", false);
        }

        function test_locationHere() {
            var page = goToPage("locationPage");
            var gpsCheck = findChild(page, "gpsCheck");
            var hereCheck = findChild(page, "hereCheck");
            var nopeCheck = findChild(page, "nopeCheck");

            var locationActionGroup = findInvisibleChild(page, "locationActionGroup");
            tryCompare(locationActionGroup.location, "state", false);
            tryCompare(locationActionGroup.gps, "state", false);

            // no tap because HERE is the default
            tryCompare(gpsCheck, "checked", false);
            tryCompare(hereCheck, "checked", true);
            tryCompare(nopeCheck, "checked", false);

            tap(findChild(page, "forwardButton"));
            tryCompare(AccountsService, "hereEnabled", true);
            tryCompare(locationActionGroup.location, "state", true);
            tryCompare(locationActionGroup.gps, "state", true);
        }

        function test_locationHereTerms() {
            var page = goToPage("locationPage");

            var link = findChild(page, "hereTermsLink");

            // Test our language lookup code a bit

            i18n.language = "fr_FR.UTF-8";
            link.linkActivated("not-used");
            page = waitForPage("hereTermsPage");
            tryCompare(findChild(page, "termsLabel"), "text", "fr_FR\n");
            tap(findChild(page, "backButton"));
            waitForPage("locationPage");

            i18n.language = "fr_CA";
            link.linkActivated("not-used");
            page = waitForPage("hereTermsPage");
            tryCompare(findChild(page, "termsLabel"), "text", "fr_CA\n");
            tap(findChild(page, "backButton"));
            waitForPage("locationPage");

            i18n.language = "fr_US";
            link.linkActivated("not-used");
            page = waitForPage("hereTermsPage");
            tryCompare(findChild(page, "termsLabel"), "text", "fr_FR\n");
            tap(findChild(page, "backButton"));
            waitForPage("locationPage");

            i18n.language = "fr.utf8";
            link.linkActivated("not-used");
            page = waitForPage("hereTermsPage");
            tryCompare(findChild(page, "termsLabel"), "text", "fr_FR\n");
            tap(findChild(page, "backButton"));
            waitForPage("locationPage");

            i18n.language = "es"; // will not be found
            link.linkActivated("not-used");
            page = waitForPage("hereTermsPage");
            tryCompare(findChild(page, "termsLabel"), "text", "en_US\n");

            // OK, done with languages, back to actual page

            var label = findChild(page, "termsLabel");
            label.linkActivated(Qt.resolvedUrl("licenses/en_US.html"));
            tryCompare(label, "visible", false);

            var webview = findChild(page, "webview");
            tryCompare(webview, "visible", true);
            tryCompare(webview, "url", Qt.resolvedUrl("licenses/en_US.html"));
            tryCompare(webview, "loadProgress", 100);

            tap(findChild(page, "backButton"));
            waitForPage("hereTermsPage"); // confirm we're on same page
            tryCompare(webview, "visible", false);
            tryCompare(label, "visible", true);

            tap(findChild(page, "backButton"));
            waitForPage("locationPage");
        }
    }
}