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

Side by Side Diff: tools/perf/metrics/speedindex_unittest.py

Issue 814813003: Added test that SurfaceFlinger metrics are calculated on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: PLEASE IGNORE: accidentally uploaded to wrong issue Created 5 years, 12 months 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 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 4
5 # These tests access private methods in the speedindex module. 5 # These tests access private methods in the speedindex module.
6 # pylint: disable=W0212 6 # pylint: disable=W0212
7 7
8 import json 8 import json
9 import os 9 import os
10 import unittest 10 import unittest
11 11
12 from telemetry.image_processing import histogram 12 from telemetry.image_processing import histogram
13 from telemetry.image_processing import rgba_color 13 from telemetry.image_processing import rgba_color
14 from telemetry.timeline import inspector_timeline_data
15 from telemetry.timeline import model 14 from telemetry.timeline import model
15 from telemetry.timeline import trace_data as trace_data_module
16 from metrics import speedindex 16 from metrics import speedindex
17 17
18 # Sample timeline data in the json format provided by devtools. 18 # Sample timeline data in the json format provided by devtools.
19 # The sample events will be used in several tests below. 19 # The sample events will be used in several tests below.
20 _TEST_DIR = os.path.join(os.path.dirname(__file__), 'unittest_data') 20 _TEST_DIR = os.path.join(os.path.dirname(__file__), 'unittest_data')
21 _SAMPLE_DATA = json.load(open(os.path.join(_TEST_DIR, 'sample_timeline.json'))) 21 _SAMPLE_DATA = json.load(open(os.path.join(_TEST_DIR, 'sample_timeline.json')))
22 _SAMPLE_TIMELINE_DATA = inspector_timeline_data.InspectorTimelineData( 22 _SAMPLE_TRACE_BUILDER = trace_data_module.TraceDataBuilder()
23 _SAMPLE_DATA) 23 _SAMPLE_TRACE_BUILDER.AddEventsTo(
24 trace_data_module.INSPECTOR_TRACE_PART, _SAMPLE_DATA)
24 _SAMPLE_EVENTS = model.TimelineModel( 25 _SAMPLE_EVENTS = model.TimelineModel(
25 timeline_data=_SAMPLE_TIMELINE_DATA).GetAllEvents() 26 _SAMPLE_TRACE_BUILDER.AsData()).GetAllEvents()
26 27
27 28
28 class FakeImageUtil(object): 29 class FakeImageUtil(object):
29 # pylint: disable=W0613 30 # pylint: disable=W0613
30 def GetColorHistogram(self, image, ignore_color=None, tolerance=None): 31 def GetColorHistogram(self, image, ignore_color=None, tolerance=None):
31 return image.ColorHistogram() 32 return image.ColorHistogram()
32 33
33 class FakeTimelineModel(object): 34 class FakeTimelineModel(object):
34 def __init__(self): 35 def __init__(self):
35 self._events = [] 36 self._events = []
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 198
198 Args: 199 Args:
199 filename: Filename of a json file which contains a 200 filename: Filename of a json file which contains a
200 expected: The result expected based on the WPT result. 201 expected: The result expected based on the WPT result.
201 """ 202 """
202 tab = FakeTab() 203 tab = FakeTab()
203 impl = speedindex.PaintRectSpeedIndexImpl() 204 impl = speedindex.PaintRectSpeedIndexImpl()
204 file_path = os.path.join(_TEST_DIR, filename) 205 file_path = os.path.join(_TEST_DIR, filename)
205 with open(file_path) as json_file: 206 with open(file_path) as json_file:
206 raw_events = json.load(json_file) 207 raw_events = json.load(json_file)
207 timeline_data = inspector_timeline_data.InspectorTimelineData(raw_events) 208 trace_data_builder = trace_data_module.TraceDataBuilder()
209 trace_data_builder.AddEventsTo(
210 trace_data_module.INSPECTOR_TRACE_PART, raw_events)
208 tab.timeline_model.SetAllEvents( 211 tab.timeline_model.SetAllEvents(
209 model.TimelineModel(timeline_data=timeline_data).GetAllEvents()) 212 model.TimelineModel(trace_data_builder.AsData()).GetAllEvents())
210 tab.SetEvaluateJavaScriptResult(viewport) 213 tab.SetEvaluateJavaScriptResult(viewport)
211 actual = impl.CalculateSpeedIndex(tab) 214 actual = impl.CalculateSpeedIndex(tab)
212 # The result might differ by 1 or more milliseconds due to rounding, 215 # The result might differ by 1 or more milliseconds due to rounding,
213 # so compare to the nearest 10 milliseconds. 216 # so compare to the nearest 10 milliseconds.
214 self.assertAlmostEqual(actual, expected, places=-1) 217 self.assertAlmostEqual(actual, expected, places=-1)
215 218
216 def testCern(self): 219 def testCern(self):
217 # Page: http://info.cern.ch/hypertext/WWW/TheProject.html 220 # Page: http://info.cern.ch/hypertext/WWW/TheProject.html
218 # This page has only one paint event. 221 # This page has only one paint event.
219 self._TestJsonTimelineExpectation( 222 self._TestJsonTimelineExpectation(
220 'cern_repeat_timeline.json', (1014, 650), 379.0) 223 'cern_repeat_timeline.json', (1014, 650), 379.0)
221 224
222 def testBaidu(self): 225 def testBaidu(self):
223 # Page: http://www.baidu.com/ 226 # Page: http://www.baidu.com/
224 # This page has several paint events, but no nested paint events. 227 # This page has several paint events, but no nested paint events.
225 self._TestJsonTimelineExpectation( 228 self._TestJsonTimelineExpectation(
226 'baidu_repeat_timeline.json', (1014, 650), 1761.43) 229 'baidu_repeat_timeline.json', (1014, 650), 1761.43)
227 230
228 def test2ch(self): 231 def test2ch(self):
229 # Page: http://2ch.net/ 232 # Page: http://2ch.net/
230 # This page has several paint events, including nested paint events. 233 # This page has several paint events, including nested paint events.
231 self._TestJsonTimelineExpectation( 234 self._TestJsonTimelineExpectation(
232 '2ch_repeat_timeline.json', (997, 650), 674.58) 235 '2ch_repeat_timeline.json', (997, 650), 674.58)
233 236
234 237
235 if __name__ == "__main__": 238 if __name__ == "__main__":
236 unittest.main() 239 unittest.main()
OLDNEW
« no previous file with comments | « tools/perf/measurements/task_execution_time.py ('k') | tools/telemetry/telemetry/core/backends/browser_backend.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698