~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to tests/autopilot/unity/tests/test_hud.py

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-04-26 12:41:09 UTC
  • Revision ID: mail@3v1n0.net-20130426124109-t3b2shjah2omiqa2
Unity: Remove all the views, but the Shortcuts

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
 
# Author: Alex Launi,
4
 
#         Marco Trevisan
5
 
#
6
 
# This program is free software: you can redistribute it and/or modify it
7
 
# under the terms of the GNU General Public License version 3, as published
8
 
# by the Free Software Foundation.
9
 
 
10
 
from __future__ import absolute_import
11
 
 
12
 
from autopilot.matchers import Eventually
13
 
from autopilot.emulators.X11 import ScreenGeometry
14
 
from autopilot.testcase import multiply_scenarios
15
 
from os import remove, environ
16
 
from os.path import exists
17
 
from tempfile import mktemp
18
 
from testtools.matchers import (
19
 
    Equals,
20
 
    EndsWith,
21
 
    GreaterThan,
22
 
    LessThan,
23
 
    NotEquals,
24
 
    )
25
 
from testtools.matchers import MismatchError
26
 
from time import sleep
27
 
 
28
 
from unity.emulators.icons import HudLauncherIcon
29
 
from unity.tests import UnityTestCase
30
 
 
31
 
 
32
 
def _make_monitor_scenarios():
33
 
    num_monitors = ScreenGeometry().get_num_monitors()
34
 
    scenarios = []
35
 
 
36
 
    if num_monitors == 1:
37
 
        scenarios = [('Single Monitor', {'hud_monitor': 0})]
38
 
    else:
39
 
        for i in range(num_monitors):
40
 
            scenarios += [('Monitor %d' % (i), {'hud_monitor': i})]
41
 
 
42
 
    return scenarios
43
 
 
44
 
 
45
 
class HudTestsBase(UnityTestCase):
46
 
 
47
 
    def setUp(self):
48
 
        super(HudTestsBase, self).setUp()
49
 
 
50
 
    def tearDown(self):
51
 
        self.unity.hud.ensure_hidden()
52
 
        super(HudTestsBase, self).tearDown()
53
 
 
54
 
    def get_num_active_launcher_icons(self):
55
 
        num_active = 0
56
 
        for icon in self.unity.launcher.model.get_launcher_icons():
57
 
            if icon.active and icon.visible:
58
 
                num_active += 1
59
 
        return num_active
60
 
 
61
 
    # Unable to exit SDM without any active apps, need a placeholder.
62
 
    # See bug LP:1079460
63
 
    def start_placeholder_app(self):
64
 
        window_spec = {
65
 
            "Title": "Placeholder application",
66
 
        }
67
 
        self.launch_test_window(window_spec)
68
 
 
69
 
 
70
 
class HudBehaviorTests(HudTestsBase):
71
 
 
72
 
    def setUp(self):
73
 
        super(HudBehaviorTests, self).setUp()
74
 
 
75
 
        if not environ.get('UBUNTU_MENUPROXY', ''):
76
 
            self.patch_environment('UBUNTU_MENUPROXY', 'libappmenu.so')
77
 
        self.hud_monitor = self.screen_geo.get_primary_monitor()
78
 
        self.screen_geo.move_mouse_to_monitor(self.hud_monitor)
79
 
 
80
 
    def test_no_initial_values(self):
81
 
        self.unity.hud.ensure_visible()
82
 
        self.assertThat(self.unity.hud.num_buttons, Equals(0))
83
 
        self.assertThat(self.unity.hud.selected_button, Equals(0))
84
 
 
85
 
    def test_check_a_values(self):
86
 
        self.unity.hud.ensure_visible()
87
 
        self.keyboard.type('a')
88
 
        self.assertThat(self.unity.hud.search_string, Eventually(Equals('a')))
89
 
        self.assertThat(self.unity.hud.num_buttons, Eventually(Equals(5)))
90
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(1)))
91
 
 
92
 
    def test_up_down_arrows(self):
93
 
        self.unity.hud.ensure_visible()
94
 
        self.keyboard.type('a')
95
 
        self.assertThat(self.unity.hud.search_string, Eventually(Equals('a')))
96
 
        self.keyboard.press_and_release('Down')
97
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(2)))
98
 
        self.keyboard.press_and_release('Down')
99
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(3)))
100
 
        self.keyboard.press_and_release('Down')
101
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(4)))
102
 
        self.keyboard.press_and_release('Down')
103
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(5)))
104
 
        # Down again stays on 5.
105
 
        self.keyboard.press_and_release('Down')
106
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(5)))
107
 
        self.keyboard.press_and_release('Up')
108
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(4)))
109
 
        self.keyboard.press_and_release('Up')
110
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(3)))
111
 
        self.keyboard.press_and_release('Up')
112
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(2)))
113
 
        self.keyboard.press_and_release('Up')
114
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(1)))
115
 
        # Up again stays on 1.
116
 
        self.keyboard.press_and_release('Up')
117
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(1)))
118
 
 
119
 
    def test_no_reset_selected_button(self):
120
 
        """Hud must not change selected button when results update over time."""
121
 
        # TODO - this test doesn't test anything. Onmy system the results never update.
122
 
        # ideally we'd send artificial results to the hud from the test.
123
 
        self.unity.hud.ensure_visible()
124
 
        self.keyboard.type('is')
125
 
        self.assertThat(self.unity.hud.search_string, Eventually(Equals('is')))
126
 
        self.keyboard.press_and_release('Down')
127
 
        self.assertThat(self.unity.hud.selected_button, Eventually(Equals(2)))
128
 
        # long sleep to let the service send updated results
129
 
        sleep(10)
130
 
        self.assertThat(self.unity.hud.selected_button, Equals(2))
131
 
 
132
 
    def test_slow_tap_not_reveal_hud(self):
133
 
        """A slow tap must not reveal the HUD."""
134
 
        self.keybinding("hud/reveal", 0.3)
135
 
        # need a long sleep to ensure that we test after the hud controller has
136
 
        # seen the keypress.
137
 
        sleep(5)
138
 
        self.assertThat(self.unity.hud.visible, Equals(False))
139
 
 
140
 
    def test_alt_f4_doesnt_show_hud(self):
141
 
        self.start_app('Calculator')
142
 
        sleep(1)
143
 
        # Do a very fast Alt+F4
144
 
        self.keyboard.press_and_release("Alt+F4", 0.05)
145
 
        sleep(1)
146
 
        self.assertFalse(self.unity.hud.visible)
147
 
 
148
 
    def test_reveal_hud_with_no_apps(self):
149
 
        """Hud must show even with no visible applications.
150
 
 
151
 
        This used to cause unity to crash (hence the lack of assertion in this test).
152
 
 
153
 
        """
154
 
        self.start_placeholder_app()
155
 
        self.unity.window_manager.enter_show_desktop()
156
 
        self.addCleanup(self.unity.window_manager.leave_show_desktop)
157
 
 
158
 
        self.unity.hud.ensure_visible()
159
 
        self.unity.hud.ensure_hidden()
160
 
 
161
 
    def test_restore_focus(self):
162
 
        """Ensures that once the hud is dismissed, the same application
163
 
        that was focused before hud invocation is refocused.
164
 
        """
165
 
        calc = self.start_app("Calculator")
166
 
 
167
 
        # first ensure that the application has started and is focused
168
 
        self.assertEqual(calc.is_active, True)
169
 
 
170
 
        self.unity.hud.ensure_visible()
171
 
        self.unity.hud.ensure_hidden()
172
 
 
173
 
        # again ensure that the application we started is focused
174
 
        self.assertEqual(calc.is_active, True)
175
 
 
176
 
        self.unity.hud.ensure_visible()
177
 
        self.unity.hud.ensure_hidden()
178
 
        # why do we do this: ???
179
 
        self.keyboard.press_and_release('Return')
180
 
        sleep(1)
181
 
 
182
 
        self.assertEqual(calc.is_active, True)
183
 
 
184
 
    def test_gedit_undo(self):
185
 
        """Test that the 'undo' action in the Hud works with GEdit."""
186
 
 
187
 
        file_path = mktemp()
188
 
        self.addCleanup(remove, file_path)
189
 
        gedit_win = self.start_app_window('Text Editor', files=[file_path], locale='C')
190
 
        self.addCleanup(self.close_all_app, 'Text Editor')
191
 
        self.assertProperty(gedit_win, is_focused=True)
192
 
 
193
 
        self.keyboard.type("0")
194
 
        self.keyboard.type(" ")
195
 
        self.keyboard.type("1")
196
 
 
197
 
        self.unity.hud.ensure_visible()
198
 
 
199
 
        self.keyboard.type("undo")
200
 
        hud_query_check = lambda: self.unity.hud.selected_hud_button.label_no_formatting
201
 
        self.assertThat(hud_query_check,
202
 
                        Eventually(Equals("Edit > Undo")))
203
 
        self.keyboard.press_and_release('Return')
204
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
205
 
 
206
 
        self.assertProperty(gedit_win, is_focused=True)
207
 
        self.keyboard.press_and_release("Ctrl+s")
208
 
        self.assertThat(lambda: exists(file_path), Eventually(Equals(True)))
209
 
 
210
 
        contents = open(file_path).read().strip('\n')
211
 
        self.assertEqual("0 ", contents)
212
 
 
213
 
    def test_hud_to_dash_has_key_focus(self):
214
 
        """When switching from the hud to the dash you don't lose key focus."""
215
 
        self.unity.hud.ensure_visible()
216
 
        self.unity.dash.ensure_visible()
217
 
        self.addCleanup(self.unity.dash.ensure_hidden)
218
 
        self.keyboard.type('focus1')
219
 
        self.assertThat(self.unity.dash.search_string, Eventually(Equals('focus1')))
220
 
 
221
 
    def test_dash_to_hud_has_key_focus(self):
222
 
        """When switching from the dash to the hud you don't lose key focus."""
223
 
        self.unity.dash.ensure_visible()
224
 
        self.unity.hud.ensure_visible()
225
 
        self.keyboard.type('focus2')
226
 
        self.assertThat(self.unity.hud.search_string, Eventually(Equals('focus2')))
227
 
 
228
 
    def test_hud_closes_on_workspace_switch(self):
229
 
        """This test shows that when you switch to another workspace the hud closes."""
230
 
        if self.workspace.num_workspaces <= 1:
231
 
            self.skipTest("This test requires enabled more than one workspace.")
232
 
        initial_workspace = self.workspace.current_workspace
233
 
        self.addCleanup(self.workspace.switch_to, initial_workspace)
234
 
        self.unity.hud.ensure_visible()
235
 
        self.workspace.switch_to((initial_workspace + 1) % self.workspace.num_workspaces)
236
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
237
 
 
238
 
    def test_hud_closes_on_spread(self):
239
 
        """This test shows that when the spread is initiated, the hud closes."""
240
 
        # Need at least one application open for the spread to work.
241
 
        self.start_app_window("Calculator")
242
 
        self.unity.hud.ensure_visible()
243
 
        self.addCleanup(self.keybinding, "spread/cancel")
244
 
        self.keybinding("spread/start")
245
 
        self.assertThat(self.unity.window_manager.scale_active, Eventually(Equals(True)))
246
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
247
 
 
248
 
    def test_hud_closes_click_outside_geo_shrunk(self):
249
 
        """
250
 
        Clicking outside the hud when it is shurnk will make it close.
251
 
        Shurnk is when the hud has no results and is much smaller then normal.
252
 
        """
253
 
 
254
 
        self.unity.hud.ensure_visible()
255
 
        (x,y,w,h) = self.unity.hud.view.geometry
256
 
        self.mouse.move(w/2, h-50)
257
 
        self.mouse.click()
258
 
 
259
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
260
 
 
261
 
    def test_hud_closes_click_outside_geo(self):
262
 
        """Clicking outside of the hud will make it close."""
263
 
 
264
 
        self.unity.hud.ensure_visible()
265
 
        self.keyboard.type("Test")
266
 
 
267
 
        (x,y,w,h) = self.unity.hud.view.geometry
268
 
        self.mouse.move(w/2, h+50)
269
 
        self.mouse.click()
270
 
 
271
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
272
 
 
273
 
    def test_hud_closes_click_after_text_removed(self):
274
 
        """Clicking outside of the hud after a search text has been entered and
275
 
        then removed from the searchbox will make it close."""
276
 
 
277
 
        self.unity.hud.ensure_visible()
278
 
        self.keyboard.type("Test")
279
 
        self.keyboard.press_and_release("Escape")
280
 
 
281
 
        (x,y,w,h) = self.unity.hud.view.geometry
282
 
        self.mouse.move(w/2, h+50)
283
 
        self.mouse.click()
284
 
 
285
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
286
 
 
287
 
    def test_alt_f4_close_hud(self):
288
 
        """Hud must close on alt+F4."""
289
 
        self.unity.hud.ensure_visible()
290
 
        self.keyboard.press_and_release("Alt+F4")
291
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
292
 
 
293
 
    def test_alt_f4_close_hud_with_capslock_on(self):
294
 
        """Hud must close on Alt+F4 even when the capslock is turned on."""
295
 
        self.keyboard.press_and_release("Caps_Lock")
296
 
        self.addCleanup(self.keyboard.press_and_release, "Caps_Lock")
297
 
 
298
 
        self.unity.hud.ensure_visible()
299
 
        self.keyboard.press_and_release("Alt+F4")
300
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
301
 
 
302
 
    def test_app_activate_on_enter(self):
303
 
        """Hud must close after activating a search item with Enter."""
304
 
        self.start_app('Text Editor', locale='C')
305
 
        self.addCleanup(self.close_all_app, "Text Editor")
306
 
 
307
 
        self.unity.hud.ensure_visible()
308
 
 
309
 
        self.keyboard.type("File > Quit")
310
 
        self.assertThat(self.unity.hud.search_string, Eventually(Equals("File > Quit")))
311
 
 
312
 
        self.keyboard.press_and_release("Enter")
313
 
 
314
 
        self.assertFalse(self.app_is_running("Text Editor"))
315
 
 
316
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
317
 
 
318
 
    def test_hud_closes_on_escape(self):
319
 
        """Hud must close on escape after searchbox is cleared"""
320
 
        self.unity.hud.ensure_visible()
321
 
 
322
 
        self.keyboard.type("ThisText")
323
 
        self.keyboard.press_and_release("Escape")
324
 
        self.keyboard.press_and_release("Escape")
325
 
 
326
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
327
 
 
328
 
    def test_hud_closes_on_escape_shrunk(self):
329
 
        """Hud must close when escape key is pressed"""
330
 
        self.unity.hud.ensure_visible()
331
 
        self.keyboard.press_and_release("Escape")
332
 
 
333
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
334
 
 
335
 
    def test_alt_arrow_keys_not_eaten(self):
336
 
        """Tests that Alt+ArrowKey events are correctly passed to the
337
 
        active window when Unity is not responding to them."""
338
 
 
339
 
        term_win = self.start_app_window("Terminal")
340
 
        self.assertProperty(term_win, is_focused=True)
341
 
 
342
 
        # Here we anyway need a sleep, since even though the terminal can have
343
 
        # keyboard focus, the shell inside might not be completely loaded yet
344
 
        # and keystrokes might not get registered
345
 
        sleep(1)
346
 
 
347
 
        #There's no easy way to read text from terminal, writing input
348
 
        #to a text file and then reading from there works.
349
 
        self.keyboard.type('echo "')
350
 
 
351
 
        #Terminal is receiving input with Alt+Arrowkeys
352
 
        self.keyboard.press("Alt")
353
 
        self.keyboard.press_and_release("Up")
354
 
        self.keyboard.press_and_release("Down")
355
 
        self.keyboard.press_and_release("Right")
356
 
        self.keyboard.press_and_release("Left")
357
 
        self.keyboard.release("Alt")
358
 
 
359
 
        self.keyboard.type('" > /tmp/ap_test_alt_keys')
360
 
        self.addCleanup(remove, '/tmp/ap_test_alt_keys')
361
 
        self.keyboard.press_and_release("Enter")
362
 
 
363
 
        file_contents = open('/tmp/ap_test_alt_keys', 'r').read().strip()
364
 
 
365
 
        self.assertThat(file_contents, Equals('ABCD'))
366
 
 
367
 
    def test_mouse_changes_selected_hud_button(self):
368
 
        """This tests moves the mouse from the top of the screen to the bottom, this must
369
 
        change the selected button from 1 to 5.
370
 
        """
371
 
 
372
 
        self.unity.hud.ensure_visible()
373
 
 
374
 
        self.keyboard.type("a")
375
 
        (x,y,w,h) = self.unity.hud.view.geometry
376
 
 
377
 
        # Specify a slower rate so that HUD can register the mouse movement properly
378
 
        self.mouse.move(w/2, 0, rate=5)
379
 
        self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(1)))
380
 
 
381
 
        self.mouse.move(w/2, h, rate=5)
382
 
        self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(5)))
383
 
 
384
 
    def test_keyboard_steals_focus_from_mouse(self):
385
 
        """This tests moves the mouse from the top of the screen to the bottom,
386
 
        then it presses the keyboard up 5 times, this must change the selected button from 5 to 1.
387
 
        """
388
 
 
389
 
        self.unity.hud.ensure_visible()
390
 
 
391
 
        self.keyboard.type("a")
392
 
        (x,y,w,h) = self.unity.hud.view.geometry
393
 
 
394
 
        self.mouse.move(w/2, 0)
395
 
        self.mouse.move(w/2, h)
396
 
        self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(5)))
397
 
 
398
 
        for i in range(5):
399
 
          self.keyboard.press_and_release('Up')
400
 
 
401
 
        self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(1)))
402
 
 
403
 
    def test_keep_focus_on_application_opens(self):
404
 
        """The Hud must keep key focus as well as stay open if an app gets opened from an external source. """
405
 
 
406
 
        self.unity.hud.ensure_visible()
407
 
        self.addCleanup(self.unity.hud.ensure_hidden)
408
 
 
409
 
        self.start_app_window("Calculator")
410
 
        sleep(1)
411
 
 
412
 
        self.keyboard.type("HasFocus")
413
 
        self.assertThat(self.unity.hud.search_string, Eventually(Equals("HasFocus")))
414
 
 
415
 
    def test_closes_mouse_down_outside(self):
416
 
        """Test that a mouse down outside of the hud closes the hud."""
417
 
 
418
 
        self.unity.hud.ensure_visible()
419
 
        current_monitor = self.unity.hud.monitor
420
 
 
421
 
        (x,y,w,h) = self.unity.hud.geometry
422
 
        (screen_x,screen_y,screen_w,screen_h) = self.screen_geo.get_monitor_geometry(current_monitor)
423
 
 
424
 
        self.mouse.move(x + w + (screen_w-((screen_x-x)+w))/2, y + h + (screen_h-((screen_y-y)+h))/2)
425
 
        self.mouse.click()
426
 
 
427
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
428
 
 
429
 
    def test_closes_then_focuses_window_on_mouse_down(self):
430
 
        """If 2 windows are open with 1 maximized and the non-maxmized
431
 
        focused. Then from the Hud clicking on the maximized window
432
 
        must focus that window and close the hud.
433
 
        """
434
 
        char_win = self.start_app("Character Map")
435
 
        self.assertProperty(char_win, is_active=True)
436
 
        self.keybinding("window/maximize")
437
 
        self.start_app("Calculator")
438
 
 
439
 
        self.unity.hud.ensure_visible()
440
 
 
441
 
        #Click bottom right of the screen
442
 
        w = self.screen_geo.get_screen_width()
443
 
        h = self.screen_geo.get_screen_height()
444
 
        self.mouse.move(w,h)
445
 
        self.mouse.click()
446
 
 
447
 
        self.assertProperty(char_win, is_active=True)
448
 
 
449
 
    def test_hud_does_not_focus_wrong_window_after_alt_tab(self):
450
 
        """Test the Hud focuses the correct window after an Alt+Tab."""
451
 
 
452
 
        char_win = self.start_app('Character Map')
453
 
        self.start_app('Calculator')
454
 
 
455
 
        self.keybinding("switcher/reveal_normal")
456
 
        self.assertProperty(char_win, is_active=True)
457
 
 
458
 
        self.unity.hud.ensure_visible()
459
 
        self.unity.hud.ensure_hidden()
460
 
 
461
 
        self.assertProperty(char_win, is_active=True)
462
 
 
463
 
    def test_mouse_does_not_steal_button_focus(self):
464
 
        """When typing in the hud the mouse must not steal button focus."""
465
 
 
466
 
        self.unity.hud.ensure_visible()
467
 
 
468
 
        (x,y,w,h) = self.unity.hud.view.geometry
469
 
        self.mouse.move(w/4, h/4)
470
 
 
471
 
        self.keyboard.type("a")
472
 
        self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(1)))
473
 
 
474
 
 
475
 
class HudLauncherInteractionsTests(HudTestsBase):
476
 
 
477
 
    launcher_modes = [('Launcher autohide', {'launcher_autohide': False}),
478
 
                      ('Launcher never hide', {'launcher_autohide': True})]
479
 
 
480
 
    scenarios = multiply_scenarios(_make_monitor_scenarios(), launcher_modes)
481
 
 
482
 
    def setUp(self):
483
 
        super(HudLauncherInteractionsTests, self).setUp()
484
 
        # Launchers on all monitors
485
 
        self.set_unity_option('num_launchers', 0)
486
 
        self.set_unity_option('launcher_hide_mode', int(self.launcher_autohide))
487
 
 
488
 
        self.screen_geo.move_mouse_to_monitor(self.hud_monitor)
489
 
        sleep(0.5)
490
 
 
491
 
    def test_multiple_hud_reveal_does_not_break_launcher(self):
492
 
        """Multiple Hud reveals must not cause the launcher to set multiple
493
 
        apps as active.
494
 
 
495
 
        """
496
 
        launcher = self.unity.launcher.get_launcher_for_monitor(self.hud_monitor)
497
 
 
498
 
        # We need an app to switch to:
499
 
        self.start_app('Character Map')
500
 
        # We need an application to play with - I'll use the calculator.
501
 
        self.start_app('Calculator')
502
 
        sleep(1)
503
 
 
504
 
        # before we start, make sure there's zero or one active icon:
505
 
        num_active = self.get_num_active_launcher_icons()
506
 
        self.assertThat(num_active, LessThan(2), "Invalid number of launcher icons active before test has run!")
507
 
 
508
 
        # reveal and hide hud several times over:
509
 
        for i in range(3):
510
 
            self.unity.hud.ensure_visible()
511
 
            self.unity.hud.ensure_hidden()
512
 
 
513
 
        # click application icons for running apps in the launcher:
514
 
        icon = self.unity.launcher.model.get_icon(desktop_id="gucharmap.desktop")
515
 
        launcher.click_launcher_icon(icon)
516
 
 
517
 
        # see how many apps are marked as being active:
518
 
        num_active = self.get_num_active_launcher_icons()
519
 
        self.assertLessEqual(num_active, 1, "More than one launcher icon active after test has run!")
520
 
 
521
 
    def test_hud_does_not_change_launcher_status(self):
522
 
        """Opening the HUD must not change the launcher visibility."""
523
 
 
524
 
        launcher = self.unity.launcher.get_launcher_for_monitor(self.hud_monitor)
525
 
 
526
 
        launcher_shows_pre = launcher.is_showing
527
 
        self.unity.hud.ensure_visible()
528
 
        launcher_shows_post = launcher.is_showing
529
 
        self.assertThat(launcher_shows_pre, Equals(launcher_shows_post))
530
 
 
531
 
 
532
 
class HudLockedLauncherInteractionsTests(HudTestsBase):
533
 
 
534
 
    scenarios = _make_monitor_scenarios()
535
 
 
536
 
    def setUp(self):
537
 
        super(HudLockedLauncherInteractionsTests, self).setUp()
538
 
        # Locked Launchers on all monitors
539
 
        self.set_unity_option('num_launchers', 0)
540
 
        self.set_unity_option('launcher_hide_mode', 0)
541
 
 
542
 
        self.screen_geo.move_mouse_to_monitor(self.hud_monitor)
543
 
        sleep(0.5)
544
 
 
545
 
    def test_hud_launcher_icon_hides_bfb(self):
546
 
        """BFB icon must be hidden when the HUD launcher icon is shown."""
547
 
 
548
 
        hud_icon = self.unity.hud.get_launcher_icon()
549
 
        bfb_icon = self.unity.launcher.model.get_bfb_icon()
550
 
 
551
 
        self.assertThat(bfb_icon.visible, Eventually(Equals(True)))
552
 
        self.assertTrue(bfb_icon.is_on_monitor(self.hud_monitor))
553
 
        self.assertThat(hud_icon.visible, Eventually(Equals(False)))
554
 
 
555
 
        self.unity.hud.ensure_visible()
556
 
 
557
 
        self.assertThat(hud_icon.visible, Eventually(Equals(True)))
558
 
        self.assertTrue(hud_icon.is_on_monitor(self.hud_monitor))
559
 
        # For some reason the BFB icon is always visible :-/
560
 
        #bfb_icon.visible, Eventually(Equals(False)
561
 
 
562
 
    def test_hud_desaturates_launcher_icons(self):
563
 
        """Launcher icons must desaturate when the HUD is opened."""
564
 
 
565
 
        self.unity.hud.ensure_visible()
566
 
 
567
 
        for icon in self.unity.launcher.model.get_launcher_icons_for_monitor(self.hud_monitor):
568
 
            if isinstance(icon, HudLauncherIcon):
569
 
                self.assertThat(icon.desaturated, Eventually(Equals(False)))
570
 
            else:
571
 
                self.assertThat(icon.desaturated, Eventually(Equals(True)))
572
 
 
573
 
    def test_hud_launcher_icon_click_hides_hud(self):
574
 
        """Clicking the Hud Icon should hide the HUD"""
575
 
 
576
 
        hud_icon = self.unity.hud.get_launcher_icon()
577
 
        self.unity.hud.ensure_visible()
578
 
 
579
 
        launcher = self.unity.launcher.get_launcher_for_monitor(self.hud_monitor)
580
 
        launcher.click_launcher_icon(hud_icon)
581
 
 
582
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
583
 
        self.assertThat(hud_icon.visible, Eventually(Equals(False)))
584
 
 
585
 
 
586
 
class HudVisualTests(HudTestsBase):
587
 
 
588
 
    launcher_modes = [('Launcher autohide', {'launcher_autohide': False}),
589
 
                      ('Launcher never hide', {'launcher_autohide': True})]
590
 
 
591
 
    launcher_screen = [('Launcher on primary monitor', {'launcher_primary_only': False}),
592
 
                       ('Launcher on all monitors', {'launcher_primary_only': True})]
593
 
 
594
 
    scenarios = multiply_scenarios(_make_monitor_scenarios(), launcher_modes, launcher_screen)
595
 
 
596
 
    def setUp(self):
597
 
        super(HudVisualTests, self).setUp()
598
 
        self.screen_geo.move_mouse_to_monitor(self.hud_monitor)
599
 
        self.set_unity_option('launcher_hide_mode', int(self.launcher_autohide))
600
 
        self.set_unity_option('num_launchers', int(self.launcher_primary_only))
601
 
        self.hud_monitor_is_primary = (self.screen_geo.get_primary_monitor() == self.hud_monitor)
602
 
        self.hud_locked = (not self.launcher_autohide and (not self.launcher_primary_only or self.hud_monitor_is_primary))
603
 
        sleep(0.5)
604
 
 
605
 
    def test_initially_hidden(self):
606
 
        self.assertFalse(self.unity.hud.visible)
607
 
 
608
 
    def test_hud_is_on_right_monitor(self):
609
 
        """HUD must be drawn on the monitor where the mouse is."""
610
 
        self.unity.hud.ensure_visible()
611
 
        self.assertThat(self.unity.hud.monitor, Eventually(Equals(self.hud_monitor)))
612
 
        self.assertTrue(self.screen_geo.is_rect_on_monitor(self.unity.hud.monitor, self.unity.hud.geometry))
613
 
 
614
 
    def test_hud_geometries(self):
615
 
        """Tests the HUD geometries for the given monitor and status."""
616
 
        self.unity.hud.ensure_visible()
617
 
        monitor_geo = self.screen_geo.get_monitor_geometry(self.hud_monitor)
618
 
        monitor_x = monitor_geo[0]
619
 
        monitor_w = monitor_geo[2]
620
 
        hud_x = self.unity.hud.geometry[0]
621
 
        hud_w = self.unity.hud.geometry[2]
622
 
 
623
 
        if self.hud_locked:
624
 
            self.assertThat(hud_x, GreaterThan(monitor_x))
625
 
            self.assertThat(hud_x, LessThan(monitor_x + monitor_w))
626
 
            self.assertThat(hud_w, Equals(monitor_x + monitor_w - hud_x))
627
 
        else:
628
 
            self.assertThat(hud_x, Equals(monitor_x))
629
 
            self.assertThat(hud_w, Equals(monitor_w))
630
 
 
631
 
    def test_hud_is_locked_to_launcher(self):
632
 
        """Tests if the HUD is locked to launcher as we expect or not."""
633
 
        self.unity.hud.ensure_visible()
634
 
        self.assertThat(self.unity.hud.is_locked_launcher, Eventually(Equals(self.hud_locked)))
635
 
 
636
 
    def test_hud_icon_is_shown(self):
637
 
        """Tests that the correct HUD icon is shown."""
638
 
        self.unity.hud.ensure_visible()
639
 
        hud_launcher_icon = self.unity.hud.get_launcher_icon()
640
 
        hud_embedded_icon = self.unity.hud.get_embedded_icon()
641
 
 
642
 
        if self.unity.hud.is_locked_launcher:
643
 
            self.assertThat(hud_launcher_icon.visible, Eventually(Equals(True)))
644
 
            self.assertTrue(hud_launcher_icon.is_on_monitor(self.hud_monitor))
645
 
            self.assertTrue(hud_launcher_icon.active)
646
 
            self.assertThat(hud_launcher_icon.monitor, Equals(self.hud_monitor))
647
 
            self.assertFalse(hud_launcher_icon.desaturated)
648
 
            self.assertThat(hud_embedded_icon, Equals(None))
649
 
        else:
650
 
            self.assertThat(hud_launcher_icon.visible, Eventually(Equals(False)))
651
 
            self.assertFalse(hud_launcher_icon.active)
652
 
            # the embedded icon has no visible property.
653
 
            self.assertThat(hud_embedded_icon, NotEquals(None))
654
 
 
655
 
    def test_hud_icon_shows_the_focused_application_emblem(self):
656
 
        """Tests that the correct HUD icon is shown."""
657
 
        self.close_all_app("Calculator")
658
 
        calc = self.start_app("Calculator")
659
 
        self.assertTrue(calc.is_active)
660
 
        self.unity.hud.ensure_visible()
661
 
 
662
 
        self.assertThat(self.unity.hud.icon.icon_name, Eventually(Equals(calc.icon)))
663
 
 
664
 
    def test_hud_icon_shows_the_ubuntu_emblem_on_empty_desktop(self):
665
 
        """When in 'show desktop' mode the hud icon must be the BFB icon."""
666
 
        self.start_placeholder_app()
667
 
        self.unity.window_manager.enter_show_desktop()
668
 
        self.addCleanup(self.unity.window_manager.leave_show_desktop)
669
 
        self.unity.hud.ensure_visible()
670
 
 
671
 
        self.assertThat(self.unity.hud.icon.icon_name, Eventually(EndsWith("launcher_bfb.png")))
672
 
 
673
 
    def test_switch_dash_hud_does_not_break_the_focused_application_emblem(self):
674
 
        """Switching from Dash to HUD must still show the correct HUD icon."""
675
 
        self.close_all_app("Calculator")
676
 
        calc = self.start_app("Calculator")
677
 
        self.assertTrue(calc.is_active)
678
 
 
679
 
        self.unity.dash.ensure_visible()
680
 
        self.unity.hud.ensure_visible()
681
 
 
682
 
        self.assertThat(self.unity.hud.icon.icon_name, Eventually(Equals(calc.icon)))
683
 
 
684
 
    def test_switch_hud_dash_does_not_break_the_focused_application_emblem(self):
685
 
        """Switching from HUD to Dash and back must still show the correct HUD icon."""
686
 
        self.close_all_app("Calculator")
687
 
        calc = self.start_app("Calculator")
688
 
        self.assertTrue(calc.is_active)
689
 
 
690
 
        self.unity.hud.ensure_visible()
691
 
        self.unity.dash.ensure_visible()
692
 
        self.unity.hud.ensure_visible()
693
 
        self.assertThat(self.unity.hud.icon.icon_name, Eventually(Equals(calc.icon)))
694
 
 
695
 
    def test_dash_hud_only_uses_icon_from_current_desktop(self):
696
 
        """
697
 
        Switching from the dash to Hud must pick an icon from applications
698
 
        from the current desktop. As the Hud must go through the entire window
699
 
        stack to find the top most window.
700
 
        """
701
 
        if self.workspace.num_workspaces <= 1:
702
 
            self.skipTest("This test requires enabled more than one workspace.")
703
 
        self.start_placeholder_app()
704
 
        initial_workspace = self.workspace.current_workspace
705
 
        self.addCleanup(self.workspace.switch_to, initial_workspace)
706
 
        self.unity.window_manager.enter_show_desktop()
707
 
        self.addCleanup(self.unity.window_manager.leave_show_desktop)
708
 
 
709
 
        calc = self.start_app("Calculator")
710
 
        self.assertTrue(calc.is_active)
711
 
        self.workspace.switch_to((initial_workspace + 1) % self.workspace.num_workspaces)
712
 
        self.unity.dash.ensure_visible()
713
 
        self.unity.hud.ensure_visible()
714
 
 
715
 
        self.assertThat(self.unity.hud.icon.icon_name, Eventually(EndsWith("launcher_bfb.png")))
716
 
 
717
 
 
718
 
class HudAlternativeKeybindingTests(HudTestsBase):
719
 
 
720
 
    def alternateCheck(self, keybinding="Alt", hide=False):
721
 
        """Nasty workaround for LP: #1157738"""
722
 
        # So, since we have no way of making sure that after changing the unity option
723
 
        # the change will be already 'applied' on the system, let's try the keybinding
724
 
        # a few times before deciding that it does not work and we have a regression
725
 
        # Seems better than a sleep(some_value_here)
726
 
        for i in range(1, 4):
727
 
            try:
728
 
                self.keyboard.press_and_release(keybinding)
729
 
                self.assertThat(self.unity.hud.visible, Eventually(Equals(True), timeout=3))
730
 
                break
731
 
            except MismatchError:
732
 
                continue
733
 
        if hide:
734
 
            self.unity.hud.ensure_hidden()
735
 
 
736
 
    def test_super_h(self):
737
 
        """Test hud reveal on <Super>h."""
738
 
        self.addCleanup(self.alternateCheck, hide=True)
739
 
        self.set_unity_option("show_hud", "<Super>h")
740
 
        # Don't use reveal_hud, but be explicit in the keybindings.
741
 
        self.alternateCheck("Super+h")
742
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(True)))
743
 
 
744
 
    def test_ctrl_alt_h(self):
745
 
        """Test hud reveal on <Contrl><Alt>h."""
746
 
        self.addCleanup(self.alternateCheck, hide=True)
747
 
        self.set_unity_option("show_hud", "<Control><Alt>h")
748
 
        # Don't use reveal_hud, but be explicit in the keybindings.
749
 
        self.alternateCheck("Ctrl+Alt+h")
750
 
        self.assertThat(self.unity.hud.visible, Eventually(Equals(True)))
751
 
 
752
 
 
753
 
class HudCrossMonitorsTests(HudTestsBase):
754
 
    """Multi-monitor hud tests."""
755
 
 
756
 
    def setUp(self):
757
 
        super(HudCrossMonitorsTests, self).setUp()
758
 
        if self.screen_geo.get_num_monitors() < 2:
759
 
            self.skipTest("This test requires more than 1 monitor.")
760
 
 
761
 
    def test_hud_stays_on_same_monitor(self):
762
 
        """If the hud is opened, then the mouse is moved to another monitor and
763
 
        the keyboard is used. The hud must not move to that monitor.
764
 
        """
765
 
 
766
 
        current_monitor = self.unity.hud.ideal_monitor
767
 
 
768
 
        self.unity.hud.ensure_visible()
769
 
        self.addCleanup(self.unity.hud.ensure_hidden)
770
 
 
771
 
        self.screen_geo.move_mouse_to_monitor((current_monitor + 1) % self.screen_geo.get_num_monitors())
772
 
        self.keyboard.type("abc")
773
 
 
774
 
        self.assertThat(self.unity.hud.ideal_monitor, Eventually(Equals(current_monitor)))
775
 
 
776
 
    def test_hud_close_on_cross_monitor_click(self):
777
 
        """Hud must close when clicking on a window in a different screen."""
778
 
 
779
 
        self.addCleanup(self.unity.hud.ensure_hidden)
780
 
 
781
 
        for monitor in range(self.screen_geo.get_num_monitors()-1):
782
 
            self.screen_geo.move_mouse_to_monitor(monitor)
783
 
            self.unity.hud.ensure_visible()
784
 
 
785
 
            self.screen_geo.move_mouse_to_monitor(monitor+1)
786
 
            sleep(.5)
787
 
            self.mouse.click()
788
 
 
789
 
            self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))