Back to index

unity  6.0.0
test_capture.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.emulators.X11 import ScreenGeometry
00013 from autopilot.matchers import Eventually
00014 import logging
00015 from testtools.matchers import Equals, LessThan, GreaterThan
00016 from time import sleep
00017 
00018 from unity.tests import UnityTestCase
00019 
00020 logger = logging.getLogger(__name__)
00021 
00022 
00023 class LauncherCaptureTests(UnityTestCase):
00024     """Test the launchers ability to capture/not capture the mouse."""
00025 
00026     screen_geo = ScreenGeometry()
00027 
00028     def setUp(self):
00029         super(LauncherCaptureTests, self).setUp()
00030 
00031         if self.screen_geo.get_num_monitors() <= 1:
00032             self.skipTest("This test requires two or more monitors.")
00033 
00034         self.set_unity_option('launcher_capture_mouse', True)
00035         self.set_unity_option('num_launchers', 0)
00036         self.setHideMode(0)
00037 
00038     def setHideMode(self, mode):
00039         self.set_unity_option('launcher_hide_mode', mode)
00040         launcher = self.launcher.get_launcher_for_monitor(0)
00041         self.assertThat(launcher.hidemode, Eventually(Equals(mode)))
00042 
00043     def leftMostMonitor(self):
00044         x1, y1, width, height = self.screen_geo.get_monitor_geometry(0)
00045         x2, y2, width, height = self.screen_geo.get_monitor_geometry(1)
00046 
00047         if x1 < x2:
00048             return 0
00049         return 1
00050 
00051     def rightMostMonitor(self):
00052         # TODO: This will break setups with 3 or more monitors.
00053         return 1 - self.leftMostMonitor()
00054 
00055 
00056     def test_launcher_captures_while_sticky_and_revealed(self):
00057         """Tests that the launcher captures the mouse when moving between monitors
00058         while revealed.
00059         """
00060         x, y, width, height = self.screen_geo.get_monitor_geometry(self.rightMostMonitor())
00061         self.mouse.move(x + width / 2, y + height / 2, False)
00062         self.mouse.move(x - width / 2, y + height / 2, True, 5, .002)
00063 
00064         x_fin, y_fin = self.mouse.position()
00065         # The launcher should have held the mouse a little bit
00066         self.assertThat(x_fin, GreaterThan(x - width / 2))
00067 
00068     def test_launcher_not_capture_while_not_sticky_and_revealed(self):
00069         """Tests that the launcher doesn't captures the mouse when moving between monitors
00070         while revealed and stick is off.
00071         """
00072 
00073         self.set_unity_option('launcher_capture_mouse', False)
00074 
00075         x, y, width, height = self.screen_geo.get_monitor_geometry(self.rightMostMonitor())
00076         self.mouse.move(x + width / 2, y + height / 2, False)
00077         self.mouse.move(x - width / 2, y + height / 2, True, 5, .002)
00078 
00079         x_fin, y_fin = self.mouse.position()
00080         # The launcher should have held the mouse a little bit
00081         self.assertThat(x_fin, Equals(x - width / 2))
00082 
00083     def test_launcher_not_capture_while_not_sticky_and_hidden_moving_right(self):
00084         """Tests that the launcher doesn't capture the mouse when moving between monitors
00085         while hidden and sticky is off.
00086         """
00087 
00088         self.set_unity_option('launcher_capture_mouse', False)
00089         self.setHideMode(1)
00090 
00091         x, y, width, height = self.screen_geo.get_monitor_geometry(self.leftMostMonitor())
00092         self.mouse.move(x + width / 2, y + height / 2, False)
00093         sleep(1.5)
00094         self.mouse.move(x + width * 1.5, y + height / 2, True, 5, .002)
00095 
00096         x_fin, y_fin = self.mouse.position()
00097         # The launcher should have held the mouse a little bit
00098         self.assertThat(x_fin, Equals(x + width * 1.5))
00099 
00100     def test_launcher_capture_while_sticky_and_hidden_moving_right(self):
00101         """Tests that the launcher captures the mouse when moving between monitors
00102         while hidden.
00103         """
00104         self.setHideMode(1)
00105 
00106         x, y, width, height = self.screen_geo.get_monitor_geometry(self.leftMostMonitor())
00107         self.mouse.move(x + width / 2, y + height / 2, False)
00108         sleep(1.5)
00109         self.mouse.move(x + width * 1.5, y + height / 2, True, 5, .002)
00110 
00111         x_fin, y_fin = self.mouse.position()
00112         # The launcher should have held the mouse a little bit
00113         self.assertThat(x_fin, LessThan(x + width * 1.5))