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 chrome_remote_control import multi_page_benchmark | 6 from chrome_remote_control import multi_page_benchmark |
7 from chrome_remote_control import util | 7 from chrome_remote_control import util |
8 | 8 |
9 class DidNotScrollException(multi_page_benchmark.MeasurementFailure): | 9 class DidNotScrollException(multi_page_benchmark.MeasurementFailure): |
10 def __init__(self): | 10 def __init__(self): |
(...skipping 26 matching lines...) Expand all Loading... |
37 help='Reports all data collected, not just FPS') | 37 help='Reports all data collected, not just FPS') |
38 | 38 |
39 @staticmethod | 39 @staticmethod |
40 def ScrollPageFully(page, tab): | 40 def ScrollPageFully(page, tab): |
41 scroll_js_path = os.path.join(os.path.dirname(__file__), 'scroll.js') | 41 scroll_js_path = os.path.join(os.path.dirname(__file__), 'scroll.js') |
42 scroll_js = open(scroll_js_path, 'r').read() | 42 scroll_js = open(scroll_js_path, 'r').read() |
43 | 43 |
44 # Run scroll test. | 44 # Run scroll test. |
45 tab.runtime.Execute(scroll_js) | 45 tab.runtime.Execute(scroll_js) |
46 | 46 |
47 start_scroll_js = """ | 47 with tab.browser.platform.GetSurfaceCollector(''): |
48 window.__renderingStatsDeltas = null; | |
49 new __ScrollTest(function(rendering_stats_deltas) { | |
50 window.__renderingStatsDeltas = rendering_stats_deltas; | |
51 }).start(element); | |
52 """ | |
53 # scrollable_element_function is a function that passes the scrollable | |
54 # element on the page to a callback. For example: | |
55 # function (callback) { | |
56 # callback(document.getElementById('foo')); | |
57 # } | |
58 if hasattr(page, 'scrollable_element_function'): | |
59 tab.runtime.Execute('(%s)(function(element) { %s });' % | |
60 (page.scrollable_element_function, start_scroll_js)) | |
61 else: | |
62 tab.runtime.Execute('(function() { var element = document.body; %s})();' % | |
63 start_scroll_js) | |
64 | 48 |
65 # Poll for scroll benchmark completion. | 49 start_scroll_js = """ |
66 util.WaitFor(lambda: tab.runtime.Evaluate( | 50 window.__renderingStatsDeltas = null; |
67 'window.__renderingStatsDeltas'), 60) | 51 new __ScrollTest(function(rendering_stats_deltas) { |
| 52 window.__renderingStatsDeltas = rendering_stats_deltas; |
| 53 }).start(element); |
| 54 """ |
| 55 # scrollable_element_function is a function that passes the scrollable |
| 56 # element on the page to a callback. For example: |
| 57 # function (callback) { |
| 58 # callback(document.getElementById('foo')); |
| 59 # } |
| 60 if hasattr(page, 'scrollable_element_function'): |
| 61 tab.runtime.Execute('(%s)(function(element) { %s });' % |
| 62 (page.scrollable_element_function, start_scroll_js)) |
| 63 else: |
| 64 tab.runtime.Execute( |
| 65 '(function() { var element = document.body; %s})();' % |
| 66 start_scroll_js) |
68 | 67 |
69 rendering_stats_deltas = tab.runtime.Evaluate( | 68 # Poll for scroll benchmark completion. |
70 'window.__renderingStatsDeltas') | 69 util.WaitFor(lambda: tab.runtime.Evaluate( |
| 70 'window.__renderingStatsDeltas'), 60) |
71 | 71 |
72 if not (rendering_stats_deltas['numFramesSentToScreen'] > 0): | 72 rendering_stats_deltas = tab.runtime.Evaluate( |
73 raise DidNotScrollException() | 73 'window.__renderingStatsDeltas') |
| 74 |
| 75 if not (rendering_stats_deltas['numFramesSentToScreen'] > 0): |
| 76 raise DidNotScrollException() |
74 return rendering_stats_deltas | 77 return rendering_stats_deltas |
75 | 78 |
76 def CustomizeBrowserOptions(self, options): | 79 def CustomizeBrowserOptions(self, options): |
77 if not options.no_gpu_benchmarking_extension: | 80 if not options.no_gpu_benchmarking_extension: |
78 options.extra_browser_args.append('--enable-gpu-benchmarking') | 81 options.extra_browser_args.append('--enable-gpu-benchmarking') |
79 | 82 |
80 def MeasurePage(self, page, tab, results): | 83 def MeasurePage(self, page, tab, results): |
81 rendering_stats_deltas = self.ScrollPageFully(page, tab) | 84 rendering_stats_deltas = self.ScrollPageFully(page, tab) |
82 CalcScrollResults(rendering_stats_deltas, results) | 85 CalcScrollResults(rendering_stats_deltas, results) |
83 if self.options.report_all_results: | 86 if self.options.report_all_results: |
84 for k, v in rendering_stats_deltas.iteritems(): | 87 for k, v in rendering_stats_deltas.iteritems(): |
85 results.Add(k, '', v) | 88 results.Add(k, '', v) |
OLD | NEW |