@@ -24,7 +24,7 @@ from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2424
2525from testtools.matchers import Equals
2626from autopilot.matchers import Eventually
27−
27+from time import sleep
2828
2929class TestHud(UnityTestCase):
3030
@@ -33,9 +33,10 @@ class TestHud(UnityTestCase):
3333 scenarios = _get_device_emulation_scenarios()
3434
3535 def test_show_hud_button_appears(self):
36− """Swiping up while an app is active must show the 'show hud' button.
36+ """Swiping up while an app is active must show the 'show hud' button, following some behaviours.
3737 The button must disappear not opening the HUD when releasing the
38− mouse again somewhere on the screen except on the button itself.
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.
3940
4041 """
4142 self.launch_unity()
@@ -52,20 +53,32 @@ class TestHud(UnityTestCase):
5253 hud_show_button
5354 )
5455 initialBottomMargin = int(hud_show_button.bottomMargin)
56+
5557 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
5658 self.addCleanup(self._maybe_release_finger)
57− self.touch._finger_move(swipe_coords.end_x, swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5);
59+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.start_y - int(edge_drag_area.distanceThreshold) - 5)
5860 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.5)))
5961 self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(initialBottomMargin)))
60− self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y - hud_show_button.height);
62+ 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)
6163 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
62−# self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(0.0)))
64+ self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(0.0)))
6365 self.touch.release();
66+ self.assertThat(hud.shown, Equals(False))
6467 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
68+
69+ self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
70+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y - int(hud_show_button.height))
6571 self.assertThat(hud.shown, Equals(False))
72+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
73+ self.touch.release()
74+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
75+ self.touch.tap(swipe_coords.end_x, swipe_coords.end_y - int(hud_show_button.height))
76+ self.assertThat(hud.shown, Equals(False))
77+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0), timeout=0.5))
6678
6779 def test_show_hud_appears(self):
6880 """Releasing the touch on the 'show hud' button must display the hud.
81+ Test that the hud button stays on screen and tapping it opens the hud.
6982
7083 """
7184 self.launch_unity()
@@ -80,14 +93,28 @@ class TestHud(UnityTestCase):
8093 window,
8194 hud_show_button
8295 )
96+
8397 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
8498 self.addCleanup(self._maybe_release_finger)
85− self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
86−
99+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y)
87100 self.assertThat(hud.shown, Eventually(Equals(False)))
88101 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
89102 self.touch.release()
90103 self.assertThat(hud.shown, Eventually(Equals(True)))
104+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
105+ x, y = hud.get_close_button_coords()
106+ self.touch.tap(x, y)
107+ self.assertThat(hud.shown, Eventually(Equals(False)))
108+
109+ self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
110+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y - int(hud_show_button.height))
111+ self.assertThat(hud.shown, Equals(False))
112+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
113+ self.touch.release()
114+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
115+ self.touch.tap(swipe_coords.end_x, swipe_coords.end_y)
116+ self.assertThat(hud.shown, Eventually(Equals(True)))
117+ self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
91118
92119 def test_hide_hud_click(self):
93120 """Tapping the close button of the Hud must dismiss it."""
@@ -160,3 +187,16 @@ class TestHud(UnityTestCase):
160187 """Only release the finger if it is in fact down."""
161188 if self.touch._touch_finger is not None:
162189 self.touch.release()
190+
191+ def _drag(self, x1, y1, x2, y2):
192+ cur_x = x1
193+ cur_y = y1
194+ dx = 1.0 * (x2 - x1) / 100
195+ dy = 1.0 * (y2 - y1) / 100
196+ for i in range(0, 100):
197+ self.touch._finger_move(int(cur_x), int(cur_y))
198+ sleep(0.002)
199+ cur_x += dx
200+ cur_y += dy
201+ self.touch._finger_move(int(x2), int(y2))
202+