Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Side by Side Diff: tools/telemetry/telemetry/page/actions/scroll.py

Issue 62443007: Replace old with new synthetic gesture framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forward declare SyntheticGestureController. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 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 4 import os
5 5
6 from telemetry.page.actions import page_action 6 from telemetry.page.actions import page_action
7 7
8 class ScrollAction(page_action.PageAction): 8 class ScrollAction(page_action.PageAction):
9 def __init__(self, attributes=None): 9 def __init__(self, attributes=None):
10 super(ScrollAction, self).__init__(attributes) 10 super(ScrollAction, self).__init__(attributes)
11 11
12 def WillRunAction(self, page, tab): 12 def WillRunAction(self, page, tab):
13 for js_file in ['gesture_common.js', 'scroll.js']: 13 for js_file in ['gesture_common.js', 'scroll.js']:
14 with open(os.path.join(os.path.dirname(__file__), js_file)) as f: 14 with open(os.path.join(os.path.dirname(__file__), js_file)) as f:
15 js = f.read() 15 js = f.read()
16 tab.ExecuteJavaScript(js) 16 tab.ExecuteJavaScript(js)
17 17
18 # Fail if browser doesn't support synthetic scroll gestures. 18 # Fail if browser doesn't support synthetic scroll gestures.
19 if not tab.EvaluateJavaScript('window.__ScrollAction_SupportedByBrowser()'): 19 if not tab.EvaluateJavaScript('window.__ScrollAction_SupportedByBrowser()'):
20 raise page_action.PageActionNotSupported( 20 raise page_action.PageActionNotSupported(
21 'Synthetic scroll not supported for this browser') 21 'Synthetic scroll not supported for this browser')
22 22
23 # Fail if this action requires touch and we can't send touch events. 23 # Fail if this action requires touch and we can't send touch events.
24 # TODO(dominikg): Query synthetic gesture target to check if touch is
25 # supported.
24 if (hasattr(self, 'scroll_requires_touch') and 26 if (hasattr(self, 'scroll_requires_touch') and
25 self.scroll_requires_touch and not 27 self.scroll_requires_touch and not
26 tab.EvaluateJavaScript( 28 tab.EvaluateJavaScript(
27 'chrome.gpuBenchmarking.smoothScrollBySendsTouch()')): 29 'chrome.gpuBenchmarking.smoothScrollBySendsTouch()')):
28 raise page_action.PageActionNotSupported( 30 raise page_action.PageActionNotSupported(
29 'Touch scroll not supported for this browser') 31 'Touch scroll not supported for this browser')
30 32
31 distance_func = 'null' 33 distance_func = 'null'
32 if hasattr(self, 'remaining_scroll_distance_function'): 34 if hasattr(self, 'remaining_scroll_distance_function'):
33 distance_func = self.remaining_scroll_distance_function 35 distance_func = self.remaining_scroll_distance_function
34 36
35 done_callback = 'function() { window.__scrollActionDone = true; }' 37 done_callback = 'function() { window.__scrollActionDone = true; }'
36 tab.ExecuteJavaScript(""" 38 tab.ExecuteJavaScript("""
37 window.__scrollActionDone = false; 39 window.__scrollActionDone = false;
38 window.__scrollAction = new __ScrollAction(%s, %s);""" 40 window.__scrollAction = new __ScrollAction(%s, %s);"""
39 % (done_callback, distance_func)) 41 % (done_callback, distance_func))
40 42
41 def RunAction(self, page, tab, previous_action): 43 def RunAction(self, page, tab, previous_action):
42 # scrollable_element_function is a function that passes the scrollable 44 # scrollable_element_function is a function that passes the scrollable
43 # element on the page to a callback. For example: 45 # element on the page to a callback. For example:
44 # function (callback) { 46 # function (callback) {
45 # callback(document.getElementById('foo')); 47 # callback(document.getElementById('foo'));
46 # } 48 # }
47 left_start_percentage = 0.5 49 left_start_percentage = 0.5
48 top_start_percentage = 0.5 50 top_start_percentage = 0.5
51 gesture_source_type = 'chrome.gpuBenchmarking.DEFAULT_INPUT'
49 if hasattr(self, 'left_start_percentage'): 52 if hasattr(self, 'left_start_percentage'):
50 left_start_percentage = self.left_start_percentage 53 left_start_percentage = self.left_start_percentage
51 if hasattr(self, 'top_start_percentage'): 54 if hasattr(self, 'top_start_percentage'):
52 top_start_percentage = self.top_start_percentage 55 top_start_percentage = self.top_start_percentage
56 if hasattr(self, 'scroll_requires_touch') and self.scroll_requires_touch:
57 gesture_source_type = 'chrome.gpuBenchmarking.TOUCH_INPUT'
53 if hasattr(self, 'scrollable_element_function'): 58 if hasattr(self, 'scrollable_element_function'):
54 tab.ExecuteJavaScript(""" 59 tab.ExecuteJavaScript("""
55 (%s)(function(element) { window.__scrollAction.start( 60 (%s)(function(element) { window.__scrollAction.start(
56 { element: element, 61 { element: element,
57 left_start_percentage: %s, 62 left_start_percentage: %s,
58 top_start_percentage: %s }) 63 top_start_percentage: %s,
64 gesture_source_type: %s })
59 });""" % (self.scrollable_element_function, 65 });""" % (self.scrollable_element_function,
60 left_start_percentage, 66 left_start_percentage,
61 top_start_percentage)) 67 top_start_percentage,
68 gesture_source_type))
62 else: 69 else:
63 tab.ExecuteJavaScript(""" 70 tab.ExecuteJavaScript("""
64 window.__scrollAction.start( 71 window.__scrollAction.start(
65 { element: document.body, 72 { element: document.body,
66 left_start_percentage: %s, 73 left_start_percentage: %s,
67 top_start_percentage: %s });""" 74 top_start_percentage: %s,
68 % (left_start_percentage, top_start_percentage)) 75 gesture_source_type: %s });"""
76 % (left_start_percentage, top_start_percentage, gesture_source_type))
69 77
70 tab.WaitForJavaScriptExpression('window.__scrollActionDone', 60) 78 tab.WaitForJavaScriptExpression('window.__scrollActionDone', 60)
71 79
72 def CanBeBound(self): 80 def CanBeBound(self):
73 return True 81 return True
74 82
75 def CustomizeBrowserOptions(self, options): 83 def CustomizeBrowserOptions(self, options):
76 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') 84 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
77 85
78 def BindMeasurementJavaScript(self, tab, start_js, stop_js): 86 def BindMeasurementJavaScript(self, tab, start_js, stop_js):
79 # Make the scroll action start and stop measurement automatically. 87 # Make the scroll action start and stop measurement automatically.
80 tab.ExecuteJavaScript(""" 88 tab.ExecuteJavaScript("""
81 window.__scrollAction.beginMeasuringHook = function() { %s }; 89 window.__scrollAction.beginMeasuringHook = function() { %s };
82 window.__scrollAction.endMeasuringHook = function() { %s }; 90 window.__scrollAction.endMeasuringHook = function() { %s };
83 """ % (start_js, stop_js)) 91 """ % (start_js, stop_js))
84 92
85 def GetTimelineMarkerName(self): 93 def GetTimelineMarkerName(self):
86 return 'SyntheticGestureController::running' 94 return 'SyntheticGestureController::running'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698