on xenial help sign in
First lock screen test finished.
commit4bd2c55f31d0251ef85a24b7e63b8334b43cb926 authorThomi Richards <thomi.richards@canonical.com> dateMon 15 Jul 2013, 12:08 (13 years ago) parent4c48c29
4 files changed+132−40
tests/autopilot/unity8/__init__.py+33 tests/autopilot/unity8/shell/tests/__init__.py+20−28 tests/autopilot/unity8/shell/tests/helpers.py+21−6 tests/autopilot/unity8/shell/tests/test_lock_screen.py+58−6
tests/autopilot/unity8/__init__.py+33
@@ -6,3 +6,36 @@
66# by the Free Software Foundation.
77
88"""unity8 autopilot tests and emulators - top level package."""
9+import os.path
10+import subprocess
11+import sysconfig
12+
13+
14+def get_lib_path():
15+ """Return the library path to use in this test run."""
16+ binary_path = get_unity8_binary_path()
17+ if binary_path.startswith("/usr"):
18+ lib_path = os.path.join(
19+ "/usr/lib/",
20+ sysconfig.get_config_var('MULTIARCH'),
21+ "unity8"
22+ )
23+ else:
24+ lib_path = os.path.dirname(binary_path)
25+ return lib_path
26+
27+
28+def get_unity8_binary_path():
29+ """Return the path to the unity8 binary."""
30+ binary_path = os.path.abspath(
31+ os.path.join(
32+ os.path.dirname(__file__),
33+ "../../../../../builddir/unity8"
34+ )
35+ )
36+ if not os.path.exists(binary_path):
37+ try:
38+ binary_path = subprocess.check_output(['which', 'unity8']).strip()
39+ except subprocess.CalledProcessError as e:
40+ raise RuntimeError("Unable to locate unity8 binary: %r" % e)
41+ return binary_path
tests/autopilot/unity8/shell/tests/__init__.py+20−28
@@ -10,13 +10,13 @@
1010from autopilot.platform import model
1111from autopilot.testcase import AutopilotTestCase
1212from autopilot.matchers import Eventually
13−import subprocess
1413from testtools.matchers import Equals, NotEquals
14+from autopilot.input import Touch
1515import logging
1616import os.path
1717import sysconfig
1818
19−
19+from unity8 import get_lib_path, get_unity8_binary_path
2020from unity8.shell.emulators.main_window import MainWindow
2121
2222
@@ -34,31 +34,18 @@ class Unity8TestCase(AutopilotTestCase):
3434 def setUp(self):
3535 super(Unity8TestCase, self).setUp()
3636 self._proxy = None
37− # The lightdm mock we want to load. Options seem to be "full", "single-pin",
38− # "single-passphrase" or "single-key".
39− self.lightdm_mock = "full"
37+ self.touch = Touch.create()
4038
4139 def launch_unity(self):
4240 """Launch the unity8 shell, return a proxy object for it."""
4341 # first, work out which binary to launch:
44− binary_path = os.path.abspath(
45− os.path.join(
46− os.path.dirname(__file__),
47− "../../../../../builddir/unity8"
48− )
49− )
50− if os.path.exists(binary_path):
51− lib_path = os.path.dirname(binary_path)
52− else:
53− try:
54− binary_path = subprocess.check_output(['which', 'unity8']).strip()
55− lib_path = os.path.join(
56− "/usr/lib/",
57− sysconfig.get_config_var('MULTIARCH'),
58− "unity8"
59− )
60− except subprocess.CalledProcessError as e:
61− self.fail("Unable to locate unity8 binary: %r" % e)
42+ binary_path = get_unity8_binary_path()
43+ lib_path = get_lib_path()
44+
45+ logger.info("Lib path is '%s', binary path is '%s'",
46+ lib_path,
47+ binary_path
48+ )
6249
6350 # we now have a path to the unity8 binary, and lib_path points to the
6451 # directory where we need to patch some environment variables.
@@ -83,12 +70,12 @@ class Unity8TestCase(AutopilotTestCase):
8370
8471 def _patch_environment(self, lib_path):
8572 """Patch environment variables for launching the unity8 shell."""
86− ld_lib_path_patches = (
87− os.path.join(lib_path, "qml/mocks/libusermetrics"),
88− os.path.join(lib_path, "qml/mocks/LightDM/" + self.lightdm_mock),
89− )
73+ # ld_lib_path_patches = (
74+ # os.path.join(lib_path, "qml/mocks/libusermetrics"),
75+ # os.path.join(lib_path, "qml/mocks/LightDM/" + self.lightdm_mock),
76+ # )
9077
91− self.patch_environment("LD_LIBRARY_PATH", ":".join(ld_lib_path_patches))
78+ # self.patch_environment("LD_LIBRARY_PATH", ":".join(ld_lib_path_patches))
9279 self.patch_environment("QML2_IMPORT_PATH", os.path.join(lib_path, "qml/mocks"))
9380
9481
@@ -118,6 +105,11 @@ class Unity8TestCase(AutopilotTestCase):
118105 self.assertThat(dash, NotEquals(None))
119106 return dash
120107
108+ @property
109+ def main_window(self):
110+ return MainWindow(self._proxy)
111+
112+
121113
122114class ShellTestCase(AutopilotTestCase):
123115
tests/autopilot/unity8/shell/tests/helpers.py+21−6
@@ -8,19 +8,34 @@
88from autopilot.matchers import Eventually
99from testtools.matchers import Equals, NotEquals
1010from functools import wraps
11+import os.path
12+
13+from unity8 import get_lib_path
14+
1115
1216import logging
1317
1418logger = logging.getLogger(__name__)
1519
1620
17−def with_lightdm_mock(fn, mock_type):
21+def with_lightdm_mock(mock_type):
1822 """A simple decorator that sets up the LightDM mock for a single test."""
19− @wraps(fn)
20− def wrapper(*args, **kwargs):
21− logger.info("Setting up LightDM mock type '%s'", mock_type)
22− return fn(*args, **kwargs)
23− return wrapper
23+ def with_lightdm_mock_internal(fn):
24+ @wraps(fn)
25+ def wrapper(*args, **kwargs):
26+ logger.info("Setting up LightDM mock type '%s'", mock_type)
27+ lib_path = get_lib_path()
28+ new_ld_library_path = os.path.join(
29+ lib_path,
30+ "qml/mocks/LightDM/",
31+ mock_type
32+ )
33+
34+ logger.info("New library path: %s", new_ld_library_path)
35+ args[0].patch_environment('LD_LIBRARY_PATH', new_ld_library_path)
36+ return fn(*args, **kwargs)
37+ return wrapper
38+ return with_lightdm_mock_internal
2439
2540
2641# TODO: Mixing classes like these are ikky. Remove them, and replace with
tests/autopilot/unity8/shell/tests/test_lock_screen.py+58−6
@@ -28,11 +28,13 @@ from __future__ import absolute_import
2828from unity8.shell.tests import Unity8TestCase
2929from unity8.shell.tests.helpers import with_lightdm_mock
3030
31−from autopilot.input import Mouse, Touch, Pointer
32−from testtools.matchers import Equals, NotEquals, GreaterThan, MismatchError
31+from autopilot.matchers import Eventually
32+from testtools.matchers import Equals
33+import logging
34+import time
3335
3436
35−import time
37+logger = logging.getLogger(__name__)
3638
3739
3840class TestLockscreen(Unity8TestCase):
@@ -59,10 +61,60 @@ class TestLockscreen(Unity8TestCase):
5961
6062 @with_lightdm_mock("single-pin")
6163 def test_can_unlock_screen(self):
62− """Must be able to unlock the screen."""
63− self.lightdm_mock = "single_pin"
64+ """Must be able to unlock the PIN entry lock screen."""
6465 self.app = self.launch_unity()
65− time.sleep(30)
66+ self._unlock_greeter()
67+
68+ lockscreen = self._wait_for_lockscreen()
69+ self._enter_pincode("1234")
70+
71+ self.assertThat(lockscreen.shown, Eventually(Equals(False)))
72+
73+ def _unlock_greeter(self):
74+ greeter = self.main_window.get_greeter()
75+ self.assertThat(greeter.created, Eventually(Equals(True)))
76+
77+ if greeter.multiUser:
78+ password_field = self.select_greeter_user("No Password")
79+ self.assertThat(password_field.opacity, Eventually(Equals(1)))
80+ self.touch.tap_object(password_field)
81+
82+ else:
83+ rect = greeter.globalRect
84+ start_x = rect[0] + rect[2] - 3
85+ start_y = int(rect[1] + rect[3] / 2)
86+ stop_x = int(rect[0] + rect[2] * 0.2)
87+ stop_y = start_y
88+ self.touch.drag(start_x, start_y, stop_x, stop_y)
89+
90+ self.assertThat(greeter.created, Eventually(Equals(False)))
91+
92+ def _wait_for_lockscreen(self):
93+ """Wait for the lock screen to load, and return it."""
94+ pinPadLoader = self.main_window.get_pinPadLoader();
95+ self.assertThat(pinPadLoader.progress, Eventually(Equals(1)))
96+ lockscreen = self.main_window.get_lockscreen();
97+ self.assertThat(lockscreen.shown, Eventually(Equals(True)))
98+ return lockscreen
99+
100+ def _enter_pincode(self, code):
101+ """Enter code 'code' into the single-pin lightdm pincode entry
102+ screen.
103+
104+ :param code: must be a string of numeric characters.
105+ :raises: TypeError if code is not a string.
106+ :raises: ValueError if code contains non-numeric characters.
107+
108+ """
109+
110+ if not isinstance(code, basestring):
111+ raise TypeError("'code' parameter must be a string.")
112+ for num in code:
113+ if not num.isdigit():
114+ raise ValueError(
115+ "'code' parameter contains non-numeric characters."
116+ )
117+ self.touch.tap_object(self.main_window.get_pinPadButton(int(num)))
66118
67119 # def test_unlock(self):
68120 # self.unlock_greeter()