@@ -0,0 +1,236 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3+# Unity Indicators Autopilot Test Suite
4+# Copyright (C) 2015 Canonical
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.
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.
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/>.
19+from testscenarios import multiply_scenarios
26+from unity8.shell import tests
27+from unity8.indicators import tests
29+from autopilot.matchers import Eventually
30+from testtools.matchers import Equals, NotEquals
34+class TestIndicatorBaseTestCase(tests.IndicatorTestCase):
36+ scenarios = [ tests.IndicatorTestCase.device_emulation_scenarios[0] ]
39+ super(TestIndicatorBaseTestCase, self).setUp()
42+ environment['ARGS'] = '-t {0}'\
43+ .format(self.action_delay)
44+ self.launch_indicator_service(environment)
46+ # wait for the indicator to appear in unity
47+ self.indicator = indicators.TestIndicator(self.main_window)
49+ self.indicator.is_indicator_icon_visible(),
50+ Eventually(Equals(True), timeout=20)
52+ self.indicator_page = self.indicator.open()
54+ def launch_indicator_service(self, variables):
55+ launch_service_fixture = fixture_setup.LaunchTestIndicatorService(variables)
56+ self.useFixture(launch_service_fixture)
59+class TestServerValueUpdate(TestIndicatorBaseTestCase):
61+ """Test that an action causes the server to update"""
64+ ('Low', dict(action_delay=0)),
65+ ('Medium', dict(action_delay=2500)),
66+ ('High', dict(action_delay=8000)),
68+ scenarios = multiply_scenarios(
70+ TestIndicatorBaseTestCase.scenarios
73+ def test_switch_reaches_server_value(self):
74+ switch = self.indicator_page.get_switcher()
75+ switch_menu = self.indicator_page.get_switch_menu()
77+ switch.change_state()
80+ switch_menu.serverChecked,
81+ Eventually(Equals(switch.checked), timeout=20)
84+ def test_slider_reaches_server_value(self):
85+ slider = self.indicator_page.get_slider()
86+ slider_menu = self.indicator_page.get_slider_menu()
88+ old_value = slider.value
92+ slider_menu.serverValue,
93+ Eventually(NotEquals(old_value), timeout=20)
97+ slider_menu.serverValue,
98+ Eventually(Equals(slider.value), timeout=20)
101+class TestBuffering(TestIndicatorBaseTestCase):
103+ """Test that switching multiple times will buffer activations
105+ See https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1390136 .
109+ def test_buffered_switch(self):
111+ switch = self.indicator_page.get_switcher()
112+ switch.change_state()
113+ intermediate_value = switch.checked;
115+ # will buffer change until it receives the change from server
116+ switch.change_state()
117+ final_value = switch.checked;
119+ # backend will respond to first switch.
120+ switch_menu = self.indicator_page.get_switch_menu()
122+ switch_menu.serverChecked,
123+ Eventually(Equals(intermediate_value), timeout=20)
125+ # The buffered activation should have gone to server now.
127+ # front-end should not change as a result of server update while it is buffered
133+ # server will respond to the second activate
135+ switch_menu.serverChecked,
136+ Eventually(Equals(final_value), timeout=20)
139+ # make sure we've got the server value set.
142+ Equals(switch_menu.serverChecked)
145+ def test_buffered_slider(self):
147+ slider = self.indicator_page.get_slider()
148+ original_value = slider.value;
151+ # will buffer change until it receives the change from server
152+ slider.slide_right()
153+ final_value = slider.value;
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()
159+ slider_menu.serverValue,
160+ Eventually(NotEquals(original_value), timeout=20)
162+ # It wont yet have reached the final value due to the buffering
163+ # Second activate should have gone out by now
165+ slider_menu.serverValue,
166+ NotEquals(final_value)
169+ # front-end should not change as a result of server update while it is buffered
175+ # server will respond to the second activate
177+ slider_menu.serverValue,
178+ Eventually(Equals(final_value), timeout=20)
181+ # make sure we've got the server value set.
184+ Equals(slider_menu.serverValue)
188+class TestClientRevertsToServerValue(TestIndicatorBaseTestCase):
190+ """Test that an action which does not respond in time will revert
191+ to original value if not actioned in time.
193+ See https://bugs.launchpad.net/ubuntu/+source/unity8/+bug/1390136 .
195+ action_delay = -1 # never action.
197+ def test_switch_reverts_on_late_response(self):
199+ switch = self.indicator_page.get_switcher()
200+ switch_menu = self.indicator_page.get_switch_menu()
202+ original_value = switch.checked;
203+ switch.change_state()
205+ # switch should revert to original value after 5 seconds (30 seconds in real usage)
208+ Eventually(Equals(original_value), timeout=20)
211+ # make sure we've got the server value set.
214+ Equals(switch_menu.serverChecked)
217+ def test_slider_reverts_on_late_response(self):
219+ slider = self.indicator_page.get_slider()
220+ slider_menu = self.indicator_page.get_slider_menu()
222+ original_value = slider.value;
225+ # slider should revert to original value after 5 seconds (30 seconds in real usage)
228+ Eventually(Equals(original_value), timeout=20)
231+ # make sure we've got the server value set.
234+ Equals(slider_menu.serverValue)