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 |
| 6 |
5 from telemetry.internal.actions import page_action | 7 from telemetry.internal.actions import page_action |
| 8 from telemetry.internal.actions import utils |
6 from telemetry.web_perf import timeline_interaction_record | 9 from telemetry.web_perf import timeline_interaction_record |
7 | 10 |
8 | 11 |
9 class RepeatableScrollAction(page_action.PageAction): | 12 class RepeatableScrollAction(page_action.PageAction): |
10 | 13 |
11 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, |
12 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): |
13 super(RepeatableScrollAction, self).__init__() | 17 super(RepeatableScrollAction, self).__init__() |
14 self._x_scroll_distance_ratio = x_scroll_distance_ratio | 18 self._x_scroll_distance_ratio = x_scroll_distance_ratio |
15 self._y_scroll_distance_ratio = y_scroll_distance_ratio | 19 self._y_scroll_distance_ratio = y_scroll_distance_ratio |
16 self._repeat_count = repeat_count | 20 self._repeat_count = repeat_count |
17 self._repeat_delay_ms = repeat_delay_ms | 21 self._repeat_delay_ms = repeat_delay_ms |
18 self._windowsize = [] | 22 self._windowsize = [] |
19 self._timeout = timeout | 23 self._timeout = timeout |
| 24 self._prevent_fling = prevent_fling |
| 25 self._speed = speed |
20 | 26 |
21 def WillRunAction(self, tab): | 27 def WillRunAction(self, tab): |
| 28 utils.InjectJavaScript(tab, 'gesture_common.js') |
22 # Get the dimensions of the screen. | 29 # Get the dimensions of the screen. |
23 window_info_js = 'window.innerWidth + "," + window.innerHeight' | 30 self._windowsize = tab.EvaluateJavaScript( |
24 js_result = tab.EvaluateJavaScript(window_info_js).split(',') | 31 '[__GestureCommon_GetWindowWidth(),' |
25 | 32 ' __GestureCommon_GetWindowHeight()]') |
26 self._windowsize = [int(js_result[0]), int(js_result[1])] | 33 assert len(self._windowsize) == 2 |
| 34 assert all(isinstance(d, numbers.Number) for d in self._windowsize) |
27 | 35 |
28 def RunAction(self, tab): | 36 def RunAction(self, tab): |
29 # Set up a browser driven repeating scroll. The delay between the scrolls | 37 # Set up a browser driven repeating scroll. The delay between the scrolls |
30 # should be unaffected by render thread responsivness (or lack there of). | 38 # should be unaffected by render thread responsivness (or lack there of). |
31 tab.SynthesizeScrollGesture( | 39 tab.SynthesizeScrollGesture( |
32 x=int(self._windowsize[0] / 2), | 40 x=int(self._windowsize[0] / 2), |
33 y=int(self._windowsize[1] / 2), | 41 y=int(self._windowsize[1] / 2), |
34 xDistance=int(self._x_scroll_distance_ratio * self._windowsize[0]), | 42 xDistance=int(self._x_scroll_distance_ratio * self._windowsize[0]), |
35 yDistance=int(-self._y_scroll_distance_ratio * self._windowsize[1]), | 43 yDistance=int(-self._y_scroll_distance_ratio * self._windowsize[1]), |
| 44 preventFling=self._prevent_fling, |
| 45 speed=self._speed, |
36 repeatCount=self._repeat_count, | 46 repeatCount=self._repeat_count, |
37 repeatDelayMs=self._repeat_delay_ms, | 47 repeatDelayMs=self._repeat_delay_ms, |
38 interactionMarkerName=timeline_interaction_record.GetJavaScriptMarker( | 48 interactionMarkerName=timeline_interaction_record.GetJavaScriptMarker( |
39 'Gesture_ScrollAction', [timeline_interaction_record.REPEATABLE]), | 49 'Gesture_ScrollAction', [timeline_interaction_record.REPEATABLE]), |
40 timeout=self._timeout) | 50 timeout=self._timeout) |
OLD | NEW |