- add sources.
[platform/framework/web/crosswalk.git] / src / tools / perf / measurements / startwithurl.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
5 from measurements import startup
6 from metrics import startup_metric
7
8 class StartWithUrl(startup.Startup):
9   """Measures Chromium's startup performance when started with a URL
10
11   This test inherits support for the --warm or --cold command line options -
12   see startup.py for details.
13   """
14
15   def __init__(self):
16     super(StartWithUrl, self).__init__()
17     self.close_tabs_before_run = False
18
19
20   def AddCommandLineOptions(self, parser):
21     super(StartWithUrl, self).AddCommandLineOptions(parser)
22     parser.add_option('--url', action='store', default=None,
23                       help='Start with a request to open a specific URL')
24
25   def CustomizeBrowserOptions(self, options):
26     super(StartWithUrl, self).CustomizeBrowserOptions(options)
27     if options.url:
28       browser_options = options.browser_options
29       browser_options.startup_url = options.url
30     options.AppendExtraBrowserArgs([
31         '--restore-last-session'
32     ])
33
34   def CanRunForPage(self, page):
35     # No matter how many pages in the pageset, just perform one test iteration.
36     return page.page_set.pages.index(page) == 0
37
38   def RunNavigateSteps(self, page, tab):
39     # Overriden so that no page navigation occurs.
40     pass
41
42   def ValidatePageSet(self, page_set):
43     # Reject any pageset that contains more than one WPR archive.
44     wpr_archives = {}
45     for page in page_set:
46       wpr_archives[page_set.WprFilePathForPage(page)] = True
47
48     if len(wpr_archives.keys()) > 1:
49       raise Exception("Invalid pageset: more than 1 WPR archive found.: " +
50           ', '.join(wpr_archives.keys()))
51
52   def MeasurePage(self, page, tab, results):
53     # Wait for all tabs to finish loading.
54     for i in xrange(len(tab.browser.tabs)):
55       t = tab.browser.tabs[i]
56       t.WaitForDocumentReadyStateToBeComplete()
57
58     startup_metric.StartupMetric().AddResults(tab, results)
59