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 platform
6 from telemetry
.core
import wpr_modes
9 class ProfileExtender(object):
10 """Abstract base class for an object that constructs a Chrome profile."""
13 # The path of the profile that the browser will use while it's running.
14 # This member is initialized during SetUp().
15 self
._profile
_path
= None
17 # A reference to the browser that will be performing all of the tab
19 # This member is initialized during SetUp().
22 def Run(self
, options
):
23 """Creates or extends the profile.
25 |options| is an instance of BrowserFinderOptions. When subclass
26 implementations of this method inevitably attempt to find and launch a
27 browser, they should pass |options| to the relevant methods.
29 Several properties of |options| might require direct manipulation by
30 subclasses. These are:
31 |options.output_profile_path|: The path at which the profile should be
33 |options.browser_options.profile_dir|: If this property is None, then a
34 new profile is created. Otherwise, the existing profile is appended on
37 raise NotImplementedError()
39 def WebPageReplayArchivePath(self
):
40 """Returns the path to the WPR archive.
42 Can be overridden by subclasses.
47 def profile_path(self
):
48 return self
._profile
_path
54 def SetUp(self
, finder_options
):
55 """Finds and starts the browser.
57 Can be overridden by subclasses. Subclasses must call the super class
60 self
._profile
_path
= finder_options
.output_profile_path
61 possible_browser
= self
._GetPossibleBrowser
(finder_options
)
63 assert possible_browser
.supports_tab_control
64 assert (platform
.GetHostPlatform().GetOSName() in
65 ["win", "mac", "linux"])
67 self
._SetUpWebPageReplay
(finder_options
, possible_browser
)
68 self
._browser
= possible_browser
.Create(finder_options
)
71 """Teardown that is guaranteed to be executed before the instance is
74 Can be overridden by subclasses. Subclasses must call the super class
81 def FetchWebPageReplayArchives(self
):
82 """Fetches the web page replay archives.
84 Can be overridden by subclasses.
88 def _SetUpWebPageReplay(self
, finder_options
, possible_browser
):
89 """Sets up Web Page Replay, if necessary."""
91 wpr_archive_path
= self
.WebPageReplayArchivePath()
92 if not wpr_archive_path
:
95 self
.FetchWebPageReplayArchives()
97 # The browser options needs to be passed to both the network controller
98 # as well as the browser backend.
99 browser_options
= finder_options
.browser_options
100 if finder_options
.use_live_sites
:
101 browser_options
.wpr_mode
= wpr_modes
.WPR_OFF
103 browser_options
.wpr_mode
= wpr_modes
.WPR_REPLAY
105 network_controller
= possible_browser
.platform
.network_controller
106 make_javascript_deterministic
= True
108 network_controller
.SetReplayArgs(
109 wpr_archive_path
, browser_options
.wpr_mode
, browser_options
.netsim
,
110 browser_options
.extra_wpr_args
, make_javascript_deterministic
)