Unity 8
__init__.py
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 
22 class IndicatorPage(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
23 
24  """Autopilot helper for the IndicatorPage component."""
25 
26  # XXX Because of https://bugs.launchpad.net/autopilot-qt/+bug/1341671
27  # we need to make sure it does not match in any selection.
28  # --elopio - 2015-01-20
29 
30  @classmethod
31  def validate_dbus_object(cls, path, state):
32  return False
33 
34 
35 class Indicator():
36 
37  def __init__(self, main_window, name):
38  self._main_window = main_window
39  self._name = name
40 
41  def is_indicator_icon_visible(self):
42  panel_item = self._main_window.wait_select_single(
43  objectName=self._name+'-panelItem')
44  return panel_item.indicatorVisible
45 
46  def open(self):
47  """Open the indicator page.
48 
49  :return: The custom proxy object for the indicator page.
50 
51  """
52  if self.is_indicator_icon_visible():
53  return self._main_window.open_indicator_page(self._name)
54  else:
55  return self._open_indicator_with_icon_not_visible()
56 
57  def _open_indicator_with_icon_not_visible(self):
58  # Open any displayed indicator.
59  self._main_window.open_indicator_page('indicator-datetime')
60  self._make_indicator_icon_visible()
61  indicator_rotation_icon = self._main_window.select_single(
62  objectName=self._name+'-panelItem')
63  self._main_window.pointing_device.click_object(indicator_rotation_icon)
64  return self._main_window.wait_select_single(
65  objectName=self._name+'-page')
66 
67  def _make_indicator_icon_visible(self):
68  indicators_bar = self._main_window.select_single('IndicatorsBar')
69  indicators_bar_flickable = indicators_bar.select_single(
70  ubuntuuitoolkit.QQuickFlickable, objectName='flickable')
71  self._swipe_flickable_to_x_end(indicators_bar_flickable)
72 
73  def _swipe_flickable_to_x_end(self, flickable):
74  # XXX this should be implemented as a general horizontal swiping in
75  # the toolkit custom proxy object. -- elopio - 2015-01-20
76  if not flickable.atXEnd:
77  flickable.interactive.wait_for(True)
78  while not flickable.atXEnd:
79  start_y = stop_y = (
80  flickable.globalRect.y +
81  (flickable.globalRect.height // 2))
82  # We can't start the swipe from the border because it would
83  # open the launcher
84  start_x = flickable.globalRect.x + 45
85  stop_x = (
86  flickable.globalRect.x + flickable.globalRect.width - 5)
87  flickable.pointing_device.drag(
88  start_x, start_y, stop_x, stop_y)
89  flickable.dragging.wait_for(False)
90  flickable.moving.wait_for(False)
91 
92  def close(self):
93  """Close the indicator page."""
94  self._main_window.close_indicator_page()
95 
96 
97 class DisplayIndicator(Indicator):
98 
99  def __init__(self, main_window):
100  super(DisplayIndicator, self).__init__(main_window,
101  'indicator-rotation-lock')
102  self._main_window = main_window
103 
104 
106 
107  """Autopilot helper for the display indicator page."""
108 
109  @classmethod
110  def validate_dbus_object(cls, path, state):
111  name = introspection.get_classname_from_path(path)
112  if name == b'IndicatorPage':
113  if state['objectName'][1] == 'indicator-rotation-lock-page':
114  return True
115  return False
116 
117  def lock_rotation(self):
118  """Toggle the rotation lock indicator to locked."""
119  switcher = self._get_switcher()
120  switcher.check()
121  switcher.checked.wait_for(True)
122 
123  def _get_switcher(self):
124  return self.select_single(
125  ubuntuuitoolkit.CheckBox, objectName='switcher')
126 
127  def unlock_rotation(self):
128  """Toggle the rotation lock indicator to unlocked."""
129  switcher = self._get_switcher()
130  switcher.uncheck()
131  switcher.checked.wait_for(False)
132 
133 
134 class TestIndicator(Indicator):
135 
136  def __init__(self, main_window):
137  super(TestIndicator, self).__init__(main_window, 'indicator-mock')
138  self._main_window = main_window
139 
140 
142 
143  """Autopilot helper for the mock indicator page."""
144 
145  @classmethod
146  def validate_dbus_object(cls, path, state):
147  name = introspection.get_classname_from_path(path)
148  if name == b'IndicatorPage':
149  if state['objectName'][1] == 'indicator-mock-page':
150  return True
151  return False
152 
153  def get_switcher(self):
154  return self.select_single(
155  ubuntuuitoolkit.CheckBox, objectName='switcher')
156 
157  def get_switch_menu(self):
158  return self.select_single(
159  'SwitchMenu', objectName='indicator.action.switch')
160 
161  def get_slider(self):
162  return self.select_single(objectName='slider')
163 
164  def get_slider_menu(self):
165  return self.select_single(objectName='indicator.action.slider')
166 
167 
168 class Slider(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
169 
170  """Autopilot helper for the Slider component."""
171 
172  # XXX Because of https://bugs.launchpad.net/autopilot-qt/+bug/1341671
173  # we need to make sure it does not match in any selection.
174  # --elopio - 2015-01-20
175 
176  @classmethod
177  def validate_dbus_object(cls, path, state):
178  name = introspection.get_classname_from_path(path)
179  if name == b'Slider':
180  return True
181  return False
182 
183  def slide_left(self, timeout=10):
184  x, y, width, height = self.globalRect
185 
186  rate = 5
187  start_x = x + width/2
188  start_y = stop_y = y + height/2
189  stop_x = x
190 
191  self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
192  self.value.wait_for(self.minimumValue, timeout)
193 
194  def slide_right(self, timeout=10):
195  x, y, width, height = self.globalRect
196 
197  rate = 5
198  start_x = x + width/2
199  start_y = stop_y = y + height/2
200  stop_x = x + width
201 
202  self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
203  self.value.wait_for(self.maximumValue, timeout)