<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing connection reuse</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/entry-invariants.js"></script>
<script src="resources/connection-reuse-test.js"></script>
<script>
  const {HTTPS_ORIGIN} = get_host_info();

  // Fetches the given subresource a couple times with the same connection.
  const http_path = "resources/fake_responses.py";
  connection_reuse_test(http_path,
    {
      'on_200': invariants.assert_tao_pass_no_redirect_http,
      'on_304': invariants.assert_tao_pass_304_not_modified_http,
    }, "Reuse HTTP connection");

  // Like above, but the subresource is fetched over HTTPS while this page is
  // fetched over HTTP.
  const https_url = `${HTTPS_ORIGIN}/resource-timing/${http_path}`;
  connection_reuse_test(https_url,
    {
      'on_200': invariants.assert_tao_pass_no_redirect_https,
      'on_304': invariants.assert_tao_pass_304_not_modified_https,
    }, "Reuse HTTPS connection from HTTP page");

  // Like the above mixed-content test but the final resource is behind an HTTP
  // redirect response.
  const redirect_path = (() => {
    // The resource behind the redirect is the same fake_responses.py handler
    // on the HTTPS origin. Pass it through encodeURIComponent so that it can
    // be passed through a query-parameter.
    const redirect_url = encodeURIComponent(https_url)
    // The request is made to the HTTPS origin with a query parameter that will
    // cause a 302 response.
    return `${https_url}?redirect=${redirect_url}`;
  })();
  connection_reuse_test(redirect_path,
    {
      'on_200': invariants.assert_tao_enabled_cross_origin_redirected_resource,
      'on_304': invariants.assert_tao_enabled_cross_origin_redirected_resource,
    }, "Reuse HTTPS connection with redirects from an HTTP page");
</script>
</head>
<body>
<h1>Description</h1>
<p>See <a href="resources/connection-reuse-test.js">the included test
  script</a></p>
</body>
</html>
