| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import numbers | 5 import numbers |
| 6 | 6 |
| 7 from telemetry.internal.actions import page_action | 7 from telemetry.internal.actions import page_action |
| 8 from telemetry.internal.actions import utils | 8 from telemetry.internal.actions import utils |
| 9 from telemetry.web_perf import timeline_interaction_record | 9 from telemetry.web_perf import timeline_interaction_record |
| 10 | 10 |
| 11 | 11 |
| 12 class RepeatableScrollAction(page_action.PageAction): | 12 class RepeatableScrollAction(page_action.PageAction): |
| 13 | 13 |
| 14 def __init__(self, x_scroll_distance_ratio=0.0, y_scroll_distance_ratio=0.5, | 14 def __init__(self, x_scroll_distance_ratio=0.0, y_scroll_distance_ratio=0.5, |
| 15 repeat_count=0, repeat_delay_ms=250, timeout=60, | 15 repeat_count=0, repeat_delay_ms=250, timeout=60, |
| 16 prevent_fling=None, speed=None): | 16 prevent_fling=None, speed=None): |
| 17 super(RepeatableScrollAction, self).__init__() | 17 super(RepeatableScrollAction, self).__init__() |
| 18 self._x_scroll_distance_ratio = x_scroll_distance_ratio | 18 self._x_scroll_distance_ratio = x_scroll_distance_ratio |
| 19 self._y_scroll_distance_ratio = y_scroll_distance_ratio | 19 self._y_scroll_distance_ratio = y_scroll_distance_ratio |
| 20 self._repeat_count = repeat_count | 20 self._repeat_count = repeat_count |
| 21 self._repeat_delay_ms = repeat_delay_ms | 21 self._repeat_delay_ms = repeat_delay_ms |
| 22 self._windowsize = [] | 22 self._windowsize = [] |
| 23 self._timeout = timeout | 23 self._timeout = timeout |
| 24 self._prevent_fling = prevent_fling | 24 self._prevent_fling = prevent_fling |
| 25 self._speed = speed | 25 self._speed = speed |
| 26 | 26 |
| 27 def SimulatesUserInput(self): |
| 28 return True |
| 29 |
| 27 def WillRunAction(self, tab): | 30 def WillRunAction(self, tab): |
| 28 utils.InjectJavaScript(tab, 'gesture_common.js') | 31 utils.InjectJavaScript(tab, 'gesture_common.js') |
| 29 # Get the dimensions of the screen. | 32 # Get the dimensions of the screen. |
| 30 self._windowsize = tab.EvaluateJavaScript( | 33 self._windowsize = tab.EvaluateJavaScript( |
| 31 '[__GestureCommon_GetWindowWidth(),' | 34 '[__GestureCommon_GetWindowWidth(),' |
| 32 ' __GestureCommon_GetWindowHeight()]') | 35 ' __GestureCommon_GetWindowHeight()]') |
| 33 assert len(self._windowsize) == 2 | 36 assert len(self._windowsize) == 2 |
| 34 assert all(isinstance(d, numbers.Number) for d in self._windowsize) | 37 assert all(isinstance(d, numbers.Number) for d in self._windowsize) |
| 35 | 38 |
| 36 def RunAction(self, tab): | 39 def RunAction(self, tab): |
| 37 # Set up a browser driven repeating scroll. The delay between the scrolls | 40 # Set up a browser driven repeating scroll. The delay between the scrolls |
| 38 # should be unaffected by render thread responsivness (or lack there of). | 41 # should be unaffected by render thread responsivness (or lack there of). |
| 39 tab.SynthesizeScrollGesture( | 42 tab.SynthesizeScrollGesture( |
| 40 x=int(self._windowsize[0] / 2), | 43 x=int(self._windowsize[0] / 2), |
| 41 y=int(self._windowsize[1] / 2), | 44 y=int(self._windowsize[1] / 2), |
| 42 xDistance=int(self._x_scroll_distance_ratio * self._windowsize[0]), | 45 xDistance=int(self._x_scroll_distance_ratio * self._windowsize[0]), |
| 43 yDistance=int(-self._y_scroll_distance_ratio * self._windowsize[1]), | 46 yDistance=int(-self._y_scroll_distance_ratio * self._windowsize[1]), |
| 44 preventFling=self._prevent_fling, | 47 preventFling=self._prevent_fling, |
| 45 speed=self._speed, | 48 speed=self._speed, |
| 46 repeatCount=self._repeat_count, | 49 repeatCount=self._repeat_count, |
| 47 repeatDelayMs=self._repeat_delay_ms, | 50 repeatDelayMs=self._repeat_delay_ms, |
| 48 interactionMarkerName=timeline_interaction_record.GetJavaScriptMarker( | 51 interactionMarkerName=timeline_interaction_record.GetJavaScriptMarker( |
| 49 'Gesture_ScrollAction', [timeline_interaction_record.REPEATABLE]), | 52 'Gesture_ScrollAction', [timeline_interaction_record.REPEATABLE]), |
| 50 timeout=self._timeout) | 53 timeout=self._timeout) |
| OLD | NEW |