2
* Copyright 2016 Canonical Ltd.
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.
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.
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/>.
16
* Authored by Jonas G. Drange <jonas.drange@canonical.com>
21
import Ubuntu.Components 1.3
22
import Ubuntu.Settings.Fingerprint 0.1
23
import Ubuntu.Test 0.1
46
signalName: "slideCompleted"
50
id: enrollmentObserverProgressedSpy
51
signalName: "progressed"
55
id: enrollmentObserverSucceededSpy
56
signalName: "succeeded"
60
id: enrollmentObserverFailedSpy
65
name: "FingerprintSetup"
68
property var setupInstance: null
71
Biometryd.setAvailable(true);
72
setupInstance = setupComponent.createObject(testRoot);
73
pageStack.push(setupInstance);
75
statusLabelSpy.target = getStatusLabel();
79
statusLabelSpy.clear();
82
setupInstance.destroy();
86
function getStatusLabel() {
87
return findChild(setupInstance, "fingerprintStatusLabel");
90
function getFailedVisual() {
91
return findChild(setupInstance, "fingerprintFailedVisual");
94
function getDefaultVisual() {
95
return findChild(setupInstance, "fingerprintDefaultVisual");
98
function getDoneVisual() {
99
return findChild(setupInstance, "fingerprintDoneVisual");
102
function getProgressLabel() {
103
return findChild(setupInstance, "fingerprintProgressLabel");
106
function test_initialState() {
107
var targetText = i18n.dtr("ubuntu-settings-components", "Swipe your finger over the reader.");
108
compare(getStatusLabel().text, targetText);
110
tryCompare(getDefaultVisual(), "opacity", 1);
111
tryCompare(getFailedVisual(), "opacity", 0);
112
tryCompare(getDoneVisual(), "opacity", 0);
115
function test_startedState() {
116
var targetText = i18n.dtr("ubuntu-settings-components", "Tap your finger repeatedly on the reader.");
117
setupInstance.enrollmentProgressed(0.5, {});
118
statusLabelSpy.wait();
119
compare(getStatusLabel().text, targetText);
121
tryCompare(getDefaultVisual(), "opacity", 1);
122
tryCompare(getFailedVisual(), "opacity", 0);
123
tryCompare(getDoneVisual(), "opacity", 0);
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);
131
tryCompare(getDefaultVisual(), "opacity", 0);
132
tryCompare(getFailedVisual(), "opacity", 1);
133
tryCompare(getDoneVisual(), "opacity", 0);
136
function test_successfulState() {
137
var targetText = i18n.dtr("ubuntu-settings-components", "All done!");
139
setupInstance.enrollmentCompleted();
140
compare(getStatusLabel().text, targetText);
142
tryCompare(getDefaultVisual(), "opacity", 0);
143
tryCompare(getFailedVisual(), "opacity", 0);
144
tryCompare(getDoneVisual(), "opacity", 1);
146
var button = findChild(pageStack, "fingerprintSetupDoneButton");
147
compare(button.enabled, true, "button was disabled when done");
150
function test_notDone() {
151
var button = findChild(pageStack, "fingerprintSetupDoneButton");
152
compare(button.enabled, false, "button was enabled initially");
155
function test_statusLabel() {
156
getStatusLabel().setText("foo");
157
statusLabelSpy.wait();
158
compare(getStatusLabel().text, "foo");
161
function test_direction_data() {
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 }}
176
function test_direction(data) {
177
var vis = findChild(setupInstance, "fingerprintDirectionVisual");
179
hints[FingerprintReader.suggestedNextDirection] = data.dir;
181
setupInstance.enrollmentProgressed(0.5, hints);
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);
188
function test_progressHidden() {
189
var pl = getProgressLabel();
190
compare(pl.opacity, 0);
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));
200
function test_progressReadable() {
201
setupInstance.enrollmentProgressed(0.6666666667, {});
202
tryCompare(getProgressLabel(), "text", i18n.dtr("ubuntu-settings-components", "%1%").arg(66));
205
// This is a visual test where we can confirm that the arrow
206
// rotates using the orthodromic distance.
207
function test_directions() {
210
hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.North;
211
setupInstance.enrollmentProgressed(0.6666666667, hints);
213
hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.East;
214
setupInstance.enrollmentProgressed(0.6666666667, hints);
216
hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.South;
217
setupInstance.enrollmentProgressed(0.6666666667, hints);
219
hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.West;
220
setupInstance.enrollmentProgressed(0.6666666667, hints);
222
hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.SouthEast;
223
setupInstance.enrollmentProgressed(0.6666666667, hints);
225
hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.NorthEast;
226
setupInstance.enrollmentProgressed(0.6666666667, hints);
228
hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.NorthWest;
229
setupInstance.enrollmentProgressed(0.6666666667, hints);
231
hints[FingerprintReader.suggestedNextDirection] = FingerprintReader.NorthEast;
232
setupInstance.enrollmentProgressed(0.6666666667, hints);