~ubuntu-branches/ubuntu/saucy/ubuntu-ui-toolkit/saucy

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntuuitoolkit/tests/__init__.py

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Timo Jyrinki, Christian Dywan, Zsombor Egri, Leo Arias, Nick Dedekind, Alberto Mardegan, Dennis O'Flaherty, tpeeters, Ubuntu daily release
  • Date: 2013-09-25 07:08:56 UTC
  • mfrom: (1.1.56)
  • Revision ID: package-import@ubuntu.com-20130925070856-2xfkzyjou81vb7m9
Tags: 0.1.46+13.10.20130925.1-0ubuntu1
[ Timo Jyrinki ]
* Temporarily disable the jokes example in order to not have
  qtmultimedia dependency from examples that is not used otherwise.
  This lessens the dependency chains of packages. It can be added back
  after Ubuntu 13.10.
* Fix regression in qmlscene usage (LP: #1229541). (LP: #1229541)

[ Christian Dywan ]
* Set QCoreApplication::applicationName based on MainView. (LP:
  #1197056, #1197051, #1224126)
* Include subfolders of Components in api check.

[ Zsombor Egri ]
* Organizer EDS (Evolution Data Server) integration.
* StateSaver attached component.
* Fix alarm status reporting, updating documentation on asynchronous
  behavior of save and cancel operations. Alarm status notification
  reports the operation the status refers to. (LP: #1226516)
* Dialer + DialerHand components required for TimePicker. .

[ Leo Arias ]
* Added UbuntuUIToolkitAppTestCase as a base test case for the
  autopilot tests. (LP: #1227355)
* Added the autopilot emulator for toggles.

[ Nick Dedekind ]
* Added clipping to tab bar. (LP: #1226104)

[ Alberto Mardegan ]
* Support re-attaching to a different QQuickView Make the plugin
  correctly handle the case when the QQuickView is destroyed and a new
  one is created: this is done by avoiding using static variables, and
  instead binding the data to the QQmlEngine, QQmlContext or QWindow
  as appropriate. . (LP: #1221707)

[ Dennis O'Flaherty ]
* Reword the description for easier reading.

[ tpeeters ]
* Fix warnings when running gallery-app autopilot tests. (LP:
  #1223329, #1223326)
* Smarter automatic updating of Panel's opened property. Panel.open()
  and Panel.close() should be used to open/close a Panel, or when
  using a toolbar with ToolbarItems from a Page, set Page.tools.opened
  to open/close the toolbar. No API or behavior changes since the
  panel-open-close branch. Toolbar behavior changes will be done in a
  following MR.

[ Ubuntu daily release ]
* Automatic snapshot from revision 765

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Ubuntu UI Toolkit autopilot tests."""
18
18
 
19
 
from os import remove
20
 
import os.path
21
 
from tempfile import mktemp
22
 
import subprocess
 
19
import os
 
20
import tempfile
23
21
 
24
 
from autopilot.input import Mouse, Touch, Pointer
 
22
from autopilot.input import Pointer
25
23
from autopilot.matchers import Eventually
26
 
from autopilot.platform import model
27
24
from testtools.matchers import Is, Not, Equals
28
 
from autopilot.testcase import AutopilotTestCase
29
 
 
30
 
from ubuntuuitoolkit import emulators
31
 
 
32
 
 
33
 
def get_module_include_path():
 
25
import subprocess
 
26
 
 
27
from ubuntuuitoolkit import base, emulators
 
28
 
 
29
 
 
30
_DESKTOP_FILE_CONTENTS = ("""[Desktop Entry]
 
31
Type=Application
 
32
Exec=Not important
 
33
Path=Not important
 
34
Name=Test app
 
35
Icon=Not important
 
36
""")
 
37
 
 
38
 
 
39
def _write_test_desktop_file():
 
40
    desktop_file_dir = get_local_desktop_file_directory()
 
41
    if not os.path.exists(desktop_file_dir):
 
42
        os.makedirs(desktop_file_dir)
 
43
    desktop_file = tempfile.NamedTemporaryFile(
 
44
        suffix='.desktop', dir=desktop_file_dir, delete=False)
 
45
    desktop_file.write(_DESKTOP_FILE_CONTENTS)
 
46
    desktop_file.close()
 
47
    return desktop_file.name
 
48
 
 
49
 
 
50
def get_local_desktop_file_directory():
 
51
    return os.path.join(os.environ['HOME'], '.local', 'share', 'applications')
 
52
 
 
53
 
 
54
def _get_module_include_path():
 
55
    return os.path.join(get_path_to_source_root(), 'modules')
 
56
 
 
57
 
 
58
def get_path_to_source_root():
34
59
    return os.path.abspath(
35
60
        os.path.join(
36
 
            os.path.dirname(__file__),
37
 
            '..',
38
 
            '..',
39
 
            '..',
40
 
            '..',
41
 
            'modules')
42
 
    )
43
 
 
44
 
 
45
 
def get_input_device_scenarios():
46
 
    """Return the scenarios with the right input device for the platform."""
47
 
    if model() == 'Desktop':
48
 
        scenarios = [('with mouse', dict(input_device_class=Mouse))]
49
 
    else:
50
 
        scenarios = [('with touch', dict(input_device_class=Touch))]
51
 
    return scenarios
52
 
 
53
 
 
54
 
class UbuntuUiToolkitTestCase(AutopilotTestCase):
55
 
    """Common test case class for SDK tests."""
56
 
 
57
 
    scenarios = get_input_device_scenarios()
58
 
 
59
 
    def setUp(self):
60
 
        self.pointing_device = Pointer(self.input_device_class.create())
61
 
        super(UbuntuUiToolkitTestCase, self).setUp()
62
 
        self.launch_test_qml()
63
 
 
64
 
    def launch_test_qml(self):
65
 
        # If the test class has defined a 'test_qml' class attribute then we
66
 
        # write it to disk and launch it inside the Qml Viewer. If not, then we
67
 
        # silently do nothing (presumably the test has something else planned).
68
 
        arch = subprocess.check_output(
69
 
            ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
70
 
        if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
71
 
            qml_path = mktemp(suffix='.qml')
72
 
            open(qml_path, 'w').write(self.test_qml)
73
 
            self.addCleanup(remove, qml_path)
74
 
 
75
 
            self.app = self.launch_test_application(
76
 
                "/usr/lib/" + arch + "/qt5/bin/qmlscene",
77
 
                "-I" + get_module_include_path(),
78
 
                qml_path,
79
 
                emulator_base=emulators.UbuntuUIToolkitEmulatorBase,
80
 
                app_type='qt')
81
 
 
82
 
        if (hasattr(self, 'test_qml_file') and
83
 
                isinstance(self.test_qml_file, basestring)):
84
 
            qml_path = self.test_qml_file
85
 
            self.app = self.launch_test_application(
86
 
                "/usr/lib/" + arch + "/qt5/bin/qmlscene",
87
 
                "-I" + get_module_include_path(),
88
 
                qml_path,
89
 
                emulator_base=emulators.UbuntuUIToolkitEmulatorBase,
90
 
                app_type='qt')
91
 
 
92
 
        self.assertThat(
93
 
            self.main_view.visible, Eventually(Equals(True)))
 
61
            os.path.dirname(__file__), '..', '..', '..', '..'))
 
62
 
 
63
 
 
64
class QMLStringAppTestCase(base.UbuntuUIToolkitAppTestCase):
 
65
    """Base test case for self tests that define the QML on an string."""
 
66
 
 
67
    test_qml = ("""
 
68
import QtQuick 2.0
 
69
import Ubuntu.Components 0.1
 
70
 
 
71
MainView {
 
72
    width: units.gu(48)
 
73
    height: units.gu(60)
 
74
}
 
75
""")
 
76
 
 
77
    def setUp(self):
 
78
        super(QMLStringAppTestCase, self).setUp()
 
79
        self.pointing_device = Pointer(self.input_device_class.create())
 
80
        self.launch_application()
 
81
 
 
82
    def launch_application(self):
 
83
        arch = subprocess.check_output(
 
84
            ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
 
85
        qml_file_path = self._write_test_qml_file()
 
86
        self.addCleanup(os.remove, qml_file_path)
 
87
        desktop_file_path = _write_test_desktop_file()
 
88
        self.addCleanup(os.remove, desktop_file_path)
 
89
        self.app = self.launch_test_application(
 
90
            '/usr/lib/' + arch + '/qt5/bin/qmlscene',
 
91
            '-I' + _get_module_include_path(),
 
92
            qml_file_path,
 
93
            '--desktop_file_hint={0}'.format(desktop_file_path),
 
94
            emulator_base=emulators.UbuntuUIToolkitEmulatorBase,
 
95
            app_type='qt')
 
96
 
 
97
        self.assertThat(
 
98
            self.main_view.visible, Eventually(Equals(True)))
 
99
 
 
100
    def _write_test_qml_file(self):
 
101
        qml_file = tempfile.NamedTemporaryFile(suffix='.qml', delete=False)
 
102
        qml_file.write(self.test_qml)
 
103
        qml_file.close()
 
104
        return qml_file.name
 
105
 
 
106
    @property
 
107
    def main_view(self):
 
108
        return self.app.select_single(emulators.MainView)
 
109
 
 
110
 
 
111
class QMLFileAppTestCase(base.UbuntuUIToolkitAppTestCase):
 
112
    """Base test case for self tests that launch a QML file."""
 
113
 
 
114
    test_qml_file_path = '/path/to/file.qml'
 
115
    desktop_file_path = None
 
116
 
 
117
    def setUp(self):
 
118
        super(QMLFileAppTestCase, self).setUp()
 
119
        self.pointing_device = Pointer(self.input_device_class.create())
 
120
        self.launch_application()
 
121
 
 
122
    def launch_application(self):
 
123
        arch = subprocess.check_output(
 
124
            ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
 
125
        desktop_file_path = self._get_desktop_file_path()
 
126
        self.app = self.launch_test_application(
 
127
            '/usr/lib/' + arch + '/qt5/bin/qmlscene',
 
128
            "-I" + _get_module_include_path(),
 
129
            self.test_qml_file_path,
 
130
            '--desktop_file_hint={0}'.format(desktop_file_path),
 
131
            emulator_base=emulators.UbuntuUIToolkitEmulatorBase,
 
132
            app_type='qt')
 
133
 
 
134
        self.assertThat(
 
135
            self.main_view.visible, Eventually(Equals(True)))
 
136
 
 
137
    def _get_desktop_file_path(self):
 
138
        if self.desktop_file_path is None:
 
139
            desktop_file_path = _write_test_desktop_file()
 
140
            self.addCleanup(os.remove, desktop_file_path)
 
141
            return desktop_file_path
 
142
        else:
 
143
            self.desktop_file_path
94
144
 
95
145
    @property
96
146
    def main_view(self):