on xenial help sign in
Added scenarios for hud tests, further cleanup.
1a74d99Christopher Lee
tests/autopilot/unity8/__init__.py+7−2
@@ -11,16 +11,21 @@ import subprocess
11import sysconfig
11import sysconfig
12
12
13
13
14+def running_installed_tests():
15+ binary_path = get_unity8_binary_path()
16+ return binary_path.startswith('/usr')
17+
18+
14def get_lib_path():
19def get_lib_path():
15 """Return the library path to use in this test run."""
20 """Return the library path to use in this test run."""
16− binary_path = get_unity8_binary_path()
21+ if running_installed_tests():
17− if binary_path.startswith("/usr"):
18 lib_path = os.path.join(
22 lib_path = os.path.join(
19 "/usr/lib/",
23 "/usr/lib/",
20 sysconfig.get_config_var('MULTIARCH'),
24 sysconfig.get_config_var('MULTIARCH'),
21 "unity8"
25 "unity8"
22 )
26 )
23 else:
27 else:
28+ binary_path = get_unity8_binary_path()
24 lib_path = os.path.dirname(binary_path)
29 lib_path = os.path.dirname(binary_path)
25 return lib_path
30 return lib_path
26
31
tests/autopilot/unity8/shell/__init__.py+26−13
@@ -10,7 +10,7 @@
10from functools import wraps
10from functools import wraps
11import os.path
11import os.path
12
12
13−from unity8 import get_lib_path
13+from unity8 import get_lib_path, running_installed_tests
14
14
15import logging
15import logging
16
16
@@ -23,19 +23,32 @@ def with_lightdm_mock(mock_type):
23 @wraps(fn)
23 @wraps(fn)
24 def wrapper(*args, **kwargs):
24 def wrapper(*args, **kwargs):
25 logger.info("Setting up LightDM mock type '%s'", mock_type)
25 logger.info("Setting up LightDM mock type '%s'", mock_type)
26− lib_path = get_lib_path()
27− new_ld_library_path = os.path.join(
26+ new_ld_library_path = _get_ld_library_path(mock_type)
28− lib_path,
29− "qml/mocks/LightDM/",
30− mock_type
31− )
32− if not os.path.exists(new_ld_library_path):
33− raise RuntimeError(
34− "LightDM mock '%s' does not exist." % mock_type
35− )
36−
37 logger.info("New library path: %s", new_ld_library_path)
27 logger.info("New library path: %s", new_ld_library_path)
28+ tests_self = args[0]
38− args[0].patch_environment('LD_LIBRARY_PATH', new_ld_library_path)
29+ tests_self.patch_environment('LD_LIBRARY_PATH', new_ld_library_path)
39 return fn(*args, **kwargs)
30 return fn(*args, **kwargs)
40 return wrapper
31 return wrapper
41 return with_lightdm_mock_internal
32 return with_lightdm_mock_internal
33+
34+
35+def _get_ld_library_path(mock_type):
36+ if running_installed_tests():
37+ mock_path = "qml/mocks/LightDM/"
38+ else:
39+ mock_path = "../builddir/tests/mocks/LightDM/"
40+ lib_path = get_lib_path()
41+ new_ld_library_path = os.path.abspath(
42+ os.path.join(
43+ lib_path,
44+ mock_path,
45+ mock_type
46+ )
47+ )
48+
49+ if not os.path.exists(new_ld_library_path):
50+ raise RuntimeError(
51+ "LightDM mock '%s' does not exist at path '%s'."
52+ % (mock_type, new_ld_library_path)
53+ )
54+ return new_ld_library_path
tests/autopilot/unity8/shell/emulators/main_window.py+1−1
@@ -44,7 +44,7 @@ class MainWindow(object):
44 return self.app.select_single("HudButton")
44 return self.app.select_single("HudButton")
45
45
46 def get_dash(self):
46 def get_dash(self):
47− return self.app.select_single("Dash")
47+ return self.app.select_single(Dash)
48
48
49 def get_dash_home_applications_grid(self):
49 def get_dash_home_applications_grid(self):
50 return self.app.select_single("ApplicationsFilterGrid", objectName="dashHomeApplicationsGrid")
50 return self.app.select_single("ApplicationsFilterGrid", objectName="dashHomeApplicationsGrid")
tests/autopilot/unity8/shell/tests/__init__.py+3−2
@@ -20,6 +20,7 @@ import sysconfig
20from unity8 import get_lib_path, get_unity8_binary_path
20from unity8 import get_lib_path, get_unity8_binary_path
21from unity8.shell.emulators.main_window import MainWindow
21from unity8.shell.emulators.main_window import MainWindow
22from unity8.shell.emulators import Unity8EmulatorBase
22from unity8.shell.emulators import Unity8EmulatorBase
23+from unity8.shell.emulators.dash import Dash
23
24
24
25
25logger = logging.getLogger(__name__)
26logger = logging.getLogger(__name__)
@@ -73,7 +74,7 @@ class Unity8TestCase(AutopilotTestCase):
73 def _setup_grid_size(self, scale_divisor):
74 def _setup_grid_size(self, scale_divisor):
74 """Use the grid size that may be supplied or use the default."""
75 """Use the grid size that may be supplied or use the default."""
75 if getattr(self, 'grid_unit_px', 0) == 0:
76 if getattr(self, 'grid_unit_px', 0) == 0:
76− self.grid_size = int(os.getenv['GRID_UNIT_PX'])
77+ self.grid_size = int(os.getenv('GRID_UNIT_PX'))
77 else:
78 else:
78 self.grid_size = int(self.grid_unit_px / scale_divisor)
79 self.grid_size = int(self.grid_unit_px / scale_divisor)
79 self.patch_environment("GRID_UNIT_PX", str(self.grid_size))
80 self.patch_environment("GRID_UNIT_PX", str(self.grid_size))
@@ -145,7 +146,7 @@ class Unity8TestCase(AutopilotTestCase):
145 self._proxy = None
146 self._proxy = None
146
147
147 def get_dash(self):
148 def get_dash(self):
148− dash = self._proxy.select_single("Dash")
149+ dash = self._proxy.select_single(Dash)
149 self.assertThat(dash, NotEquals(None))
150 self.assertThat(dash, NotEquals(None))
150 return dash
151 return dash
151
152
tests/autopilot/unity8/shell/tests/test_hud.py+6
@@ -9,6 +9,7 @@ from __future__ import absolute_import
9
9
10from collections import namedtuple
10from collections import namedtuple
11
11
12+from unity8.shell import with_lightdm_mock
12from unity8.shell.tests import Unity8TestCase, _get_device_emulation_scenarios
13from unity8.shell.tests import Unity8TestCase, _get_device_emulation_scenarios
13
14
14from autopilot.display import Display
15from autopilot.display import Display
@@ -27,6 +28,7 @@ class TestHud(Unity8TestCase):
27
28
28 scenarios = _get_device_emulation_scenarios()
29 scenarios = _get_device_emulation_scenarios()
29
30
31+ @with_lightdm_mock("single")
30 def test_show_hud_button_appears(self):
32 def test_show_hud_button_appears(self):
31 """Swiping up while an app is active must show the 'show hud' button."""
33 """Swiping up while an app is active must show the 'show hud' button."""
32 self.launch_unity()
34 self.launch_unity()
@@ -43,6 +45,7 @@ class TestHud(Unity8TestCase):
43 self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
45 self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
44 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
46 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
45
47
48+ @with_lightdm_mock("single")
46 def test_show_hud_appears(self):
49 def test_show_hud_appears(self):
47 """Releasing the touch on the 'show hud' button must display the hud."""
50 """Releasing the touch on the 'show hud' button must display the hud."""
48 self.launch_unity()
51 self.launch_unity()
@@ -96,6 +99,7 @@ class TestHud(Unity8TestCase):
96 # self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
99 # self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
97 # self.assertThat(hud.shown, Eventually(Equals(False)))
100 # self.assertThat(hud.shown, Eventually(Equals(False)))
98
101
102+ @with_lightdm_mock("single")
99 def test_hide_hud_click(self):
103 def test_hide_hud_click(self):
100 """Tapping the close button of the Hud must dismiss it."""
104 """Tapping the close button of the Hud must dismiss it."""
101 self.launch_unity()
105 self.launch_unity()
@@ -119,6 +123,7 @@ class TestHud(Unity8TestCase):
119 # self.touch.tap(x, y)
123 # self.touch.tap(x, y)
120 # self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
124 # self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
121
125
126+ @with_lightdm_mock("single")
122 def test_hide_hud_dragging(self):
127 def test_hide_hud_dragging(self):
123 """Once open the Hud must close if the upper bar is dragged and released
128 """Once open the Hud must close if the upper bar is dragged and released
124 downward.
129 downward.
@@ -139,6 +144,7 @@ class TestHud(Unity8TestCase):
139 self.touch.drag(start_x, start_y, end_x, end_y)
144 self.touch.drag(start_x, start_y, end_x, end_y)
140 self.assertThat(hud.shown, Eventually(Equals(False)))
145 self.assertThat(hud.shown, Eventually(Equals(False)))
141
146
147+ @with_lightdm_mock("single")
142 def test_launcher_hides_hud(self):
148 def test_launcher_hides_hud(self):
143 """Opening the Launcher while the Hud is active must close the Hud."""
149 """Opening the Launcher while the Hud is active must close the Hud."""
144 self.launch_unity()
150 self.launch_unity()
tests/autopilot/unity8/shell/tests/testhud.pydeleted−123
@@ -1,123 +0,0 @@
1−# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2−# Copyright 2013 Canonical
3−#
4−# This program is free software: you can redistribute it and/or modify it
5−# under the terms of the GNU General Public License version 3, as published
6−# by the Free Software Foundation.
7−
8−
9−"""Tests for the Shell"""
10−
11−from __future__ import absolute_import
12−
13−from unity8.shell.tests import Unity8TestCase
14−
15−from autopilot.input import Touch
16−from testtools.matchers import Equals, MismatchError
17−from autopilot.matchers import Eventually
18−from autopilot.display import Display
19−
20−
21−class TestHud(Unity8TestCase):
22−
23− """Tests the Shell HUD."""
24−
25− # Scenarios:
26− # Fill in the scenarios to run the whole test suite with multiple configurations.
27− # Use app_width, app_height and grid_unit_px to set the apps geometry.
28− # Set app_width and app_height to 0 to use fullscreen.
29− # Set grid_unit_px to 0 to use the current system environment.
30−
31−# if model() == 'Desktop':
32−# scenarios = [
33−# ('Nexus 4', dict(app_width=768, app_height=1280, grid_unit_px=18, lightdm_mock="single")),
34−# ('Nexus 10', dict(app_width=2560, app_height=1600, grid_unit_px=20, lightdm_mock="full")),
35−# # TODO: don't run fullscreen tests just yet as the VM is performing too badly for that. Enable this once
36−# # Autopilot tests are running on bear metal.
37−# # ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=10, lightdm_mock="full")),
38−# ]
39−# else:
40−# scenarios = [
41−# ('Fullscreen', dict(app_width=0, app_height=0, grid_unit_px=0, lightdm_mock="single")),
42−# ]
43−
44− def setUp(self):
45− self.touch = Touch.create()
46−
47− sg = Display().create()
48− divisor = 1
49− while (sg.get_screen_width() < self.app_width / divisor or sg.get_screen_height() < self.app_height / divisor):
50− divisor = divisor * 2
51− super(TestHud, self).setUp("%sx%s" % (self.app_width / divisor, self.app_height / divisor), "%s" % (self.grid_unit_px / divisor))
52−
53− dash = self.main_window.get_dash()
54− self.assertThat(dash.showScopeOnLoaded, Eventually(Equals(""), timeout=30))
55−
56− def test_show_hud(self):
57− hud = self.main_window.get_hud()
58− self.unlock_greeter()
59− self.show_hud()
60− self.assertThat(hud.shown, Eventually(Equals(True)))
61−
62− def test_show_hud_button_dont_open(self):
63− self.unlock_greeter()
64− self.open_first_dash_home_app()
65− hud_show_button = self.main_window.get_hud_show_button()
66− hud = self.main_window.get_hud()
67− window = self.main_window.get_qml_view()
68− start_x = int(window.x + window.width / 2)
69− start_y = window.y + window.height - 2
70− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
71− self.touch.press(start_x, start_y)
72− self.touch._finger_move(start_x, start_y - self.grid_size)
73− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
74− self.touch._finger_move(start_x, start_y - self.grid_size * 2)
75− self.touch._finger_move(start_x, start_y - self.grid_size * 3)
76− self.touch._finger_move(start_x, start_y - self.grid_size * 4)
77− self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
78− self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
79− self.touch._finger_move(start_x, start_y - self.grid_size * 34)
80− self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
81− self.assertThat(hud_show_button.mouseOver, Eventually(Equals(True)))
82− self.touch._finger_move(start_x, start_y - self.grid_size)
83− self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
84− self.assertThat(hud_show_button.mouseOver, Eventually(Equals(False)))
85− self.touch.release()
86− self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
87− self.assertThat(hud.shown, Eventually(Equals(False)))
88−
89− def test_hide_hud_click(self):
90− hud = self.main_window.get_hud()
91− self.unlock_greeter()
92− self.show_hud()
93− self.close_hud_click()
94− self.assertThat(hud.shown, Eventually(Equals(False)))
95−
96− def test_hide_hud_click_outside_handle(self):
97− hud = self.main_window.get_hud()
98− self.unlock_greeter()
99− self.show_hud()
100− rect = hud.globalRect
101− x = int(rect[0] + rect[2] / 2)
102− y = rect[1] + hud.handleHeight + 1
103− self.touch.tap(x, y)
104− self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
105−
106− def test_hide_hud_dragging(self):
107− hud = self.main_window.get_hud()
108− self.unlock_greeter()
109− self.show_hud()
110− rect = hud.globalRect
111− start_x = rect[0] + (rect[2] - rect[0]) / 2
112− start_y = rect[1] + 1
113− stop_x = start_x
114− stop_y = start_y + (rect[3] - rect[1]) / 2
115− self.touch.drag(start_x, start_y, stop_x, stop_y)
116− self.assertThat(hud.shown, Eventually(Equals(False)))
117−
118− def test_hide_hud_launcher(self):
119− hud = self.main_window.get_hud()
120− self.unlock_greeter()
121− self.show_hud()
122− self.show_launcher()
123− self.assertThat(hud.shown, Eventually(Equals(False)))