def __init__(self, browser_options, backend_settings, rndis, output_profile_path, extensions_to_load): super(AndroidBrowserBackend, self).__init__( is_content_shell=backend_settings.is_content_shell, supports_extensions=False, browser_options=browser_options, output_profile_path=output_profile_path, extensions_to_load=extensions_to_load) if len(extensions_to_load) > 0: raise browser_backend.ExtensionsNotSupportedException( 'Android browser does not support extensions.') # Initialize fields so that an explosion during init doesn't break in Close. self._adb = backend_settings.adb self._backend_settings = backend_settings self._saved_cmdline = None self._port = adb_commands.AllocateTestServerPort() # Kill old browser. self._adb.CloseApplication(self._backend_settings.package) if self._adb.Adb().CanAccessProtectedFileContents(): if not self.browser_options.dont_override_profile: self._backend_settings.RemoveProfile() if self.browser_options.profile_dir: self._backend_settings.PushProfile(self.browser_options.profile_dir) # Pre-configure RNDIS forwarding. self._rndis_forwarder = None if rndis or self.browser_options.netsim: self._rndis_forwarder = android_rndis.RndisForwarderWithRoot(self._adb) self.WEBPAGEREPLAY_HOST = self._rndis_forwarder.host_ip # TODO(szym): only override DNS if WPR has privileges to proxy on port 25. self._override_dns = self.browser_options.netsim
def __init__(self, desktop_platform_backend, browser_options, executable, flash_path, is_content_shell, browser_directory, output_profile_path, extensions_to_load): super(DesktopBrowserBackend, self).__init__(desktop_platform_backend, supports_tab_control=not is_content_shell, supports_extensions=not is_content_shell, browser_options=browser_options, output_profile_path=output_profile_path, extensions_to_load=extensions_to_load) # Initialize fields so that an explosion during init doesn't break in Close. self._proc = None self._tmp_profile_dir = None self._tmp_output_file = None self._executable = executable if not self._executable: raise Exception('Cannot create browser, no executable found!') assert not flash_path or os.path.exists(flash_path) self._flash_path = flash_path self._is_content_shell = is_content_shell if len(extensions_to_load) > 0 and is_content_shell: raise browser_backend.ExtensionsNotSupportedException( 'Content shell does not support extensions.') self._browser_directory = browser_directory self._port = None self._tmp_minidump_dir = tempfile.mkdtemp() self._crash_service = None self._SetupProfile()
def __init__(self, browser_options, backend_settings, use_rndis_forwarder, output_profile_path, extensions_to_load, target_arch, android_platform_backend): super(AndroidBrowserBackend, self).__init__( supports_tab_control=backend_settings.supports_tab_control, supports_extensions=False, browser_options=browser_options, output_profile_path=output_profile_path, extensions_to_load=extensions_to_load) if len(extensions_to_load) > 0: raise browser_backend.ExtensionsNotSupportedException( 'Android browser does not support extensions.') # Initialize fields so that an explosion during init doesn't break in Close. self._android_platform_backend = android_platform_backend self._backend_settings = backend_settings self._saved_cmdline = '' self._target_arch = target_arch self._saved_sslflag = '' # TODO(tonyg): This is flaky because it doesn't reserve the port that it # allocates. Need to fix this. self._port = adb_commands.AllocateTestServerPort() # Disables android.net SSL certificate check. This is necessary for # applications using the android.net stack to work with proxy HTTPS server # created by telemetry if self._backend_settings.relax_ssl_check: self._saved_sslflag = self._adb.device().GetProp( 'socket.relaxsslcheck') self._adb.device().SetProp('socket.relaxsslcheck', 'yes') # Kill old browser. self._KillBrowser() if self._adb.device().old_interface.CanAccessProtectedFileContents(): if self.browser_options.profile_dir: self._backend_settings.PushProfile( self.browser_options.profile_dir, self._adb) elif not self.browser_options.dont_override_profile: self._backend_settings.RemoveProfile(self._adb) self._forwarder_factory = android_forwarder.AndroidForwarderFactory( self._adb, use_rndis_forwarder) if self.browser_options.netsim or use_rndis_forwarder: assert use_rndis_forwarder, 'Netsim requires RNDIS forwarding.' self.wpr_port_pairs = forwarders.PortPairs( http=forwarders.PortPair(0, 80), https=forwarders.PortPair(0, 443), dns=forwarders.PortPair(0, 53)) # Set the debug app if needed. if self._adb.IsUserBuild(): logging.debug('User build device, setting debug app') self._adb.device().RunShellCommand( 'am set-debug-app --persistent %s' % self._backend_settings.package)
def __init__(self, options, backend_settings): super(AndroidBrowserBackend, self).__init__( is_content_shell=backend_settings.is_content_shell, supports_extensions=False, options=options) if len(options.extensions_to_load) > 0: raise browser_backend.ExtensionsNotSupportedException( 'Android browser does not support extensions.') # Initialize fields so that an explosion during init doesn't break in Close. self._options = options self._adb = backend_settings.adb self._backend_settings = backend_settings self._saved_cmdline = None if not options.keep_test_server_ports: adb_commands.ResetTestServerPortAllocation() self._port = adb_commands.AllocateTestServerPort() # Kill old browser. self._adb.CloseApplication(self._backend_settings.package) if self._adb.Adb().CanAccessProtectedFileContents(): if not options.dont_override_profile: self._backend_settings.RemoveProfile() if options.profile_dir: self._backend_settings.PushProfile(options.profile_dir) # Set up the command line. self._saved_cmdline = ''.join(self._adb.Adb().GetProtectedFileContents( self._backend_settings.cmdline_file) or []) args = [backend_settings.pseudo_exec_name] args.extend(self.GetBrowserStartupArgs()) def QuoteIfNeeded(arg): # Escape 'key=valueA valueB' to 'key="valueA valueB"' # Already quoted values, or values without space are left untouched. # This is required so CommandLine.java can parse valueB correctly rather # than as a separate switch. params = arg.split('=') if len(params) != 2: return arg key, values = params if ' ' not in values: return arg if values[0] in '"\'' and values[-1] == values[0]: return arg return '%s="%s"' % (key, values) args = map(QuoteIfNeeded, args) self._adb.Adb().SetProtectedFileContents( self._backend_settings.cmdline_file, ' '.join(args)) cmdline = self._adb.Adb().GetProtectedFileContents( self._backend_settings.cmdline_file) if len(cmdline) != 1 or cmdline[0] != ' '.join(args): logging.critical('Failed to set Chrome command line. ' 'Fix this by flashing to a userdebug build.') sys.exit(1)
def __init__(self, android_platform_backend, browser_options, backend_settings, use_rndis_forwarder, output_profile_path, extensions_to_load, target_arch): assert isinstance(android_platform_backend, android_platform_backend_module.AndroidPlatformBackend) super(AndroidBrowserBackend, self).__init__( android_platform_backend, supports_tab_control=backend_settings.supports_tab_control, supports_extensions=False, browser_options=browser_options, output_profile_path=output_profile_path, extensions_to_load=extensions_to_load) if len(extensions_to_load) > 0: raise browser_backend.ExtensionsNotSupportedException( 'Android browser does not support extensions.') # Initialize fields so that an explosion during init doesn't break in Close. self._backend_settings = backend_settings self._saved_cmdline = '' self._target_arch = target_arch self._saved_sslflag = '' # TODO(tonyg): This is flaky because it doesn't reserve the port that it # allocates. Need to fix this. self._port = adb_commands.AllocateTestServerPort() # TODO(wuhu): Move to network controller backend. self._platform_backend.InstallTestCa() # Kill old browser. self._KillBrowser() if self._adb.device().old_interface.CanAccessProtectedFileContents(): if self.browser_options.profile_dir: self._platform_backend.PushProfile( self._backend_settings.package, self.browser_options.profile_dir) elif not self.browser_options.dont_override_profile: self._platform_backend.RemoveProfile( self._backend_settings.package, self._backend_settings.profile_ignore_list) self._forwarder_factory = android_forwarder.AndroidForwarderFactory( self._adb, use_rndis_forwarder) if self.browser_options.netsim or use_rndis_forwarder: assert use_rndis_forwarder, 'Netsim requires RNDIS forwarding.' self.wpr_port_pairs = forwarders.PortPairs( http=forwarders.PortPair(0, 80), https=forwarders.PortPair(0, 443), dns=forwarders.PortPair(0, 53)) # Set the debug app if needed. self._platform_backend.SetDebugApp(self._backend_settings.package)
def __init__(self, browser_options, backend_settings, use_rndis_forwarder, output_profile_path, extensions_to_load): super(AndroidBrowserBackend, self).__init__( is_content_shell=backend_settings.is_content_shell, supports_extensions=False, browser_options=browser_options, output_profile_path=output_profile_path, extensions_to_load=extensions_to_load) if len(extensions_to_load) > 0: raise browser_backend.ExtensionsNotSupportedException( 'Android browser does not support extensions.') # Initialize fields so that an explosion during init doesn't break in Close. self._adb = backend_settings.adb self._backend_settings = backend_settings self._saved_cmdline = '' # TODO(tonyg): This is flaky because it doesn't reserve the port that it # allocates. Need to fix this. self._port = adb_commands.AllocateTestServerPort() # Kill old browser. self._adb.CloseApplication(self._backend_settings.package) if self._adb.Adb().CanAccessProtectedFileContents(): if self.browser_options.profile_dir: self._backend_settings.PushProfile( self.browser_options.profile_dir) elif not self.browser_options.dont_override_profile: self._backend_settings.RemoveProfile() self._forwarder_factory = android_forwarder.AndroidForwarderFactory( self._adb, use_rndis_forwarder) if self.browser_options.netsim: assert use_rndis_forwarder, 'Netsim requires RNDIS forwarding.' self.wpr_port_pairs = forwarders.PortPairs( http=forwarders.PortPair(0, 80), https=forwarders.PortPair(0, 443), dns=forwarders.PortPair(0, 53)) # Set the debug app if needed. if self._adb.IsUserBuild(): logging.debug('User build device, setting debug app') self._adb.RunShellCommand('am set-debug-app --persistent %s' % self._backend_settings.package)
def __init__(self, options, executable, flash_path, is_content_shell, browser_directory, delete_profile_dir_after_run=True): super(DesktopBrowserBackend, self).__init__(is_content_shell=is_content_shell, supports_extensions=not is_content_shell, options=options) # Initialize fields so that an explosion during init doesn't break in Close. self._proc = None self._tmpdir = None self._tmp_output_file = None self._executable = executable if not self._executable: raise Exception('Cannot create browser, no executable found!') self._flash_path = flash_path if self._flash_path and not os.path.exists(self._flash_path): logging.warning( ('Could not find flash at %s. Running without flash.\n\n' 'To fix this see http://go/read-src-internal') % self._flash_path) self._flash_path = None if len(options.extensions_to_load) > 0 and is_content_shell: raise browser_backend.ExtensionsNotSupportedException( 'Content shell does not support extensions.') self._browser_directory = browser_directory self._port = util.GetAvailableLocalPort() self._profile_dir = None self._supports_net_benchmarking = True self._delete_profile_dir_after_run = delete_profile_dir_after_run self._SetupProfile()
def __init__(self, browser_options, executable, flash_path, is_content_shell, browser_directory, output_profile_path, extensions_to_load): super(DesktopBrowserBackend, self).__init__(is_content_shell=is_content_shell, supports_extensions=not is_content_shell, browser_options=browser_options, output_profile_path=output_profile_path, extensions_to_load=extensions_to_load) # Initialize fields so that an explosion during init doesn't break in Close. self._proc = None self._tmp_profile_dir = None self._tmp_output_file = None self._executable = executable if not self._executable: raise Exception('Cannot create browser, no executable found!') self._flash_path = flash_path if (browser_options.warn_if_no_flash and self._flash_path and not os.path.exists(self._flash_path)): logging.warning( ('Could not find flash at %s. Running without flash.\n\n' 'To fix this see http://go/read-src-internal') % self._flash_path) self._flash_path = None if len(extensions_to_load) > 0 and is_content_shell: raise browser_backend.ExtensionsNotSupportedException( 'Content shell does not support extensions.') self._browser_directory = browser_directory self._port = None self._profile_dir = None self._tmp_minidump_dir = tempfile.mkdtemp() self._crash_service = None self._SetupProfile()
def extensions(self): if not self.supports_extensions: raise browser_backend.ExtensionsNotSupportedException( 'Extensions not supported') return extension_dict.ExtensionDict( self._browser_backend.extension_backend)
def extensions(self): """Returns the extension dictionary if it exists.""" if not self.supports_extensions: raise browser_backend.ExtensionsNotSupportedException( 'Extensions not supported') return self._extensions