20 """Tests for the application lifecycle."""
26 from autopilot.platform
import model
28 from unity8
import process_helpers
32 logger = logging.getLogger(__name__)
35 class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
38 if model() ==
'Desktop':
39 self.skipTest(
'Test cannot be run on the desktop.')
42 def swipe_screen_from_right(self):
43 width = self.main_window.width
44 height = self.main_window.height
46 start_y = int(height/2)
47 end_x = int(width*3/4)
50 logger.info(
"Swiping screen from the right edge")
51 self.main_window.pointing_device.drag(start_x, start_y, end_x, end_y)
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
60 def test_can_launch_application(self):
61 """Must be able to launch an application."""
62 application_name = self.launch_fake_app()
63 self.assert_current_focused_application(application_name)
65 def test_can_launch_multiple_applications(self):
66 """A second application launched must be focused."""
67 application1_name = self.launch_fake_app()
68 self.assert_current_focused_application(application1_name)
70 application2_name = self.launch_fake_app()
71 self.assertFalse(application1_name == application2_name)
72 self.assert_current_focused_application(application2_name)
74 def test_app_moves_from_unfocused_to_focused(self):
75 """An application that is in the unfocused state must be able to be
76 brought back to the focused state.
79 application1_name = self.launch_fake_app()
80 self.assert_current_focused_application(application1_name)
82 application2_name = self.launch_fake_app()
83 self.assertFalse(application1_name == application2_name)
84 self.assert_current_focused_application(application2_name)
86 self.swipe_screen_from_right()
88 self.assert_current_focused_application(application1_name)
90 def test_greeter_hides_on_app_open(self):
91 """Greeter should hide when an app is opened"""
92 process_helpers.lock_unity()
97 def unlock_thread_worker(greeter):
98 greeter.wait_swiped_away()
99 process_helpers.unlock_unity()
100 greeter.created.wait_for(
False)
102 greeter = self.main_window.get_greeter()
103 unlock_thread = threading.Thread(
104 target=unlock_thread_worker, args=(greeter,))
105 unlock_thread.start()
106 application_name = self.launch_fake_app()
107 unlock_thread.join(10)
109 self.assert_current_focused_application(application_name)
111 def test_greeter_hides_on_app_focus(self):
112 """Greeter should hide when an app is re-focused"""
113 application_name = self.launch_fake_app()
114 self.assert_current_focused_application(application_name)
116 self.main_window.show_dash_swiping()
117 self.assert_current_focused_application(
'unity8-dash')
119 process_helpers.lock_unity()
121 self.launch_upstart_application(application_name)
122 greeter = self.main_window.get_greeter()
123 greeter.wait_swiped_away()
124 process_helpers.unlock_unity()
125 self.assert_current_focused_application(application_name)
127 def test_click_dash_icon_must_unfocus_application(self):
128 application_name = self.launch_fake_app()
129 self.assert_current_focused_application(application_name)
131 self.main_window.show_dash_from_launcher()
133 self.assert_current_focused_application(
'unity8-dash')
135 def test_click_app_icon_on_dash_must_focus_it(self):
136 application_name = self.launch_fake_app()
137 self.main_window.show_dash_from_launcher()
139 self.main_window.launch_application(application_name)
140 self.assert_current_focused_application(application_name)