OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 from telemetry.internal.actions import page_action | 5 from telemetry.internal.actions import page_action |
6 from telemetry.internal.actions import utils | 6 from telemetry.internal.actions import utils |
7 from telemetry.util import js_template | 7 from telemetry.util import js_template |
8 | 8 |
9 | 9 |
10 class PinchAction(page_action.PageAction): | 10 class PinchAction(page_action.PageAction): |
11 def __init__(self, selector=None, text=None, element_function=None, | 11 def __init__(self, selector=None, text=None, element_function=None, |
12 left_anchor_ratio=0.5, top_anchor_ratio=0.5, | 12 left_anchor_ratio=0.5, top_anchor_ratio=0.5, |
13 scale_factor=None, speed_in_pixels_per_second=800, | 13 scale_factor=None, speed_in_pixels_per_second=800, |
14 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): | 14 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): |
15 super(PinchAction, self).__init__() | 15 super(PinchAction, self).__init__() |
16 self._selector = selector | 16 self._selector = selector |
17 self._text = text | 17 self._text = text |
18 self._element_function = element_function | 18 self._element_function = element_function |
19 self._left_anchor_ratio = left_anchor_ratio | 19 self._left_anchor_ratio = left_anchor_ratio |
20 self._top_anchor_ratio = top_anchor_ratio | 20 self._top_anchor_ratio = top_anchor_ratio |
21 self._scale_factor = scale_factor | 21 self._scale_factor = scale_factor |
22 self._speed = speed_in_pixels_per_second | 22 self._speed = speed_in_pixels_per_second |
23 self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % | 23 self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % |
24 synthetic_gesture_source) | 24 synthetic_gesture_source) |
25 | 25 |
26 if (self._selector is None and self._text is None and | 26 if (self._selector is None and self._text is None and |
27 self._element_function is None): | 27 self._element_function is None): |
28 self._element_function = 'document.body' | 28 self._element_function = 'document.body' |
29 | 29 |
| 30 def SimulatesUserInput(self): |
| 31 return True |
| 32 |
30 def WillRunAction(self, tab): | 33 def WillRunAction(self, tab): |
31 utils.InjectJavaScript(tab, 'gesture_common.js') | 34 utils.InjectJavaScript(tab, 'gesture_common.js') |
32 utils.InjectJavaScript(tab, 'pinch.js') | 35 utils.InjectJavaScript(tab, 'pinch.js') |
33 | 36 |
34 # Fail if browser doesn't support synthetic pinch gestures. | 37 # Fail if browser doesn't support synthetic pinch gestures. |
35 if not tab.EvaluateJavaScript('window.__PinchAction_SupportedByBrowser()'): | 38 if not tab.EvaluateJavaScript('window.__PinchAction_SupportedByBrowser()'): |
36 raise page_action.PageActionNotSupported( | 39 raise page_action.PageActionNotSupported( |
37 'Synthetic pinch not supported for this browser') | 40 'Synthetic pinch not supported for this browser') |
38 | 41 |
39 tab.ExecuteJavaScript(""" | 42 tab.ExecuteJavaScript(""" |
(...skipping 25 matching lines...) Expand all Loading... |
65 }); | 68 }); |
66 }''', | 69 }''', |
67 left_anchor_ratio=self._left_anchor_ratio, | 70 left_anchor_ratio=self._left_anchor_ratio, |
68 top_anchor_ratio=self._top_anchor_ratio, | 71 top_anchor_ratio=self._top_anchor_ratio, |
69 scale_factor=scale_factor, | 72 scale_factor=scale_factor, |
70 speed=self._speed) | 73 speed=self._speed) |
71 page_action.EvaluateCallbackWithElement( | 74 page_action.EvaluateCallbackWithElement( |
72 tab, code, selector=self._selector, text=self._text, | 75 tab, code, selector=self._selector, text=self._text, |
73 element_function=self._element_function) | 76 element_function=self._element_function) |
74 tab.WaitForJavaScriptCondition('window.__pinchActionDone', timeout=60) | 77 tab.WaitForJavaScriptCondition('window.__pinchActionDone', timeout=60) |
OLD | NEW |