@@ -0,0 +1,124 @@
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.
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/>.
18+import ubuntuuitoolkit
19+from autopilot import introspection
21+from unity8.shell import emulators
24+class IndicatorPage(emulators.UnityEmulatorBase):
26+ """Autopilot helper for the IndicatorPage component."""
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
33+ def validate_dbus_object(cls, path, state):
37+class DisplayIndicator(object):
39+ def __init__(self, main_window):
40+ self._main_window = main_window
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
48+ """Open the display indicator page.
50+ :return: The custom proxy object for the display indicator page.
53+ if self.is_indicator_icon_visible():
54+ return self._main_window.open_indicator_page(
55+ 'indicator-rotation-lock')
57+ return self._open_indicator_with_icon_not_visible()
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')
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)
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:
81+ flickable.globalRect.y +
82+ (flickable.globalRect.height // 2))
83+ # We can't start the swipe from the border because it would
85+ start_x = flickable.globalRect.x + 45
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)
94+ """Close the indicator page."""
95+ self._main_window.close_indicator_page()
98+class DisplayIndicatorPage(IndicatorPage):
100+ """Autopilot helper for the display indicator page."""
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':
110+ def lock_rotation(self):
111+ """Toggle the rotation lock indicator to locked."""
112+ switcher = self._get_switcher()
114+ switcher.checked.wait_for(True)
116+ def _get_switcher(self):
117+ return self.select_single(
118+ ubuntuuitoolkit.CheckBox, objectName='switcher')
120+ def unlock_rotation(self):
121+ """Toggle the rotation lock indicator to unlocked."""
122+ switcher = self._get_switcher()
124+ switcher.checked.wait_for(False)