Ejemplo n.º 1
0
def _ForwarderPortPairs(started_ports, wpr_port_pairs):
    """Return PortPairs with started local ports and requested remote ports.

  The local host is where Telemetry is run. The remote is host where
  the target application is run. The local and remote hosts may be
  the same (e.g., testing a desktop browser) or different (e.g., testing
  an android browser).

  The remote ports may be zero. In that case, the forwarder determines
  the remote ports.

  Args:
    started_ports: a tuple of of integer ports from which to forward:
        (HTTP_PORT, HTTPS_PORT, DNS_PORT)  # DNS_PORT may be None
    wpr_port_pairs: a forwarders.PortPairs instance where the remote ports,
        if set, are used.
  Returns:
    a forwarders.PortPairs instance used to create the forwarder.
  """
    local_http_port, local_https_port, local_dns_port = started_ports
    return forwarders.PortPairs(
        forwarders.PortPair(local_http_port, wpr_port_pairs.http.remote_port),
        forwarders.PortPair(local_https_port,
                            wpr_port_pairs.https.remote_port),
        (forwarders.PortPair(local_dns_port, wpr_port_pairs.dns.remote_port)
         if wpr_port_pairs.dns is not None else None))
  def __init__(self, supports_tab_control, supports_extensions, browser_options,
               output_profile_path, extensions_to_load):
    super(ChromeBrowserBackend, self).__init__(
        supports_extensions=supports_extensions,
        browser_options=browser_options,
        tab_list_backend=tab_list_backend.TabListBackend)
    self._port = None

    self._supports_tab_control = supports_tab_control
    self._tracing_backend = None
    self._system_info_backend = None

    self._output_profile_path = output_profile_path
    self._extensions_to_load = extensions_to_load

    if browser_options.netsim:
      self.wpr_port_pairs = forwarders.PortPairs(
          http=forwarders.PortPair(80, 80),
          https=forwarders.PortPair(443, 443),
          dns=forwarders.PortPair(53, 53))
    else:
      self.wpr_port_pairs = forwarders.PortPairs(
          http=forwarders.PortPair(0, 0),
          https=forwarders.PortPair(0, 0),
          dns=None)

    if (self.browser_options.dont_override_profile and
        not options_for_unittests.AreSet()):
      sys.stderr.write('Warning: Not overriding profile. This can cause '
                       'unexpected effects due to profile-specific settings, '
                       'such as about:flags settings, cookies, and '
                       'extensions.\n')
 def testPortMismatchRaisesPortsMismatchError(self):
     # The do_nothing_forward cannot forward from one port to another.
     port_pairs = forwarders.PortPairs(http=forwarders.PortPair(80, 80),
                                       https=forwarders.PortPair(8443, 443),
                                       dns=None)
     with self.assertRaises(do_nothing_forwarder.PortsMismatchError):
         TestDoNothingForwarder(port_pairs)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def __init__(self, browser_type, browser_options, cri, is_guest,
                 extensions_to_load):
        super(CrOSBrowserBackend,
              self).__init__(is_content_shell=False,
                             supports_extensions=not is_guest,
                             browser_options=browser_options,
                             output_profile_path=None,
                             extensions_to_load=extensions_to_load)

        from telemetry.core.backends.chrome import chrome_browser_options
        assert isinstance(browser_options,
                          chrome_browser_options.CrosBrowserOptions)

        # Initialize fields so that an explosion during init doesn't break in Close.
        self._browser_type = browser_type
        self._cri = cri
        self._is_guest = is_guest
        self._forwarder = None

        self.wpr_port_pairs = forwarders.PortPairs(
            http=forwarders.PortPair(self.wpr_port_pairs.http.local_port,
                                     self._cri.GetRemotePort()),
            https=forwarders.PortPair(self.wpr_port_pairs.https.local_port,
                                      self._cri.GetRemotePort()),
            dns=None)
        self._remote_debugging_port = self._cri.GetRemotePort()
        self._port = self._remote_debugging_port

        self._SetBranchNumber(self._GetChromeVersion())

        # Copy extensions to temp directories on the device.
        # Note that we also perform this copy locally to ensure that
        # the owner of the extensions is set to chronos.
        for e in extensions_to_load:
            output = cri.RunCmdOnDevice(
                ['mktemp', '-d', '/tmp/extension_XXXXX'])
            extension_dir = output[0].rstrip()
            cri.PushFile(e.path, extension_dir)
            cri.Chown(extension_dir)
            e.local_path = os.path.join(extension_dir,
                                        os.path.basename(e.path))

        # Ensure the UI is running and logged out.
        self._RestartUI()
        util.WaitFor(self.IsBrowserRunning, 20)

        # Delete test user's cryptohome vault (user data directory).
        if not self.browser_options.dont_override_profile:
            self._cri.RunCmdOnDevice([
                'cryptohome', '--action=remove', '--force',
                '--user=%s' % self.browser_options.username
            ])
        if self.browser_options.profile_dir:
            cri.RmRF(self.profile_directory)
            cri.PushFile(self.browser_options.profile_dir + '/Default',
                         self.profile_directory)
            cri.Chown(self.profile_directory)
 def testChecksOnlyHttpHttps(self):
     port_pairs = forwarders.PortPairs(http=forwarders.PortPair(80, 80),
                                       https=forwarders.PortPair(443, 443),
                                       dns=forwarders.PortPair(53, 53))
     f = TestDoNothingForwarder(port_pairs)
     expected_connected_addresses = [
         ('127.0.0.1', 80),
         ('127.0.0.1', 443),
         # Port 53 is skipped because it is UDP and does not support connections.
     ]
     self.assertEqual(expected_connected_addresses, f.connected_addresses)
 def testNoDnsStillChecksHttpHttps(self):
     port_pairs = forwarders.PortPairs(http=forwarders.PortPair(5566, 5566),
                                       https=forwarders.PortPair(
                                           7788, 7788),
                                       dns=None)
     f = TestDoNothingForwarder(port_pairs)
     expected_connected_addresses = [
         ('127.0.0.1', 5566),
         ('127.0.0.1', 7788),
     ]
     self.assertEqual(expected_connected_addresses, f.connected_addresses)
  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)
Ejemplo n.º 9
0
    def __init__(self, driver_creator, supports_extensions, browser_options):
        super(WebDriverBrowserBackend,
              self).__init__(supports_extensions=supports_extensions,
                             browser_options=browser_options,
                             tab_list_backend=webdriver_tab_list_backend.
                             WebDriverTabListBackend)

        self._driver_creator = driver_creator
        self._driver = None
        self.wpr_port_pairs = forwarders.PortPairs(
            http=forwarders.PortPair(80, 80),
            https=forwarders.PortPair(443, 443),
            dns=forwarders.PortPair(53, 53))
Ejemplo n.º 10
0
 def testZeroIsOkayForRemotePorts(self):
     started_ports = (8080, 8443, None)
     wpr_port_pairs = forwarders.PortPairs(http=forwarders.PortPair(0, 0),
                                           https=forwarders.PortPair(0, 0),
                                           dns=None)
     expected_port_pairs = forwarders.PortPairs(
         http=forwarders.PortPair(8080, 0),
         https=forwarders.PortPair(8443, 0),
         dns=None)
     self.assertEqual(
         expected_port_pairs,
         network_controller_backend._ForwarderPortPairs(
             started_ports, wpr_port_pairs))
Ejemplo n.º 11
0
    def __init__(self, cros_platform_backend, browser_options, cri, is_guest,
                 extensions_to_load):
        super(CrOSBrowserBackend,
              self).__init__(cros_platform_backend,
                             supports_tab_control=True,
                             supports_extensions=not is_guest,
                             browser_options=browser_options,
                             output_profile_path=None,
                             extensions_to_load=extensions_to_load)
        assert browser_options.IsCrosBrowserOptions()
        # Initialize fields so that an explosion during init doesn't break in Close.
        self._cri = cri
        self._is_guest = is_guest
        self._forwarder = None
        self.wpr_port_pairs = forwarders.PortPairs(
            http=forwarders.PortPair(
                self.wpr_port_pairs.http.local_port,
                self.GetRemotePort(self.wpr_port_pairs.http.local_port)),
            https=forwarders.PortPair(
                self.wpr_port_pairs.https.local_port,
                self.GetRemotePort(self.wpr_port_pairs.http.local_port)),
            dns=None)
        self._remote_debugging_port = self._cri.GetRemotePort()
        self._port = self._remote_debugging_port

        # Copy extensions to temp directories on the device.
        # Note that we also perform this copy locally to ensure that
        # the owner of the extensions is set to chronos.
        for e in extensions_to_load:
            extension_dir = cri.RunCmdOnDevice(
                ['mktemp', '-d', '/tmp/extension_XXXXX'])[0].rstrip()
            cri.PushFile(e.path, extension_dir)
            cri.Chown(extension_dir)
            e.local_path = os.path.join(extension_dir,
                                        os.path.basename(e.path))

        self._cri.RestartUI(self.browser_options.clear_enterprise_policy)
        util.WaitFor(self.IsBrowserRunning, 20)

        # Delete test user's cryptohome vault (user data directory).
        if not self.browser_options.dont_override_profile:
            self._cri.RunCmdOnDevice([
                'cryptohome', '--action=remove', '--force',
                '--user=%s' % self._username
            ])
        if self.browser_options.profile_dir:
            cri.RmRF(self.profile_directory)
            cri.PushFile(self.browser_options.profile_dir + '/Default',
                         self.profile_directory)
            cri.Chown(self.profile_directory)
Ejemplo n.º 12
0
  def Start(self, local_server_controller):
    assert self._subprocess == None
    self._local_server_controller = local_server_controller

    self.host_ip = local_server_controller.host_ip

    server_args = self.GetBackendStartupArgs()
    server_args_as_json = json.dumps(server_args)
    server_module_name = self._server_backend_class.__module__

    self._devnull = open(os.devnull, 'w')
    cmd = [sys.executable, '-m', __name__]
    cmd.extend(["run_backend"])
    cmd.extend([server_module_name, self._server_backend_class.__name__,
                server_args_as_json])

    env = os.environ.copy()
    env['PYTHONPATH'] = os.pathsep.join(sys.path)

    cwd = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', '..'))

    self._subprocess = subprocess.Popen(
        cmd, cwd=cwd, env=env, stdout=subprocess.PIPE)

    named_ports = self._GetNamedPortsFromBackend()
    named_port_pair_map = {'http': None, 'https': None, 'dns': None}
    for name, port in named_ports:
      assert name in named_port_pair_map, '%s forwarding is unsupported' % name
      named_port_pair_map[name] = (
          forwarders.PortPair(port,
                              local_server_controller.GetRemotePort(port)))
    self.forwarder = local_server_controller.CreateForwarder(
        forwarders.PortPairs(**named_port_pair_map))
Ejemplo n.º 13
0
    def testGetRemotePortAndIsHTTPServerRunningOnPort(self):
        with self._GetCRI() as cri:
            # Create local server.
            sock = socket.socket()
            sock.bind(('', 0))
            port = sock.getsockname()[1]
            sock.listen(0)

            # Get remote port and ensure that it was unused.
            remote_port = cri.GetRemotePort()
            self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port))

            # Forward local server's port to remote device's remote_port.
            forwarder = cros_forwarder.CrOsForwarderFactory(cri).Create(
                forwarders.PortPairs(http=forwarders.PortPair(
                    port, remote_port),
                                     https=None,
                                     dns=None))

            # At this point, remote device should be able to connect to local server.
            self.assertTrue(cri.IsHTTPServerRunningOnPort(remote_port))

            # Next remote port shouldn't be the same as remote_port, since remote_port
            # is now in use.
            self.assertTrue(cri.GetRemotePort() != remote_port)

            # Close forwarder and local server ports.
            forwarder.Close()
            sock.close()

            # Device should no longer be able to connect to remote_port since it is no
            # longer in use.
            self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port))
Ejemplo n.º 14
0
    def Start(self):
        # Escape all commas in the startup arguments we pass to Chrome
        # because dbus-send delimits array elements by commas
        startup_args = [
            a.replace(',', '\\,') for a in self.GetBrowserStartupArgs()
        ]

        # Restart Chrome with the login extension and remote debugging.
        logging.info('Restarting Chrome with flags and login')
        args = [
            'dbus-send', '--system', '--type=method_call',
            '--dest=org.chromium.SessionManager',
            '/org/chromium/SessionManager',
            'org.chromium.SessionManagerInterface.EnableChromeTesting',
            'boolean:true',
            'array:string:"%s"' % ','.join(startup_args)
        ]
        self._cri.RunCmdOnDevice(args)

        if not self._cri.local:
            self._port = util.GetUnreservedAvailableLocalPort()
            self._forwarder = self.forwarder_factory.Create(
                forwarders.PortPairs(http=forwarders.PortPair(
                    self._port, self._remote_debugging_port),
                                     https=None,
                                     dns=None),
                forwarding_flag='L')

        try:
            self._WaitForBrowserToComeUp(wait_for_extensions=False)
            self._PostBrowserStartupInitialization()
        except:
            import traceback
            traceback.print_exc()
            self.Close()
            raise

        # chrome_branch_number is set in _PostBrowserStartupInitialization.
        # Without --skip-hwid-check (introduced in crrev.com/203397), devices/VMs
        # will be stuck on the bad hwid screen.
        if self.chrome_branch_number <= 1500 and not self.hwid:
            raise exceptions.LoginException(
                'Hardware id not set on device/VM. --skip-hwid-check not supported '
                'with chrome branches 1500 or earlier.')

        util.WaitFor(lambda: self.oobe_exists, 10)

        if self.browser_options.auto_login:
            if self._is_guest:
                pid = self.pid
                self._NavigateGuestLogin()
                # Guest browsing shuts down the current browser and launches an
                # incognito browser in a separate process, which we need to wait for.
                util.WaitFor(lambda: pid != self.pid, 10)
                self._WaitForBrowserToComeUp()
            else:
                self._NavigateLogin()

        logging.info('Browser is up!')
    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)
Ejemplo n.º 16
0
  def __init__(self, browser_backend, path, is_record_mode, is_append_mode,
               make_javascript_deterministic):
    self._browser_backend = browser_backend
    self._forwarder = None
    self._web_page_replay = None
    self._is_record_mode = is_record_mode
    self._is_append_mode = is_append_mode

    wpr_args = browser_backend.browser_options.extra_wpr_args
    if self._is_record_mode:
      if self._is_append_mode:
        wpr_args.append('--append')
      else:
        wpr_args.append('--record')
    if not make_javascript_deterministic:
      wpr_args.append('--inject_scripts=')
    browser_backend.AddReplayServerOptions(wpr_args)
    self._web_page_replay = webpagereplay.ReplayServer(
        path, self._browser_backend.forwarder_factory.host_ip,
        browser_backend.wpr_port_pairs.dns.local_port if
        browser_backend.wpr_port_pairs.dns else 0,
        browser_backend.wpr_port_pairs.http.local_port,
        browser_backend.wpr_port_pairs.https.local_port,
        wpr_args)
    # Remove --no-dns_forwarding if it wasn't explicitly requested by backend.
    if '--no-dns_forwarding' not in wpr_args:
      self._web_page_replay.replay_options.remove('--no-dns_forwarding')
    self._web_page_replay.StartServer()

    browser_backend.wpr_port_pairs = forwarders.PortPairs(
        http=forwarders.PortPair(
            self._web_page_replay.http_port,
            browser_backend.wpr_port_pairs.http.remote_port or
            self._web_page_replay.http_port),
        https=forwarders.PortPair(
            self._web_page_replay.https_port,
            browser_backend.wpr_port_pairs.https.remote_port or
            self._web_page_replay.https_port),
        dns=forwarders.PortPair(
            self._web_page_replay.dns_port,
            browser_backend.wpr_port_pairs.dns.remote_port or
            self._web_page_replay.dns_port)
            if browser_backend.wpr_port_pairs.dns else None)

    self._forwarder = browser_backend.forwarder_factory.Create(
        browser_backend.wpr_port_pairs)
    def Start(self):
        # Escape all commas in the startup arguments we pass to Chrome
        # because dbus-send delimits array elements by commas
        startup_args = [
            a.replace(',', '\\,') for a in self.GetBrowserStartupArgs()
        ]

        # Restart Chrome with the login extension and remote debugging.
        logging.info('Restarting Chrome with flags and login')
        args = [
            'dbus-send', '--system', '--type=method_call',
            '--dest=org.chromium.SessionManager',
            '/org/chromium/SessionManager',
            'org.chromium.SessionManagerInterface.EnableChromeTesting',
            'boolean:true',
            'array:string:"%s"' % ','.join(startup_args)
        ]
        self._cri.RunCmdOnDevice(args)

        if not self._cri.local:
            self._port = util.GetUnreservedAvailableLocalPort()
            self._forwarder = self.forwarder_factory.Create(
                forwarders.PortPairs(http=forwarders.PortPair(
                    self._port, self._remote_debugging_port),
                                     https=None,
                                     dns=None),
                forwarding_flag='L')

        try:
            self._WaitForBrowserToComeUp(wait_for_extensions=False)
            self._PostBrowserStartupInitialization()
        except:
            import traceback
            traceback.print_exc()
            self.Close()
            raise

        util.WaitFor(lambda: self.oobe_exists, 10)

        if self.browser_options.auto_login:
            if self._is_guest:
                pid = self.pid
                self.oobe.NavigateGuestLogin()
                # Guest browsing shuts down the current browser and launches an
                # incognito browser in a separate process, which we need to wait for.
                util.WaitFor(lambda: pid != self.pid, 10)
            elif self.browser_options.gaia_login:
                try:
                    self.oobe.NavigateGaiaLogin(self._username, self._password)
                except util.TimeoutException:
                    self._cri.TakeScreenShot('gaia-login')
                    raise
            else:
                self.oobe.NavigateFakeLogin(self._username, self._password)
            self._WaitForLogin()

        logging.info('Browser is up!')
Ejemplo n.º 18
0
 def __init__(self, adb, port_pairs):
   super(AndroidForwarder, self).__init__(port_pairs)
   self._device = adb.device()
   forwarder.Forwarder.Map([(p.remote_port, p.local_port)
                            for p in port_pairs if p], self._device)
   self._port_pairs = forwarders.PortPairs(*[
       forwarders.PortPair(
           p.local_port,
           forwarder.Forwarder.DevicePortForHostPort(p.local_port))
       if p else None for p in port_pairs])
Ejemplo n.º 19
0
class ForwardingArgsTest(unittest.TestCase):
    port_pairs = forwarders.PortPairs(http=forwarders.PortPair(111, 222),
                                      https=forwarders.PortPair(333, 444),
                                      dns=None)

    def testForwardingArgsReverse(self):
        forwarding_args = cros_forwarder.CrOsSshForwarder._ForwardingArgs(
            use_remote_port_forwarding=True,
            host_ip='5.5.5.5',
            port_pairs=self.port_pairs)
        self.assertEqual(['-R222:5.5.5.5:111', '-R444:5.5.5.5:333'],
                         forwarding_args)

    def testForwardingArgs(self):
        forwarding_args = cros_forwarder.CrOsSshForwarder._ForwardingArgs(
            use_remote_port_forwarding=False,
            host_ip='2.2.2.2',
            port_pairs=self.port_pairs)
        self.assertEqual(['-L111:2.2.2.2:222', '-L333:2.2.2.2:444'],
                         forwarding_args)
Ejemplo n.º 20
0
    def __init__(self, is_content_shell, supports_extensions, browser_options,
                 output_profile_path, extensions_to_load):
        super(ChromeBrowserBackend,
              self).__init__(is_content_shell=is_content_shell,
                             supports_extensions=supports_extensions,
                             browser_options=browser_options,
                             tab_list_backend=tab_list_backend.TabListBackend)
        self._port = None

        self._inspector_protocol_version = 0
        self._chrome_branch_number = None
        self._tracing_backend = None
        self._system_info_backend = None

        self._output_profile_path = output_profile_path
        self._extensions_to_load = extensions_to_load

        if browser_options.netsim:
            self.wpr_port_pairs = forwarders.PortPairs(
                http=forwarders.PortPair(80, 80),
                https=forwarders.PortPair(443, 443),
                dns=forwarders.PortPair(53, 53))
        else:
            self.wpr_port_pairs = forwarders.PortPairs(
                http=forwarders.PortPair(0, 0),
                https=forwarders.PortPair(0, 0),
                dns=None)

        if (self.browser_options.dont_override_profile
                and not options_for_unittests.AreSet()):
            sys.stderr.write(
                'Warning: Not overriding profile. This can cause '
                'unexpected effects due to profile-specific settings, '
                'such as about:flags settings, cookies, and '
                'extensions.\n')
        self._misc_web_contents_backend = (
            misc_web_contents_backend.MiscWebContentsBackend(self))
        self._extension_dict_backend = None
        if supports_extensions:
            self._extension_dict_backend = (
                extension_dict_backend.ExtensionDictBackend(self))
Ejemplo n.º 21
0
def main():
    # Install APK
    adb = GetAdb()
    adb.device().EnableRoot()
    adb.device().Install(APP_APK)
    # Start USB reverse tethering.
    # Port map is ignored for tethering; must create one to placate assertions.
    named_port_pair_map = {
        'http': (forwarders.PortPair(0, 0)),
        'https': None,
        'dns': None
    }
    port_pairs = forwarders.PortPairs(**named_port_pair_map)
    forwarder = GetForwarderFactory(adb).Create(port_pairs)
    # Start HTTP server.
    http_server_doc_root = GenerateHttpTestResources()
    config_file = tempfile.NamedTemporaryFile()
    http_server = lighttpd_server.LighttpdServer(
        http_server_doc_root,
        port=HTTP_PORT,
        base_config_path=config_file.name)
    GenerateLighttpdConfig(config_file, http_server_doc_root, http_server)
    assert http_server.StartupHttpServer()
    config_file.close()
    # Start QUIC server.
    quic_server_doc_root = GenerateQuicTestResources(adb)
    quic_server = QuicServer(quic_server_doc_root)
    quic_server.StartupQuicServer(adb)
    # Launch Telemetry's benchmark_runner on CronetPerfTestBenchmark.
    # By specifying this file's directory as the benchmark directory, it will
    # allow benchmark_runner to in turn open this file up and find the
    # CronetPerfTestBenchmark class to run the benchmark.
    top_level_dir = os.path.dirname(os.path.realpath(__file__))
    runner_config = benchmark_runner.ProjectConfig(
        top_level_dir=top_level_dir, benchmark_dirs=[top_level_dir])
    sys.argv.insert(1, 'run')
    sys.argv.insert(2, 'run.CronetPerfTestBenchmark')
    sys.argv.insert(3, '--android-rndis')
    benchmark_runner.main(runner_config)
    # Shutdown.
    quic_server.ShutdownQuicServer()
    shutil.rmtree(quic_server_doc_root)
    http_server.ShutdownHttpServer()
    shutil.rmtree(http_server_doc_root)
Ejemplo n.º 22
0
 def testCombineStartedAndRemotePorts(self):
     started_ports = (8888, 4343, 5353)
     wpr_port_pairs = forwarders.PortPairs(http=forwarders.PortPair(0, 80),
                                           https=forwarders.PortPair(
                                               0, 443),
                                           dns=forwarders.PortPair(0, 53))
     expected_port_pairs = forwarders.PortPairs(
         http=forwarders.PortPair(8888, 80),
         https=forwarders.PortPair(4343, 443),
         dns=forwarders.PortPair(5353, 53))
     self.assertEqual(
         expected_port_pairs,
         network_controller_backend._ForwarderPortPairs(
             started_ports, wpr_port_pairs))
 def testConnectionTimeoutRaisesConnectionError(self):
     port_pairs = forwarders.PortPairs(http=forwarders.PortPair(80, 80),
                                       https=forwarders.PortPair(8443, 443),
                                       dns=None)
     with self.assertRaises(do_nothing_forwarder.ConnectionError):
         TestErrorDoNothingForwarder(port_pairs)
 def __init__(self, http_ports, https_ports, dns_ports):
   self.wpr_port_pairs = forwarders.PortPairs(
     http=forwarders.PortPair(*http_ports),
     https=forwarders.PortPair(*https_ports),
     dns=forwarders.PortPair(*dns_ports) if dns_ports else None)
Ejemplo n.º 25
0
 def __init__(self, http_ports, https_ports, dns_ports):
     self.wpr_port_pairs = forwarders.PortPairs(
         http=forwarders.PortPair(*http_ports),
         https=forwarders.PortPair(*https_ports),
         dns=forwarders.PortPair(*dns_ports) if dns_ports else None)
     self.forwarder_factory = FakeForwarderFactory()