20 """Tests for the application lifecycle."""
26 from autopilot.platform
import model
27 from autopilot.application
import _launcher
29 from unity8
import process_helpers
33 logger = logging.getLogger(__name__)
36 class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
39 if model() ==
'Desktop':
40 self.skipTest(
'Test cannot be run on the desktop.')
43 def swipe_screen_from_right(self):
44 width = self.main_window.width
45 height = self.main_window.height
47 start_y = int(height/2)
48 end_x = int(width*3/4)
51 logger.info(
"Swiping screen from the right edge")
52 self.main_window.pointing_device.drag(start_x, start_y, end_x, end_y)
54 def launch_fake_app(self):
55 _, desktop_file_path = self.create_test_application()
56 desktop_file_name = os.path.basename(desktop_file_path)
57 application_name, _ = os.path.splitext(desktop_file_name)
58 self.launch_upstart_application(application_name)
59 return application_name
61 def test_can_launch_application(self):
62 """Must be able to launch an application."""
63 application_name = self.launch_fake_app()
64 self.assert_current_focused_application(application_name)
66 def test_can_launch_multiple_applications(self):
67 """A second application launched must be focused."""
68 application1_name = self.launch_fake_app()
69 self.assert_current_focused_application(application1_name)
71 application2_name = self.launch_fake_app()
72 self.assertFalse(application1_name == application2_name)
73 self.assert_current_focused_application(application2_name)
75 def test_app_moves_from_unfocused_to_focused(self):
76 """An application that is in the unfocused state must be able to be
77 brought back to the focused state.
80 application1_name = self.launch_fake_app()
81 self.assert_current_focused_application(application1_name)
83 application2_name = self.launch_fake_app()
84 self.assertFalse(application1_name == application2_name)
85 self.assert_current_focused_application(application2_name)
87 self.swipe_screen_from_right()
89 self.assert_current_focused_application(application1_name)
91 def test_greeter_hides_on_app_open(self):
92 """Greeter should hide when an app is opened"""
93 process_helpers.lock_unity()
98 def unlock_thread_worker(greeter):
99 greeter.wait_swiped_away()
100 process_helpers.unlock_unity()
101 greeter.created.wait_for(
False)
103 greeter = self.main_window.get_greeter()
104 unlock_thread = threading.Thread(
105 target=unlock_thread_worker, args=(greeter,))
106 unlock_thread.start()
107 application_name = self.launch_fake_app()
108 unlock_thread.join(10)
110 self.assert_current_focused_application(application_name)
112 def test_greeter_hides_on_app_focus(self):
113 """Greeter should hide when an app is re-focused"""
114 application_name = self.launch_fake_app()
115 self.assert_current_focused_application(application_name)
117 self.main_window.show_dash_swiping()
118 self.assert_current_focused_application(
'unity8-dash')
120 process_helpers.lock_unity()
122 self.launch_upstart_application(application_name, [], _launcher.AlreadyLaunchedUpstartLauncher)
123 greeter = self.main_window.get_greeter()
124 greeter.wait_swiped_away()
125 process_helpers.unlock_unity()
126 self.assert_current_focused_application(application_name)
128 def test_click_dash_icon_must_unfocus_application(self):
129 application_name = self.launch_fake_app()
130 self.assert_current_focused_application(application_name)
132 self.main_window.show_dash_from_launcher()
134 self.assert_current_focused_application(
'unity8-dash')
136 def test_click_app_icon_on_dash_must_focus_it(self):
137 application_name = self.launch_fake_app()
138 self.main_window.show_dash_from_launcher()
140 self.main_window.launch_application(application_name)
141 self.assert_current_focused_application(application_name)