def testAdjustedAreaDict(self): impl = speedindex.PaintRectSpeedIndexImpl() paint_events = impl._IncludedPaintEvents(_SAMPLE_EVENTS) viewport = 1000, 1000 time_area_dict = impl._TimeAreaDict(paint_events, viewport) self.assertEqual(len(time_area_dict), 4) # The event that ends at time 100 is a fullscreen; it's discounted by half. self.assertEqual(time_area_dict[100], 500000) self.assertEqual(time_area_dict[300], 100000) self.assertEqual(time_area_dict[400], 200000) self.assertEqual(time_area_dict[800], 200000)
def testWithSampleData(self): tab = FakeTab() impl = speedindex.PaintRectSpeedIndexImpl() viewport = 1000, 1000 # Add up the parts of the speed index for each time interval. # Each part is the time interval multiplied by the proportion of the # total area value that is not yet painted for that interval. parts = [] parts.append(100 * 1.0) parts.append(200 * 0.5) parts.append(100 * 0.4) parts.append(400 * 0.2) expected = sum(parts) # 330.0 tab.timeline_model.SetAllEvents(_SAMPLE_EVENTS) tab.SetEvaluateJavaScriptResult(viewport) actual = impl.CalculateSpeedIndex(tab) self.assertEqual(actual, expected)
def _TestJsonTimelineExpectation(self, filename, viewport, expected): """Check whether the result for some timeline data is as expected. Args: filename: Filename of a json file which contains a expected: The result expected based on the WPT result. """ tab = FakeTab() impl = speedindex.PaintRectSpeedIndexImpl() file_path = os.path.join(_TEST_DIR, filename) with open(file_path) as json_file: raw_events = json.load(json_file) tab.timeline_model.SetAllEvents( model.TimelineModel(event_data=raw_events).GetAllEvents()) tab.SetEvaluateJavaScriptResult(viewport) actual = impl.CalculateSpeedIndex(tab) # The result might differ by 1 or more milliseconds due to rounding, # so compare to the nearest 10 milliseconds. self.assertAlmostEqual(actual, expected, places=-1)
def testNumberPaintEvents(self): 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) self.assertEqual(len(events), 5)