on xenial help sign in
Added an initial set of autopilot tests for the display indicator.
cea4e04Ying-Chun Liu
tests/autopilot/unity8/fixture_setup.py+35−1
@@ -1,7 +1,7 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
2#
3# Unity Autopilot Test Suite
3# Unity Autopilot Test Suite
4−# Copyright (C) 2014 Canonical
4+# Copyright (C) 2014, 2015 Canonical
5#
5#
6# This program is free software: you can redistribute it and/or modify
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
7# it under the terms of the GNU General Public License as published by
@@ -18,6 +18,8 @@
18#
18#
19
19
20import fixtures
20import fixtures
21+import subprocess
22+
21from autopilot import introspection
23from autopilot import introspection
22
24
23from unity8 import process_helpers
25from unity8 import process_helpers
@@ -62,3 +64,35 @@ class LaunchDashApp(fixtures.Fixture):
62
64
63 def stop_application(self):
65 def stop_application(self):
64 process_helpers.stop_job('unity8-dash')
66 process_helpers.stop_job('unity8-dash')
67+
68+
69+class DisplayRotationLock(fixtures.Fixture):
70+
71+ def __init__(self, enable):
72+ super(DisplayRotationLock, self).__init__()
73+ self.enable = enable
74+
75+ def setUp(self):
76+ super(DisplayRotationLock, self).setUp()
77+ original_state = self._is_rotation_lock_enabled()
78+ if self.enable != original_state:
79+ self.addCleanup(self._set_rotation_lock, original_state)
80+ self._set_rotation_lock(self.enable)
81+
82+ def _is_rotation_lock_enabled(self):
83+ command = [
84+ 'gsettings', 'get',
85+ 'com.ubuntu.touch.system',
86+ 'rotation-lock'
87+ ]
88+ output = subprocess.check_output(command, universal_newlines=True)
89+ return True if output.count('true') else False
90+
91+ def _set_rotation_lock(self, value):
92+ value_string = 'true' if value else 'false'
93+ command = [
94+ 'gsettings', 'set',
95+ 'com.ubuntu.touch.system',
96+ 'rotation-lock', value_string
97+ ]
98+ subprocess.check_output(command)
tests/autopilot/unity8/indicators/__init__.py+124
@@ -0,0 +1,124 @@
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+# You should have received a copy of the GNU General Public License
16+# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+import ubuntuuitoolkit
19+from autopilot import introspection
20+
21+from unity8.shell import emulators
22+
23+
24+class IndicatorPage(emulators.UnityEmulatorBase):
25+
26+ """Autopilot helper for the IndicatorPage component."""
27+
28+ # XXX Because of https://bugs.launchpad.net/autopilot-qt/+bug/1341671
29+ # we need to make sure it does not match in any selection.
30+ # --elopio - 2015-01-20
31+
32+ @classmethod
33+ def validate_dbus_object(cls, path, state):
34+ return False
35+
36+
37+class DisplayIndicator(object):
38+
39+ def __init__(self, main_window):
40+ self._main_window = main_window
41+
42+ def is_indicator_icon_visible(self):
43+ panel_item = self._main_window.wait_select_single(
44+ objectName='indicator-rotation-lock-panelItem')
45+ return panel_item.indicatorVisible
46+
47+ def open(self):
48+ """Open the display indicator page.
49+
50+ :return: The custom proxy object for the display indicator page.
51+
52+ """
53+ if self.is_indicator_icon_visible():
54+ return self._main_window.open_indicator_page(
55+ 'indicator-rotation-lock')
56+ else:
57+ return self._open_indicator_with_icon_not_visible()
58+
59+ def _open_indicator_with_icon_not_visible(self):
60+ # Open any displayed indicator.
61+ self._main_window.open_indicator_page('indicator-datetime')
62+ self._make_indicator_icon_visible()
63+ indicator_rotation_icon = self._main_window.select_single(
64+ objectName='indicator-rotation-lock-panelItem')
65+ self._main_window.pointing_device.click_object(indicator_rotation_icon)
66+ return self._main_window.wait_select_single(
67+ objectName='indicator-rotation-lock-page')
68+
69+ def _make_indicator_icon_visible(self):
70+ indicators_bar_flickable = self._main_window.select_single(
71+ 'IndicatorsBar').select_single(
72+ ubuntuuitoolkit.QQuickFlickable, objectName='flickable')
73+ self._swipe_flickable_to_x_end(indicators_bar_flickable)
74+
75+ def _swipe_flickable_to_x_end(self, flickable):
76+ # XXX this should be implemented as a general horizontal swiping in
77+ # the toolkit custom proxy object. -- elopio - 2015-01-20
78+ if not flickable.atXEnd:
79+ while not flickable.atXEnd:
80+ start_y = stop_y = (
81+ flickable.globalRect.y +
82+ (flickable.globalRect.height // 2))
83+ # We can't start the swipe from the border because it would
84+ # open the launcher
85+ start_x = flickable.globalRect.x + 45
86+ stop_x = (
87+ flickable.globalRect.x + flickable.globalRect.width - 5)
88+ flickable.pointing_device.drag(
89+ start_x, start_y, stop_x, stop_y)
90+ flickable.dragging.wait_for(False)
91+ flickable.moving.wait_for(False)
92+
93+ def close(self):
94+ """Close the indicator page."""
95+ self._main_window.close_indicator_page()
96+
97+
98+class DisplayIndicatorPage(IndicatorPage):
99+
100+ """Autopilot helper for the display indicator page."""
101+
102+ @classmethod
103+ def validate_dbus_object(cls, path, state):
104+ name = introspection.get_classname_from_path(path)
105+ if name == b'IndicatorPage':
106+ if state['objectName'][1] == 'indicator-rotation-lock-page':
107+ return True
108+ return False
109+
110+ def lock_rotation(self):
111+ """Toggle the rotation lock indicator to locked."""
112+ switcher = self._get_switcher()
113+ switcher.check()
114+ switcher.checked.wait_for(True)
115+
116+ def _get_switcher(self):
117+ return self.select_single(
118+ ubuntuuitoolkit.CheckBox, objectName='switcher')
119+
120+ def unlock_rotation(self):
121+ """Toggle the rotation lock indicator to unlocked."""
122+ switcher = self._get_switcher()
123+ switcher.uncheck()
124+ switcher.checked.wait_for(False)
tests/autopilot/unity8/indicators/tests/__init__.py+18−1
@@ -1,7 +1,7 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
2#
3# Unity - Indicators Autopilot Test Suite
3# Unity - Indicators Autopilot Test Suite
4−# Copyright (C) 2013, 2014 Canonical
4+# Copyright (C) 2013, 2014, 2015 Canonical
5#
5#
6# This program is free software: you can redistribute it and/or modify
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
7# it under the terms of the GNU General Public License as published by
@@ -15,3 +15,20 @@
15#
15#
16# You should have received a copy of the GNU General Public License
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/>.
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+from autopilot import platform
20+
21+from unity8 import process_helpers
22+from unity8.shell import tests
23+
24+
25+class IndicatorTestCase(tests.UnityTestCase):
26+
27+ device_emulation_scenarios = tests._get_device_emulation_scenarios()
28+
29+ def setUp(self):
30+ if platform.model() == 'Desktop':
31+ self.skipTest('Test cannot be run on the desktop.')
32+ super(IndicatorTestCase, self).setUp()
33+ self.unity_proxy = self.launch_unity()
34+ process_helpers.unlock_unity(self.unity_proxy)
tests/autopilot/unity8/indicators/tests/test_display_indicator.pynew file+53
@@ -0,0 +1,53 @@
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+)
23+from unity8.indicators import tests
24+
25+
26+class DisplayIndicatorTestCase(tests.IndicatorTestCase):
27+
28+ def test_indicator_icon_must_be_visible_after_rotation_locked(self):
29+ # TODO remove the skip when the bug is fixed. --elopio - 2015-01-20
30+ self.skipTest(
31+ 'This test fails because of bug http://pad.lv/1410915')
32+ rotation_unlocked = fixture_setup.DisplayRotationLock(False)
33+ self.useFixture(rotation_unlocked)
34+ display_indicator = indicators.DisplayIndicator(self.main_window)
35+ self.assertFalse(display_indicator.is_indicator_icon_visible())
36+
37+ display_indicator_page = display_indicator.open()
38+ display_indicator_page.lock_rotation()
39+ display_indicator.close()
40+
41+ self.assertTrue(display_indicator.is_indicator_icon_visible())
42+
43+ def test_indicator_icon_must_not_be_visible_after_rotation_unlocked(self):
44+ rotation_locked = fixture_setup.DisplayRotationLock(True)
45+ self.useFixture(rotation_locked)
46+ display_indicator = indicators.DisplayIndicator(self.main_window)
47+ self.assertTrue(display_indicator.is_indicator_icon_visible())
48+
49+ display_indicator_page = display_indicator.open()
50+ display_indicator_page.unlock_rotation()
51+ display_indicator.close()
52+
53+ self.assertFalse(display_indicator.is_indicator_icon_visible())
tests/autopilot/unity8/indicators/tests/test_indicators.py+6−19
@@ -1,7 +1,7 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
2#
3# Unity Indicators Autopilot Test Suite
3# Unity Indicators Autopilot Test Suite
4−# Copyright (C) 2013, 2014 Canonical
4+# Copyright (C) 2013, 2014, 2015 Canonical
5#
5#
6# This program is free software: you can redistribute it and/or modify
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
7# it under the terms of the GNU General Public License as published by
@@ -22,23 +22,10 @@ from testscenarios import multiply_scenarios
22
22
23from autopilot import platform
23from autopilot import platform
24
24
25−from unity8.process_helpers import unlock_unity
25+from unity8.indicators import tests
26−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
27
26
28
27
29−class IndicatorTestCase(UnityTestCase):
30−
31− device_emulation_scenarios = _get_device_emulation_scenarios()
32−
33− def setUp(self):
34− if platform.model() == 'Desktop':
35− self.skipTest('Test cannot be run on the desktop.')
36− super(IndicatorTestCase, self).setUp()
37− self.unity_proxy = self.launch_unity()
38− unlock_unity(self.unity_proxy)
39−
40−
41−class IndicatorExistsTestCase(IndicatorTestCase):
28+class IndicatorExistsTestCase(tests.IndicatorTestCase):
42
29
43 indicator_scenarios = [
30 indicator_scenarios = [
44 ('Bluetooth', dict(indicator_name='indicator-bluetooth')),
31 ('Bluetooth', dict(indicator_name='indicator-bluetooth')),
@@ -51,7 +38,7 @@ class IndicatorExistsTestCase(IndicatorTestCase):
51 ]
38 ]
52 scenarios = multiply_scenarios(
39 scenarios = multiply_scenarios(
53 indicator_scenarios,
40 indicator_scenarios,
54− IndicatorTestCase.device_emulation_scenarios
41+ tests.IndicatorTestCase.device_emulation_scenarios
55 )
42 )
56
43
57 def setUp(self):
44 def setUp(self):
@@ -66,7 +53,7 @@ class IndicatorExistsTestCase(IndicatorTestCase):
66 )
53 )
67
54
68
55
69−class IndicatorPageTitleMatchesWidgetTestCase(IndicatorTestCase):
56+class IndicatorPageTitleMatchesWidgetTestCase(tests.IndicatorTestCase):
70
57
71 indicator_scenarios = [
58 indicator_scenarios = [
72 ('Bluetooth', dict(indicator_name='indicator-bluetooth',
59 ('Bluetooth', dict(indicator_name='indicator-bluetooth',
@@ -86,7 +73,7 @@ class IndicatorPageTitleMatchesWidgetTestCase(IndicatorTestCase):
86 ]
73 ]
87 scenarios = multiply_scenarios(
74 scenarios = multiply_scenarios(
88 indicator_scenarios,
75 indicator_scenarios,
89− IndicatorTestCase.device_emulation_scenarios
76+ tests.IndicatorTestCase.device_emulation_scenarios
90 )
77 )
91
78
92 def setUp(self):
79 def setUp(self):
tests/autopilot/unity8/shell/emulators/main_window.py+11−1
@@ -1,7 +1,7 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
2#
3# Unity Autopilot Test Suite
3# Unity Autopilot Test Suite
4−# Copyright (C) 2012, 2013, 2014 Canonical
4+# Copyright (C) 2012, 2013, 2014, 2015 Canonical
5#
5#
6# This program is free software: you can redistribute it and/or modify
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
7# it under the terms of the GNU General Public License as published by
@@ -88,6 +88,16 @@ class QQuickView(emulators.UnityEmulatorBase):
88 self.wait_select_single('IndicatorsMenu', fullyOpened=True)
88 self.wait_select_single('IndicatorsMenu', fullyOpened=True)
89 return self._get_indicator_page(indicator_name)
89 return self._get_indicator_page(indicator_name)
90
90
91+ @autopilot_logging.log_action(logger.info)
92+ def close_indicator_page(self):
93+ """Swipe to close the opened indicator, wait until it's closed."""
94+ indicators_menu = self.wait_select_single('IndicatorsMenu')
95+ end_x, end_y = input.get_center_point(indicators_menu)
96+ start_x = end_x
97+ start_y = self.height
98+ self.pointing_device.drag(start_x, start_y, end_x, end_y)
99+ indicators_menu.fullyClosed.wait_for(True)
100+
91 @autopilot_logging.log_action(logger.info)
101 @autopilot_logging.log_action(logger.info)
92 def show_dash_swiping(self):
102 def show_dash_swiping(self):
93 """Show the dash swiping from the left."""
103 """Show the dash swiping from the left."""