~ci-train-bot/ubuntu-settings-components/ubuntu-settings-components-ubuntu-yakkety-1895

« back to all changes in this revision

Viewing changes to tests/qmltests/Fingerprint/tst_FingerprintSetup.qml

  • Committer: Bileto Bot
  • Date: 2016-06-20 14:01:03 UTC
  • mfrom: (103.6.69 fingerprint)
  • Revision ID: ci-train-bot@canonical.com-20160620140103-q57lulbze89e6yyd
jonas-drange
* Add components for Fingerprint management.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by Jonas G. Drange <jonas.drange@canonical.com>
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import QtTest 1.0
 
21
import Ubuntu.Components 1.3
 
22
import Ubuntu.Settings.Fingerprint 0.1
 
23
import Ubuntu.Test 0.1
 
24
import Biometryd 0.0
 
25
 
 
26
Item {
 
27
    id: testRoot
 
28
    width: units.gu(50)
 
29
    height: units.gu(90)
 
30
 
 
31
    Component {
 
32
        id: setupComponent
 
33
 
 
34
        Setup {
 
35
            anchors.fill: parent
 
36
            visible: false
 
37
        }
 
38
    }
 
39
 
 
40
    PageStack {
 
41
        id: pageStack
 
42
    }
 
43
 
 
44
    SignalSpy {
 
45
        id: statusLabelSpy
 
46
        signalName: "slideCompleted"
 
47
    }
 
48
 
 
49
    SignalSpy {
 
50
        id: enrollmentObserverProgressedSpy
 
51
        signalName: "progressed"
 
52
    }
 
53
 
 
54
    SignalSpy {
 
55
        id: enrollmentObserverSucceededSpy
 
56
        signalName: "succeeded"
 
57
    }
 
58
 
 
59
    SignalSpy {
 
60
        id: enrollmentObserverFailedSpy
 
61
        signalName: "failed"
 
62
    }
 
63
 
 
64
    UbuntuTestCase {
 
65
        name: "SetupUI"
 
66
        when: windowShown
 
67
 
 
68
        property var setupInstance: null
 
69
 
 
70
        function init() {
 
71
            Biometryd.setAvailable(true);
 
72
            setupInstance = setupComponent.createObject(testRoot);
 
73
            pageStack.push(setupInstance);
 
74
 
 
75
            statusLabelSpy.target = getStatusLabel();
 
76
        }
 
77
 
 
78
        function cleanup() {
 
79
            statusLabelSpy.clear();
 
80
 
 
81
            pageStack.pop();
 
82
            setupInstance.destroy();
 
83
            setupInstance = null
 
84
        }
 
85
 
 
86
        function getStatusLabel() {
 
87
            return findChild(setupInstance, "fingerprintStatusLabel");
 
88
        }
 
89
 
 
90
        function getFailedVisual() {
 
91
            return findChild(setupInstance, "fingerprintFailedVisual");
 
92
        }
 
93
 
 
94
        function getDefaultVisual() {
 
95
            return findChild(setupInstance, "fingerprintDefaultVisual");
 
96
        }
 
97
 
 
98
        function getDoneVisual() {
 
99
            return findChild(setupInstance, "fingerprintDoneVisual");
 
100
        }
 
101
 
 
102
        function getProgressLabel() {
 
103
            return findChild(setupInstance, "fingerprintProgressLabel");
 
104
        }
 
105
 
 
106
        function test_initialState() {
 
107
            var targetText = i18n.dtr("ubuntu-settings-components", "Swipe your finger over the reader.");
 
108
            compare(getStatusLabel().text, targetText);
 
109
 
 
110
            tryCompare(getDefaultVisual(), "opacity", 1);
 
111
            tryCompare(getFailedVisual(), "opacity", 0);
 
112
            tryCompare(getDoneVisual(), "opacity", 0);
 
113
        }
 
114
 
 
115
        function test_startedState() {
 
116
            var targetText = i18n.dtr("ubuntu-settings-components", "Swipe your finger repeatedly over the reader.");
 
117
            setupInstance.enrollmentProgressed(0.5, {});
 
118
            statusLabelSpy.wait();
 
119
            compare(getStatusLabel().text, targetText);
 
120
 
 
121
            tryCompare(getDefaultVisual(), "opacity", 1);
 
122
            tryCompare(getFailedVisual(), "opacity", 0);
 
123
            tryCompare(getDoneVisual(), "opacity", 0);
 
124
        }
 
125
 
 
126
        function test_failedStatus() {
 
127
            var targetText = i18n.dtr("ubuntu-settings-components", "Sorry, the reader doesn’t seem to be working.");
 
128
            setupInstance.enrollmentFailed("test failure");
 
129
            compare(getStatusLabel().text, targetText);
 
130
 
 
131
            tryCompare(getDefaultVisual(), "opacity", 0);
 
132
            tryCompare(getFailedVisual(), "opacity", 1);
 
133
            tryCompare(getDoneVisual(), "opacity", 0);
 
134
        }
 
135
 
 
136
        function test_successfulState() {
 
137
            var targetText = i18n.dtr("ubuntu-settings-components", "All done!");
 
138
 
 
139
            setupInstance.enrollmentCompleted();
 
140
            compare(getStatusLabel().text, targetText);
 
141
 
 
142
            tryCompare(getDefaultVisual(), "opacity", 0);
 
143
            tryCompare(getFailedVisual(), "opacity", 0);
 
144
            tryCompare(getDoneVisual(), "opacity", 1);
 
145
 
 
146
            var button = findChild(pageStack, "fingerprintSetupDoneButton");
 
147
            compare(button.enabled, true, "button was disabled when done");
 
148
        }
 
149
 
 
150
        function test_notDone() {
 
151
            var button = findChild(pageStack, "fingerprintSetupDoneButton");
 
152
            compare(button.enabled, false, "button was enabled initially");
 
153
        }
 
154
 
 
155
        function test_statusLabel() {
 
156
            getStatusLabel().setText("foo");
 
157
            statusLabelSpy.wait();
 
158
            compare(getStatusLabel().text, "foo");
 
159
        }
 
160
 
 
161
        function test_direction_data() {
 
162
            return [
 
163
                { tag: "empty", visual: { visible: false, rotation: 0 }},
 
164
                { tag: "not available", dir: FingerprintReader.NotAvailable, visual: { visible: false, rotation: 0 }},
 
165
                { tag: "SouthWest", dir: FingerprintReader.SouthWest, visual: { visible: true, rotation: 225 }},
 
166
                { tag: "South", dir: FingerprintReader.South, visual: { visible: true, rotation: 180 }},
 
167
                { tag: "SouthEast", dir: FingerprintReader.SouthEast, visual: { visible: true, rotation: 135 }},
 
168
                { tag: "NorthWest", dir: FingerprintReader.NorthWest, visual: { visible: true, rotation: 315 }},
 
169
                { tag: "North", dir: FingerprintReader.North, visual: { visible: true, rotation: 0 }},
 
170
                { tag: "NorthEast", dir: FingerprintReader.NorthEast, visual: { visible: true, rotation: 45 }},
 
171
                { tag: "East", dir: FingerprintReader.East, visual: { visible: true, rotation: 90 }},
 
172
                { tag: "West", dir: FingerprintReader.West, visual: { visible: true, rotation: 270 }}
 
173
            ]
 
174
        }
 
175
 
 
176
        function test_direction(data) {
 
177
            var vis = findChild(setupInstance, "fingerprintDirectionVisual");
 
178
            var hints = {};
 
179
            hints[FingerprintReader.suggestedNextDirection] = data.dir;
 
180
 
 
181
            setupInstance.enrollmentProgressed(0.5, hints);
 
182
 
 
183
            tryCompare(vis, "opacity", data.visual.visible ? 1 : 0)
 
184
            compare(vis.opacity, data.visual.visible ? 1 : 0);
 
185
            compare(vis.rotation, data.visual.rotation);
 
186
        }
 
187
 
 
188
        function test_progressHidden() {
 
189
            var pl = getProgressLabel();
 
190
            compare(pl.opacity, 0);
 
191
        }
 
192
 
 
193
        function test_progressVisible() {
 
194
            var pl = getProgressLabel();
 
195
            setupInstance.enrollmentProgressed(0.5, {});
 
196
            tryCompare(pl, "opacity", 1);
 
197
            tryCompare(pl, "text", i18n.dtr("ubuntu-settings-components", "%1%").arg(50));
 
198
        }
 
199
 
 
200
        function test_progressReadable() {
 
201
            setupInstance.enrollmentProgressed(0.6666666667, {});
 
202
            tryCompare(getProgressLabel(), "text", i18n.dtr("ubuntu-settings-components", "%1%").arg(66));
 
203
        }
 
204
 
 
205
        // This is a visual test where we can confirm that the arrow
 
206
        // rotates using the orthodromic distance.
 
207
        function test_directions() {
 
208
            var hints = {};
 
209
 
 
210
            hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.North;
 
211
            setupInstance.enrollmentProgressed(0.6666666667, hints);
 
212
            wait(200)
 
213
            hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.East;
 
214
            setupInstance.enrollmentProgressed(0.6666666667, hints);
 
215
            wait(200)
 
216
            hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.South;
 
217
            setupInstance.enrollmentProgressed(0.6666666667, hints);
 
218
            wait(200)
 
219
            hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.West;
 
220
            setupInstance.enrollmentProgressed(0.6666666667, hints);
 
221
            wait(200)
 
222
            hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.SouthEast;
 
223
            setupInstance.enrollmentProgressed(0.6666666667, hints);
 
224
            wait(200)
 
225
            hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.NorthEast;
 
226
            setupInstance.enrollmentProgressed(0.6666666667, hints);
 
227
            wait(200)
 
228
            hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.NorthWest;
 
229
            setupInstance.enrollmentProgressed(0.6666666667, hints);
 
230
            wait(200)
 
231
            hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.NorthEast;
 
232
            setupInstance.enrollmentProgressed(0.6666666667, hints);
 
233
            wait(200)
 
234
        }
 
235
    }
 
236
}