| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 collections | 5 import collections |
| 6 import logging | 6 import logging |
| 7 import re | 7 import re |
| 8 import sys | |
| 9 import urllib | 8 import urllib |
| 10 | 9 |
| 11 from telemetry import decorators | |
| 12 from telemetry import story as story_module | 10 from telemetry import story as story_module |
| 13 # TODO(perezju): Remove references to telementry.internal when | 11 # TODO(perezju): Remove references to telementry.internal when |
| 14 # https://github.com/catapult-project/catapult/issues/2102 is resolved. | 12 # https://github.com/catapult-project/catapult/issues/2102 is resolved. |
| 15 from telemetry.internal.browser import browser_finder | 13 from telemetry.internal.browser import browser_finder |
| 16 from telemetry.internal.browser import browser_finder_exceptions | 14 from telemetry.internal.browser import browser_finder_exceptions |
| 17 from telemetry.util import wpr_modes | 15 from telemetry.util import wpr_modes |
| 18 | 16 |
| 19 from page_sets.top_10_mobile import URL_LIST | 17 from page_sets.top_10_mobile import URL_LIST |
| 20 | 18 |
| 21 | 19 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 (s.browser_type, None) for s in story_set) | 69 (s.browser_type, None) for s in story_set) |
| 72 self._current_story = None | 70 self._current_story = None |
| 73 self._current_browser = None | 71 self._current_browser = None |
| 74 self._current_tab = None | 72 self._current_tab = None |
| 75 | 73 |
| 76 possible_browser = self._PrepareBrowser('default', finder_options) | 74 possible_browser = self._PrepareBrowser('default', finder_options) |
| 77 if not possible_browser: | 75 if not possible_browser: |
| 78 raise browser_finder_exceptions.BrowserFinderException( | 76 raise browser_finder_exceptions.BrowserFinderException( |
| 79 'No browser found.\n\nAvailable browsers:\n%s\n' % | 77 'No browser found.\n\nAvailable browsers:\n%s\n' % |
| 80 '\n'.join(browser_finder.GetAllAvailableBrowserTypes(finder_options))) | 78 '\n'.join(browser_finder.GetAllAvailableBrowserTypes(finder_options))) |
| 81 if not finder_options.run_disabled_tests: | |
| 82 self._CheckTestEnabled(test, possible_browser) | |
| 83 | 79 |
| 84 extra_browser_types = set(story.browser_type for story in story_set) | 80 extra_browser_types = set(story.browser_type for story in story_set) |
| 85 extra_browser_types.remove('default') # Must include 'default' browser. | 81 extra_browser_types.remove('default') # Must include 'default' browser. |
| 86 for browser_type in extra_browser_types: | 82 for browser_type in extra_browser_types: |
| 87 options = _OptionsForBrowser(browser_type, finder_options) | 83 options = _OptionsForBrowser(browser_type, finder_options) |
| 88 if not self._PrepareBrowser(browser_type, options): | 84 if not self._PrepareBrowser(browser_type, options): |
| 89 logging.warning('Skipping %s (%s) because %s browser is not available', | 85 logging.warning( |
| 90 test.__name__, str(test), browser_type) | 86 'Cannot run %s (%s) because %s browser is not available', |
| 87 test.__name__, str(test), browser_type) |
| 91 logging.warning('Install %s to be able to run the test.', browser_type) | 88 logging.warning('Install %s to be able to run the test.', browser_type) |
| 92 sys.exit(0) | 89 raise Exception("Browser not available, unable to run benchmark.") |
| 93 | 90 |
| 94 # TODO(crbug/404771): Move network controller options out of | 91 # TODO(crbug/404771): Move network controller options out of |
| 95 # browser_options and into finder_options. | 92 # browser_options and into finder_options. |
| 96 browser_options = finder_options.browser_options | 93 browser_options = finder_options.browser_options |
| 97 if finder_options.use_live_sites: | 94 if finder_options.use_live_sites: |
| 98 wpr_mode = wpr_modes.WPR_OFF | 95 wpr_mode = wpr_modes.WPR_OFF |
| 99 elif browser_options.wpr_mode == wpr_modes.WPR_RECORD: | 96 elif browser_options.wpr_mode == wpr_modes.WPR_RECORD: |
| 100 wpr_mode = wpr_modes.WPR_RECORD | 97 wpr_mode = wpr_modes.WPR_RECORD |
| 101 else: | 98 else: |
| 102 wpr_mode = wpr_modes.WPR_REPLAY | 99 wpr_mode = wpr_modes.WPR_REPLAY |
| 103 | 100 |
| 104 self.platform.network_controller.Open(wpr_mode, | 101 self.platform.network_controller.Open(wpr_mode, |
| 105 browser_options.extra_wpr_args) | 102 browser_options.extra_wpr_args) |
| 106 | 103 |
| 107 @property | 104 @property |
| 108 def current_tab(self): | 105 def current_tab(self): |
| 109 return self._current_tab | 106 return self._current_tab |
| 110 | 107 |
| 111 @property | 108 @property |
| 112 def platform(self): | 109 def platform(self): |
| 113 return self._platform | 110 return self._platform |
| 114 | 111 |
| 115 def _CheckTestEnabled(self, test, possible_browser): | |
| 116 should_skip, msg = decorators.ShouldSkip(test, possible_browser) | |
| 117 if should_skip: | |
| 118 logging.warning(msg) | |
| 119 logging.warning('You are trying to run a disabled test.') | |
| 120 logging.warning( | |
| 121 'Pass --also-run-disabled-tests to squelch this message.') | |
| 122 sys.exit(0) | |
| 123 | |
| 124 def _PrepareBrowser(self, browser_type, options): | 112 def _PrepareBrowser(self, browser_type, options): |
| 125 """Add a browser to the dict of possible browsers. | 113 """Add a browser to the dict of possible browsers. |
| 126 | 114 |
| 127 TODO(perezju): When available, use the GetBrowserForPlatform API instead. | 115 TODO(perezju): When available, use the GetBrowserForPlatform API instead. |
| 128 See: crbug.com/570348 | 116 See: crbug.com/570348 |
| 129 | 117 |
| 130 Returns: | 118 Returns: |
| 131 The possible browser if found, or None otherwise. | 119 The possible browser if found, or None otherwise. |
| 132 """ | 120 """ |
| 133 possible_browser = browser_finder.FindBrowser(options) | 121 possible_browser = browser_finder.FindBrowser(options) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 url=GOOGLE_SEARCH + urllib.urlencode({'q': query}), | 250 url=GOOGLE_SEARCH + urllib.urlencode({'q': query}), |
| 263 browser_type='android-webview', | 251 browser_type='android-webview', |
| 264 phase='on_webview')) | 252 phase='on_webview')) |
| 265 | 253 |
| 266 # Stories that run on the browser selected by command line options. | 254 # Stories that run on the browser selected by command line options. |
| 267 self.AddStory(SinglePage( | 255 self.AddStory(SinglePage( |
| 268 name=re.sub(r'\W+', '_', url), | 256 name=re.sub(r'\W+', '_', url), |
| 269 url=url, | 257 url=url, |
| 270 browser_type='default', | 258 browser_type='default', |
| 271 phase='on_chrome')) | 259 phase='on_chrome')) |
| OLD | NEW |