@@ -31,37 +31,67 @@ class Unity8TestCase(AutopilotTestCase):
3131
3232 """A sane test case base class for the Unity8 shell tests."""
3333
34+ # The lightdm mock we want to load. Options seem to be "full", "single-pin",
35+ # "single-passphrase" or "single-key".
36+ lightdm_mock = "full"
37+
3438 def setUp(self):
3539 super(Unity8TestCase, self).setUp()
3640 self._proxy = None
3741
3842 def launch_unity(self):
3943 """Launch the unity8 shell, return a proxy object for it."""
40− shell_binary_path = self._get_shell_binary_path()
44+ # first, work out which binary to launch:
45+ binary_path = os.path.abspath(
46+ os.path.join(
47+ os.path.dirname(__file__),
48+ "../../../../../builddir/unity8"
49+ )
50+ )
51+ if os.path.exists(binary_path):
52+ lib_path = os.path.dirname(binary_path)
53+ else:
54+ try:
55+ binary_path = subprocess.check_output(['which', 'unity8']).strip()
56+ lib_path = os.path.join(
57+ "/usr/lib/",
58+ sysconfig.get_config_var('MULTIARCH'),
59+ "unity8"
60+ )
61+ except subprocess.CalledProcessError as e:
62+ self.fail("Unable to locate unity8 binary: %r" % e)
63+
64+ # we now have a path to the unity8 binary, and lib_path points to the
65+ # directory where we need to patch some environment variables.
66+
67+ # do the environment variable patching:
68+ self._patch_environment(lib_path)
69+
70+ # launch the shell:
4171 app_proxy = self.launch_test_application(
42− shell_binary_path,
72+ binary_path,
4373 "-fullscreen",
4474 app_type='qt'
4575 )
4676 logger.debug("Started unity8 shell, backend is: %r", app_proxy._Backend)
4777 self._set_proxy(app_proxy)
4878
49− # this line ensures that the dash is visible before we return.
79+ # Ensure that the dash is visible before we return:
5080 logger.info("Waiting for the dash to load...")
5181 self.assertThat(self.get_dash().showScopeOnLoaded, Eventually(Equals("")))
5282 logger.info("dash loaded!")
5383 return app_proxy
5484
55− def _set_proxy(self, proxy):
56− """Keep a copy of the proxy object, so we can use it to get common parts
57− of the shell later on.
85+ def _patch_environment(self, lib_path):
86+ """Patch environment variables for launching the unity8 shell."""
87+ ld_lib_path_patches = (
88+ os.path.join(lib_path, "qml/mocks/libusermetrics"),
89+ os.path.join(lib_path, "qml/mocks/LightDM/" + self.lightdm_mock),
90+ )
5891
59− """
60− self._proxy = proxy
61− self.addCleanup(self._clear_proxy)
92+ self.patch_environment("LD_LIBRARY_PATH", ":".join(ld_lib_path_patches))
93+ self.patch_environment("QML2_IMPORT_PATH", os.path.join(lib_path, "qml/mocks"))
6294
63− def _clear_proxy(self):
64− self._proxy = None
6595
6696 def _get_shell_binary_path(self):
6797 """Return a path to the unity8 binary, either the locally built binary
@@ -71,18 +101,18 @@ class Unity8TestCase(AutopilotTestCase):
71101
72102 """
73103
74− local_path = os.path.abspath(
75− os.path.join(
76− os.path.dirname(__file__),
77− "../../../../../builddir/unity8"
78− )
79− )
80− if os.path.exists(local_path):
81− return local_path
82− try:
83− return subprocess.check_output(['which', 'unity8']).strip()
84− except subprocess.CalledProcessError as e:
85− self.fail("Unable to locate unity8 binary: %r" % e)
104+
105+
106+ def _set_proxy(self, proxy):
107+ """Keep a copy of the proxy object, so we can use it to get common parts
108+ of the shell later on.
109+
110+ """
111+ self._proxy = proxy
112+ self.addCleanup(self._clear_proxy)
113+
114+ def _clear_proxy(self):
115+ self._proxy = None
86116
87117 def get_dash(self):
88118 dash = self._proxy.select_single("Dash")