~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

Viewing changes to tests/autopilot/autopilot/tests/test_shortcut_hint.py

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2012 Canonical
 
3
# Authors: Marco Trevisan (TreviƱo)
 
4
#
 
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.
 
8
 
 
9
from testtools.matchers import Equals
 
10
from time import sleep
 
11
 
 
12
from autopilot.tests import AutopilotTestCase
 
13
from autopilot.emulators.unity.shortcut_hint import ShortcutController
 
14
from autopilot.emulators.X11 import ScreenGeometry
 
15
 
 
16
 
 
17
class BaseShortcutHintTests(AutopilotTestCase):
 
18
    """Base class for the shortcut hint tests"""
 
19
 
 
20
    def setUp(self):
 
21
        super(BaseShortcutHintTests, self).setUp()
 
22
 
 
23
        self.DEFAULT_WIDTH = 970;
 
24
        self.DEFAULT_HEIGHT = 680;
 
25
 
 
26
        self.shortcut_hint = self.get_shortcut_controller()
 
27
        self.set_unity_option('shortcut_overlay', True)
 
28
        self.skip_if_monitor_too_small()
 
29
        sleep(1)
 
30
 
 
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
 
39
 
 
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")
 
43
 
 
44
    def get_shortcut_controller(self):
 
45
        controllers = ShortcutController.get_all_instances()
 
46
        self.assertThat(len(controllers), Equals(1))
 
47
        return controllers[0]
 
48
 
 
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)
 
55
 
 
56
 
 
57
class ShortcutHintTests(BaseShortcutHintTests):
 
58
    """Test the shortcuthint."""
 
59
 
 
60
    def test_shortcut_hint_reveal(self):
 
61
        """Test that the shortcut hint is shown."""
 
62
        sleep(.5)
 
63
        self.shortcut_hint.show()
 
64
        self.addCleanup(self.shortcut_hint.hide)
 
65
        sleep(2)
 
66
 
 
67
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
68
 
 
69
    def test_shortcut_hint_reveal_timeout(self):
 
70
        """Test that the shortcut hint is shown when it should."""
 
71
        sleep(.5)
 
72
        timeout = self.shortcut_hint.get_show_timeout()
 
73
        self.shortcut_hint.show()
 
74
        self.addCleanup(self.shortcut_hint.hide)
 
75
 
 
76
        sleep(timeout/2.0)
 
77
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
78
 
 
79
        sleep(timeout/2.0)
 
80
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
81
 
 
82
    def test_shortcut_hint_unreveal(self):
 
83
        """Test that the shortcut hint is hidden when it should."""
 
84
        sleep(.5)
 
85
        self.shortcut_hint.show()
 
86
        sleep(self.shortcut_hint.get_show_timeout())
 
87
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
88
        sleep(.25)
 
89
 
 
90
        self.shortcut_hint.hide()
 
91
        sleep(.25)
 
92
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
93
 
 
94
    def test_shortcut_hint_cancel(self):
 
95
        """Test that the shortcut hint is shown when requested."""
 
96
        sleep(.5)
 
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))
 
101
        sleep(.25)
 
102
 
 
103
        self.shortcut_hint.cancel()
 
104
        sleep(.25)
 
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))
 
108
 
 
109
    def test_shortcut_hint_geometries(self):
 
110
        """Test that the shortcut hint has the wanted geometries."""
 
111
        sleep(.5)
 
112
        self.shortcut_hint.show()
 
113
        self.addCleanup(self.shortcut_hint.hide)
 
114
        sleep(self.shortcut_hint.get_show_timeout())
 
115
 
 
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))
 
119
 
 
120
 
 
121
class ShortcutHintInteractionsTests(BaseShortcutHintTests):
 
122
    """Test the shortcuthint interactions with other Unity parts."""
 
123
 
 
124
    def test_shortcut_hint_hide_using_unity_shortcuts(self):
 
125
        """Test that the shortcut hints is hidden pressing unity shortcuts."""
 
126
        sleep(.5)
 
127
        self.shortcut_hint.show()
 
128
        self.addCleanup(self.shortcut_hint.hide)
 
129
        sleep(self.shortcut_hint.get_show_timeout())
 
130
 
 
131
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
132
        self.keybinding_tap("expo/start")
 
133
        self.addCleanup(self.keybinding, "expo/cancel")
 
134
        sleep(.25)
 
135
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
136
        sleep(.25)
 
137
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
138
 
 
139
    def test_launcher_switcher_next_doesnt_show_shortcut_hint(self):
 
140
        """Moving forward in launcher switcher must not show the shortcut hint."""
 
141
        sleep(.5)
 
142
        switcher_timeout = self.shortcut_hint.get_show_timeout()
 
143
        self.shortcut_hint.show()
 
144
        self.addCleanup(self.shortcut_hint.hide)
 
145
 
 
146
        sleep(switcher_timeout * 0.2)
 
147
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
148
 
 
149
        self.keybinding("launcher/switcher/next")
 
150
        sleep(.25)
 
151
 
 
152
        self.keybinding("launcher/switcher/next")
 
153
        self.addCleanup(self.keyboard.press_and_release, "Escape")
 
154
        sleep(switcher_timeout * 2)
 
155
 
 
156
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
157
 
 
158
    def test_launcher_switcher_prev_doesnt_show_shortcut_hint(self):
 
159
        """Moving backward in launcher switcher must not show the shortcut hint."""
 
160
        sleep(.5)
 
161
        switcher_timeout = self.shortcut_hint.get_show_timeout()
 
162
        self.shortcut_hint.show()
 
163
        self.addCleanup(self.shortcut_hint.hide)
 
164
 
 
165
        sleep(switcher_timeout * 0.2)
 
166
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
167
 
 
168
        self.keybinding("launcher/switcher/next")
 
169
        self.addCleanup(self.keyboard.press_and_release, "Escape")
 
170
        sleep(.25)
 
171
        self.assertThat(self.launcher.key_nav_is_active, Equals(True))
 
172
 
 
173
        self.keybinding("launcher/switcher/next")
 
174
        sleep(.25)
 
175
 
 
176
        self.keybinding("launcher/switcher/prev")
 
177
        sleep(switcher_timeout)
 
178
 
 
179
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
180
 
 
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.
 
184
 
 
185
        """
 
186
        sleep(.5)
 
187
        show_timeout = self.shortcut_hint.get_show_timeout()
 
188
        self.shortcut_hint.show()
 
189
        self.addCleanup(self.shortcut_hint.hide)
 
190
 
 
191
        sleep(show_timeout)
 
192
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
193
 
 
194
        launcher = self.get_launcher()
 
195
        launcher.start_switcher()
 
196
        self.addCleanup(launcher.end_switcher, True)
 
197
        sleep(.25)
 
198
        self.assertThat(self.launcher.key_nav_is_active, Equals(True))
 
199
 
 
200
        launcher.switcher_next()
 
201
        sleep(.25)
 
202
        launcher.switcher_next()
 
203
        sleep(show_timeout)
 
204
 
 
205
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
206
 
 
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.
 
210
 
 
211
        """
 
212
        sleep(.5)
 
213
        show_timeout = self.shortcut_hint.get_show_timeout()
 
214
        self.shortcut_hint.show()
 
215
        self.addCleanup(self.shortcut_hint.hide)
 
216
 
 
217
        sleep(show_timeout)
 
218
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
219
 
 
220
        launcher = self.get_launcher()
 
221
        launcher.start_switcher()
 
222
        self.addCleanup(launcher.end_switcher, True)
 
223
        sleep(.25)
 
224
        self.assertThat(self.launcher.key_nav_is_active, Equals(True))
 
225
 
 
226
        launcher.switcher_prev()
 
227
        sleep(.25)
 
228
        launcher.switcher_prev()
 
229
        sleep(show_timeout)
 
230
 
 
231
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
232
 
 
233
    def test_launcher_switcher_cancel_doesnt_hide_shortcut_hint(self):
 
234
        """Cancelling the launcher switcher (by Escape) should not hide the
 
235
        shortcut hint view.
 
236
 
 
237
        """
 
238
        sleep(.5)
 
239
        show_timeout = self.shortcut_hint.get_show_timeout()
 
240
        self.shortcut_hint.show()
 
241
        self.addCleanup(self.shortcut_hint.hide)
 
242
 
 
243
        sleep(show_timeout)
 
244
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
245
 
 
246
        launcher = self.get_launcher()
 
247
        launcher.start_switcher()
 
248
        self.addCleanup(launcher.end_switcher, True)
 
249
        sleep(.25)
 
250
        self.assertThat(self.launcher.key_nav_is_active, Equals(True))
 
251
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
252
 
 
253
        launcher.switcher_next()
 
254
        sleep(.25)
 
255
        self.keyboard.press_and_release("Escape")
 
256
        sleep(.25)
 
257
 
 
258
        self.assertThat(self.launcher.key_nav_is_active, Equals(False))
 
259
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
260
        sleep(.5)
 
261
 
 
262
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
263
 
 
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.
 
267
 
 
268
        """
 
269
        sleep(.5)
 
270
        show_timeout = self.shortcut_hint.get_show_timeout()
 
271
        self.shortcut_hint.show()
 
272
        self.addCleanup(self.shortcut_hint.hide)
 
273
 
 
274
        sleep(show_timeout)
 
275
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
276
 
 
277
        launcher = self.get_launcher()
 
278
        launcher.start_switcher()
 
279
        self.addCleanup(launcher.end_switcher, True)
 
280
        sleep(.25)
 
281
        self.assertThat(self.launcher.key_nav_is_active, Equals(True))
 
282
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
283
 
 
284
        launcher.switcher_next()
 
285
        sleep(.25)
 
286
        self.keyboard.press_and_release("Escape")
 
287
        sleep(.25)
 
288
 
 
289
        self.assertThat(self.launcher.key_nav_is_active, Equals(False))
 
290
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
291
        sleep(.25)
 
292
 
 
293
        self.shortcut_hint.cancel()
 
294
        sleep(.25)
 
295
        self.assertThat(self.shortcut_hint.is_visible(), Equals(False))
 
296
 
 
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
 
299
        be shown.
 
300
 
 
301
        """
 
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())
 
306
 
 
307
 
 
308
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))
 
309
        self.assertThat(launcher.are_shortcuts_showing(), Equals(True))
 
310
 
 
311
    def test_shortcut_hint_shows_with_launcher_icons_hints(self):
 
312
        """When the launcher icons hints are shown also the shortcut hint should
 
313
        be shown.
 
314
 
 
315
        """
 
316
        launcher = self.get_launcher()
 
317
        launcher.keyboard_reveal_launcher()
 
318
        self.addCleanup(launcher.keyboard_unreveal_launcher)
 
319
        sleep(1)
 
320
 
 
321
        self.assertThat(launcher.are_shortcuts_showing(), Equals(True))
 
322
        self.assertThat(self.shortcut_hint.is_visible(), Equals(True))