Back to index

unity  6.0.0
test_shortcut_hint.py
Go to the documentation of this file.
00001 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
00002 # Copyright 2012 Canonical
00003 # Authors: Marco Trevisan (TreviƱo)
00004 #
00005 # This program is free software: you can redistribute it and/or modify it
00006 # under the terms of the GNU General Public License version 3, as published
00007 # by the Free Software Foundation.
00008 
00009 from __future__ import absolute_import
00010 
00011 from autopilot.matchers import Eventually
00012 from testtools.matchers import Equals
00013 from time import sleep
00014 
00015 from unity.emulators.shortcut_hint import ShortcutController
00016 from unity.tests import UnityTestCase
00017 
00018 
00019 class BaseShortcutHintTests(UnityTestCase):
00020     """Base class for the shortcut hint tests"""
00021 
00022     def setUp(self):
00023         super(BaseShortcutHintTests, self).setUp()
00024 
00025         self.DEFAULT_WIDTH = 970;
00026         self.DEFAULT_HEIGHT = 680;
00027 
00028         self.shortcut_hint = self.get_shortcut_controller()
00029         self.set_unity_option('shortcut_overlay', True)
00030         self.skip_if_monitor_too_small()
00031         sleep(1)
00032 
00033     def skip_if_monitor_too_small(self):
00034         monitor = self.screen_geo.get_primary_monitor()
00035         monitor_geo = self.screen_geo.get_monitor_geometry(monitor);
00036         monitor_w = monitor_geo[2];
00037         monitor_h = monitor_geo[3];
00038         launcher_width = self.launcher.get_launcher_for_monitor(monitor).geometry[2];
00039         panel_height = 24 # TODO get it from panel
00040 
00041         if ((monitor_w - launcher_width) <= self.DEFAULT_WIDTH or
00042             (monitor_h - panel_height) <= self.DEFAULT_HEIGHT):
00043             self.skipTest("This test requires a bigger screen, to show the ShortcutHint")
00044 
00045     def get_shortcut_controller(self):
00046         controllers = ShortcutController.get_all_instances()
00047         self.assertThat(len(controllers), Equals(1))
00048         return controllers[0]
00049 
00050     def get_launcher(self):
00051         # We could parameterise this so all tests run on both monitors (if MM is
00052         # set up), but I think it's fine to just always use monitor primary monitor:
00053         monitor = self.screen_geo.get_primary_monitor()
00054         return self.launcher.get_launcher_for_monitor(monitor)
00055 
00056 
00057 class ShortcutHintTests(BaseShortcutHintTests):
00058     """Tests for the shortcut hint functionality in isolation."""
00059 
00060     def test_shortcut_hint_reveal(self):
00061         """Test that the shortcut hint is shown."""
00062         self.shortcut_hint.show()
00063         self.addCleanup(self.shortcut_hint.ensure_hidden)
00064         self.assertThat(self.shortcut_hint.visible, Eventually(Equals(True)))
00065 
00066     def test_shortcut_hint_reveal_timeout(self):
00067         """Shortcut hint must be shown after a sufficient timeout."""
00068         timeout = self.shortcut_hint.get_show_timeout()
00069         self.shortcut_hint.show()
00070         self.addCleanup(self.shortcut_hint.ensure_hidden)
00071 
00072         sleep(timeout/2.0)
00073         self.assertThat(self.shortcut_hint.visible, Equals(False))
00074         # This should happen after 3/4 of 'timeout':
00075         self.assertThat(self.shortcut_hint.visible, Eventually(Equals(True)))
00076 
00077     def test_shortcut_hint_unreveal(self):
00078         """Shortcut hint must hide when keys are released."""
00079         self.shortcut_hint.ensure_visible()
00080         self.shortcut_hint.hide()
00081         self.assertThat(self.shortcut_hint.visible, Eventually(Equals(False)))
00082 
00083     def test_shortcut_hint_cancel(self):
00084         """Shortcut hint must hide when cancelled."""
00085         self.shortcut_hint.ensure_visible()
00086         self.shortcut_hint.cancel()
00087         self.assertThat(self.shortcut_hint.visible, Eventually(Equals(False)))
00088 
00089     def test_shortcut_hint_no_blur(self):
00090         """"""
00091         self.shortcut_hint.ensure_visible()
00092         self.addCleanup(self.shortcut_hint.ensure_hidden)
00093 
00094         self.assertThat(self.shortcut_hint.get_shortcut_view().bg_texture_is_valid, Eventually(Equals(True)))
00095 
00096 class ShortcutHintInteractionsTests(BaseShortcutHintTests):
00097     """Test the shortcuthint interactions with other Unity parts."""
00098 
00099     def test_shortcut_hint_hide_using_unity_shortcuts(self):
00100         """Unity shortcuts (like expo) must hide the shortcut hint."""
00101         self.shortcut_hint.ensure_visible()
00102         self.addCleanup(self.shortcut_hint.ensure_hidden)
00103 
00104         self.keybinding_tap("expo/start")
00105         self.addCleanup(self.keybinding, "expo/cancel")
00106 
00107     def test_shortcut_hint_hide_pressing_modifiers(self):
00108         """Pressing a modifer key must hide the shortcut hint."""
00109         self.shortcut_hint.ensure_visible()
00110         self.addCleanup(self.shortcut_hint.ensure_hidden)
00111 
00112         self.keyboard.press('Control')
00113 
00114         self.assertThat(self.shortcut_hint.visible, Eventually(Equals(False)))
00115 
00116     def test_launcher_switcher_next_doesnt_show_shortcut_hint(self):
00117         """Super+Tab switcher cycling forward must not show shortcut hint."""
00118         switcher_timeout = self.shortcut_hint.get_show_timeout()
00119         self.shortcut_hint.show()
00120         self.addCleanup(self.shortcut_hint.ensure_hidden)
00121 
00122         self.keybinding("launcher/switcher/next")
00123         self.keybinding("launcher/switcher/next")
00124         self.addCleanup(self.keyboard.press_and_release, "Escape")
00125         sleep(switcher_timeout * 2)
00126 
00127         self.assertThat(self.shortcut_hint.visible, Equals(False))
00128 
00129     def test_launcher_switcher_prev_doesnt_show_shortcut_hint(self):
00130         """Super+Tab switcher cycling backwards must not show shortcut hint."""
00131         switcher_timeout = self.shortcut_hint.get_show_timeout()
00132         self.shortcut_hint.show()
00133         self.addCleanup(self.shortcut_hint.ensure_hidden)
00134 
00135         self.keybinding("launcher/switcher/next")
00136         self.addCleanup(self.keyboard.press_and_release, "Escape")
00137         self.keybinding("launcher/switcher/next")
00138         self.keybinding("launcher/switcher/prev")
00139         sleep(switcher_timeout * 2)
00140 
00141         self.assertThat(self.shortcut_hint.visible, Equals(False))
00142 
00143     def test_launcher_icons_hints_show_with_shortcut_hint(self):
00144         """When the shortcut hint is shown also the launcer's icons hints should
00145         be shown.
00146 
00147         """
00148         launcher = self.get_launcher()
00149         self.shortcut_hint.ensure_visible()
00150         self.addCleanup(self.shortcut_hint.ensure_hidden)
00151 
00152         self.assertThat(self.shortcut_hint.visible, Equals(True))
00153         self.assertThat(launcher.shortcuts_shown, Equals(True))
00154 
00155     def test_shortcut_hint_shows_with_launcher_icons_hints(self):
00156         """When the launcher icons hints are shown also the shortcut hint should
00157         be shown.
00158 
00159         """
00160         launcher = self.get_launcher()
00161         launcher.keyboard_reveal_launcher()
00162         self.addCleanup(launcher.keyboard_unreveal_launcher)
00163 
00164         self.assertThat(launcher.shortcuts_shown, Eventually(Equals(True)))
00165         self.assertThat(self.shortcut_hint.visible, Eventually(Equals(True)))