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
3 # found in the LICENSE file.
4 from measurements import timeline_controller
5 from metrics import loading
6 from metrics import timeline
7 from telemetry.page import page_measurement
9 class LoadingTrace(page_measurement.PageMeasurement):
10 def __init__(self, *args, **kwargs):
11 super(LoadingTrace, self).__init__(*args, **kwargs)
12 self._timeline_controller = timeline_controller.TimelineController()
15 def results_are_the_same_on_every_page(self):
18 def WillNavigateToPage(self, page, tab):
19 self._timeline_controller.Start(page, tab)
21 def MeasurePage(self, page, tab, results):
22 # In current telemetry tests, all tests wait for DocumentComplete state,
23 # but we need to wait for the load event.
24 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300)
26 # TODO(nduca): when crbug.com/168431 is fixed, modify the page sets to
27 # recognize loading as a toplevel action.
28 self._timeline_controller.Stop(tab)
30 loading.LoadingMetric().AddResults(tab, results)
31 timeline_metric = timeline.LoadTimesTimelineMetric(
32 self._timeline_controller.model,
33 self._timeline_controller.renderer_process,
34 self._timeline_controller.action_ranges)
35 timeline_metric.AddResults(tab, results)
37 def CleanUpAfterPage(self, _, tab):
38 self._timeline_controller.CleanUp(tab)