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/>.
18
import QtQuick.Layouts 1.1
21
import "../../../qml/Greeter"
22
import Ubuntu.Components 0.1
23
import LightDM 0.1 as LightDM
24
import Unity.Test 0.1 as UT
33
property bool visible: fakeKeyboard.visible
34
property var keyboardRectangle: QtObject {
35
property real x: fakeKeyboard.x
36
property real y: fakeKeyboard.y
37
property real width: fakeKeyboard.width
38
property real height: fakeKeyboard.height
43
target: LightDM.Greeter
57
inputMethod: fakeInputMethod
58
locked: !LightDM.Greeter.authenticated
65
objectName: "selectedSpy"
67
signalName: "selected"
76
anchors.bottom: root.bottom
78
height: greeter.height * 0.6
79
visible: keyboardVisibleCheckbox.checked
81
text: "Keyboard Rectangle"
84
fontSizeMode: Text.Fit
85
minimumPixelSize: 10; font.pixelSize: 200
86
verticalAlignment: Text.AlignVCenter
87
x: (parent.width - width) / 2
88
y: (parent.height - height) / 2
102
Layout.fillWidth: true
104
id: keyboardVisibleCheckbox
106
Label { text: "Keyboard Visible"; anchors.verticalCenter: parent.verticalCenter }
113
signalName: "unlocked"
119
signalName: "selected"
133
keyboardVisibleCheckbox.checked = false;
136
function select_index(i) {
137
// We could be anywhere in list; find target index to know which direction
138
var userlist = findChild(greeter, "userList")
139
if (userlist.currentIndex == i)
140
keyClick(Qt.Key_Escape) // Reset state if we're not moving
141
while (userlist.currentIndex != i) {
142
var next = userlist.currentIndex + 1
143
if (userlist.currentIndex > i) {
144
next = userlist.currentIndex - 1
146
var account = findChild(greeter, "username"+next)
147
mouseClick(account, 1, 1)
148
tryCompare(userlist, "currentIndex", next)
149
tryCompare(userlist, "movingInternally", false)
153
function select_user(name) {
154
// We could be anywhere in list; find target index to know which direction
155
for (var i = 0; i < greeter.model.count; i++) {
156
if (greeter.model.data(i, LightDM.UserRoles.NameRole) == name) {
160
if (i == greeter.model.count) {
161
fail("Didn't find name")
168
function test_properties() {
169
compare(greeter.multiUser, true)
170
compare(greeter.narrowMode, false)
173
function test_cycle_data() {
174
var data = new Array()
175
for (var i = 0; i < greeter.model.count; i++) {
176
data[i] = {tag: greeter.model.data(i, LightDM.UserRoles.NameRole), uid: i }
181
function test_cycle(data) {
182
selectionSpy.clear();
183
var userList = findChild(greeter, "userList")
184
var waitForSignal = data.uid != 0 && userList.currentIndex != data.uid
185
select_index(data.uid)
186
tryCompare(userList, "currentIndex", data.uid)
187
tryCompare(greeter, "locked", data.tag !== "no-password")
190
tryCompare(selectionSpy, "count", 1)
194
function test_unlock_password() {
195
select_user("no-password") // to guarantee a selected signal
197
select_user("has-password")
198
var passwordInput = findChild(greeter, "passwordInput")
199
tryCompare(passwordInput, "opacity", 1)
200
mouseClick(passwordInput, 1, 1)
201
compare(unlockSpy.count, 0)
202
typeString("password")
203
keyClick(Qt.Key_Enter)
207
function test_unlock_wrong_password() {
208
select_user("no-password") // to guarantee a selected signal
210
select_user("has-password")
211
wait(0) // spin event loop to start any pending animations
212
var passwordInput = findChild(greeter, "passwordInput")
213
tryCompare(passwordInput, "opacity", 1) // wait for opacity animation to be finished
214
mouseClick(passwordInput, 1, 1)
215
compare(unlockSpy.count, 0)
216
typeString("wr0ng p4ssw0rd")
217
keyClick(Qt.Key_Enter)
218
compare(unlockSpy.count, 0)
221
function test_unlock_no_password() {
223
select_user("no-password")
224
var passwordInput = findChild(greeter, "passwordInput")
225
tryCompare(passwordInput, "opacity", 1)
226
mouseClick(passwordInput, 1, 1)
228
compare(unlockSpy.count, 1)
231
function test_empty_name() {
232
for (var i = 0; i < greeter.model.count; i++) {
233
if (greeter.model.data(i, LightDM.UserRoles.NameRole) == "empty-name") {
234
compare(greeter.model.data(i, LightDM.UserRoles.RealNameRole), greeter.model.data(i, LightDM.UserRoles.NameRole))
238
fail("Didn't find empty-name")
241
function test_auth_error() {
242
select_user("auth-error")
243
var passwordInput = findChild(greeter, "passwordInput")
244
tryCompare(passwordInput, "placeholderText", "Retry")
247
function test_different_prompt() {
248
select_user("different-prompt")
249
var passwordInput = findChild(greeter, "passwordInput")
250
tryCompare(passwordInput, "placeholderText", "Secret word")
253
function test_no_response() {
255
select_user("no-response")
256
var passwordInput = findChild(greeter, "passwordInput")
257
tryCompare(passwordInput, "opacity", 1)
258
mouseClick(passwordInput, 1, 1)
259
compare(unlockSpy.count, 0)
260
typeString("password")
261
keyClick(Qt.Key_Enter)
262
tryCompare(passwordInput, "enabled", false)
263
keyClick(Qt.Key_Escape)
264
tryCompare(passwordInput, "enabled", true)
265
compare(unlockSpy.count, 0)
268
function test_two_factor_correct() {
270
select_user("two-factor")
271
var passwordInput = findChild(greeter, "passwordInput")
272
tryCompare(passwordInput, "opacity", 1)
273
tryCompare(passwordInput, "echoMode", TextInput.Password)
274
tryCompare(passwordInput, "placeholderText", "Password")
275
mouseClick(passwordInput, 1, 1)
276
compare(unlockSpy.count, 0)
277
typeString("password")
278
keyClick(Qt.Key_Enter)
279
tryCompare(passwordInput, "echoMode", TextInput.Normal)
280
tryCompare(passwordInput, "placeholderText", "otp")
281
tryCompare(passwordInput, "enabled", true)
283
keyClick(Qt.Key_Enter)
287
function test_two_factor_wrong1() {
289
select_user("two-factor")
290
var passwordInput = findChild(greeter, "passwordInput")
291
tryCompare(passwordInput, "opacity", 1)
292
tryCompare(passwordInput, "placeholderText", "Password")
293
mouseClick(passwordInput, 1, 1)
294
compare(unlockSpy.count, 0)
295
typeString("wr0ng p4ssw0rd")
296
keyClick(Qt.Key_Enter)
297
tryCompare(passwordInput, "placeholderText", "Password")
298
tryCompare(passwordInput, "enabled", true)
299
compare(unlockSpy.count, 0)
302
function test_two_factor_wrong2() {
304
select_user("two-factor")
305
var passwordInput = findChild(greeter, "passwordInput")
306
tryCompare(passwordInput, "opacity", 1)
307
tryCompare(passwordInput, "placeholderText", "Password")
308
mouseClick(passwordInput, 1, 1)
309
compare(unlockSpy.count, 0)
310
typeString("password")
311
keyClick(Qt.Key_Enter)
312
tryCompare(passwordInput, "placeholderText", "otp")
313
tryCompare(passwordInput, "enabled", true)
314
typeString("wr0ng p4ssw0rd")
315
keyClick(Qt.Key_Enter)
316
tryCompare(passwordInput, "placeholderText", "Password")
317
tryCompare(passwordInput, "enabled", true)
318
compare(unlockSpy.count, 0)
321
function test_unicode() {
322
var index = select_user("unicode")
323
var label = findChild(greeter, "username"+index)
324
tryCompare(label, "text", "가나다라마")
327
function test_long_name() {
328
var index = select_user("long-name")
329
var label = findChild(greeter, "username"+index)
330
tryCompare(label, "truncated", true)
333
function test_info_prompt() {
334
select_user("info-prompt")
335
var label = findChild(greeter, "infoLabel")
336
tryCompare(label, "text", "Welcome to Unity Greeter")
337
tryCompare(label, "opacity", 1)
338
tryCompare(label, "clip", true)
339
tryCompareFunction(function() {return label.contentWidth > label.width;}, false) // c.f. wide-info-prompt
340
var passwordInput = findChild(greeter, "passwordInput")
341
mouseClick(passwordInput, 1, 1)
342
keyClick(Qt.Key_Escape)
345
function test_info_prompt_escape() {
346
select_user("info-prompt")
347
var passwordInput = findChild(greeter, "passwordInput")
348
mouseClick(passwordInput, 1, 1)
349
keyClick(Qt.Key_Escape)
350
var label = findChild(greeter, "infoLabel")
351
tryCompare(label, "text", "Welcome to Unity Greeter")
352
tryCompare(label, "opacity", 1)
355
function test_wide_info_prompt() {
356
select_user("wide-info-prompt")
357
var label = findChild(greeter, "infoLabel")
358
tryCompare(label, "clip", true)
359
tryCompareFunction(function() {return label.contentWidth > label.width;}, true)
362
function test_html_info_prompt() {
363
select_user("html-info-prompt")
364
var label = findChild(greeter, "infoLabel")
365
tryCompare(label, "text", "<b>&</b>")
368
function test_long_info_prompt() {
369
select_user("long-info-prompt")
370
var label = findChild(greeter, "infoLabel")
371
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.")
372
tryCompare(label, "textFormat", Text.StyledText) // for parsing above correctly
373
tryCompare(label, "clip", true)
374
tryCompareFunction(function() {return label.contentWidth > label.width;}, true)
377
function test_multi_info_prompt() {
378
select_user("multi-info-prompt")
379
var label = findChild(greeter, "infoLabel")
380
tryCompare(label, "text", "Welcome to Unity Greeter<br><font color=\"#df382c\">This is an error</font><br>You should have seen three messages")
381
tryCompare(label, "textFormat", Text.StyledText) // for parsing above correctly
384
function test_bg_color() {
385
var index = select_user("color-background")
386
compare(greeter.model.data(index, LightDM.UserRoles.BackgroundPathRole), "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#dd4814'/></svg>")
389
function test_bg_none() {
390
var index = select_user("no-background")
391
compare(greeter.model.data(index, LightDM.UserRoles.BackgroundPathRole), "")
394
function test_tappedSignal_data() {
396
{tag: "left", posX: units.gu(2)},
397
{tag: "right", posX: greeter.width - units.gu(2)}
401
function test_tappedSignal(data) {
402
select_user("no-password");
404
tap(greeter, data.posX, greeter.height - units.gu(1))
405
tryCompare(tappedSpy, "count", 1)
408
function test_teaseLockedUnlocked_data() {
410
{tag: "unlocked", locked: false, narrow: false},
411
{tag: "locked", locked: true, narrow: false},
415
function test_teaseLockedUnlocked(data) {
417
greeter.locked = data.locked;
419
tap(greeter, greeter.width - units.gu(5), greeter.height - units.gu(1));
421
if (!data.locked || data.narrow) {
423
tryCompare(tappedSpy, "count", 1);
425
// waiting 100ms to make sure nothing happens
427
compare(tappedSpy.count, 0, "Greeter teasing not disabled even though it's locked.");
431
greeter.locked = false;
434
function test_dbus_set_active_entry() {
435
select_user("no-password") // to guarantee a selected signal
437
LightDM.Greeter.requestAuthenticationUser("has-password")
440
tryCompare(selectionSpy, "count", 1)
442
var userlist = findChild(greeter, "userList")
443
compare(greeter.model.data(userlist.currentIndex, LightDM.UserRoles.NameRole), "has-password")
446
function test_initial_selected_signal() {
447
var greeterObj = greeterComponent.createObject(this)
448
var spy = findChild(greeterObj, "selectedSpy")
450
tryCompare(spy, "count", 1)
454
function test_login_list_not_covered_by_keyboard() {
455
var loginList = findChild(greeter, "loginLoader").item;
456
compare(loginList.height, greeter.height);
458
// when the vkb shows up, loginList is moved up to remain fully uncovered
460
keyboardVisibleCheckbox.checked = true;
462
tryCompare(loginList, "height", greeter.height - fakeInputMethod.keyboardRectangle.height);
463
tryCompareFunction( function() {
464
var loginListRect = loginList.mapToItem(greeter, 0, 0, loginList.width, loginList.height);
465
return loginListRect.y + loginListRect.height <= fakeInputMethod.keyboardRectangle.y;
468
// once the vkb goes away, loginList goes back to its full height
470
keyboardVisibleCheckbox.checked = false;
472
tryCompare(loginList, "height", greeter.height);