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