on xenial help sign in
renames + test fixes
233109fNick Dedekind
CMakeLists.txt+1−1
@@ -106,7 +106,7 @@ set(SHELL_APP unity8)
106set(DASH_APP unity8-dash)
106set(DASH_APP unity8-dash)
107set(SCOPE_TOOL unity-scope-tool)
107set(SCOPE_TOOL unity-scope-tool)
108set(INDICATORS_CLIENT_APP indicators-client)
108set(INDICATORS_CLIENT_APP indicators-client)
109−set(INDICATOR_TEST_SERVICE_APP unity-indicator-test-service)
109+set(MOCK_INDICATOR_SERVICE_APP unity-mock-indicator-service)
110
110
111include_directories(
111include_directories(
112 ${CMAKE_SOURCE_DIR}/include
112 ${CMAKE_SOURCE_DIR}/include
data/CMakeLists.txt−8
@@ -11,13 +11,5 @@ install(FILES
11 DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
11 DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
12 )
12 )
13
13
14−# install upstart config files
15−install(FILES
16− ${SHELL_APP}.conf
17− ${DASH_APP}.conf
18− ${INDICATOR_TEST_SERVICE_APP}.conf
19− DESTINATION ${CMAKE_INSTALL_DATADIR}/upstart/sessions
20− )
21−
22install(FILES com.canonical.Unity8.gschema.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas)
14install(FILES com.canonical.Unity8.gschema.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas)
23install(FILES unity8-dash.url-dispatcher DESTINATION ${CMAKE_INSTALL_DATADIR}/url-dispatcher/urls)
15install(FILES unity8-dash.url-dispatcher DESTINATION ${CMAKE_INSTALL_DATADIR}/url-dispatcher/urls)
data/unity-indicator-test-service.confdeleted−7
@@ -1,7 +0,0 @@
1−description "Unity Shell v8 Test Indicator"
2−author "Nick Dedekind <nick.dedekind@canonical.com>"
3−
4−respawn
5−respawn limit 2 10
6−
7−exec ${BINARY:-unity-indicator-test-service} $ARGS
data/unity-mock-indicator-service.confnew file+7
@@ -0,0 +1,7 @@
1+description "Unity Shell v8 Mock Indicator"
2+author "Nick Dedekind <nick.dedekind@canonical.com>"
3+
4+respawn
5+respawn limit 2 10
6+
7+exec ${BINARY:-unity-mock-indicator-service} $ARGS
debian/indicators-client.install−1
@@ -1,3 +1,2 @@
1−data/indicators-client.conf usr/share/upstart/sessions/
2usr/share/applications/indicators-client.desktop
1usr/share/applications/indicators-client.desktop
3/usr/bin/indicators-client
2/usr/bin/indicators-client
debian/unity8-autopilot.install+2−2
@@ -1,4 +1,4 @@
1−data/unity-indicator-test-service.conf usr/share/upstart/sessions/
1+data/unity-mock-indicator-service.conf usr/share/upstart/sessions/
2−usr/bin/unity-indicator-test-service
2+usr/bin/unity-mock-indicator-service
3usr/lib/python*/*/unity*
3usr/lib/python*/*/unity*
4usr/share/unity8/unlock-device
4usr/share/unity8/unlock-device
src/Panel/Indicators/CMakeLists.txt−1
@@ -1,2 +1 @@
1add_subdirectory(client)
1add_subdirectory(client)
2−add_subdirectory(indicator-test-service)
src/Panel/Indicators/indicator-test-service/CMakeLists.txtdeleted−24
@@ -1,24 +0,0 @@
1−project(indicator-test-service)
2−pkg_search_module(GIO REQUIRED gio-2.0)
3−
4−set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
5−
6−include_directories(
7− ${CMAKE_CURRENT_SOURCE_DIR}
8− ${GIO_INCLUDE_DIRS}
9−)
10−
11−set(INDICATOR_TEST_SERVICE_SRC
12− indicator-test-service.c
13−)
14−
15−add_executable(${INDICATOR_TEST_SERVICE_APP}
16− ${INDICATOR_TEST_SERVICE_SRC}
17−)
18−
19−target_link_libraries(${INDICATOR_TEST_SERVICE_APP} ${GIO_LDFLAGS})
20−
21−set_target_properties(${INDICATOR_TEST_SERVICE_APP} PROPERTIES COMPILE_FLAGS -fPIC)
22−
23−install(TARGETS ${INDICATOR_TEST_SERVICE_APP}
24− RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
tests/autopilot/unity8/fixture_setup.py+17−7
@@ -22,7 +22,10 @@ import subprocess
22
22
23from autopilot import introspection
23from autopilot import introspection
24
24
25−from unity8 import process_helpers
25+from unity8 import (
26+ get_binary_path,
27+ process_helpers
28+)
26from unity8.shell import emulators
29from unity8.shell import emulators
27
30
28
31
@@ -101,31 +104,38 @@ class LaunchTestIndicatorService(fixtures.Fixture):
101
104
102 """Fixture to launch the indicator test service."""
105 """Fixture to launch the indicator test service."""
103
106
104− def __init__(self, binary_path, variables):
107+ def __init__(self, variables, ensure_not_running=True):
105 """Initialize an instance.
108 """Initialize an instance.
106
109
107− :param str binary_path: The path to the indicator test app binary.
108 :param variables: The variables to use when launching the app.
110 :param variables: The variables to use when launching the app.
109 :type variables: A dictionary.
111 :type variables: A dictionary.
112+ :param boolean ensure_not_running: Make sure service is not running
110
113
111 """
114 """
112 super(LaunchTestIndicatorService, self).__init__()
115 super(LaunchTestIndicatorService, self).__init__()
113− self.binary_path = binary_path
114 self.variables = variables
116 self.variables = variables
117+ self.ensure_not_running = ensure_not_running
115
118
116 def setUp(self):
119 def setUp(self):
117 super(LaunchTestIndicatorService, self).setUp()
120 super(LaunchTestIndicatorService, self).setUp()
121+ if self.ensure_not_running:
122+ self.ensure_service_not_running()
118 self.addCleanup(self.stop_service)
123 self.addCleanup(self.stop_service)
119 self.application_proxy = self.launch_service()
124 self.application_proxy = self.launch_service()
120
125
121 def launch_service(self):
126 def launch_service(self):
127+ binary_path = get_binary_path('unity-mock-indicator-service')
122− binary_arg = 'BINARY={}'.format(self.binary_path)
128+ binary_arg = 'BINARY={}'.format(binary_path)
123 testability_arg = 'QT_LOAD_TESTABILITY={}'.format(1)
129 testability_arg = 'QT_LOAD_TESTABILITY={}'.format(1)
124 env_args = [
130 env_args = [
125 '{}={}'.format(key, value) for key, value in self.variables.items()
131 '{}={}'.format(key, value) for key, value in self.variables.items()
126 ]
132 ]
127 all_args = [binary_arg, testability_arg] + env_args
133 all_args = [binary_arg, testability_arg] + env_args
128− process_helpers.start_job('unity-indicator-test-service', *all_args)
134+ process_helpers.start_job('unity-mock-indicator-service', *all_args)
129
135
130 def stop_service(self):
136 def stop_service(self):
131− process_helpers.stop_job('unity-indicator-test-service')
137+ process_helpers.stop_job('unity-mock-indicator-service')
138+
139+ def ensure_service_not_running(self):
140+ if process_helpers.is_job_running('unity-mock-indicator-service'):
141+ self.stop_service()
tests/autopilot/unity8/indicators/__init__.py+46−10
@@ -135,19 +135,19 @@ class DisplayIndicatorPage(IndicatorPage):
135class TestIndicator(Indicator):
135class TestIndicator(Indicator):
136
136
137 def __init__(self, main_window):
137 def __init__(self, main_window):
138− super(TestIndicator, self).__init__(main_window, 'indicator-test')
138+ super(TestIndicator, self).__init__(main_window, 'indicator-mock')
139 self._main_window = main_window
139 self._main_window = main_window
140
140
141
141
142class TestIndicatorPage(IndicatorPage):
142class TestIndicatorPage(IndicatorPage):
143
143
144− """Autopilot helper for the test indicator page."""
144+ """Autopilot helper for the mock indicator page."""
145
145
146 @classmethod
146 @classmethod
147 def validate_dbus_object(cls, path, state):
147 def validate_dbus_object(cls, path, state):
148 name = introspection.get_classname_from_path(path)
148 name = introspection.get_classname_from_path(path)
149 if name == b'IndicatorPage':
149 if name == b'IndicatorPage':
150− if state['objectName'][1] == 'indicator-test-page':
150+ if state['objectName'][1] == 'indicator-mock-page':
151 return True
151 return True
152 return False
152 return False
153
153
@@ -155,14 +155,50 @@ class TestIndicatorPage(IndicatorPage):
155 return self.select_single(
155 return self.select_single(
156 ubuntuuitoolkit.CheckBox, objectName='switcher')
156 ubuntuuitoolkit.CheckBox, objectName='switcher')
157
157
158− def get_checkbox(self):
159− return self.select_single(
160− ubuntuuitoolkit.CheckBox, objectName='checkbox')
161−
162 def get_switch_menu(self):
158 def get_switch_menu(self):
163 return self.select_single(
159 return self.select_single(
164 'SwitchMenu', objectName='indicator.action.switch')
160 'SwitchMenu', objectName='indicator.action.switch')
165
161
166− def get_checkbox_menu(self):
162+ def get_slider(self):
167− return self.select_single(
163+ return self.select_single(objectName='slider')
164+
165+ def get_slider_menu(self):
168− 'CheckableMenu', objectName='indicator.action.check')
166+ return self.select_single(objectName='indicator.action.slider')
167+
168+
169+class Slider(emulators.UnityEmulatorBase):
170+
171+ """Autopilot helper for the Slider component."""
172+
173+ # XXX Because of https://bugs.launchpad.net/autopilot-qt/+bug/1341671
174+ # we need to make sure it does not match in any selection.
175+ # --elopio - 2015-01-20
176+
177+ @classmethod
178+ def validate_dbus_object(cls, path, state):
179+ name = introspection.get_classname_from_path(path)
180+ if name == b'Slider':
181+ return True
182+ return False
183+
184+ def slide_left(self, timeout=10):
185+ x, y, width, height = self.globalRect
186+
187+ rate = 5
188+ start_x = x + width/2
189+ start_y = stop_y = y + height/2
190+ stop_x = x
191+
192+ self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
193+ self.value.wait_for(self.minimumValue, timeout);
194+
195+ def slide_right(self, timeout=10):
196+ x, y, width, height = self.globalRect
197+
198+ rate = 5
199+ start_x = x + width/2
200+ start_y = stop_y = y + height/2
201+ stop_x = x + width
202+
203+ self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
204+ self.value.wait_for(self.maximumValue, timeout);
tests/autopilot/unity8/indicators/tests/__init__.py+1−1
@@ -24,7 +24,7 @@ from unity8.shell import tests
24
24
25class IndicatorTestCase(tests.UnityTestCase):
25class IndicatorTestCase(tests.UnityTestCase):
26
26
27− device_emulation_scenarios = tests._get_device_emulation_scenarios('Nexus4')
27+ device_emulation_scenarios = tests._get_device_emulation_scenarios()
28
28
29 def setUp(self):
29 def setUp(self):
30 super(IndicatorTestCase, self).setUp()
30 super(IndicatorTestCase, self).setUp()
tests/autopilot/unity8/indicators/tests/test_action_latency.pynew file+236
@@ -0,0 +1,236 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Indicators Autopilot Test Suite
4+# Copyright (C) 2015 Canonical
5+#
6+# This program is free software: you can redistribute it and/or modify
7+# it under the terms of the GNU General Public License as published by
8+# the Free Software Foundation, either version 3 of the License, or
9+# (at your option) any later version.
10+#
11+# This program is distributed in the hope that it will be useful,
12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+# GNU General Public License for more details.
15+#
16+# You should have received a copy of the GNU General Public License
17+# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+from testscenarios import multiply_scenarios
20+
21+from unity8 import (
22+ fixture_setup,
23+ indicators,
24+ process_helpers
25+)
26+from unity8.shell import tests
27+from unity8.indicators import tests
28+
29+from autopilot.matchers import Eventually
30+from testtools.matchers import Equals, NotEquals
31+import time
32+
33+
34+class TestIndicatorBaseTestCase(tests.IndicatorTestCase):
35+
36+ scenarios = [ tests.IndicatorTestCase.device_emulation_scenarios[0] ]
37+
38+ def setUp(self):
39+ super(TestIndicatorBaseTestCase, self).setUp()
40+
41+ environment = {}
42+ environment['ARGS'] = '-t {0}'\
43+ .format(self.action_delay)
44+ self.launch_indicator_service(environment)
45+
46+ # wait for the indicator to appear in unity
47+ self.indicator = indicators.TestIndicator(self.main_window)
48+ self.assertThat(
49+ self.indicator.is_indicator_icon_visible(),
50+ Eventually(Equals(True), timeout=20)
51+ )
52+ self.indicator_page = self.indicator.open()
53+
54+ def launch_indicator_service(self, variables):
55+ launch_service_fixture = fixture_setup.LaunchTestIndicatorService(variables)
56+ self.useFixture(launch_service_fixture)
57+
58+
59+class TestServerValueUpdate(TestIndicatorBaseTestCase):
60+
61+ """Test that an action causes the server to update"""
62+
63+ time_scenarios = [
64+ ('Low', dict(action_delay=0)),
65+ ('Medium', dict(action_delay=2500)),
66+ ('High', dict(action_delay=8000)),
67+ ]
68+ scenarios = multiply_scenarios(
69+ time_scenarios,
70+ TestIndicatorBaseTestCase.scenarios
71+ )
72+
73+ def test_switch_reaches_server_value(self):
74+ switch = self.indicator_page.get_switcher()
75+ switch_menu = self.indicator_page.get_switch_menu()
76+
77+ switch.change_state()
78+
79+ self.assertThat(
80+ switch_menu.serverChecked,
81+ Eventually(Equals(switch.checked), timeout=20)
82+ )
83+
84+ def test_slider_reaches_server_value(self):
85+ slider = self.indicator_page.get_slider()
86+ slider_menu = self.indicator_page.get_slider_menu()
87+
88+ old_value = slider.value
89+ slider.slide_left()
90+
91+ self.assertThat(
92+ slider_menu.serverValue,
93+ Eventually(NotEquals(old_value), timeout=20)
94+ )
95+
96+ self.assertThat(
97+ slider_menu.serverValue,
98+ Eventually(Equals(slider.value), timeout=20)
99+ )
100+
101+class TestBuffering(TestIndicatorBaseTestCase):
102+
103+ """Test that switching multiple times will buffer activations
104+
105+ See https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1390136 .
106+ """
107+ action_delay = 2500
108+
109+ def test_buffered_switch(self):
110+
111+ switch = self.indicator_page.get_switcher()
112+ switch.change_state()
113+ intermediate_value = switch.checked;
114+
115+ # will buffer change until it receives the change from server
116+ switch.change_state()
117+ final_value = switch.checked;
118+
119+ # backend will respond to first switch.
120+ switch_menu = self.indicator_page.get_switch_menu()
121+ self.assertThat(
122+ switch_menu.serverChecked,
123+ Eventually(Equals(intermediate_value), timeout=20)
124+ )
125+ # The buffered activation should have gone to server now.
126+
127+ # front-end should not change as a result of server update while it is buffered
128+ self.assertThat(
129+ switch.checked,
130+ Equals(final_value)
131+ )
132+
133+ # server will respond to the second activate
134+ self.assertThat(
135+ switch_menu.serverChecked,
136+ Eventually(Equals(final_value), timeout=20)
137+ )
138+
139+ # make sure we've got the server value set.
140+ self.assertThat(
141+ switch.checked,
142+ Equals(switch_menu.serverChecked)
143+ )
144+
145+ def test_buffered_slider(self):
146+
147+ slider = self.indicator_page.get_slider()
148+ original_value = slider.value;
149+ slider.slide_left()
150+
151+ # will buffer change until it receives the change from server
152+ slider.slide_right()
153+ final_value = slider.value;
154+
155+ # backend will respond to first slider. Since it's a live slider it'll probably
156+ # be a random value along the slide.
157+ slider_menu = self.indicator_page.get_slider_menu()
158+ self.assertThat(
159+ slider_menu.serverValue,
160+ Eventually(NotEquals(original_value), timeout=20)
161+ )
162+ # It wont yet have reached the final value due to the buffering
163+ # Second activate should have gone out by now
164+ self.assertThat(
165+ slider_menu.serverValue,
166+ NotEquals(final_value)
167+ )
168+
169+ # front-end should not change as a result of server update while it is buffered
170+ self.assertThat(
171+ slider.value,
172+ Equals(final_value)
173+ )
174+
175+ # server will respond to the second activate
176+ self.assertThat(
177+ slider_menu.serverValue,
178+ Eventually(Equals(final_value), timeout=20)
179+ )
180+
181+ # make sure we've got the server value set.
182+ self.assertThat(
183+ slider.value,
184+ Equals(slider_menu.serverValue)
185+ )
186+
187+
188+class TestClientRevertsToServerValue(TestIndicatorBaseTestCase):
189+
190+ """Test that an action which does not respond in time will revert
191+ to original value if not actioned in time.
192+
193+ See https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1390136 .
194+ """
195+ action_delay = -1 # never action.
196+
197+ def test_switch_reverts_on_late_response(self):
198+
199+ switch = self.indicator_page.get_switcher()
200+ switch_menu = self.indicator_page.get_switch_menu()
201+
202+ original_value = switch.checked;
203+ switch.change_state()
204+
205+ # switch should revert to original value after 5 seconds (30 seconds in real usage)
206+ self.assertThat(
207+ switch.checked,
208+ Eventually(Equals(original_value), timeout=20)
209+ )
210+
211+ # make sure we've got the server value set.
212+ self.assertThat(
213+ switch.checked,
214+ Equals(switch_menu.serverChecked)
215+ )
216+
217+ def test_slider_reverts_on_late_response(self):
218+
219+ slider = self.indicator_page.get_slider()
220+ slider_menu = self.indicator_page.get_slider_menu()
221+
222+ original_value = slider.value;
223+ slider.slide_left()
224+
225+ # slider should revert to original value after 5 seconds (30 seconds in real usage)
226+ self.assertThat(
227+ slider.value,
228+ Eventually(Equals(original_value), timeout=20)
229+ )
230+
231+ # make sure we've got the server value set.
232+ self.assertThat(
233+ slider.value,
234+ Equals(slider_menu.serverValue)
235+ )
236+
tests/autopilot/unity8/indicators/tests/test_test_indicator.pydeleted−192
@@ -1,192 +0,0 @@
1−# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2−#
3−# Unity Indicators Autopilot Test Suite
4−# Copyright (C) 2015 Canonical
5−#
6−# This program is free software: you can redistribute it and/or modify
7−# it under the terms of the GNU General Public License as published by
8−# the Free Software Foundation, either version 3 of the License, or
9−# (at your option) any later version.
10−#
11−# This program is distributed in the hope that it will be useful,
12−# but WITHOUT ANY WARRANTY; without even the implied warranty of
13−# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14−# GNU General Public License for more details.
15−#
16−# You should have received a copy of the GNU General Public License
17−# along with this program. If not, see <http://www.gnu.org/licenses/>.
18−
19−from unity8 import (
20− fixture_setup,
21− indicators,
22− get_binary_path,
23− process_helpers
24−)
25−from unity8.indicators import tests
26−
27−from autopilot.matchers import Eventually
28−from testtools.matchers import Equals
29−import time
30−
31−class TestIndicatorBaseTestCase(tests.IndicatorTestCase):
32−
33− scenarios = tests.IndicatorTestCase.device_emulation_scenarios
34−
35− def setUp(self, action_delay=30000):
36− """
37− :parameter action_delay: number of milliseconds for indicator backend
38− to wait before performing actions
39− """
40− super(TestIndicatorBaseTestCase, self).setUp()
41−
42− self.ensure_service_not_running();
43−
44− binary_path = get_binary_path('unity-indicator-test-service')
45− environment = {}
46− environment['ARGS'] = '-t {0}'\
47− .format(action_delay)
48− self.launch_indicator_service(binary_path, environment)
49−
50− # wait for the indicator to appear in unity
51− self.indicator = indicators.TestIndicator(self.main_window)
52− self.assertThat(
53− self.indicator.is_indicator_icon_visible(),
54− Eventually(Equals(True), timeout=20)
55− )
56− self.indicator_page = self.indicator.open()
57−
58− def launch_indicator_service(self, binary_path, variables):
59− launch_service_fixture = fixture_setup.LaunchTestIndicatorService(binary_path, variables)
60− self.useFixture(launch_service_fixture)
61−
62− def ensure_service_not_running(self):
63− if process_helpers.is_job_running('unity-indicator-test-service'):
64− process_helpers.stop_job('unity-indicator-test-service')
65−
66−
67−class TestLowLatencyIndicator(TestIndicatorBaseTestCase):
68−
69− def setUp(self):
70− """Set up for indicator actions to take 50 milliseconds for be actioned"""
71− super(TestLowLatencyIndicator, self).setUp(50)
72−
73−
74− def test_switch_reaches_server_value(self):
75− """Test that switching causes the server to update"""
76− self.assertThat(
77− self.indicator_page.get_switch_menu().serverChecked,
78− Equals(self.indicator_page.get_switcher().checked)
79− )
80−
81− self.indicator_page.get_switcher().change_state()
82−
83− self.assertThat(
84− self.indicator_page.get_switch_menu().serverChecked,
85− Eventually(Equals(self.indicator_page.get_switcher().checked), timeout=10)
86− )
87−
88−class TestMediumLatencyIndicator(TestIndicatorBaseTestCase):
89−
90− def setUp(self):
91− """Set up for indicator actions to take 2.5 seconds for be actioned"""
92− super(TestMediumLatencyIndicator, self).setUp(2500)
93−
94− def test_buffered_switch(self):
95− """Test that switching multiple times will buffer activations if
96− within the activation timeout period
97−
98− See https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1390136 .
99− """
100− self.indicator_page.get_switcher().change_state()
101− # will buffer change until it receives the change from server
102− self.indicator_page.get_switcher().change_state()
103− new_value = self.indicator_page.get_switcher().checked;
104−
105− # backend will respond to first switch. The buffered activation should have gone to server now.
106− self.assertThat(
107− self.indicator_page.get_switch_menu().serverChecked,
108− Eventually(Equals(not new_value), timeout=15)
109− )
110−
111− # front-end should not change while it is buffered
112− self.assertThat(
113− self.indicator_page.get_switcher().checked,
114− Equals(new_value)
115− )
116−
117− # server will respond to the second activate
118− self.assertThat(
119− self.indicator_page.get_switch_menu().serverChecked,
120− Eventually(Equals(new_value), timeout=15)
121− )
122−
123− # make sure we've got the server value set.
124− self.assertThat(
125− self.indicator_page.get_switcher().checked,
126− Equals(self.indicator_page.get_switch_menu().serverChecked)
127− )
128−
129−
130−
131−class TestHighLatencyIndicator(TestIndicatorBaseTestCase):
132−
133− def setUp(self):
134− """Set up for indicator actions to take 8 seconds for be actioned"""
135− super(TestHighLatencyIndicator, self).setUp(8000)
136−
137− def test_switch_reverts_to_server_value(self):
138− """Test that switching a high latency backend value will revert to original value
139− if not actioned in time.
140−
141− See https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1390136 .
142− """
143− self.assertThat(
144− self.indicator_page.get_switch_menu().serverChecked,
145− Equals(self.indicator_page.get_switcher().checked)
146− )
147−
148− original_value = self.indicator_page.get_switcher().checked;
149− self.indicator_page.get_switcher().change_state()
150−
151− # switch should revert to original value after 5 seconds (30 seconds in real usage)
152− self.assertThat(
153− self.indicator_page.get_switch_menu().serverChecked,
154− Eventually(Equals(original_value), timeout=15)
155− )
156− # value will eventually switch back. See test_switch_always_reaches_server_value
157−
158− def test_switch_always_reaches_server_value(self):
159− """Test that switching a high latency backend value will always end up following the
160− server value, even if had a reversion
161−
162− See https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1390136 .
163− """
164− self.test_switch_reverts_to_server_value()
165−
166− self.assertThat(
167− self.indicator_page.get_switch_menu().serverChecked,
168− Eventually(Equals(self.indicator_page.get_switcher().checked), timeout=15)
169− )
170−
171− def test_revert_on_late_response(self):
172− """If the server does not respond in the given amount of time
173− then we wont switch again even if the switch is buffered
174−
175− See https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1390136 .
176− """
177− self.indicator_page.get_switcher().change_state()
178− # will buffer change until it receives the change from server
179− self.indicator_page.get_switcher().change_state()
180− new_value = self.indicator_page.get_switcher().checked;
181−
182− # backend will respond to first switch. The buffered activation will be discarded
183− self.assertThat(
184− self.indicator_page.get_switch_menu().serverChecked,
185− Eventually(Equals(not new_value), timeout=15)
186− )
187−
188− # make sure we've got the server value set.
189− self.assertThat(
190− self.indicator_page.get_switcher().checked,
191− Equals(self.indicator_page.get_switch_menu().serverChecked)
192− )
tests/mocks/CMakeLists.txt+1
@@ -30,6 +30,7 @@ endmacro()
30
30
31add_subdirectory(AccountsService)
31add_subdirectory(AccountsService)
32add_subdirectory(GSettings.1.0)
32add_subdirectory(GSettings.1.0)
33+add_subdirectory(indicator-service)
33add_subdirectory(libusermetrics)
34add_subdirectory(libusermetrics)
34add_subdirectory(LightDM)
35add_subdirectory(LightDM)
35add_subdirectory(Lights)
36add_subdirectory(Lights)
tests/mocks/data/unity/indicators/com.canonical.indicator.mocknew file+10
@@ -0,0 +1,10 @@
1+[Indicator Service]
2+Name=indicator-mock
3+ObjectPath=/com/canonical/indicator/mock
4+Position=0
5+
6+[phone]
7+ObjectPath=/com/canonical/indicator/mock/desktop
8+
9+[desktop]
10+ObjectPath=/com/canonical/indicator/mock/desktop
tests/mocks/data/unity/indicators/com.canonical.indicator.testdeleted−10
@@ -1,10 +0,0 @@
1−[Indicator Service]
2−Name=indicator-test
3−ObjectPath=/com/canonical/indicator/test
4−Position=0
5−
6−[phone]
7−ObjectPath=/com/canonical/indicator/test/desktop
8−
9−[desktop]
10−ObjectPath=/com/canonical/indicator/test/desktop
tests/mocks/indicator-service/CMakeLists.txtnew file+24
@@ -0,0 +1,24 @@
1+project(mock-indicator-service)
2+pkg_search_module(GIO REQUIRED gio-2.0)
3+
4+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
5+
6+include_directories(
7+ ${CMAKE_CURRENT_SOURCE_DIR}
8+ ${GIO_INCLUDE_DIRS}
9+)
10+
11+set(MOCK_INDICATOR_SERVICE_SRC
12+ mock-indicator-service.c
13+)
14+
15+add_executable(${MOCK_INDICATOR_SERVICE_APP}
16+ ${MOCK_INDICATOR_SERVICE_SRC}
17+)
18+
19+target_link_libraries(${MOCK_INDICATOR_SERVICE_APP} ${GIO_LDFLAGS})
20+
21+set_target_properties(${MOCK_INDICATOR_SERVICE_APP} PROPERTIES COMPILE_FLAGS -fPIC)
22+
23+install(TARGETS ${MOCK_INDICATOR_SERVICE_APP}
24+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
src/Panel/Indicators/indicator-test-service/indicator-test-service.c → tests/mocks/indicator-service/mock-indicator-service.crenamed+9−4
@@ -24,7 +24,7 @@ bus_acquired (GDBusConnection *connection,
24 GError *error = NULL;
24 GError *error = NULL;
25
25
26 indicator->actions_export_id = g_dbus_connection_export_action_group (connection,
26 indicator->actions_export_id = g_dbus_connection_export_action_group (connection,
27− "/com/canonical/indicator/test",
27+ "/com/canonical/indicator/mock",
28 G_ACTION_GROUP (indicator->actions),
28 G_ACTION_GROUP (indicator->actions),
29 &error);
29 &error);
30 if (indicator->actions_export_id == 0)
30 if (indicator->actions_export_id == 0)
@@ -35,7 +35,7 @@ bus_acquired (GDBusConnection *connection,
35 }
35 }
36
36
37 indicator->menu_export_id = g_dbus_connection_export_menu_model (connection,
37 indicator->menu_export_id = g_dbus_connection_export_menu_model (connection,
38− "/com/canonical/indicator/test/desktop",
38+ "/com/canonical/indicator/mock/desktop",
39 G_MENU_MODEL (indicator->menu),
39 G_MENU_MODEL (indicator->menu),
40 &error);
40 &error);
41 if (indicator->menu_export_id == 0)
41 if (indicator->menu_export_id == 0)
@@ -141,6 +141,7 @@ main (int argc, char **argv)
141 " 'accessible-desc': <'Test indicator'> }", NULL },
141 " 'accessible-desc': <'Test indicator'> }", NULL },
142 { "action.show", activate_show, NULL, NULL, NULL },
142 { "action.show", activate_show, NULL, NULL, NULL },
143 { "action.switch", activate_switch, NULL, "true", NULL },
143 { "action.switch", activate_switch, NULL, "true", NULL },
144+ { "action.checkbox", activate_switch, NULL, "true", NULL },
144 { "action.accessPoint", activate_switch, NULL, "false", NULL },
145 { "action.accessPoint", activate_switch, NULL, "false", NULL },
145 { "action.slider", NULL, NULL, "0.5", change_slider }
146 { "action.slider", NULL, NULL, "0.5", change_slider }
146 };
147 };
@@ -202,7 +203,11 @@ main (int argc, char **argv)
202 g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.switch");
203 g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.switch");
203 g_menu_append_item(submenu, item);
204 g_menu_append_item(submenu, item);
204
205
205− // Access Point
206+ // Checkbox
207+ item = g_menu_item_new("Checkbox", "indicator.action.checkbox");
208+ g_menu_append_item(submenu, item);
209+
210+ // Slider
206 item = g_menu_item_new("Slider", "indicator.action.slider");
211 item = g_menu_item_new("Slider", "indicator.action.slider");
207 g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.slider");
212 g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.slider");
208 g_menu_append_item(submenu, item);
213 g_menu_append_item(submenu, item);
@@ -220,7 +225,7 @@ main (int argc, char **argv)
220 g_menu_append_item (indicator.menu, item);
225 g_menu_append_item (indicator.menu, item);
221
226
222 g_bus_own_name (G_BUS_TYPE_SESSION,
227 g_bus_own_name (G_BUS_TYPE_SESSION,
223− "com.canonical.indicator.test",
228+ "com.canonical.indicator.mock",
224 G_BUS_NAME_OWNER_FLAGS_NONE,
229 G_BUS_NAME_OWNER_FLAGS_NONE,
225 bus_acquired,
230 bus_acquired,
226 NULL,
231 NULL,