| 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 SwipeAction(page_action.PageAction): | 10 class SwipeAction(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_start_ratio=0.5, top_start_ratio=0.5, | 12 left_start_ratio=0.5, top_start_ratio=0.5, |
| 13 direction='left', distance=100, speed_in_pixels_per_second=800, | 13 direction='left', distance=100, 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(SwipeAction, self).__init__() | 15 super(SwipeAction, self).__init__() |
| 16 if direction not in ['down', 'up', 'left', 'right']: | 16 if direction not in ['down', 'up', 'left', 'right']: |
| 17 raise page_action.PageActionNotSupported( | 17 raise page_action.PageActionNotSupported( |
| 18 'Invalid swipe direction: %s' % self.direction) | 18 'Invalid swipe direction: %s' % self.direction) |
| 19 self._selector = selector | 19 self._selector = selector |
| 20 self._text = text | 20 self._text = text |
| 21 self._element_function = element_function | 21 self._element_function = element_function |
| 22 self._left_start_ratio = left_start_ratio | 22 self._left_start_ratio = left_start_ratio |
| 23 self._top_start_ratio = top_start_ratio | 23 self._top_start_ratio = top_start_ratio |
| 24 self._direction = direction | 24 self._direction = direction |
| 25 self._distance = distance | 25 self._distance = distance |
| 26 self._speed = speed_in_pixels_per_second | 26 self._speed = speed_in_pixels_per_second |
| 27 self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % | 27 self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % |
| 28 synthetic_gesture_source) | 28 synthetic_gesture_source) |
| 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, 'swipe.js') | 35 utils.InjectJavaScript(tab, 'swipe.js') |
| 33 | 36 |
| 34 # Fail if browser doesn't support synthetic swipe gestures. | 37 # Fail if browser doesn't support synthetic swipe gestures. |
| 35 if not tab.EvaluateJavaScript('window.__SwipeAction_SupportedByBrowser()'): | 38 if not tab.EvaluateJavaScript('window.__SwipeAction_SupportedByBrowser()'): |
| 36 raise page_action.PageActionNotSupported( | 39 raise page_action.PageActionNotSupported( |
| 37 'Synthetic swipe not supported for this browser') | 40 'Synthetic swipe not supported for this browser') |
| 38 | 41 |
| 39 if (self._synthetic_gesture_source == | 42 if (self._synthetic_gesture_source == |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 }''', | 74 }''', |
| 72 left_start_ratio=self._left_start_ratio, | 75 left_start_ratio=self._left_start_ratio, |
| 73 top_start_ratio=self._top_start_ratio, | 76 top_start_ratio=self._top_start_ratio, |
| 74 direction=self._direction, | 77 direction=self._direction, |
| 75 distance=self._distance, | 78 distance=self._distance, |
| 76 speed=self._speed) | 79 speed=self._speed) |
| 77 page_action.EvaluateCallbackWithElement( | 80 page_action.EvaluateCallbackWithElement( |
| 78 tab, code, selector=self._selector, text=self._text, | 81 tab, code, selector=self._selector, text=self._text, |
| 79 element_function=self._element_function) | 82 element_function=self._element_function) |
| 80 tab.WaitForJavaScriptCondition('window.__swipeActionDone', timeout=60) | 83 tab.WaitForJavaScriptCondition('window.__swipeActionDone', timeout=60) |
| OLD | NEW |