OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import copy | 5 import copy |
6 | 6 |
7 from telemetry.core import platform | 7 from telemetry.core import platform |
8 from telemetry.util import wpr_modes | 8 from telemetry.util import wpr_modes |
9 from telemetry.internal.browser import browser_finder | 9 from telemetry.internal.browser import browser_finder |
10 from telemetry.internal.browser import browser_finder_exceptions | 10 from telemetry.internal.browser import browser_finder_exceptions |
(...skipping 17 matching lines...) Expand all Loading... |
28 then a new profile is created. Otherwise, the existing profile is | 28 then a new profile is created. Otherwise, the existing profile is |
29 appended on to. | 29 appended on to. |
30 """ | 30 """ |
31 self._finder_options = copy.deepcopy(finder_options) | 31 self._finder_options = copy.deepcopy(finder_options) |
32 # Since profile extenders are not supported on remote platforms, | 32 # Since profile extenders are not supported on remote platforms, |
33 # this should be the same as target platform. | 33 # this should be the same as target platform. |
34 self._os_name = platform.GetHostPlatform().GetOSName() | 34 self._os_name = platform.GetHostPlatform().GetOSName() |
35 | 35 |
36 # A reference to the browser that will be performing all of the tab | 36 # A reference to the browser that will be performing all of the tab |
37 # navigations. | 37 # navigations. |
38 # This member is initialized during SetUpBrowser(). | 38 # These members are initialized during SetUpBrowser(). |
| 39 self._possible_browser = None |
39 self._browser = None | 40 self._browser = None |
40 | 41 |
41 def Run(self): | 42 def Run(self): |
42 """Creates or extends the profile.""" | 43 """Creates or extends the profile.""" |
43 raise NotImplementedError() | 44 raise NotImplementedError() |
44 | 45 |
45 def WebPageReplayArchivePath(self): | 46 def WebPageReplayArchivePath(self): |
46 """Returns the path to the WPR archive. | 47 """Returns the path to the WPR archive. |
47 | 48 |
48 Can be overridden by subclasses. | 49 Can be overridden by subclasses. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 def SetUpBrowser(self): | 82 def SetUpBrowser(self): |
82 """Finds and starts the browser. | 83 """Finds and starts the browser. |
83 | 84 |
84 Can be overridden by subclasses. The subclass implementation must call the | 85 Can be overridden by subclasses. The subclass implementation must call the |
85 super class implementation. | 86 super class implementation. |
86 | 87 |
87 Subclasses do not need to call this method. This method is only necessary | 88 Subclasses do not need to call this method. This method is only necessary |
88 if the subclass needs to start a browser. If a subclass does call this | 89 if the subclass needs to start a browser. If a subclass does call this |
89 method, the subclass must also call TearDownBrowser(). | 90 method, the subclass must also call TearDownBrowser(). |
90 """ | 91 """ |
91 possible_browser = self._GetPossibleBrowser(self.finder_options) | 92 self._possible_browser = self._GetPossibleBrowser(self.finder_options) |
92 enabled_os_list = self.EnabledOSList() | 93 enabled_os_list = self.EnabledOSList() |
93 if self._os_name not in enabled_os_list: | 94 if self._os_name not in enabled_os_list: |
94 raise NotImplementedError( | 95 raise NotImplementedError( |
95 'This profile extender on %s is not yet supported' | 96 'This profile extender on %s is not yet supported' |
96 % self._os_name) | 97 % self._os_name) |
97 if possible_browser.IsRemote(): | 98 if self._possible_browser.IsRemote(): |
98 raise NotImplementedError( | 99 raise NotImplementedError( |
99 'Profile extenders are not yet supported on remote platforms.') | 100 'Profile extenders are not yet supported on remote platforms.') |
100 assert possible_browser.supports_tab_control | 101 assert self._possible_browser.supports_tab_control |
101 | 102 |
102 self._SetUpWebPageReplay(self.finder_options, possible_browser) | 103 self._SetUpWebPageReplay(self.finder_options) |
103 self._browser = possible_browser.Create(self.finder_options) | 104 self._browser = possible_browser.Create(self.finder_options) |
104 | 105 |
105 def TearDownBrowser(self): | 106 def TearDownBrowser(self): |
106 """Tears down the browser. | 107 """Tears down the browser. |
107 | 108 |
108 Can be overridden by subclasses. The subclass implementation must call the | 109 Can be overridden by subclasses. The subclass implementation must call the |
109 super class implementation. | 110 super class implementation. |
110 """ | 111 """ |
111 if self._browser: | 112 if self._browser: |
112 self._browser.Close() | 113 self._browser.Close() |
113 self._browser = None | 114 self._browser = None |
| 115 if self._possible_browser: |
| 116 self._possible_browser.platform.network_controller.Close() |
114 | 117 |
115 def FetchWebPageReplayArchives(self): | 118 def FetchWebPageReplayArchives(self): |
116 """Fetches the web page replay archives. | 119 """Fetches the web page replay archives. |
117 | 120 |
118 Can be overridden by subclasses. | 121 Can be overridden by subclasses. |
119 """ | 122 """ |
120 pass | 123 pass |
121 | 124 |
122 def _SetUpWebPageReplay(self, finder_options, possible_browser): | 125 def _SetUpWebPageReplay(self, finder_options): |
123 """Sets up Web Page Replay, if necessary.""" | 126 """Sets up Web Page Replay, if necessary.""" |
124 | 127 |
125 wpr_archive_path = self.WebPageReplayArchivePath() | 128 wpr_archive_path = self.WebPageReplayArchivePath() |
126 if not wpr_archive_path: | 129 if not wpr_archive_path: |
127 return | 130 return |
128 | 131 |
129 self.FetchWebPageReplayArchives() | 132 self.FetchWebPageReplayArchives() |
130 | 133 |
131 # The browser options needs to be passed to both the network controller | |
132 # as well as the browser backend. | |
133 browser_options = finder_options.browser_options | 134 browser_options = finder_options.browser_options |
134 if finder_options.use_live_sites: | 135 if finder_options.use_live_sites: |
135 browser_options.wpr_mode = wpr_modes.WPR_OFF | 136 wpr_mode = wpr_modes.WPR_OFF |
136 else: | 137 else: |
137 browser_options.wpr_mode = wpr_modes.WPR_REPLAY | 138 wpr_mode = wpr_modes.WPR_REPLAY |
138 | 139 |
139 network_controller = possible_browser.platform.network_controller | 140 network_controller = self._possible_browser.platform.network_controller |
140 make_javascript_deterministic = True | 141 network_controller.Open( |
141 | 142 wpr_mode, browser_options.netsim, browser_options.extra_wpr_args) |
142 network_controller.SetReplayArgs( | 143 network_controller.StartReplay( |
143 wpr_archive_path, browser_options.wpr_mode, browser_options.netsim, | 144 wpr_archive_path, make_javascript_deterministic=True) |
144 browser_options.extra_wpr_args, make_javascript_deterministic) | |
145 | 145 |
146 def _GetPossibleBrowser(self, finder_options): | 146 def _GetPossibleBrowser(self, finder_options): |
147 """Return a possible_browser with the given options.""" | 147 """Return a possible_browser with the given options.""" |
148 possible_browser = browser_finder.FindBrowser(finder_options) | 148 possible_browser = browser_finder.FindBrowser(finder_options) |
149 if not possible_browser: | 149 if not possible_browser: |
150 raise browser_finder_exceptions.BrowserFinderException( | 150 raise browser_finder_exceptions.BrowserFinderException( |
151 'No browser found.\n\nAvailable browsers:\n%s\n' % | 151 'No browser found.\n\nAvailable browsers:\n%s\n' % |
152 '\n'.join(browser_finder.GetAllAvailableBrowserTypes(finder_options))) | 152 '\n'.join(browser_finder.GetAllAvailableBrowserTypes(finder_options))) |
153 finder_options.browser_options.browser_type = ( | 153 finder_options.browser_options.browser_type = ( |
154 possible_browser.browser_type) | 154 possible_browser.browser_type) |
155 | 155 |
156 return possible_browser | 156 return possible_browser |
157 | |
OLD | NEW |