Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: telemetry/telemetry/internal/actions/action_runner.py

Issue 2421433003: Add ScrollPageToElement to action_runner. (Closed)
Patch Set: Add ScrollPageToElement to action_runner. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 logging 5 import logging
6 import time 6 import time
7 import urlparse 7 import urlparse
8 8
9 from telemetry.internal.actions.drag import DragAction 9 from telemetry.internal.actions.drag import DragAction
10 from telemetry.internal.actions.javascript_click import ClickElementAction 10 from telemetry.internal.actions.javascript_click import ClickElementAction
11 from telemetry.internal.actions.key_event import KeyPressAction 11 from telemetry.internal.actions.key_event import KeyPressAction
12 from telemetry.internal.actions.load_media import LoadMediaAction 12 from telemetry.internal.actions.load_media import LoadMediaAction
13 from telemetry.internal.actions.loop import LoopAction 13 from telemetry.internal.actions.loop import LoopAction
14 from telemetry.internal.actions.mouse_click import MouseClickAction 14 from telemetry.internal.actions.mouse_click import MouseClickAction
15 from telemetry.internal.actions.navigate import NavigateAction 15 from telemetry.internal.actions.navigate import NavigateAction
16 from telemetry.internal.actions.page_action import GESTURE_SOURCE_DEFAULT 16 from telemetry.internal.actions.page_action import GESTURE_SOURCE_DEFAULT
17 from telemetry.internal.actions.page_action import SUPPORTED_GESTURE_SOURCES 17 from telemetry.internal.actions.page_action import SUPPORTED_GESTURE_SOURCES
18 from telemetry.internal.actions.pinch import PinchAction 18 from telemetry.internal.actions.pinch import PinchAction
19 from telemetry.internal.actions.play import PlayAction 19 from telemetry.internal.actions.play import PlayAction
20 from telemetry.internal.actions.repaint_continuously import ( 20 from telemetry.internal.actions.repaint_continuously import (
21 RepaintContinuouslyAction) 21 RepaintContinuouslyAction)
22 from telemetry.internal.actions.repeatable_scroll import RepeatableScrollAction 22 from telemetry.internal.actions.repeatable_scroll import RepeatableScrollAction
23 from telemetry.internal.actions.scroll import ScrollAction 23 from telemetry.internal.actions.scroll import ScrollAction
24 from telemetry.internal.actions.scroll_bounce import ScrollBounceAction 24 from telemetry.internal.actions.scroll_bounce import ScrollBounceAction
25 from telemetry.internal.actions.scroll_to_element import ScrollToElementAction
25 from telemetry.internal.actions.seek import SeekAction 26 from telemetry.internal.actions.seek import SeekAction
26 from telemetry.internal.actions.swipe import SwipeAction 27 from telemetry.internal.actions.swipe import SwipeAction
27 from telemetry.internal.actions.tap import TapAction 28 from telemetry.internal.actions.tap import TapAction
28 from telemetry.internal.actions.wait import WaitForElementAction 29 from telemetry.internal.actions.wait import WaitForElementAction
29 from telemetry.web_perf import timeline_interaction_record 30 from telemetry.web_perf import timeline_interaction_record
30 31
31 32
32 _DUMP_WAIT_TIME = 3 33 _DUMP_WAIT_TIME = 3
33 34
34 35
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 synthetic_gesture_source: the source input device type for the 387 synthetic_gesture_source: the source input device type for the
387 synthetic gesture: 'DEFAULT', 'TOUCH' or 'MOUSE'. 388 synthetic gesture: 'DEFAULT', 'TOUCH' or 'MOUSE'.
388 """ 389 """
389 assert synthetic_gesture_source in SUPPORTED_GESTURE_SOURCES 390 assert synthetic_gesture_source in SUPPORTED_GESTURE_SOURCES
390 self._RunAction(ScrollAction( 391 self._RunAction(ScrollAction(
391 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, 392 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio,
392 direction=direction, distance=distance, distance_expr=distance_expr, 393 direction=direction, distance=distance, distance_expr=distance_expr,
393 speed_in_pixels_per_second=speed_in_pixels_per_second, 394 speed_in_pixels_per_second=speed_in_pixels_per_second,
394 use_touch=use_touch, synthetic_gesture_source=synthetic_gesture_source)) 395 use_touch=use_touch, synthetic_gesture_source=synthetic_gesture_source))
395 396
397 def ScrollPageToElement(self, selector=None, element_function=None,
398 speed_in_pixels_per_second=800):
399 """Perform scroll gesture on page until an element is in view.
400
401 Args:
402 selector: A CSS selector describing the element.
403 element_function: A JavaScript function (as string) that is used
404 to retrieve the element. For example:
405 'function() { return foo.element; }'.
406 speed_in_pixels_per_second: Speed to scroll.
407 """
408 self._RunAction(ScrollToElementAction(
409 selector=selector, element_function=element_function,
410 speed_in_pixels_per_second=speed_in_pixels_per_second))
411
396 def RepeatableBrowserDrivenScroll(self, x_scroll_distance_ratio=0.0, 412 def RepeatableBrowserDrivenScroll(self, x_scroll_distance_ratio=0.0,
397 y_scroll_distance_ratio=0.5, 413 y_scroll_distance_ratio=0.5,
398 repeat_count=0, 414 repeat_count=0,
399 repeat_delay_ms=250, 415 repeat_delay_ms=250,
400 timeout=60, 416 timeout=60,
401 prevent_fling=None, 417 prevent_fling=None,
402 speed=None): 418 speed=None):
403 """Perform a browser driven repeatable scroll gesture. 419 """Perform a browser driven repeatable scroll gesture.
404 420
405 The scroll gesture is driven from the browser, this is useful because the 421 The scroll gesture is driven from the browser, this is useful because the
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 timeline_interaction_record.GetJavaScriptMarker( 797 timeline_interaction_record.GetJavaScriptMarker(
782 self._label, self._flags)) 798 self._label, self._flags))
783 799
784 def End(self): 800 def End(self):
785 assert self._started 801 assert self._started
786 self._started = False 802 self._started = False
787 self._action_runner.ExecuteJavaScript( 803 self._action_runner.ExecuteJavaScript(
788 'console.timeEnd("%s");' % 804 'console.timeEnd("%s");' %
789 timeline_interaction_record.GetJavaScriptMarker( 805 timeline_interaction_record.GetJavaScriptMarker(
790 self._label, self._flags)) 806 self._label, self._flags))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698