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
=== modified file 'Hud/Hud.qml'
--- Hud/Hud.qml 2013-03-21 15:54:40 +0000
+++ Hud/Hud.qml 2013-03-22 15:49:31 +0000
@@ -485,6 +485,7 @@
485485
486 HudParametrizedActionsPage {486 HudParametrizedActionsPage {
487 id: parametrizedActionsPage487 id: parametrizedActionsPage
488 objectName: "parametrizedActionsPage"
488 property bool shown: false489 property bool shown: false
489490
490 anchors.bottom: parent.bottom491 anchors.bottom: parent.bottom
491492
=== modified file 'tests/qmluitests/qml/HudClient/fake_libhud_client.cpp'
--- tests/qmluitests/qml/HudClient/fake_libhud_client.cpp 2013-03-21 10:24:56 +0000
+++ tests/qmluitests/qml/HudClient/fake_libhud_client.cpp 2013-03-22 15:49:31 +0000
@@ -41,6 +41,8 @@
4141
42DeeModel *resultsModel = 0;42DeeModel *resultsModel = 0;
43DeeModel *appStackModel = 0;43DeeModel *appStackModel = 0;
44GMenuModel *parametrizedActionModel = 0;
45GActionGroup *parametrizedActionGroup = 0;
4446
45HudClientQuery *hud_client_query_new(const gchar *query)47HudClientQuery *hud_client_query_new(const gchar *query)
46{48{
@@ -75,11 +77,13 @@
75 columns[0] = g_variant_new_variant(g_variant_new_uint64(2));77 columns[0] = g_variant_new_variant(g_variant_new_uint64(2));
76 columns[1] = g_variant_new_string("Foo");78 columns[1] = g_variant_new_string("Foo");
77 columns[3] = g_variant_new_string("Show Foo");79 columns[3] = g_variant_new_string("Show Foo");
80 columns[7] = g_variant_new_boolean(true);
78 dee_model_append_row(resultsModel, columns);81 dee_model_append_row(resultsModel, columns);
7982
80 columns[0] = g_variant_new_variant(g_variant_new_uint64(3));83 columns[0] = g_variant_new_variant(g_variant_new_uint64(3));
81 columns[1] = g_variant_new_string("Bar");84 columns[1] = g_variant_new_string("Bar");
82 columns[3] = g_variant_new_string("Show Bar");85 columns[3] = g_variant_new_string("Show Bar");
86 columns[7] = g_variant_new_boolean(false);
83 dee_model_append_row(resultsModel, columns);87 dee_model_append_row(resultsModel, columns);
8488
85 columns[0] = g_variant_new_variant(g_variant_new_uint64(4));89 columns[0] = g_variant_new_variant(g_variant_new_uint64(4));
@@ -132,13 +136,98 @@
132 Q_UNUSED(timestamp);136 Q_UNUSED(timestamp);
133 for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {137 for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {
134 DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);138 DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);
135 GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);139 if (!dee_model_get_bool(resultsModel, iter, 7)) {
136 if (g_variant_equal (command_key, it_command)) {140 GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
137 HudClientStub::m_lastExecutedCommandRow = i;141 if (g_variant_equal (command_key, it_command)) {
142 HudClientStub::m_lastExecutedCommandRow = i;
143 g_variant_unref(it_command);
144 return;
145 }
138 g_variant_unref(it_command);146 g_variant_unref(it_command);
139 return;
140 }147 }
141 g_variant_unref(it_command);
142 }148 }
143 HudClientStub::m_lastExecutedCommandRow = -1;149 HudClientStub::m_lastExecutedCommandRow = -1;
144}150}
151
152HudClientParam *hud_client_query_execute_param_command(HudClientQuery *cquery, GVariant *command_key, guint timestamp)
153{
154 Q_UNUSED(cquery);
155 Q_UNUSED(timestamp);
156 for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {
157 DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);
158 if (dee_model_get_bool(resultsModel, iter, 7)) {
159 GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
160 if (g_variant_equal (command_key, it_command)) {
161 HudClientStub::m_lastExecutedParametrizedCommandRow = i;
162 g_variant_unref(it_command);
163 // No need to create a real HudClientParam since it's always passed down to us
164 return (HudClientParam *)g_object_new(G_TYPE_OBJECT, NULL);
165 }
166 g_variant_unref(it_command);
167 }
168 }
169 HudClientStub::m_lastExecutedParametrizedCommandRow = -1;
170 return NULL;
171}
172
173GMenuModel *hud_client_param_get_model(HudClientParam *param)
174{
175 Q_UNUSED(param);
176
177 if (!parametrizedActionModel) {
178 GMenu *menu = g_menu_new();
179 GMenuItem *item = g_menu_item_new("Item1Label", NULL);
180 g_menu_item_set_attribute_value(item, "parameter-type", g_variant_new_string("slider"));
181 g_menu_item_set_attribute_value(item, "min", g_variant_new_double(10));
182 g_menu_item_set_attribute_value(item, "max", g_variant_new_double(80));
183 g_menu_item_set_attribute_value(item, "live", g_variant_new_boolean(true));
184 g_menu_item_set_attribute_value(item, "value", g_variant_new_double(75));
185 g_menu_item_set_attribute_value(item, "action", g_variant_new_string("costAction"));
186 g_menu_append_item (menu, item);
187
188 parametrizedActionModel = G_MENU_MODEL(menu);
189 }
190
191 return parametrizedActionModel;
192}
193
194void hud_client_param_send_cancel(HudClientParam *param)
195{
196 Q_UNUSED(param);
197 g_clear_object(&parametrizedActionModel);
198 parametrizedActionModel = 0;
199 HudClientStub::m_lastParametrizedCommandCommited = false;
200}
201
202static void on_signal_activated (GSimpleAction *action, GVariant *parameter, gpointer /*user_data*/)
203{
204 // Only double for the moment
205 HudClientStub::m_activatedActions.insert(g_action_get_name(G_ACTION(action)), QVariant(g_variant_get_double(parameter)));
206}
207
208GActionGroup *hud_client_param_get_actions(HudClientParam *param)
209{
210 Q_UNUSED(param);
211 if (!parametrizedActionGroup) {
212 GSimpleActionGroup *actionGroup = g_simple_action_group_new();
213 GSimpleAction *action = g_simple_action_new("costAction", G_VARIANT_TYPE_DOUBLE);
214 g_simple_action_group_insert(actionGroup, G_ACTION(action));
215
216 g_signal_connect (action, "activate", G_CALLBACK (on_signal_activated), NULL);
217
218
219 parametrizedActionGroup = G_ACTION_GROUP(actionGroup);
220 }
221
222 return parametrizedActionGroup;
223}
224
225void hud_client_param_send_commit(HudClientParam *param)
226{
227 Q_UNUSED(param);
228 g_object_unref(parametrizedActionGroup);
229 parametrizedActionGroup = 0;
230 g_clear_object(&parametrizedActionModel);
231 parametrizedActionModel = 0;
232 HudClientStub::m_lastParametrizedCommandCommited = true;
233}
145234
=== modified file 'tests/qmluitests/qml/HudClient/libhud_client_stub.cpp'
--- tests/qmluitests/qml/HudClient/libhud_client_stub.cpp 2013-03-21 15:57:43 +0000
+++ tests/qmluitests/qml/HudClient/libhud_client_stub.cpp 2013-03-22 15:49:31 +0000
@@ -22,6 +22,9 @@
22QString HudClientStub::m_lastSetAppStackApplicationId;22QString HudClientStub::m_lastSetAppStackApplicationId;
23QString HudClientStub::m_lastSetQuery;23QString HudClientStub::m_lastSetQuery;
24int HudClientStub::m_lastExecutedCommandRow;24int HudClientStub::m_lastExecutedCommandRow;
25int HudClientStub::m_lastExecutedParametrizedCommandRow;
26bool HudClientStub::m_lastParametrizedCommandCommited;
27QVariantMap HudClientStub::m_activatedActions;
2528
26int HudClientStub::lastExecutedToolbarItem() const29int HudClientStub::lastExecutedToolbarItem() const
27{30{
@@ -43,12 +46,30 @@
43 return m_lastExecutedCommandRow;46 return m_lastExecutedCommandRow;
44}47}
4548
49int HudClientStub::lastExecutedParametrizedCommandRow() const
50{
51 return m_lastExecutedParametrizedCommandRow;
52}
53
54bool HudClientStub::lastParametrizedCommandCommited() const
55{
56 return m_lastParametrizedCommandCommited;
57}
58
59QVariantMap HudClientStub::activatedActions() const
60{
61 return m_activatedActions;
62}
63
46void HudClientStub::reset()64void HudClientStub::reset()
47{65{
48 m_lastExecutedToolbarItem = -1;66 m_lastExecutedToolbarItem = -1;
49 m_lastSetAppStackApplicationId.clear();67 m_lastSetAppStackApplicationId.clear();
50 m_lastSetQuery.clear();68 m_lastSetQuery.clear();
51 m_lastExecutedCommandRow = -1;69 m_lastExecutedCommandRow = -1;
70 m_lastExecutedParametrizedCommandRow = -1;
71 m_lastParametrizedCommandCommited = false;
72 m_activatedActions.clear();
52}73}
5374
54int HudClientStub::fullScreenToolbarItemValue() const75int HudClientStub::fullScreenToolbarItemValue() const
5576
=== modified file 'tests/qmluitests/qml/HudClient/libhud_client_stub.h'
--- tests/qmluitests/qml/HudClient/libhud_client_stub.h 2013-03-21 15:57:43 +0000
+++ tests/qmluitests/qml/HudClient/libhud_client_stub.h 2013-03-22 15:49:31 +0000
@@ -19,6 +19,8 @@
1919
20#include <QObject>20#include <QObject>
2121
22#include <QVariantMap>
23
22class HudClientStub : public QObject24class HudClientStub : public QObject
23{25{
24 Q_OBJECT26 Q_OBJECT
@@ -27,12 +29,18 @@
27 Q_PROPERTY(QString lastSetAppStackApplicationId READ lastSetAppStackApplicationId)29 Q_PROPERTY(QString lastSetAppStackApplicationId READ lastSetAppStackApplicationId)
28 Q_PROPERTY(QString lastSetQuery READ lastSetQuery)30 Q_PROPERTY(QString lastSetQuery READ lastSetQuery)
29 Q_PROPERTY(int lastExecutedCommandRow READ lastExecutedCommandRow)31 Q_PROPERTY(int lastExecutedCommandRow READ lastExecutedCommandRow)
32 Q_PROPERTY(int lastExecutedParametrizedCommandRow READ lastExecutedParametrizedCommandRow)
33 Q_PROPERTY(bool lastParametrizedCommandCommited READ lastParametrizedCommandCommited)
34 Q_PROPERTY(QVariantMap activatedActions READ activatedActions)
3035
31public:36public:
32 int lastExecutedToolbarItem() const;37 int lastExecutedToolbarItem() const;
33 QString lastSetAppStackApplicationId() const;38 QString lastSetAppStackApplicationId() const;
34 QString lastSetQuery() const;39 QString lastSetQuery() const;
35 int lastExecutedCommandRow() const;40 int lastExecutedCommandRow() const;
41 int lastExecutedParametrizedCommandRow() const;
42 bool lastParametrizedCommandCommited() const;
43 QVariantMap activatedActions() const;
3644
37 Q_INVOKABLE void reset();45 Q_INVOKABLE void reset();
38 Q_INVOKABLE int fullScreenToolbarItemValue() const;46 Q_INVOKABLE int fullScreenToolbarItemValue() const;
@@ -45,6 +53,9 @@
45 static QString m_lastSetAppStackApplicationId;53 static QString m_lastSetAppStackApplicationId;
46 static QString m_lastSetQuery;54 static QString m_lastSetQuery;
47 static int m_lastExecutedCommandRow;55 static int m_lastExecutedCommandRow;
56 static int m_lastExecutedParametrizedCommandRow;
57 static bool m_lastParametrizedCommandCommited;
58 static QVariantMap m_activatedActions;
48};59};
4960
5061
5162
=== modified file 'tests/qmluitests/tst_Hud.qml'
--- tests/qmluitests/tst_Hud.qml 2013-03-21 15:58:18 +0000
+++ tests/qmluitests/tst_Hud.qml 2013-03-22 15:49:31 +0000
@@ -34,9 +34,12 @@
34 when: windowShown34 when: windowShown
3535
36 function resetToInitialState() {36 function resetToInitialState() {
37 var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
38
37 hud.show()39 hud.show()
38 hud.resetToInitialState()40 hud.resetToInitialState()
39 hudClientStub.reset()41 hudClientStub.reset()
42 tryCompare(parametrizedActionsPage, "x", hud.width) // Make sure the parametrized page action animation is finished
40 }43 }
4144
42 function test_hud_toolbar() {45 function test_hud_toolbar() {
@@ -201,6 +204,73 @@
201204
202 mouseClick(resultListRepeater.itemAt(1), 0, 0)205 mouseClick(resultListRepeater.itemAt(1), 0, 0)
203 compare(hudClientStub.lastExecutedCommandRow, 1, "Last executed row was 1")206 compare(hudClientStub.lastExecutedCommandRow, 1, "Last executed row was 1")
207 compare(hud.shown, false, "Should not be shown after executing")
208 }
209
210 function number_of_activated_actions(activatedActionsObject) {
211 var activatedActions = 0
212 for(var key in activatedActionsObject) {
213 ++activatedActions
214 }
215 return activatedActions
216 }
217
218 function test_hud_result_suggestion_parametrized_execution_and_back() {
219 var resultListRepeater = findChild(hud, "resultListRepeater")
220 var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
221 var backButton = parametrizedActionsPage.children[1].children[0]
222 resetToInitialState()
223
224 compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden at start")
225 tryCompare(parametrizedActionsPage, "x", hud.width)
226
227 mouseClick(resultListRepeater.itemAt(2), 0, 0)
228 compare(hudClientStub.lastExecutedCommandRow, -1, "We executed a param action not a regular one")
229 compare(hudClientStub.lastExecutedParametrizedCommandRow, 2, "Last executed row was 2")
230 compare(parametrizedActionsPage.shown, true, "Parametrized action page should be shown after executing a parametrized action")
231 tryCompare(parametrizedActionsPage, "x", 0)
232
233 var sliderLabel = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[0]
234 var slider = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[1]
235 compare(sliderLabel.text, "Item1Label")
236 compare(slider.minimumValue, 10)
237 compare(slider.maximumValue, 80)
238 compare(slider.live, true)
239 compare(number_of_activated_actions(hudClientStub.activatedActions), 0)
240
241 // Since it's live moving the slider will activate it already
242 var slider = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[1]
243 mouseClick(slider, units.gu(1), units.gu(1))
244 compare(number_of_activated_actions(hudClientStub.activatedActions), 1)
245 compare(hudClientStub.activatedActions["costAction"], 10)
246
247 mouseClick(backButton, 0, 0)
248 compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden after going back")
249 compare(hudClientStub.lastParametrizedCommandCommited, false, "Cancelling does not commit")
250 tryCompare(parametrizedActionsPage, "x", hud.width)
251 }
252
253 function test_hud_result_suggestion_parametrized_execution_and_confirm() {
254 var resultListRepeater = findChild(hud, "resultListRepeater")
255 var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
256 var confirmButton = parametrizedActionsPage.children[1].children[2]
257 resetToInitialState()
258
259 compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden at start")
260 tryCompare(parametrizedActionsPage, "x", hud.width)
261
262 mouseClick(resultListRepeater.itemAt(2), 0, 0)
263 compare(hudClientStub.lastExecutedCommandRow, -1, "We executed a param action not a regular one")
264 compare(hudClientStub.lastExecutedParametrizedCommandRow, 2, "Last executed row was 2")
265 compare(parametrizedActionsPage.shown, true, "Parametrized action page should be shown after executing a parametrized action")
266 tryCompare(parametrizedActionsPage, "x", 0)
267 compare(number_of_activated_actions(hudClientStub.activatedActions), 0)
268
269 mouseClick(confirmButton, 0, 0)
270 compare(hud.shown, false, "Should not be shown after executing")
271 compare(number_of_activated_actions(hudClientStub.activatedActions), 1)
272 compare(hudClientStub.activatedActions["costAction"], 75)
273 compare(hudClientStub.lastParametrizedCommandCommited, true, "Confirming does commit")
204 }274 }
205 }275 }
206}276}

Subscribers

People subscribed via source and target branches