on xenial help sign in
Created Hud,Dash,Launcher emulators. Fixing up Hud tests.
commita918cebcda66ff47cc32438cd74355d690f2df22 authorChristopher Lee <chris.lee@canonical.com> dateTue 16 Jul 2013, 20:00 (13 years ago) parent814a6b6
5 files changed+199−79
run+1 tests/autopilot/unity8/__init__.py+1−1 tests/autopilot/unity8/shell/emulators/main_window.py+3 tests/autopilot/unity8/shell/tests/__init__.py+32−5 tests/autopilot/unity8/shell/tests/test_hud.py+162−73
run+1
@@ -68,5 +68,6 @@ fi
6868if $GDB; then
6969 gdb -ex run --args $QML_PHONE_SHELL_PATH $QML_PHONE_SHELL_ARGS $@
7070else
71+ echo $QML_PHONE_SHELL_PATH $QML_PHONE_SHELL_ARGS $@
7172 $QML_PHONE_SHELL_PATH $QML_PHONE_SHELL_ARGS $@
7273fi
tests/autopilot/unity8/__init__.py+1−1
@@ -30,7 +30,7 @@ def get_unity8_binary_path():
3030 binary_path = os.path.abspath(
3131 os.path.join(
3232 os.path.dirname(__file__),
33− "../../../../../builddir/unity8"
33+ "../../../builddir/unity8"
3434 )
3535 )
3636 if not os.path.exists(binary_path):
tests/autopilot/unity8/shell/emulators/main_window.py+3
@@ -7,6 +7,9 @@
77
88
99from unity8.shell.emulators.greeter import Greeter
10+from unity8.shell.emulators.hud import Hud
11+from unity8.shell.emulators.dash import Dash
12+from unity8.shell.emulators.launcher import Launcher
1013
1114
1215class MainWindow(object):
tests/autopilot/unity8/shell/tests/__init__.py+32−5
@@ -27,6 +27,12 @@ logger = logging.getLogger(__name__)
2727class FormFactors(object):
2828 Phone, Tablet, Desktop = range(3)
2929
30+def _get_device_emulation_scenarios():
31+ if model() == 'Desktop':
32+ return [ ('Desktop Nexus 4', dict(app_width=384, app_height=640, grid_unit_px=18)) ]
33+ # return [ ('Desktop Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18)) ]
34+ else:
35+ return [ ('Native Device', dict(app_width=0, app_height=0, grid_unit_px=0)) ]
3036
3137class Unity8TestCase(AutopilotTestCase):
3238
@@ -36,6 +42,27 @@ class Unity8TestCase(AutopilotTestCase):
3642 super(Unity8TestCase, self).setUp()
3743 self._proxy = None
3844 self.touch = Touch.create()
45+ self._setup_grid_size()
46+ self._determine_geometry()
47+
48+ def _setup_grid_size(self):
49+ """Use the grid size that may be supplied or use the default."""
50+ if getattr(self, 'grid_unit_px', 0) == 0:
51+ self.grid_size = int(os.getenv['GRID_UNIT_PX'])
52+ else:
53+ self.grid_size = self.grid_unit_px
54+ self.patch_environment("GRID_UNIT_PX", str(self.grid_size))
55+
56+ def _determine_geometry(self):
57+ """Use the geometry that may be supplied or use the default."""
58+ width = getattr(self, 'app_width', 0)
59+ height = getattr(self, 'app_height', 0)
60+ if width == 0 and width == 0:
61+ self.unity_geometry_args = ['-fullscreen']
62+ else:
63+ # Work it out until it fits to screen i.e. divisor
64+ geo_string = "%sx%s" % (width, height)
65+ self.unity_geometry_args = ['-geometry', geo_string, '-frameless', '-mousetouch']
3966
4067 def launch_unity(self):
4168 """Launch the unity8 shell, return a proxy object for it."""
@@ -56,11 +83,11 @@ class Unity8TestCase(AutopilotTestCase):
5683
5784 # launch the shell:
5885 app_proxy = self.launch_test_application(
59− binary_path,
60− "-fullscreen",
61− app_type='qt',
62− emulator_base=Unity8EmulatorBase,
63− )
86+ binary_path,
87+ *self.unity_geometry_args,
88+ app_type='qt',
89+ emulator_base=Unity8EmulatorBase
90+ )
6491 logger.debug("Started unity8 shell, backend is: %r", app_proxy._Backend)
6592 self._set_proxy(app_proxy)
6693
tests/autopilot/unity8/shell/tests/test_hud.py+162−73
@@ -25,7 +25,9 @@
2525
2626from __future__ import absolute_import
2727
28−from unity8.shell.tests import Unity8TestCase
28+from collections import namedtuple
29+
30+from unity8.shell.tests import Unity8TestCase, _get_device_emulation_scenarios
2931
3032from autopilot.input import Touch
3133from testtools.matchers import Equals, MismatchError
@@ -34,98 +36,185 @@ from autopilot.display import Display
3436from autopilot.platform import model
3537
3638
39+SwipeCoords = namedtuple('SwipeCoords', 'start_x end_x start_y end_y')
40+
41+
3742class TestHud(Unity8TestCase):
3843
3944 """Tests the Shell HUD"""
4045
41− # Scenarios:
42− # Fill in the scenarios to run the whole test suite with multiple configurations.
43− # Use app_width, app_height and grid_unit_px to set the apps geometry.
44− # Set app_width and app_height to 0 to use fullscreen.
45− # Set grid_unit_px to 0 to use the current system environment.
46−
47−# if model() == 'Desktop':
48−# scenarios = [
49−# ('Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18, lightdm_mock="single")),
50−# ('Nexus 10', dict(app_width=2560, app_height=1600, grid_unit_px=20, lightdm_mock="full")),
51−# # TODO: don't run fullscreen tests just yet as the VM is performing too badly for that. Enable this once
52−# # Autopilot tests are running on bear metal.
53−# # ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=10, lightdm_mock="full")),
54−# ]
55−# else:
56−# scenarios = [
57−# ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=0, lightdm_mock="single")),
58−# ]
59−
60−
61− def test_show_hud(self):
46+ scenarios = _get_device_emulation_scenarios()
47+
48+ def _launch_application_from_app_screen(self):
49+ # find the first application and launch it.
50+ # becuase launch_application on the desktop will launch it on the
51+ # desktop.
52+ dash = self.main_window.get_dash()
53+ icon = dash.get_application_icon()
54+ self.touch.tap_object(icon)
55+
56+ # Ensure application is open
57+ bottombar = self.main_window.get_bottombar()
58+ self.assertThat(bottombar.applicationIsOnForeground, Eventually(Equals(True)))
59+
60+ # Because some tests are manually manipulating the finger, we want to
61+ # cleanup if the test fails, but we don't want to fail with an exception if
62+ # we don't.
63+ def _maybe_release_finger(self):
64+ """Only release the finger if it is in fact down."""
65+ if self.touch._touch_finger is not None:
66+ self.touch.release()
67+
68+ def test_show_hud_button_appears(self):
69+ """Swiping up while an app is active must show the 'show hud' button."""
6270 self.launch_unity()
71+ self.main_window.get_greeter().unlock()
72+
73+ window = self.main_window.get_qml_view()
74+ hud_show_button = self.main_window.get_hud_show_button()
6375 hud = self.main_window.get_hud()
64− greeter = self.main_window.get_greeter()
65− greeter.unlock()
6676
67− self.show_hud()
68− self.assertThat(hud.shown, Eventually(Equals(True)))
77+ # determine the swipe
78+ swipe_coords = self._get_hud_button_swipe_coords(window, hud_show_button)
79+ # start_x = int(window.x + (window.width / 2))
80+ # end_x = start_x
81+ # start_y = window.y + (window.height -3)
82+ # end_y = int(hud_show_button.y)
83+
84+ self._launch_application_from_app_screen()
6985
70− def test_show_hud_button_dont_open(self):
71− self.unlock_greeter()
72− self.open_first_dash_home_app()
86+ self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
87+ self.addCleanup(self.touch.release)
88+ self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
89+
90+ hud_show_button.opacity.wait_for(1.0)
91+ self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
92+
93+ def test_show_hud_appears(self):
94+ """Releasing the touch on the 'show hud' button must display the hud."""
95+ self.launch_unity()
96+ self.main_window.get_greeter().unlock()
97+
98+ window = self.main_window.get_qml_view()
7399 hud_show_button = self.main_window.get_hud_show_button()
74100 hud = self.main_window.get_hud()
75− window = self.main_window.get_qml_view()
76− start_x = int(window.x + window.width / 2)
77− start_y = window.y + window.height - 2
78− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
79− self.touch.press(start_x, start_y)
80− self.touch._finger_move(start_x, start_y - self.grid_size)
81− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
82− self.touch._finger_move(start_x, start_y - self.grid_size * 2)
83− self.touch._finger_move(start_x, start_y - self.grid_size * 3)
84− self.touch._finger_move(start_x, start_y - self.grid_size * 4)
85− self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
86− self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
87− self.touch._finger_move(start_x, start_y - self.grid_size * 34)
88− self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
89− self.assertThat(hud_show_button.mouseOver, Eventually(Equals(True)))
90− self.touch._finger_move(start_x, start_y - self.grid_size)
101+
102+ # determine the swipe
103+ swipe_coords = self._get_hud_button_swipe_coords(window, hud_show_button)
104+ # start_x = int(window.x + (window.width / 2))
105+ # end_x = start_x
106+ # start_y = window.y + (window.height -3)
107+ # end_y = int(hud_show_button.y)
108+
109+ self._launch_application_from_app_screen()
110+
111+ self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
112+ self.addCleanup(self._maybe_release_finger)
113+ self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
114+
115+ self.assertThat(hud.shown, Eventually(Equals(False)))
116+ hud_show_button.opacity.wait_for(1.0)
91117 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
92− self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
93118 self.touch.release()
94− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
95− self.assertThat(hud.shown, Eventually(Equals(False)))
119+ self.assertThat(hud.shown, Eventually(Equals(True)))
120+
121+ # self.launch_unity()
122+ # hud = self.main_window.get_hud()
123+ # greeter = self.main_window.get_greeter()
124+ # greeter.unlock()
125+
126+ # self._launch_application_from_app_screen()
127+
128+ # hud.show()
129+ # self.assertThat(hud.shown, Eventually(Equals(True)))
130+
131+ # def test_show_hud_button_dont_open(self):
132+ # self.launch_unity()
133+ # hud_show_button = self.main_window.get_hud_show_button()
134+ # hud = self.main_window.get_hud()
135+ # greeter = self.main_window.get_greeter()
136+ # greeter.unlock()
137+
138+ # self.unlock_greeter()
139+ # self.open_first_dash_home_app()
140+ # hud_show_button = self.main_window.get_hud_show_button()
141+ # hud = self.main_window.get_hud()
142+ # window = self.main_window.get_qml_view()
143+ # start_x = int(window.x + window.width / 2)
144+ # start_y = window.y + window.height - 2
145+ # self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
146+ # self.touch.press(start_x, start_y)
147+ # self.touch._finger_move(start_x, start_y - self.grid_size)
148+ # self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
149+ # self.touch._finger_move(start_x, start_y - self.grid_size * 2)
150+ # self.touch._finger_move(start_x, start_y - self.grid_size * 3)
151+ # self.touch._finger_move(start_x, start_y - self.grid_size * 4)
152+ # self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
153+ # self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
154+ # self.touch._finger_move(start_x, start_y - self.grid_size * 34)
155+ # self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
156+ # self.assertThat(hud_show_button.mouseOver, Eventually(Equals(True)))
157+ # self.touch._finger_move(start_x, start_y - self.grid_size)
158+ # self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
159+ # self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
160+ # self.touch.release()
161+ # self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
162+ # self.assertThat(hud.shown, Eventually(Equals(False)))
96163
97164 def test_hide_hud_click(self):
165+ """Tapping the close button of the Hud must dismiss it."""
166+ self.launch_unity()
167+ self.main_window.get_greeter().unlock()
168+ self._launch_application_from_app_screen()
98169 hud = self.main_window.get_hud()
99− self.unlock_greeter()
100− self.show_hud()
101− self.close_hud_click()
102− self.assertThat(hud.shown, Eventually(Equals(False)))
170+ hud.show()
103171
104− def test_hide_hud_click_outside_handle(self):
105− hud = self.main_window.get_hud()
106− self.unlock_greeter()
107− self.show_hud()
108172 rect = hud.globalRect
109173 x = int(rect[0] + rect[2] / 2)
110− y = rect[1] + hud.handleHeight + 1
111− self.touch.tap(x, y)
112− self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
174+ y = rect[1] + self.grid_size
113175
114− def test_hide_hud_dragging(self):
115− hud = self.main_window.get_hud()
116− self.unlock_greeter()
117− self.show_hud()
118− rect = hud.globalRect
119− start_x = rect[0] + (rect[2] - rect[0]) / 2
120− start_y = rect[1] + 1
121− stop_x = start_x
122− stop_y = start_y + (rect[3] - rect[1]) / 2
123− self.touch.drag(start_x, start_y, stop_x, stop_y)
176+ self.touch.tap(x, y)
124177 self.assertThat(hud.shown, Eventually(Equals(False)))
125178
126− def test_hide_hud_launcher(self):
179+ # def test_hide_hud_click_outside_handle(self):
180+ # hud = self.main_window.get_hud()
181+ # self.unlock_greeter()
182+ # self.show_hud()
183+ # rect = hud.globalRect
184+ # x = int(rect[0] + rect[2] / 2)
185+ # y = rect[1] + hud.handleHeight + 1
186+ # self.touch.tap(x, y)
187+ # self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
188+
189+ # def test_hide_hud_dragging(self):
190+ # hud = self.main_window.get_hud()
191+ # self.unlock_greeter()
192+ # self.show_hud()
193+ # rect = hud.globalRect
194+ # start_x = rect[0] + (rect[2] - rect[0]) / 2
195+ # start_y = rect[1] + 1
196+ # stop_x = start_x
197+ # stop_y = start_y + (rect[3] - rect[1]) / 2
198+ # self.touch.drag(start_x, start_y, stop_x, stop_y)
199+ # self.assertThat(hud.shown, Eventually(Equals(False)))
200+
201+ def test_launcher_hides_hud(self):
202+ """Opening the Launcher while the Hud is active must close the Hud."""
203+ self.launch_unity()
204+ self.main_window.get_greeter().unlock()
205+ self._launch_application_from_app_screen()
127206 hud = self.main_window.get_hud()
128− self.unlock_greeter()
129− self.show_hud()
130− self.show_launcher()
207+ launcher = self.main_window.get_launcher()
208+
209+ hud.show()
210+ launcher.show()
211+
131212 self.assertThat(hud.shown, Eventually(Equals(False)))
213+
214+ def _get_hud_button_swipe_coords(self, main_view, hud_show_button):
215+ start_x = int(main_view.x + (main_view.width / 2))
216+ end_x = start_x
217+ start_y = main_view.y + (main_view.height -3)
218+ end_y = int(hud_show_button.y)
219+
220+ return SwipeCoords(start_x, end_x, start_y, end_y)