1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2012 Canonical
3
# Authors: Marco Trevisan (TreviƱo)
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
9
from testtools.matchers import Equals
10
from time import sleep
12
from autopilot.tests import AutopilotTestCase
13
from autopilot.emulators.unity.shortcut_hint import ShortcutController
14
from autopilot.emulators.X11 import ScreenGeometry
17
class BaseShortcutHintTests(AutopilotTestCase):
18
"""Base class for the shortcut hint tests"""
21
super(BaseShortcutHintTests, self).setUp()
23
self.DEFAULT_WIDTH = 970;
24
self.DEFAULT_HEIGHT = 680;
26
self.shortcut_hint = self.get_shortcut_controller()
27
self.set_unity_option('shortcut_overlay', True)
28
self.skip_if_monitor_too_small()
31
def skip_if_monitor_too_small(self):
32
screen = ScreenGeometry();
33
monitor = screen.get_primary_monitor()
34
monitor_geo = screen.get_monitor_geometry(monitor);
35
monitor_w = monitor_geo[2];
36
monitor_h = monitor_geo[3];
37
launcher_width = self.launcher.get_launcher_for_monitor(monitor).geometry[2];
38
panel_height = 24 # TODO get it from panel
40
if ((monitor_w - launcher_width) <= self.DEFAULT_WIDTH or
41
(monitor_h - panel_height) <= self.DEFAULT_HEIGHT):
42
self.skipTest("This test requires a bigger screen, to show the ShortcutHint")
44
def get_shortcut_controller(self):
45
controllers = ShortcutController.get_all_instances()
46
self.assertThat(len(controllers), Equals(1))
49
def get_launcher(self):
50
# We could parameterise this so all tests run on both monitors (if MM is
51
# set up), but I think it's fine to just always use monitor primary monitor:
52
screen = ScreenGeometry();
53
monitor = screen.get_primary_monitor()
54
return self.launcher.get_launcher_for_monitor(monitor)
57
class ShortcutHintTests(BaseShortcutHintTests):
58
"""Test the shortcuthint."""
60
def test_shortcut_hint_reveal(self):
61
"""Test that the shortcut hint is shown."""
63
self.shortcut_hint.show()
64
self.addCleanup(self.shortcut_hint.hide)
67
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
69
def test_shortcut_hint_reveal_timeout(self):
70
"""Test that the shortcut hint is shown when it should."""
72
timeout = self.shortcut_hint.get_show_timeout()
73
self.shortcut_hint.show()
74
self.addCleanup(self.shortcut_hint.hide)
77
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
80
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
82
def test_shortcut_hint_unreveal(self):
83
"""Test that the shortcut hint is hidden when it should."""
85
self.shortcut_hint.show()
86
sleep(self.shortcut_hint.get_show_timeout())
87
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
90
self.shortcut_hint.hide()
92
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
94
def test_shortcut_hint_cancel(self):
95
"""Test that the shortcut hint is shown when requested."""
97
self.shortcut_hint.show()
98
self.addCleanup(self.shortcut_hint.hide)
99
sleep(self.shortcut_hint.get_show_timeout())
100
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
103
self.shortcut_hint.cancel()
105
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
106
sleep(self.shortcut_hint.get_show_timeout())
107
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
109
def test_shortcut_hint_geometries(self):
110
"""Test that the shortcut hint has the wanted geometries."""
112
self.shortcut_hint.show()
113
self.addCleanup(self.shortcut_hint.hide)
114
sleep(self.shortcut_hint.get_show_timeout())
116
(x, y, w, h) = self.shortcut_hint.get_geometry()
117
self.assertThat(w, Equals(self.DEFAULT_WIDTH))
118
self.assertThat(h, Equals(self.DEFAULT_HEIGHT))
121
class ShortcutHintInteractionsTests(BaseShortcutHintTests):
122
"""Test the shortcuthint interactions with other Unity parts."""
124
def test_shortcut_hint_hide_using_unity_shortcuts(self):
125
"""Test that the shortcut hints is hidden pressing unity shortcuts."""
127
self.shortcut_hint.show()
128
self.addCleanup(self.shortcut_hint.hide)
129
sleep(self.shortcut_hint.get_show_timeout())
131
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
132
self.keybinding_tap("expo/start")
133
self.addCleanup(self.keybinding, "expo/cancel")
135
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
137
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
139
def test_launcher_switcher_next_doesnt_show_shortcut_hint(self):
140
"""Moving forward in launcher switcher must not show the shortcut hint."""
142
switcher_timeout = self.shortcut_hint.get_show_timeout()
143
self.shortcut_hint.show()
144
self.addCleanup(self.shortcut_hint.hide)
146
sleep(switcher_timeout * 0.2)
147
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
149
self.keybinding("launcher/switcher/next")
152
self.keybinding("launcher/switcher/next")
153
self.addCleanup(self.keyboard.press_and_release, "Escape")
154
sleep(switcher_timeout * 2)
156
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
158
def test_launcher_switcher_prev_doesnt_show_shortcut_hint(self):
159
"""Moving backward in launcher switcher must not show the shortcut hint."""
161
switcher_timeout = self.shortcut_hint.get_show_timeout()
162
self.shortcut_hint.show()
163
self.addCleanup(self.shortcut_hint.hide)
165
sleep(switcher_timeout * 0.2)
166
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
168
self.keybinding("launcher/switcher/next")
169
self.addCleanup(self.keyboard.press_and_release, "Escape")
171
self.assertThat(self.launcher.key_nav_is_active, Equals(True))
173
self.keybinding("launcher/switcher/next")
176
self.keybinding("launcher/switcher/prev")
177
sleep(switcher_timeout)
179
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
181
def test_launcher_switcher_next_keeps_shortcut_hint(self):
182
"""Moving forward in launcher switcher after the shortcut hint has been
183
shown must keep the shortcuts there.
187
show_timeout = self.shortcut_hint.get_show_timeout()
188
self.shortcut_hint.show()
189
self.addCleanup(self.shortcut_hint.hide)
192
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
194
launcher = self.get_launcher()
195
launcher.start_switcher()
196
self.addCleanup(launcher.end_switcher, True)
198
self.assertThat(self.launcher.key_nav_is_active, Equals(True))
200
launcher.switcher_next()
202
launcher.switcher_next()
205
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
207
def test_launcher_switcher_prev_keeps_shortcut_hint(self):
208
"""Moving backward in launcher switcher after the shortcut hint has been
209
shown must keep the shortcuts there.
213
show_timeout = self.shortcut_hint.get_show_timeout()
214
self.shortcut_hint.show()
215
self.addCleanup(self.shortcut_hint.hide)
218
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
220
launcher = self.get_launcher()
221
launcher.start_switcher()
222
self.addCleanup(launcher.end_switcher, True)
224
self.assertThat(self.launcher.key_nav_is_active, Equals(True))
226
launcher.switcher_prev()
228
launcher.switcher_prev()
231
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
233
def test_launcher_switcher_cancel_doesnt_hide_shortcut_hint(self):
234
"""Cancelling the launcher switcher (by Escape) should not hide the
239
show_timeout = self.shortcut_hint.get_show_timeout()
240
self.shortcut_hint.show()
241
self.addCleanup(self.shortcut_hint.hide)
244
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
246
launcher = self.get_launcher()
247
launcher.start_switcher()
248
self.addCleanup(launcher.end_switcher, True)
250
self.assertThat(self.launcher.key_nav_is_active, Equals(True))
251
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
253
launcher.switcher_next()
255
self.keyboard.press_and_release("Escape")
258
self.assertThat(self.launcher.key_nav_is_active, Equals(False))
259
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
262
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
264
def test_launcher_switcher_and_shortcut_hint_escaping(self):
265
"""Cancelling the launcher switcher (by Escape) should not hide the
266
shortcut hint view, an extra keypress is needed.
270
show_timeout = self.shortcut_hint.get_show_timeout()
271
self.shortcut_hint.show()
272
self.addCleanup(self.shortcut_hint.hide)
275
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
277
launcher = self.get_launcher()
278
launcher.start_switcher()
279
self.addCleanup(launcher.end_switcher, True)
281
self.assertThat(self.launcher.key_nav_is_active, Equals(True))
282
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
284
launcher.switcher_next()
286
self.keyboard.press_and_release("Escape")
289
self.assertThat(self.launcher.key_nav_is_active, Equals(False))
290
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
293
self.shortcut_hint.cancel()
295
self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
297
def test_launcher_icons_hints_show_with_shortcut_hint(self):
298
"""When the shortcut hint is shown also the launcer's icons hints should
302
launcher = self.get_launcher()
303
self.shortcut_hint.show()
304
self.addCleanup(self.shortcut_hint.hide)
305
sleep(self.shortcut_hint.get_show_timeout())
308
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
309
self.assertThat(launcher.are_shortcuts_showing(), Equals(True))
311
def test_shortcut_hint_shows_with_launcher_icons_hints(self):
312
"""When the launcher icons hints are shown also the shortcut hint should
316
launcher = self.get_launcher()
317
launcher.keyboard_reveal_launcher()
318
self.addCleanup(launcher.keyboard_unreveal_launcher)
321
self.assertThat(launcher.are_shortcuts_showing(), Equals(True))
322
self.assertThat(self.shortcut_hint.is_visible(), Equals(True))