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 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 from __future__ import absolute_import
23 
24 import logging
25 import os
26 
27 from autopilot.matchers import Eventually
28 from autopilot.platform import model
29 from testtools.matchers import Equals
30 
31 from unity8 import process_helpers
32 from unity8.application_lifecycle import tests
33 
34 
35 logger = logging.getLogger(__name__)
36 
37 
38 class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
39 
40  def setUp(self):
41  if model() == 'Desktop':
42  self.skipTest('Test cannot be run on the desktop.')
43  super(ApplicationLifecycleTests, self).setUp()
44 
45  def swipe_screen_from_right(self):
46  width = self.main_window.width
47  height = self.main_window.height
48  start_x = width
49  start_y = int(height/2)
50  end_x = int(width*3/4)
51  end_y = start_y
52 
53  logger.info("Swiping screen from the right edge")
54  self.touch.drag(start_x, start_y, end_x, end_y)
55 
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
62 
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)
67 
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)
72 
73  application2_name = self.launch_fake_app()
74  self.assertFalse(application1_name == application2_name)
75  self.assert_current_focused_application(application2_name)
76 
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.
80 
81  """
82  application1_name = self.launch_fake_app()
83  self.assert_current_focused_application(application1_name)
84 
85  application2_name = self.launch_fake_app()
86  self.assertFalse(application1_name == application2_name)
87  self.assert_current_focused_application(application2_name)
88 
89  self.swipe_screen_from_right()
90 
91  self.assert_current_focused_application(application1_name)
92 
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)))
98 
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)
103 
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)
108 
109  self.main_window.show_dash_swiping()
110  self.assert_current_focused_application('unity8-dash')
111 
112  process_helpers.lock_unity()
113  greeter = self.main_window.get_greeter()
114  self.assertThat(greeter.created, Eventually(Equals(True)))
115 
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)
120 
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)
124 
125  self.main_window.show_dash_from_launcher()
126 
127  self.assert_current_focused_application('unity8-dash')
128 
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()
132 
133  self.main_window.launch_application(application_name)
134  self.assert_current_focused_application(application_name)