Unity 8
test_rotation.py
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Unity Autopilot Test Suite
4 # Copyright (C) 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 shell-rotation"""
21 
22 from autopilot.platform import model
23 from unity8 import (
24  fixture_setup,
25  process_helpers
26 )
27 from unity8.shell import tests
28 import logging
29 from testtools.matchers import Equals
30 from autopilot.matchers import Eventually
31 
32 logger = logging.getLogger(__name__)
33 
34 
36  """Base class for all shell-rotation tests that provides helper methods."""
37 
38  def setUp(self):
39  if model() == 'Desktop':
40  self.skipTest('Test cannot be run on the desktop.')
41  super().setUp()
42  self._qml_mock_enabled = False
43  self._data_dirs_mock_enabled = False
44 
45  def _assert_change_of_orientation_and_angle(self):
46  self.assertThat(self.shell_proxy.orientation,
47  Eventually(Equals(self.orientation)))
48  self.assertThat(self.shell_proxy.orientationAngle,
49  Eventually(Equals(self.angle)))
50 
51 
52 class TestFakeSensor(RotationBase):
53  scenarios = [('top up', {'action': 'top_up', 'orientation': 1}),
54  ('right up', {'action': 'right_up', 'orientation': 8}),
55  ('top down', {'action': 'top_down', 'orientation': 4}),
56  ('left up', {'action': 'left_up', 'orientation': 2})]
57 
58  def test_fake_sensor(self):
59  unity_with_sensors = fixture_setup.LaunchUnityWithFakeSensors()
60  self.useFixture(unity_with_sensors)
61  process_helpers.unlock_unity()
62  fake_sensors = unity_with_sensors.fake_sensors
63  o_proxy = unity_with_sensors.main_win.select_single('OrientedShell')
64 
65  fake_sensors.set_orientation(self.action)
66  self.assertThat(o_proxy.physicalOrientation,
67  Eventually(Equals(self.orientation), timeout=15))
68 
69 
70 class TestRotationWithApp(RotationBase):
71  scenarios = [
72  ('top up, angle 0',
73  {'action': 'top_up', 'orientation': 1, 'angle': 0}),
74  ('right up, angle 90',
75  {'action': 'right_up', 'orientation': 8, 'angle': 90}),
76  ('top down, angle 180',
77  {'action': 'top_down', 'orientation': 4, 'angle': 180}),
78  ('left up, angle 270',
79  {'action': 'left_up', 'orientation': 2, 'angle': 270})]
80 
81  def test_rotation_with_webbrowser_app(self):
82  """Do an orientation-change and verify that an app and the shell
83  adapted correctly"""
84 
85  unity_with_sensors = fixture_setup.LaunchUnityWithFakeSensors()
86  self.useFixture(unity_with_sensors)
87  process_helpers.unlock_unity()
88  fake_sensors = unity_with_sensors.fake_sensors
89  o_proxy = unity_with_sensors.main_win.select_single('OrientedShell')
90  self.shell_proxy = unity_with_sensors.main_win.select_single('Shell')
91 
92  # launch an application
93  self.launch_upstart_application('webbrowser-app')
94  unity_with_sensors.main_win.show_dash_from_launcher()
95  unity_with_sensors.main_win.launch_application('webbrowser-app')
96 
97  # skip test early, if device doesn't support a certain orientation
98  if not (self.shell_proxy.orientation & o_proxy.supportedOrientations):
99  self.skipTest('unsupported orientation ' + self.action)
100 
101  self.assertThat(
102  unity_with_sensors.main_win.get_current_focused_app_id(),
103  Eventually(Equals('webbrowser-app')))
104 
105  # get default orientation and angle
106  self.orientation = self.shell_proxy.orientation
107  self.angle = self.shell_proxy.orientationAngle
108 
109  # check if fake sensors affect orientation and angle
110  fake_sensors.set_orientation(self.action)
111  self.assertThat(o_proxy.physicalOrientation,
112  Eventually(Equals(self.orientation), timeout=15))