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

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

Issue 668753002: [Telemetry] Migrate bitmap.py from bitmaptools.cc to numpy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years 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
« no previous file with comments | « tools/perf/metrics/speedindex.py ('k') | tools/telemetry/telemetry/core/_bitmap.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.core import bitmap 12 from telemetry.image_processing import histogram
13 from telemetry.image_processing import rgba_color
13 from telemetry.timeline import inspector_timeline_data 14 from telemetry.timeline import inspector_timeline_data
14 from telemetry.timeline import model 15 from telemetry.timeline import model
15 from metrics import speedindex 16 from metrics import speedindex
16 17
17 # Sample timeline data in the json format provided by devtools. 18 # Sample timeline data in the json format provided by devtools.
18 # The sample events will be used in several tests below. 19 # The sample events will be used in several tests below.
19 _TEST_DIR = os.path.join(os.path.dirname(__file__), 'unittest_data') 20 _TEST_DIR = os.path.join(os.path.dirname(__file__), 'unittest_data')
20 _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')))
21 _SAMPLE_TIMELINE_DATA = inspector_timeline_data.InspectorTimelineData( 22 _SAMPLE_TIMELINE_DATA = inspector_timeline_data.InspectorTimelineData(
22 _SAMPLE_DATA) 23 _SAMPLE_DATA)
23 _SAMPLE_EVENTS = model.TimelineModel( 24 _SAMPLE_EVENTS = model.TimelineModel(
24 timeline_data=_SAMPLE_TIMELINE_DATA).GetAllEvents() 25 timeline_data=_SAMPLE_TIMELINE_DATA).GetAllEvents()
25 26
26 27
28 class FakeImageUtil(object):
29 # pylint: disable=W0613
30 def GetColorHistogram(self, image, ignore_color=None, tolerance=None):
31 return image.ColorHistogram()
32
27 class FakeTimelineModel(object): 33 class FakeTimelineModel(object):
28
29 def __init__(self): 34 def __init__(self):
30 self._events = [] 35 self._events = []
31 36
32 def SetAllEvents(self, events): 37 def SetAllEvents(self, events):
33 self._events = events 38 self._events = events
34 39
35 def GetAllEvents(self, recursive=True): 40 def GetAllEvents(self, recursive=True):
36 assert recursive == True 41 assert recursive == True
37 return self._events 42 return self._events
38 43
39 44
40 class FakeVideo(object): 45 class FakeVideo(object):
41
42 def __init__(self, frames): 46 def __init__(self, frames):
43 self._frames = frames 47 self._frames = frames
44 48
45 def GetVideoFrameIter(self): 49 def GetVideoFrameIter(self):
46 for frame in self._frames: 50 for frame in self._frames:
47 yield frame 51 yield frame
48 52
49 class FakeBitmap(object): 53 class FakeBitmap(object):
50
51 def __init__(self, r, g, b): 54 def __init__(self, r, g, b):
52 self._histogram = bitmap.ColorHistogram(r, g, b, bitmap.WHITE) 55 self._histogram = histogram.ColorHistogram(r, g, b, rgba_color.WHITE)
53 56
54 # pylint: disable=W0613 57 # pylint: disable=W0613
55 def ColorHistogram(self, ignore_color=None, tolerance=None): 58 def ColorHistogram(self, ignore_color=None, tolerance=None):
56 return self._histogram 59 return self._histogram
57 60
58 61
59 class FakeTab(object): 62 class FakeTab(object):
60
61 def __init__(self, video_capture_result=None): 63 def __init__(self, video_capture_result=None):
62 self._timeline_model = FakeTimelineModel() 64 self._timeline_model = FakeTimelineModel()
63 self._javascript_result = None 65 self._javascript_result = None
64 self._video_capture_result = FakeVideo(video_capture_result) 66 self._video_capture_result = FakeVideo(video_capture_result)
65 67
66 @property 68 @property
67 def timeline_model(self): 69 def timeline_model(self):
68 return self._timeline_model 70 return self._timeline_model
69 71
70 @property 72 @property
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 (0.0, FakeBitmap([ 0, 0, 0,10], [ 0, 0, 0,10], [ 0, 0, 0,10])), 118 (0.0, FakeBitmap([ 0, 0, 0,10], [ 0, 0, 0,10], [ 0, 0, 0,10])),
117 (0.1, FakeBitmap([10, 0, 0, 0], [10, 0, 0, 0], [10, 0, 0, 0])), 119 (0.1, FakeBitmap([10, 0, 0, 0], [10, 0, 0, 0], [10, 0, 0, 0])),
118 (0.2, FakeBitmap([ 0, 0, 2, 8], [ 0, 0, 4, 6], [ 0, 0, 1, 9])), 120 (0.2, FakeBitmap([ 0, 0, 2, 8], [ 0, 0, 4, 6], [ 0, 0, 1, 9])),
119 (0.3, FakeBitmap([ 0, 3, 2, 5], [ 2, 1, 0, 7], [ 0, 3, 0, 7])), 121 (0.3, FakeBitmap([ 0, 3, 2, 5], [ 2, 1, 0, 7], [ 0, 3, 0, 7])),
120 (0.4, FakeBitmap([ 0, 0, 1, 0], [ 0, 0, 1, 0], [ 0, 0, 1, 0])), 122 (0.4, FakeBitmap([ 0, 0, 1, 0], [ 0, 0, 1, 0], [ 0, 0, 1, 0])),
121 (0.5, FakeBitmap([ 0, 4, 6, 0], [ 0, 4, 6, 0], [ 0, 4, 6, 0])), 123 (0.5, FakeBitmap([ 0, 4, 6, 0], [ 0, 4, 6, 0], [ 0, 4, 6, 0])),
122 ] 124 ]
123 max_distance = 42. 125 max_distance = 42.
124 126
125 tab = FakeTab(frames) 127 tab = FakeTab(frames)
126 impl = speedindex.VideoSpeedIndexImpl() 128 impl = speedindex.VideoSpeedIndexImpl(FakeImageUtil())
127 impl.Start(tab) 129 impl.Start(tab)
128 impl.Stop(tab) 130 impl.Stop(tab)
129 time_completeness = impl.GetTimeCompletenessList(tab) 131 time_completeness = impl.GetTimeCompletenessList(tab)
130 self.assertEqual(len(time_completeness), 6) 132 self.assertEqual(len(time_completeness), 6)
131 self.assertEqual(time_completeness[0], (0.0, 0)) 133 self.assertEqual(time_completeness[0], (0.0, 0))
132 self.assertTimeCompleteness( 134 self.assertTimeCompleteness(
133 time_completeness[1], 0.1, 1 - (16 + 16 + 16) / max_distance) 135 time_completeness[1], 0.1, 1 - (16 + 16 + 16) / max_distance)
134 self.assertTimeCompleteness( 136 self.assertTimeCompleteness(
135 time_completeness[2], 0.2, 1 - (12 + 10 + 13) / max_distance) 137 time_completeness[2], 0.2, 1 - (12 + 10 + 13) / max_distance)
136 self.assertTimeCompleteness( 138 self.assertTimeCompleteness(
137 time_completeness[3], 0.3, 1 - (6 + 10 + 8) / max_distance) 139 time_completeness[3], 0.3, 1 - (6 + 10 + 8) / max_distance)
138 self.assertTimeCompleteness( 140 self.assertTimeCompleteness(
139 time_completeness[4], 0.4, 1 - (4 + 4 + 4) / max_distance) 141 time_completeness[4], 0.4, 1 - (4 + 4 + 4) / max_distance)
140 self.assertEqual(time_completeness[5], (0.5, 1)) 142 self.assertEqual(time_completeness[5], (0.5, 1))
141 143
142 def testBlankPage(self): 144 def testBlankPage(self):
143 frames = [ 145 frames = [
144 (0.0, FakeBitmap([0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1])), 146 (0.0, FakeBitmap([0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1])),
145 (0.1, FakeBitmap([0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1])), 147 (0.1, FakeBitmap([0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1])),
146 (0.2, FakeBitmap([1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1])), 148 (0.2, FakeBitmap([1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1])),
147 (0.3, FakeBitmap([0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1])), 149 (0.3, FakeBitmap([0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1])),
148 ] 150 ]
149 tab = FakeTab(frames) 151 tab = FakeTab(frames)
150 impl = speedindex.VideoSpeedIndexImpl() 152 impl = speedindex.VideoSpeedIndexImpl(FakeImageUtil())
151 impl.Start(tab) 153 impl.Start(tab)
152 impl.Stop(tab) 154 impl.Stop(tab)
153 time_completeness = impl.GetTimeCompletenessList(tab) 155 time_completeness = impl.GetTimeCompletenessList(tab)
154 self.assertEqual(len(time_completeness), 4) 156 self.assertEqual(len(time_completeness), 4)
155 self.assertEqual(time_completeness[0], (0.0, 1.0)) 157 self.assertEqual(time_completeness[0], (0.0, 1.0))
156 self.assertEqual(time_completeness[1], (0.1, 1.0)) 158 self.assertEqual(time_completeness[1], (0.1, 1.0))
157 self.assertEqual(time_completeness[2], (0.2, 0.0)) 159 self.assertEqual(time_completeness[2], (0.2, 0.0))
158 self.assertEqual(time_completeness[3], (0.3, 1.0)) 160 self.assertEqual(time_completeness[3], (0.3, 1.0))
159 161
160 def assertTimeCompleteness(self, time_completeness, time, completeness): 162 def assertTimeCompleteness(self, time_completeness, time, completeness):
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 227
226 def test2ch(self): 228 def test2ch(self):
227 # Page: http://2ch.net/ 229 # Page: http://2ch.net/
228 # This page has several paint events, including nested paint events. 230 # This page has several paint events, including nested paint events.
229 self._TestJsonTimelineExpectation( 231 self._TestJsonTimelineExpectation(
230 '2ch_repeat_timeline.json', (997, 650), 674.58) 232 '2ch_repeat_timeline.json', (997, 650), 674.58)
231 233
232 234
233 if __name__ == "__main__": 235 if __name__ == "__main__":
234 unittest.main() 236 unittest.main()
OLDNEW
« no previous file with comments | « tools/perf/metrics/speedindex.py ('k') | tools/telemetry/telemetry/core/_bitmap.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698