20"""lomiri autopilot tests."""
23 from gi.repository
import Gio
30from autopilot
import introspection
31from autopilot.platform
import model
32from autopilot.testcase
import AutopilotTestCase
33from autopilot.matchers
import Eventually
34from autopilot.display
import Display
35from testtools.matchers
import Equals
38from lomiriuitoolkit
import (
39 fixture_setup
as toolkit_fixtures,
46 get_mocks_library_path,
47 get_default_extra_mock_libraries,
60logger = logging.getLogger(__name__)
62LOMIRISHELL_GSETTINGS_SCHEMA =
"org.compiz.lomirishell"
63LOMIRISHELL_GSETTINGS_PATH =
"/org/compiz/profiles/lomiri/plugins/lomirishell/"
64LOMIRISHELL_LAUNCHER_KEY =
"launcher-hide-mode"
65LOMIRISHELL_LAUNCHER_MODE = 1
69 """Return True if Lomiri7 is running. Otherwise, return False."""
72 LOMIRISHELL_GSETTINGS_SCHEMA
in
73 Gio.Settings.list_relocatable_schemas()
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 Lomiri shell tests."""
95 is_lomiri_running = process_helpers.is_job_running(
'lomiri')
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 lomiri` failed, most probably the '
102 'lomiri session could not be found:\n\n'
104 'Please install lomiri or copy data/lomiri.conf to '
105 '{1}\n'.format(e.output, upstart_config_path)
109 assert not is_lomiri_running, (
110 'Lomiri is currently running, these tests require it to be '
112 'Please run this command before running these tests: \n'
113 'initctl stop lomiri\n')
118 self.useFixture(toolkit_fixtures.HideLomiri7Launcher())
127 def _setup_display_details(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)
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 lomiri 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 lomiri
191 binary_path = get_binary_path()
192 lib_path = get_lib_path()
195 "Lib path is '%s', binary path is '%s'",
210 lomiri_cli_args_list = [
"--mode={}".format(mode)]
212 lomiri_cli_args_list += args
222 logger.debug(
"Lomiri started, waiting for it to be ready.")
224 logger.debug(
"Lomiri loaded and ready.")
226 if model() ==
'Desktop':
229 process_helpers.stop_job(
'lomiri-dash')
233 def _launch_lomiri_with_upstart(self, binary_path, args):
234 logger.info(
"Starting lomiri")
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_lomiri_fixture)
243 return launch_lomiri_fixture.lomiri_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
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_lomiri(self):
289 greeter = self.
main_window.wait_select_single(objectName=
'greeter')
290 greeter.waiting.wait_for(
False)
293 pid = process_helpers.get_job_pid(
'lomiri-dash')
294 dash_proxy = introspection.get_proxy_object_for_existing_process(
296 emulator_base=lomiriuitoolkit.LomiriUIToolkitCustomProxyObjectBase
298 dash_app = dash_helpers.DashApp(dash_proxy)
302 def main_window(self):
306class DashBaseTestCase(AutopilotTestCase):
308 scenarios = lomiri_scenarios.get_device_simulation_scenarios()
309 qml_mock_enabled =
True
316 self.useFixture(toolkit_fixtures.HideLomiri7Launcher())
318 if model() !=
'Desktop':
320 self.addCleanup(process_helpers.stop_job,
'lomiri')
321 process_helpers.restart_lomiri_with_testability()
322 process_helpers.unlock_lomiri()
324 self.ensure_dash_not_running()
326 if self.qml_mock_enabled:
327 self.environment[
'QML2_IMPORT_PATH'] = (
331 if self.should_simulate_device():
334 self.simulate_device()
336 binary_path = get_binary_path(
'lomiri-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(
'lomiri-dash'):
345 process_helpers.stop_job(
'lomiri-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)
_setup_grid_size(self, scale_divisor)
_get_lightdm_mock_path(self)
launch_lomiri(self, mode="full-greeter", *args)
_get_scaled_down_geo(self, width, height)
_launch_lomiri_with_upstart(self, binary_path, args)
_determine_geometry(self)
_geo_larger_than_display(self, width, height)
_setup_display_details(self)
get_qml_import_path_with_mock()