Index: tools/perf/metrics/speedindex_unittest.py |
diff --git a/tools/perf/metrics/speedindex_unittest.py b/tools/perf/metrics/speedindex_unittest.py |
index 25f3433a20ec5d84b7a6ab86f408c3225cf0ccf3..9275de20cac50951dc5be276642490e59c6e6cb1 100644 |
--- a/tools/perf/metrics/speedindex_unittest.py |
+++ b/tools/perf/metrics/speedindex_unittest.py |
@@ -10,18 +10,22 @@ import os |
import unittest |
from telemetry.core import bitmap |
-from telemetry.timeline import inspector_timeline_data |
from telemetry.timeline import model |
+from telemetry.value import trace as trace_value_module |
from metrics import speedindex |
# Sample timeline data in the json format provided by devtools. |
# The sample events will be used in several tests below. |
+ |
_TEST_DIR = os.path.join(os.path.dirname(__file__), 'unittest_data') |
-_SAMPLE_DATA = json.load(open(os.path.join(_TEST_DIR, 'sample_timeline.json'))) |
-_SAMPLE_TIMELINE_DATA = inspector_timeline_data.InspectorTimelineData( |
- _SAMPLE_DATA) |
-_SAMPLE_EVENTS = model.TimelineModel( |
- timeline_data=_SAMPLE_TIMELINE_DATA).GetAllEvents() |
+ |
+def _GetSampleEvents(): |
+ with open(os.path.join(_TEST_DIR, 'sample_timeline.json') as f: |
+ data = json.load(f) |
+ builder = trace_value_module.TraceValueBuilder() |
+ builder.AddEventsTo(trace_value_module.INSPECTOR_TRACE_PART, data) |
+ model = model.TimelineModel(builder.AsValue()) |
+ return model.GetAllEvents() |
class FakeTimelineModel(object): |
@@ -29,7 +33,7 @@ class FakeTimelineModel(object): |
def __init__(self): |
self._events = [] |
- def SetAllEvents(self, events): |
+ def SetAllEventsOnFake(self, events): |
self._events = events |
def GetAllEvents(self, recursive=True): |
@@ -94,14 +98,14 @@ class IncludedPaintEventsTest(unittest.TestCase): |
impl = speedindex.PaintRectSpeedIndexImpl() |
# In the sample data, there's one event that occurs before the layout event, |
# and one paint event that's not a leaf paint event. |
- events = impl._IncludedPaintEvents(_SAMPLE_EVENTS) |
+ events = impl._IncludedPaintEvents(_GetSampleEvents()) |
self.assertEqual(len(events), 5) |
class SpeedIndexImplTest(unittest.TestCase): |
def testAdjustedAreaDict(self): |
impl = speedindex.PaintRectSpeedIndexImpl() |
- paint_events = impl._IncludedPaintEvents(_SAMPLE_EVENTS) |
+ paint_events = impl._IncludedPaintEvents(_GetSampleEvents()) |
viewport = 1000, 1000 |
time_area_dict = impl._TimeAreaDict(paint_events, viewport) |
self.assertEqual(len(time_area_dict), 4) |
@@ -176,7 +180,7 @@ class SpeedIndexTest(unittest.TestCase): |
parts.append(100 * 0.4) |
parts.append(400 * 0.2) |
expected = sum(parts) # 330.0 |
- tab.timeline_model.SetAllEvents(_SAMPLE_EVENTS) |
+ tab.timeline_model.SetAllEventsOnFake(_GetSampleEvents()) |
tab.SetEvaluateJavaScriptResult(viewport) |
actual = impl.CalculateSpeedIndex(tab) |
self.assertEqual(actual, expected) |
@@ -202,9 +206,10 @@ class WPTComparisonTest(unittest.TestCase): |
file_path = os.path.join(_TEST_DIR, filename) |
with open(file_path) as json_file: |
raw_events = json.load(json_file) |
- timeline_data = inspector_timeline_data.InspectorTimelineData(raw_events) |
- tab.timeline_model.SetAllEvents( |
- model.TimelineModel(timeline_data=timeline_data).GetAllEvents()) |
+ builder = trace_value_module.TraceValueBuilder() |
+ builder.AddEventsTo(trace_value_module.INSPECTOR_TRACE_PART, raw_events) |
+ all_events = model.TimelineModel(builder.AsValue()).GetAllEvents() |
+ tab.timeline_model.SetAllEventsOnFake() |
tab.SetEvaluateJavaScriptResult(viewport) |
actual = impl.CalculateSpeedIndex(tab) |
# The result might differ by 1 or more milliseconds due to rounding, |