@@ -1,278 +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 QtTest 1.0
19−import ".."
20−import "../../../qml/Greeter"
21−import Ubuntu.Components 0.1
22−import LightDM 0.1 as LightDM
23−import Unity.Test 0.1 as UT
24−
25−Item {
26− width: units.gu(120)
27− height: units.gu(80)
28−
29− Greeter {
30− id: greeter
31− anchors.fill: parent
32− tabletMode: true
33− }
34−
35− Component {
36− id: greeterComponent
37− Greeter {
38− SignalSpy {
39− objectName: "selectedSpy"
40− target: parent
41− signalName: "selected"
42− }
43− }
44− }
45−
46− SignalSpy {
47− id: unlockSpy
48− target: greeter
49− signalName: "unlocked"
50− }
51−
52− SignalSpy {
53− id: selectionSpy
54− target: greeter
55− signalName: "selected"
56− }
57−
58− SignalSpy {
59− id: tappedSpy
60− target: greeter
61− signalName: "tapped"
62− }
63−
64− UT.UnityTestCase {
65− name: "MultiGreeter"
66− when: windowShown
67−
68− function select_index(i) {
69− // We could be anywhere in list; find target index to know which direction
70− var userlist = findChild(greeter, "userList")
71− if (userlist.currentIndex == i)
72− keyClick(Qt.Key_Escape) // Reset state if we're not moving
73− while (userlist.currentIndex != i) {
74− var next = userlist.currentIndex + 1
75− if (userlist.currentIndex > i) {
76− next = userlist.currentIndex - 1
77− }
78− var account = findChild(greeter, "username"+next)
79− mouseClick(account, 1, 1)
80− tryCompare(userlist, "currentIndex", next)
81− tryCompare(userlist, "movingInternally", false)
82− }
83− }
84−
85− function select_user(name) {
86− // We could be anywhere in list; find target index to know which direction
87− for (var i = 0; i < LightDM.Users.count; i++) {
88− if (LightDM.Users.data(i, LightDM.UserRoles.NameRole) == name) {
89− break
90− }
91− }
92− if (i == LightDM.Users.count) {
93− fail("Didn't find name")
94− return -1
95− }
96− select_index(i)
97− return i
98− }
99−
100− function test_properties() {
101− compare(greeter.multiUser, true)
102− compare(greeter.narrowMode, false)
103− }
104−
105− function test_cycle_data() {
106− var data = new Array()
107− for (var i = 0; i < LightDM.Users.count; i++) {
108− data[i] = {tag: LightDM.Users.data(i, LightDM.UserRoles.NameRole), uid: i }
109− }
110− return data
111− }
112−
113− function test_cycle(data) {
114− selectionSpy.clear();
115− var userList = findChild(greeter, "userList")
116− var waitForSignal = data.uid != 0 && userList.currentIndex != data.uid
117− select_index(data.uid)
118− tryCompare(userList, "currentIndex", data.uid)
119− tryCompare(greeter, "locked", data.tag !== "no-password")
120− if (waitForSignal) {
121− selectionSpy.wait()
122− tryCompare(selectionSpy, "count", 1)
123− }
124− }
125−
126− function test_unlock_password() {
127− select_user("no-password") // to guarantee a selected signal
128− unlockSpy.clear()
129− select_user("has-password")
130− var passwordInput = findChild(greeter, "passwordInput")
131− tryCompare(passwordInput, "opacity", 1)
132− mouseClick(passwordInput, 1, 1)
133− compare(unlockSpy.count, 0)
134− typeString("password")
135− keyClick(Qt.Key_Enter)
136− unlockSpy.wait()
137− }
138−
139− function test_unlock_wrong_password() {
140− select_user("no-password") // to guarantee a selected signal
141− unlockSpy.clear()
142− select_user("has-password")
143− wait(0) // spin event loop to start any pending animations
144− var passwordInput = findChild(greeter, "passwordInput")
145− tryCompare(passwordInput, "opacity", 1) // wait for opacity animation to be finished
146− mouseClick(passwordInput, 1, 1)
147− compare(unlockSpy.count, 0)
148− typeString("wr0ng p4ssw0rd")
149− keyClick(Qt.Key_Enter)
150− compare(unlockSpy.count, 0)
151− }
152−
153− function test_unlock_no_password() {
154− unlockSpy.clear()
155− select_user("no-password")
156− var passwordInput = findChild(greeter, "passwordInput")
157− tryCompare(passwordInput, "opacity", 1)
158− mouseClick(passwordInput, 1, 1)
159− unlockSpy.wait()
160− compare(unlockSpy.count, 1)
161− }
162−
163− function test_no_response() {
164− unlockSpy.clear()
165− select_user("no-response")
166− var passwordInput = findChild(greeter, "passwordInput")
167− tryCompare(passwordInput, "opacity", 1)
168− mouseClick(passwordInput, 1, 1)
169− compare(unlockSpy.count, 0)
170− typeString("password")
171− keyClick(Qt.Key_Enter)
172− tryCompare(passwordInput, "enabled", false)
173− keyClick(Qt.Key_Escape)
174− tryCompare(passwordInput, "enabled", true)
175− compare(unlockSpy.count, 0)
176− }
177−
178− function test_two_factor_correct() {
179− unlockSpy.clear()
180− select_user("two-factor")
181− var passwordInput = findChild(greeter, "passwordInput")
182− tryCompare(passwordInput, "opacity", 1)
183− tryCompare(passwordInput, "echoMode", TextInput.Password)
184− tryCompare(passwordInput, "placeholderText", "Password")
185− mouseClick(passwordInput, 1, 1)
186− compare(unlockSpy.count, 0)
187− typeString("password")
188− keyClick(Qt.Key_Enter)
189− tryCompare(passwordInput, "echoMode", TextInput.Normal)
190− tryCompare(passwordInput, "placeholderText", "otp")
191− tryCompare(passwordInput, "enabled", true)
192− typeString("otp")
193− keyClick(Qt.Key_Enter)
194− unlockSpy.wait()
195− }
196−
197− function test_info_prompt() {
198− select_user("info-prompt")
199− var label = findChild(greeter, "infoLabel")
200− tryCompare(label, "text", "Welcome to Unity Greeter")
201− tryCompare(label, "opacity", 1)
202− tryCompare(label, "clip", true)
203− tryCompareFunction(function() {return label.contentWidth > label.width;}, false) // c.f. wide-info-prompt
204− var passwordInput = findChild(greeter, "passwordInput")
205− mouseClick(passwordInput, 1, 1)
206− keyClick(Qt.Key_Escape)
207− }
208−
209− function test_info_prompt_escape() {
210− select_user("info-prompt")
211− var passwordInput = findChild(greeter, "passwordInput")
212− mouseClick(passwordInput, 1, 1)
213− keyClick(Qt.Key_Escape)
214− var label = findChild(greeter, "infoLabel")
215− tryCompare(label, "text", "Welcome to Unity Greeter")
216− tryCompare(label, "opacity", 1)
217− }
218−
219− function test_wide_info_prompt() {
220− select_user("wide-info-prompt")
221− var label = findChild(greeter, "infoLabel")
222− tryCompare(label, "clip", true)
223− tryCompareFunction(function() {return label.contentWidth > label.width;}, true)
224− }
225−
226− function test_html_info_prompt() {
227− select_user("html-info-prompt")
228− var label = findChild(greeter, "infoLabel")
229− tryCompare(label, "text", "<b>&</b>")
230− }
231−
232− function test_long_info_prompt() {
233− select_user("long-info-prompt")
234− var label = findChild(greeter, "infoLabel")
235− 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.")
236− tryCompare(label, "textFormat", Text.StyledText) // for parsing above correctly
237− tryCompare(label, "clip", true)
238− tryCompareFunction(function() {return label.contentWidth > label.width;}, true)
239− }
240−
241− function test_multi_info_prompt() {
242− select_user("multi-info-prompt")
243− var label = findChild(greeter, "infoLabel")
244− tryCompare(label, "text", "Welcome to Unity Greeter<br><font color=\"#df382c\">This is an error</font><br>You should have seen three messages")
245− tryCompare(label, "textFormat", Text.StyledText) // for parsing above correctly
246− }
247−
248− function test_bg_color() {
249− var index = select_user("color-background")
250− compare(LightDM.Users.data(index, LightDM.UserRoles.BackgroundPathRole), "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#dd4814'/></svg>")
251− }
252−
253− function test_bg_none() {
254− var index = select_user("no-background")
255− compare(LightDM.Users.data(index, LightDM.UserRoles.BackgroundPathRole), "")
256− }
257−
258− function test_dbus_set_active_entry() {
259− select_user("no-password") // to guarantee a selected signal
260− selectionSpy.clear()
261− LightDM.Greeter.requestAuthenticationUser("has-password")
262−
263− selectionSpy.wait()
264− tryCompare(selectionSpy, "count", 1)
265−
266− var userlist = findChild(greeter, "userList")
267− compare(LightDM.Users.data(userlist.currentIndex, LightDM.UserRoles.NameRole), "has-password")
268− }
269−
270− function test_initial_selected_signal() {
271− var greeterObj = greeterComponent.createObject(this)
272− var spy = findChild(greeterObj, "selectedSpy")
273− spy.wait()
274− tryCompare(spy, "count", 1)
275− greeterObj.destroy()
276− }
277− }
278−}