20 """Tests for the application lifecycle."""
22 from __future__
import absolute_import
27 from autopilot.matchers
import Eventually
28 from autopilot.platform
import model
29 from testtools.matchers
import Equals
31 from unity8
import process_helpers
35 logger = logging.getLogger(__name__)
38 class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
41 if model() ==
'Desktop':
42 self.skipTest(
'Test cannot be run on the desktop.')
43 super(ApplicationLifecycleTests, self).setUp()
45 def swipe_screen_from_right(self):
46 width = self.main_window.width
47 height = self.main_window.height
49 start_y = int(height/2)
50 end_x = int(width*3/4)
53 logger.info(
"Swiping screen from the right edge")
54 self.touch.drag(start_x, start_y, end_x, end_y)
56 def launch_fake_app(self):
57 _, desktop_file_path = self.create_test_application()
58 desktop_file_name = os.path.basename(desktop_file_path)
59 application_name, _ = os.path.splitext(desktop_file_name)
60 self.launch_upstart_application(application_name)
61 return application_name
63 def test_can_launch_application(self):
64 """Must be able to launch an application."""
65 application_name = self.launch_fake_app()
66 self.assert_current_focused_application(application_name)
68 def test_can_launch_multiple_applications(self):
69 """A second application launched must be focused."""
70 application1_name = self.launch_fake_app()
71 self.assert_current_focused_application(application1_name)
73 application2_name = self.launch_fake_app()
74 self.assertFalse(application1_name == application2_name)
75 self.assert_current_focused_application(application2_name)
77 def test_app_moves_from_unfocused_to_focused(self):
78 """An application that is in the unfocused state must be able to be
79 brought back to the focused state.
82 application1_name = self.launch_fake_app()
83 self.assert_current_focused_application(application1_name)
85 application2_name = self.launch_fake_app()
86 self.assertFalse(application1_name == application2_name)
87 self.assert_current_focused_application(application2_name)
89 self.swipe_screen_from_right()
91 self.assert_current_focused_application(application1_name)
93 def test_greeter_hides_on_app_open(self):
94 """Greeter should hide when an app is opened"""
95 process_helpers.lock_unity()
96 greeter = self.main_window.get_greeter()
97 self.assertThat(greeter.created, Eventually(Equals(
True)))
99 application_name = self.launch_fake_app()
100 greeter.wait_swiped_away()
101 process_helpers.unlock_unity()
102 self.assert_current_focused_application(application_name)
104 def test_greeter_hides_on_app_focus(self):
105 """Greeter should hide when an app is re-focused"""
106 application_name = self.launch_fake_app()
107 self.assert_current_focused_application(application_name)
109 self.main_window.show_dash_swiping()
110 self.assert_current_focused_application(
'unity8-dash')
112 process_helpers.lock_unity()
113 greeter = self.main_window.get_greeter()
114 self.assertThat(greeter.created, Eventually(Equals(
True)))
116 self.launch_upstart_application(application_name)
117 greeter.wait_swiped_away()
118 process_helpers.unlock_unity()
119 self.assert_current_focused_application(application_name)
121 def test_click_dash_icon_must_unfocus_application(self):
122 application_name = self.launch_fake_app()
123 self.assert_current_focused_application(application_name)
125 self.main_window.show_dash_from_launcher()
127 self.assert_current_focused_application(
'unity8-dash')
129 def test_click_app_icon_on_dash_must_focus_it(self):
130 application_name = self.launch_fake_app()
131 self.main_window.show_dash_from_launcher()
133 self.main_window.launch_application(application_name)
134 self.assert_current_focused_application(application_name)