on xenial help sign in
Replaced the camera with a fake application.
8366c80Leo Arias
debian/control+1−2
@@ -103,8 +103,7 @@ Description: Unity 8 shell
103
103
104Package: unity8-autopilot
104Package: unity8-autopilot
105Architecture: all
105Architecture: all
106−Depends: camera-app,
107− gir1.2-glib-2.0,
106+Depends: gir1.2-glib-2.0,
108 libautopilot-qt (>= 1.4),
107 libautopilot-qt (>= 1.4),
109 libqt5test5,
108 libqt5test5,
110 libqt5widgets5,
109 libqt5widgets5,
tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py+63−7
@@ -20,10 +20,12 @@
20"""Test the integration with the URL dispatcher service."""
20"""Test the integration with the URL dispatcher service."""
21
21
22import os
22import os
23+import tempfile
23
24
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
27
29
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):
33
35
34 scenarios = tests._get_device_emulation_scenarios()
36 scenarios = tests._get_device_emulation_scenarios()
35
37
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+
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)
44
67
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+
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()
103+
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')
106+ os.system(
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,