@@ -1,475 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
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.
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 General Public License for more details.
12− *
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/>.
15− */
16−
17−import QtQuick 2.0
18−import QtQuick.Layouts 1.1
19−import QtTest 1.0
20−import ".."
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
25−
26−Item {
27− id: root
28− width: units.gu(140)
29− height: units.gu(80)
30−
31− QtObject {
32− id: fakeInputMethod
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
39− }
40− }
41−
42− Binding {
43− target: LightDM.Greeter
44− property: "mockMode"
45− value: "full"
46− }
47− Binding {
48− target: LightDM.Users
49− property: "mockMode"
50− value: "full"
51− }
52−
53− Greeter {
54− id: greeter
55− width: units.gu(120)
56− height: root.height
57− inputMethod: fakeInputMethod
58− locked: !LightDM.Greeter.authenticated
59− }
60−
61− Component {
62− id: greeterComponent
63− Greeter {
64− SignalSpy {
65− objectName: "selectedSpy"
66− target: parent
67− signalName: "selected"
68− }
69− }
70− }
71−
72− Rectangle {
73− id: fakeKeyboard
74− color: "green"
75− opacity: 0.7
76− anchors.bottom: root.bottom
77− width: greeter.width
78− height: greeter.height * 0.6
79− visible: keyboardVisibleCheckbox.checked
80− Text {
81− text: "Keyboard Rectangle"
82− color: "yellow"
83− font.bold: true
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
89− width: parent.width
90− height: parent.height
91− }
92− }
93−
94− Item {
95− anchors {
96− top: root.top
97− bottom: root.bottom
98− left: greeter.right
99− right: root.right
100− }
101− RowLayout {
102− Layout.fillWidth: true
103− CheckBox {
104− id: keyboardVisibleCheckbox
105− }
106− Label { text: "Keyboard Visible"; anchors.verticalCenter: parent.verticalCenter }
107− }
108− }
109−
110− SignalSpy {
111− id: unlockSpy
112− target: greeter
113− signalName: "unlocked"
114− }
115−
116− SignalSpy {
117− id: selectionSpy
118− target: greeter
119− signalName: "selected"
120− }
121−
122− SignalSpy {
123− id: tappedSpy
124− target: greeter
125− signalName: "tapped"
126− }
127−
128− UT.UnityTestCase {
129− name: "MultiGreeter"
130− when: windowShown
131−
132− function cleanup() {
133− keyboardVisibleCheckbox.checked = false;
134− }
135−
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
145− }
146− var account = findChild(greeter, "username"+next)
147− mouseClick(account, 1, 1)
148− tryCompare(userlist, "currentIndex", next)
149− tryCompare(userlist, "movingInternally", false)
150− }
151− }
152−
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) {
157− break
158− }
159− }
160− if (i == greeter.model.count) {
161− fail("Didn't find name")
162− return -1
163− }
164− select_index(i)
165− return i
166− }
167−
168− function test_properties() {
169− compare(greeter.multiUser, true)
170− compare(greeter.narrowMode, false)
171− }
172−
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 }
177− }
178− return data
179− }
180−
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")
188− if (waitForSignal) {
189− selectionSpy.wait()
190− tryCompare(selectionSpy, "count", 1)
191− }
192− }
193−
194− function test_unlock_password() {
195− select_user("no-password") // to guarantee a selected signal
196− unlockSpy.clear()
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)
204− unlockSpy.wait()
205− }
206−
207− function test_unlock_wrong_password() {
208− select_user("no-password") // to guarantee a selected signal
209− unlockSpy.clear()
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)
219− }
220−
221− function test_unlock_no_password() {
222− unlockSpy.clear()
223− select_user("no-password")
224− var passwordInput = findChild(greeter, "passwordInput")
225− tryCompare(passwordInput, "opacity", 1)
226− mouseClick(passwordInput, 1, 1)
227− unlockSpy.wait()
228− compare(unlockSpy.count, 1)
229− }
230−
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))
235− return
236− }
237− }
238− fail("Didn't find empty-name")
239− }
240−
241− function test_auth_error() {
242− select_user("auth-error")
243− var passwordInput = findChild(greeter, "passwordInput")
244− tryCompare(passwordInput, "placeholderText", "Retry")
245− }
246−
247− function test_different_prompt() {
248− select_user("different-prompt")
249− var passwordInput = findChild(greeter, "passwordInput")
250− tryCompare(passwordInput, "placeholderText", "Secret word")
251− }
252−
253− function test_no_response() {
254− unlockSpy.clear()
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)
266− }
267−
268− function test_two_factor_correct() {
269− unlockSpy.clear()
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)
282− typeString("otp")
283− keyClick(Qt.Key_Enter)
284− unlockSpy.wait()
285− }
286−
287− function test_two_factor_wrong1() {
288− unlockSpy.clear()
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)
300− }
301−
302− function test_two_factor_wrong2() {
303− unlockSpy.clear()
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)
319− }
320−
321− function test_unicode() {
322− var index = select_user("unicode")
323− var label = findChild(greeter, "username"+index)
324− tryCompare(label, "text", "가나다라마")
325− }
326−
327− function test_long_name() {
328− var index = select_user("long-name")
329− var label = findChild(greeter, "username"+index)
330− tryCompare(label, "truncated", true)
331− }
332−
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)
343− }
344−
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)
353− }
354−
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)
360− }
361−
362− function test_html_info_prompt() {
363− select_user("html-info-prompt")
364− var label = findChild(greeter, "infoLabel")
365− tryCompare(label, "text", "<b>&</b>")
366− }
367−
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)
375− }
376−
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
382− }
383−
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>")
387− }
388−
389− function test_bg_none() {
390− var index = select_user("no-background")
391− compare(greeter.model.data(index, LightDM.UserRoles.BackgroundPathRole), "")
392− }
393−
394− function test_tappedSignal_data() {
395− return [
396− {tag: "left", posX: units.gu(2)},
397− {tag: "right", posX: greeter.width - units.gu(2)}
398− ]
399− }
400−
401− function test_tappedSignal(data) {
402− select_user("no-password");
403− tappedSpy.clear();
404− tap(greeter, data.posX, greeter.height - units.gu(1))
405− tryCompare(tappedSpy, "count", 1)
406− }
407−
408− function test_teaseLockedUnlocked_data() {
409− return [
410− {tag: "unlocked", locked: false, narrow: false},
411− {tag: "locked", locked: true, narrow: false},
412− ];
413− }
414−
415− function test_teaseLockedUnlocked(data) {
416− tappedSpy.clear()
417− greeter.locked = data.locked;
418−
419− tap(greeter, greeter.width - units.gu(5), greeter.height - units.gu(1));
420−
421− if (!data.locked || data.narrow) {
422− tappedSpy.wait()
423− tryCompare(tappedSpy, "count", 1);
424− } else {
425− // waiting 100ms to make sure nothing happens
426− wait(100);
427− compare(tappedSpy.count, 0, "Greeter teasing not disabled even though it's locked.");
428− }
429−
430− // Reset value
431− greeter.locked = false;
432− }
433−
434− function test_dbus_set_active_entry() {
435− select_user("no-password") // to guarantee a selected signal
436− selectionSpy.clear()
437− LightDM.Greeter.requestAuthenticationUser("has-password")
438−
439− selectionSpy.wait()
440− tryCompare(selectionSpy, "count", 1)
441−
442− var userlist = findChild(greeter, "userList")
443− compare(greeter.model.data(userlist.currentIndex, LightDM.UserRoles.NameRole), "has-password")
444− }
445−
446− function test_initial_selected_signal() {
447− var greeterObj = greeterComponent.createObject(this)
448− var spy = findChild(greeterObj, "selectedSpy")
449− spy.wait()
450− tryCompare(spy, "count", 1)
451− greeterObj.destroy()
452− }
453−
454− function test_login_list_not_covered_by_keyboard() {
455− var loginList = findChild(greeter, "loginLoader").item;
456− compare(loginList.height, greeter.height);
457−
458− // when the vkb shows up, loginList is moved up to remain fully uncovered
459−
460− keyboardVisibleCheckbox.checked = true;
461−
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;
466− }, true);
467−
468− // once the vkb goes away, loginList goes back to its full height
469−
470− keyboardVisibleCheckbox.checked = false;
471−
472− tryCompare(loginList, "height", greeter.height);
473− }
474− }
475−}