/usr/lib/python2.7/dist-packages/unity/tests/launcher/test_keynav.py is in unity-autopilot 7.5.0+18.04.20180413-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2012 Canonical
# Authors: Thomi Richards,
# Marco Trevisan (TreviƱo)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
from __future__ import absolute_import
from autopilot.matchers import Eventually
import logging
from testtools.matchers import Equals, GreaterThan
from unity.emulators.launcher import LauncherPosition
from unity.tests.launcher import LauncherTestCase
logger = logging.getLogger(__name__)
class LauncherKeyNavTests(LauncherTestCase):
"""Test the launcher key navigation"""
def start_keynav_with_cleanup_cancel(self):
"""Start keynav mode safely.
This adds a cleanup action that cancels keynav mode at the end of the
test if it's still running (but does nothing otherwise).
"""
self.launcher_instance.key_nav_start()
self.addCleanup(self.safe_quit_keynav)
def safe_quit_keynav(self):
"""Quit the keynav mode if it's engaged."""
if self.unity.launcher.key_nav_is_active:
self.launcher_instance.key_nav_cancel()
def test_launcher_keynav_initiate(self):
"""Tests we can initiate keyboard navigation on the launcher."""
self.start_keynav_with_cleanup_cancel()
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(True)))
self.assertThat(self.unity.launcher.key_nav_is_grabbed, Eventually(Equals(True)))
def test_launcher_keynav_cancel(self):
"""Test that we can exit keynav mode."""
self.launcher_instance.key_nav_start()
self.launcher_instance.key_nav_cancel()
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(False)))
self.assertThat(self.unity.launcher.key_nav_is_grabbed, Eventually(Equals(False)))
def test_launcher_keynav_cancel_resume_focus(self):
"""Test that ending the launcher keynav resume the focus."""
calc = self.process_manager.start_app("Calculator")
self.assertTrue(calc.is_active)
self.start_keynav_with_cleanup_cancel()
self.assertFalse(calc.is_active)
self.launcher_instance.key_nav_cancel()
self.assertTrue(calc.is_active)
def test_launcher_keynav_starts_at_index_zero(self):
"""Test keynav mode starts at index 0."""
self.start_keynav_with_cleanup_cancel()
self.assertThat(self.unity.launcher.key_nav_selection, Eventually(Equals(0)))
def test_launcher_keynav_forward(self):
"""Must be able to move forwards while in keynav mode."""
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.key_nav_next(self.launcher_position)
# The launcher model has hidden items, so the keynav indexes do not
# increase by 1 each time. This test was failing because the 2nd icon
# had an index of 2, not 1 as expected. The best we can do here is to
# make sure that the index has increased. This opens us to the
# possibility that the launcher really is skipping forward more than one
# icon at a time, but we can't do much about that.
self.assertThat(self.unity.launcher.key_nav_selection, Eventually(GreaterThan(0)))
def test_launcher_keynav_prev_works(self):
"""Must be able to move backwards while in keynav mode."""
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.key_nav_next(self.launcher_position)
self.assertThat(self.unity.launcher.key_nav_selection, Eventually(GreaterThan(0)))
self.launcher_instance.key_nav_prev(self.launcher_position)
self.assertThat(self.unity.launcher.key_nav_selection, Eventually(Equals(0)))
def test_launcher_keynav_cycling_forward(self):
"""Launcher keynav must loop through icons when cycling forwards"""
self.start_keynav_with_cleanup_cancel()
prev_icon = 0
for icon in range(1, self.unity.launcher.model.num_launcher_icons()):
self.launcher_instance.key_nav_next(self.launcher_position)
# FIXME We can't directly check for selection/icon number equalty
# since the launcher model also contains "hidden" icons that aren't
# shown, so the selection index can increment by more than 1.
self.assertThat(self.unity.launcher.key_nav_selection, Eventually(GreaterThan(prev_icon)))
prev_icon = self.unity.launcher.key_nav_selection
self.launcher_instance.key_nav_next(self.launcher_position)
self.assertThat(self.unity.launcher.key_nav_selection, Eventually(Equals(0)))
def test_launcher_keynav_cycling_backward(self):
"""Launcher keynav must loop through icons when cycling backwards"""
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.key_nav_prev(self.launcher_position)
# FIXME We can't directly check for self.unity.launcher.num_launcher_icons - 1
self.assertThat(self.unity.launcher.key_nav_selection, Eventually(GreaterThan(1)))
def test_launcher_keynav_can_open_and_close_quicklist(self):
"""Tests that we can open and close a quicklist from keynav mode."""
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.key_nav_next(self.launcher_position)
self.addCleanup(self.keyboard.press_and_release, "Escape")
self.launcher_instance.key_nav_enter_quicklist(self.launcher_position)
self.assertThat(self.launcher_instance.quicklist_open, Eventually(Equals(True)))
# We can't close a quicklist from keynav mode when launcher at bottom.
if self.launcher_position == LauncherPosition.LEFT:
self.launcher_instance.key_nav_exit_quicklist()
self.assertThat(self.launcher_instance.quicklist_open, Eventually(Equals(False)))
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(True)))
self.assertThat(self.unity.launcher.key_nav_is_grabbed, Eventually(Equals(True)))
def test_launcher_keynav_mode_toggles(self):
"""Tests that keynav mode toggles with Alt+F1."""
# was initiated in setup.
self.start_keynav_with_cleanup_cancel()
self.keybinding("launcher/keynav")
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(False)))
def test_launcher_keynav_activate_keep_focus(self):
"""Activating a running launcher icon must focus it."""
calc = self.process_manager.start_app("Calculator")
mahjongg = self.process_manager.start_app("Mahjongg")
self.assertTrue(mahjongg.is_active)
self.assertFalse(calc.is_active)
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.keyboard_select_icon(self.launcher_position, tooltip_text=calc.name)
self.launcher_instance.key_nav_activate()
self.assertTrue(calc.is_active)
self.assertFalse(mahjongg.is_active)
def test_launcher_keynav_expo_focus(self):
"""When entering expo mode from KeyNav the Desktop must get focus."""
if self.workspace.num_workspaces < 2:
self.skipTest("This test requires enabled more than one workspace.")
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.keyboard_select_icon(self.launcher_position, tooltip_text="Workspace Switcher")
self.launcher_instance.key_nav_activate()
self.addCleanup(self.keybinding, "expo/cancel")
self.assertThat(self.unity.panels.get_active_panel().title, Eventually(Equals("Ubuntu Desktop")))
def test_launcher_keynav_expo_exit_on_esc(self):
"""Esc should quit expo when entering it from KeyNav."""
if self.workspace.num_workspaces < 2:
self.skipTest("This test requires enabled more than one workspace.")
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.keyboard_select_icon(self.launcher_position, tooltip_text="Workspace Switcher")
self.launcher_instance.key_nav_activate()
self.keyboard.press_and_release("Escape")
self.assertThat(self.unity.window_manager.expo_active, Eventually(Equals(False)))
def test_launcher_keynav_alt_tab_quits(self):
"""Tests that alt+tab exits keynav mode."""
self.start_keynav_with_cleanup_cancel()
self.keybinding("switcher/reveal_normal")
self.addCleanup(self.unity.switcher.terminate)
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(False)))
def test_launcher_keynav_alt_grave_quits(self):
"""Tests that alt+` exits keynav mode."""
self.start_keynav_with_cleanup_cancel()
# Can't use switcher emulat here since the switcher won't appear.
self.keybinding("switcher/reveal_details")
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(False)))
def test_launcher_keynav_cancel_doesnt_activate_icon(self):
"""This tests when canceling keynav the current icon doesnt activate."""
self.start_keynav_with_cleanup_cancel()
self.keyboard.press_and_release("Escape")
self.assertThat(self.unity.dash.visible, Eventually(Equals(False)))
def test_alt_f1_closes_dash(self):
"""Pressing Alt+F1 when the Dash is open must close the Dash and start keynav."""
self.unity.dash.ensure_visible()
self.start_keynav_with_cleanup_cancel()
self.assertThat(self.unity.dash.visible, Equals(False))
self.assertThat(self.unity.launcher.key_nav_is_active, Equals(True))
def test_alt_f1_closes_hud(self):
"""Pressing Alt+F1 when the HUD is open must close the HUD and start keynav."""
self.unity.hud.ensure_visible()
self.start_keynav_with_cleanup_cancel()
self.assertThat(self.unity.hud.visible, Equals(False))
self.assertThat(self.unity.launcher.key_nav_is_active, Equals(True))
def test_launcher_keynav_cancel_on_click_outside(self):
"""A single click outside of launcher must cancel keynav."""
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.move_mouse_beside_launcher()
self.mouse.click()
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(False)))
def test_launcher_keynav_cancel_on_click_icon(self):
"""A single click on a launcher icon must cancel keynav."""
calc_win = self.process_manager.start_app_window('Calculator', locale = 'C')
calc_app = calc_win.application
calc_icon = self.unity.launcher.model.get_icon(desktop_id=calc_app.desktop_file)
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.click_launcher_icon(calc_icon)
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(False)))
def test_launcher_keynav_cancel_on_quicklist_activate(self):
"""A single click on a quicklist item must cancel keynav."""
self.start_keynav_with_cleanup_cancel()
self.launcher_instance.key_nav_enter_quicklist(self.launcher_position)
bfb_icon = self.unity.launcher.model.get_bfb_icon()
bfb_ql = bfb_icon.get_quicklist()
bfb_ql.click_item(bfb_ql.selected_item)
self.addCleanup(self.unity.dash.ensure_hidden)
self.assertThat(self.unity.dash.visible, Eventually(Equals(True)))
self.assertThat(self.unity.launcher.key_nav_is_active, Eventually(Equals(False)))
def test_launcher_keynav_changes_panel(self):
"""The panel title must change when in key nav mode
and LIM is not enabled.
"""
self.start_keynav_with_cleanup_cancel()
panel = self.unity.panels.get_active_panel()
expected_panel_title = ("" if panel.menus.integrated_menus
else "Search your computer and online sources")
self.assertThat(panel.title, Eventually(Equals(expected_panel_title)))
|