@@ -19,29 +19,30 @@
20from __future__ import absolute_import
20from __future__ import absolute_import
22−from unity8.shell import with_lightdm_mock
22+from unity8.shell import with_lightdm_mock, DragMixin
23from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
23from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
25from testtools.matchers import Equals
25from testtools.matchers import Equals
26from autopilot.matchers import Eventually
26from autopilot.matchers import Eventually
29−class TestHud(UnityTestCase):
28+class TestHud(UnityTestCase, DragMixin):
31 """Tests the Shell HUD."""
30 """Tests the Shell HUD."""
33 scenarios = _get_device_emulation_scenarios()
32 scenarios = _get_device_emulation_scenarios()
35 def test_show_hud_button_appears(self):
34 def test_show_hud_button_appears(self):
36− """Swiping up while an app is active must show the 'show hud' button.
35+ """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
36 The button must disappear not opening the HUD when releasing the
38− mouse again somewhere on the screen except on the button itself.
37+ mouse again somewhere on the screen except on the button itself following a timeout.
38+ The button must disappear when touching somewhere on the screen except the button itself.
41 self.launch_unity()
41 self.launch_unity()
42 self.main_window.get_greeter().swipe()
42 self.main_window.get_greeter().swipe()
43 window = self.main_window.get_qml_view()
43 window = self.main_window.get_qml_view()
44 hud_show_button = self.main_window.get_hud_show_button()
44 hud_show_button = self.main_window.get_hud_show_button()
45+ edge_drag_area = self.main_window.get_hud_edge_drag_area()
45 hud = self.main_window.get_hud()
46 hud = self.main_window.get_hud()
47 self._launch_test_app_from_app_screen()
48 self._launch_test_app_from_app_screen()
@@ -50,16 +51,33 @@ class TestHud(UnityTestCase):
51 hud_show_button
52 hud_show_button
54+ initialBottomMargin = int(hud_show_button.bottomMargin)
53 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
56 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
54 self.addCleanup(self._maybe_release_finger)
57 self.addCleanup(self._maybe_release_finger)
55− self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y + hud_show_button.height);
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)
56 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
62 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
63+ self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(0.0)))
57 self.touch.release();
64 self.touch.release();
65+ self.assertThat(hud.shown, Equals(False))
58 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
66 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
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)))
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))
59 self.assertThat(hud.shown, Equals(False))
75 self.assertThat(hud.shown, Equals(False))
76+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
61 def test_show_hud_appears(self):
78 def test_show_hud_appears(self):
62 """Releasing the touch on the 'show hud' button must display the hud.
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.
65 self.launch_unity()
83 self.launch_unity()
@@ -74,14 +92,28 @@ class TestHud(UnityTestCase):
75 hud_show_button
93 hud_show_button
77 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
96 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
78 self.addCleanup(self._maybe_release_finger)
97 self.addCleanup(self._maybe_release_finger)
79− self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
98+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y)
80−
99+ self.assertThat(hud.shown, Eventually(Equals(False)))
100+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
101+ self.touch.release()
102+ self.assertThat(hud.shown, Eventually(Equals(True)))
103+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
104+ x, y = hud.get_close_button_coords()
105+ self.touch.tap(x, y)
81 self.assertThat(hud.shown, Eventually(Equals(False)))
106 self.assertThat(hud.shown, Eventually(Equals(False)))
108+ self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
109+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y - int(hud_show_button.height))
110+ self.assertThat(hud.shown, Equals(False))
82 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
111 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
83 self.touch.release()
112 self.touch.release()
113+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
114+ self.touch.tap(swipe_coords.end_x, swipe_coords.end_y)
84 self.assertThat(hud.shown, Eventually(Equals(True)))
115 self.assertThat(hud.shown, Eventually(Equals(True)))
116+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
86 def test_hide_hud_click(self):
118 def test_hide_hud_click(self):
87 """Tapping the close button of the Hud must dismiss it."""
119 """Tapping the close button of the Hud must dismiss it."""
@@ -90,6 +122,7 @@ class TestHud(UnityTestCase):
90 hud = self.main_window.get_hud()
122 hud = self.main_window.get_hud()
92 self._launch_test_app_from_app_screen()
124 self._launch_test_app_from_app_screen()
93 hud.show()
126 hud.show()
95 x, y = hud.get_close_button_coords()
128 x, y = hud.get_close_button_coords()
@@ -103,10 +136,11 @@ class TestHud(UnityTestCase):
104 self.launch_unity()
137 self.launch_unity()
105 self.main_window.get_greeter().swipe()
138 self.main_window.get_greeter().swipe()
106− hud = self.main_window.get_hud()
107 window = self.main_window.get_qml_view()
139 window = self.main_window.get_qml_view()
140+ hud = self.main_window.get_hud()
109 self._launch_test_app_from_app_screen()
142 self._launch_test_app_from_app_screen()
110 hud.show()
144 hud.show()
112 start_x, start_y = hud.get_close_button_coords()
146 start_x, start_y = hud.get_close_button_coords()