20 """Tests for the application lifecycle."""
25 from autopilot.matchers
import Eventually
26 from autopilot.platform
import model
27 from testtools.matchers
import Equals
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.touch.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()
95 application_name = self.launch_fake_app()
96 greeter = self.main_window.get_greeter()
97 greeter.wait_swiped_away()
98 process_helpers.unlock_unity()
99 self.assert_current_focused_application(application_name)
101 def test_greeter_hides_on_app_focus(self):
102 """Greeter should hide when an app is re-focused"""
103 application_name = self.launch_fake_app()
104 self.assert_current_focused_application(application_name)
106 self.main_window.show_dash_swiping()
107 self.assert_current_focused_application(
'unity8-dash')
109 process_helpers.lock_unity()
111 self.launch_upstart_application(application_name)
112 greeter = self.main_window.get_greeter()
113 greeter.wait_swiped_away()
114 process_helpers.unlock_unity()
115 self.assert_current_focused_application(application_name)
117 def test_click_dash_icon_must_unfocus_application(self):
118 application_name = self.launch_fake_app()
119 self.assert_current_focused_application(application_name)
121 self.main_window.show_dash_from_launcher()
123 self.assert_current_focused_application(
'unity8-dash')
125 def test_click_app_icon_on_dash_must_focus_it(self):
126 application_name = self.launch_fake_app()
127 self.main_window.show_dash_from_launcher()
129 self.main_window.launch_application(application_name)
130 self.assert_current_focused_application(application_name)