@@ -0,0 +1,299 @@
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(120)
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+ WideView {
40+ background: Qt.resolvedUrl("../../../qml/graphics/tablet_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+
50+ Component.onDestruction: {
51+ loader.itemDestroyed = true
52+ }
53+
54+ onSelected: {
55+ currentIndexField.text = index;
56+ }
57+ }
58+ }
59+ }
60+
61+ Rectangle {
62+ id: controls
63+ color: "white"
64+ width: units.gu(40)
65+ height: parent.height
66+
67+ Column {
68+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
69+ spacing: units.gu(1)
70+
71+ Row {
72+ Button {
73+ text: "Show Last Chance"
74+ onClicked: loader.item.showLastChance()
75+ }
76+ }
77+ Row {
78+ Button {
79+ text: "Hide"
80+ onClicked: loader.item.hide()
81+ }
82+ }
83+ Row {
84+ Button {
85+ text: "Reset"
86+ onClicked: loader.item.reset()
87+ }
88+ }
89+ Row {
90+ Button {
91+ text: "Show Message"
92+ onClicked: loader.item.showMessage(messageField.text)
93+ }
94+ TextField {
95+ id: messageField
96+ width: units.gu(10)
97+ text: ""
98+ }
99+ }
100+ Row {
101+ Button {
102+ text: "Show Prompt"
103+ onClicked: loader.item.showPrompt(promptField.text, isSecretCheckBox.checked, isDefaultPromptCheckBox.checked)
104+ }
105+ TextField {
106+ id: promptField
107+ width: units.gu(10)
108+ text: ""
109+ }
110+ CheckBox {
111+ id: isSecretCheckBox
112+ }
113+ Label {
114+ text: "secret"
115+ }
116+ CheckBox {
117+ id: isDefaultPromptCheckBox
118+ }
119+ Label {
120+ text: "default"
121+ }
122+ }
123+ Row {
124+ Button {
125+ text: "Authenticated"
126+ onClicked: loader.item.authenticated(successCheckBox.checked)
127+ }
128+ CheckBox {
129+ id: successCheckBox
130+ }
131+ Label {
132+ text: "success"
133+ }
134+ }
135+ Row {
136+ Button {
137+ text: "Try To Unlock"
138+ onClicked: loader.item.tryToUnlock(toTheRightCheckBox.checked)
139+ }
140+ CheckBox {
141+ id: toTheRightCheckBox
142+ }
143+ Label {
144+ text: "toTheRight"
145+ }
146+ }
147+ Row {
148+ TextField {
149+ id: launcherOffsetField
150+ width: units.gu(10)
151+ text: "0"
152+ }
153+ Label {
154+ text: "launcherOffset"
155+ }
156+ }
157+ Row {
158+ TextField {
159+ id: currentIndexField
160+ width: units.gu(10)
161+ text: "0"
162+ }
163+ Label {
164+ text: "currentIndex"
165+ }
166+ }
167+ Row {
168+ TextField {
169+ id: delayMinutesField
170+ width: units.gu(10)
171+ text: "0"
172+ }
173+ Label {
174+ text: "delayMinutes"
175+ }
176+ }
177+ Row {
178+ TextField {
179+ id: backgroundTopMarginField
180+ width: units.gu(10)
181+ text: "0"
182+ }
183+ Label {
184+ text: "backgroundTopMargin"
185+ }
186+ }
187+ Row {
188+ CheckBox {
189+ id: lockedCheckBox
190+ }
191+ Label {
192+ text: "locked"
193+ }
194+ }
195+ Row {
196+ Label {
197+ text: "selected: " + selectedSpy.count
198+ }
199+ }
200+ Row {
201+ Label {
202+ text: "responded: " + respondedSpy.count
203+ }
204+ }
205+ Row {
206+ Label {
207+ text: "teased: " + teaseSpy.count
208+ }
209+ }
210+ Row {
211+ Label {
212+ text: "emergency: " + emergencySpy.count
213+ }
214+ }
215+ Row {
216+ Button {
217+ text: "Reload View"
218+ onClicked: {
219+ loader.active = false;
220+ loader.active = true;
221+ }
222+ }
223+ }
224+ }
225+ }
226+ }
227+
228+ SignalSpy {
229+ id: selectedSpy
230+ target: loader.item
231+ signalName: "selected"
232+ }
233+
234+ SignalSpy {
235+ id: respondedSpy
236+ target: loader.item
237+ signalName: "responded"
238+ }
239+
240+ SignalSpy {
241+ id: teaseSpy
242+ target: loader.item
243+ signalName: "tease"
244+ }
245+
246+ SignalSpy {
247+ id: emergencySpy
248+ target: loader.item
249+ signalName: "emergencyCall"
250+ }
251+
252+ UT.UnityTestCase {
253+ name: "WideView"
254+ when: windowShown
255+
256+ property Item view: loader.status === Loader.Ready ? loader.item : null
257+
258+ function init() {
259+ view.currentIndex = 0; // break binding with text field
260+ selectedSpy.clear();
261+ respondedSpy.clear();
262+ teaseSpy.clear();
263+ emergencySpy.clear();
264+ }
265+
266+ function cleanup() {
267+ loader.itemDestroyed = false;
268+ loader.active = false;
269+ tryCompare(loader, "status", Loader.Null);
270+ tryCompare(loader, "item", null);
271+ tryCompare(loader, "itemDestroyed", true);
272+ loader.active = true;
273+ tryCompare(loader, "status", Loader.Ready);
274+ }
275+
276+ function test_tease() {
277+ tap(view, 1, 1);
278+ compare(teaseSpy.count, 1);
279+ }
280+
281+ function test_selected() {
282+ var delegate = findChild(view, "username2");
283+ tap(delegate);
284+ compare(selectedSpy.count, 1);
285+ compare(selectedSpy.signalArguments[0][0], 2);
286+ compare(view.currentIndex, 0); // confirm we didn't change
287+ }
288+
289+ function test_responded() {
290+ view.showPrompt("Prompt", true, true);
291+ var passwordInput = findChild(view, "passwordInput");
292+ tap(passwordInput);
293+ typeString("password");
294+ keyClick(Qt.Key_Enter);
295+ compare(respondedSpy.count, 1);
296+ compare(respondedSpy.signalArguments[0][0], "password");
297+ }
298+ }
299+}