on xenial help sign in
Cleanup launching default apps.
16b8436Christopher Lee
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+32−47
@@ -21,14 +21,14 @@
21
21
22from __future__ import absolute_import
22from __future__ import absolute_import
23
23
24+from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
25+
24from autopilot.matchers import Eventually
26from autopilot.matchers import Eventually
25from autopilot.platform import model
27from autopilot.platform import model
28+from testtools.matchers import Equals, NotEquals
26
29
27import logging
30import logging
28
31
29−from testtools.matchers import Equals, NotEquals
30−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
31−
32logger = logging.getLogger(__name__)
32logger = logging.getLogger(__name__)
33
33
34
34
@@ -39,9 +39,9 @@ class ApplicationLifecycleTests(UnityTestCase):
39 def setUp(self):
39 def setUp(self):
40 super(ApplicationLifecycleTests, self).setUp()
40 super(ApplicationLifecycleTests, self).setUp()
41 if model() == "Desktop":
41 if model() == "Desktop":
42− self.skipTest("Test must be run on a device.")
42+ self.skipTest("Test cannot be run on the desktop.")
43
43
44− def swipe_from_right(self):
44+ def swipe_screen_from_right(self):
45 qml_view = self.main_window.get_qml_view()
45 qml_view = self.main_window.get_qml_view()
46 width = qml_view.width
46 width = qml_view.width
47 height = qml_view.height
47 height = qml_view.height
@@ -50,50 +50,48 @@ class ApplicationLifecycleTests(UnityTestCase):
50 end_x = int(width/2)
50 end_x = int(width/2)
51 end_y = start_y
51 end_y = start_y
52
52
53+ logger.info("Swiping screen from the right edge")
53 self.touch.drag(start_x, start_y, end_x, end_y)
54 self.touch.drag(start_x, start_y, end_x, end_y)
54
55
55− def test_can_launch_application(self):
56+ def _launch_default_app(self, app_name):
56− """must be able to launch and interact with an application."""
57+ """Launches the default application *app_name*
57− unity = self.launch_unity()
58+
58− self.main_window.get_greeter().swipe()
59+ *app_name* must be the name of a default application i.e. messaging-app
59
60
60− app = self.launch_test_application(
61+ """
61− "messaging-app",
62− "--desktop_file_hint="
62+ desktop_file = "--desktop_file_hint="\
63− "/usr/share/applications/messaging-app.desktop",
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,
64 "--stage_hint=main_stage",
69 "--stage_hint=main_stage",
65 app_type='qt'
70 app_type='qt'
66 )
71 )
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+
67 shell = unity.select_single("Shell")
80 shell = unity.select_single("Shell")
68
81
69 self.assertThat(app, NotEquals(None))
82 self.assertThat(app, NotEquals(None))
70 self.assertThat(shell.currentFocusedAppId, Equals("messaging-app"))
83 self.assertThat(shell.currentFocusedAppId, Equals("messaging-app"))
71
84
72 def test_can_launch_multiple_applications(self):
85 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."""
74 unity = self.launch_unity()
87 unity = self.launch_unity()
75 self.main_window.get_greeter().swipe()
88 self.main_window.get_greeter().swipe()
76
89
77− first_app = self.launch_test_application(
78− "messaging-app",
90+ self._launch_default_app("messaging-app")
79− "--desktop_file_hint="
91+ self._launch_default_app("address-book-app")
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− )
92
92
93 shell = unity.select_single("Shell")
93 shell = unity.select_single("Shell")
94
94
95− # Required?
96− self.assertThat(shell.currentFocusedAppId, NotEquals("messaging-app"))
97 self.assertThat(shell.currentFocusedAppId, Equals("address-book-app"))
95 self.assertThat(shell.currentFocusedAppId, Equals("address-book-app"))
98
96
99 def test_app_moves_from_unfocused_to_focused(self):
97 def test_app_moves_from_unfocused_to_focused(self):
@@ -104,23 +102,10 @@ class ApplicationLifecycleTests(UnityTestCase):
104 unity = self.launch_unity()
102 unity = self.launch_unity()
105 self.main_window.get_greeter().swipe()
103 self.main_window.get_greeter().swipe()
106
104
107− first_app = self.launch_test_application(
108− "messaging-app",
105+ self._launch_default_app("messaging-app")
109− "--desktop_file_hint="
106+ self._launch_default_app("address-book-app")
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− )
122
107
123− self.swipe_from_right()
108+ self.swipe_screen_from_right()
124
109
125 shell = unity.select_single("Shell")
110 shell = unity.select_single("Shell")
126 self.assertThat(
111 self.assertThat(