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
.page
import profile_creator
10 from telemetry
import benchmark
11 from telemetry
.page
import page_test
12 from telemetry
.page
import test_expectations
13 from telemetry
.results
import results_options
14 from telemetry
.user_story
import user_story_runner
17 class SmallProfileCreator(profile_creator
.ProfileCreator
):
19 Runs a browser through a series of operations to fill in a small test profile.
21 This consists of performing a single navigation to each of the top 25 pages.
23 class PageTest(page_test
.PageTest
):
25 super(SmallProfileCreator
.PageTest
, self
).__init
__()
26 self
._page
_set
= page_sets
.Typical25PageSet()
28 # Open all links in the same tab save for the last _NUM_TABS links which
29 # are each opened in a new tab.
32 def TabForPage(self
, page
, browser
):
33 """Superclass override."""
34 idx
= page
.page_set
.pages
.index(page
)
35 # The last _NUM_TABS pages open a new tab.
36 if idx
<= (len(page
.page_set
.pages
) - self
._NUM
_TABS
):
37 return browser
.tabs
[0]
39 return browser
.tabs
.New()
41 def ValidateAndMeasurePage(self
, page
, tab
, results
):
42 """Superclass override."""
43 tab
.WaitForDocumentReadyStateToBeComplete()
46 super(SmallProfileCreator
, self
).__init
__()
47 self
._page
_test
= SmallProfileCreator
.PageTest()
49 def Run(self
, options
):
50 expectations
= test_expectations
.TestExpectations()
51 results
= results_options
.CreateResults(
52 benchmark
.BenchmarkMetadata(profile_creator
.__class
__.__name
__),
54 user_story_runner
.Run(self
._page
_test
, self
._page
_test
._page
_set
,
55 expectations
, options
, results
)
58 logging
.warning('Some pages failed to load.')
59 logging
.warning('Failed pages:\n%s',
60 '\n'.join(map(str, results
.pages_that_failed
)))
61 raise Exception('SmallProfileCreator failed.')