@@ -24,7 +24,7 @@ from 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
27−
27+from time import sleep
29class TestHud(UnityTestCase):
29class TestHud(UnityTestCase):
@@ -33,9 +33,10 @@ class TestHud(UnityTestCase):
33 scenarios = _get_device_emulation_scenarios()
33 scenarios = _get_device_emulation_scenarios()
35 def test_show_hud_button_appears(self):
35 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.
37 The button must disappear not opening the HUD when releasing the
37 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.
41 self.launch_unity()
42 self.launch_unity()
@@ -52,20 +53,32 @@ class TestHud(UnityTestCase):
52 hud_show_button
53 hud_show_button
54 initialBottomMargin = int(hud_show_button.bottomMargin)
55 initialBottomMargin = int(hud_show_button.bottomMargin)
55 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
57 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
56 self.addCleanup(self._maybe_release_finger)
58 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)
58 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.5)))
60 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.5)))
59 self.assertThat(hud_show_button.bottomMargin, Eventually(Equals(initialBottomMargin)))
61 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)
61 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
63 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)))
63 self.touch.release();
65 self.touch.release();
66+ self.assertThat(hud.shown, Equals(False))
64 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
67 self.assertThat(hud_show_button.opacity, Eventually(Equals(0.0)))
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))
65 self.assertThat(hud.shown, Equals(False))
71 self.assertThat(hud.shown, Equals(False))
72+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
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))
67 def test_show_hud_appears(self):
79 def test_show_hud_appears(self):
68 """Releasing the touch on the 'show hud' button must display the hud.
80 """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.
71 self.launch_unity()
84 self.launch_unity()
@@ -80,14 +93,28 @@ class TestHud(UnityTestCase):
81 hud_show_button
94 hud_show_button
83 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
97 self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
84 self.addCleanup(self._maybe_release_finger)
98 self.addCleanup(self._maybe_release_finger)
85− self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
99+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y)
87 self.assertThat(hud.shown, Eventually(Equals(False)))
100 self.assertThat(hud.shown, Eventually(Equals(False)))
88 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
101 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
89 self.touch.release()
102 self.touch.release()
90 self.assertThat(hud.shown, Eventually(Equals(True)))
103 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)))
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)))
92 def test_hide_hud_click(self):
119 def test_hide_hud_click(self):
93 """Tapping the close button of the Hud must dismiss it."""
120 """Tapping the close button of the Hud must dismiss it."""
@@ -160,3 +187,16 @@ class TestHud(UnityTestCase):
160 """Only release the finger if it is in fact down."""
187 """Only release the finger if it is in fact down."""
161 if self.touch._touch_finger is not None:
188 if self.touch._touch_finger is not None:
162 self.touch.release()
189 self.touch.release()
191+ def _drag(self, x1, y1, x2, y2):
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))
201+ self.touch._finger_move(int(x2), int(y2))