@@ -34,6 +34,7 @@ import os.path
3434import subprocess
3535import sys
3636from testtools.matchers import Equals
37+from ubuntuuitoolkit import fixture_setup as toolkit_fixtures
3738
3839from unity8 import (
3940 get_lib_path,
@@ -42,9 +43,14 @@ from unity8 import (
4243 get_default_extra_mock_libraries,
4344 get_data_dirs
4445)
45−from unity8.process_helpers import restart_unity_with_testability
46−from unity8.shell.emulators import main_window as main_window_emulator
47−from unity8.shell.emulators.dash import Dash
46+from unity8 import (
47+ fixture_setup,
48+ process_helpers
49+)
50+from unity8.shell.emulators import (
51+ dash as dash_helpers,
52+ main_window as main_window_emulator,
53+)
4854
4955
5056logger = logging.getLogger(__name__)
@@ -78,6 +84,26 @@ def _get_device_emulation_scenarios(devices='All'):
7884 return [native]
7985
8086
87+def is_unity7_running():
88+ """Return True if Unity7 is running. Otherwise, return False."""
89+ return (
90+ Gio is not None and
91+ UNITYSHELL_GSETTINGS_SCHEMA in
92+ Gio.Settings.list_relocatable_schemas()
93+ )
94+
95+
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'))
101+
102+ qml_import_path = ':'.join(qml_import_path)
103+ logger.info("New QML2 import path: %s", qml_import_path)
104+ return qml_import_path
105+
106+
81107class UnityTestCase(AutopilotTestCase):
82108
83109 """A test case base class for the Unity shell tests."""
@@ -118,23 +144,8 @@ class UnityTestCase(AutopilotTestCase):
118144
119145 def setUp(self):
120146 super(UnityTestCase, self).setUp()
121− if (Gio is not None and
122− UNITYSHELL_GSETTINGS_SCHEMA in
123− Gio.Settings.list_relocatable_schemas()):
124−
125− # Hide Unity launcher
126− self._unityshell_schema = Gio.Settings.new_with_path(
127− UNITYSHELL_GSETTINGS_SCHEMA,
128− UNITYSHELL_GSETTINGS_PATH,
129− )
130− self._launcher_hide_mode = self._unityshell_schema.get_int(
131− UNITYSHELL_LAUNCHER_KEY,
132− )
133− self._unityshell_schema.set_int(
134− UNITYSHELL_LAUNCHER_KEY,
135− UNITYSHELL_LAUNCHER_MODE,
136− )
137− self.addCleanup(self._reset_launcher)
147+ if is_unity7_running():
148+ self.useFixture(toolkit_fixtures.HideUnity7Launcher())
138149
139150 self._proxy = None
140151 self._lightdm_mock_type = None
@@ -263,7 +274,9 @@ class UnityTestCase(AutopilotTestCase):
263274 self.patch_lightdm_mock()
264275
265276 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()
279+ )
267280
268281 if self._data_dirs_mock_enabled:
269282 self._patch_data_dirs()
@@ -308,7 +321,7 @@ class UnityTestCase(AutopilotTestCase):
308321
309322 self.addCleanup(self._cleanup_launching_upstart_unity)
310323
311− return restart_unity_with_testability(*all_args)
324+ return process_helpers.restart_unity_with_testability(*all_args)
312325
313326 def _cleanup_launching_upstart_unity(self):
314327 logger.info("Stopping unity")
@@ -353,15 +366,6 @@ class UnityTestCase(AutopilotTestCase):
353366 )
354367 return lightdm_mock_path
355368
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'))
360−
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
364−
365369 def _set_proxy(self, proxy):
366370 """Keep a copy of the proxy object, so we can use it to get common
367371 parts of the shell later on.
@@ -385,10 +389,76 @@ class UnityTestCase(AutopilotTestCase):
385389 )
386390 self.assertThat(home_scope.isCurrent, Eventually(Equals(True)))
387391
392+
388393 def get_dash(self):
389− dash = self._proxy.wait_select_single(Dash)
394+ dash = self._proxy.wait_select_single(dash_helpers.Dash)
390395 return dash
391396
392397 @property
393398 def main_window(self):
394399 return self._proxy.select_single(main_window_emulator.QQuickView)
400+
401+
402+class DashBaseTestCase(AutopilotTestCase):
403+
404+ scenarios = _get_device_emulation_scenarios()
405+ qml_mock_enabled = True
406+ environment = {}
407+
408+ def setUp(self):
409+ if model() != 'Desktop':
410+ process_helpers.restart_unity()
411+
412+ super(DashBaseTestCase, self).setUp()
413+
414+ if self.qml_mock_enabled:
415+ self.environment['QML2_IMPORT_PATH'] = (
416+ get_qml_import_path_with_mock()
417+ )
418+
419+ if self.should_simulate_device():
420+ # This sets the grid units, so it should be called before launching
421+ # the app.
422+ self.simulate_device()
423+
424+ binary_path = get_binary_path('unity8-dash')
425+ dash_proxy = self.launch_dash(binary_path, self.environment)
426+
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()
432+
433+ self.dash_app = dash_helpers.DashApp(dash_proxy)
434+ self.dash = self.dash_app.dash
435+
436+ def should_simulate_device(self):
437+ return (hasattr(self, 'app_width') and hasattr(self, 'app_height') and
438+ hasattr(self, 'grid_unit_px'))
439+
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
446+
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)
451+
452+ def get_window_size():
453+ _, _, window_width, window_height = window.geometry
454+ return window_width, window_height
455+
456+ self.assertThat(
457+ get_window_size,
458+ Eventually(Equals((self.app_width, self.app_height))))
459+
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