on xenial help sign in
Fixed issue in laggy indicator autpilot tests Fixes: #1446846

Approved by: Albert Astals Cid

commitffbe66d9059b531644a5d51f9bd474bdce6e6403 authorNick Dedekind <nick.dedekind@canonical.com> dateMon 18 May 2015, 23:04 (11 years ago) parent242ea271e50a77
3 files changed+93−17
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+13−3 tests/autopilot/unity8/indicators/tests/test_action_latency.py+4−2 tests/mocks/indicator-service/mock-indicator-service.c+76−12
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+13−3
@@ -21,6 +21,7 @@
2121
2222import logging
2323import os
24+import threading
2425
2526from autopilot.platform import model
2627
@@ -90,10 +91,19 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
9091 """Greeter should hide when an app is opened"""
9192 process_helpers.lock_unity()
9293
93− application_name = self.launch_fake_app()
94+ # FIXME - this is because the device greeter uses a password.
95+ # Need to be able to selectively enable mocks so that we can use the fake greeter.
96+ def unlock_thread_worker(greeter):
97+ greeter.wait_swiped_away()
98+ process_helpers.unlock_unity()
99+ greeter.created.wait_for(False)
100+
94101 greeter = self.main_window.get_greeter()
95− greeter.wait_swiped_away()
96− process_helpers.unlock_unity()
102+ unlock_thread = threading.Thread(target=unlock_thread_worker, args=(greeter,))
103+ unlock_thread.start()
104+ application_name = self.launch_fake_app()
105+ unlock_thread.join(10)
106+
97107 self.assert_current_focused_application(application_name)
98108
99109 def test_greeter_hides_on_app_focus(self):
tests/autopilot/unity8/indicators/tests/test_action_latency.py+4−2
@@ -70,10 +70,11 @@ class TestServerValueUpdate(TestIndicatorBaseTestCase):
7070 switch_menu = self.indicator_page.get_switch_menu()
7171
7272 switch.change_state()
73+ final_value = switch.checked
7374
7475 self.assertThat(
7576 switch_menu.serverChecked,
76− Eventually(Equals(switch.checked), timeout=20)
77+ Eventually(Equals(final_value), timeout=20)
7778 )
7879
7980 def test_slider_reaches_server_value(self):
@@ -82,6 +83,7 @@ class TestServerValueUpdate(TestIndicatorBaseTestCase):
8283
8384 old_value = slider.value
8485 slider.slide_left()
86+ final_value = slider.value
8587
8688 self.assertThat(
8789 slider_menu.serverValue,
@@ -90,7 +92,7 @@ class TestServerValueUpdate(TestIndicatorBaseTestCase):
9092
9193 self.assertThat(
9294 slider_menu.serverValue,
93− Eventually(Equals(slider.value), timeout=20)
95+ Eventually(Equals(final_value), timeout=20)
9496 )
9597
9698
tests/mocks/indicator-service/mock-indicator-service.c+76−12
@@ -27,8 +27,15 @@ typedef struct
2727 guint actions_export_id;
2828 guint menu_export_id;
2929 int action_delay;
30+ int change_interval;
3031} IndicatorTestService;
3132
33+typedef struct
34+{
35+ GSimpleAction *action;
36+ GVariant* value;
37+} Action;
38+
3239static void
3340bus_acquired (GDBusConnection *connection,
3441 const gchar *name,
@@ -96,10 +103,10 @@ actual_switch (gpointer user_data)
96103 gboolean state = g_variant_get_boolean (v);
97104 GVariant *new_state = g_variant_new_boolean (state == TRUE ? FALSE : TRUE);
98105
99− g_simple_action_set_state(G_SIMPLE_ACTION(action), new_state);
106+ g_simple_action_set_state(action, new_state);
100107
101108 g_variant_unref (v);
102− g_message ("switching");
109+ g_message ("switching %d", state);
103110 return FALSE;
104111}
105112
@@ -120,13 +127,12 @@ activate_switch (GSimpleAction *action,
120127static gboolean
121128actual_slide (gpointer user_data)
122129{
123− GSimpleAction *action = user_data;
124−
125− GVariant* new_state = g_object_get_qdata (G_OBJECT (action), slider_value_quark ());
130+ Action *slide_action = user_data;
126131
127− g_simple_action_set_state(G_SIMPLE_ACTION(action), new_state);
132+ g_simple_action_set_state(G_SIMPLE_ACTION(slide_action->action), slide_action->value);
133+ g_message ("sliding %f", g_variant_get_double(slide_action->value));
134+ free(slide_action);
128135
129− g_message ("switching");
130136 return FALSE;
131137}
132138
@@ -136,10 +142,40 @@ void change_slider (GSimpleAction *action,
136142{
137143 IndicatorTestService *indicator = user_data;
138144
139− g_object_set_qdata (G_OBJECT (action), slider_value_quark (), g_variant_ref(value));
145+ Action* slide_action = malloc(sizeof(Action));
146+ slide_action->action = action;
147+ slide_action->value = g_variant_ref(value);
140148
141− g_timeout_add(indicator->action_delay, actual_slide, action);
142− g_message ("slide delay %.03f", g_variant_get_double(value));
149+ g_timeout_add(indicator->action_delay, actual_slide, slide_action);
150+ g_message ("slide delay %f", g_variant_get_double(value));
151+}
152+
153+static gboolean
154+change_interval (gpointer user_data)
155+{
156+ g_message ("change interval");
157+
158+ IndicatorTestService *indicator = user_data;
159+
160+ GAction* action_switch = g_action_map_lookup_action(G_ACTION_MAP(indicator->actions), "action.switch");
161+ actual_switch(G_SIMPLE_ACTION(action_switch));
162+
163+ GAction* action_checkbox = g_action_map_lookup_action(G_ACTION_MAP(indicator->actions), "action.checkbox");
164+ actual_switch(G_SIMPLE_ACTION(action_checkbox));
165+
166+ GAction* action_accessPoint = g_action_map_lookup_action(G_ACTION_MAP(indicator->actions), "action.accessPoint");
167+ actual_switch(G_SIMPLE_ACTION(action_accessPoint));
168+
169+ GAction* action_slider = g_action_map_lookup_action(G_ACTION_MAP(indicator->actions), "action.slider");
170+ static double old_value = 0.25;
171+ double new_value = old_value == 0.25 ? 0.75 : 0.25;
172+ old_value = new_value;
173+ Action* slide_action = malloc(sizeof(Action));
174+ slide_action->action = G_SIMPLE_ACTION(action_slider);
175+ slide_action->value = g_variant_new_double(new_value);
176+ actual_slide(slide_action);
177+
178+ return TRUE;
143179}
144180
145181int
@@ -147,6 +183,7 @@ main (int argc, char **argv)
147183{
148184 IndicatorTestService indicator = { 0 };
149185 indicator.action_delay = -1;
186+ indicator.change_interval = -1;
150187 GMenuItem *item;
151188 GMenu *submenu;
152189 GActionEntry entries[] = {
@@ -191,6 +228,27 @@ main (int argc, char **argv)
191228 }
192229 break;
193230 }
231+
232+ case 'c':
233+ {
234+ arg += 2;
235+ if (!arg[0] && i < argc-1) {
236+ i++;
237+ int interval = -1;
238+
239+ if (sscanf(argv[i], "%d", &interval) == 1) {
240+ indicator.change_interval = interval;
241+ } else {
242+ printf("Invalid change interval value: %s\n", argv[i]);
243+ help = 1;
244+ }
245+ } else {
246+ printf("Invalid change interval value: %s\n", argv[i]);
247+ help = 1;
248+ }
249+ break;
250+ }
251+
194252 case 'h':
195253 help = 1;
196254 break;
@@ -201,8 +259,9 @@ main (int argc, char **argv)
201259
202260 if (help) {
203261 printf("Usage: %s [<options>]\n"
204− " -t DELAY Action activation delay\n"
205− " -h Show this help text\n"
262+ " -t DELAY Action activation delay\n"
263+ " -c CHANGE_INTERVAL Interval to change action values\n"
264+ " -h Show this help text\n"
206265 , argv[0]);
207266 return 0;
208267 }
@@ -249,6 +308,11 @@ main (int argc, char **argv)
249308 NULL);
250309
251310 loop = g_main_loop_new (NULL, FALSE);
311+
312+ if (indicator.change_interval != -1) {
313+ g_timeout_add(indicator.change_interval, change_interval, &indicator);
314+ }
315+
252316 g_main_loop_run (loop);
253317
254318 g_object_unref (submenu);