@@ -21,28 +21,26 @@
22from __future__ import absolute_import
22from __future__ import absolute_import
24−from unity8.process_helpers import lock_unity, unlock_unity
24+import logging
25−from unity8.shell import disable_qml_mocking
25+import os
26−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
28from autopilot.matchers import Eventually
27from autopilot.matchers import Eventually
29from autopilot.platform import model
28from autopilot.platform import model
30−from testtools.matchers import Equals, NotEquals
29+from testtools.matchers import Equals
32−import logging
31+from unity8 import process_helpers
33−import subprocess
32+from unity8.application_lifecycle import tests
35−logger = logging.getLogger(__name__)
35+logger = logging.getLogger(__name__)
38−class ApplicationLifecycleTests(UnityTestCase):
40− scenarios = _get_device_emulation_scenarios()
38+class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
42 def setUp(self):
40 def setUp(self):
41+ if model() == 'Desktop':
42+ self.skipTest('Test cannot be run on the desktop.')
43 super(ApplicationLifecycleTests, self).setUp()
43 super(ApplicationLifecycleTests, self).setUp()
44− if model() == "Desktop":
45− self.skipTest("Test cannot be run on the desktop.")
47 def swipe_screen_from_right(self):
45 def swipe_screen_from_right(self):
48 width = self.main_window.width
46 width = self.main_window.width
@@ -55,142 +53,65 @@ class ApplicationLifecycleTests(UnityTestCase):
55 logger.info("Swiping screen from the right edge")
53 logger.info("Swiping screen from the right edge")
56 self.touch.drag(start_x, start_y, end_x, end_y)
54 self.touch.drag(start_x, start_y, end_x, end_y)
58− def swipe_screen_from_left(self):
56+ def launch_fake_app(self):
59− width = self.main_window.width
57+ _, desktop_file_path = self.create_test_application()
60− height = self.main_window.height
58+ desktop_file_name = os.path.basename(desktop_file_path)
61− start_x = 0
59+ application_name, _ = os.path.splitext(desktop_file_name)
62− start_y = int(height/2)
60+ self.launch_upstart_application(application_name)
63− end_x = width
61+ return application_name
66− logger.info("Swiping screen from the left edge")
67− self.touch.drag(start_x, start_y, end_x, end_y)
69− def _launch_app_directly(self, app_name):
70− """Launches the application *app_name*
72− Assumes that the desktop file resides at:
73− /usr/share/applications/{app_name}.desktop
76− desktop_file = "--desktop_file_hint="\
77− "/usr/share/applications/{app_name}.desktop".format(
80− return self.launch_test_application(
83− "--stage_hint=main_stage",
87− def _launch_app(self, app_name):
88− """Launches the application *app_name* via upstart."""
89− command = ['initctl', '--quiet', 'start', 'application',
90− 'APP_ID=%s' % app_name]
91− subprocess.check_call(command)
93− command = ['pkill', '-f', '-9', app_name]
94− self.addCleanup(subprocess.call, command)
97 def test_can_launch_application(self):
63 def test_can_launch_application(self):
98 """Must be able to launch an application."""
64 """Must be able to launch an application."""
99− unity_proxy = self.launch_unity()
65+ application_name = self.launch_fake_app()
100− unlock_unity(unity_proxy)
66+ self.assert_current_focused_application(application_name)
102− self._launch_app("messaging-app")
104− self.main_window.get_current_focused_app_id(),
105− Eventually(Equals("messaging-app"))
108− @disable_qml_mocking
109 def test_can_launch_multiple_applications(self):
68 def test_can_launch_multiple_applications(self):
110 """A second application launched must be focused."""
69 """A second application launched must be focused."""
111− unity_proxy = self.launch_unity()
70+ application1_name = self.launch_fake_app()
112− unlock_unity(unity_proxy)
71+ self.assert_current_focused_application(application1_name)
114− self._launch_app("messaging-app")
73+ application2_name = self.launch_fake_app()
115− self.assertThat(
74+ self.assertFalse(application1_name == application2_name)
116− self.main_window.get_current_focused_app_id(),
75+ self.assert_current_focused_application(application2_name)
117− Eventually(Equals("messaging-app"))
76+
120− self._launch_app("address-book-app")
122− self.main_window.get_current_focused_app_id(),
123− Eventually(Equals("address-book-app"))
126− @disable_qml_mocking
127 def test_app_moves_from_unfocused_to_focused(self):
77 def test_app_moves_from_unfocused_to_focused(self):
128 """An application that is in the unfocused state must be able to be
78 """An application that is in the unfocused state must be able to be
129 brought back to the focused state.
79 brought back to the focused state.
132− unity_proxy = self.launch_unity()
82+ application1_name = self.launch_fake_app()
133− unlock_unity(unity_proxy)
83+ self.assert_current_focused_application(application1_name)
135− self._launch_app("messaging-app")
85+ application2_name = self.launch_fake_app()
136− self.assertThat(
86+ self.assertFalse(application1_name == application2_name)
137− self.main_window.get_current_focused_app_id(),
87+ self.assert_current_focused_application(application2_name)
138− Eventually(Equals("messaging-app"))
141− # FIXME: this should be able to launch via upstart. Bug #1273844
142− self._launch_app_directly("address-book-app")
144− self.main_window.get_current_focused_app_id(),
145− Eventually(Equals("address-book-app"))
148 self.swipe_screen_from_right()
89 self.swipe_screen_from_right()
150− self.assertThat(
91+ self.assert_current_focused_application(application1_name)
151− self.main_window.get_current_focused_app_id(),
152− Eventually(Equals("messaging-app"))
155− @disable_qml_mocking
156 def test_greeter_hides_on_app_open(self):
93 def test_greeter_hides_on_app_open(self):
157 """Greeter should hide when an app is opened"""
94 """Greeter should hide when an app is opened"""
158− unity_proxy = self.launch_unity()
95+ process_helpers.lock_unity()
159 greeter = self.main_window.get_greeter()
96 greeter = self.main_window.get_greeter()
160 self.assertThat(greeter.created, Eventually(Equals(True)))
97 self.assertThat(greeter.created, Eventually(Equals(True)))
162− self._launch_app("messaging-app")
99+ application_name = self.launch_fake_app()
163 self.assertThat(greeter.created, Eventually(Equals(False)))
100 self.assertThat(greeter.created, Eventually(Equals(False)))
164− self.assertThat(
101+ self.assert_current_focused_application(application_name)
165− self.main_window.get_current_focused_app_id(),
166− Eventually(Equals("messaging-app"))
169− @disable_qml_mocking
170 def test_greeter_hides_on_app_focus(self):
103 def test_greeter_hides_on_app_focus(self):
171 """Greeter should hide when an app is re-focused"""
104 """Greeter should hide when an app is re-focused"""
172− unity_proxy = self.launch_unity()
105+ application_name = self.launch_fake_app()
173− greeter = self.main_window.get_greeter()
106+ self.assert_current_focused_application(application_name)
174− unlock_unity(unity_proxy)
176− self._launch_app("messaging-app")
108+ self.main_window.show_dash_swiping()
177− self.assertThat(
109+ self.assert_current_focused_application('')
178− self.main_window.get_current_focused_app_id(),
179− Eventually(Equals("messaging-app"))
182− self.swipe_screen_from_left()
111+ process_helpers.lock_unity()
184− self.main_window.get_current_focused_app_id(),
112+ greeter = self.main_window.get_greeter()
185− Eventually(Equals(''))
189 self.assertThat(greeter.created, Eventually(Equals(True)))
113 self.assertThat(greeter.created, Eventually(Equals(True)))
191− self._launch_app("messaging-app")
115+ self.launch_upstart_application(application_name)
192 self.assertThat(greeter.created, Eventually(Equals(False)))
116 self.assertThat(greeter.created, Eventually(Equals(False)))
193− self.assertThat(
117+ self.assert_current_focused_application(application_name)
194− self.main_window.get_current_focused_app_id(),
195− Eventually(Equals("messaging-app"))