Unity 8
 All Classes Functions
disabled_test_hud.py
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Unity Autopilot Test Suite
4 # Copyright (C) 2012, 2013, 2014 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 
20 from __future__ import absolute_import
21 
22 from unity8.process_helpers import unlock_unity
23 from unity8.shell import DragMixin
24 from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
25 
26 from testtools.matchers import Equals
27 from autopilot.matchers import Eventually
28 
29 
30 class TestHud(UnityTestCase, DragMixin):
31 
32  """Tests the Shell HUD."""
33 
34  scenarios = _get_device_emulation_scenarios()
35 
37  """Swiping up while an app is active must show the 'show hud' button.
38 
39  It should follow some behaviours.
40  The button must disappear not opening the HUD when releasing the
41  mouse again somewhere on the screen except on the button itself
42  following a timeout.
43  The button must disappear when touching somewhere on the screen
44  except the button itself.
45 
46  """
47  unity_proxy = self.launch_unity()
48  unlock_unity(unity_proxy)
49  hud_show_button = self.main_window.get_hud_show_button()
50  edge_drag_area = self.main_window.get_hud_edge_drag_area()
51  hud = self.main_window.get_hud()
52 
54 
55  swipe_coords = hud.get_button_swipe_coords(
56  self.main_window,
57  hud_show_button
58  )
59  initialBottomMargin = int(hud_show_button.bottomMargin)
60 
61  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
62  self.addCleanup(self._maybe_release_finger)
63  self._drag(
64  swipe_coords.start_x,
65  swipe_coords.start_y,
66  swipe_coords.start_x,
67  swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5)
68  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.5)))
69  self.assertThat(
70  hud_show_button.bottomMargin,
71  Eventually(Equals(initialBottomMargin)))
72  self._drag(
73  swipe_coords.start_x,
74  swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5,
75  swipe_coords.end_x,
76  swipe_coords.start_y - int(edge_drag_area.distanceThreshold) -
77  int(edge_drag_area.commitDistance) - 5)
78  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
79  self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(0.0)))
80  self.touch.release()
81  self.assertThat(hud.shown, Equals(False))
82  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
83 
84  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
85  self._drag(
86  swipe_coords.start_x,
87  swipe_coords.start_y,
88  swipe_coords.start_x,
89  swipe_coords.end_y - int(hud_show_button.height))
90  self.assertThat(hud.shown, Equals(False))
91  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
92  self.touch.release()
93  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
94  self.touch.tap(
95  swipe_coords.end_x,
96  swipe_coords.end_y - int(hud_show_button.height))
97  self.assertThat(hud.shown, Equals(False))
98  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
99 
101  """Releasing the touch on the 'show hud' button must display the hud.
102  Test that the hud button stays on screen and tapping it opens the
103  hud.
104 
105  """
106  unity_proxy = self.launch_unity()
107  unlock_unity(unity_proxy)
108  hud_show_button = self.main_window.get_hud_show_button()
109  hud = self.main_window.get_hud()
110 
112 
113  swipe_coords = hud.get_button_swipe_coords(
114  self.main_window,
115  hud_show_button
116  )
117 
118  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
119  self.addCleanup(self._maybe_release_finger)
120  self._drag(
121  swipe_coords.start_x,
122  swipe_coords.start_y,
123  swipe_coords.start_x,
124  swipe_coords.end_y)
125  self.assertThat(hud.shown, Eventually(Equals(False)))
126  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
127  self.touch.release()
128  self.assertThat(hud.shown, Eventually(Equals(True)))
129  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
130  x, y = hud.get_close_button_coords()
131  self.touch.tap(x, y)
132  self.assertThat(hud.shown, Eventually(Equals(False)))
133 
134  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
135  self._drag(
136  swipe_coords.start_x,
137  swipe_coords.start_y,
138  swipe_coords.start_x,
139  swipe_coords.end_y - int(hud_show_button.height))
140  self.assertThat(hud.shown, Equals(False))
141  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
142  self.touch.release()
143  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
144  self.touch.tap(swipe_coords.end_x, swipe_coords.end_y)
145  self.assertThat(hud.shown, Eventually(Equals(True)))
146  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
147 
149  """Tapping the close button of the Hud must dismiss it."""
150  unity_proxy = self.launch_unity()
151  unlock_unity(unity_proxy)
152  hud = self.main_window.get_hud()
153 
155 
156  hud.show()
157 
158  x, y = hud.get_close_button_coords()
159  self.touch.tap(x, y)
160  self.assertThat(hud.shown, Eventually(Equals(False)))
161 
163  """Once open the Hud must close if the upper bar is dragged and
164  released downward.
165 
166  """
167  unity_proxy = self.launch_unity()
168  unlock_unity(unity_proxy)
169  hud = self.main_window.get_hud()
170 
172 
173  hud.show()
174 
175  start_x, start_y = hud.get_close_button_coords()
176  end_x = start_x
177  end_y = int(self.main_window.height / 2)
178 
179  self.touch.drag(start_x, start_y, end_x, end_y)
180  self.assertThat(hud.shown, Eventually(Equals(False)))
181 
183  """Opening the Launcher while the Hud is active must close the Hud."""
184  unity_proxy = self.launch_unity()
185  unlock_unity(unity_proxy)
186  hud = self.main_window.get_hud()
187 
189 
190  hud.show()
191  self.main_window.open_launcher()
192 
193  self.assertThat(hud.shown, Eventually(Equals(False)))
194 
195  def _launch_test_app_from_app_screen(self):
196  """Launches the browser app using the Dash UI.
197 
198  Because when testing on the desktop running
199  self.launch_application() will launch the application on the desktop
200  itself and not within the Unity UI.
201 
202  """
203  dash = self.main_window.get_dash()
204  icon = dash.get_application_icon('Browser')
205  self.touch.tap_object(icon)
206 
207  # Ensure application is open
208  bottombar = self.main_window.get_bottombar()
209  self.assertThat(bottombar.applicationIsOnForeground,
210  Eventually(Equals(True)))
211 
212  # Because some tests are manually manipulating the finger, we want to
213  # cleanup if the test fails, but we don't want to fail with an exception if
214  # we don't.
215  def _maybe_release_finger(self):
216  """Only release the finger if it is in fact down."""
217  # XXX This ugly code is here just temporarily, waiting for uinput
218  # improvements to land on autopilot so we don't have to access device
219  # private internal attributes. --elopio - 2014-02-12
220  try:
221  pressed = self.touch._touch_finger is not None
222  except AttributeError:
223  pressed = self.touch.pressed
224  if pressed:
225  self.touch.release()