2
* Copyright 2013 Canonical Ltd.
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.
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.
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/>.
20
import "../../../Greeter"
21
import Ubuntu.Components 0.1
22
import LightDM 0.1 as LightDM
23
import Unity.Test 0.1 as UT
37
signalName: "unlocked"
43
signalName: "selected"
50
function select_index(i) {
51
// We could be anywhere in list; find target index to know which direction
52
var userlist = findChild(greeter, "userList")
53
if (userlist.currentIndex == i)
54
keyClick(Qt.Key_Escape) // Reset state if we're not moving
55
while (userlist.currentIndex != i) {
56
var next = userlist.currentIndex + 1
57
if (userlist.currentIndex > i) {
58
next = userlist.currentIndex - 1
60
var account = findChild(greeter, "username"+next)
61
mouseClick(account, 1, 1)
62
tryCompare(userlist, "currentIndex", next)
63
tryCompare(userlist, "movingInternally", false)
67
function select_user(name) {
68
// We could be anywhere in list; find target index to know which direction
69
for (var i = 0; i < greeter.model.count; i++) {
70
if (greeter.model.data(i, LightDM.UserRoles.NameRole) == name) {
74
if (i == greeter.model.count) {
75
fail("Didn't find name")
82
function test_properties() {
83
compare(greeter.multiUser, true)
84
compare(greeter.narrowMode, false)
87
function test_cycle_data() {
88
var data = new Array()
89
for (var i = 0; i < greeter.model.count; i++) {
90
data[i] = {tag: greeter.model.data(i, LightDM.UserRoles.NameRole), uid: i }
95
function test_cycle(data) {
97
var userList = findChild(greeter, "userList")
98
var waitForSignal = data.uid != 0 && userList.currentIndex != data.uid
99
select_index(data.uid)
100
tryCompare(userList, "currentIndex", data.uid)
101
tryCompare(greeter, "locked", data.tag !== "no-password" &&
102
data.tag !== "auth-error")
105
tryCompare(selectionSpy, "count", 1)
109
function test_unlock_password() {
110
select_user("no-password") // to guarantee a selected signal
112
select_user("has-password")
113
var passwordInput = findChild(greeter, "passwordInput")
114
tryCompare(passwordInput, "opacity", 1)
115
mouseClick(passwordInput, 1, 1)
116
compare(unlockSpy.count, 0)
117
typeString("password")
118
keyClick(Qt.Key_Enter)
122
function test_unlock_wrong_password() {
123
select_user("no-password") // to guarantee a selected signal
125
select_user("has-password")
126
wait(0) // spin event loop to start any pending animations
127
var passwordInput = findChild(greeter, "passwordInput")
128
tryCompare(passwordInput, "opacity", 1) // wait for opacity animation to be finished
129
mouseClick(passwordInput, 1, 1)
130
compare(unlockSpy.count, 0)
131
typeString("wr0ng p4ssw0rd")
132
keyClick(Qt.Key_Enter)
133
compare(unlockSpy.count, 0)
136
function test_unlock_no_password() {
138
select_user("no-password")
139
var passwordInput = findChild(greeter, "passwordInput")
140
tryCompare(passwordInput, "opacity", 1)
141
mouseClick(passwordInput, 1, 1)
143
compare(unlockSpy.count, 1)
146
function test_empty_name() {
147
for (var i = 0; i < greeter.model.count; i++) {
148
if (greeter.model.data(i, LightDM.UserRoles.NameRole) == "empty-name") {
149
compare(greeter.model.data(i, LightDM.UserRoles.RealNameRole), greeter.model.data(i, LightDM.UserRoles.NameRole))
153
fail("Didn't find empty-name")
156
function test_auth_error() {
157
select_user("auth-error")
158
var passwordInput = findChild(greeter, "passwordInput")
159
tryCompare(passwordInput, "placeholderText", "Retry")
162
function test_different_prompt() {
163
select_user("different-prompt")
164
var passwordInput = findChild(greeter, "passwordInput")
165
tryCompare(passwordInput, "placeholderText", "Secret word")
168
function test_no_response() {
170
select_user("no-response")
171
var passwordInput = findChild(greeter, "passwordInput")
172
tryCompare(passwordInput, "opacity", 1)
173
mouseClick(passwordInput, 1, 1)
174
compare(unlockSpy.count, 0)
175
typeString("password")
176
keyClick(Qt.Key_Enter)
177
tryCompare(passwordInput, "enabled", false)
178
keyClick(Qt.Key_Escape)
179
tryCompare(passwordInput, "enabled", true)
180
compare(unlockSpy.count, 0)
183
function test_two_factor_correct() {
185
select_user("two-factor")
186
var passwordInput = findChild(greeter, "passwordInput")
187
tryCompare(passwordInput, "opacity", 1)
188
tryCompare(passwordInput, "echoMode", TextInput.Password)
189
tryCompare(passwordInput, "placeholderText", "Password")
190
mouseClick(passwordInput, 1, 1)
191
compare(unlockSpy.count, 0)
192
typeString("password")
193
keyClick(Qt.Key_Enter)
194
tryCompare(passwordInput, "echoMode", TextInput.Normal)
195
tryCompare(passwordInput, "placeholderText", "otp")
196
tryCompare(passwordInput, "enabled", true)
198
keyClick(Qt.Key_Enter)
202
function test_two_factor_wrong1() {
204
select_user("two-factor")
205
var passwordInput = findChild(greeter, "passwordInput")
206
tryCompare(passwordInput, "opacity", 1)
207
tryCompare(passwordInput, "placeholderText", "Password")
208
mouseClick(passwordInput, 1, 1)
209
compare(unlockSpy.count, 0)
210
typeString("wr0ng p4ssw0rd")
211
keyClick(Qt.Key_Enter)
212
tryCompare(passwordInput, "placeholderText", "Password")
213
tryCompare(passwordInput, "enabled", true)
214
compare(unlockSpy.count, 0)
217
function test_two_factor_wrong2() {
219
select_user("two-factor")
220
var passwordInput = findChild(greeter, "passwordInput")
221
tryCompare(passwordInput, "opacity", 1)
222
tryCompare(passwordInput, "placeholderText", "Password")
223
mouseClick(passwordInput, 1, 1)
224
compare(unlockSpy.count, 0)
225
typeString("password")
226
keyClick(Qt.Key_Enter)
227
tryCompare(passwordInput, "placeholderText", "otp")
228
tryCompare(passwordInput, "enabled", true)
229
typeString("wr0ng p4ssw0rd")
230
keyClick(Qt.Key_Enter)
231
tryCompare(passwordInput, "placeholderText", "Password")
232
tryCompare(passwordInput, "enabled", true)
233
compare(unlockSpy.count, 0)
236
function test_unicode() {
237
var index = select_user("unicode")
238
var label = findChild(greeter, "username"+index)
239
tryCompare(label, "text", "가나다라마")
242
function test_long_name() {
243
var index = select_user("long-name")
244
var label = findChild(greeter, "username"+index)
245
tryCompare(label, "truncated", true)
248
function test_info_prompt() {
249
select_user("info-prompt")
250
var label = findChild(greeter, "infoLabel")
251
tryCompare(label, "text", "Welcome to Unity Greeter")
252
tryCompare(label, "opacity", 1)
253
tryCompare(label, "clip", true)
254
tryCompareFunction(function() {return label.contentWidth > label.width;}, false) // c.f. wide-info-prompt
255
var passwordInput = findChild(greeter, "passwordInput")
256
mouseClick(passwordInput, 1, 1)
257
keyClick(Qt.Key_Escape)
260
function test_info_prompt_escape() {
261
select_user("info-prompt")
262
var passwordInput = findChild(greeter, "passwordInput")
263
mouseClick(passwordInput, 1, 1)
264
keyClick(Qt.Key_Escape)
265
var label = findChild(greeter, "infoLabel")
266
tryCompare(label, "text", "Welcome to Unity Greeter")
267
tryCompare(label, "opacity", 1)
270
function test_wide_info_prompt() {
271
select_user("wide-info-prompt")
272
var label = findChild(greeter, "infoLabel")
273
tryCompare(label, "clip", true)
274
tryCompareFunction(function() {return label.contentWidth > label.width;}, true)
277
function test_html_info_prompt() {
278
select_user("html-info-prompt")
279
var label = findChild(greeter, "infoLabel")
280
tryCompare(label, "text", "<b>&</b>")
283
function test_long_info_prompt() {
284
select_user("long-info-prompt")
285
var label = findChild(greeter, "infoLabel")
286
tryCompare(label, "text", "Welcome to Unity Greeter<br><br>We like to annoy you with super ridiculously long messages.<br>Like this one<br><br>This is the last line of a multiple line message.")
287
tryCompare(label, "textFormat", Text.StyledText) // for parsing above correctly
288
tryCompare(label, "clip", true)
289
tryCompareFunction(function() {return label.contentWidth > label.width;}, true)
292
function test_multi_info_prompt() {
293
select_user("multi-info-prompt")
294
var label = findChild(greeter, "infoLabel")
295
tryCompare(label, "text", "Welcome to Unity Greeter<br><font color=\"#df382c\">This is an error</font><br>You should have seen three messages")
296
tryCompare(label, "textFormat", Text.StyledText) // for parsing above correctly
299
function test_bg_color() {
300
var index = select_user("color-background")
301
compare(greeter.model.data(index, LightDM.UserRoles.BackgroundPathRole), "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#dd4814'/></svg>")
304
function test_bg_none() {
305
var index = select_user("no-background")
306
compare(greeter.model.data(index, LightDM.UserRoles.BackgroundPathRole), "")