OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 logging | 5 import logging |
6 import optparse | 6 import optparse |
7 import os | 7 import os |
8 import random | 8 import random |
9 import sys | 9 import sys |
10 import tempfile | 10 import tempfile |
11 import time | 11 import time |
12 | 12 |
13 from telemetry import decorators | 13 from telemetry import decorators |
14 from telemetry.core import browser_finder | 14 from telemetry.core import browser_finder |
15 from telemetry.core import browser_info | 15 from telemetry.core import browser_info |
16 from telemetry.core import exceptions | 16 from telemetry.core import exceptions |
17 from telemetry.core import util | 17 from telemetry.core import util |
18 from telemetry.core import wpr_modes | 18 from telemetry.core import wpr_modes |
19 from telemetry.core.platform.profiler import profiler_finder | 19 from telemetry.core.platform.profiler import profiler_finder |
20 from telemetry.page import page_filter | 20 from telemetry.page import page_filter |
21 from telemetry.page import page_test | 21 from telemetry.page import page_test |
22 from telemetry.page.actions import navigate | |
23 from telemetry.page.actions import page_action | 22 from telemetry.page.actions import page_action |
24 from telemetry.results import results_options | 23 from telemetry.results import results_options |
25 from telemetry.util import cloud_storage | 24 from telemetry.util import cloud_storage |
26 from telemetry.util import exception_formatter | 25 from telemetry.util import exception_formatter |
27 from telemetry.value import failure | 26 from telemetry.value import failure |
28 from telemetry.value import skip | 27 from telemetry.value import skip |
29 | 28 |
30 | 29 |
31 class _RunState(object): | 30 class _RunState(object): |
32 def __init__(self): | 31 def __init__(self): |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 if is_repeating: | 132 if is_repeating: |
134 output_file = util.GetSequentialFileName(output_file) | 133 output_file = util.GetSequentialFileName(output_file) |
135 self.browser.platform.profiling_controller.Start( | 134 self.browser.platform.profiling_controller.Start( |
136 finder_options.profiler, output_file) | 135 finder_options.profiler, output_file) |
137 | 136 |
138 def StopProfiling(self): | 137 def StopProfiling(self): |
139 if self.browser: | 138 if self.browser: |
140 self.browser.platform.profiling_controller.Stop() | 139 self.browser.platform.profiling_controller.Stop() |
141 | 140 |
142 | 141 |
143 class PageState(object): | 142 class _PageState(object): |
144 def __init__(self, page, tab): | 143 def __init__(self, page, tab): |
145 self.page = page | 144 self.page = page |
146 self.tab = tab | 145 self.tab = tab |
147 | 146 |
148 self._did_login = False | 147 self._did_login = False |
149 | 148 |
150 def PreparePage(self, test=None): | 149 def PreparePage(self, test): |
151 if self.page.is_file: | 150 if self.page.is_file: |
152 self.tab.browser.SetHTTPServerDirectories( | 151 self.tab.browser.SetHTTPServerDirectories( |
153 self.page.page_set.serving_dirs | set([self.page.serving_dir])) | 152 self.page.page_set.serving_dirs | set([self.page.serving_dir])) |
154 | 153 |
155 if self.page.credentials: | 154 if self.page.credentials: |
156 if not self.tab.browser.credentials.LoginNeeded( | 155 if not self.tab.browser.credentials.LoginNeeded( |
157 self.tab, self.page.credentials): | 156 self.tab, self.page.credentials): |
158 raise page_test.Failure('Login as ' + self.page.credentials + ' failed') | 157 raise page_test.Failure('Login as ' + self.page.credentials + ' failed') |
159 self._did_login = True | 158 self._did_login = True |
160 | 159 |
161 if test: | 160 if test.clear_cache_before_each_run: |
162 if test.clear_cache_before_each_run: | 161 self.tab.ClearCache(force=True) |
163 self.tab.ClearCache(force=True) | |
164 | 162 |
165 def ImplicitPageNavigation(self, test=None): | 163 def ImplicitPageNavigation(self, test): |
166 """Executes the implicit navigation that occurs for every page iteration. | 164 """Executes the implicit navigation that occurs for every page iteration. |
167 | 165 |
168 This function will be called once per page before any actions are executed. | 166 This function will be called once per page before any actions are executed. |
169 """ | 167 """ |
170 if test: | 168 test.WillNavigateToPage(self.page, self.tab) |
171 test.WillNavigateToPage(self.page, self.tab) | 169 test.RunNavigateSteps(self.page, self.tab) |
172 test.RunNavigateSteps(self.page, self.tab) | 170 test.DidNavigateToPage(self.page, self.tab) |
173 test.DidNavigateToPage(self.page, self.tab) | |
174 else: | |
175 i = navigate.NavigateAction() | |
176 i.RunAction(self.page, self.tab, None) | |
177 | 171 |
178 def CleanUpPage(self, test): | 172 def CleanUpPage(self, test): |
179 test.CleanUpAfterPage(self.page, self.tab) | 173 test.CleanUpAfterPage(self.page, self.tab) |
180 if self.page.credentials and self._did_login: | 174 if self.page.credentials and self._did_login: |
181 self.tab.browser.credentials.LoginNoLongerNeeded( | 175 self.tab.browser.credentials.LoginNoLongerNeeded( |
182 self.tab, self.page.credentials) | 176 self.tab, self.page.credentials) |
183 | 177 |
184 | 178 |
185 def AddCommandLineArgs(parser): | 179 def AddCommandLineArgs(parser): |
186 page_filter.PageFilter.AddCommandLineArgs(parser) | 180 page_filter.PageFilter.AddCommandLineArgs(parser) |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 results.DidRunPage(page) | 457 results.DidRunPage(page) |
464 return valid_pages | 458 return valid_pages |
465 | 459 |
466 | 460 |
467 def _RunPage(test, page, state, expectation, results): | 461 def _RunPage(test, page, state, expectation, results): |
468 if expectation == 'skip': | 462 if expectation == 'skip': |
469 logging.debug('Skipping test: Skip expectation for %s', page.url) | 463 logging.debug('Skipping test: Skip expectation for %s', page.url) |
470 results.AddValue(skip.SkipValue(page, 'Skipped by test expectations')) | 464 results.AddValue(skip.SkipValue(page, 'Skipped by test expectations')) |
471 return | 465 return |
472 | 466 |
473 page_state = PageState(page, test.TabForPage(page, state.browser)) | 467 page_state = _PageState(page, test.TabForPage(page, state.browser)) |
474 | 468 |
475 def ProcessError(): | 469 def ProcessError(): |
476 if expectation == 'fail': | 470 if expectation == 'fail': |
477 msg = 'Expected exception while running %s' % page.url | 471 msg = 'Expected exception while running %s' % page.url |
478 else: | 472 else: |
479 msg = 'Exception while running %s' % page.url | 473 msg = 'Exception while running %s' % page.url |
480 results.AddValue(failure.FailureValue(page, sys.exc_info())) | 474 results.AddValue(failure.FailureValue(page, sys.exc_info())) |
481 exception_formatter.PrintFormattedException(msg=msg) | 475 exception_formatter.PrintFormattedException(msg=msg) |
482 | 476 |
483 try: | 477 try: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 logging.warning('Device is thermally throttled before running ' | 524 logging.warning('Device is thermally throttled before running ' |
531 'performance tests, results will vary.') | 525 'performance tests, results will vary.') |
532 | 526 |
533 | 527 |
534 def _CheckThermalThrottling(platform): | 528 def _CheckThermalThrottling(platform): |
535 if not platform.CanMonitorThermalThrottling(): | 529 if not platform.CanMonitorThermalThrottling(): |
536 return | 530 return |
537 if platform.HasBeenThermallyThrottled(): | 531 if platform.HasBeenThermallyThrottled(): |
538 logging.warning('Device has been thermally throttled during ' | 532 logging.warning('Device has been thermally throttled during ' |
539 'performance tests, results will vary.') | 533 'performance tests, results will vary.') |
OLD | NEW |