@@ -21,14 +21,14 @@
2121
2222from __future__ import absolute_import
2323
24+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
25+
2426from autopilot.matchers import Eventually
2527from autopilot.platform import model
28+from testtools.matchers import Equals, NotEquals
2629
2730import logging
2831
29−from testtools.matchers import Equals, NotEquals
30−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
31−
3232logger = logging.getLogger(__name__)
3333
3434
@@ -39,9 +39,9 @@ class ApplicationLifecycleTests(UnityTestCase):
3939 def setUp(self):
4040 super(ApplicationLifecycleTests, self).setUp()
4141 if model() == "Desktop":
42− self.skipTest("Test must be run on a device.")
42+ self.skipTest("Test cannot be run on the desktop.")
4343
44− def swipe_from_right(self):
44+ def swipe_screen_from_right(self):
4545 qml_view = self.main_window.get_qml_view()
4646 width = qml_view.width
4747 height = qml_view.height
@@ -50,50 +50,48 @@ class ApplicationLifecycleTests(UnityTestCase):
5050 end_x = int(width/2)
5151 end_y = start_y
5252
53+ logger.info("Swiping screen from the right edge")
5354 self.touch.drag(start_x, start_y, end_x, end_y)
5455
55− def test_can_launch_application(self):
56− """must be able to launch and interact with an application."""
57− unity = self.launch_unity()
58− self.main_window.get_greeter().swipe()
56+ def _launch_default_app(self, app_name):
57+ """Launches the default application *app_name*
58+
59+ *app_name* must be the name of a default application i.e. messaging-app
5960
60− app = self.launch_test_application(
61− "messaging-app",
62− "--desktop_file_hint="
63− "/usr/share/applications/messaging-app.desktop",
61+ """
62+ desktop_file = "--desktop_file_hint="\
63+ "/usr/share/applications/{app_name}.desktop".format(
64+ app_name=app_name
65+ )
66+ return self.launch_test_application(
67+ app_name,
68+ desktop_file,
6469 "--stage_hint=main_stage",
6570 app_type='qt'
6671 )
72+
73+ def test_can_launch_application(self):
74+ """Must be able to launch an application."""
75+ unity = self.launch_unity()
76+ self.main_window.get_greeter().swipe()
77+
78+ app = self._launch_default_app("messaging-app")
79+
6780 shell = unity.select_single("Shell")
6881
6982 self.assertThat(app, NotEquals(None))
7083 self.assertThat(shell.currentFocusedAppId, Equals("messaging-app"))
7184
7285 def test_can_launch_multiple_applications(self):
73− """A second application launched must be usable."""
86+ """A second application launched must be focused and usable."""
7487 unity = self.launch_unity()
7588 self.main_window.get_greeter().swipe()
7689
77− first_app = self.launch_test_application(
78− "messaging-app",
79− "--desktop_file_hint="
80− "/usr/share/applications/messaging-app.desktop",
81− "--stage_hint=main_stage",
82− app_type='qt'
83− )
84−
85− second_app = self.launch_test_application(
86− "address-book-app",
87− "--desktop_file_hint="
88− "/usr/share/applications/address-book-app.desktop",
89− "--stage_hint=main_stage",
90− app_type='qt'
91− )
90+ self._launch_default_app("messaging-app")
91+ self._launch_default_app("address-book-app")
9292
9393 shell = unity.select_single("Shell")
9494
95− # Required?
96− self.assertThat(shell.currentFocusedAppId, NotEquals("messaging-app"))
9795 self.assertThat(shell.currentFocusedAppId, Equals("address-book-app"))
9896
9997 def test_app_moves_from_unfocused_to_focused(self):
@@ -104,23 +102,10 @@ class ApplicationLifecycleTests(UnityTestCase):
104102 unity = self.launch_unity()
105103 self.main_window.get_greeter().swipe()
106104
107− first_app = self.launch_test_application(
108− "messaging-app",
109− "--desktop_file_hint="
110− "/usr/share/applications/messaging-app.desktop",
111− "--stage_hint=main_stage",
112− app_type='qt'
113− )
114−
115− second_app = self.launch_test_application(
116− "address-book-app",
117− "--desktop_file_hint="
118− "/usr/share/applications/address-book-app.desktop",
119− "--stage_hint=main_stage",
120− app_type='qt'
121− )
105+ self._launch_default_app("messaging-app")
106+ self._launch_default_app("address-book-app")
122107
123− self.swipe_from_right()
108+ self.swipe_screen_from_right()
124109
125110 shell = unity.select_single("Shell")
126111 self.assertThat(