on xenial help sign in
Fixed issue in laggy indicator autpilot tests Fixes: #1446846
ffbe66dNick Dedekind
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+13−3
@@ -21,6 +21,7 @@
21
21
22import logging
22import logging
23import os
23import os
24+import threading
24
25
25from autopilot.platform import model
26from autopilot.platform import model
26
27
@@ -90,10 +91,19 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
90 """Greeter should hide when an app is opened"""
91 """Greeter should hide when an app is opened"""
91 process_helpers.lock_unity()
92 process_helpers.lock_unity()
92
93
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+
94 greeter = self.main_window.get_greeter()
101 greeter = self.main_window.get_greeter()
95− greeter.wait_swiped_away()
102+ unlock_thread = threading.Thread(target=unlock_thread_worker, args=(greeter,))
96− process_helpers.unlock_unity()
103+ unlock_thread.start()
104+ application_name = self.launch_fake_app()
105+ unlock_thread.join(10)
106+
97 self.assert_current_focused_application(application_name)
107 self.assert_current_focused_application(application_name)
98
108
99 def test_greeter_hides_on_app_focus(self):
109 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):
70 switch_menu = self.indicator_page.get_switch_menu()
70 switch_menu = self.indicator_page.get_switch_menu()
71
71
72 switch.change_state()
72 switch.change_state()
73+ final_value = switch.checked
73
74
74 self.assertThat(
75 self.assertThat(
75 switch_menu.serverChecked,
76 switch_menu.serverChecked,
76− Eventually(Equals(switch.checked), timeout=20)
77+ Eventually(Equals(final_value), timeout=20)
77 )
78 )
78
79
79 def test_slider_reaches_server_value(self):
80 def test_slider_reaches_server_value(self):
@@ -82,6 +83,7 @@ class TestServerValueUpdate(TestIndicatorBaseTestCase):
82
83
83 old_value = slider.value
84 old_value = slider.value
84 slider.slide_left()
85 slider.slide_left()
86+ final_value = slider.value
85
87
86 self.assertThat(
88 self.assertThat(
87 slider_menu.serverValue,
89 slider_menu.serverValue,
@@ -90,7 +92,7 @@ class TestServerValueUpdate(TestIndicatorBaseTestCase):
90
92
91 self.assertThat(
93 self.assertThat(
92 slider_menu.serverValue,
94 slider_menu.serverValue,
93− Eventually(Equals(slider.value), timeout=20)
95+ Eventually(Equals(final_value), timeout=20)
94 )
96 )
95
97
96
98
tests/mocks/indicator-service/mock-indicator-service.c+76−12
@@ -27,8 +27,15 @@ typedef struct
27 guint actions_export_id;
27 guint actions_export_id;
28 guint menu_export_id;
28 guint menu_export_id;
29 int action_delay;
29 int action_delay;
30+ int change_interval;
30} IndicatorTestService;
31} IndicatorTestService;
31
32
33+typedef struct
34+{
35+ GSimpleAction *action;
36+ GVariant* value;
37+} Action;
38+
32static void
39static void
33bus_acquired (GDBusConnection *connection,
40bus_acquired (GDBusConnection *connection,
34 const gchar *name,
41 const gchar *name,
@@ -96,10 +103,10 @@ actual_switch (gpointer user_data)
96 gboolean state = g_variant_get_boolean (v);
103 gboolean state = g_variant_get_boolean (v);
97 GVariant *new_state = g_variant_new_boolean (state == TRUE ? FALSE : TRUE);
104 GVariant *new_state = g_variant_new_boolean (state == TRUE ? FALSE : TRUE);
98
105
99− g_simple_action_set_state(G_SIMPLE_ACTION(action), new_state);
106+ g_simple_action_set_state(action, new_state);
100
107
101 g_variant_unref (v);
108 g_variant_unref (v);
102− g_message ("switching");
109+ g_message ("switching %d", state);
103 return FALSE;
110 return FALSE;
104}
111}
105
112
@@ -120,13 +127,12 @@ activate_switch (GSimpleAction *action,
120static gboolean
127static gboolean
121actual_slide (gpointer user_data)
128actual_slide (gpointer user_data)
122{
129{
123− GSimpleAction *action = user_data;
130+ Action *slide_action = user_data;
124−
125− GVariant* new_state = g_object_get_qdata (G_OBJECT (action), slider_value_quark ());
126
131
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);
128
135
129− g_message ("switching");
130 return FALSE;
136 return FALSE;
131}
137}
132
138
@@ -136,10 +142,40 @@ void change_slider (GSimpleAction *action,
136{
142{
137 IndicatorTestService *indicator = user_data;
143 IndicatorTestService *indicator = user_data;
138
144
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);
140
148
141− g_timeout_add(indicator->action_delay, actual_slide, action);
149+ g_timeout_add(indicator->action_delay, actual_slide, slide_action);
142− g_message ("slide delay %.03f", g_variant_get_double(value));
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;
143}
179}
144
180
145int
181int
@@ -147,6 +183,7 @@ main (int argc, char **argv)
147{
183{
148 IndicatorTestService indicator = { 0 };
184 IndicatorTestService indicator = { 0 };
149 indicator.action_delay = -1;
185 indicator.action_delay = -1;
186+ indicator.change_interval = -1;
150 GMenuItem *item;
187 GMenuItem *item;
151 GMenu *submenu;
188 GMenu *submenu;
152 GActionEntry entries[] = {
189 GActionEntry entries[] = {
@@ -191,6 +228,27 @@ main (int argc, char **argv)
191 }
228 }
192 break;
229 break;
193 }
230 }
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+
194 case 'h':
252 case 'h':
195 help = 1;
253 help = 1;
196 break;
254 break;
@@ -201,8 +259,9 @@ main (int argc, char **argv)
201
259
202 if (help) {
260 if (help) {
203 printf("Usage: %s [<options>]\n"
261 printf("Usage: %s [<options>]\n"
204− " -t DELAY Action activation delay\n"
262+ " -t DELAY Action activation delay\n"
263+ " -c CHANGE_INTERVAL Interval to change action values\n"
205− " -h Show this help text\n"
264+ " -h Show this help text\n"
206 , argv[0]);
265 , argv[0]);
207 return 0;
266 return 0;
208 }
267 }
@@ -249,6 +308,11 @@ main (int argc, char **argv)
249 NULL);
308 NULL);
250
309
251 loop = g_main_loop_new (NULL, FALSE);
310 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+
252 g_main_loop_run (loop);
316 g_main_loop_run (loop);
253
317
254 g_object_unref (submenu);
318 g_object_unref (submenu);