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.
7 from telemetry
.core
import util
8 from telemetry
.value
import histogram
9 from telemetry
.value
import histogram_util
11 from measurements
import startup
12 from metrics
import cpu
13 from metrics
import startup_metric
18 'name': 'SessionRestore.ForegroundTabFirstLoaded',
19 'display_name': 'SessionRestore_ForegroundTabFirstLoaded',
22 'name': 'SessionRestore.AllTabsLoaded',
23 'display_name': 'SessionRestore_AllTabsLoaded',
27 class SessionRestore(startup
.Startup
):
28 """Performs a measurement of Chromium's Session restore performance.
30 This test is meant to be run against a generated profile.
31 This test inherits support for the 'cold' option -
32 see startup.py for details.
35 def __init__(self
, cold
=False):
36 super(SessionRestore
, self
).__init
__(cold
=cold
)
37 self
.close_tabs_before_run
= False
38 self
._cpu
_metric
= None
40 def CustomizeBrowserOptions(self
, options
):
41 super(SessionRestore
, self
).CustomizeBrowserOptions(options
)
42 histogram_util
.CustomizeBrowserOptions(options
)
43 options
.AppendExtraBrowserArgs([
44 '--restore-last-session'
47 # Prevent about:blank from being the foreground tab, as that prevents
48 # accurately measuring foreground first load time for session restore.
49 options
.startup_url
= ''
51 def TabForPage(self
, page
, browser
):
52 # Detect that the session restore has completed.
53 util
.WaitFor(lambda: browser
.tabs
and
54 histogram_util
.GetHistogramCount(
55 histogram_util
.BROWSER_HISTOGRAM
,
56 'SessionRestore.AllTabsLoaded',
57 browser
.foreground_tab
),
59 return browser
.foreground_tab
61 def RunNavigateSteps(self
, page
, tab
):
62 # Overridden so that no page navigation occurs.
65 def DidStartBrowser(self
, browser
):
66 self
._cpu
_metric
= cpu
.CpuMetric(browser
)
67 self
._cpu
_metric
.Start(None, None)
69 def ValidateAndMeasurePage(self
, page
, tab
, results
):
70 tab
.WaitForDocumentReadyStateToBeComplete()
71 super(SessionRestore
, self
).ValidateAndMeasurePage(page
, tab
, results
)
73 # Record CPU usage from browser start to when the foreground page is loaded.
74 self
._cpu
_metric
.Stop(None, None)
75 self
._cpu
_metric
.AddResults(tab
, results
, 'cpu_utilization')
78 histogram_data
= histogram_util
.GetHistogram(
79 histogram_util
.BROWSER_HISTOGRAM
, h
['name'], tab
)
81 results
.AddValue(histogram
.HistogramValue(
82 page
, h
['display_name'], 'ms', raw_value_json
=histogram_data
,