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.
5 from telemetry
.core
import util
6 from telemetry
.value
import histogram
7 from telemetry
.value
import histogram_util
9 from measurements
import startup
10 from metrics
import cpu
15 'name': 'SessionRestore.ForegroundTabFirstLoaded',
16 'display_name': 'SessionRestore_ForegroundTabFirstLoaded',
19 'name': 'SessionRestore.AllTabsLoaded',
20 'display_name': 'SessionRestore_AllTabsLoaded',
24 class SessionRestore(startup
.Startup
):
25 """Performs a measurement of Chromium's Session restore performance.
27 This test is meant to be run against a generated profile.
28 This test inherits support for the 'cold' option -
29 see startup.py for details.
32 def __init__(self
, cold
=False):
33 super(SessionRestore
, self
).__init
__(cold
=cold
)
34 self
.close_tabs_before_run
= False
35 self
._cpu
_metric
= None
37 def CustomizeBrowserOptions(self
, options
):
38 super(SessionRestore
, self
).CustomizeBrowserOptions(options
)
39 histogram_util
.CustomizeBrowserOptions(options
)
40 options
.AppendExtraBrowserArgs([
41 '--restore-last-session'
44 # Prevent about:blank from being the foreground tab, as that prevents
45 # accurately measuring foreground first load time for session restore.
46 options
.startup_url
= ''
48 def TabForPage(self
, page
, browser
):
49 # Detect that the session restore has completed.
50 util
.WaitFor(lambda: browser
.tabs
and
51 histogram_util
.GetHistogramCount(
52 histogram_util
.BROWSER_HISTOGRAM
,
53 'SessionRestore.AllTabsLoaded',
54 browser
.foreground_tab
),
56 return browser
.foreground_tab
58 def RunNavigateSteps(self
, page
, tab
):
59 # Overridden so that no page navigation occurs.
62 def DidStartBrowser(self
, browser
):
63 self
._cpu
_metric
= cpu
.CpuMetric(browser
)
64 self
._cpu
_metric
.Start(None, None)
66 def ValidateAndMeasurePage(self
, page
, tab
, results
):
67 tab
.WaitForDocumentReadyStateToBeComplete()
68 super(SessionRestore
, self
).ValidateAndMeasurePage(page
, tab
, results
)
70 # Record CPU usage from browser start to when the foreground page is loaded.
71 self
._cpu
_metric
.Stop(None, None)
72 self
._cpu
_metric
.AddResults(tab
, results
, 'cpu_utilization')
75 histogram_data
= histogram_util
.GetHistogram(
76 histogram_util
.BROWSER_HISTOGRAM
, h
['name'], tab
)
78 results
.AddValue(histogram
.HistogramValue(
79 page
, h
['display_name'], 'ms', raw_value_json
=histogram_data
,