Chromium Code Reviews| Index: telemetry/telemetry/internal/actions/swipe.py |
| diff --git a/telemetry/telemetry/internal/actions/swipe.py b/telemetry/telemetry/internal/actions/swipe.py |
| index 1232e3ba88c66d2f2f96740f2f8d12f48371c9f1..f2ffc35bf61b9f6180b6bd43f6d68a79f0d64b93 100644 |
| --- a/telemetry/telemetry/internal/actions/swipe.py |
| +++ b/telemetry/telemetry/internal/actions/swipe.py |
| @@ -10,8 +10,9 @@ from telemetry.util import js_template |
| class SwipeAction(page_action.PageAction): |
| def __init__(self, selector=None, text=None, element_function=None, |
| left_start_ratio=0.5, top_start_ratio=0.5, |
| - direction='left', distance=100, speed_in_pixels_per_second=800, |
| - synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): |
| + direction='right', distance=100, speed_in_pixels_per_second=800, |
| + synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT, |
| + velocity_x=0, velocity_y=0): |
| super(SwipeAction, self).__init__() |
| if direction not in ['down', 'up', 'left', 'right']: |
| raise page_action.PageActionNotSupported( |
| @@ -26,6 +27,8 @@ class SwipeAction(page_action.PageAction): |
| self._speed = speed_in_pixels_per_second |
| self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % |
| synthetic_gesture_source) |
| + self._velocity_x = velocity_x |
| + self._velocity_y = velocity_y |
| def WillRunAction(self, tab): |
| utils.InjectJavaScript(tab, 'gesture_common.js') |
| @@ -36,14 +39,16 @@ class SwipeAction(page_action.PageAction): |
| raise page_action.PageActionNotSupported( |
| 'Synthetic swipe not supported for this browser') |
| - if (self._synthetic_gesture_source == |
| - 'chrome.gpuBenchmarking.MOUSE_INPUT'): |
| - raise page_action.PageActionNotSupported( |
| - 'Swipe page action does not support mouse input') |
| + # Fail if source is mouse and velocity is zero. |
| + if self._synthetic_gesture_source == 'chrome.gpuBenchmarking.MOUSE_INPUT': |
|
nednguyen
2017/04/26 20:17:35
Instead of "if a:; if b and c:", can you change th
|
| + if self._velocity_x == 0 and self._velocity_y == 0: |
| + raise page_action.PageActionNotSupported( |
| + 'Touchpad fling must have non-zero velocity.') |
|
nednguyen
2017/04/26 20:17:35
If self._synthetic_gesture_source != 'chrome.gpuBe
|
| - if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): |
| - raise page_action.PageActionNotSupported( |
| - 'Touch input not supported for this browser') |
| + if self._synthetic_gesture_source == 'chrome.gpuBenchmarking.TOUCH_INPUT': |
| + if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): |
| + raise page_action.PageActionNotSupported( |
| + 'Touch input not supported for this browser') |
| tab.ExecuteJavaScript(""" |
| window.__swipeActionDone = false; |
| @@ -66,14 +71,20 @@ class SwipeAction(page_action.PageAction): |
| top_start_ratio: {{ top_start_ratio }}, |
| direction: {{ direction }}, |
| distance: {{ distance }}, |
| - speed: {{ speed }} |
| + speed: {{ speed }}, |
| + gesture_source_type: {{ @gesture_source_type }}, |
| + velocity_x: {{ velocity_x }}, |
| + velocity_y: {{ velocity_y }} |
| }); |
| }''', |
| left_start_ratio=self._left_start_ratio, |
| top_start_ratio=self._top_start_ratio, |
| direction=self._direction, |
| distance=self._distance, |
| - speed=self._speed) |
| + speed=self._speed, |
| + gesture_source_type=self._synthetic_gesture_source, |
| + velocity_x=self._velocity_x, |
| + velocity_y=self._velocity_y) |
| page_action.EvaluateCallbackWithElement( |
| tab, code, selector=self._selector, text=self._text, |
| element_function=self._element_function) |