summaryrefslogtreecommitdiff
path: root/tests
diff options
authorChris Townsend <christopher.townsend@canonical.com>2013-09-17 11:01:28 -0400
committerChris Townsend <christopher.townsend@canonical.com>2013-09-17 11:01:28 -0400
commit25027148d32b6c48f90c3365c8cd7ba42a681310 (patch)
treeb1b4cda0b3722649701bc794c04fec7cb06dcf17 /tests
parent9aca7b62bf4c22e1be0cd751cfb998e5a2a6d121 (diff)
Make the mouse movement infinite while loop into a for loop and only iterate 10 times w/ a 0.5 second delay between movements. Raise an error if the correct icon is not found when the loop terminates.
Consolidate the autoscroll_to_icon() function into the move_mouse_to_icon() function and change move_mouse_to_icon() to handle autoscrolling offsets. Fixes LP: #1226639 (bzr r3511.1.1)
Diffstat (limited to 'tests')
-rw-r--r--tests/autopilot/unity/emulators/launcher.py57
-rw-r--r--tests/autopilot/unity/tests/launcher/test_scroll.py4
2 files changed, 23 insertions, 38 deletions
diff --git a/tests/autopilot/unity/emulators/launcher.py b/tests/autopilot/unity/emulators/launcher.py
index 42e4a1ae8..7c2033886 100644
--- a/tests/autopilot/unity/emulators/launcher.py
+++ b/tests/autopilot/unity/emulators/launcher.py
@@ -121,16 +121,28 @@ class Launcher(UnityIntrospectionObject, KeybindingsHelper):
logger.debug("Moving mouse to center of launcher.")
self._mouse.move(target_x, target_y)
- def move_mouse_to_icon(self, icon):
- # The icon may be off the bottom of screen, so we do this in a loop:
- while 1:
- target_x = icon.center_x + self.x
- target_y = icon.center_y
+ def move_mouse_to_icon(self, icon, autoscroll_offset=0):
+ """Move the mouse to a specific icon."""
+ (x, y, w, h) = self.geometry
+ found = False
+
+ # Only try 10 times (5 secs.) before giving up.
+ for i in xrange(0, 10):
+ mouse_x = target_x = icon.center_x + self.x
+ mouse_y = target_y = icon.center_y
+ if target_y > h:
+ mouse_y = h + y - autoscroll_offset
+ elif target_y < 0:
+ mouse_y = y + autoscroll_offset
if self._mouse.x == target_x and self._mouse.y == target_y:
+ found = True
break
- self._mouse.move(target_x, target_y)
+ self._mouse.move(mouse_x, mouse_y)
sleep(0.5)
+ if not found:
+ raise RuntimeError("Could not move mouse to the icon")
+
def mouse_reveal_launcher(self):
"""Reveal this launcher with the mouse.
@@ -309,17 +321,11 @@ class Launcher(UnityIntrospectionObject, KeybindingsHelper):
logger.debug("Clicking launcher icon %r on monitor %d with mouse button %d",
icon, self.monitor, button)
- self.mouse_reveal_launcher()
- # The icon may be off the screen, so we do this in a loop:
- while 1:
- target_x = icon.center_x + self.x
- target_y = icon.center_y
- if self._mouse.x == target_x and self._mouse.y == target_y:
- break
- self._mouse.move(target_x, target_y )
- sleep(1)
+ self.mouse_reveal_launcher()
+ self.move_mouse_to_icon(icon)
self._mouse.click(button)
+
if (move_mouse_after):
self.move_mouse_to_right_of_launcher()
@@ -422,27 +428,6 @@ class Launcher(UnityIntrospectionObject, KeybindingsHelper):
pin_item = quicklist.get_quicklist_item_by_text('Unlock from Launcher')
quicklist.click_item(pin_item)
- def autoscroll_to_icon(self, icon, autoscroll_offset=0):
- """Moves the mouse to the autoscroll zone to scroll the Launcher to the icon
- in question.
-
- autoscroll_offet is the offset, in number of pixels, from the end of the
- autoscroll zone where is the autoscroll zone is currently 24 pixels high.
- """
- (x, y, w, h) = self.geometry
-
- while 1:
- mouse_x = target_x = icon.center_x + self.x
- mouse_y = target_y = icon.center_y
- if target_y > h:
- mouse_y = h + y - autoscroll_offset
- elif target_y < 0:
- mouse_y = y + autoscroll_offset
- if self._mouse.x == target_x and self._mouse.y == target_y:
- break
- self._mouse.move(mouse_x, mouse_y)
- sleep(0.5)
-
@property
def geometry(self):
"""Returns a tuple of (x,y,w,h) for the current launcher."""
diff --git a/tests/autopilot/unity/tests/launcher/test_scroll.py b/tests/autopilot/unity/tests/launcher/test_scroll.py
index f2b6fc93b..31c162290 100644
--- a/tests/autopilot/unity/tests/launcher/test_scroll.py
+++ b/tests/autopilot/unity/tests/launcher/test_scroll.py
@@ -58,7 +58,7 @@ class LauncherScrollTests(LauncherTestCase):
self.assertThat(last_icon.center_y, Eventually(GreaterThan(h)))
# Autoscroll to the last icon
- launcher_instance.autoscroll_to_icon(last_icon, autoscroll_offset)
+ launcher_instance.move_mouse_to_icon(last_icon, autoscroll_offset)
(x_fin, y_fin) = self.mouse.position()
@@ -90,7 +90,7 @@ class LauncherScrollTests(LauncherTestCase):
self.assertThat(first_icon.center_y, Eventually(LessThan(y)))
# Autoscroll to the first icon
- launcher_instance.autoscroll_to_icon(first_icon, autoscroll_offset)
+ launcher_instance.move_mouse_to_icon(first_icon, autoscroll_offset)
(x_fin, y_fin) = self.mouse.position()