on xenial help sign in
Added scenarios for hud tests, further cleanup.
commit1a74d99d2d1ff6c47cae42a14b8f35445788c107 authorChristopher Lee <chris.lee@canonical.com> dateWed 17 Jul 2013, 17:19 (13 years ago) parente226799
6 files changed+43−141
tests/autopilot/unity8/__init__.py+7−2 tests/autopilot/unity8/shell/__init__.py+26−13 tests/autopilot/unity8/shell/emulators/main_window.py+1−1 tests/autopilot/unity8/shell/tests/__init__.py+3−2 tests/autopilot/unity8/shell/tests/test_hud.py+6 tests/autopilot/unity8/shell/tests/testhud.py−123
tests/autopilot/unity8/__init__.py+7−2
@@ -11,16 +11,21 @@ import subprocess
1111import sysconfig
1212
1313
14+def running_installed_tests():
15+ binary_path = get_unity8_binary_path()
16+ return binary_path.startswith('/usr')
17+
18+
1419def get_lib_path():
1520 """Return the library path to use in this test run."""
16− binary_path = get_unity8_binary_path()
17− if binary_path.startswith("/usr"):
21+ if running_installed_tests():
1822 lib_path = os.path.join(
1923 "/usr/lib/",
2024 sysconfig.get_config_var('MULTIARCH'),
2125 "unity8"
2226 )
2327 else:
28+ binary_path = get_unity8_binary_path()
2429 lib_path = os.path.dirname(binary_path)
2530 return lib_path
2631
tests/autopilot/unity8/shell/__init__.py+26−13
@@ -10,7 +10,7 @@
1010from functools import wraps
1111import os.path
1212
13−from unity8 import get_lib_path
13+from unity8 import get_lib_path, running_installed_tests
1414
1515import logging
1616
@@ -23,19 +23,32 @@ def with_lightdm_mock(mock_type):
2323 @wraps(fn)
2424 def wrapper(*args, **kwargs):
2525 logger.info("Setting up LightDM mock type '%s'", mock_type)
26− lib_path = get_lib_path()
27− new_ld_library_path = os.path.join(
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−
26+ new_ld_library_path = _get_ld_library_path(mock_type)
3727 logger.info("New library path: %s", new_ld_library_path)
38− args[0].patch_environment('LD_LIBRARY_PATH', new_ld_library_path)
28+ tests_self = args[0]
29+ tests_self.patch_environment('LD_LIBRARY_PATH', new_ld_library_path)
3930 return fn(*args, **kwargs)
4031 return wrapper
4132 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):
4444 return self.app.select_single("HudButton")
4545
4646 def get_dash(self):
47− return self.app.select_single("Dash")
47+ return self.app.select_single(Dash)
4848
4949 def get_dash_home_applications_grid(self):
5050 return self.app.select_single("ApplicationsFilterGrid", objectName="dashHomeApplicationsGrid")
tests/autopilot/unity8/shell/tests/__init__.py+3−2
@@ -20,6 +20,7 @@ import sysconfig
2020from unity8 import get_lib_path, get_unity8_binary_path
2121from unity8.shell.emulators.main_window import MainWindow
2222from unity8.shell.emulators import Unity8EmulatorBase
23+from unity8.shell.emulators.dash import Dash
2324
2425
2526logger = logging.getLogger(__name__)
@@ -73,7 +74,7 @@ class Unity8TestCase(AutopilotTestCase):
7374 def _setup_grid_size(self, scale_divisor):
7475 """Use the grid size that may be supplied or use the default."""
7576 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'))
7778 else:
7879 self.grid_size = int(self.grid_unit_px / scale_divisor)
7980 self.patch_environment("GRID_UNIT_PX", str(self.grid_size))
@@ -145,7 +146,7 @@ class Unity8TestCase(AutopilotTestCase):
145146 self._proxy = None
146147
147148 def get_dash(self):
148− dash = self._proxy.select_single("Dash")
149+ dash = self._proxy.select_single(Dash)
149150 self.assertThat(dash, NotEquals(None))
150151 return dash
151152
tests/autopilot/unity8/shell/tests/test_hud.py+6
@@ -9,6 +9,7 @@ from __future__ import absolute_import
99
1010from collections import namedtuple
1111
12+from unity8.shell import with_lightdm_mock
1213from unity8.shell.tests import Unity8TestCase, _get_device_emulation_scenarios
1314
1415from autopilot.display import Display
@@ -27,6 +28,7 @@ class TestHud(Unity8TestCase):
2728
2829 scenarios = _get_device_emulation_scenarios()
2930
31+ @with_lightdm_mock("single")
3032 def test_show_hud_button_appears(self):
3133 """Swiping up while an app is active must show the 'show hud' button."""
3234 self.launch_unity()
@@ -43,6 +45,7 @@ class TestHud(Unity8TestCase):
4345 self.touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
4446 self.assertThat(hud_show_button.opacity, Eventually(Equals(1.0)))
4547
48+ @with_lightdm_mock("single")
4649 def test_show_hud_appears(self):
4750 """Releasing the touch on the 'show hud' button must display the hud."""
4851 self.launch_unity()
@@ -96,6 +99,7 @@ class TestHud(Unity8TestCase):
9699 # self.assertThat(hud_show_button.opacity, Eventually(Equals(0)))
97100 # self.assertThat(hud.shown, Eventually(Equals(False)))
98101
102+ @with_lightdm_mock("single")
99103 def test_hide_hud_click(self):
100104 """Tapping the close button of the Hud must dismiss it."""
101105 self.launch_unity()
@@ -119,6 +123,7 @@ class TestHud(Unity8TestCase):
119123 # self.touch.tap(x, y)
120124 # self.assertRaises(MismatchError, lambda: self.assertThat(hud.shown, Eventually(Equals(False), timeout=3)))
121125
126+ @with_lightdm_mock("single")
122127 def test_hide_hud_dragging(self):
123128 """Once open the Hud must close if the upper bar is dragged and released
124129 downward.
@@ -139,6 +144,7 @@ class TestHud(Unity8TestCase):
139144 self.touch.drag(start_x, start_y, end_x, end_y)
140145 self.assertThat(hud.shown, Eventually(Equals(False)))
141146
147+ @with_lightdm_mock("single")
142148 def test_launcher_hides_hud(self):
143149 """Opening the Launcher while the Hud is active must close the Hud."""
144150 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)))