~nick-dedekind/unity8/indicators.hint-interval

« back to all changes in this revision

Viewing changes to tests/autopilot/unity8/application_lifecycle/tests/test_url_dispatcher.py

  • Committer: Nick Dedekind
  • Date: 2014-03-07 15:54:57 UTC
  • mfrom: (638.1.118 unity8)
  • Revision ID: nicholas.dedekind@gmail.com-20140307155457-f0s1zu5ll2czt3rq
merged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# Unity Autopilot Test Suite
 
4
# Copyright (C) 2014 Canonical
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
#
 
19
 
 
20
"""Test the integration with the URL dispatcher service."""
 
21
 
 
22
import os
 
23
import tempfile
 
24
 
 
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
 
29
 
 
30
from unity8 import process_helpers
 
31
from unity8.shell import tests
 
32
 
 
33
 
 
34
class URLDispatcherTestCase(tests.UnityTestCase):
 
35
 
 
36
    scenarios = tests._get_device_emulation_scenarios()
 
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
 
 
59
    def setUp(self):
 
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)
 
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(self):
 
98
        return os.path.join(
 
99
            os.environ.get('HOME'), '.local', 'share', 'applications')
 
100
 
 
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)
 
105
 
 
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))
 
109
        self.assertThat(
 
110
            self.main_window.get_current_focused_app_id,
 
111
            Eventually(Equals(application_name)))
 
112
 
 
113
        self.main_window.show_dash_swiping()
 
114
        self.assertThat(
 
115
            self.main_window.get_current_focused_app_id,
 
116
            Eventually(Equals('')))