Unity 8
test_application_lifecycle.py
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Unity Autopilot Test Suite
4 # Copyright (C) 2013, 2014, 2015 Canonical
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 
20 """Tests for the application lifecycle."""
21 
22 import logging
23 import os
24 import threading
25 
26 from autopilot.platform import model
27 
28 from unity8 import process_helpers
29 from unity8.application_lifecycle import tests
30 
31 
32 logger = logging.getLogger(__name__)
33 
34 
35 class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
36 
37  def setUp(self):
38  if model() == 'Desktop':
39  self.skipTest('Test cannot be run on the desktop.')
40  super().setUp()
41 
42  def swipe_screen_from_right(self):
43  width = self.main_window.width
44  height = self.main_window.height
45  start_x = width
46  start_y = int(height/2)
47  end_x = int(width*3/4)
48  end_y = start_y
49 
50  logger.info("Swiping screen from the right edge")
51  self.main_window.pointing_device.drag(start_x, start_y, end_x, end_y)
52 
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
59 
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)
64 
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)
69 
70  application2_name = self.launch_fake_app()
71  self.assertFalse(application1_name == application2_name)
72  self.assert_current_focused_application(application2_name)
73 
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.
77 
78  """
79  application1_name = self.launch_fake_app()
80  self.assert_current_focused_application(application1_name)
81 
82  application2_name = self.launch_fake_app()
83  self.assertFalse(application1_name == application2_name)
84  self.assert_current_focused_application(application2_name)
85 
86  self.swipe_screen_from_right()
87 
88  self.assert_current_focused_application(application1_name)
89 
90  def test_greeter_hides_on_app_open(self):
91  """Greeter should hide when an app is opened"""
92  process_helpers.lock_unity()
93 
94  # FIXME - this is because the device greeter uses a password.
95  # Need to be able to selectively enable mocks so that we can use the
96  # fake greeter.
97  def unlock_thread_worker(greeter):
98  greeter.wait_swiped_away()
99  process_helpers.unlock_unity()
100  greeter.created.wait_for(False)
101 
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)
108 
109  self.assert_current_focused_application(application_name)
110 
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)
115 
116  self.main_window.show_dash_swiping()
117  self.assert_current_focused_application('unity8-dash')
118 
119  process_helpers.lock_unity()
120 
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)
126 
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)
130 
131  self.main_window.show_dash_from_launcher()
132 
133  self.assert_current_focused_application('unity8-dash')
134 
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()
138 
139  self.main_window.launch_application(application_name)
140  self.assert_current_focused_application(application_name)