Unity 8
 All Classes Functions Properties
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 with_lightdm_mock, 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 class TestHud(UnityTestCase, DragMixin):
30 
31  """Tests the Shell HUD."""
32 
33  scenarios = _get_device_emulation_scenarios()
34 
36  """Swiping up while an app is active must show the 'show hud' button, following some behaviours.
37  The button must disappear not opening the HUD when releasing the
38  mouse again somewhere on the screen except on the button itself following a timeout.
39  The button must disappear when touching somewhere on the screen except the button itself.
40 
41  """
42  unity_proxy = self.launch_unity()
43  unlock_unity(unity_proxy)
44  hud_show_button = self.main_window.get_hud_show_button()
45  edge_drag_area = self.main_window.get_hud_edge_drag_area()
46  hud = self.main_window.get_hud()
47 
49 
50  swipe_coords = hud.get_button_swipe_coords(
51  self.main_window,
52  hud_show_button
53  )
54  initialBottomMargin = int(hud_show_button.bottomMargin)
55 
56  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
57  self.addCleanup(self._maybe_release_finger)
58  self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5)
59  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.5)))
60  self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(initialBottomMargin)))
61  self._drag(swipe_coords.start_x, swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5, swipe_coords.end_x, swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - int(edge_drag_area.commitDistance) - 5)
62  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
63  self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(0.0)))
64  self.touch.release();
65  self.assertThat(hud.shown, Equals(False))
66  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
67 
68  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
69  self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y - int(hud_show_button.height))
70  self.assertThat(hud.shown, Equals(False))
71  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
72  self.touch.release()
73  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
74  self.touch.tap(swipe_coords.end_x, swipe_coords.end_y - int(hud_show_button.height))
75  self.assertThat(hud.shown, Equals(False))
76  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
77 
79  """Releasing the touch on the 'show hud' button must display the hud.
80  Test that the hud button stays on screen and tapping it opens the hud.
81 
82  """
83  unity_proxy = self.launch_unity()
84  unlock_unity(unity_proxy)
85  hud_show_button = self.main_window.get_hud_show_button()
86  hud = self.main_window.get_hud()
87 
89 
90  swipe_coords = hud.get_button_swipe_coords(
91  self.main_window,
92  hud_show_button
93  )
94 
95  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
96  self.addCleanup(self._maybe_release_finger)
97  self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y)
98  self.assertThat(hud.shown, Eventually(Equals(False)))
99  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
100  self.touch.release()
101  self.assertThat(hud.shown, Eventually(Equals(True)))
102  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
103  x, y = hud.get_close_button_coords()
104  self.touch.tap(x, y)
105  self.assertThat(hud.shown, Eventually(Equals(False)))
106 
107  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
108  self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y - int(hud_show_button.height))
109  self.assertThat(hud.shown, Equals(False))
110  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
111  self.touch.release()
112  self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
113  self.touch.tap(swipe_coords.end_x, swipe_coords.end_y)
114  self.assertThat(hud.shown, Eventually(Equals(True)))
115  self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
116 
118  """Tapping the close button of the Hud must dismiss it."""
119  unity_proxy = self.launch_unity()
120  unlock_unity(unity_proxy)
121  hud = self.main_window.get_hud()
122 
124 
125  hud.show()
126 
127  x, y = hud.get_close_button_coords()
128  self.touch.tap(x, y)
129  self.assertThat(hud.shown, Eventually(Equals(False)))
130 
132  """Once open the Hud must close if the upper bar is dragged and
133  released downward.
134 
135  """
136  unity_proxy = self.launch_unity()
137  unlock_unity(unity_proxy)
138  hud = self.main_window.get_hud()
139 
141 
142  hud.show()
143 
144  start_x, start_y = hud.get_close_button_coords()
145  end_x = start_x
146  end_y = int(self.main_window.height / 2)
147 
148  self.touch.drag(start_x, start_y, end_x, end_y)
149  self.assertThat(hud.shown, Eventually(Equals(False)))
150 
152  """Opening the Launcher while the Hud is active must close the Hud."""
153  unity_proxy = self.launch_unity()
154  unlock_unity(unity_proxy)
155  hud = self.main_window.get_hud()
156  launcher = self.main_window.get_launcher()
157 
159 
160  hud.show()
161  launcher.show()
162 
163  self.assertThat(hud.shown, Eventually(Equals(False)))
164 
165  def _launch_test_app_from_app_screen(self):
166  """Launches the browser app using the Dash UI.
167 
168  Because when testing on the desktop running
169  self.launch_application() will launch the application on the desktop
170  itself and not within the Unity UI.
171 
172  """
173  dash = self.main_window.get_dash()
174  icon = dash.get_application_icon('Browser')
175  self.touch.tap_object(icon)
176 
177  # Ensure application is open
178  bottombar = self.main_window.get_bottombar()
179  self.assertThat(bottombar.applicationIsOnForeground,
180  Eventually(Equals(True)))
181 
182  # Because some tests are manually manipulating the finger, we want to
183  # cleanup if the test fails, but we don't want to fail with an exception if
184  # we don't.
185  def _maybe_release_finger(self):
186  """Only release the finger if it is in fact down."""
187  # XXX This ugly code is here just temporarily, waiting for uinput
188  # improvements to land on autopilot so we don't have to access device
189  # private internal attributes. --elopio - 2014-02-12
190  try:
191  pressed = self.touch._touch_finger is not None
192  except AttributeError:
193  pressed = self.touch.pressed
194  if pressed:
195  self.touch.release()