@@ -0,0 +1,205 @@
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+Rectangle {
26+ width: units.gu(60)
27+ height: units.gu(80)
28+ color: "orange"
29+
30+ Lockscreen {
31+ id: lockscreen
32+ anchors.fill: parent
33+ anchors.rightMargin: units.gu(18)
34+ placeholderText: "Please enter your PIN"
35+ alphaNumeric: pinPadCheckBox.checked
36+ pinLength: pinLengthTextField.text
37+ username: "Lola"
38+ }
39+
40+ Connections {
41+ target: lockscreen
42+
43+ onEmergencyCall: emergencyCheckBox.checked = true
44+ onUnlocked: unlockedCheckBox.checked = true
45+ }
46+
47+ Connections {
48+ target: LightDM.Greeter
49+
50+ onShowPrompt: {
51+ if (text.indexOf("PIN") >= 0) {
52+ lockscreen.alphaNumeric = false
53+ } else {
54+ lockscreen.alphaNumeric = true
55+ }
56+ lockscreen.placeholderText = text;
57+ }
58+ }
59+
60+ Rectangle {
61+ anchors.fill: parent
62+ anchors.leftMargin: lockscreen.width
63+ color: "lightgray"
64+
65+ Column {
66+ anchors.fill: parent
67+ anchors.margins: units.gu(1)
68+
69+ Row {
70+ CheckBox {
71+ id: pinPadCheckBox
72+ }
73+ Label {
74+ text: "Alphanumeric"
75+ anchors.verticalCenter: parent.verticalCenter
76+ }
77+ }
78+ Row {
79+ CheckBox {
80+ id: emergencyCheckBox
81+ }
82+ Label {
83+ text: "Emergency Call"
84+ anchors.verticalCenter: parent.verticalCenter
85+ }
86+ }
87+ Row {
88+ TextField {
89+ id: pinLengthTextField
90+ width: units.gu(7)
91+ text: "4"
92+ }
93+ Label {
94+ text: "PIN length"
95+ }
96+ }
97+ Label {
98+ id: pinLabel
99+ anchors.verticalCenter: parent.verticalCenter
100+ }
101+ Row {
102+ CheckBox {
103+ id: unlockedCheckBox
104+ }
105+ Label {
106+ text: "Unlocked signal"
107+ anchors.verticalCenter: parent.verticalCenter
108+ }
109+ }
110+ Button {
111+ text: "start auth (1234)"
112+ onClicked: LightDM.Greeter.authenticate("has-pin")
113+ }
114+ Button {
115+ text: "start auth (password)"
116+ onClicked: LightDM.Greeter.authenticate("has-password")
117+ }
118+ }
119+ }
120+
121+ UT.UnityTestCase {
122+ name: "Lockscreen"
123+ when: windowShown
124+
125+ function test_loading_data() {
126+ return [
127+ {tag: "numeric", alphanumeric: false, pinPadAvailable: true },
128+ {tag: "alphanumeric", alphanumeric: true, pinPadAvailable: false }
129+ ]
130+ }
131+
132+ function test_loading(data) {
133+ lockscreen.alphaNumeric = data.alphanumeric
134+ waitForRendering(lockscreen)
135+ if (data.pinPadAvailable) {
136+ compare(findChild(lockscreen, "pinPadButton8").text, "8", "Could not find number 8 on PinPad")
137+ } else {
138+ compare(findChild(lockscreen, "pinPadButton8"), undefined, "Could find number 8 on PinPad even though it should be only OSK")
139+ }
140+ }
141+
142+ function test_emergency_call_data() {
143+ return [
144+ {tag: "numeric", alphanumeric: false },
145+ {tag: "alphanumeric", alphanumeric: true }
146+ ]
147+ }
148+
149+ function test_emergency_call(data) {
150+ emergencyCheckBox.checked = false
151+ lockscreen.alphaNumeric = data.alphanumeric
152+ waitForRendering(lockscreen)
153+ var emergencyButton = findChild(lockscreen, "emergencyCallIcon")
154+ mouseClick(emergencyButton, units.gu(1), units.gu(1))
155+ tryCompare(emergencyCheckBox, "checked", true)
156+
157+ }
158+
159+ function test_labels_data() {
160+ return [
161+ {tag: "numeric", alphanumeric: false, placeholderText: "Please enter your PIN", username: "foobar" },
162+ {tag: "alphanumeric", alphanumeric: true, placeholderText: "Please enter your password", username: "Lola" }
163+ ]
164+ }
165+
166+ function test_labels(data) {
167+ lockscreen.alphaNumeric = data.alphanumeric
168+ lockscreen.placeholderText = data.placeholderText
169+ waitForRendering(lockscreen)
170+ compare(findChild(lockscreen, "pinentryField").placeholderText, data.placeholderText, "Placeholdertext is not what it should be")
171+ if (data.alphanumeric) {
172+ compare(findChild(lockscreen, "greeterLabel").text, "Hello " + data.username, "Greeter is not set correctly")
173+ }
174+ }
175+
176+
177+ function test_unlock_data() {
178+ return [
179+ {tag: "numeric", alphanumeric: false, username: "has-pin", password: "1234", unlockedSignal: true},
180+ {tag: "alphanumeric", alphanumeric: true, username: "has-password", password: "password", unlockedSignal: true},
181+ {tag: "numeric (wrong)", alphanumeric: false, username: "has-pin", password: "4321", unlockedSignal: false},
182+ {tag: "alphanumeric (wrong)", alphanumeric: true, username: "has-password", password: "drowssap", unlockedSignal: false},
183+ ]
184+ }
185+
186+ function test_unlock(data) {
187+ unlockedCheckBox.checked = false
188+ LightDM.Greeter.authenticate(data.username)
189+
190+ if (data.alphanumeric) {
191+ var inputField = findChild(lockscreen, "pinentryField")
192+ mouseClick(inputField, units.gu(1), units.gu(1))
193+ typeString(data.password)
194+ keyClick(Qt.Key_Enter)
195+ } else {
196+ for (var i = 0; i < data.password.length; ++i) {
197+ var character = data.password.charAt(i)
198+ var button = findChild(lockscreen, "pinPadButton" + character)
199+ mouseClick(button, units.gu(1), units.gu(1))
200+ }
201+ }
202+ tryCompare(unlockedCheckBox, "checked", data.unlockedSignal)
203+ }
204+ }
205+}