def LocalWprHost(wpr_archive_path,
                 record=False,
                 network_condition_name=None,
                 disable_script_injection=False,
                 out_log_path=None):
    """Launches web page replay host.

  Args:
    wpr_archive_path: host sided WPR archive's path.
    record: Enables or disables WPR archive recording.
    network_condition_name: Network condition name available in
        emulation.NETWORK_CONDITIONS.
    disable_script_injection: Disable JavaScript file injections that is
      fighting against resources name entropy.
    out_log_path: Path of the WPR host's log.

  Returns:
    WprAttribute
  """
    if wpr_archive_path == None:
        _VerifySilentWprHost(record, network_condition_name)
        yield []
        return

    with common_util.TemporaryDirectory() as temp_home_dir:
        # Generate a root certification authority certificate for WPR.
        private_ca_cert_path = os.path.join(temp_home_dir, 'wpr.pem')
        ca_cert_path = os.path.join(temp_home_dir, 'wpr-cert.pem')
        certutils.write_dummy_ca_cert(*certutils.generate_dummy_ca_cert(),
                                      cert_path=private_ca_cert_path)
        assert os.path.isfile(ca_cert_path)
        certutils.install_cert_in_nssdb(temp_home_dir, ca_cert_path)

        with _WprHost(wpr_archive_path,
                      record=record,
                      network_condition_name=network_condition_name,
                      disable_script_injection=disable_script_injection,
                      wpr_ca_cert_path=private_ca_cert_path,
                      out_log_path=out_log_path) as (http_port, https_port):
            chrome_args = _FormatWPRRelatedChromeArgumentFor(http_port,
                                                             https_port,
                                                             escape=False)
            yield WprAttribute(chrome_args=chrome_args,
                               chrome_env_override={'HOME': temp_home_dir})
Beispiel #2
0
def LocalWprHost(wpr_archive_path, record=False,
                 network_condition_name=None,
                 disable_script_injection=False,
                 out_log_path=None):
  """Launches web page replay host.

  Args:
    wpr_archive_path: host sided WPR archive's path.
    record: Enables or disables WPR archive recording.
    network_condition_name: Network condition name available in
        emulation.NETWORK_CONDITIONS.
    disable_script_injection: Disable JavaScript file injections that is
      fighting against resources name entropy.
    out_log_path: Path of the WPR host's log.

  Returns:
    WprAttribute
  """
  if wpr_archive_path == None:
    _VerifySilentWprHost(record, network_condition_name)
    yield []
    return

  with common_util.TemporaryDirectory() as temp_home_dir:
    # Generate a root certification authority certificate for WPR.
    private_ca_cert_path = os.path.join(temp_home_dir, 'wpr.pem')
    ca_cert_path = os.path.join(temp_home_dir, 'wpr-cert.pem')
    certutils.write_dummy_ca_cert(*certutils.generate_dummy_ca_cert(),
                                  cert_path=private_ca_cert_path)
    assert os.path.isfile(ca_cert_path)
    certutils.install_cert_in_nssdb(temp_home_dir, ca_cert_path)

    with _WprHost(
        wpr_archive_path,
        record=record,
        network_condition_name=network_condition_name,
        disable_script_injection=disable_script_injection,
        wpr_ca_cert_path=private_ca_cert_path,
        out_log_path=out_log_path) as (http_port, https_port):
      chrome_args = _FormatWPRRelatedChromeArgumentFor(http_port, https_port,
                                                       escape=False)
      yield WprAttribute(chrome_args=chrome_args,
                         chrome_env_override={'HOME': temp_home_dir})