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 """A Telemetry page_action that performs the "drag" action on pages. | 5 """A Telemetry page_action that performs the "drag" action on pages. |
6 | 6 |
7 Action parameters are: | 7 Action parameters are: |
8 - selector: If no selector is defined then the action attempts to drag the | 8 - selector: If no selector is defined then the action attempts to drag the |
9 document element on the page. | 9 document element on the page. |
10 - element_function: CSS selector used to evaluate callback when test completes | 10 - element_function: CSS selector used to evaluate callback when test completes |
11 - text: The element with exact text is selected. | 11 - text: The element with exact text is selected. |
12 - left_start_ratio: ratio of start point's left coordinate to the element | 12 - left_start_ratio: ratio of start point's left coordinate to the element |
13 width. | 13 width. |
14 - top_start_ratio: ratio of start point's top coordinate to the element height. | 14 - top_start_ratio: ratio of start point's top coordinate to the element height. |
15 - left_end_ratio: ratio of end point's left coordinate to the element width. | 15 - left_end_ratio: ratio of end point's left coordinate to the element width. |
16 - left_end_ratio: ratio of end point's top coordinate to the element height. | 16 - left_end_ratio: ratio of end point's top coordinate to the element height. |
17 - speed_in_pixels_per_second: speed of the drag gesture in pixels per second. | 17 - speed_in_pixels_per_second: speed of the drag gesture in pixels per second. |
18 - use_touch: boolean value to specify if gesture should use touch input or not. | 18 - use_touch: boolean value to specify if gesture should use touch input or not. |
19 """ | 19 """ |
20 | 20 |
21 import os | |
22 | |
23 from telemetry.internal.actions import page_action | 21 from telemetry.internal.actions import page_action |
| 22 from telemetry.internal.actions import utils |
24 | 23 |
25 | 24 |
26 class DragAction(page_action.PageAction): | 25 class DragAction(page_action.PageAction): |
27 | 26 |
28 def __init__(self, selector=None, text=None, element_function=None, | 27 def __init__(self, selector=None, text=None, element_function=None, |
29 left_start_ratio=None, top_start_ratio=None, left_end_ratio=None, | 28 left_start_ratio=None, top_start_ratio=None, left_end_ratio=None, |
30 top_end_ratio=None, speed_in_pixels_per_second=800, | 29 top_end_ratio=None, speed_in_pixels_per_second=800, |
31 use_touch=False, | 30 use_touch=False, |
32 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): | 31 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): |
33 super(DragAction, self).__init__() | 32 super(DragAction, self).__init__() |
34 self._selector = selector | 33 self._selector = selector |
35 self._text = text | 34 self._text = text |
36 self._element_function = element_function | 35 self._element_function = element_function |
37 self._left_start_ratio = left_start_ratio | 36 self._left_start_ratio = left_start_ratio |
38 self._top_start_ratio = top_start_ratio | 37 self._top_start_ratio = top_start_ratio |
39 self._left_end_ratio = left_end_ratio | 38 self._left_end_ratio = left_end_ratio |
40 self._top_end_ratio = top_end_ratio | 39 self._top_end_ratio = top_end_ratio |
41 self._speed = speed_in_pixels_per_second | 40 self._speed = speed_in_pixels_per_second |
42 self._use_touch = use_touch | 41 self._use_touch = use_touch |
43 self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % | 42 self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % |
44 synthetic_gesture_source) | 43 synthetic_gesture_source) |
45 | 44 |
46 def WillRunAction(self, tab): | 45 def WillRunAction(self, tab): |
47 for js_file in ['gesture_common.js', 'drag.js']: | 46 utils.InjectJavaScript(tab, 'gesture_common.js') |
48 with open(os.path.join(os.path.dirname(__file__), js_file)) as f: | 47 utils.InjectJavaScript(tab, 'drag.js') |
49 js = f.read() | |
50 tab.ExecuteJavaScript(js) | |
51 | 48 |
52 # Fail if browser doesn't support synthetic drag gestures. | 49 # Fail if browser doesn't support synthetic drag gestures. |
53 if not tab.EvaluateJavaScript('window.__DragAction_SupportedByBrowser()'): | 50 if not tab.EvaluateJavaScript('window.__DragAction_SupportedByBrowser()'): |
54 raise page_action.PageActionNotSupported( | 51 raise page_action.PageActionNotSupported( |
55 'Synthetic drag not supported for this browser') | 52 'Synthetic drag not supported for this browser') |
56 | 53 |
57 # Fail if this action requires touch and we can't send touch events. | 54 # Fail if this action requires touch and we can't send touch events. |
58 if self._use_touch: | 55 if self._use_touch: |
59 if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): | 56 if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): |
60 raise page_action.PageActionNotSupported( | 57 raise page_action.PageActionNotSupported( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 }''' % (self._left_start_ratio, | 95 }''' % (self._left_start_ratio, |
99 self._top_start_ratio, | 96 self._top_start_ratio, |
100 self._left_end_ratio, | 97 self._left_end_ratio, |
101 self._top_end_ratio, | 98 self._top_end_ratio, |
102 self._speed, | 99 self._speed, |
103 gesture_source_type) | 100 gesture_source_type) |
104 page_action.EvaluateCallbackWithElement( | 101 page_action.EvaluateCallbackWithElement( |
105 tab, code, selector=self._selector, text=self._text, | 102 tab, code, selector=self._selector, text=self._text, |
106 element_function=self._element_function) | 103 element_function=self._element_function) |
107 tab.WaitForJavaScriptExpression('window.__dragActionDone', 60) | 104 tab.WaitForJavaScriptExpression('window.__dragActionDone', 60) |
OLD | NEW |