@@ -34,6 +34,7 @@ import os.path
34import subprocess
34import subprocess
36from testtools.matchers import Equals
36from testtools.matchers import Equals
37+from ubuntuuitoolkit import fixture_setup as toolkit_fixtures
38from unity8 import (
39from unity8 import (
39 get_lib_path,
40 get_lib_path,
@@ -42,9 +43,14 @@ from unity8 import (
42 get_default_extra_mock_libraries,
43 get_default_extra_mock_libraries,
43 get_data_dirs
44 get_data_dirs
45−from unity8.process_helpers import restart_unity_with_testability
46+from unity8 import (
50+from unity8.shell.emulators import (
51+ dash as dash_helpers,
46−from unity8.shell.emulators import main_window as main_window_emulator
52+ main_window as main_window_emulator,
47−from unity8.shell.emulators.dash import Dash
53+)
50logger = logging.getLogger(__name__)
56logger = logging.getLogger(__name__)
@@ -78,6 +84,26 @@ def _get_device_emulation_scenarios(devices='All'):
78 return [native]
84 return [native]
87+def is_unity7_running():
88+ """Return True if Unity7 is running. Otherwise, return False."""
91+ UNITYSHELL_GSETTINGS_SCHEMA in
92+ Gio.Settings.list_relocatable_schemas()
96+def get_qml_import_path_with_mock():
97+ """Return the QML2_IMPORT_PATH value with the mock path preppended."""
98+ qml_import_path = [get_mocks_library_path()]
99+ if os.getenv('QML2_IMPORT_PATH') is not None:
100+ qml_import_path.append(os.getenv('QML2_IMPORT_PATH'))
102+ qml_import_path = ':'.join(qml_import_path)
103+ logger.info("New QML2 import path: %s", qml_import_path)
104+ return qml_import_path
81class UnityTestCase(AutopilotTestCase):
107class UnityTestCase(AutopilotTestCase):
83 """A test case base class for the Unity shell tests."""
109 """A test case base class for the Unity shell tests."""
@@ -118,23 +144,8 @@ class UnityTestCase(AutopilotTestCase):
119 def setUp(self):
145 def setUp(self):
120 super(UnityTestCase, self).setUp()
146 super(UnityTestCase, self).setUp()
121− if (Gio is not None and
147+ if is_unity7_running():
122− UNITYSHELL_GSETTINGS_SCHEMA in
148+ self.useFixture(toolkit_fixtures.HideUnity7Launcher())
123− Gio.Settings.list_relocatable_schemas()):
125− # Hide Unity launcher
126− self._unityshell_schema = Gio.Settings.new_with_path(
127− UNITYSHELL_GSETTINGS_SCHEMA,
128− UNITYSHELL_GSETTINGS_PATH,
130− self._launcher_hide_mode = self._unityshell_schema.get_int(
131− UNITYSHELL_LAUNCHER_KEY,
133− self._unityshell_schema.set_int(
134− UNITYSHELL_LAUNCHER_KEY,
135− UNITYSHELL_LAUNCHER_MODE,
137− self.addCleanup(self._reset_launcher)
139 self._proxy = None
150 self._proxy = None
140 self._lightdm_mock_type = None
151 self._lightdm_mock_type = None
@@ -263,7 +274,9 @@ class UnityTestCase(AutopilotTestCase):
263 self.patch_lightdm_mock()
274 self.patch_lightdm_mock()
265 if self._qml_mock_enabled:
276 if self._qml_mock_enabled:
266− self._setup_extra_mock_environment_patch()
277+ self._environment['QML2_IMPORT_PATH'] = (
278+ get_qml_import_path_with_mock()
268 if self._data_dirs_mock_enabled:
281 if self._data_dirs_mock_enabled:
269 self._patch_data_dirs()
282 self._patch_data_dirs()
@@ -308,7 +321,7 @@ class UnityTestCase(AutopilotTestCase):
309 self.addCleanup(self._cleanup_launching_upstart_unity)
322 self.addCleanup(self._cleanup_launching_upstart_unity)
311− return restart_unity_with_testability(*all_args)
324+ return process_helpers.restart_unity_with_testability(*all_args)
313 def _cleanup_launching_upstart_unity(self):
326 def _cleanup_launching_upstart_unity(self):
314 logger.info("Stopping unity")
327 logger.info("Stopping unity")
@@ -353,15 +366,6 @@ class UnityTestCase(AutopilotTestCase):
354 return lightdm_mock_path
367 return lightdm_mock_path
356− def _setup_extra_mock_environment_patch(self):
357− qml_import_path = [get_mocks_library_path()]
358− if os.getenv('QML2_IMPORT_PATH') is not None:
359− qml_import_path.append(os.getenv('QML2_IMPORT_PATH'))
361− qml_import_path = ':'.join(qml_import_path)
362− logger.info("New QML2 import path: %s", qml_import_path)
363− self._environment['QML2_IMPORT_PATH'] = qml_import_path
365 def _set_proxy(self, proxy):
369 def _set_proxy(self, proxy):
366 """Keep a copy of the proxy object, so we can use it to get common
370 """Keep a copy of the proxy object, so we can use it to get common
367 parts of the shell later on.
371 parts of the shell later on.
@@ -385,10 +389,76 @@ class UnityTestCase(AutopilotTestCase):
386 self.assertThat(home_scope.isCurrent, Eventually(Equals(True)))
390 self.assertThat(home_scope.isCurrent, Eventually(Equals(True)))
388 def get_dash(self):
393 def get_dash(self):
389− dash = self._proxy.wait_select_single(Dash)
394+ dash = self._proxy.wait_select_single(dash_helpers.Dash)
390 return dash
395 return dash
392 @property
397 @property
393 def main_window(self):
398 def main_window(self):
394 return self._proxy.select_single(main_window_emulator.QQuickView)
399 return self._proxy.select_single(main_window_emulator.QQuickView)
402+class DashBaseTestCase(AutopilotTestCase):
404+ scenarios = _get_device_emulation_scenarios()
405+ qml_mock_enabled = True
409+ if model() != 'Desktop':
410+ process_helpers.restart_unity()
412+ super(DashBaseTestCase, self).setUp()
414+ if self.qml_mock_enabled:
415+ self.environment['QML2_IMPORT_PATH'] = (
416+ get_qml_import_path_with_mock()
419+ if self.should_simulate_device():
420+ # This sets the grid units, so it should be called before launching
422+ self.simulate_device()
424+ binary_path = get_binary_path('unity8-dash')
425+ dash_proxy = self.launch_dash(binary_path, self.environment)
427+ if self.should_simulate_device():
428+ # XXX Currently we have no way to launch the application with a
429+ # specific size, so we must resize it after it's launched.
430+ # --elopio - 2014-06-25
431+ self.resize_window()
433+ self.dash_app = dash_helpers.DashApp(dash_proxy)
434+ self.dash = self.dash_app.dash
436+ def should_simulate_device(self):
437+ return (hasattr(self, 'app_width') and hasattr(self, 'app_height') and
438+ hasattr(self, 'grid_unit_px'))
440+ def simulate_device(self):
441+ simulate_device_fixture = self.useFixture(
442+ toolkit_fixtures.SimulateDevice(
443+ self.app_width, self.app_height, self.grid_unit_px))
444+ self.app_width = simulate_device_fixture.app_width
445+ self.app_height = simulate_device_fixture.app_height
447+ def resize_window(self):
448+ application = self.process_manager.get_running_applications()[0]
449+ window = application.get_windows()[0]
450+ window.resize(self.app_width, self.app_height)
452+ def get_window_size():
453+ _, _, window_width, window_height = window.geometry
454+ return window_width, window_height
458+ Eventually(Equals((self.app_width, self.app_height))))
460+ def launch_dash(self, binary_path, variables):
461+ launch_dash_app_fixture = fixture_setup.LaunchDashApp(
462+ binary_path, variables)
463+ self.useFixture(launch_dash_app_fixture)
464+ return launch_dash_app_fixture.application_proxy