OLD | NEW |
1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 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 ScrollAction(page_action.PageAction): | 9 class ScrollAction(page_action.PageAction): |
10 # TODO(chrishenry): Ignore attributes, to be deleted when usage in | 10 # TODO(chrishenry): Ignore attributes, to be deleted when usage in |
11 # other repo is cleaned up. | 11 # other repo is cleaned up. |
12 def __init__(self, selector=None, text=None, element_function=None, | 12 def __init__(self, selector=None, text=None, element_function=None, |
13 left_start_ratio=0.5, top_start_ratio=0.5, direction='down', | 13 left_start_ratio=0.5, top_start_ratio=0.5, direction='down', |
14 distance=None, distance_expr=None, | 14 distance=None, distance_expr=None, |
15 speed_in_pixels_per_second=800, use_touch=False, | 15 speed_in_pixels_per_second=800, use_touch=False, |
16 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): | 16 synthetic_gesture_source=page_action.GESTURE_SOURCE_DEFAULT): |
(...skipping 24 matching lines...) Expand all Loading... |
41 | 41 |
42 def WillRunAction(self, tab): | 42 def WillRunAction(self, tab): |
43 if self._direction in ('downleft', 'downright', 'upleft', 'upright'): | 43 if self._direction in ('downleft', 'downright', 'upleft', 'upright'): |
44 # Diagonal scrolling support was added in Chrome branch number 2332. | 44 # Diagonal scrolling support was added in Chrome branch number 2332. |
45 branch_num = ( | 45 branch_num = ( |
46 tab.browser._browser_backend.devtools_client.GetChromeBranchNumber()) | 46 tab.browser._browser_backend.devtools_client.GetChromeBranchNumber()) |
47 if branch_num < 2332: | 47 if branch_num < 2332: |
48 raise ValueError('Diagonal scrolling requires Chrome branch number' | 48 raise ValueError('Diagonal scrolling requires Chrome branch number' |
49 ' 2332 or later. Found branch number %d' % | 49 ' 2332 or later. Found branch number %d' % |
50 branch_num) | 50 branch_num) |
51 for js_file in ['gesture_common.js', 'scroll.js']: | 51 utils.InjectJavaScript(tab, 'gesture_common.js') |
52 with open(os.path.join(os.path.dirname(__file__), js_file)) as f: | 52 utils.InjectJavaScript(tab, 'scroll.js') |
53 js = f.read() | |
54 tab.ExecuteJavaScript(js) | |
55 | 53 |
56 # Fail if browser doesn't support synthetic scroll gestures. | 54 # Fail if browser doesn't support synthetic scroll gestures. |
57 if not tab.EvaluateJavaScript('window.__ScrollAction_SupportedByBrowser()'): | 55 if not tab.EvaluateJavaScript('window.__ScrollAction_SupportedByBrowser()'): |
58 raise page_action.PageActionNotSupported( | 56 raise page_action.PageActionNotSupported( |
59 'Synthetic scroll not supported for this browser') | 57 'Synthetic scroll not supported for this browser') |
60 | 58 |
61 # Fail if this action requires touch and we can't send touch events. | 59 # Fail if this action requires touch and we can't send touch events. |
62 if self._use_touch: | 60 if self._use_touch: |
63 if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): | 61 if not page_action.IsGestureSourceTypeSupported(tab, 'touch'): |
64 raise page_action.PageActionNotSupported( | 62 raise page_action.PageActionNotSupported( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 }); | 97 }); |
100 }''' % (self._left_start_ratio, | 98 }''' % (self._left_start_ratio, |
101 self._top_start_ratio, | 99 self._top_start_ratio, |
102 self._direction, | 100 self._direction, |
103 self._speed, | 101 self._speed, |
104 gesture_source_type) | 102 gesture_source_type) |
105 page_action.EvaluateCallbackWithElement( | 103 page_action.EvaluateCallbackWithElement( |
106 tab, code, selector=self._selector, text=self._text, | 104 tab, code, selector=self._selector, text=self._text, |
107 element_function=self._element_function) | 105 element_function=self._element_function) |
108 tab.WaitForJavaScriptExpression('window.__scrollActionDone', 60) | 106 tab.WaitForJavaScriptExpression('window.__scrollActionDone', 60) |
OLD | NEW |