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. 4from measurements import timeline_controller 5from metrics import loading 6from metrics import timeline 7from telemetry.page import page_test 8from telemetry.web_perf import timeline_interaction_record as tir_module 9 10class LoadingTrace(page_test.PageTest): 11 def __init__(self, *args, **kwargs): 12 super(LoadingTrace, self).__init__(*args, **kwargs) 13 self._timeline_controller = timeline_controller.TimelineController() 14 15 def WillNavigateToPage(self, page, tab): 16 self._timeline_controller.SetUp(page, tab) 17 self._timeline_controller.Start(tab) 18 19 def ValidateAndMeasurePage(self, page, tab, results): 20 # In current telemetry tests, all tests wait for DocumentComplete state, 21 # but we need to wait for the load event. 22 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) 23 24 # TODO(nduca): when crbug.com/168431 is fixed, modify the page sets to 25 # recognize loading as a toplevel action. 26 self._timeline_controller.Stop(tab) 27 28 loading.LoadingMetric().AddResults(tab, results) 29 timeline_metric = timeline.LoadTimesTimelineMetric() 30 renderer_thread = \ 31 self._timeline_controller.model.GetRendererThreadFromTabId(tab.id) 32 record = tir_module.TimelineInteractionRecord( 33 "loading_trace_interaction", 0, float('inf')) 34 timeline_metric.AddResults( 35 self._timeline_controller.model, 36 renderer_thread, 37 [record], 38 results) 39 40 def CleanUpAfterPage(self, _, tab): 41 self._timeline_controller.CleanUp(tab) 42