示例#1
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

        self.webpagereplay_local_http_port = util.GetAvailableLocalPort()
        self.webpagereplay_local_https_port = util.GetAvailableLocalPort()
        self.webpagereplay_remote_http_port = self.webpagereplay_local_http_port
        self.webpagereplay_remote_https_port = self.webpagereplay_local_https_port

        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))
示例#2
0
    def __init__(self, is_content_shell, supports_extensions, options):
        self.browser_type = options.browser_type
        self.is_content_shell = is_content_shell
        self._supports_extensions = supports_extensions
        self.options = options
        self._browser = None
        self._port = None

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

        self.webpagereplay_local_http_port = util.GetAvailableLocalPort()
        self.webpagereplay_local_https_port = util.GetAvailableLocalPort()
        self.webpagereplay_remote_http_port = self.webpagereplay_local_http_port
        self.webpagereplay_remote_https_port = self.webpagereplay_local_https_port

        if 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._tab_list_backend = tab_list_backend.TabListBackend(self)
        self._extension_dict_backend = None
        if supports_extensions:
            self._extension_dict_backend = (
                extension_dict_backend.ExtensionDictBackend(self))
示例#3
0
  def __init__(self, options, executable, is_content_shell, use_login):
    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._use_login = use_login

    self._executable = executable
    if not self._executable:
      raise Exception('Cannot create browser, no executable found!')

    if len(options.extensions_to_load) > 0 and is_content_shell:
      raise browser_backend.ExtensionsNotSupportedException(
          'Content shell does not support extensions.')

    self._port = util.GetAvailableLocalPort()
    self._supports_net_benchmarking = True
    self._LaunchBrowser(options)

    # For old chrome versions, might have to relaunch to have the
    # correct benchmarking switch.
    if self._chrome_branch_number < 1418:
      self.Close()
      self._supports_net_benchmarking = False
      self._LaunchBrowser(options)

    if self._use_login:
      cros_util.NavigateLogin(self)
示例#4
0
    def __init__(self, browser_backend, paths):
        self._server = None
        self._devnull = None
        self._paths = paths
        self._forwarder = None
        self._host_port = util.GetAvailableLocalPort()

        for path in self._paths:
            assert os.path.exists(path), path

        self._devnull = open(os.devnull, 'w')
        cmd = [
            sys.executable, '-m', 'memory_cache_http_server',
            str(self._host_port)
        ]
        cmd.extend(self._paths)
        env = os.environ.copy()
        env['PYTHONPATH'] = os.path.abspath(os.path.dirname(__file__))
        self._server = subprocess.Popen(cmd,
                                        cwd=os.path.commonprefix(self._paths),
                                        env=env,
                                        stdout=self._devnull,
                                        stderr=self._devnull)

        self._forwarder = browser_backend.CreateForwarder(
            util.PortPair(self._host_port,
                          browser_backend.GetRemotePort(self._host_port)))

        def IsServerUp():
            return not socket.socket().connect_ex(
                ('localhost', self._host_port))

        util.WaitFor(IsServerUp, 10)
    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:
            # Find a free local port.
            self._port = util.GetAvailableLocalPort()

            # Forward the remote debugging port.
            logging.info('Forwarding remote debugging port')
            self._forwarder = SSHForwarder(
                self._cri, 'L',
                util.PortPair(self._port, self._remote_debugging_port))

        # Wait for the browser to come up.
        logging.info('Waiting for browser to be ready')
        try:
            self._WaitForBrowserToComeUp()
            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.')

        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,
                 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()
示例#7
0
 def GetRemotePort(self, _):
     return util.GetAvailableLocalPort()
示例#8
0
  def __init__(self, browser_type, options, cri, is_guest):
    super(CrOSBrowserBackend, self).__init__(is_content_shell=False,
        supports_extensions=not is_guest, options=options)
    # Initialize fields so that an explosion during init doesn't break in Close.
    self._browser_type = browser_type
    self._options = options
    self._cri = cri
    self._is_guest = is_guest

    self._remote_debugging_port = self._cri.GetRemotePort()
    self._port = self._remote_debugging_port

    self._login_ext_dir = os.path.join(os.path.dirname(__file__),
                                       'chromeos_login_ext')

    # Push a dummy login extension to the device.
    # This extension automatically logs in as [email protected]
    # Note that we also perform this copy locally to ensure that
    # the owner of the extensions is set to chronos.
    logging.info('Copying dummy login extension to the device')
    cri.PushFile(self._login_ext_dir, '/tmp/')
    self._login_ext_dir = '/tmp/chromeos_login_ext'
    cri.RunCmdOnDevice(['chown', '-R', 'chronos:chronos',
                        self._login_ext_dir])

    # 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 options.extensions_to_load:
      output = cri.RunCmdOnDevice(['mktemp', '-d', '/tmp/extension_XXXXX'])
      extension_dir = output[0].rstrip()
      cri.PushFile(e.path, extension_dir)
      cri.RunCmdOnDevice(['chown', '-R', 'chronos:chronos', 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(lambda: self.IsBrowserRunning(), 20)  # pylint: disable=W0108

    # Delete [email protected]'s cryptohome vault (user data directory).
    if not options.dont_override_profile:
      logging.info('Deleting user\'s cryptohome vault (the user data dir)')
      self._cri.RunCmdOnDevice(
          ['cryptohome', '--action=remove', '--force', '[email protected]'])
    if options.profile_dir:
      profile_dir = '/home/chronos/Default'
      cri.RunCmdOnDevice(['rm', '-rf', profile_dir])
      cri.PushFile(options.profile_dir + '/Default', profile_dir)
      cri.RunCmdOnDevice(['chown', '-R', 'chronos:chronos', profile_dir])

    # 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)]
    cri.RunCmdOnDevice(args)

    if not cri.local:
      # Find a free local port.
      self._port = util.GetAvailableLocalPort()

      # Forward the remote debugging port.
      logging.info('Forwarding remote debugging port')
      self._forwarder = SSHForwarder(
        cri, 'L',
        util.PortPair(self._port, self._remote_debugging_port))

    # Wait for the browser to come up.
    logging.info('Waiting for browser to be ready')
    try:
      self._WaitForBrowserToComeUp()
      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.')

    if self._is_guest:
      pid = self.pid
      cros_util.NavigateGuestLogin(self, cri)
      # 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:
      cros_util.NavigateLogin(self, cri)

    logging.info('Browser is up!')
示例#9
0
  def __init__(self, browser_type, options, cri, is_guest):
    super(CrOSBrowserBackend, self).__init__(is_content_shell=False,
        supports_extensions=True, options=options)
    # Initialize fields so that an explosion during init doesn't break in Close.
    self._browser_type = browser_type
    self._options = options
    self._cri = cri
    self._is_guest = is_guest

    self._remote_debugging_port = self._cri.GetRemotePort()
    self._port = self._remote_debugging_port

    self._login_ext_dir = os.path.join(os.path.dirname(__file__),
                                       'chromeos_login_ext')
    if not cri.local:
      # Push a dummy login extension to the device.
      # This extension automatically logs in as [email protected]
      logging.info('Copying dummy login extension to the device')
      cri.PushFile(self._login_ext_dir, '/tmp/')
      self._login_ext_dir = '/tmp/chromeos_login_ext'
      cri.RunCmdOnDevice(['chown', '-R', 'chronos:chronos',
                          self._login_ext_dir])

      # Copy local extensions to temp directories on the device.
      for e in options.extensions_to_load:
        output = cri.RunCmdOnDevice(['mktemp', '-d', '/tmp/extension_XXXXX'])
        extension_dir = output[0].rstrip()
        cri.PushFile(e.path, extension_dir)
        cri.RunCmdOnDevice(['chown', '-R', 'chronos:chronos', 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(lambda: self.IsBrowserRunning(), 20)  # pylint: disable=W0108

    # Delete [email protected]'s cryptohome vault (user data directory).
    if not options.dont_override_profile:
      logging.info('Deleting user\'s cryptohome vault (the user data dir)')
      self._cri.RunCmdOnDevice(
          ['cryptohome', '--action=remove', '--force', '[email protected]'])
    if options.profile_dir:
      profile_dir = '/home/chronos/Default'
      cri.GetCmdOutput(['rm', '-rf', profile_dir])
      cri.PushFile(options.profile_dir + '/Default', profile_dir)
      cri.GetCmdOutput(['chown', '-R', 'chronos:chronos', profile_dir])

    # 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(self.GetBrowserStartupArgs())]
    cri.RunCmdOnDevice(args)

    if not cri.local:
      # Find a free local port.
      self._port = util.GetAvailableLocalPort()

      # Forward the remote debugging port.
      logging.info('Forwarding remote debugging port')
      self._forwarder = SSHForwarder(
        cri, 'L',
        util.PortPair(self._port, self._remote_debugging_port))

    # Wait for the browser to come up.
    logging.info('Waiting for browser to be ready')
    try:
      self._WaitForBrowserToComeUp()
      self._PostBrowserStartupInitialization()
    except:
      import traceback
      traceback.print_exc()
      self.Close()
      raise

    if self._is_guest:
      cros_util.NavigateGuestLogin(self, cri)
      # Guest browsing shuts down the current browser and launches an incognito
      # browser, which we need to wait for.
      self._WaitForBrowserToComeUp()
    else:
      cros_util.NavigateLogin(self)

    logging.info('Browser is up!')