OLD | NEW |
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.core import util | 6 from telemetry.core import util |
7 from telemetry.page import page_action | 7 from telemetry.page import page_action |
8 | 8 |
9 class ScrollingAction(page_action.PageAction): | 9 class ScrollingAction(page_action.PageAction): |
10 def __init__(self, attributes=None): | 10 def __init__(self, attributes=None): |
11 super(ScrollingAction, self).__init__(attributes) | 11 super(ScrollingAction, self).__init__(attributes) |
12 | 12 |
13 def WillRunAction(self, page, tab): | 13 def WillRunAction(self, page, tab): |
14 with open( | 14 with open( |
15 os.path.join(os.path.dirname(__file__), | 15 os.path.join(os.path.dirname(__file__), |
16 'scrolling_action.js')) as f: | 16 'scrolling_action.js')) as f: |
17 js = f.read() | 17 js = f.read() |
18 tab.ExecuteJavaScript(js) | 18 tab.ExecuteJavaScript(js) |
19 | 19 |
20 tab.ExecuteJavaScript(""" | 20 tab.ExecuteJavaScript(""" |
21 window.__scrollingActionDone = false; | 21 window.__scrollingActionDone = false; |
22 window.__scrollingAction = new __ScrollingAction(function() { | 22 window.__scrollingAction = new __ScrollingAction(function() { |
23 window.__scrollingActionDone = true; | 23 window.__scrollingActionDone = true; |
24 }); | 24 }); |
25 """) | 25 """) |
26 | 26 |
27 def RunAction(self, page, tab, previous_action): | 27 def RunAction(self, page, tab, previous_action): |
28 with tab.browser.platform.GetSurfaceCollector(''): | 28 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
29 # scrollable_element_function is a function that passes the scrollable | 29 tab.browser.platform.StartRawDisplayFrameRateMeasurement('') |
30 # element on the page to a callback. For example: | 30 # scrollable_element_function is a function that passes the scrollable |
31 # function (callback) { | 31 # element on the page to a callback. For example: |
32 # callback(document.getElementById('foo')); | 32 # function (callback) { |
33 # } | 33 # callback(document.getElementById('foo')); |
34 if hasattr(self, 'scrollable_element_function'): | 34 # } |
35 tab.ExecuteJavaScript(""" | 35 if hasattr(self, 'scrollable_element_function'): |
36 (%s)(function(element) { | 36 tab.ExecuteJavaScript(""" |
37 window.__scrollingAction.start(element); | 37 (%s)(function(element) { |
38 });""" % (self.scrollable_element_function)) | 38 window.__scrollingAction.start(element); |
39 else: | 39 });""" % (self.scrollable_element_function)) |
40 tab.ExecuteJavaScript( | 40 else: |
41 'window.__scrollingAction.start(document.body);') | 41 tab.ExecuteJavaScript( |
| 42 'window.__scrollingAction.start(document.body);') |
42 | 43 |
43 # Poll for scroll benchmark completion. | 44 # Poll for scroll benchmark completion. |
44 util.WaitFor(lambda: tab.EvaluateJavaScript( | 45 util.WaitFor(lambda: tab.EvaluateJavaScript( |
45 'window.__scrollingActionDone'), 60) | 46 'window.__scrollingActionDone'), 60) |
| 47 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 48 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
46 | 49 |
47 def CanBeBound(self): | 50 def CanBeBound(self): |
48 return True | 51 return True |
49 | 52 |
50 def BindMeasurementJavaScript(self, tab, start_js, stop_js): | 53 def BindMeasurementJavaScript(self, tab, start_js, stop_js): |
51 # Make the scrolling action start and stop measurement automatically. | 54 # Make the scrolling action start and stop measurement automatically. |
52 tab.ExecuteJavaScript(""" | 55 tab.ExecuteJavaScript(""" |
53 window.__scrollingAction.beginMeasuringHook = function() { %s }; | 56 window.__scrollingAction.beginMeasuringHook = function() { %s }; |
54 window.__scrollingAction.endMeasuringHook = function() { %s }; | 57 window.__scrollingAction.endMeasuringHook = function() { %s }; |
55 """ % (start_js, stop_js)) | 58 """ % (start_js, stop_js)) |
OLD | NEW |