@@ -20,10 +20,12 @@
20"""Test the integration with the URL dispatcher service."""
20"""Test the integration with the URL dispatcher service."""
24from autopilot import platform
25from autopilot import platform
25from autopilot.matchers import Eventually
26from autopilot.matchers import Eventually
26from testtools.matchers import Equals
27from testtools.matchers import Equals
28+from ubuntuuitoolkit import base as toolkit_base
28from unity8 import process_helpers
30from unity8 import process_helpers
29from unity8.shell import tests
31from unity8.shell import tests
@@ -33,6 +35,27 @@ class URLDispatcherTestCase(tests.UnityTestCase):
34 scenarios = tests._get_device_emulation_scenarios()
36 scenarios = tests._get_device_emulation_scenarios()
40+import Ubuntu.Components 0.1
47+ text: 'Test application.'
52+ desktop_file_contents = ("""[Desktop Entry]
55+Exec={qmlscene} {qml_file_path}
36 def setUp(self):
59 def setUp(self):
37 if platform.model() == 'Desktop':
60 if platform.model() == 'Desktop':
38 self.skipTest("URL dispatcher doesn't work on the desktop.")
61 self.skipTest("URL dispatcher doesn't work on the desktop.")
@@ -42,17 +65,50 @@ class URLDispatcherTestCase(tests.UnityTestCase):
42 unity_proxy = self.launch_unity()
65 unity_proxy = self.launch_unity()
43 process_helpers.unlock_unity(unity_proxy)
66 process_helpers.unlock_unity(unity_proxy)
68+ def create_test_application(self):
69+ # FIXME most of this code is duplicated in the toolkit. We should
70+ # create a fixture on the toolkit for other projects to use.
71+ # http://pad.lv/1277334 --elopio - 2014-02-06
72+ qml_file_path = self._write_test_qml_file()
73+ self.addCleanup(os.remove, qml_file_path)
74+ desktop_file_path = self._write_test_desktop_file(qml_file_path)
75+ self.addCleanup(os.remove, desktop_file_path)
76+ return qml_file_path, desktop_file_path
78+ def _write_test_qml_file(self):
79+ qml_file = tempfile.NamedTemporaryFile(suffix='.qml', delete=False)
80+ qml_file.write(self.test_qml.encode('utf-8'))
84+ def _write_test_desktop_file(self, qml_file_path):
85+ desktop_file_dir = self._get_local_desktop_file_directory()
86+ if not os.path.exists(desktop_file_dir):
87+ os.makedirs(desktop_file_dir)
88+ desktop_file = tempfile.NamedTemporaryFile(
89+ suffix='.desktop', dir=desktop_file_dir, delete=False)
90+ contents = self.desktop_file_contents.format(
91+ qmlscene=toolkit_base.get_qmlscene_launch_command(),
92+ qml_file_path=qml_file_path)
93+ desktop_file.write(contents.encode('utf-8'))
95+ return desktop_file.name
97+ def _get_local_desktop_file_directory():
99+ os.environ.get('HOME'), '.local', 'share', 'applications')
45 def test_swipe_out_application_started_by_url_dispatcher(self):
101 def test_swipe_out_application_started_by_url_dispatcher(self):
102+ _, desktop_file_path = self.create_test_application()
46 self.assertEqual('', self.main_window.get_current_focused_app_id())
104 self.assertEqual('', self.main_window.get_current_focused_app_id())
47− # XXX we shouldn't depend on external applications; but the camera app
48− # is already a depedency for other tests, so it's not that bad to use
49− # it until the url-dispatcher implements the testability features to
50− # let us launch a fake app. --elopio - 2014-02-05
51− self.addCleanup(os.system, 'pkill camera-app')
105+ self.addCleanup(os.system, 'pkill qmlscene')
52− os.system('url-dispatcher application:///camera-app.desktop')
107+ 'url-dispatcher application:///{}'.format(
108+ os.basename(desktop_file_path)))
53 self.assertThat(
109 self.assertThat(
54 self.main_window.get_current_focused_app_id,
110 self.main_window.get_current_focused_app_id,
55− Eventually(Equals('camera-app')))
111+ Eventually(Equals('test')))
56 self.main_window.show_dash_swiping()
112 self.main_window.show_dash_swiping()
57 self.assertThat(
113 self.assertThat(
58 self.main_window.get_current_focused_app_id,
114 self.main_window.get_current_focused_app_id,