on xenial help sign in
WIP
commit1cb0f02e7fc38894303887d7bc29e048fb313593 authorChristopher Lee <chris.lee@canonical.com> dateWed 11 Sep 2013, 12:13 (13 years ago) parent8b02a3b
4 files changed+188−1
tests/autopilot/unity8/application_lifecycle/__init__.py+20 tests/autopilot/unity8/application_lifecycle/tests/__init__.py tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+167 tests/autopilot/unity8/shell/tests/__init__.py+1−1
tests/autopilot/unity8/application_lifecycle/__init__.pynew file+20
@@ -0,0 +1,20 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Autopilot Test Suite
4+# Copyright (C) 2013 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+"""Tests for the application lifecycle base package."""
tests/autopilot/unity8/application_lifecycle/tests/__init__.pynew file

No changes to the content.

tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.pynew file+167
@@ -0,0 +1,167 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Autopilot Test Suite
4+# Copyright (C) 2013 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+"""Tests for the application lifecycle."""
21+
22+from __future__ import absolute_import
23+
24+import logging
25+from textwrap import dedent
26+import os
27+from tempfile import mktemp
28+
29+from autopilot.platform import model
30+
31+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
32+
33+from testtools.matchers import Equals
34+
35+
36+logger = logging.getLogger(__name__)
37+
38+
39+class ApplicationLifecycleTests(UnityTestCase):
40+
41+ scenarios = _get_device_emulation_scenarios()
42+
43+ def setUp(self):
44+ super(ApplicationLifecycleTests, self).setUp()
45+ if model() == "Desktop":
46+ self.skipTest("Test must be run on a device.")
47+
48+ def swipe_from_right(self):
49+ x, y, w, h = self.main_window.globalRect
50+ start_x = w
51+ start_y = int(h / 2)
52+ end_x = int(w / 2)
53+ end_y = start_y
54+
55+ self.touch.drag(start_x, start_y, end_x, end_y)
56+
57+ def _start_qml_script(self, script_contents):
58+ """Launch a qml script."""
59+ qml_path = mktemp(suffix='.qml')
60+ open(qml_path, 'w').write(script_contents)
61+ self.addCleanup(os.remove, qml_path)
62+
63+ desktop_file = self._get_dummy_desktop_file()
64+
65+ return self.launch_test_application(
66+ "qmlscene",
67+ qml_path,
68+ "--desktop_file_hint=%s" % desktop_file,
69+ app_type='qt',
70+ )
71+
72+ def _get_dummy_desktop_file(self):
73+ """Create a temp desktop file with app name *app_name*.
74+
75+ Returns the full path to the file.
76+
77+ """
78+ file_path = mktemp(suffix='.desktop')
79+ script_contents = dedent(
80+"""[Desktop Entry]
81+Name=App1
82+Comment=My project description
83+Exec=true
84+Icon=qmlscene
85+Terminal=false
86+Type=Application
87+X-Ubuntu-Touch=true""")
88+ open(file_path, 'w').write(script_contents)
89+ self.addCleanup(os.remove, file_path)
90+
91+ print ">>> file path: ", file_path
92+ return file_path
93+
94+ # def _get_qml_script(self, title="Test App"):
95+ # return dedent("""
96+ # import QtQuick 2.0
97+ # import Ubuntu.Components 0.1
98+
99+ # Page {
100+ # title: "%s"
101+ # width: units.gu(48)
102+ # height: units.gu(60)
103+ # }
104+ # """ % title)
105+ def _get_qml_script(self, name="TestApp"):
106+ return dedent("""
107+ import QtQuick 2.0
108+ import Ubuntu.Components 0.1
109+
110+ Rectangle {
111+ objectName: "%s"
112+ color: "lightblue"
113+ Text {
114+ text: "%s"
115+ font.pixelSize: units.gu(8)
116+ }
117+ }
118+ """ % (name, name))
119+
120+ def test_can_launch_application(self):
121+ """must be able to launch and interact with an application."""
122+ self.launch_unity()
123+ self.main_window.get_greeter().swipe()
124+
125+ #import pdb; pdb.set_trace()
126+
127+ test_qml = self._get_qml_script()
128+ app = self._start_qml_script(test_qml)
129+ main_window = app.select_single("Page")
130+
131+ self.assertThat(main_window.title, Equals("Test App"))
132+ self.assertThat(main_window.visible, Equals(True))
133+
134+ def test_can_launch_multiple_applications(self):
135+ """A second application launched must be usable."""
136+ self.launch_unity()
137+ self.main_window.get_greeter().swipe()
138+ first_app = self._start_qml_script(self._get_qml_script("App 1"))
139+ second_app = self._start_qml_script(self._get_qml_script("App 2"))
140+
141+ first_main_window = first_app.select_single("Page")
142+ second_main_window = second_app.select_single("Page")
143+
144+ self.assertThat(first_main_window.visible, Equals(False))
145+
146+ self.assertThat(second_main_window.title, Equals("App 2"))
147+ self.assertThat(second_main_window.visible, Equals(True))
148+
149+ def test_app_moves_from_unfocused_to_focused(self):
150+ """An application that is in the unfocused state must be able to be
151+ brought back to the focused state.
152+
153+ """
154+ self.launch_unity()
155+ self.main_window.get_greeter().swipe()
156+ first_app = self._start_qml_script(self._get_qml_script("App 1"))
157+ self._start_qml_script(self._get_qml_script("App 2"))
158+
159+ first_main_window = first_app.select_single("Page")
160+
161+ self.swipe_from_right()
162+
163+ self.assertThat(first_main_window.title, Equals("App 1"))
164+ self.assertThat(first_main_window.visible, Equals(True))
165+
166+ # interact with it . . .
167+ # self.assertThat(first_main_window.visible, Equals(True))
tests/autopilot/unity8/shell/tests/__init__.py+1−1
@@ -160,7 +160,7 @@ class UnityTestCase(AutopilotTestCase):
160160
161161 if self._lightdm_mock_type is None:
162162 self.patch_lightdm_mock()
163− self._setup_extra_mock_environment_patch()
163+ #self._setup_extra_mock_environment_patch()
164164
165165 app_proxy = self.launch_test_application(
166166 binary_path,