@@ -0,0 +1,167 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3+# Unity Autopilot Test Suite
4+# Copyright (C) 2013 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+"""Tests for the application lifecycle."""
22+from __future__ import absolute_import
25+from textwrap import dedent
27+from tempfile import mktemp
29+from autopilot.platform import model
31+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
33+from testtools.matchers import Equals
36+logger = logging.getLogger(__name__)
39+class ApplicationLifecycleTests(UnityTestCase):
41+ scenarios = _get_device_emulation_scenarios()
44+ super(ApplicationLifecycleTests, self).setUp()
45+ if model() == "Desktop":
46+ self.skipTest("Test must be run on a device.")
48+ def swipe_from_right(self):
49+ x, y, w, h = self.main_window.globalRect
55+ self.touch.drag(start_x, start_y, end_x, end_y)
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)
63+ desktop_file = self._get_dummy_desktop_file()
65+ return self.launch_test_application(
68+ "--desktop_file_hint=%s" % desktop_file,
72+ def _get_dummy_desktop_file(self):
73+ """Create a temp desktop file with app name *app_name*.
75+ Returns the full path to the file.
78+ file_path = mktemp(suffix='.desktop')
79+ script_contents = dedent(
82+Comment=My project description
87+X-Ubuntu-Touch=true""")
88+ open(file_path, 'w').write(script_contents)
89+ self.addCleanup(os.remove, file_path)
91+ print ">>> file path: ", file_path
94+ # def _get_qml_script(self, title="Test App"):
97+ # import Ubuntu.Components 0.1
101+ # width: units.gu(48)
102+ # height: units.gu(60)
105+ def _get_qml_script(self, name="TestApp"):
108+ import Ubuntu.Components 0.1
115+ font.pixelSize: units.gu(8)
120+ def test_can_launch_application(self):
121+ """must be able to launch and interact with an application."""
123+ self.main_window.get_greeter().swipe()
125+ #import pdb; pdb.set_trace()
127+ test_qml = self._get_qml_script()
128+ app = self._start_qml_script(test_qml)
129+ main_window = app.select_single("Page")
131+ self.assertThat(main_window.title, Equals("Test App"))
132+ self.assertThat(main_window.visible, Equals(True))
134+ def test_can_launch_multiple_applications(self):
135+ """A second application launched must be usable."""
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"))
141+ first_main_window = first_app.select_single("Page")
142+ second_main_window = second_app.select_single("Page")
144+ self.assertThat(first_main_window.visible, Equals(False))
146+ self.assertThat(second_main_window.title, Equals("App 2"))
147+ self.assertThat(second_main_window.visible, Equals(True))
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.
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"))
159+ first_main_window = first_app.select_single("Page")
161+ self.swipe_from_right()
163+ self.assertThat(first_main_window.title, Equals("App 1"))
164+ self.assertThat(first_main_window.visible, Equals(True))
166+ # interact with it . . .
167+ # self.assertThat(first_main_window.visible, Equals(True))