@@ -0,0 +1,332 @@
1+/*
2+ * Copyright 2014 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 LightDM 0.1 as LightDM
22+import Ubuntu.Components 0.1
23+import Unity.Test 0.1 as UT
24+
25+Item {
26+ id: root
27+ width: units.gu(90)
28+ height: units.gu(80)
29+
30+ Row {
31+ anchors.fill: parent
32+ Loader {
33+ id: loader
34+ width: root.width - controls.width
35+ height: parent.height
36+
37+ property bool itemDestroyed: false
38+ sourceComponent: Component {
39+ NarrowView {
40+ background: Qt.resolvedUrl("../../../qml/graphics/phone_background.jpg")
41+ userModel: LightDM.Users
42+ infographicModel: LightDM.Infographic
43+
44+ launcherOffset: parseFloat(launcherOffsetField.text)
45+ currentIndex: parseInt(currentIndexField.text, 10)
46+ delayMinutes: parseInt(delayMinutesField.text, 10)
47+ backgroundTopMargin: parseFloat(backgroundTopMarginField.text)
48+ locked: lockedCheckBox.checked
49+ alphanumeric: alphanumericCheckBox.checked
50+
51+ Component.onDestruction: {
52+ loader.itemDestroyed = true
53+ }
54+
55+ onSelected: {
56+ currentIndexField.text = index;
57+ }
58+ }
59+ }
60+ }
61+
62+ Rectangle {
63+ id: controls
64+ color: "white"
65+ width: units.gu(40)
66+ height: parent.height
67+
68+ Column {
69+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
70+ spacing: units.gu(1)
71+
72+ Row {
73+ Button {
74+ text: "Show Last Chance"
75+ onClicked: loader.item.showLastChance()
76+ }
77+ }
78+ Row {
79+ Button {
80+ text: "Hide"
81+ onClicked: loader.item.hide()
82+ }
83+ }
84+ Row {
85+ Button {
86+ text: "Reset"
87+ onClicked: loader.item.reset()
88+ }
89+ }
90+ Row {
91+ Button {
92+ text: "Show Message"
93+ onClicked: loader.item.showMessage(messageField.text)
94+ }
95+ TextField {
96+ id: messageField
97+ width: units.gu(10)
98+ text: ""
99+ }
100+ }
101+ Row {
102+ Button {
103+ text: "Show Prompt"
104+ onClicked: loader.item.showPrompt(promptField.text, isSecretCheckBox.checked, isDefaultPromptCheckBox.checked)
105+ }
106+ TextField {
107+ id: promptField
108+ width: units.gu(10)
109+ text: ""
110+ }
111+ CheckBox {
112+ id: isSecretCheckBox
113+ }
114+ Label {
115+ text: "secret"
116+ }
117+ CheckBox {
118+ id: isDefaultPromptCheckBox
119+ }
120+ Label {
121+ text: "default"
122+ }
123+ }
124+ Row {
125+ Button {
126+ text: "Authenticated"
127+ onClicked: loader.item.authenticated(successCheckBox.checked)
128+ }
129+ CheckBox {
130+ id: successCheckBox
131+ }
132+ Label {
133+ text: "success"
134+ }
135+ }
136+ Row {
137+ Button {
138+ text: "Try To Unlock"
139+ onClicked: loader.item.tryToUnlock(toTheRightCheckBox.checked)
140+ }
141+ CheckBox {
142+ id: toTheRightCheckBox
143+ }
144+ Label {
145+ text: "toTheRight"
146+ }
147+ }
148+ Row {
149+ TextField {
150+ id: launcherOffsetField
151+ width: units.gu(10)
152+ text: "0"
153+ }
154+ Label {
155+ text: "launcherOffset"
156+ }
157+ }
158+ Row {
159+ TextField {
160+ id: currentIndexField
161+ width: units.gu(10)
162+ text: "0"
163+ }
164+ Label {
165+ text: "currentIndex"
166+ }
167+ }
168+ Row {
169+ TextField {
170+ id: delayMinutesField
171+ width: units.gu(10)
172+ text: "0"
173+ }
174+ Label {
175+ text: "delayMinutes"
176+ }
177+ }
178+ Row {
179+ TextField {
180+ id: backgroundTopMarginField
181+ width: units.gu(10)
182+ text: "0"
183+ }
184+ Label {
185+ text: "backgroundTopMargin"
186+ }
187+ }
188+ Row {
189+ CheckBox {
190+ id: lockedCheckBox
191+ }
192+ Label {
193+ text: "locked"
194+ }
195+ }
196+ Row {
197+ CheckBox {
198+ id: alphanumericCheckBox
199+ }
200+ Label {
201+ text: "alphanumeric"
202+ }
203+ }
204+ Row {
205+ Label {
206+ text: "selected: " + selectedSpy.count
207+ }
208+ }
209+ Row {
210+ Label {
211+ text: "responded: " + respondedSpy.count
212+ }
213+ }
214+ Row {
215+ Label {
216+ text: "teased: " + teaseSpy.count
217+ }
218+ }
219+ Row {
220+ Label {
221+ text: "emergency: " + emergencySpy.count
222+ }
223+ }
224+ Row {
225+ Button {
226+ text: "Reload View"
227+ onClicked: {
228+ loader.active = false;
229+ loader.active = true;
230+ }
231+ }
232+ }
233+ }
234+ }
235+ }
236+
237+ SignalSpy {
238+ id: selectedSpy
239+ target: loader.item
240+ signalName: "selected"
241+ }
242+
243+ SignalSpy {
244+ id: respondedSpy
245+ target: loader.item
246+ signalName: "responded"
247+ }
248+
249+ SignalSpy {
250+ id: teaseSpy
251+ target: loader.item
252+ signalName: "tease"
253+ }
254+
255+ SignalSpy {
256+ id: emergencySpy
257+ target: loader.item
258+ signalName: "emergencyCall"
259+ }
260+
261+ UT.UnityTestCase {
262+ name: "WideView"
263+ when: windowShown
264+
265+ property Item view: loader.status === Loader.Ready ? loader.item : null
266+
267+ function init() {
268+ view.currentIndex = 0; // break binding with text field
269+ selectedSpy.clear();
270+ respondedSpy.clear();
271+ teaseSpy.clear();
272+ emergencySpy.clear();
273+ }
274+
275+ function cleanup() {
276+ loader.itemDestroyed = false;
277+ loader.active = false;
278+ tryCompare(loader, "status", Loader.Null);
279+ tryCompare(loader, "item", null);
280+ tryCompare(loader, "itemDestroyed", true);
281+ loader.active = true;
282+ tryCompare(loader, "status", Loader.Ready);
283+ removeTimeConstraintsFromDirectionalDragAreas(loader.item);
284+ }
285+
286+ function swipeAwayCover() {
287+ tryCompare(view, "fullyShown", true);
288+ var touchY = view.height / 2;
289+ touchFlick(view, view.width, touchY, 0, touchY);
290+ var coverPage = findChild(view, "coverPage");
291+ tryCompare(coverPage, "showProgress", 0);
292+ waitForRendering(view);
293+ }
294+
295+ function enterPin(pin) {
296+ for (var i = 0; i < pin.length; ++i) {
297+ var character = pin.charAt(i);
298+ var button = findChild(view, "pinPadButton" + character);
299+ tap(button);
300+ }
301+ }
302+
303+ function test_tease() {
304+ tap(view, 1, 1);
305+ compare(teaseSpy.count, 1);
306+ }
307+
308+ function test_respondedWithPin() {
309+ view.locked = true;
310+ swipeAwayCover();
311+ enterPin("1234");
312+ compare(respondedSpy.count, 1);
313+ compare(respondedSpy.signalArguments[0][0], "1234");
314+ }
315+
316+ function test_respondedWithPassphrase() {
317+ view.locked = true;
318+ view.alphanumeric = true;
319+ swipeAwayCover();
320+ typeString("test");
321+ keyClick(Qt.Key_Enter);
322+ compare(respondedSpy.count, 1);
323+ compare(respondedSpy.signalArguments[0][0], "test");
324+ }
325+
326+ function test_respondedWithSwipe() {
327+ swipeAwayCover();
328+ compare(respondedSpy.count, 1);
329+ compare(respondedSpy.signalArguments[0][0], "");
330+ }
331+ }
332+}