Merge lp:~townsend/unity/fix-ap-mouse-infinite-loop into lp:unity

Proposed by Christopher Townsend
Status: Merged
Approved by: Francis Ginther
Approved revision: no longer in the source branch.
Merged at revision: 3512
Proposed branch: lp:~townsend/unity/fix-ap-mouse-infinite-loop
Merge into: lp:unity
Diff against target: 108 lines (+23/-38)
2 files modified
tests/autopilot/unity/emulators/launcher.py (+21/-36)
tests/autopilot/unity/tests/launcher/test_scroll.py (+2/-2)
To merge this branch: bzr merge lp:~townsend/unity/fix-ap-mouse-infinite-loop
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Brandon Schaefer (community) Approve
Review via email: mp+186070@code.launchpad.net

Commit message

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.

Description of the change

= Issue =
Some AP tests will move the mouse to a specific icon. The function to handle moving the mouse to the icon contained an infinite loop to move the mouse. The infinite loop was to make sure the Launcher would scroll since the icon could be off the screen. However, certain conditions can cause the Launcher to not scroll which led to a very long delay in the AP test of 7200 seconds! This also led to no movie of the failure to be created.

= Fix =
Instead of using an infinite while loop, now instead use a for loop and only iterate 10 times with a 0.5 second delay between movements. If the icon is not found after the loop terminates, raise an error which will fail the test and we should have a movie of what was causing the Launcher to not scroll.

I also consolidated the autoscroll_to_icon(0 function into the move_mouse_to_icon() function and added support to the move_mouse_to_icon() function to handle autscrolling offsets.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/autopilot/unity/emulators/launcher.py'
--- tests/autopilot/unity/emulators/launcher.py 2013-09-12 15:56:41 +0000
+++ tests/autopilot/unity/emulators/launcher.py 2013-09-17 15:16:51 +0000
@@ -121,16 +121,28 @@
121 logger.debug("Moving mouse to center of launcher.")121 logger.debug("Moving mouse to center of launcher.")
122 self._mouse.move(target_x, target_y)122 self._mouse.move(target_x, target_y)
123123
124 def move_mouse_to_icon(self, icon):124 def move_mouse_to_icon(self, icon, autoscroll_offset=0):
125 # The icon may be off the bottom of screen, so we do this in a loop:125 """Move the mouse to a specific icon."""
126 while 1:126 (x, y, w, h) = self.geometry
127 target_x = icon.center_x + self.x127 found = False
128 target_y = icon.center_y128
129 # Only try 10 times (5 secs.) before giving up.
130 for i in xrange(0, 10):
131 mouse_x = target_x = icon.center_x + self.x
132 mouse_y = target_y = icon.center_y
133 if target_y > h:
134 mouse_y = h + y - autoscroll_offset
135 elif target_y < 0:
136 mouse_y = y + autoscroll_offset
129 if self._mouse.x == target_x and self._mouse.y == target_y:137 if self._mouse.x == target_x and self._mouse.y == target_y:
138 found = True
130 break139 break
131 self._mouse.move(target_x, target_y)140 self._mouse.move(mouse_x, mouse_y)
132 sleep(0.5)141 sleep(0.5)
133142
143 if not found:
144 raise RuntimeError("Could not move mouse to the icon")
145
134 def mouse_reveal_launcher(self):146 def mouse_reveal_launcher(self):
135 """Reveal this launcher with the mouse.147 """Reveal this launcher with the mouse.
136148
@@ -309,17 +321,11 @@
309321
310 logger.debug("Clicking launcher icon %r on monitor %d with mouse button %d",322 logger.debug("Clicking launcher icon %r on monitor %d with mouse button %d",
311 icon, self.monitor, button)323 icon, self.monitor, button)
324
312 self.mouse_reveal_launcher()325 self.mouse_reveal_launcher()
313326 self.move_mouse_to_icon(icon)
314 # The icon may be off the screen, so we do this in a loop:
315 while 1:
316 target_x = icon.center_x + self.x
317 target_y = icon.center_y
318 if self._mouse.x == target_x and self._mouse.y == target_y:
319 break
320 self._mouse.move(target_x, target_y )
321 sleep(1)
322 self._mouse.click(button)327 self._mouse.click(button)
328
323 if (move_mouse_after):329 if (move_mouse_after):
324 self.move_mouse_to_right_of_launcher()330 self.move_mouse_to_right_of_launcher()
325331
@@ -422,27 +428,6 @@
422 pin_item = quicklist.get_quicklist_item_by_text('Unlock from Launcher')428 pin_item = quicklist.get_quicklist_item_by_text('Unlock from Launcher')
423 quicklist.click_item(pin_item)429 quicklist.click_item(pin_item)
424430
425 def autoscroll_to_icon(self, icon, autoscroll_offset=0):
426 """Moves the mouse to the autoscroll zone to scroll the Launcher to the icon
427 in question.
428
429 autoscroll_offet is the offset, in number of pixels, from the end of the
430 autoscroll zone where is the autoscroll zone is currently 24 pixels high.
431 """
432 (x, y, w, h) = self.geometry
433
434 while 1:
435 mouse_x = target_x = icon.center_x + self.x
436 mouse_y = target_y = icon.center_y
437 if target_y > h:
438 mouse_y = h + y - autoscroll_offset
439 elif target_y < 0:
440 mouse_y = y + autoscroll_offset
441 if self._mouse.x == target_x and self._mouse.y == target_y:
442 break
443 self._mouse.move(mouse_x, mouse_y)
444 sleep(0.5)
445
446 @property431 @property
447 def geometry(self):432 def geometry(self):
448 """Returns a tuple of (x,y,w,h) for the current launcher."""433 """Returns a tuple of (x,y,w,h) for the current launcher."""
449434
=== modified file 'tests/autopilot/unity/tests/launcher/test_scroll.py'
--- tests/autopilot/unity/tests/launcher/test_scroll.py 2013-05-20 10:36:31 +0000
+++ tests/autopilot/unity/tests/launcher/test_scroll.py 2013-09-17 15:16:51 +0000
@@ -58,7 +58,7 @@
58 self.assertThat(last_icon.center_y, Eventually(GreaterThan(h)))58 self.assertThat(last_icon.center_y, Eventually(GreaterThan(h)))
5959
60 # Autoscroll to the last icon60 # Autoscroll to the last icon
61 launcher_instance.autoscroll_to_icon(last_icon, autoscroll_offset)61 launcher_instance.move_mouse_to_icon(last_icon, autoscroll_offset)
62 62
63 (x_fin, y_fin) = self.mouse.position()63 (x_fin, y_fin) = self.mouse.position()
6464
@@ -90,7 +90,7 @@
90 self.assertThat(first_icon.center_y, Eventually(LessThan(y)))90 self.assertThat(first_icon.center_y, Eventually(LessThan(y)))
91 91
92 # Autoscroll to the first icon92 # Autoscroll to the first icon
93 launcher_instance.autoscroll_to_icon(first_icon, autoscroll_offset)93 launcher_instance.move_mouse_to_icon(first_icon, autoscroll_offset)
9494
95 (x_fin, y_fin) = self.mouse.position()95 (x_fin, y_fin) = self.mouse.position()
9696