def _StartBrowser(self, page): assert self._browser is None self._AllowInteractionForStage('before-start-browser') if self._page_test: self._page_test.WillStartBrowser(self.platform) # Create a deep copy of browser_options so that we can add page-level # arguments and url to it without polluting the run for the next page. browser_options = self._finder_options.browser_options.Copy() browser_options.AppendExtraBrowserArgs(page.extra_browser_args) self._possible_browser.SetUpEnvironment(browser_options) # Clear caches before starting browser. self.platform.FlushDnsCache() if browser_options.clear_sytem_cache_for_browser_and_profile_on_start: # TODO(crbug.com/811244): Consider whether we can do this unconditionally. self._possible_browser.FlushOsPageCaches() self._browser = self._possible_browser.Create() if self._page_test: self._page_test.DidStartBrowser(self.browser) if browser_options.assert_gpu_compositing: gpu_compositing_checker.AssertGpuCompositingEnabled( self._browser.GetSystemInfo()) if self._first_browser: self._first_browser = False self._AllowInteractionForStage('after-start-browser')
def _GetBrowserInstance(self, existing, clear_caches, startup_url=None): browser_backend = android_browser_backend.AndroidBrowserBackend( self._platform_backend, self._browser_options, self.browser_directory, self.profile_directory, self._backend_settings) # TODO(crbug.com/811244): Remove when this is handled by shared state. if clear_caches: self._ClearCachesOnStart() try: returned_browser = browser.Browser(browser_backend, self._platform_backend, startup_args=(), startup_url=startup_url, find_existing=existing) # TODO(crbug.com/916086): Move this assertion to callers. if self._browser_options.assert_gpu_compositing: gpu_compositing_checker.AssertGpuCompositingEnabled( returned_browser.GetSystemInfo()) return returned_browser except Exception: exc_info = sys.exc_info() logging.error('Failed with %s while creating Android browser.', exc_info[0].__name__) try: browser_backend.Close() except Exception: # pylint: disable=broad-except logging.exception( 'Secondary failure while closing browser backend.') raise exc_info[0], exc_info[1], exc_info[2]
def _StartBrowser(self, page): assert self._browser is None self._AllowInteractionForStage('before-start-browser') if self._page_test: self._page_test.WillStartBrowser(self.platform) # Create a deep copy of browser_options so that we can add page-level # arguments and url to it without polluting the run for the next page. browser_options = self._finder_options.browser_options.Copy() browser_options.AppendExtraBrowserArgs(page.extra_browser_args) self._possible_browser.SetUpEnvironment(browser_options) # Clear caches before starting browser. self.platform.FlushDnsCache() if browser_options.flush_os_page_caches_on_start: self._possible_browser.FlushOsPageCaches() self._browser = self._possible_browser.Create() if self._page_test: self._page_test.DidStartBrowser(self.browser) if browser_options.assert_gpu_compositing: gpu_compositing_checker.AssertGpuCompositingEnabled( self._browser.GetSystemInfo()) if self._first_browser: self._first_browser = False # Cut back on mostly redundant logs length per crbug.com/943650. self._finder_options.browser_options.trim_logs = True self._AllowInteractionForStage('after-start-browser')
def _GetBrowserInstance(self, existing=False): browser_backend = android_browser_backend.AndroidBrowserBackend( self._platform_backend, self._browser_options, self.browser_directory, self.profile_directory, self._backend_settings) self._ClearCachesOnStart() try: returned_browser = browser.Browser(browser_backend, self._platform_backend, startup_args=(), find_existing=existing) if self._browser_options.assert_gpu_compositing: gpu_compositing_checker.AssertGpuCompositingEnabled( returned_browser.GetSystemInfo()) return returned_browser except Exception: exc_info = sys.exc_info() logging.error('Failed with %s while creating Android browser.', exc_info[0].__name__) try: browser_backend.Close() except Exception: # pylint: disable=broad-except logging.exception( 'Secondary failure while closing browser backend.') raise exc_info[0], exc_info[1], exc_info[2] finally: # After the browser has been launched (or not) it's fine to restore the # command line flags on the device. self._RestoreCommandLineFlags()
def Create(self, clear_caches=True): if self._flash_path and not os.path.exists(self._flash_path): logging.warning( 'Could not find Flash at %s. Continuing without Flash.\n' 'To run with Flash, check it out via http://go/read-src-internal', self._flash_path) self._flash_path = None self._InitPlatformIfNeeded() num_retries = 3 for x in range(0, num_retries): returned_browser = None try: # Note: we need to regenerate the browser startup arguments for each # browser startup attempt since the state of the startup arguments # may not be guaranteed the same each time # For example, see: crbug.com/865895#c17 startup_args = self.GetBrowserStartupArgs(self._browser_options) startup_url = self._browser_options.startup_url returned_browser = None browser_backend = desktop_browser_backend.DesktopBrowserBackend( self._platform_backend, self._browser_options, self._browser_directory, self._profile_directory, self._local_executable, self._flash_path, self._is_content_shell) # TODO(crbug.com/811244): Remove when this is handled by shared state. if clear_caches: self._ClearCachesOnStart() returned_browser = browser.Browser( browser_backend, self._platform_backend, startup_args, startup_url=startup_url) # TODO(crbug.com/916086): Move this assertion to callers. if self._browser_options.assert_gpu_compositing: gpu_compositing_checker.AssertGpuCompositingEnabled( returned_browser.GetSystemInfo()) return returned_browser # Do not retry if gpu assertion failure is raised. except gpu_compositing_checker.GpuCompositingAssertionFailure: raise except Exception: # pylint: disable=broad-except report = 'Browser creation failed (attempt %d of %d)' % ( (x + 1), num_retries) if x < num_retries - 1: report += ', retrying' logging.warning(report) # Attempt to clean up things left over from the failed browser startup. try: if returned_browser: returned_browser.DumpStateUponFailure() returned_browser.Close() except Exception: # pylint: disable=broad-except pass # Re-raise the exception the last time through. if x == num_retries - 1: raise
def Create(self): if self._flash_path and not os.path.exists(self._flash_path): logging.warning( 'Could not find Flash at %s. Continuing without Flash.\n' 'To run with Flash, check it out via http://go/read-src-internal', self._flash_path) self._flash_path = None self._InitPlatformIfNeeded() startup_args = self.GetBrowserStartupArgs(self._browser_options) num_retries = 3 for x in range(0, num_retries): returned_browser = None try: returned_browser = None browser_backend = desktop_browser_backend.DesktopBrowserBackend( self._platform_backend, self._browser_options, self._browser_directory, self._profile_directory, self._local_executable, self._flash_path, self._is_content_shell) self._ClearCachesOnStart() returned_browser = browser.Browser(browser_backend, self._platform_backend, startup_args) if self._browser_options.assert_gpu_compositing: gpu_compositing_checker.AssertGpuCompositingEnabled( returned_browser.GetSystemInfo()) return returned_browser # Do not retry if gpu assertion failure is raised. except gpu_compositing_checker.GpuCompositingAssertionFailure: raise except Exception: # pylint: disable=broad-except report = 'Browser creation failed (attempt %d of %d)' % ( (x + 1), num_retries) if x < num_retries - 1: report += ', retrying' logging.warning(report) # Attempt to clean up things left over from the failed browser startup. try: if returned_browser: returned_browser.Close() except Exception: # pylint: disable=broad-except pass # Re-raise the exception the last time through. if x == num_retries - 1: raise
def Create(self): startup_args = self.GetBrowserStartupArgs(self._browser_options) browser_backend = cros_browser_backend.CrOSBrowserBackend( self._platform_backend, self._browser_options, self.browser_directory, self.profile_directory, self._is_guest) self._ClearCachesOnStart() if self._browser_options.create_browser_with_oobe: return cros_browser_with_oobe.CrOSBrowserWithOOBE( browser_backend, self._platform_backend, startup_args) returned_browser = browser.Browser( browser_backend, self._platform_backend, startup_args) if self._browser_options.assert_gpu_compositing: gpu_compositing_checker.AssertGpuCompositingEnabled( returned_browser.GetSystemInfo()) return returned_browser
def testAssertGpuCompositingEnabledPassed(self): data = { 'model_name': 'MacBookPro 10.1', 'gpu': { 'devices': [ { 'vendor_id': 1000, 'device_id': 2000, 'vendor_string': 'a', 'device_string': 'b' }, ], 'feature_status': { 'gpu_compositing': 'enabled' }, } } info = system_info.SystemInfo.FromDict(data) gpu_compositing_checker.AssertGpuCompositingEnabled(info)
def Create(self, clear_caches=True): startup_args = self.GetBrowserStartupArgs(self._browser_options) browser_backend = cros_browser_backend.CrOSBrowserBackend( self._platform_backend, self._browser_options, self.browser_directory, self.profile_directory, self._is_guest) # TODO(crbug.com/811244): Remove when this is handled by shared state. if clear_caches: self._ClearCachesOnStart() if self._browser_options.create_browser_with_oobe: return cros_browser_with_oobe.CrOSBrowserWithOOBE( browser_backend, self._platform_backend, startup_args) returned_browser = browser.Browser(browser_backend, self._platform_backend, startup_args) if self._browser_options.assert_gpu_compositing: gpu_compositing_checker.AssertGpuCompositingEnabled( returned_browser.GetSystemInfo()) return returned_browser
def testAssertGpuCompositingEnabledFailed(self): data = { 'model_name': 'MacBookPro 10.1', 'gpu': { 'devices': [ { 'vendor_id': 1000, 'device_id': 2000, 'vendor_string': 'a', 'device_string': 'b' }, ], 'feature_status': { 'gpu_compositing': 'disabled' }, } } info = system_info.SystemInfo.FromDict(data) with self.assertRaises( gpu_compositing_checker.GpuCompositingAssertionFailure): gpu_compositing_checker.AssertGpuCompositingEnabled(info)