~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_Fingerprints.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.Test 0.1
 
22
import Ubuntu.Settings.Fingerprint 0.1
 
23
import Biometryd 0.0
 
24
import GSettings 1.0
 
25
 
 
26
Item {
 
27
    id: testRoot
 
28
    width: units.gu(50)
 
29
    height: units.gu(90)
 
30
 
 
31
    Component {
 
32
        id: fingerprintsComponent
 
33
 
 
34
        Fingerprints {
 
35
            anchors.fill: parent
 
36
        }
 
37
    }
 
38
 
 
39
    SignalSpy {
 
40
        id: spy
 
41
    }
 
42
 
 
43
    UbuntuTestCase {
 
44
        name: "FingerprintPanel"
 
45
        when: windowShown
 
46
 
 
47
        property var fingerprintsInstance: null
 
48
 
 
49
        function init() {
 
50
            Biometryd.setAvailable(true);
 
51
            fingerprintsInstance = fingerprintsComponent.createObject(testRoot);
 
52
        }
 
53
 
 
54
        function cleanup() {
 
55
            spy.clear();
 
56
            spy.target = null;
 
57
            spy.signalName = "";
 
58
            fingerprintsInstance.destroy();
 
59
            GSettingsController.setFingerprintNames({});
 
60
        }
 
61
 
 
62
        function getClearanceObserver() {
 
63
            return findInvisibleChild(fingerprintsInstance, "clearanceObserver");
 
64
        }
 
65
 
 
66
        function getListObserver() {
 
67
            return findInvisibleChild(fingerprintsInstance, "listObserver");
 
68
        }
 
69
 
 
70
        function getEnrollmentObserver() {
 
71
            return findInvisibleChild(fingerprintsInstance, "enrollmentObserver");
 
72
        }
 
73
 
 
74
        function getRemovalObserver() {
 
75
            return findInvisibleChild(fingerprintsInstance, "removalObserver");
 
76
        }
 
77
 
 
78
        function getBrokenDialog() {
 
79
            return findChild(testRoot, "fingerprintReaderBrokenDialog");
 
80
        }
 
81
 
 
82
        function getBrokenDialogOk() {
 
83
            return findChild(testRoot, "fingerprintReaderBrokenDialogOK");
 
84
        }
 
85
 
 
86
        function getAddFingerprintItem() {
 
87
            return findChild(fingerprintsInstance, "fingerprintAddListItemLayout");
 
88
        }
 
89
 
 
90
        function getRemoveAllButton() {
 
91
            return findChild(fingerprintsInstance, "fingerprintRemoveAllButton");
 
92
        }
 
93
 
 
94
        function getFingerprintsList() {
 
95
            return findChild(fingerprintsInstance, "fingerprintsList");
 
96
        }
 
97
 
 
98
        function getSetupEntry() {
 
99
            return findChild(fingerprintsInstance, "fingerprintSetupEntry");
 
100
        }
 
101
 
 
102
        function test_failures_data() {
 
103
            return [
 
104
                { tag: "clearance", observer: getClearanceObserver, mock: "mockClearance", mockArgs: ["failed"] },
 
105
                { tag: "list", observer: getListObserver, mock: "mockList", mockArgs: [[], "failed"] }
 
106
            ]
 
107
        }
 
108
 
 
109
        function test_failures(data) {
 
110
            var obs = data.observer();
 
111
            spy.signalName = "failed";
 
112
            spy.target = obs;
 
113
            obs[data.mock].apply(null, data.mockArgs);
 
114
            spy.wait();
 
115
            var errorDiag = getBrokenDialog();
 
116
            var ok = getBrokenDialogOk();
 
117
            mouseClick(ok, ok.width / 2, ok.height / 2);
 
118
 
 
119
            // Halt testing until dialog has been destroyed.
 
120
            tryCompareFunction(function() {
 
121
                return getBrokenDialog();
 
122
            }, null);
 
123
        }
 
124
 
 
125
        function test_noPasscode() {
 
126
            fingerprintsInstance.passcodeSet = false;
 
127
            compare(fingerprintsInstance.state, "noPasscode");
 
128
 
 
129
            var setButton = findChild(fingerprintsInstance, "fingerprintSetPasscodeButton");
 
130
            compare(setButton.visible, true);
 
131
 
 
132
            var setupEntry = getSetupEntry();
 
133
            compare(setupEntry.enabled, false);
 
134
 
 
135
            var fingerprintsList = getFingerprintsList();
 
136
            compare(fingerprintsList.enabled, false);
 
137
        }
 
138
 
 
139
        function test_noScanner() {
 
140
            fingerprintsInstance.passcodeSet = true;
 
141
            Biometryd.setAvailable(false);
 
142
            compare(fingerprintsInstance.state, "noScanner");
 
143
 
 
144
            var addItem = getAddFingerprintItem();
 
145
            compare(addItem.enabled, false);
 
146
 
 
147
            var removeButton = getRemoveAllButton();
 
148
            compare(removeButton.enabled, false);
 
149
 
 
150
            var fingerprintsList = getFingerprintsList();
 
151
            compare(fingerprintsList.visible, false);
 
152
        }
 
153
 
 
154
        function test_passcode() {
 
155
            fingerprintsInstance.passcodeSet = true;
 
156
            compare(fingerprintsInstance.state, "");
 
157
            var setButton = findChild(fingerprintsInstance, "fingerprintSetPasscodeButton");
 
158
            compare(setButton.visible, false);
 
159
            var setupEntry = getSetupEntry();
 
160
            compare(setupEntry.enabled, true);
 
161
        }
 
162
 
 
163
        function test_changePasscode() {
 
164
            fingerprintsInstance.passcodeSet = false;
 
165
            var setButton = findChild(fingerprintsInstance, "fingerprintSetPasscodeButton");
 
166
 
 
167
            spy.signalName = "requestPasscode"
 
168
            spy.target = fingerprintsInstance;
 
169
            mouseClick(setButton, setButton.width / 2, setButton.height / 2);
 
170
            spy.wait();
 
171
 
 
172
            compare(spy.count, 1);
 
173
        }
 
174
 
 
175
        function test_setup() {
 
176
            fingerprintsInstance.passcodeSet = false;
 
177
            var add = getAddFingerprintItem();
 
178
            var remove = getRemoveAllButton();
 
179
            compare(add.enabled, false);
 
180
            compare(remove.enabled, false);
 
181
        }
 
182
 
 
183
        function test_noRemove() {
 
184
            fingerprintsInstance.passcodeSet = true;
 
185
            GSettingsController.setFingerprintNames({});
 
186
            var remove = getRemoveAllButton();
 
187
            compare(remove.enabled, false);
 
188
        }
 
189
 
 
190
        function test_remove() {
 
191
            fingerprintsInstance.passcodeSet = true;
 
192
            GSettingsController.setFingerprintNames({"tmplId": "A Finger"});
 
193
 
 
194
            var remove = getRemoveAllButton();
 
195
            mouseClick(remove, remove.width / 2, remove.height / 2);
 
196
            var diag = findChild(testRoot, "fingerprintRemoveAllDialog");
 
197
            var confirm = findChild(diag, "fingerprintRemoveAllConfirmationButton");
 
198
            compare(confirm.visible, true);
 
199
            mouseClick(confirm, confirm.width / 2, confirm.height / 2);
 
200
 
 
201
            var obs = getClearanceObserver();
 
202
            spy.signalName = "succeeded";
 
203
            spy.target = obs;
 
204
            obs.mockClearance("");
 
205
            spy.wait();
 
206
            compare(spy.count, 1);
 
207
 
 
208
            // Wait for dialog destruction (which is required for other tests)
 
209
            // to function.
 
210
            tryCompareFunction(function() {
 
211
                return findChild(testRoot, "fingerprintRemoveAllDialog");
 
212
            }, null);
 
213
        }
 
214
 
 
215
        function test_enrollmentSucceeded() {
 
216
            var obs = getEnrollmentObserver();
 
217
            var targetFingerprintName = i18n.dtr("ubuntu-settings-components", "Finger %1").arg(1);
 
218
            spy.signalName = "succeeded";
 
219
            spy.target = obs;
 
220
            obs.mockEnroll("tmplId", "");
 
221
            spy.wait();
 
222
            compare(spy.count, 1);
 
223
            compare(spy.signalArguments[0][0], "tmplId");
 
224
 
 
225
            tryCompareFunction(function() {
 
226
                return GSettingsController.fingerprintNames()["tmplId"];
 
227
            }, targetFingerprintName);
 
228
        }
 
229
    }
 
230
}