20 """unity autopilot tests."""
23 from gi.repository
import Gio
30 from autopilot
import introspection
31 from autopilot.platform
import model
32 from autopilot.testcase
import AutopilotTestCase
33 from autopilot.matchers
import Eventually
34 from autopilot.display
import Display
35 from testtools.matchers
import Equals
37 import ubuntuuitoolkit
38 from ubuntuuitoolkit
import (
39 fixture_setup
as toolkit_fixtures,
46 get_mocks_library_path,
47 get_default_extra_mock_libraries,
60 logger = logging.getLogger(__name__)
62 UNITYSHELL_GSETTINGS_SCHEMA =
"org.compiz.unityshell"
63 UNITYSHELL_GSETTINGS_PATH =
"/org/compiz/profiles/unity/plugins/unityshell/"
64 UNITYSHELL_LAUNCHER_KEY =
"launcher-hide-mode"
65 UNITYSHELL_LAUNCHER_MODE = 1
68 def is_unity7_running():
69 """Return True if Unity7 is running. Otherwise, return False."""
72 UNITYSHELL_GSETTINGS_SCHEMA
in
73 Gio.Settings.list_relocatable_schemas()
77 def get_qml_import_path_with_mock():
78 """Return the QML2_IMPORT_PATH value with the mock path prepended."""
79 qml_import_path = [get_mocks_library_path()]
80 if os.getenv(
'QML2_IMPORT_PATH')
is not None:
81 qml_import_path.append(os.getenv(
'QML2_IMPORT_PATH'))
83 qml_import_path =
':'.join(qml_import_path)
84 logger.info(
"New QML2 import path: %s", qml_import_path)
85 return qml_import_path
90 """A test case base class for the Unity shell tests."""
95 is_unity_running = process_helpers.is_job_running(
'unity8')
96 except process_helpers.JobError
as e:
97 xdg_config_home = os.getenv(
98 'XDG_CONFIG_HOME', os.path.join(os.getenv(
'HOME'),
'.config'))
99 upstart_config_path = os.path.join(xdg_config_home,
'upstart')
101 '`initctl status unity8` failed, most probably the '
102 'unity8 session could not be found:\n\n'
104 'Please install unity8 or copy data/unity8.conf to '
105 '{1}\n'.format(e.output, upstart_config_path)
109 assert not is_unity_running, (
110 'Unity is currently running, these tests require it to be '
112 'Please run this command before running these tests: \n'
113 'initctl stop unity8\n')
117 if is_unity7_running():
118 self.useFixture(toolkit_fixtures.HideUnity7Launcher())
127 def _setup_display_details(self):
131 def _determine_geometry(self):
132 """Use the geometry that may be supplied or use the default."""
133 width = getattr(self,
'app_width', 0)
134 height = getattr(self,
'app_height', 0)
137 if width > 0
and height > 0:
140 width = width / scale_divisor
141 height = height / scale_divisor
143 "Geometry larger than display, scaled down to: %dx%d",
147 geo_string =
"%dx%d" % (width, height)
156 def _setup_grid_size(self, scale_divisor):
157 """Use the grid size that may be supplied or use the default."""
158 if getattr(self,
'grid_unit_px', 0) == 0:
159 self.
grid_size = int(os.getenv(
'GRID_UNIT_PX'))
161 self.
grid_size = int(self.grid_unit_px / scale_divisor)
164 def _geo_larger_than_display(self, width, height):
165 should_scale = getattr(self,
'scale_geo',
True)
167 screen = Display.create()
168 screen_width = screen.get_screen_width()
169 screen_height = screen.get_screen_height()
170 return (width > screen_width)
or (height > screen_height)
174 def _get_scaled_down_geo(self, width, height):
177 divisor = divisor * 2
182 Launch the unity shell, return a proxy object for it.
184 :param str mode: The type of greeter/shell mode to use
185 :param args: A list of aguments to pass to unity8
188 binary_path = get_binary_path()
189 lib_path = get_lib_path()
192 "Lib path is '%s', binary path is '%s'",
201 get_qml_import_path_with_mock()
207 unity8_cli_args_list = [
"--mode={}".format(mode)]
209 unity8_cli_args_list += args
219 logger.debug(
"Unity started, waiting for it to be ready.")
221 logger.debug(
"Unity loaded and ready.")
223 if model() ==
'Desktop':
226 process_helpers.stop_job(
'unity8-dash')
230 def _launch_unity_with_upstart(self, binary_path, args):
231 logger.info(
"Starting unity")
232 self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
233 global_=
True, QT_LOAD_TESTABILITY=1))
236 variables[
'ARGS'] =
" ".join(args)
238 binary_path, variables)
239 self.useFixture(launch_unity_fixture)
240 return launch_unity_fixture.unity_proxy
242 def _patch_data_dirs(self):
244 if data_dirs
is not None:
247 def patch_lightdm_mock(self):
248 logger.info(
"Setting up LightDM mock lib")
249 new_ld_library_path = [
250 get_default_extra_mock_libraries(),
253 if os.getenv(
'LD_LIBRARY_PATH')
is not None:
254 new_ld_library_path.append(os.getenv(
'LD_LIBRARY_PATH'))
256 new_ld_library_path =
':'.join(new_ld_library_path)
257 logger.info(
"New library path: %s", new_ld_library_path)
259 self.
_environment[
'LD_LIBRARY_PATH'] = new_ld_library_path
261 def _get_lightdm_mock_path(self):
262 lib_path = get_mocks_library_path()
263 lightdm_mock_path = os.path.abspath(
264 os.path.join(lib_path,
"IntegratedLightDM",
"liblightdm")
267 if not os.path.exists(lightdm_mock_path):
269 "LightDM mock does not exist at path '%s'."
270 % (lightdm_mock_path)
272 return lightdm_mock_path
274 def _set_proxy(self, proxy):
275 """Keep a copy of the proxy object, so we can use it to get common
276 parts of the shell later on.
282 def _clear_proxy(self):
285 def wait_for_unity(self):
286 greeter = self.main_window.wait_select_single(objectName=
'greeter')
287 greeter.waiting.wait_for(
False)
290 pid = process_helpers.get_job_pid(
'unity8-dash')
291 dash_proxy = introspection.get_proxy_object_for_existing_process(
293 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
295 dash_app = dash_helpers.DashApp(dash_proxy)
299 def main_window(self):
303 class DashBaseTestCase(AutopilotTestCase):
305 scenarios = ubuntu_scenarios.get_device_simulation_scenarios()
306 qml_mock_enabled =
True
312 if is_unity7_running():
313 self.useFixture(toolkit_fixtures.HideUnity7Launcher())
315 if model() !=
'Desktop':
317 self.addCleanup(process_helpers.stop_job,
'unity8')
318 process_helpers.restart_unity_with_testability()
319 process_helpers.unlock_unity()
321 self.ensure_dash_not_running()
323 if self.qml_mock_enabled:
324 self.environment[
'QML2_IMPORT_PATH'] = (
325 get_qml_import_path_with_mock()
328 if self.should_simulate_device():
331 self.simulate_device()
333 binary_path = get_binary_path(
'unity8-dash')
334 dash_proxy = self.launch_dash(binary_path, self.environment)
336 self.dash_app = dash_helpers.DashApp(dash_proxy)
337 self.dash = self.dash_app.dash
340 def ensure_dash_not_running(self):
341 if process_helpers.is_job_running(
'unity8-dash'):
342 process_helpers.stop_job(
'unity8-dash')
344 def launch_dash(self, binary_path, variables):
346 binary_path, variables)
347 self.useFixture(launch_dash_app_fixture)
348 return launch_dash_app_fixture.application_proxy
350 def wait_for_dash(self):
351 home_scope = self.dash.get_scope_by_index(0)
356 Eventually(Equals(
True), timeout=60)
358 self.assertThat(home_scope.isCurrent, Eventually(Equals(
True)))
360 def should_simulate_device(self):
361 return (hasattr(self,
'app_width')
and hasattr(self,
'app_height')
and
362 hasattr(self,
'grid_unit_px'))
364 def simulate_device(self):
365 simulate_device_fixture = self.useFixture(
366 toolkit_fixtures.SimulateDevice(
367 self.app_width, self.app_height, self.grid_unit_px))
368 self.environment[
'GRID_UNIT_PX'] = simulate_device_fixture.grid_unit_px
369 self.environment[
'ARGS'] =
'-windowgeometry {0}x{1}'\
370 .format(simulate_device_fixture.app_width,
371 simulate_device_fixture.app_height)
def launch_unity(self, mode="full-greeter", args)
def _patch_data_dirs(self)
def _set_proxy(self, proxy)
def _geo_larger_than_display(self, width, height)
def patch_lightdm_mock(self)
def _setup_grid_size(self, scale_divisor)
def _get_lightdm_mock_path(self)
def _setup_display_details(self)
def _determine_geometry(self)
def _launch_unity_with_upstart(self, binary_path, args)
def _get_scaled_down_geo(self, width, height)