Back to index

unity  6.0.0
test_icon_behavior.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: Thomi Richards,
00004 #          Marco Trevisan (TreviƱo)
00005 #
00006 # This program is free software: you can redistribute it and/or modify it
00007 # under the terms of the GNU General Public License version 3, as published
00008 # by the Free Software Foundation.
00009 
00010 from __future__ import absolute_import
00011 
00012 from autopilot.matchers import Eventually
00013 from autopilot.testcase import multiply_scenarios
00014 import logging
00015 from testtools.matchers import Equals, NotEquals
00016 from time import sleep
00017 
00018 from unity.emulators.launcher import IconDragType
00019 from unity.tests.launcher import LauncherTestCase, _make_scenarios
00020 
00021 logger = logging.getLogger(__name__)
00022 
00023 
00024 class LauncherIconsTests(LauncherTestCase):
00025     """Test the launcher icons interactions"""
00026 
00027     def setUp(self):
00028         super(LauncherIconsTests, self).setUp()
00029         self.set_unity_option('launcher_hide_mode', 0)
00030 
00031     def test_bfb_tooltip_disappear_when_dash_is_opened(self):
00032          """Tests that the bfb tooltip disappear when the dash is opened."""
00033          bfb = self.launcher.model.get_bfb_icon()
00034          self.mouse.move(bfb.center_x, bfb.center_y)
00035 
00036          self.dash.ensure_visible()
00037          self.addCleanup(self.dash.ensure_hidden)
00038 
00039          self.assertThat(bfb.get_tooltip().active, Eventually(Equals(False)))
00040 
00041     def test_bfb_tooltip_is_disabled_when_dash_is_open(self):
00042          """Tests the that bfb tooltip is disabled when the dash is open."""
00043          self.dash.ensure_visible()
00044          self.addCleanup(self.dash.ensure_hidden)
00045 
00046          bfb = self.launcher.model.get_bfb_icon()
00047          self.mouse.move(bfb.center_x, bfb.center_y)
00048 
00049          self.assertThat(bfb.get_tooltip().active, Eventually(Equals(False)))
00050 
00051     def test_shift_click_opens_new_application_instance(self):
00052         """Shift+Clicking MUST open a new instance of an already-running application."""
00053         app = self.start_app("Calculator")
00054         desktop_id = app.desktop_file
00055         icon = self.launcher.model.get_icon_by_desktop_id(desktop_id)
00056         launcher_instance = self.launcher.get_launcher_for_monitor(0)
00057 
00058         self.keyboard.press("Shift")
00059         self.addCleanup(self.keyboard.release, "Shift")
00060         launcher_instance.click_launcher_icon(icon)
00061 
00062         self.assertNumberWinsIsEventually(app, 2)
00063 
00064     def test_launcher_activate_last_focused_window(self):
00065         """Activating a launcher icon must raise only the last focused instance
00066         of that application.
00067 
00068         """
00069         mah_win1 = self.start_app_window("Mahjongg")
00070         calc_win = self.start_app_window("Calculator")
00071         mah_win2 = self.start_app_window("Mahjongg")
00072 
00073         self.assertVisibleWindowStack([mah_win2, calc_win, mah_win1])
00074 
00075         mahj_icon = self.launcher.model.get_icon_by_desktop_id(
00076             mah_win2.application.desktop_file)
00077         calc_icon = self.launcher.model.get_icon_by_desktop_id(
00078             calc_win.application.desktop_file)
00079 
00080         self.launcher_instance.click_launcher_icon(calc_icon)
00081         self.assertProperty(calc_win, is_focused=True)
00082         self.assertVisibleWindowStack([calc_win, mah_win2, mah_win1])
00083 
00084         self.launcher_instance.click_launcher_icon(mahj_icon)
00085         self.assertProperty(mah_win2, is_focused=True)
00086         self.assertVisibleWindowStack([mah_win2, calc_win, mah_win1])
00087 
00088         self.keybinding("window/minimize")
00089 
00090         self.assertThat(lambda: mah_win2.is_hidden, Eventually(Equals(True)))
00091         self.assertProperty(calc_win, is_focused=True)
00092         self.assertVisibleWindowStack([calc_win, mah_win1])
00093 
00094         self.launcher_instance.click_launcher_icon(mahj_icon)
00095         self.assertProperty(mah_win1, is_focused=True)
00096         self.assertThat(lambda: mah_win2.is_hidden, Eventually(Equals(True)))
00097         self.assertVisibleWindowStack([mah_win1, calc_win])
00098 
00099     def test_clicking_icon_twice_initiates_spread(self):
00100         """This tests shows that when you click on a launcher icon twice,
00101         when an application window is focused, the spread is initiated.
00102         """
00103         calc_win1 = self.start_app_window("Calculator")
00104         calc_win2 = self.start_app_window("Calculator")
00105         calc_app = calc_win1.application
00106 
00107         self.assertVisibleWindowStack([calc_win2, calc_win1])
00108         self.assertProperty(calc_win2, is_focused=True)
00109 
00110         calc_icon = self.launcher.model.get_icon_by_desktop_id(calc_app.desktop_file)
00111         self.addCleanup(self.keybinding, "spread/cancel")
00112         self.launcher_instance.click_launcher_icon(calc_icon)
00113 
00114         self.assertThat(self.window_manager.scale_active, Eventually(Equals(True)))
00115         self.assertThat(self.window_manager.scale_active_for_group, Eventually(Equals(True)))
00116 
00117     def test_icon_shows_on_quick_application_reopen(self):
00118         """Icons must stay on launcher when an application is quickly closed/reopened."""
00119         calc = self.start_app("Calculator")
00120         desktop_file = calc.desktop_file
00121         calc_icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
00122         self.assertThat(calc_icon.visible, Eventually(Equals(True)))
00123 
00124         self.close_all_app("Calculator")
00125         calc = self.start_app("Calculator")
00126         sleep(2)
00127 
00128         calc_icon = self.launcher.model.get_icon_by_desktop_id(desktop_file)
00129         self.assertThat(calc_icon, NotEquals(None))
00130         self.assertThat(calc_icon.visible, Eventually(Equals(True)))
00131 
00132 
00133 class LauncherDragIconsBehavior(LauncherTestCase):
00134     """Tests dragging icons around the Launcher."""
00135 
00136     scenarios = multiply_scenarios(_make_scenarios(),
00137                                    [
00138                                        ('inside', {'drag_type': IconDragType.INSIDE}),
00139                                        ('outside', {'drag_type': IconDragType.OUTSIDE}),
00140                                    ])
00141 
00142     def ensure_calc_icon_not_in_launcher(self):
00143         """Wait until the launcher model updates and removes the calc icon."""
00144         refresh_fn = lambda: self.launcher.model.get_icon_by_desktop_id("gcalctool.desktop")
00145         self.assertThat(refresh_fn, Eventually(Equals(None)))
00146 
00147     def test_can_drag_icon_below_bfb(self):
00148         """Application icons must be draggable to below the BFB."""
00149 
00150         self.ensure_calc_icon_not_in_launcher()
00151         calc = self.start_app("Calculator")
00152         calc_icon = self.launcher.model.get_icon_by_desktop_id(calc.desktop_file)
00153 
00154         bfb_icon_position = 0
00155         self.launcher_instance.drag_icon_to_position(calc_icon,
00156                                                      bfb_icon_position,
00157                                                      self.drag_type)
00158         moved_icon = self.launcher.model.\
00159                      get_launcher_icons_for_monitor(self.launcher_monitor)[1]
00160         self.assertThat(moved_icon.id, Equals(calc_icon.id))
00161 
00162     def test_can_drag_icon_above_window_switcher(self):
00163         """Application icons must be dragable to above the workspace switcher icon."""
00164 
00165         self.ensure_calc_icon_not_in_launcher()
00166         calc = self.start_app("Calculator")
00167         calc_icon = self.launcher.model.get_icon_by_desktop_id(calc.desktop_file)
00168 
00169         # Move a known icon to the top as it needs to be more than 2 icon
00170         # spaces away for this test to actually do anything
00171         bfb_icon_position = 0
00172         self.launcher_instance.drag_icon_to_position(calc_icon,
00173                                                      bfb_icon_position,
00174                                                      self.drag_type)
00175         sleep(1)
00176         switcher_pos = -2
00177         self.launcher_instance.drag_icon_to_position(calc_icon,
00178                                                      switcher_pos,
00179                                                      self.drag_type)
00180 
00181         moved_icon = self.launcher.model.\
00182                      get_launcher_icons_for_monitor(self.launcher_monitor)[-3]
00183         self.assertThat(moved_icon.id, Equals(calc_icon.id))