OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import codecs | 4 import codecs |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import time | 7 import time |
8 import traceback | 8 import traceback |
9 import urlparse | 9 import urlparse |
10 import random | 10 import random |
11 | 11 |
12 from telemetry import browser_gone_exception | 12 from telemetry.core import util |
13 from telemetry import page_filter as page_filter_module | 13 from telemetry.core import wpr_modes |
14 from telemetry import page_test | 14 from telemetry.core import exceptions |
15 from telemetry import tab_crash_exception | 15 from telemetry.page import page_filter as page_filter_module |
16 from telemetry import util | 16 from telemetry.page import page_test |
17 from telemetry import wpr_modes | |
18 | 17 |
19 class PageState(object): | 18 class PageState(object): |
20 def __init__(self): | 19 def __init__(self): |
21 self.did_login = False | 20 self.did_login = False |
22 | 21 |
23 class _RunState(object): | 22 class _RunState(object): |
24 def __init__(self): | 23 def __init__(self): |
25 self.first_browser = True | 24 self.first_browser = True |
26 self.browser = None | 25 self.browser = None |
27 self.tab = None | 26 self.tab = None |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 credentials_path, page.archive_path) | 137 credentials_path, page.archive_path) |
139 if not state.tab: | 138 if not state.tab: |
140 if len(state.browser.tabs) == 0: | 139 if len(state.browser.tabs) == 0: |
141 state.browser.tabs.New() | 140 state.browser.tabs.New() |
142 state.tab = state.browser.tabs[0] | 141 state.tab = state.browser.tabs[0] |
143 if options.trace_dir: | 142 if options.trace_dir: |
144 self._SetupTracingTab(state) | 143 self._SetupTracingTab(state) |
145 | 144 |
146 try: | 145 try: |
147 self._RunPage(options, page, state.tab, test, results) | 146 self._RunPage(options, page, state.tab, test, results) |
148 except tab_crash_exception.TabCrashException: | 147 except exceptions.TabCrashException: |
149 stdout = '' | 148 stdout = '' |
150 if not options.show_stdout: | 149 if not options.show_stdout: |
151 stdout = state.browser.GetStandardOutput() | 150 stdout = state.browser.GetStandardOutput() |
152 stdout = (('\nStandard Output:\n') + | 151 stdout = (('\nStandard Output:\n') + |
153 ('*' * 80) + | 152 ('*' * 80) + |
154 '\n\t' + stdout.replace('\n', '\n\t') + '\n' + | 153 '\n\t' + stdout.replace('\n', '\n\t') + '\n' + |
155 ('*' * 80)) | 154 ('*' * 80)) |
156 logging.warning('Tab crashed: %s%s', page.url, stdout) | 155 logging.warning('Tab crashed: %s%s', page.url, stdout) |
157 state.Close() | 156 state.Close() |
158 | 157 |
159 if options.trace_dir: | 158 if options.trace_dir: |
160 self._EndTracing(state, options, page) | 159 self._EndTracing(state, options, page) |
161 | 160 |
162 if test.needs_browser_restart_after_each_run: | 161 if test.needs_browser_restart_after_each_run: |
163 state.Close() | 162 state.Close() |
164 | 163 |
165 break | 164 break |
166 except browser_gone_exception.BrowserGoneException: | 165 except exceptions.BrowserGoneException: |
167 logging.warning('Lost connection to browser. Retrying.') | 166 logging.warning('Lost connection to browser. Retrying.') |
168 state.Close() | 167 state.Close() |
169 tries -= 1 | 168 tries -= 1 |
170 if not tries: | 169 if not tries: |
171 logging.error('Lost connection to browser 3 times. Failing.') | 170 logging.error('Lost connection to browser 3 times. Failing.') |
172 raise | 171 raise |
173 finally: | 172 finally: |
174 state.Close() | 173 state.Close() |
175 | 174 |
176 def _RunPage(self, options, page, tab, test, results): | 175 def _RunPage(self, options, page, tab, test, results): |
177 if not test.CanRunForPage(page): | 176 if not test.CanRunForPage(page): |
178 logging.warning('Skiping test: it cannot run for %s', page.url) | 177 logging.warning('Skiping test: it cannot run for %s', page.url) |
179 results.AddSkippedPage(page, 'Test cannot run', '') | 178 results.AddSkippedPage(page, 'Test cannot run', '') |
180 return | 179 return |
181 | 180 |
182 logging.info('Running %s' % page.url) | 181 logging.info('Running %s' % page.url) |
183 | 182 |
184 page_state = PageState() | 183 page_state = PageState() |
185 try: | 184 try: |
186 did_prepare = self._PreparePage(page, tab, page_state, test, results) | 185 did_prepare = self._PreparePage(page, tab, page_state, test, results) |
187 except util.TimeoutException, ex: | 186 except util.TimeoutException, ex: |
188 logging.warning('Timed out waiting for reply on %s. This is unusual.', | 187 logging.warning('Timed out waiting for reply on %s. This is unusual.', |
189 page.url) | 188 page.url) |
190 results.AddFailure(page, ex, traceback.format_exc()) | 189 results.AddFailure(page, ex, traceback.format_exc()) |
191 return | 190 return |
192 except tab_crash_exception.TabCrashException, ex: | 191 except exceptions.TabCrashException, ex: |
193 results.AddFailure(page, ex, traceback.format_exc()) | 192 results.AddFailure(page, ex, traceback.format_exc()) |
194 raise | 193 raise |
195 except browser_gone_exception.BrowserGoneException: | 194 except exceptions.BrowserGoneException: |
196 raise | 195 raise |
197 except Exception, ex: | 196 except Exception, ex: |
198 logging.error('Unexpected failure while running %s: %s', | 197 logging.error('Unexpected failure while running %s: %s', |
199 page.url, traceback.format_exc()) | 198 page.url, traceback.format_exc()) |
200 self._CleanUpPage(page, tab, page_state) | 199 self._CleanUpPage(page, tab, page_state) |
201 raise | 200 raise |
202 | 201 |
203 if not did_prepare: | 202 if not did_prepare: |
204 self._CleanUpPage(page, tab, page_state) | 203 self._CleanUpPage(page, tab, page_state) |
205 return | 204 return |
206 | 205 |
207 try: | 206 try: |
208 test.Run(options, page, tab, results) | 207 test.Run(options, page, tab, results) |
209 except page_test.Failure, ex: | 208 except page_test.Failure, ex: |
210 logging.info('%s: %s', ex, page.url) | 209 logging.info('%s: %s', ex, page.url) |
211 results.AddFailure(page, ex, traceback.format_exc()) | 210 results.AddFailure(page, ex, traceback.format_exc()) |
212 return | 211 return |
213 except util.TimeoutException, ex: | 212 except util.TimeoutException, ex: |
214 logging.warning('Timed out while running %s', page.url) | 213 logging.warning('Timed out while running %s', page.url) |
215 results.AddFailure(page, ex, traceback.format_exc()) | 214 results.AddFailure(page, ex, traceback.format_exc()) |
216 return | 215 return |
217 except tab_crash_exception.TabCrashException, ex: | 216 except exceptions.TabCrashException, ex: |
218 results.AddFailure(page, ex, traceback.format_exc()) | 217 results.AddFailure(page, ex, traceback.format_exc()) |
219 raise | 218 raise |
220 except browser_gone_exception.BrowserGoneException: | 219 except exceptions.BrowserGoneException: |
221 raise | 220 raise |
222 except Exception, ex: | 221 except Exception, ex: |
223 logging.error('Unexpected failure while running %s: %s', | 222 logging.error('Unexpected failure while running %s: %s', |
224 page.url, traceback.format_exc()) | 223 page.url, traceback.format_exc()) |
225 raise | 224 raise |
226 finally: | 225 finally: |
227 self._CleanUpPage(page, tab, page_state) | 226 self._CleanUpPage(page, tab, page_state) |
228 | 227 |
229 results.AddSuccess(page) | 228 results.AddSuccess(page) |
230 | 229 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 tab.browser.credentials.LoginNoLongerNeeded(tab, page.credentials) | 310 tab.browser.credentials.LoginNoLongerNeeded(tab, page.credentials) |
312 try: | 311 try: |
313 tab.EvaluateJavaScript("""window.chrome && chrome.benchmarking && | 312 tab.EvaluateJavaScript("""window.chrome && chrome.benchmarking && |
314 chrome.benchmarking.closeConnections()""") | 313 chrome.benchmarking.closeConnections()""") |
315 except Exception: | 314 except Exception: |
316 pass | 315 pass |
317 | 316 |
318 @staticmethod | 317 @staticmethod |
319 def AddCommandLineOptions(parser): | 318 def AddCommandLineOptions(parser): |
320 page_filter_module.PageFilter.AddCommandLineOptions(parser) | 319 page_filter_module.PageFilter.AddCommandLineOptions(parser) |
OLD | NEW |