1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2012 Canonical
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.
10
from __future__ import absolute_import
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 (
25
from testtools.matchers import MismatchError
26
from time import sleep
28
from unity.emulators.icons import HudLauncherIcon
29
from unity.tests import UnityTestCase
32
def _make_monitor_scenarios():
33
num_monitors = ScreenGeometry().get_num_monitors()
37
scenarios = [('Single Monitor', {'hud_monitor': 0})]
39
for i in range(num_monitors):
40
scenarios += [('Monitor %d' % (i), {'hud_monitor': i})]
45
class HudTestsBase(UnityTestCase):
48
super(HudTestsBase, self).setUp()
51
self.unity.hud.ensure_hidden()
52
super(HudTestsBase, self).tearDown()
54
def get_num_active_launcher_icons(self):
56
for icon in self.unity.launcher.model.get_launcher_icons():
57
if icon.active and icon.visible:
61
# Unable to exit SDM without any active apps, need a placeholder.
63
def start_placeholder_app(self):
65
"Title": "Placeholder application",
67
self.launch_test_window(window_spec)
70
class HudBehaviorTests(HudTestsBase):
73
super(HudBehaviorTests, self).setUp()
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)
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))
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)))
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)))
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
130
self.assertThat(self.unity.hud.selected_button, Equals(2))
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
138
self.assertThat(self.unity.hud.visible, Equals(False))
140
def test_alt_f4_doesnt_show_hud(self):
141
self.start_app('Calculator')
143
# Do a very fast Alt+F4
144
self.keyboard.press_and_release("Alt+F4", 0.05)
146
self.assertFalse(self.unity.hud.visible)
148
def test_reveal_hud_with_no_apps(self):
149
"""Hud must show even with no visible applications.
151
This used to cause unity to crash (hence the lack of assertion in this test).
154
self.start_placeholder_app()
155
self.unity.window_manager.enter_show_desktop()
156
self.addCleanup(self.unity.window_manager.leave_show_desktop)
158
self.unity.hud.ensure_visible()
159
self.unity.hud.ensure_hidden()
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.
165
calc = self.start_app("Calculator")
167
# first ensure that the application has started and is focused
168
self.assertEqual(calc.is_active, True)
170
self.unity.hud.ensure_visible()
171
self.unity.hud.ensure_hidden()
173
# again ensure that the application we started is focused
174
self.assertEqual(calc.is_active, True)
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')
182
self.assertEqual(calc.is_active, True)
184
def test_gedit_undo(self):
185
"""Test that the 'undo' action in the Hud works with GEdit."""
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)
193
self.keyboard.type("0")
194
self.keyboard.type(" ")
195
self.keyboard.type("1")
197
self.unity.hud.ensure_visible()
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)))
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)))
210
contents = open(file_path).read().strip('\n')
211
self.assertEqual("0 ", contents)
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')))
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')))
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)))
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)))
248
def test_hud_closes_click_outside_geo_shrunk(self):
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.
254
self.unity.hud.ensure_visible()
255
(x,y,w,h) = self.unity.hud.view.geometry
256
self.mouse.move(w/2, h-50)
259
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
261
def test_hud_closes_click_outside_geo(self):
262
"""Clicking outside of the hud will make it close."""
264
self.unity.hud.ensure_visible()
265
self.keyboard.type("Test")
267
(x,y,w,h) = self.unity.hud.view.geometry
268
self.mouse.move(w/2, h+50)
271
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
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."""
277
self.unity.hud.ensure_visible()
278
self.keyboard.type("Test")
279
self.keyboard.press_and_release("Escape")
281
(x,y,w,h) = self.unity.hud.view.geometry
282
self.mouse.move(w/2, h+50)
285
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
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)))
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")
298
self.unity.hud.ensure_visible()
299
self.keyboard.press_and_release("Alt+F4")
300
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
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")
307
self.unity.hud.ensure_visible()
309
self.keyboard.type("File > Quit")
310
self.assertThat(self.unity.hud.search_string, Eventually(Equals("File > Quit")))
312
self.keyboard.press_and_release("Enter")
314
self.assertFalse(self.app_is_running("Text Editor"))
316
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
318
def test_hud_closes_on_escape(self):
319
"""Hud must close on escape after searchbox is cleared"""
320
self.unity.hud.ensure_visible()
322
self.keyboard.type("ThisText")
323
self.keyboard.press_and_release("Escape")
324
self.keyboard.press_and_release("Escape")
326
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
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")
333
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
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."""
339
term_win = self.start_app_window("Terminal")
340
self.assertProperty(term_win, is_focused=True)
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
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 "')
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")
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")
363
file_contents = open('/tmp/ap_test_alt_keys', 'r').read().strip()
365
self.assertThat(file_contents, Equals('ABCD'))
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.
372
self.unity.hud.ensure_visible()
374
self.keyboard.type("a")
375
(x,y,w,h) = self.unity.hud.view.geometry
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)))
381
self.mouse.move(w/2, h, rate=5)
382
self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(5)))
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.
389
self.unity.hud.ensure_visible()
391
self.keyboard.type("a")
392
(x,y,w,h) = self.unity.hud.view.geometry
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)))
399
self.keyboard.press_and_release('Up')
401
self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(1)))
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. """
406
self.unity.hud.ensure_visible()
407
self.addCleanup(self.unity.hud.ensure_hidden)
409
self.start_app_window("Calculator")
412
self.keyboard.type("HasFocus")
413
self.assertThat(self.unity.hud.search_string, Eventually(Equals("HasFocus")))
415
def test_closes_mouse_down_outside(self):
416
"""Test that a mouse down outside of the hud closes the hud."""
418
self.unity.hud.ensure_visible()
419
current_monitor = self.unity.hud.monitor
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)
424
self.mouse.move(x + w + (screen_w-((screen_x-x)+w))/2, y + h + (screen_h-((screen_y-y)+h))/2)
427
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
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.
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")
439
self.unity.hud.ensure_visible()
441
#Click bottom right of the screen
442
w = self.screen_geo.get_screen_width()
443
h = self.screen_geo.get_screen_height()
447
self.assertProperty(char_win, is_active=True)
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."""
452
char_win = self.start_app('Character Map')
453
self.start_app('Calculator')
455
self.keybinding("switcher/reveal_normal")
456
self.assertProperty(char_win, is_active=True)
458
self.unity.hud.ensure_visible()
459
self.unity.hud.ensure_hidden()
461
self.assertProperty(char_win, is_active=True)
463
def test_mouse_does_not_steal_button_focus(self):
464
"""When typing in the hud the mouse must not steal button focus."""
466
self.unity.hud.ensure_visible()
468
(x,y,w,h) = self.unity.hud.view.geometry
469
self.mouse.move(w/4, h/4)
471
self.keyboard.type("a")
472
self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(1)))
475
class HudLauncherInteractionsTests(HudTestsBase):
477
launcher_modes = [('Launcher autohide', {'launcher_autohide': False}),
478
('Launcher never hide', {'launcher_autohide': True})]
480
scenarios = multiply_scenarios(_make_monitor_scenarios(), launcher_modes)
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))
488
self.screen_geo.move_mouse_to_monitor(self.hud_monitor)
491
def test_multiple_hud_reveal_does_not_break_launcher(self):
492
"""Multiple Hud reveals must not cause the launcher to set multiple
496
launcher = self.unity.launcher.get_launcher_for_monitor(self.hud_monitor)
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')
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!")
508
# reveal and hide hud several times over:
510
self.unity.hud.ensure_visible()
511
self.unity.hud.ensure_hidden()
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)
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!")
521
def test_hud_does_not_change_launcher_status(self):
522
"""Opening the HUD must not change the launcher visibility."""
524
launcher = self.unity.launcher.get_launcher_for_monitor(self.hud_monitor)
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))
532
class HudLockedLauncherInteractionsTests(HudTestsBase):
534
scenarios = _make_monitor_scenarios()
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)
542
self.screen_geo.move_mouse_to_monitor(self.hud_monitor)
545
def test_hud_launcher_icon_hides_bfb(self):
546
"""BFB icon must be hidden when the HUD launcher icon is shown."""
548
hud_icon = self.unity.hud.get_launcher_icon()
549
bfb_icon = self.unity.launcher.model.get_bfb_icon()
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)))
555
self.unity.hud.ensure_visible()
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)
562
def test_hud_desaturates_launcher_icons(self):
563
"""Launcher icons must desaturate when the HUD is opened."""
565
self.unity.hud.ensure_visible()
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)))
571
self.assertThat(icon.desaturated, Eventually(Equals(True)))
573
def test_hud_launcher_icon_click_hides_hud(self):
574
"""Clicking the Hud Icon should hide the HUD"""
576
hud_icon = self.unity.hud.get_launcher_icon()
577
self.unity.hud.ensure_visible()
579
launcher = self.unity.launcher.get_launcher_for_monitor(self.hud_monitor)
580
launcher.click_launcher_icon(hud_icon)
582
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))
583
self.assertThat(hud_icon.visible, Eventually(Equals(False)))
586
class HudVisualTests(HudTestsBase):
588
launcher_modes = [('Launcher autohide', {'launcher_autohide': False}),
589
('Launcher never hide', {'launcher_autohide': True})]
591
launcher_screen = [('Launcher on primary monitor', {'launcher_primary_only': False}),
592
('Launcher on all monitors', {'launcher_primary_only': True})]
594
scenarios = multiply_scenarios(_make_monitor_scenarios(), launcher_modes, launcher_screen)
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))
605
def test_initially_hidden(self):
606
self.assertFalse(self.unity.hud.visible)
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))
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]
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))
628
self.assertThat(hud_x, Equals(monitor_x))
629
self.assertThat(hud_w, Equals(monitor_w))
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)))
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()
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))
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))
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()
662
self.assertThat(self.unity.hud.icon.icon_name, Eventually(Equals(calc.icon)))
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()
671
self.assertThat(self.unity.hud.icon.icon_name, Eventually(EndsWith("launcher_bfb.png")))
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)
679
self.unity.dash.ensure_visible()
680
self.unity.hud.ensure_visible()
682
self.assertThat(self.unity.hud.icon.icon_name, Eventually(Equals(calc.icon)))
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)
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)))
695
def test_dash_hud_only_uses_icon_from_current_desktop(self):
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.
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)
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()
715
self.assertThat(self.unity.hud.icon.icon_name, Eventually(EndsWith("launcher_bfb.png")))
718
class HudAlternativeKeybindingTests(HudTestsBase):
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):
728
self.keyboard.press_and_release(keybinding)
729
self.assertThat(self.unity.hud.visible, Eventually(Equals(True), timeout=3))
731
except MismatchError:
734
self.unity.hud.ensure_hidden()
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)))
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)))
753
class HudCrossMonitorsTests(HudTestsBase):
754
"""Multi-monitor hud tests."""
757
super(HudCrossMonitorsTests, self).setUp()
758
if self.screen_geo.get_num_monitors() < 2:
759
self.skipTest("This test requires more than 1 monitor.")
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.
766
current_monitor = self.unity.hud.ideal_monitor
768
self.unity.hud.ensure_visible()
769
self.addCleanup(self.unity.hud.ensure_hidden)
771
self.screen_geo.move_mouse_to_monitor((current_monitor + 1) % self.screen_geo.get_num_monitors())
772
self.keyboard.type("abc")
774
self.assertThat(self.unity.hud.ideal_monitor, Eventually(Equals(current_monitor)))
776
def test_hud_close_on_cross_monitor_click(self):
777
"""Hud must close when clicking on a window in a different screen."""
779
self.addCleanup(self.unity.hud.ensure_hidden)
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()
785
self.screen_geo.move_mouse_to_monitor(monitor+1)
789
self.assertThat(self.unity.hud.visible, Eventually(Equals(False)))