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 if os.getenv(
'GRID_UNIT_PX') ==
None:
162 self.
grid_size = int(os.getenv(
'GRID_UNIT_PX'))
164 self.
grid_size = int(self.grid_unit_px / scale_divisor)
167 def _geo_larger_than_display(self, width, height):
168 should_scale = getattr(self,
'scale_geo',
True)
170 screen = Display.create()
171 screen_width = screen.get_screen_width()
172 screen_height = screen.get_screen_height()
173 return (width > screen_width)
or (height > screen_height)
177 def _get_scaled_down_geo(self, width, height):
180 divisor = divisor * 2
185 Launch the unity shell, return a proxy object for it. 187 :param str mode: The type of greeter/shell mode to use 188 :param args: A list of aguments to pass to unity8 191 binary_path = get_binary_path()
192 lib_path = get_lib_path()
195 "Lib path is '%s', binary path is '%s'",
204 get_qml_import_path_with_mock()
210 unity8_cli_args_list = [
"--mode={}".format(mode)]
212 unity8_cli_args_list += args
222 logger.debug(
"Unity started, waiting for it to be ready.")
224 logger.debug(
"Unity loaded and ready.")
226 if model() ==
'Desktop':
229 process_helpers.stop_job(
'unity8-dash')
233 def _launch_unity_with_upstart(self, binary_path, args):
234 logger.info(
"Starting unity")
235 self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
236 global_=
True, QT_LOAD_TESTABILITY=1))
239 variables[
'ARGS'] =
" ".join(args)
241 binary_path, variables)
242 self.useFixture(launch_unity_fixture)
243 return launch_unity_fixture.unity_proxy
245 def _patch_data_dirs(self):
247 if data_dirs
is not None:
250 def patch_lightdm_mock(self):
251 logger.info(
"Setting up LightDM mock lib")
252 new_ld_library_path = [
253 get_default_extra_mock_libraries(),
256 if os.getenv(
'LD_LIBRARY_PATH')
is not None:
257 new_ld_library_path.append(os.getenv(
'LD_LIBRARY_PATH'))
259 new_ld_library_path =
':'.join(new_ld_library_path)
260 logger.info(
"New library path: %s", new_ld_library_path)
262 self.
_environment[
'LD_LIBRARY_PATH'] = new_ld_library_path
264 def _get_lightdm_mock_path(self):
265 lib_path = get_mocks_library_path()
266 lightdm_mock_path = os.path.abspath(
267 os.path.join(lib_path,
"liblightdm")
270 if not os.path.exists(lightdm_mock_path):
272 "LightDM mock does not exist at path '%s'." 273 % (lightdm_mock_path)
275 return lightdm_mock_path
277 def _set_proxy(self, proxy):
278 """Keep a copy of the proxy object, so we can use it to get common 279 parts of the shell later on. 285 def _clear_proxy(self):
288 def wait_for_unity(self):
289 greeter = self.main_window.wait_select_single(objectName=
'greeter')
290 greeter.waiting.wait_for(
False)
293 pid = process_helpers.get_job_pid(
'unity8-dash')
294 dash_proxy = introspection.get_proxy_object_for_existing_process(
296 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
298 dash_app = dash_helpers.DashApp(dash_proxy)
302 def main_window(self):
306 class DashBaseTestCase(AutopilotTestCase):
308 scenarios = ubuntu_scenarios.get_device_simulation_scenarios()
309 qml_mock_enabled =
True 315 if is_unity7_running():
316 self.useFixture(toolkit_fixtures.HideUnity7Launcher())
318 if model() !=
'Desktop':
320 self.addCleanup(process_helpers.stop_job,
'unity8')
321 process_helpers.restart_unity_with_testability()
322 process_helpers.unlock_unity()
324 self.ensure_dash_not_running()
326 if self.qml_mock_enabled:
327 self.environment[
'QML2_IMPORT_PATH'] = (
328 get_qml_import_path_with_mock()
331 if self.should_simulate_device():
334 self.simulate_device()
336 binary_path = get_binary_path(
'unity8-dash')
337 dash_proxy = self.launch_dash(binary_path, self.environment)
339 self.dash_app = dash_helpers.DashApp(dash_proxy)
340 self.dash = self.dash_app.dash
343 def ensure_dash_not_running(self):
344 if process_helpers.is_job_running(
'unity8-dash'):
345 process_helpers.stop_job(
'unity8-dash')
347 def launch_dash(self, binary_path, variables):
349 binary_path, variables)
350 self.useFixture(launch_dash_app_fixture)
351 return launch_dash_app_fixture.application_proxy
353 def wait_for_dash(self):
354 home_scope = self.dash.get_scope_by_index(0)
359 Eventually(Equals(
True), timeout=60)
361 self.assertThat(home_scope.isCurrent, Eventually(Equals(
True)))
363 def should_simulate_device(self):
364 return (hasattr(self,
'app_width')
and hasattr(self,
'app_height')
and 365 hasattr(self,
'grid_unit_px'))
367 def simulate_device(self):
368 simulate_device_fixture = self.useFixture(
369 toolkit_fixtures.SimulateDevice(
370 self.app_width, self.app_height, self.grid_unit_px))
371 self.environment[
'GRID_UNIT_PX'] = simulate_device_fixture.grid_unit_px
372 self.environment[
'ARGS'] =
'-windowgeometry {0}x{1}'\
373 .format(simulate_device_fixture.app_width,
374 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)