@@ -21,27 +21,23 @@
2121
2222from __future__ import absolute_import
2323
24−from unity8.process_helpers import 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
28−from autopilot.matchers import Eventually
2927from autopilot.platform import model
30−from testtools.matchers import Equals, NotEquals
3128
32−import logging
29+from unity8.application_lifecycle import tests
3330
34−logger = logging.getLogger(__name__)
3531
32+logger = logging.getLogger(__name__)
3633
37−class ApplicationLifecycleTests(UnityTestCase):
3834
39− scenarios = _get_device_emulation_scenarios()
35+class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
4036
4137 def setUp(self):
38+ if model() == 'Desktop':
39+ self.skipTest('Test cannot be run on the desktop.')
4240 super(ApplicationLifecycleTests, self).setUp()
43− if model() == "Desktop":
44− self.skipTest("Test cannot be run on the desktop.")
4541
4642 def swipe_screen_from_right(self):
4743 width = self.main_window.width
@@ -54,80 +50,39 @@ class ApplicationLifecycleTests(UnityTestCase):
5450 logger.info("Swiping screen from the right edge")
5551 self.touch.drag(start_x, start_y, end_x, end_y)
5652
57− def _launch_app(self, app_name):
58− """Launches the application *app_name*
59−
60− Assumes that the desktop file resides at:
61− /usr/share/applications/{app_name}.desktop
53+ def launch_fake_app(self):
54+ _, desktop_file_path = self.create_test_application()
55+ desktop_file_name = os.path.basename(desktop_file_path)
56+ application_name, _ = os.path.splitext(desktop_file_name)
57+ self.launch_upstart_application(application_name)
58+ return application_name
6259
63− """
64− desktop_file = "--desktop_file_hint="\
65− "/usr/share/applications/{app_name}.desktop".format(
66− app_name=app_name
67− )
68− return self.launch_test_application(
69− app_name,
70− desktop_file,
71− "--stage_hint=main_stage",
72− app_type='qt'
73− )
74−
75− @disable_qml_mocking
7660 def test_can_launch_application(self):
7761 """Must be able to launch an application."""
78− unity_proxy = self.launch_unity()
79− unlock_unity(unity_proxy)
62+ application_name = self.launch_fake_app()
63+ self.assert_current_focused_application(application_name)
8064
81− app = self._launch_app("messaging-app")
82−
83− self.assertThat(app, NotEquals(None))
84− self.assertThat(
85− self.main_window.get_current_focused_app_id(),
86− Eventually(Equals("messaging-app"))
87− )
88−
89− @disable_qml_mocking
9065 def test_can_launch_multiple_applications(self):
9166 """A second application launched must be focused."""
92− unity_proxy = self.launch_unity()
93− unlock_unity(unity_proxy)
94−
95− self._launch_app("messaging-app")
96− self.assertThat(
97− self.main_window.get_current_focused_app_id(),
98− Eventually(Equals("messaging-app"))
99− )
100−
101− self._launch_app("address-book-app")
102− self.assertThat(
103− self.main_window.get_current_focused_app_id(),
104− Eventually(Equals("address-book-app"))
105− )
106−
107− @disable_qml_mocking
67+ application1_name = self.launch_fake_app()
68+ self.assert_current_focused_application(application1_name)
69+
70+ application2_name = self.launch_fake_app()
71+ self.assertFalse(application1_name == application2_name)
72+ self.assert_current_focused_application(application2_name)
73+
10874 def test_app_moves_from_unfocused_to_focused(self):
10975 """An application that is in the unfocused state must be able to be
11076 brought back to the focused state.
11177
11278 """
113− unity_proxy = self.launch_unity()
114− unlock_unity(unity_proxy)
115−
116− self._launch_app("messaging-app")
117− self.assertThat(
118− self.main_window.get_current_focused_app_id(),
119− Eventually(Equals("messaging-app"))
120− )
79+ application1_name = self.launch_fake_app()
80+ self.assert_current_focused_application(application1_name)
12181
122− self._launch_app("address-book-app")
123− self.assertThat(
124− self.main_window.get_current_focused_app_id(),
125− Eventually(Equals("address-book-app"))
126− )
82+ application2_name = self.launch_fake_app()
83+ self.assertFalse(application1_name == application2_name)
84+ self.assert_current_focused_application(application2_name)
12785
12886 self.swipe_screen_from_right()
12987
130− self.assertThat(
131− self.main_window.get_current_focused_app_id(),
132− Eventually(Equals("messaging-app"))
133− )
88+ self.assert_current_focused_application(application1_name)