~unity-team/unity8/ota9.5

« back to all changes in this revision

Viewing changes to tests/qmltests/Greeter/tst_Tablet.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "../../../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
    }
 
33
 
 
34
    SignalSpy {
 
35
        id: unlockSpy
 
36
        target: greeter
 
37
        signalName: "unlocked"
 
38
    }
 
39
 
 
40
    SignalSpy {
 
41
        id: selectionSpy
 
42
        target: greeter
 
43
        signalName: "selected"
 
44
    }
 
45
 
 
46
    UT.UnityTestCase {
 
47
        name: "Greeter"
 
48
        when: windowShown
 
49
 
 
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
 
59
                }
 
60
                var account = findChild(greeter, "username"+next)
 
61
                mouseClick(account, 1, 1)
 
62
                tryCompare(userlist, "currentIndex", next)
 
63
                tryCompare(userlist, "movingInternally", false)
 
64
            }
 
65
        }
 
66
 
 
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) {
 
71
                    break
 
72
                }
 
73
            }
 
74
            if (i == greeter.model.count) {
 
75
                fail("Didn't find name")
 
76
                return -1
 
77
            }
 
78
            select_index(i)
 
79
            return i
 
80
        }
 
81
 
 
82
        function test_properties() {
 
83
            compare(greeter.multiUser, true)
 
84
            compare(greeter.narrowMode, false)
 
85
        }
 
86
 
 
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 }
 
91
            }
 
92
            return data
 
93
        }
 
94
 
 
95
        function test_cycle(data) {
 
96
            selectionSpy.clear();
 
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")
 
103
            if (waitForSignal) {
 
104
                selectionSpy.wait()
 
105
                tryCompare(selectionSpy, "count", 1)
 
106
            }
 
107
        }
 
108
 
 
109
        function test_unlock_password() {
 
110
            select_user("no-password") // to guarantee a selected signal
 
111
            unlockSpy.clear()
 
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)
 
119
            unlockSpy.wait()
 
120
        }
 
121
 
 
122
        function test_unlock_wrong_password() {
 
123
            select_user("no-password") // to guarantee a selected signal
 
124
            unlockSpy.clear()
 
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)
 
134
        }
 
135
 
 
136
        function test_unlock_no_password() {
 
137
            unlockSpy.clear()
 
138
            select_user("no-password")
 
139
            var passwordInput = findChild(greeter, "passwordInput")
 
140
            tryCompare(passwordInput, "opacity", 1)
 
141
            mouseClick(passwordInput, 1, 1)
 
142
            unlockSpy.wait()
 
143
            compare(unlockSpy.count, 1)
 
144
        }
 
145
 
 
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))
 
150
                    return
 
151
                }
 
152
            }
 
153
            fail("Didn't find empty-name")
 
154
        }
 
155
 
 
156
        function test_auth_error() {
 
157
            select_user("auth-error")
 
158
            var passwordInput = findChild(greeter, "passwordInput")
 
159
            tryCompare(passwordInput, "placeholderText", "Retry")
 
160
        }
 
161
 
 
162
        function test_different_prompt() {
 
163
            select_user("different-prompt")
 
164
            var passwordInput = findChild(greeter, "passwordInput")
 
165
            tryCompare(passwordInput, "placeholderText", "Secret word")
 
166
        }
 
167
 
 
168
        function test_no_response() {
 
169
            unlockSpy.clear()
 
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)
 
181
        }
 
182
 
 
183
        function test_two_factor_correct() {
 
184
            unlockSpy.clear()
 
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)
 
197
            typeString("otp")
 
198
            keyClick(Qt.Key_Enter)
 
199
            unlockSpy.wait()
 
200
        }
 
201
 
 
202
        function test_two_factor_wrong1() {
 
203
            unlockSpy.clear()
 
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)
 
215
        }
 
216
 
 
217
        function test_two_factor_wrong2() {
 
218
            unlockSpy.clear()
 
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)
 
234
        }
 
235
 
 
236
        function test_unicode() {
 
237
            var index = select_user("unicode")
 
238
            var label = findChild(greeter, "username"+index)
 
239
            tryCompare(label, "text", "가나다라마")
 
240
        }
 
241
 
 
242
        function test_long_name() {
 
243
            var index = select_user("long-name")
 
244
            var label = findChild(greeter, "username"+index)
 
245
            tryCompare(label, "truncated", true)
 
246
        }
 
247
 
 
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)
 
258
        }
 
259
 
 
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)
 
268
        }
 
269
 
 
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)
 
275
        }
 
276
 
 
277
        function test_html_info_prompt() {
 
278
            select_user("html-info-prompt")
 
279
            var label = findChild(greeter, "infoLabel")
 
280
            tryCompare(label, "text", "&lt;b&gt;&amp;&lt;/b&gt;")
 
281
        }
 
282
 
 
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)
 
290
        }
 
291
 
 
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
 
297
        }
 
298
 
 
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>")
 
302
        }
 
303
 
 
304
        function test_bg_none() {
 
305
            var index = select_user("no-background")
 
306
            compare(greeter.model.data(index, LightDM.UserRoles.BackgroundPathRole), "")
 
307
        }
 
308
    }
 
309
}