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 
25 from autopilot.matchers import Eventually
26 from autopilot.platform import model
27 from testtools.matchers import Equals
28 
29 from unity8 import process_helpers
30 from unity8.application_lifecycle import tests
31 
32 
33 logger = logging.getLogger(__name__)
34 
35 
36 class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
37 
38  def setUp(self):
39  if model() == 'Desktop':
40  self.skipTest('Test cannot be run on the desktop.')
41  super().setUp()
42 
43  def swipe_screen_from_right(self):
44  width = self.main_window.width
45  height = self.main_window.height
46  start_x = width
47  start_y = int(height/2)
48  end_x = int(width*3/4)
49  end_y = start_y
50 
51  logger.info("Swiping screen from the right edge")
52  self.touch.drag(start_x, start_y, end_x, end_y)
53 
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
60 
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)
65 
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)
70 
71  application2_name = self.launch_fake_app()
72  self.assertFalse(application1_name == application2_name)
73  self.assert_current_focused_application(application2_name)
74 
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.
78 
79  """
80  application1_name = self.launch_fake_app()
81  self.assert_current_focused_application(application1_name)
82 
83  application2_name = self.launch_fake_app()
84  self.assertFalse(application1_name == application2_name)
85  self.assert_current_focused_application(application2_name)
86 
87  self.swipe_screen_from_right()
88 
89  self.assert_current_focused_application(application1_name)
90 
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)))
96 
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)
101 
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)
106 
107  self.main_window.show_dash_swiping()
108  self.assert_current_focused_application('unity8-dash')
109 
110  process_helpers.lock_unity()
111  greeter = self.main_window.get_greeter()
112  self.assertThat(greeter.created, Eventually(Equals(True)))
113 
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)
118 
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)
122 
123  self.main_window.show_dash_from_launcher()
124 
125  self.assert_current_focused_application('unity8-dash')
126 
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()
130 
131  self.main_window.launch_application(application_name)
132  self.assert_current_focused_application(application_name)