@@ -20,10 +20,12 @@
2020"""Test the integration with the URL dispatcher service."""
2121
2222import os
23+import tempfile
2324
2425from autopilot import platform
2526from autopilot.matchers import Eventually
2627from testtools.matchers import Equals
28+from ubuntuuitoolkit import base as toolkit_base
2729
2830from unity8 import process_helpers
2931from unity8.shell import tests
@@ -33,6 +35,27 @@ class URLDispatcherTestCase(tests.UnityTestCase):
3335
3436 scenarios = tests._get_device_emulation_scenarios()
3537
38+ test_qml = ("""
39+import QtQuick 2.0
40+import Ubuntu.Components 0.1
41+
42+MainView {
43+ width: units.gu(48)
44+ height: units.gu(60)
45+
46+ Label {
47+ text: 'Test application.'
48+ }
49+}
50+""")
51+
52+ desktop_file_contents = ("""[Desktop Entry]
53+Type=Application
54+Name=test
55+Exec={qmlscene} {qml_file_path}
56+Icon=Not important
57+""")
58+
3659 def setUp(self):
3760 if platform.model() == 'Desktop':
3861 self.skipTest("URL dispatcher doesn't work on the desktop.")
@@ -42,17 +65,50 @@ class URLDispatcherTestCase(tests.UnityTestCase):
4265 unity_proxy = self.launch_unity()
4366 process_helpers.unlock_unity(unity_proxy)
4467
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
77+
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'))
81+ qml_file.close()
82+ return qml_file.name
83+
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'))
94+ desktop_file.close()
95+ return desktop_file.name
96+
97+ def _get_local_desktop_file_directory():
98+ return os.path.join(
99+ os.environ.get('HOME'), '.local', 'share', 'applications')
100+
45101 def test_swipe_out_application_started_by_url_dispatcher(self):
102+ _, desktop_file_path = self.create_test_application()
103+
46104 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')
52− os.system('url-dispatcher application:///camera-app.desktop')
105+ self.addCleanup(os.system, 'pkill qmlscene')
106+ os.system(
107+ 'url-dispatcher application:///{}'.format(
108+ os.basename(desktop_file_path)))
53109 self.assertThat(
54110 self.main_window.get_current_focused_app_id,
55− Eventually(Equals('camera-app')))
111+ Eventually(Equals('test')))
56112 self.main_window.show_dash_swiping()
57113 self.assertThat(
58114 self.main_window.get_current_focused_app_id,