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 import os | 5 import os |
6 | 6 |
7 from telemetry.internal.actions import page_action | 7 from telemetry.internal.actions import page_action |
8 | 8 |
9 | 9 |
10 class SwipeAction(page_action.PageAction): | 10 class SwipeAction(page_action.PageAction): |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 done_callback = 'function() { window.__swipeActionDone = true; }' | 50 done_callback = 'function() { window.__swipeActionDone = true; }' |
51 tab.ExecuteJavaScript(""" | 51 tab.ExecuteJavaScript(""" |
52 window.__swipeActionDone = false; | 52 window.__swipeActionDone = false; |
53 window.__swipeAction = new __SwipeAction(%s);""" | 53 window.__swipeAction = new __SwipeAction(%s);""" |
54 % (done_callback)) | 54 % (done_callback)) |
55 | 55 |
56 def RunAction(self, tab): | 56 def RunAction(self, tab): |
57 if (self._selector is None and self._text is None and | 57 if (self._selector is None and self._text is None and |
58 self._element_function is None): | 58 self._element_function is None): |
59 self._element_function = 'document.body' | 59 self._element_function = 'document.scrollingElement' |
60 code = ''' | 60 code = ''' |
61 function(element, info) { | 61 function(element, info) { |
62 if (!element) { | 62 if (!element) { |
63 throw Error('Cannot find element: ' + info); | 63 throw Error('Cannot find element: ' + info); |
64 } | 64 } |
65 window.__swipeAction.start({ | 65 window.__swipeAction.start({ |
66 element: element, | 66 element: element, |
67 left_start_ratio: %s, | 67 left_start_ratio: %s, |
68 top_start_ratio: %s, | 68 top_start_ratio: %s, |
69 direction: '%s', | 69 direction: '%s', |
70 distance: %s, | 70 distance: %s, |
71 speed: %s | 71 speed: %s |
72 }); | 72 }); |
73 }''' % (self._left_start_ratio, | 73 }''' % (self._left_start_ratio, |
74 self._top_start_ratio, | 74 self._top_start_ratio, |
75 self._direction, | 75 self._direction, |
76 self._distance, | 76 self._distance, |
77 self._speed) | 77 self._speed) |
78 page_action.EvaluateCallbackWithElement( | 78 page_action.EvaluateCallbackWithElement( |
79 tab, code, selector=self._selector, text=self._text, | 79 tab, code, selector=self._selector, text=self._text, |
80 element_function=self._element_function) | 80 element_function=self._element_function) |
81 tab.WaitForJavaScriptExpression('window.__swipeActionDone', 60) | 81 tab.WaitForJavaScriptExpression('window.__swipeActionDone', 60) |
OLD | NEW |