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 import os | 4 import os |
5 | 5 |
6 from telemetry.page.actions import gesture_action | 6 from telemetry.page.actions import gesture_action |
7 from telemetry.page.actions import page_action | 7 from telemetry.page.actions import page_action |
8 | 8 |
9 class SwipeAction(gesture_action.GestureAction): | 9 class SwipeAction(gesture_action.GestureAction): |
10 def __init__(self, attributes=None): | 10 def __init__(self, attributes=None): |
(...skipping 18 matching lines...) Expand all Loading... |
29 tab.ExecuteJavaScript(""" | 29 tab.ExecuteJavaScript(""" |
30 window.__swipeActionDone = false; | 30 window.__swipeActionDone = false; |
31 window.__swipeAction = new __SwipeAction(%s);""" | 31 window.__swipeAction = new __SwipeAction(%s);""" |
32 % (done_callback)) | 32 % (done_callback)) |
33 | 33 |
34 def RunGesture(self, page, tab, previous_action): | 34 def RunGesture(self, page, tab, previous_action): |
35 left_start_percentage = 0.5 | 35 left_start_percentage = 0.5 |
36 top_start_percentage = 0.5 | 36 top_start_percentage = 0.5 |
37 direction = 'left' | 37 direction = 'left' |
38 distance = 100 | 38 distance = 100 |
| 39 speed = 800 |
39 if hasattr(self, 'left_start_percentage'): | 40 if hasattr(self, 'left_start_percentage'): |
40 left_start_percentage = self.left_start_percentage | 41 left_start_percentage = self.left_start_percentage |
41 if hasattr(self, 'top_start_percentage'): | 42 if hasattr(self, 'top_start_percentage'): |
42 top_start_percentage = self.top_start_percentage | 43 top_start_percentage = self.top_start_percentage |
43 if hasattr(self, 'direction'): | 44 if hasattr(self, 'direction'): |
44 direction = self.direction | 45 direction = self.direction |
45 if direction not in ['down', 'up', 'left', 'right']: | 46 if direction not in ['down', 'up', 'left', 'right']: |
46 raise page_action.PageActionNotSupported( | 47 raise page_action.PageActionNotSupported( |
47 'Invalid swipe direction: %s' % direction) | 48 'Invalid swipe direction: %s' % direction) |
48 if hasattr(self, 'distance'): | 49 if hasattr(self, 'distance'): |
49 distance = self.distance | 50 distance = self.distance |
| 51 if hasattr(self, 'speed'): |
| 52 speed = self.speed |
50 if hasattr(self, 'element_function'): | 53 if hasattr(self, 'element_function'): |
51 tab.ExecuteJavaScript(""" | 54 tab.ExecuteJavaScript(""" |
52 (%s)(function(element) { window.__swipeAction.start( | 55 (%s)(function(element) { window.__swipeAction.start( |
53 { element: element, | 56 { element: element, |
54 left_start_percentage: %s, | 57 left_start_percentage: %s, |
55 top_start_percentage: %s, | 58 top_start_percentage: %s, |
56 direction: '%s', | 59 direction: '%s', |
57 distance: %s }) | 60 distance: %s, |
| 61 speed: %s }) |
58 });""" % (self.element_function, | 62 });""" % (self.element_function, |
59 left_start_percentage, | 63 left_start_percentage, |
60 top_start_percentage, | 64 top_start_percentage, |
61 direction, | 65 direction, |
62 distance)) | 66 distance, |
| 67 speed)) |
63 else: | 68 else: |
64 tab.ExecuteJavaScript(""" | 69 tab.ExecuteJavaScript(""" |
65 window.__swipeAction.start( | 70 window.__swipeAction.start( |
66 { element: document.body, | 71 { element: document.body, |
67 left_start_percentage: %s, | 72 left_start_percentage: %s, |
68 top_start_percentage: %s, | 73 top_start_percentage: %s, |
69 direction: '%s', | 74 direction: '%s', |
70 distance: %s });""" | 75 distance: %s, |
| 76 speed: %s });""" |
71 % (left_start_percentage, | 77 % (left_start_percentage, |
72 top_start_percentage, | 78 top_start_percentage, |
73 direction, | 79 direction, |
74 distance)) | 80 distance, |
| 81 speed)) |
75 | 82 |
76 tab.WaitForJavaScriptExpression('window.__swipeActionDone', 60) | 83 tab.WaitForJavaScriptExpression('window.__swipeActionDone', 60) |
77 | 84 |
78 def CanBeBound(self): | 85 def CanBeBound(self): |
79 return True | 86 return True |
80 | 87 |
81 def BindMeasurementJavaScript(self, tab, start_js, stop_js): | 88 def BindMeasurementJavaScript(self, tab, start_js, stop_js): |
82 # Make the swipe action start and stop measurement automatically. | 89 # Make the swipe action start and stop measurement automatically. |
83 tab.ExecuteJavaScript(""" | 90 tab.ExecuteJavaScript(""" |
84 window.__swipeAction.beginMeasuringHook = function() { %s }; | 91 window.__swipeAction.beginMeasuringHook = function() { %s }; |
85 window.__swipeAction.endMeasuringHook = function() { %s }; | 92 window.__swipeAction.endMeasuringHook = function() { %s }; |
86 """ % (start_js, stop_js)) | 93 """ % (start_js, stop_js)) |
OLD | NEW |