1 # Copyright 2014 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.
5 from telemetry
.page
import page
6 from telemetry
.page
import page_test
7 from telemetry
.value
import scalar
10 class PageForPolymerLoad(page
.Page
):
12 def __init__(self
, url
, page_set
, ready_event
='polymer-ready'):
13 super(PageForPolymerLoad
, self
).__init
__(
16 self
.script_to_evaluate_on_commit
= '''
17 document.addEventListener("%s", function() {
18 var unused = document.body.offsetHeight;
19 window.__polymer_ready_time = performance.now();
20 setTimeout(function() {
21 window.__polymer_ready = true;
26 def RunNavigateSteps(self
, action_runner
):
27 super(PageForPolymerLoad
, self
).RunNavigateSteps(action_runner
)
28 action_runner
.WaitForJavaScriptCondition('window.__polymer_ready')
31 class PolymerLoadMeasurement(page_test
.PageTest
):
33 super(PolymerLoadMeasurement
, self
).__init
__()
35 def ValidateAndMeasurePage(self
, _
, tab
, results
):
36 result
= int(tab
.EvaluateJavaScript('__polymer_ready_time'))
37 results
.AddValue(scalar
.ScalarValue(
38 results
.current_page
, 'Total', 'ms', result
))