Merge lp:~aacid/unity/testParametrizedActions into lp:unity/phablet

Proposed by Albert Astals Cid
Status: Merged
Approved by: Albert Astals Cid
Approved revision: no longer in the source branch.
Merged at revision: 522
Proposed branch: lp:~aacid/unity/testParametrizedActions
Merge into: lp:unity/phablet
Prerequisite: lp:~aacid/unity/testHudRefactor
Diff against target: 320 lines (+197/-5)
5 files modified
Hud/Hud.qml (+1/-0)
tests/qmluitests/qml/HudClient/fake_libhud_client.cpp (+94/-5)
tests/qmluitests/qml/HudClient/libhud_client_stub.cpp (+21/-0)
tests/qmluitests/qml/HudClient/libhud_client_stub.h (+11/-0)
tests/qmluitests/tst_Hud.qml (+70/-0)
To merge this branch: bzr merge lp:~aacid/unity/testParametrizedActions
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michael Zanetti (community) Approve
Review via email: mp+154750@code.launchpad.net

Commit message

Test the parametrized actions

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Albert Astals Cid (aacid) wrote :

Last autolanding failed due to jenkins hickup, retriggerting

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Hud/Hud.qml'
2--- Hud/Hud.qml 2013-03-21 15:54:40 +0000
3+++ Hud/Hud.qml 2013-03-22 15:49:31 +0000
4@@ -485,6 +485,7 @@
5
6 HudParametrizedActionsPage {
7 id: parametrizedActionsPage
8+ objectName: "parametrizedActionsPage"
9 property bool shown: false
10
11 anchors.bottom: parent.bottom
12
13=== modified file 'tests/qmluitests/qml/HudClient/fake_libhud_client.cpp'
14--- tests/qmluitests/qml/HudClient/fake_libhud_client.cpp 2013-03-21 10:24:56 +0000
15+++ tests/qmluitests/qml/HudClient/fake_libhud_client.cpp 2013-03-22 15:49:31 +0000
16@@ -41,6 +41,8 @@
17
18 DeeModel *resultsModel = 0;
19 DeeModel *appStackModel = 0;
20+GMenuModel *parametrizedActionModel = 0;
21+GActionGroup *parametrizedActionGroup = 0;
22
23 HudClientQuery *hud_client_query_new(const gchar *query)
24 {
25@@ -75,11 +77,13 @@
26 columns[0] = g_variant_new_variant(g_variant_new_uint64(2));
27 columns[1] = g_variant_new_string("Foo");
28 columns[3] = g_variant_new_string("Show Foo");
29+ columns[7] = g_variant_new_boolean(true);
30 dee_model_append_row(resultsModel, columns);
31
32 columns[0] = g_variant_new_variant(g_variant_new_uint64(3));
33 columns[1] = g_variant_new_string("Bar");
34 columns[3] = g_variant_new_string("Show Bar");
35+ columns[7] = g_variant_new_boolean(false);
36 dee_model_append_row(resultsModel, columns);
37
38 columns[0] = g_variant_new_variant(g_variant_new_uint64(4));
39@@ -132,13 +136,98 @@
40 Q_UNUSED(timestamp);
41 for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {
42 DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);
43- GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
44- if (g_variant_equal (command_key, it_command)) {
45- HudClientStub::m_lastExecutedCommandRow = i;
46+ if (!dee_model_get_bool(resultsModel, iter, 7)) {
47+ GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
48+ if (g_variant_equal (command_key, it_command)) {
49+ HudClientStub::m_lastExecutedCommandRow = i;
50+ g_variant_unref(it_command);
51+ return;
52+ }
53 g_variant_unref(it_command);
54- return;
55 }
56- g_variant_unref(it_command);
57 }
58 HudClientStub::m_lastExecutedCommandRow = -1;
59 }
60+
61+HudClientParam *hud_client_query_execute_param_command(HudClientQuery *cquery, GVariant *command_key, guint timestamp)
62+{
63+ Q_UNUSED(cquery);
64+ Q_UNUSED(timestamp);
65+ for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {
66+ DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);
67+ if (dee_model_get_bool(resultsModel, iter, 7)) {
68+ GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
69+ if (g_variant_equal (command_key, it_command)) {
70+ HudClientStub::m_lastExecutedParametrizedCommandRow = i;
71+ g_variant_unref(it_command);
72+ // No need to create a real HudClientParam since it's always passed down to us
73+ return (HudClientParam *)g_object_new(G_TYPE_OBJECT, NULL);
74+ }
75+ g_variant_unref(it_command);
76+ }
77+ }
78+ HudClientStub::m_lastExecutedParametrizedCommandRow = -1;
79+ return NULL;
80+}
81+
82+GMenuModel *hud_client_param_get_model(HudClientParam *param)
83+{
84+ Q_UNUSED(param);
85+
86+ if (!parametrizedActionModel) {
87+ GMenu *menu = g_menu_new();
88+ GMenuItem *item = g_menu_item_new("Item1Label", NULL);
89+ g_menu_item_set_attribute_value(item, "parameter-type", g_variant_new_string("slider"));
90+ g_menu_item_set_attribute_value(item, "min", g_variant_new_double(10));
91+ g_menu_item_set_attribute_value(item, "max", g_variant_new_double(80));
92+ g_menu_item_set_attribute_value(item, "live", g_variant_new_boolean(true));
93+ g_menu_item_set_attribute_value(item, "value", g_variant_new_double(75));
94+ g_menu_item_set_attribute_value(item, "action", g_variant_new_string("costAction"));
95+ g_menu_append_item (menu, item);
96+
97+ parametrizedActionModel = G_MENU_MODEL(menu);
98+ }
99+
100+ return parametrizedActionModel;
101+}
102+
103+void hud_client_param_send_cancel(HudClientParam *param)
104+{
105+ Q_UNUSED(param);
106+ g_clear_object(&parametrizedActionModel);
107+ parametrizedActionModel = 0;
108+ HudClientStub::m_lastParametrizedCommandCommited = false;
109+}
110+
111+static void on_signal_activated (GSimpleAction *action, GVariant *parameter, gpointer /*user_data*/)
112+{
113+ // Only double for the moment
114+ HudClientStub::m_activatedActions.insert(g_action_get_name(G_ACTION(action)), QVariant(g_variant_get_double(parameter)));
115+}
116+
117+GActionGroup *hud_client_param_get_actions(HudClientParam *param)
118+{
119+ Q_UNUSED(param);
120+ if (!parametrizedActionGroup) {
121+ GSimpleActionGroup *actionGroup = g_simple_action_group_new();
122+ GSimpleAction *action = g_simple_action_new("costAction", G_VARIANT_TYPE_DOUBLE);
123+ g_simple_action_group_insert(actionGroup, G_ACTION(action));
124+
125+ g_signal_connect (action, "activate", G_CALLBACK (on_signal_activated), NULL);
126+
127+
128+ parametrizedActionGroup = G_ACTION_GROUP(actionGroup);
129+ }
130+
131+ return parametrizedActionGroup;
132+}
133+
134+void hud_client_param_send_commit(HudClientParam *param)
135+{
136+ Q_UNUSED(param);
137+ g_object_unref(parametrizedActionGroup);
138+ parametrizedActionGroup = 0;
139+ g_clear_object(&parametrizedActionModel);
140+ parametrizedActionModel = 0;
141+ HudClientStub::m_lastParametrizedCommandCommited = true;
142+}
143
144=== modified file 'tests/qmluitests/qml/HudClient/libhud_client_stub.cpp'
145--- tests/qmluitests/qml/HudClient/libhud_client_stub.cpp 2013-03-21 15:57:43 +0000
146+++ tests/qmluitests/qml/HudClient/libhud_client_stub.cpp 2013-03-22 15:49:31 +0000
147@@ -22,6 +22,9 @@
148 QString HudClientStub::m_lastSetAppStackApplicationId;
149 QString HudClientStub::m_lastSetQuery;
150 int HudClientStub::m_lastExecutedCommandRow;
151+int HudClientStub::m_lastExecutedParametrizedCommandRow;
152+bool HudClientStub::m_lastParametrizedCommandCommited;
153+QVariantMap HudClientStub::m_activatedActions;
154
155 int HudClientStub::lastExecutedToolbarItem() const
156 {
157@@ -43,12 +46,30 @@
158 return m_lastExecutedCommandRow;
159 }
160
161+int HudClientStub::lastExecutedParametrizedCommandRow() const
162+{
163+ return m_lastExecutedParametrizedCommandRow;
164+}
165+
166+bool HudClientStub::lastParametrizedCommandCommited() const
167+{
168+ return m_lastParametrizedCommandCommited;
169+}
170+
171+QVariantMap HudClientStub::activatedActions() const
172+{
173+ return m_activatedActions;
174+}
175+
176 void HudClientStub::reset()
177 {
178 m_lastExecutedToolbarItem = -1;
179 m_lastSetAppStackApplicationId.clear();
180 m_lastSetQuery.clear();
181 m_lastExecutedCommandRow = -1;
182+ m_lastExecutedParametrizedCommandRow = -1;
183+ m_lastParametrizedCommandCommited = false;
184+ m_activatedActions.clear();
185 }
186
187 int HudClientStub::fullScreenToolbarItemValue() const
188
189=== modified file 'tests/qmluitests/qml/HudClient/libhud_client_stub.h'
190--- tests/qmluitests/qml/HudClient/libhud_client_stub.h 2013-03-21 15:57:43 +0000
191+++ tests/qmluitests/qml/HudClient/libhud_client_stub.h 2013-03-22 15:49:31 +0000
192@@ -19,6 +19,8 @@
193
194 #include <QObject>
195
196+#include <QVariantMap>
197+
198 class HudClientStub : public QObject
199 {
200 Q_OBJECT
201@@ -27,12 +29,18 @@
202 Q_PROPERTY(QString lastSetAppStackApplicationId READ lastSetAppStackApplicationId)
203 Q_PROPERTY(QString lastSetQuery READ lastSetQuery)
204 Q_PROPERTY(int lastExecutedCommandRow READ lastExecutedCommandRow)
205+ Q_PROPERTY(int lastExecutedParametrizedCommandRow READ lastExecutedParametrizedCommandRow)
206+ Q_PROPERTY(bool lastParametrizedCommandCommited READ lastParametrizedCommandCommited)
207+ Q_PROPERTY(QVariantMap activatedActions READ activatedActions)
208
209 public:
210 int lastExecutedToolbarItem() const;
211 QString lastSetAppStackApplicationId() const;
212 QString lastSetQuery() const;
213 int lastExecutedCommandRow() const;
214+ int lastExecutedParametrizedCommandRow() const;
215+ bool lastParametrizedCommandCommited() const;
216+ QVariantMap activatedActions() const;
217
218 Q_INVOKABLE void reset();
219 Q_INVOKABLE int fullScreenToolbarItemValue() const;
220@@ -45,6 +53,9 @@
221 static QString m_lastSetAppStackApplicationId;
222 static QString m_lastSetQuery;
223 static int m_lastExecutedCommandRow;
224+ static int m_lastExecutedParametrizedCommandRow;
225+ static bool m_lastParametrizedCommandCommited;
226+ static QVariantMap m_activatedActions;
227 };
228
229
230
231=== modified file 'tests/qmluitests/tst_Hud.qml'
232--- tests/qmluitests/tst_Hud.qml 2013-03-21 15:58:18 +0000
233+++ tests/qmluitests/tst_Hud.qml 2013-03-22 15:49:31 +0000
234@@ -34,9 +34,12 @@
235 when: windowShown
236
237 function resetToInitialState() {
238+ var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
239+
240 hud.show()
241 hud.resetToInitialState()
242 hudClientStub.reset()
243+ tryCompare(parametrizedActionsPage, "x", hud.width) // Make sure the parametrized page action animation is finished
244 }
245
246 function test_hud_toolbar() {
247@@ -201,6 +204,73 @@
248
249 mouseClick(resultListRepeater.itemAt(1), 0, 0)
250 compare(hudClientStub.lastExecutedCommandRow, 1, "Last executed row was 1")
251+ compare(hud.shown, false, "Should not be shown after executing")
252+ }
253+
254+ function number_of_activated_actions(activatedActionsObject) {
255+ var activatedActions = 0
256+ for(var key in activatedActionsObject) {
257+ ++activatedActions
258+ }
259+ return activatedActions
260+ }
261+
262+ function test_hud_result_suggestion_parametrized_execution_and_back() {
263+ var resultListRepeater = findChild(hud, "resultListRepeater")
264+ var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
265+ var backButton = parametrizedActionsPage.children[1].children[0]
266+ resetToInitialState()
267+
268+ compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden at start")
269+ tryCompare(parametrizedActionsPage, "x", hud.width)
270+
271+ mouseClick(resultListRepeater.itemAt(2), 0, 0)
272+ compare(hudClientStub.lastExecutedCommandRow, -1, "We executed a param action not a regular one")
273+ compare(hudClientStub.lastExecutedParametrizedCommandRow, 2, "Last executed row was 2")
274+ compare(parametrizedActionsPage.shown, true, "Parametrized action page should be shown after executing a parametrized action")
275+ tryCompare(parametrizedActionsPage, "x", 0)
276+
277+ var sliderLabel = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[0]
278+ var slider = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[1]
279+ compare(sliderLabel.text, "Item1Label")
280+ compare(slider.minimumValue, 10)
281+ compare(slider.maximumValue, 80)
282+ compare(slider.live, true)
283+ compare(number_of_activated_actions(hudClientStub.activatedActions), 0)
284+
285+ // Since it's live moving the slider will activate it already
286+ var slider = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[1]
287+ mouseClick(slider, units.gu(1), units.gu(1))
288+ compare(number_of_activated_actions(hudClientStub.activatedActions), 1)
289+ compare(hudClientStub.activatedActions["costAction"], 10)
290+
291+ mouseClick(backButton, 0, 0)
292+ compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden after going back")
293+ compare(hudClientStub.lastParametrizedCommandCommited, false, "Cancelling does not commit")
294+ tryCompare(parametrizedActionsPage, "x", hud.width)
295+ }
296+
297+ function test_hud_result_suggestion_parametrized_execution_and_confirm() {
298+ var resultListRepeater = findChild(hud, "resultListRepeater")
299+ var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
300+ var confirmButton = parametrizedActionsPage.children[1].children[2]
301+ resetToInitialState()
302+
303+ compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden at start")
304+ tryCompare(parametrizedActionsPage, "x", hud.width)
305+
306+ mouseClick(resultListRepeater.itemAt(2), 0, 0)
307+ compare(hudClientStub.lastExecutedCommandRow, -1, "We executed a param action not a regular one")
308+ compare(hudClientStub.lastExecutedParametrizedCommandRow, 2, "Last executed row was 2")
309+ compare(parametrizedActionsPage.shown, true, "Parametrized action page should be shown after executing a parametrized action")
310+ tryCompare(parametrizedActionsPage, "x", 0)
311+ compare(number_of_activated_actions(hudClientStub.activatedActions), 0)
312+
313+ mouseClick(confirmButton, 0, 0)
314+ compare(hud.shown, false, "Should not be shown after executing")
315+ compare(number_of_activated_actions(hudClientStub.activatedActions), 1)
316+ compare(hudClientStub.activatedActions["costAction"], 75)
317+ compare(hudClientStub.lastParametrizedCommandCommited, true, "Confirming does commit")
318 }
319 }
320 }

Subscribers

People subscribed via source and target branches