OLD | NEW |
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 time | 5 import time |
6 import logging | 6 import logging |
7 import urlparse | 7 import urlparse |
8 | 8 |
| 9 from telemetry.page.actions.drag import DragAction |
9 from telemetry.page.actions.javascript_click import ClickElementAction | 10 from telemetry.page.actions.javascript_click import ClickElementAction |
10 from telemetry.page.actions.loop import LoopAction | 11 from telemetry.page.actions.loop import LoopAction |
11 from telemetry.page.actions.mouse_click import MouseClickAction | 12 from telemetry.page.actions.mouse_click import MouseClickAction |
12 from telemetry.page.actions.navigate import NavigateAction | 13 from telemetry.page.actions.navigate import NavigateAction |
13 from telemetry.page.actions.pinch import PinchAction | 14 from telemetry.page.actions.pinch import PinchAction |
14 from telemetry.page.actions.play import PlayAction | 15 from telemetry.page.actions.play import PlayAction |
15 from telemetry.page.actions.repaint_continuously import ( | 16 from telemetry.page.actions.repaint_continuously import ( |
16 RepaintContinuouslyAction) | 17 RepaintContinuouslyAction) |
17 from telemetry.page.actions.scroll import ScrollAction | 18 from telemetry.page.actions.scroll import ScrollAction |
18 from telemetry.page.actions.scroll_bounce import ScrollBounceAction | 19 from telemetry.page.actions.scroll_bounce import ScrollBounceAction |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 Args: | 233 Args: |
233 selector: A CSS selector describing the element. | 234 selector: A CSS selector describing the element. |
234 text: The element must contains this exact text. | 235 text: The element must contains this exact text. |
235 element_function: A JavaScript function (as string) that is used | 236 element_function: A JavaScript function (as string) that is used |
236 to retrieve the element. For example: | 237 to retrieve the element. For example: |
237 '(function() { return foo.element; })()'. | 238 '(function() { return foo.element; })()'. |
238 """ | 239 """ |
239 self._RunAction(ClickElementAction( | 240 self._RunAction(ClickElementAction( |
240 selector=selector, text=text, element_function=element_function)) | 241 selector=selector, text=text, element_function=element_function)) |
241 | 242 |
| 243 def DragPage(self, left_start_ratio, top_start_ratio, left_end_ratio, |
| 244 top_end_ratio, speed_in_pixels_per_second=800, use_touch=False): |
| 245 """Perform a drag gesture on the page. |
| 246 |
| 247 You should specify a start and an end point in ratios of page width and |
| 248 height (see drag.js for full implementation). |
| 249 |
| 250 Args: |
| 251 left_start_ratio: The horizontal starting coordinate of the |
| 252 gesture, as a ratio of the visible bounding rectangle for |
| 253 document.body. |
| 254 top_start_ratio: The vertical starting coordinate of the |
| 255 gesture, as a ratio of the visible bounding rectangle for |
| 256 document.body. |
| 257 left_end_ratio: The horizontal ending coordinate of the |
| 258 gesture, as a ratio of the visible bounding rectangle for |
| 259 document.body. |
| 260 top_end_ratio: The vertical ending coordinate of the |
| 261 gesture, as a ratio of the visible bounding rectangle for |
| 262 document.body. |
| 263 speed_in_pixels_per_second: The speed of the gesture (in pixels/s). |
| 264 use_touch: Whether dragging should be done with touch input. |
| 265 """ |
| 266 self._RunAction(DragAction( |
| 267 left_start_ratio=left_start_ratio, top_start_ratio=top_start_ratio, |
| 268 left_end_ratio=left_end_ratio, top_end_ratio=top_end_ratio, |
| 269 speed_in_pixels_per_second=speed_in_pixels_per_second, |
| 270 use_touch=use_touch)) |
| 271 |
242 def PinchPage(self, left_anchor_ratio=0.5, top_anchor_ratio=0.5, | 272 def PinchPage(self, left_anchor_ratio=0.5, top_anchor_ratio=0.5, |
243 scale_factor=None, speed_in_pixels_per_second=800): | 273 scale_factor=None, speed_in_pixels_per_second=800): |
244 """Perform the pinch gesture on the page. | 274 """Perform the pinch gesture on the page. |
245 | 275 |
246 It computes the pinch gesture automatically based on the anchor | 276 It computes the pinch gesture automatically based on the anchor |
247 coordinate and the scale factor. The scale factor is the ratio of | 277 coordinate and the scale factor. The scale factor is the ratio of |
248 of the final span and the initial span of the gesture. | 278 of the final span and the initial span of the gesture. |
249 | 279 |
250 Args: | 280 Args: |
251 left_anchor_ratio: The horizontal pinch anchor coordinate of the | 281 left_anchor_ratio: The horizontal pinch anchor coordinate of the |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 self._action_runner.ExecuteJavaScript('console.time("%s");' % | 641 self._action_runner.ExecuteJavaScript('console.time("%s");' % |
612 timeline_interaction_record.GetJavaScriptMarker( | 642 timeline_interaction_record.GetJavaScriptMarker( |
613 self._label, self._flags)) | 643 self._label, self._flags)) |
614 | 644 |
615 def End(self): | 645 def End(self): |
616 assert self._started | 646 assert self._started |
617 self._started = False | 647 self._started = False |
618 self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' % | 648 self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' % |
619 timeline_interaction_record.GetJavaScriptMarker( | 649 timeline_interaction_record.GetJavaScriptMarker( |
620 self._label, self._flags)) | 650 self._label, self._flags)) |
OLD | NEW |