| 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 desktop browsers that can be controlled by telemetry.""" | 4 """Finds desktop browsers that can be controlled by telemetry.""" |
| 5 | 5 |
| 6 import logging | 6 import logging |
| 7 from operator import attrgetter | 7 from operator import attrgetter |
| 8 import os | 8 import os |
| 9 import platform | 9 import platform |
| 10 import subprocess | 10 import subprocess |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 from telemetry.core import browser | 13 from telemetry.core import browser |
| 14 from telemetry.core import platform as core_platform | 14 from telemetry.core import platform as core_platform |
| 15 from telemetry.core import possible_browser | 15 from telemetry.core import possible_browser |
| 16 from telemetry.core import profile_types | |
| 17 from telemetry.core import util | 16 from telemetry.core import util |
| 18 from telemetry.core.chrome import cros_interface | 17 from telemetry.core.chrome import cros_interface |
| 19 from telemetry.core.chrome import desktop_browser_backend | 18 from telemetry.core.chrome import desktop_browser_backend |
| 20 | 19 |
| 21 ALL_BROWSER_TYPES = ','.join([ | 20 ALL_BROWSER_TYPES = ','.join([ |
| 22 'exact', | 21 'exact', |
| 23 'release', | 22 'release', |
| 24 'release_x64', | 23 'release_x64', |
| 25 'debug', | 24 'debug', |
| 26 'debug_x64', | 25 'debug_x64', |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 super(PossibleDesktopBrowser, self).__init__(browser_type, options) | 36 super(PossibleDesktopBrowser, self).__init__(browser_type, options) |
| 38 self._local_executable = executable | 37 self._local_executable = executable |
| 39 self._flash_path = flash_path | 38 self._flash_path = flash_path |
| 40 self._is_content_shell = is_content_shell | 39 self._is_content_shell = is_content_shell |
| 41 self._browser_directory = browser_directory | 40 self._browser_directory = browser_directory |
| 42 self.is_local_build = is_local_build | 41 self.is_local_build = is_local_build |
| 43 | 42 |
| 44 def __repr__(self): | 43 def __repr__(self): |
| 45 return 'PossibleDesktopBrowser(browser_type=%s)' % self.browser_type | 44 return 'PossibleDesktopBrowser(browser_type=%s)' % self.browser_type |
| 46 | 45 |
| 47 # Constructs a browser. | 46 def Create(self): |
| 48 # Returns a touple of the form: (browser, backend) | |
| 49 def _CreateBrowserInternal(self, delete_profile_dir_after_run): | |
| 50 backend = desktop_browser_backend.DesktopBrowserBackend( | 47 backend = desktop_browser_backend.DesktopBrowserBackend( |
| 51 self._options, self._local_executable, self._flash_path, | 48 self._options, self._local_executable, self._flash_path, |
| 52 self._is_content_shell, self._browser_directory, | 49 self._is_content_shell, self._browser_directory, |
| 53 delete_profile_dir_after_run=delete_profile_dir_after_run) | 50 output_profile_path=self._options.output_profile_path) |
| 54 b = browser.Browser(backend, | 51 b = browser.Browser(backend, |
| 55 core_platform.CreatePlatformBackendForCurrentOS()) | 52 core_platform.CreatePlatformBackendForCurrentOS()) |
| 56 return b | 53 return b |
| 57 | 54 |
| 58 def Create(self): | |
| 59 # If a dirty profile is needed, instantiate an initial browser object and | |
| 60 # use that to create a dirty profile. | |
| 61 creator_class = profile_types.GetProfileCreator(self.options.profile_type) | |
| 62 if creator_class: | |
| 63 logging.info( | |
| 64 'Creating a dirty profile of type: %s', self.options.profile_type) | |
| 65 (b, backend) = \ | |
| 66 self._CreateBrowserInternal(delete_profile_dir_after_run=False) | |
| 67 with b as b: | |
| 68 creator = creator_class(b) | |
| 69 creator.CreateProfile() | |
| 70 dirty_profile_dir = backend.profile_directory | |
| 71 logging.info( | |
| 72 "Dirty profile created succesfully in '%s'", dirty_profile_dir) | |
| 73 | |
| 74 # Now create another browser to run tests on using the dirty profile | |
| 75 # we just created. | |
| 76 b = self._CreateBrowserInternal(delete_profile_dir_after_run=True) | |
| 77 backend.SetProfileDirectory(dirty_profile_dir) | |
| 78 else: | |
| 79 b = self._CreateBrowserInternal(delete_profile_dir_after_run=True) | |
| 80 return b | |
| 81 | |
| 82 def SupportsOptions(self, options): | 55 def SupportsOptions(self, options): |
| 83 if (len(options.extensions_to_load) != 0) and self._is_content_shell: | 56 if (len(options.extensions_to_load) != 0) and self._is_content_shell: |
| 84 return False | 57 return False |
| 85 return True | 58 return True |
| 86 | 59 |
| 87 @property | 60 @property |
| 88 def last_modification_time(self): | 61 def last_modification_time(self): |
| 89 if os.path.exists(self._local_executable): | 62 if os.path.exists(self._local_executable): |
| 90 return os.path.getmtime(self._local_executable) | 63 return os.path.getmtime(self._local_executable) |
| 91 return -1 | 64 return -1 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 if AddIfFoundWin('system', system_path): | 218 if AddIfFoundWin('system', system_path): |
| 246 break | 219 break |
| 247 | 220 |
| 248 if len(browsers) and not has_display: | 221 if len(browsers) and not has_display: |
| 249 logging.warning( | 222 logging.warning( |
| 250 'Found (%s), but you do not have a DISPLAY environment set.' % | 223 'Found (%s), but you do not have a DISPLAY environment set.' % |
| 251 ','.join([b.browser_type for b in browsers])) | 224 ','.join([b.browser_type for b in browsers])) |
| 252 return [] | 225 return [] |
| 253 | 226 |
| 254 return browsers | 227 return browsers |
| OLD | NEW |