@@ -21,28 +21,26 @@
2121
2222from __future__ import absolute_import
2323
24−from unity8.process_helpers import lock_unity, unlock_unity
25−from unity8.shell import disable_qml_mocking
26−from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
24+import logging
25+import os
2726
2827from autopilot.matchers import Eventually
2928from autopilot.platform import model
30−from testtools.matchers import Equals, NotEquals
29+from testtools.matchers import Equals
3130
32−import logging
33−import subprocess
31+from unity8 import process_helpers
32+from unity8.application_lifecycle import tests
3433
35−logger = logging.getLogger(__name__)
3634
35+logger = logging.getLogger(__name__)
3736
38−class ApplicationLifecycleTests(UnityTestCase):
3937
40− scenarios = _get_device_emulation_scenarios()
38+class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
4139
4240 def setUp(self):
41+ if model() == 'Desktop':
42+ self.skipTest('Test cannot be run on the desktop.')
4343 super(ApplicationLifecycleTests, self).setUp()
44− if model() == "Desktop":
45− self.skipTest("Test cannot be run on the desktop.")
4644
4745 def swipe_screen_from_right(self):
4846 width = self.main_window.width
@@ -55,142 +53,65 @@ class ApplicationLifecycleTests(UnityTestCase):
5553 logger.info("Swiping screen from the right edge")
5654 self.touch.drag(start_x, start_y, end_x, end_y)
5755
58− def swipe_screen_from_left(self):
59− width = self.main_window.width
60− height = self.main_window.height
61− start_x = 0
62− start_y = int(height/2)
63− end_x = width
64− end_y = start_y
65−
66− logger.info("Swiping screen from the left edge")
67− self.touch.drag(start_x, start_y, end_x, end_y)
68−
69− def _launch_app_directly(self, app_name):
70− """Launches the application *app_name*
71−
72− Assumes that the desktop file resides at:
73− /usr/share/applications/{app_name}.desktop
56+ def launch_fake_app(self):
57+ _, desktop_file_path = self.create_test_application()
58+ desktop_file_name = os.path.basename(desktop_file_path)
59+ application_name, _ = os.path.splitext(desktop_file_name)
60+ self.launch_upstart_application(application_name)
61+ return application_name
7462
75− """
76− desktop_file = "--desktop_file_hint="\
77− "/usr/share/applications/{app_name}.desktop".format(
78− app_name=app_name
79− )
80− return self.launch_test_application(
81− app_name,
82− desktop_file,
83− "--stage_hint=main_stage",
84− app_type='qt'
85− )
86−
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)
92−
93− command = ['pkill', '-f', '-9', app_name]
94− self.addCleanup(subprocess.call, command)
95−
96− @disable_qml_mocking
9763 def test_can_launch_application(self):
9864 """Must be able to launch an application."""
99− unity_proxy = self.launch_unity()
100− unlock_unity(unity_proxy)
65+ application_name = self.launch_fake_app()
66+ self.assert_current_focused_application(application_name)
10167
102− self._launch_app("messaging-app")
103− self.assertThat(
104− self.main_window.get_current_focused_app_id(),
105− Eventually(Equals("messaging-app"))
106− )
107−
108− @disable_qml_mocking
10968 def test_can_launch_multiple_applications(self):
11069 """A second application launched must be focused."""
111− unity_proxy = self.launch_unity()
112− unlock_unity(unity_proxy)
113−
114− self._launch_app("messaging-app")
115− self.assertThat(
116− self.main_window.get_current_focused_app_id(),
117− Eventually(Equals("messaging-app"))
118− )
119−
120− self._launch_app("address-book-app")
121− self.assertThat(
122− self.main_window.get_current_focused_app_id(),
123− Eventually(Equals("address-book-app"))
124− )
125−
126− @disable_qml_mocking
70+ application1_name = self.launch_fake_app()
71+ self.assert_current_focused_application(application1_name)
72+
73+ application2_name = self.launch_fake_app()
74+ self.assertFalse(application1_name == application2_name)
75+ self.assert_current_focused_application(application2_name)
76+
12777 def test_app_moves_from_unfocused_to_focused(self):
12878 """An application that is in the unfocused state must be able to be
12979 brought back to the focused state.
13080
13181 """
132− unity_proxy = self.launch_unity()
133− unlock_unity(unity_proxy)
134−
135− self._launch_app("messaging-app")
136− self.assertThat(
137− self.main_window.get_current_focused_app_id(),
138− Eventually(Equals("messaging-app"))
139− )
140−
141− # FIXME: this should be able to launch via upstart. Bug #1273844
142− self._launch_app_directly("address-book-app")
143− self.assertThat(
144− self.main_window.get_current_focused_app_id(),
145− Eventually(Equals("address-book-app"))
146− )
82+ application1_name = self.launch_fake_app()
83+ self.assert_current_focused_application(application1_name)
84+
85+ application2_name = self.launch_fake_app()
86+ self.assertFalse(application1_name == application2_name)
87+ self.assert_current_focused_application(application2_name)
14788
14889 self.swipe_screen_from_right()
14990
150− self.assertThat(
151− self.main_window.get_current_focused_app_id(),
152− Eventually(Equals("messaging-app"))
153− )
91+ self.assert_current_focused_application(application1_name)
15492
155− @disable_qml_mocking
15693 def test_greeter_hides_on_app_open(self):
15794 """Greeter should hide when an app is opened"""
158− unity_proxy = self.launch_unity()
95+ process_helpers.lock_unity()
15996 greeter = self.main_window.get_greeter()
16097 self.assertThat(greeter.created, Eventually(Equals(True)))
16198
162− self._launch_app("messaging-app")
99+ application_name = self.launch_fake_app()
163100 self.assertThat(greeter.created, Eventually(Equals(False)))
164− self.assertThat(
165− self.main_window.get_current_focused_app_id(),
166− Eventually(Equals("messaging-app"))
167− )
101+ self.assert_current_focused_application(application_name)
168102
169− @disable_qml_mocking
170103 def test_greeter_hides_on_app_focus(self):
171104 """Greeter should hide when an app is re-focused"""
172− unity_proxy = self.launch_unity()
173− greeter = self.main_window.get_greeter()
174− unlock_unity(unity_proxy)
105+ application_name = self.launch_fake_app()
106+ self.assert_current_focused_application(application_name)
175107
176− self._launch_app("messaging-app")
177− self.assertThat(
178− self.main_window.get_current_focused_app_id(),
179− Eventually(Equals("messaging-app"))
180− )
108+ self.main_window.show_dash_swiping()
109+ self.assert_current_focused_application('')
181110
182− self.swipe_screen_from_left()
183− self.assertThat(
184− self.main_window.get_current_focused_app_id(),
185− Eventually(Equals(''))
186− )
187−
188− lock_unity()
111+ process_helpers.lock_unity()
112+ greeter = self.main_window.get_greeter()
189113 self.assertThat(greeter.created, Eventually(Equals(True)))
190114
191− self._launch_app("messaging-app")
115+ self.launch_upstart_application(application_name)
192116 self.assertThat(greeter.created, Eventually(Equals(False)))
193− self.assertThat(
194− self.main_window.get_current_focused_app_id(),
195− Eventually(Equals("messaging-app"))
196− )
117+ self.assert_current_focused_application(application_name)