Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / tools / perf / measurements / loading_trace.py
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
8
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()
13
14   @property
15   def results_are_the_same_on_every_page(self):
16     return False
17
18   def WillNavigateToPage(self, page, tab):
19     self._timeline_controller.Start(page, tab)
20
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)
25
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)
29
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)
36
37   def CleanUpAfterPage(self, _, tab):
38     self._timeline_controller.CleanUp(tab)