@@ -0,0 +1,136 @@
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
24+from unity8.shell import disable_qml_mocking
25+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
27+from autopilot.matchers import Eventually
28+from autopilot.platform import model
29+from testtools.matchers import Equals, NotEquals
33+logger = logging.getLogger(__name__)
36+class ApplicationLifecycleTests(UnityTestCase):
38+ scenarios = _get_device_emulation_scenarios()
41+ super(ApplicationLifecycleTests, self).setUp()
42+ if model() == "Desktop":
43+ self.skipTest("Test cannot be run on the desktop.")
45+ def swipe_screen_from_right(self):
46+ qml_view = self.main_window.get_qml_view()
47+ width = qml_view.width
48+ height = qml_view.height
50+ start_y = int(height/2)
54+ logger.info("Swiping screen from the right edge")
55+ self.touch.drag(start_x, start_y, end_x, end_y)
57+ def _get_current_focused_app_id(self):
58+ return self._proxy.select_single("Shell").currentFocusedAppId
60+ def _launch_app(self, app_name):
61+ """Launches the application *app_name*
63+ Assumes that the desktop file resides at:
64+ /usr/share/applications/{app_name}.desktop
67+ desktop_file = "--desktop_file_hint="\
68+ "/usr/share/applications/{app_name}.desktop".format(
71+ return self.launch_test_application(
74+ "--stage_hint=main_stage",
79+ def test_can_launch_application(self):
80+ """Must be able to launch an application."""
82+ self.main_window.get_greeter().swipe()
84+ app = self._launch_app("messaging-app")
86+ self.assertThat(app, NotEquals(None))
88+ self._get_current_focused_app_id(),
89+ Eventually(Equals("messaging-app"))
93+ def test_can_launch_multiple_applications(self):
94+ """A second application launched must be focused."""
96+ self.main_window.get_greeter().swipe()
98+ self._launch_app("messaging-app")
100+ self._get_current_focused_app_id(),
101+ Eventually(Equals("messaging-app"))
104+ self._launch_app("address-book-app")
106+ self._get_current_focused_app_id(),
107+ Eventually(Equals("address-book-app"))
110+ @disable_qml_mocking
111+ def test_app_moves_from_unfocused_to_focused(self):
112+ """An application that is in the unfocused state must be able to be
113+ brought back to the focused state.
117+ self.main_window.get_greeter().swipe()
119+ self._launch_app("messaging-app")
121+ self._get_current_focused_app_id(),
122+ Eventually(Equals("messaging-app"))
125+ self._launch_app("address-book-app")
127+ self._get_current_focused_app_id(),
128+ Eventually(Equals("address-book-app"))
131+ self.swipe_screen_from_right()
134+ self._get_current_focused_app_id(),
135+ Eventually(Equals("messaging-app"))