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_test
8 from telemetry
.web_perf
import timeline_interaction_record
as tir_module
10 class LoadingTrace(page_test
.PageTest
):
11 def __init__(self
, *args
, **kwargs
):
12 super(LoadingTrace
, self
).__init
__(*args
, **kwargs
)
13 self
._timeline
_controller
= timeline_controller
.TimelineController()
15 def WillNavigateToPage(self
, page
, tab
):
16 self
._timeline
_controller
.SetUp(page
, tab
)
17 self
._timeline
_controller
.Start(tab
)
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)
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
)
28 loading
.LoadingMetric().AddResults(tab
, results
)
29 timeline_metric
= timeline
.LoadTimesTimelineMetric()
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
,
40 def CleanUpAfterPage(self
, _
, tab
):
41 self
._timeline
_controller
.CleanUp(tab
)