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 import page_interaction | 6 from telemetry import page_interaction |
7 from telemetry import util | 7 from telemetry import util |
8 | 8 |
9 class ScrollingInteraction(page_interaction.PageInteraction): | 9 class ScrollingInteraction(page_interaction.PageInteraction): |
10 def __init__(self, attributes=None): | 10 def __init__(self, attributes=None): |
11 super(ScrollingInteraction, self).__init__(attributes) | 11 super(ScrollingInteraction, self).__init__(attributes) |
12 | 12 |
13 def PerformInteraction(self, page, tab): | 13 def PerformInteraction(self, page, tab): |
14 scroll_js_path = os.path.join(os.path.dirname(__file__), 'scroll.js') | 14 scroll_js_path = os.path.join(os.path.dirname(__file__), 'scroll.js') |
15 scroll_js = open(scroll_js_path, 'r').read() | 15 scroll_js = open(scroll_js_path, 'r').read() |
16 | 16 |
17 # Run scroll test. | 17 # Run scroll test. |
18 tab.runtime.Execute(scroll_js) | 18 tab.runtime.Execute(scroll_js) |
19 | 19 |
20 with tab.browser.platform.GetSurfaceCollector(''): | 20 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 21 tab.browser.platform.StartRawDisplayFrameRateMeasurement('') |
| 22 start_scroll_js = """ |
| 23 window.__renderingStatsDeltas = null; |
| 24 new __ScrollTest(function(rendering_stats_deltas) { |
| 25 window.__renderingStatsDeltas = rendering_stats_deltas; |
| 26 }).start(element); |
| 27 """ |
| 28 # scrollable_element_function is a function that passes the scrollable |
| 29 # element on the page to a callback. For example: |
| 30 # function (callback) { |
| 31 # callback(document.getElementById('foo')); |
| 32 # } |
| 33 if hasattr(self, 'scrollable_element_function'): |
| 34 tab.runtime.Execute('(%s)(function(element) { %s });' % |
| 35 (self.scrollable_element_function, start_scroll_js)) |
| 36 else: |
| 37 tab.runtime.Execute( |
| 38 '(function() { var element = document.body; %s})();' % |
| 39 start_scroll_js) |
21 | 40 |
22 start_scroll_js = """ | 41 # Poll for scroll benchmark completion. |
23 window.__renderingStatsDeltas = null; | 42 util.WaitFor(lambda: tab.runtime.Evaluate( |
24 new __ScrollTest(function(rendering_stats_deltas) { | 43 'window.__renderingStatsDeltas'), 60) |
25 window.__renderingStatsDeltas = rendering_stats_deltas; | 44 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
26 }).start(element); | 45 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
27 """ | |
28 # scrollable_element_function is a function that passes the scrollable | |
29 # element on the page to a callback. For example: | |
30 # function (callback) { | |
31 # callback(document.getElementById('foo')); | |
32 # } | |
33 if hasattr(self, 'scrollable_element_function'): | |
34 tab.runtime.Execute('(%s)(function(element) { %s });' % | |
35 (self.scrollable_element_function, start_scroll_js)) | |
36 else: | |
37 tab.runtime.Execute( | |
38 '(function() { var element = document.body; %s})();' % | |
39 start_scroll_js) | |
40 | |
41 # Poll for scroll benchmark completion. | |
42 util.WaitFor(lambda: tab.runtime.Evaluate( | |
43 'window.__renderingStatsDeltas'), 60) | |
OLD | NEW |