Merge lp:~mzanetti/unity/phablet-greeter-tests into lp:unity/phablet

Proposed by Michael Zanetti
Status: Merged
Approved by: Albert Astals Cid
Approved revision: no longer in the source branch.
Merged at revision: 486
Proposed branch: lp:~mzanetti/unity/phablet-greeter-tests
Merge into: lp:unity/phablet
Diff against target: 330 lines (+227/-4)
7 files modified
Greeter/Greeter.qml (+14/-2)
Greeter/GreeterContent.qml (+6/-2)
Greeter/LoginList.qml (+1/-0)
Shell.qml (+4/-0)
tests/qmluitests/CMakeLists.txt (+1/-0)
tests/qmluitests/UnityTestCase.qml (+89/-0)
tests/qmluitests/tst_Greeter.qml (+112/-0)
To merge this branch: bzr merge lp:~mzanetti/unity/phablet-greeter-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Albert Astals Cid (community) Approve
Review via email: mp+153963@code.launchpad.net

Commit message

add tests for the greeter

Description of the change

add tests for the greeter

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks good besides the typeString thing, but we will improve Qt to remove it.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Greeter/Greeter.qml'
--- Greeter/Greeter.qml 2013-03-13 18:54:11 +0000
+++ Greeter/Greeter.qml 2013-03-19 12:02:23 +0000
@@ -24,14 +24,18 @@
24 enabled: shown24 enabled: shown
25 created: greeterContentLoader.status == Loader.Ready && greeterContentLoader.item.ready25 created: greeterContentLoader.status == Loader.Ready && greeterContentLoader.item.ready
2626
27 property alias model: userList
27 property bool locked: shown && multiUser && !greeterContentLoader.guestAccount28 property bool locked: shown && multiUser && !greeterContentLoader.guestAccount
2829
29 readonly property bool narrowMode: width <= units.gu(60)30 readonly property bool narrowMode: width <= units.gu(60)
30 readonly property bool multiUser: !narrowMode // TODO: populate with real value31 readonly property bool multiUser: !narrowMode // TODO: populate with real value
31 32
33 signal selected(int uid)
34 signal unlocked(int uid)
35
32 ListModel {36 ListModel {
33 id: userList37 id: userList
34 ListElement { name: "Guest"; background: "../graphics/tablet_background.jpg" }38 ListElement { name: "Guest"; background: "graphics/tablet_background.jpg" }
35 }39 }
3640
37 // TODO: Replace with a ModelAggregator once we have one.41 // TODO: Replace with a ModelAggregator once we have one.
@@ -57,7 +61,7 @@
57 for (var i = 0; i < xmlReader.count; i++) {61 for (var i = 0; i < xmlReader.count; i++) {
58 userList.append(xmlReader.get(i));62 userList.append(xmlReader.get(i));
59 }63 }
60 userList.append({ "name": "Guest", background: "../graphics/tablet_background.jpg" });64 userList.append({ "name": "Guest", background: "graphics/tablet_background.jpg" });
6165
62 greeterContentLoader.model = userList;66 greeterContentLoader.model = userList;
63 greeterContentLoader.currentIndex = 0;67 greeterContentLoader.currentIndex = 0;
@@ -74,5 +78,13 @@
74 property bool guestAccount: item ? item.guestAccount : false78 property bool guestAccount: item ? item.guestAccount : false
7579
76 source: required ? "GreeterContent.qml" : ""80 source: required ? "GreeterContent.qml" : ""
81
82
83 Connections {
84 target: greeterContentLoader.item
85
86 onSelected: greeter.selected(uid);
87 onUnlocked: greeter.unlocked(uid);
88 }
77 }89 }
78}90}
7991
=== modified file 'Greeter/GreeterContent.qml'
--- Greeter/GreeterContent.qml 2013-02-28 15:56:55 +0000
+++ Greeter/GreeterContent.qml 2013-03-19 12:02:23 +0000
@@ -19,10 +19,14 @@
19import "../Components"19import "../Components"
2020
21MouseArea {21MouseArea {
22 id: root
22 anchors.fill: parent23 anchors.fill: parent
2324
24 property bool guestAccount: loginLoader.status == Loader.Ready && loginLoader.item.guestAccount25 property bool guestAccount: loginLoader.status == Loader.Ready && loginLoader.item.guestAccount
25 property bool ready: wallpaper.status == Image.Ready26 property bool ready: wallpaper.status == Image.Ready
27
28 signal selected(int uid)
29 signal unlocked(int uid)
2630
27 CrossFadeImage {31 CrossFadeImage {
28 id: wallpaper32 id: wallpaper
@@ -77,11 +81,11 @@
77 target: loginLoader.item81 target: loginLoader.item
7882
79 onSelected: {83 onSelected: {
80 shell.background = userList.get(uid).background;84 root.selected(uid);
81 }85 }
8286
83 onUnlocked: {87 onUnlocked: {
84 greeter.hide();88 root.unlocked(uid);
85 }89 }
8690
87 onCurrentIndexChanged: {91 onCurrentIndexChanged: {
8892
=== modified file 'Greeter/LoginList.qml'
--- Greeter/LoginList.qml 2013-03-18 21:10:01 +0000
+++ Greeter/LoginList.qml 2013-03-19 12:02:23 +0000
@@ -140,6 +140,7 @@
140 }140 }
141141
142 delegate: Item {142 delegate: Item {
143 objectName: "username" + index
143 width: parent.width144 width: parent.width
144 // Adding 2 gus in height to close gaps in draggable area between items145 // Adding 2 gus in height to close gaps in draggable area between items
145 height: (index == userList.currentIndex ? root.highlightedHeight : root.cellHeight) + units.gu(2)146 height: (index == userList.currentIndex ? root.highlightedHeight : root.cellHeight) + units.gu(2)
146147
=== modified file 'Shell.qml'
--- Shell.qml 2013-03-12 12:26:25 +0000
+++ Shell.qml 2013-03-19 12:02:23 +0000
@@ -408,6 +408,10 @@
408 height: parent.height - panel.panelHeight408 height: parent.height - panel.panelHeight
409409
410 onShownChanged: if (shown) greeter.forceActiveFocus()410 onShownChanged: if (shown) greeter.forceActiveFocus()
411
412 onUnlocked: greeter.hide()
413 onSelected: shell.background = greeter.model.get(uid).background;
414
411 }415 }
412416
413 Revealer {417 Revealer {
414418
=== modified file 'tests/qmluitests/CMakeLists.txt'
--- tests/qmluitests/CMakeLists.txt 2013-03-15 19:01:53 +0000
+++ tests/qmluitests/CMakeLists.txt 2013-03-19 12:02:23 +0000
@@ -23,3 +23,4 @@
23add_qml_test(DraggingArea)23add_qml_test(DraggingArea)
24add_qml_test(FilterGrid ${CMAKE_BINARY_DIR}/plugins)24add_qml_test(FilterGrid ${CMAKE_BINARY_DIR}/plugins)
25add_qml_test(Hud ${CMAKE_CURRENT_BINARY_DIR}/qml)25add_qml_test(Hud ${CMAKE_CURRENT_BINARY_DIR}/qml)
26add_qml_test(Greeter)
2627
=== modified file 'tests/qmluitests/UnityTestCase.qml'
--- tests/qmluitests/UnityTestCase.qml 2013-03-19 09:34:54 +0000
+++ tests/qmluitests/UnityTestCase.qml 2013-03-19 12:02:23 +0000
@@ -33,4 +33,93 @@
33 if (releaseMouse)33 if (releaseMouse)
34 mouseRelease(item, toX, toY)34 mouseRelease(item, toX, toY)
35 }35 }
36
37
38 // Find an object with the given name recursively, starting
39 // at the given object "obj"
40 function findChild(obj,objectName) {
41 for (var i in obj.children) {
42 var child = obj.children[i];
43 if (child.objectName === objectName) return child;
44 var subChild = findChild(child,objectName);
45 if (subChild !== undefined) return subChild;
46 }
47 return undefined;
48 }
49
50 // Type a full string instead of keyClick letter by letter
51 // TODO: this is not ugly, this is uber-ugly and does not support
52 // any special character. Remove the keyMap once keyClick(obj, char)
53 // has landed in upstream Qt.
54 function typeString(str) {
55 var keyMap = {
56 "a": Qt.Key_A,
57 "b": Qt.Key_B,
58 "c": Qt.Key_C,
59 "d": Qt.Key_D,
60 "e": Qt.Key_E,
61 "f": Qt.Key_F,
62 "g": Qt.Key_G,
63 "h": Qt.Key_H,
64 "i": Qt.Key_I,
65 "j": Qt.Key_J,
66 "k": Qt.Key_K,
67 "l": Qt.Key_L,
68 "m": Qt.Key_M,
69 "n": Qt.Key_N,
70 "o": Qt.Key_O,
71 "p": Qt.Key_P,
72 "q": Qt.Key_Q,
73 "r": Qt.Key_R,
74 "s": Qt.Key_S,
75 "t": Qt.Key_T,
76 "u": Qt.Key_U,
77 "v": Qt.Key_V,
78 "w": Qt.Key_W,
79 "x": Qt.Key_X,
80 "y": Qt.Key_Y,
81 "z": Qt.Key_Z,
82 "A": Qt.Key_A,
83 "B": Qt.Key_B,
84 "C": Qt.Key_C,
85 "D": Qt.Key_D,
86 "E": Qt.Key_E,
87 "F": Qt.Key_F,
88 "G": Qt.Key_G,
89 "H": Qt.Key_H,
90 "I": Qt.Key_I,
91 "J": Qt.Key_J,
92 "K": Qt.Key_K,
93 "L": Qt.Key_L,
94 "M": Qt.Key_M,
95 "N": Qt.Key_N,
96 "O": Qt.Key_O,
97 "P": Qt.Key_P,
98 "Q": Qt.Key_Q,
99 "R": Qt.Key_R,
100 "S": Qt.Key_S,
101 "T": Qt.Key_T,
102 "U": Qt.Key_U,
103 "V": Qt.Key_V,
104 "W": Qt.Key_W,
105 "X": Qt.Key_X,
106 "Y": Qt.Key_Y,
107 "Z": Qt.Key_Z,
108 "0": Qt.Key_0,
109 "1": Qt.Key_1,
110 "2": Qt.Key_2,
111 "3": Qt.Key_3,
112 "4": Qt.Key_4,
113 "5": Qt.Key_5,
114 "6": Qt.Key_6,
115 "7": Qt.Key_7,
116 "8": Qt.Key_8,
117 "9": Qt.Key_9,
118 " ": Qt.Key_Space,
119 }
120 for (var i = 0; i < str.length; i++) {
121 keyClick(keyMap[str[i]])
122 }
123 }
124
36}125}
37126
=== added file 'tests/qmluitests/tst_Greeter.qml'
--- tests/qmluitests/tst_Greeter.qml 1970-01-01 00:00:00 +0000
+++ tests/qmluitests/tst_Greeter.qml 2013-03-19 12:02:23 +0000
@@ -0,0 +1,112 @@
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
17import QtQuick 2.0
18import QtTest 1.0
19import "../../Greeter"
20import Ubuntu.Components 0.1
21
22Item {
23 width: units.gu(120)
24 height: units.gu(80)
25 UnityTestCase {
26 name: "GreeterTest"
27 when: windowShown
28
29 function test_cycle_data() {
30 var data = new Array()
31 for (var i = 1; i < greeter.model.count; i++) {
32 data[i] = {tag: greeter.model.get(i).name, username: "username"+i, uid: i }
33 }
34 data[greeter.model.count] = {tag: greeter.model.get(0).name, username: "username0", uid: 0 }
35 return data
36 }
37
38 function test_cycle(data) {
39 selectionSpy.clear();
40 var user = findChild(greeter, data.username)
41 mouseClick(user, user.width / 2, user.height / 2)
42 var pathview = findChild(greeter, "userList")
43 tryCompare(pathview, "currentIndex", data.uid)
44 tryCompare(greeter, "locked", greeter.model.get(data.uid).password !== undefined)
45 selectionSpy.wait()
46 compare(selectionSpy.count, 1)
47 }
48
49 function test_unlock_password() {
50 unlockSpy.clear()
51 // First one is Lolas account right now. Replace with password protected user from lightdm
52 var account = findChild(greeter, "username1")
53 mouseClick(account, 1, 1)
54 account = findChild(greeter, "username0")
55 mouseClick(account, 1, 1)
56 var passwordInput = findChild(greeter, "passwordInput")
57 tryCompare(passwordInput, "opacity", 0)
58 tryCompare(passwordInput, "opacity", 1)
59 mouseClick(passwordInput, 1, 1)
60 compare(unlockSpy.count, 0)
61 typeString(greeter.model.get(0).password)
62 keyClick(Qt.Key_Enter)
63 unlockSpy.wait()
64 }
65
66 function test_unlock_wrong_password() {
67 unlockSpy.clear()
68 // First one is Lolas account right now. Replace with password protected user from lightdm
69 var account = findChild(greeter, "username1")
70 mouseClick(account, 1, 1)
71 account = findChild(greeter, "username0")
72 mouseClick(account, 1, 1)
73 var passwordInput = findChild(greeter, "passwordInput")
74 tryCompare(passwordInput, "opacity", 0)
75 tryCompare(passwordInput, "opacity", 1)
76 mouseClick(passwordInput, 1, 1)
77 compare(unlockSpy.count, 0)
78 typeString("wr0ng p4ssw0rd")
79 keyClick(Qt.Key_Enter)
80 compare(unlockSpy.count, 0)
81 }
82
83 function test_unlock_no_password() {
84 unlockSpy.clear()
85 // Last one is the guest account for now. Replace with passwordless user from lightdm
86 var guestAccount = findChild(greeter, "username" + (greeter.model.count - 1))
87 mouseClick(guestAccount, guestAccount.width / 2, guestAccount.height / 2)
88 var passwordInput = findChild(greeter, "passwordInput")
89 tryCompare(passwordInput, "opacity", 1)
90 mouseClick(passwordInput, 1, 1)
91 unlockSpy.wait()
92 compare(unlockSpy.count, 1)
93 }
94 }
95
96 Greeter {
97 id: greeter
98 anchors.fill: parent
99 }
100
101 SignalSpy {
102 id: unlockSpy
103 target: greeter
104 signalName: "unlocked"
105 }
106
107 SignalSpy {
108 id: selectionSpy
109 target: greeter
110 signalName: "selected"
111 }
112}

Subscribers

People subscribed via source and target branches