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()
94 greeter = self.main_window.get_greeter()
95 self.assertThat(greeter.created, Eventually(Equals(
True)))
97 application_name = self.launch_fake_app()
98 greeter.wait_swiped_away()
99 process_helpers.unlock_unity()
100 self.assert_current_focused_application(application_name)
102 def test_greeter_hides_on_app_focus(self):
103 """Greeter should hide when an app is re-focused"""
104 application_name = self.launch_fake_app()
105 self.assert_current_focused_application(application_name)
107 self.main_window.show_dash_swiping()
108 self.assert_current_focused_application(
'unity8-dash')
110 process_helpers.lock_unity()
111 greeter = self.main_window.get_greeter()
112 self.assertThat(greeter.created, Eventually(Equals(
True)))
114 self.launch_upstart_application(application_name)
115 greeter.wait_swiped_away()
116 process_helpers.unlock_unity()
117 self.assert_current_focused_application(application_name)
119 def test_click_dash_icon_must_unfocus_application(self):
120 application_name = self.launch_fake_app()
121 self.assert_current_focused_application(application_name)
123 self.main_window.show_dash_from_launcher()
125 self.assert_current_focused_application(
'unity8-dash')
127 def test_click_app_icon_on_dash_must_focus_it(self):
128 application_name = self.launch_fake_app()
129 self.main_window.show_dash_from_launcher()
131 self.main_window.launch_application(application_name)
132 self.assert_current_focused_application(application_name)