1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Unity Autopilot Test Suite
4
# Copyright (C) 2014 Canonical
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
"""Test the integration with the URL dispatcher service."""
25
from autopilot import platform
26
from autopilot.matchers import Eventually
27
from testtools.matchers import Equals
28
from ubuntuuitoolkit import base as toolkit_base
30
from unity8 import process_helpers
31
from unity8.shell import tests
34
class URLDispatcherTestCase(tests.UnityTestCase):
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}
60
if platform.model() == 'Desktop':
61
self.skipTest("URL dispatcher doesn't work on the desktop.")
62
super(URLDispatcherTestCase, self).setUp()
63
self._qml_mock_enabled = False
64
self._data_dirs_mock_enabled = False
65
unity_proxy = self.launch_unity()
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(self):
99
os.environ.get('HOME'), '.local', 'share', 'applications')
101
def test_swipe_out_application_started_by_url_dispatcher(self):
102
_, desktop_file_path = self.create_test_application()
103
desktop_file_name = os.path.basename(desktop_file_path)
104
application_name, _ = os.path.splitext(desktop_file_name)
106
self.assertEqual('', self.main_window.get_current_focused_app_id())
107
self.addCleanup(os.system, 'pkill qmlscene')
108
os.system('url-dispatcher application:///{}'.format(desktop_file_name))
110
self.main_window.get_current_focused_app_id,
111
Eventually(Equals(application_name)))
113
self.main_window.show_dash_swiping()
115
self.main_window.get_current_focused_app_id,
116
Eventually(Equals('')))