Chromium Code Reviews| 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 """Finds browsers that can be controlled by telemetry.""" | 4 """Finds browsers that can be controlled by telemetry.""" |
| 5 | 5 |
| 6 import logging | 6 import logging |
| 7 | 7 |
| 8 from telemetry.core.chrome import android_browser_finder | 8 from telemetry.core.chrome import android_browser_finder |
| 9 from telemetry.core.chrome import cros_browser_finder | 9 from telemetry.core.chrome import cros_browser_finder |
| 10 from telemetry.core.chrome import desktop_browser_finder | 10 from telemetry.core.chrome import desktop_browser_finder |
| 11 | 11 |
| 12 ALL_BROWSER_TYPES = ( | 12 BROWSER_FINDERS = [ |
| 13 desktop_browser_finder.ALL_BROWSER_TYPES + ',' + | 13 desktop_browser_finder, |
| 14 android_browser_finder.ALL_BROWSER_TYPES + ',' + | 14 android_browser_finder, |
| 15 cros_browser_finder.ALL_BROWSER_TYPES) | 15 cros_browser_finder |
|
achuithb
2013/07/24 01:20:07
Why not reverse this? If the user specifies --remo
| |
| 16 ] | |
| 17 | |
| 18 ALL_BROWSER_TYPES = ','.join([bf.ALL_BROWSER_TYPES for bf in BROWSER_FINDERS]) | |
| 19 | |
| 16 | 20 |
| 17 class BrowserTypeRequiredException(Exception): | 21 class BrowserTypeRequiredException(Exception): |
| 18 pass | 22 pass |
| 19 | 23 |
| 20 class BrowserFinderException(Exception): | 24 class BrowserFinderException(Exception): |
| 21 pass | 25 pass |
| 22 | 26 |
| 23 def FindBrowser(options): | 27 def FindBrowser(options): |
| 24 """Finds the best PossibleBrowser object to run given the provided | 28 """Finds the best PossibleBrowser object to run given the provided |
| 25 BrowserOptions object. The returned possiblity object can then be used to | 29 BrowserOptions object. The returned possiblity object can then be used to |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 36 | 40 |
| 37 if options.browser_type == 'cros-chrome' and options.cros_remote == None: | 41 if options.browser_type == 'cros-chrome' and options.cros_remote == None: |
| 38 raise BrowserFinderException( | 42 raise BrowserFinderException( |
| 39 'browser_type=cros-chrome requires cros_remote be set.') | 43 'browser_type=cros-chrome requires cros_remote be set.') |
| 40 if (options.browser_type != 'cros-chrome' and | 44 if (options.browser_type != 'cros-chrome' and |
| 41 options.browser_type != 'cros-chrome-guest' and | 45 options.browser_type != 'cros-chrome-guest' and |
| 42 options.cros_remote != None): | 46 options.cros_remote != None): |
| 43 raise BrowserFinderException( | 47 raise BrowserFinderException( |
| 44 'cros_remote requires browser_type=cros-chrome or cros-chrome-guest.') | 48 'cros_remote requires browser_type=cros-chrome or cros-chrome-guest.') |
| 45 | 49 |
| 50 browsers = [] | |
| 51 default_browser = None | |
| 52 for finder in BROWSER_FINDERS: | |
| 53 curr_browsers = finder.FindAllAvailableBrowsers(options) | |
| 54 if not default_browser: | |
| 55 default_browser = finder.SelectDefaultBrowser(curr_browsers) | |
| 56 browsers.extend(curr_browsers) | |
| 57 | |
| 46 if options.browser_type == None: | 58 if options.browser_type == None: |
| 47 raise BrowserTypeRequiredException('browser_type must be specified') | 59 if default_browser: |
| 48 | 60 logging.warning('--browser omitted. Using most recent local build: %s' % |
| 49 browsers = [] | 61 default_browser.browser_type) |
| 50 browsers.extend(desktop_browser_finder.FindAllAvailableBrowsers(options)) | 62 return default_browser |
| 51 browsers.extend(android_browser_finder.FindAllAvailableBrowsers(options)) | 63 raise BrowserTypeRequiredException( |
| 52 browsers.extend(cros_browser_finder.FindAllAvailableBrowsers(options)) | 64 '--browser must be specified. Available browsers:\n%s' % |
| 53 | 65 '\n'.join(sorted(set([b.browser_type for b in browsers])))) |
| 54 if options.browser_type == 'any': | |
| 55 types = ALL_BROWSER_TYPES.split(',') | |
| 56 def compare_browsers_on_type_priority(x, y): | |
| 57 x_idx = types.index(x.browser_type) | |
| 58 y_idx = types.index(y.browser_type) | |
| 59 return x_idx - y_idx | |
| 60 browsers.sort(compare_browsers_on_type_priority) | |
| 61 if len(browsers) >= 1: | |
| 62 return browsers[0] | |
| 63 else: | |
| 64 return None | |
| 65 | 66 |
| 66 matching_browsers = [b for b in browsers | 67 matching_browsers = [b for b in browsers |
| 67 if b.browser_type == options.browser_type and b.SupportsOptions(options)] | 68 if b.browser_type == options.browser_type and b.SupportsOptions(options)] |
| 68 | 69 |
| 69 if len(matching_browsers) == 1: | 70 if len(matching_browsers) == 1: |
| 70 return matching_browsers[0] | 71 return matching_browsers[0] |
| 71 elif len(matching_browsers) > 1: | 72 elif len(matching_browsers) > 1: |
| 72 logging.warning('Multiple browsers of the same type found: %s' % ( | 73 logging.warning('Multiple browsers of the same type found: %s' % ( |
| 73 repr(matching_browsers))) | 74 repr(matching_browsers))) |
| 74 return matching_browsers[0] | 75 return matching_browsers[0] |
| 75 else: | 76 else: |
| 76 return None | 77 return None |
| 77 | 78 |
| 78 def GetAllAvailableBrowserTypes(options): | 79 def GetAllAvailableBrowserTypes(options): |
| 79 """Returns an array of browser types supported on this system. | 80 """Returns an array of browser types supported on this system. |
| 80 A BrowserFinderException will be raised if the BrowserOptions argument is | 81 A BrowserFinderException will be raised if the BrowserOptions argument is |
| 81 improperly set or if an error occurs when finding a browser. | 82 improperly set or if an error occurs when finding a browser. |
| 82 """ | 83 """ |
| 83 browsers = [] | 84 browsers = [] |
| 84 browsers.extend(desktop_browser_finder.FindAllAvailableBrowsers(options)) | 85 for finder in BROWSER_FINDERS: |
| 85 browsers.extend(android_browser_finder.FindAllAvailableBrowsers(options)) | 86 browsers.extend(finder.FindAllAvailableBrowsers(options)) |
| 86 browsers.extend(cros_browser_finder.FindAllAvailableBrowsers(options)) | |
| 87 | 87 |
| 88 type_list = set([browser.browser_type for browser in browsers]) | 88 type_list = set([browser.browser_type for browser in browsers]) |
| 89 type_list = list(type_list) | 89 type_list = list(type_list) |
| 90 type_list.sort() | 90 type_list.sort() |
| 91 return type_list | 91 return type_list |
| OLD | NEW |