| 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 import os | |
| 5 | 4 |
| 6 from telemetry.internal.actions import page_action | 5 from telemetry.internal.actions import page_action |
| 6 from telemetry.internal.actions import utils |
| 7 | 7 |
| 8 | 8 |
| 9 class ScrollBounceAction(page_action.PageAction): | 9 class ScrollBounceAction(page_action.PageAction): |
| 10 def __init__(self, selector=None, text=None, element_function=None, | 10 def __init__(self, selector=None, text=None, element_function=None, |
| 11 left_start_ratio=0.5, top_start_ratio=0.5, | 11 left_start_ratio=0.5, top_start_ratio=0.5, |
| 12 direction='down', distance=100, | 12 direction='down', distance=100, |
| 13 overscroll=10, repeat_count=10, | 13 overscroll=10, repeat_count=10, |
| 14 speed_in_pixels_per_second=400, | 14 speed_in_pixels_per_second=400, |
| 15 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): | 15 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): |
| 16 super(ScrollBounceAction, self).__init__() | 16 super(ScrollBounceAction, self).__init__() |
| (...skipping 17 matching lines...) Expand all Loading... |
| 34 # 7 pixels per frame should be plenty of frames. | 34 # 7 pixels per frame should be plenty of frames. |
| 35 self._speed = speed_in_pixels_per_second | 35 self._speed = speed_in_pixels_per_second |
| 36 self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % | 36 self._synthetic_gesture_source = ('chrome.gpuBenchmarking.%s_INPUT' % |
| 37 synthetic_gesture_source) | 37 synthetic_gesture_source) |
| 38 | 38 |
| 39 if (self._selector is None and self._text is None and | 39 if (self._selector is None and self._text is None and |
| 40 self._element_function is None): | 40 self._element_function is None): |
| 41 self._element_function = '(document.scrollingElement || document.body)' | 41 self._element_function = '(document.scrollingElement || document.body)' |
| 42 | 42 |
| 43 def WillRunAction(self, tab): | 43 def WillRunAction(self, tab): |
| 44 for js_file in ['gesture_common.js', 'scroll_bounce.js']: | 44 utils.InjectJavaScript(tab, 'gesture_common.js') |
| 45 with open(os.path.join(os.path.dirname(__file__), js_file)) as f: | 45 utils.InjectJavaScript(tab, 'scroll_bounce.js') |
| 46 js = f.read() | |
| 47 tab.ExecuteJavaScript(js) | |
| 48 | 46 |
| 49 # Fail if browser doesn't support synthetic scroll bounce gestures. | 47 # Fail if browser doesn't support synthetic scroll bounce gestures. |
| 50 if not tab.EvaluateJavaScript( | 48 if not tab.EvaluateJavaScript( |
| 51 'window.__ScrollBounceAction_SupportedByBrowser()'): | 49 'window.__ScrollBounceAction_SupportedByBrowser()'): |
| 52 raise page_action.PageActionNotSupported( | 50 raise page_action.PageActionNotSupported( |
| 53 'Synthetic scroll bounce not supported for this browser') | 51 'Synthetic scroll bounce not supported for this browser') |
| 54 | 52 |
| 55 # Fail if we can't send touch events (bouncing is really only | 53 # Fail if we can't send touch events (bouncing is really only |
| 56 # interesting for touch) | 54 # interesting for touch) |
| 57 if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): | 55 if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 self._top_start_ratio, | 87 self._top_start_ratio, |
| 90 self._direction, | 88 self._direction, |
| 91 self._distance, | 89 self._distance, |
| 92 self._overscroll, | 90 self._overscroll, |
| 93 self._repeat_count, | 91 self._repeat_count, |
| 94 self._speed) | 92 self._speed) |
| 95 page_action.EvaluateCallbackWithElement( | 93 page_action.EvaluateCallbackWithElement( |
| 96 tab, code, selector=self._selector, text=self._text, | 94 tab, code, selector=self._selector, text=self._text, |
| 97 element_function=self._element_function) | 95 element_function=self._element_function) |
| 98 tab.WaitForJavaScriptExpression('window.__scrollBounceActionDone', 60) | 96 tab.WaitForJavaScriptExpression('window.__scrollBounceActionDone', 60) |
| OLD | NEW |