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
3 # found in the LICENSE file.
7 from telemetry
.internal
.actions
import page_action
8 from telemetry
.internal
.actions
import utils
9 from telemetry
.web_perf
import timeline_interaction_record
12 class RepeatableScrollAction(page_action
.PageAction
):
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,
16 prevent_fling
=None, speed
=None):
17 super(RepeatableScrollAction
, self
).__init
__()
18 self
._x
_scroll
_distance
_ratio
= x_scroll_distance_ratio
19 self
._y
_scroll
_distance
_ratio
= y_scroll_distance_ratio
20 self
._repeat
_count
= repeat_count
21 self
._repeat
_delay
_ms
= repeat_delay_ms
23 self
._timeout
= timeout
24 self
._prevent
_fling
= prevent_fling
27 def WillRunAction(self
, tab
):
28 utils
.InjectJavaScript(tab
, 'gesture_common.js')
29 # Get the dimensions of the screen.
30 self
._windowsize
= tab
.EvaluateJavaScript(
31 '[__GestureCommon_GetWindowWidth(),'
32 ' __GestureCommon_GetWindowHeight()]')
33 assert len(self
._windowsize
) == 2
34 assert all(isinstance(d
, numbers
.Number
) for d
in self
._windowsize
)
36 def RunAction(self
, tab
):
37 # Set up a browser driven repeating scroll. The delay between the scrolls
38 # should be unaffected by render thread responsivness (or lack there of).
39 tab
.SynthesizeScrollGesture(
40 x
=int(self
._windowsize
[0] / 2),
41 y
=int(self
._windowsize
[1] / 2),
42 xDistance
=int(self
._x
_scroll
_distance
_ratio
* self
._windowsize
[0]),
43 yDistance
=int(-self
._y
_scroll
_distance
_ratio
* self
._windowsize
[1]),
44 preventFling
=self
._prevent
_fling
,
46 repeatCount
=self
._repeat
_count
,
47 repeatDelayMs
=self
._repeat
_delay
_ms
,
48 interactionMarkerName
=timeline_interaction_record
.GetJavaScriptMarker(
49 'Gesture_ScrollAction', [timeline_interaction_record
.REPEATABLE
]),
50 timeout
=self
._timeout
)