chromium/third_party/blink/web_tests/external/wpt/html/semantics/scripting-1/the-script-element/json-module/referrer-policies.sub.html

<!DOCTYPE html>
<html>
<head>
<title>Referrers with JSON module requests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script type="module">
  // "name" parameter is necessary for bypassing the module map.
  import referrerSame from "./referrer-checker.py?name=sameNoReferrerPolicy" with { type: "json"};
  import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py?name=remoteNoReferrerPolicy" with { type: "json"};

  const origin = (new URL(location.href)).origin + "/";
  const originUrl = location.href;

  test(t => {
    assert_equals(
        referrerSame.referrer, originUrl,
        "Referrer URL should be sent for the same-origin top-level script.");
  }, "Importing a same-origin top-level script with the default referrer policy.");

  test(t => {
    assert_equals(
        referrerRemote.referrer, origin,
        "Referrer origin should be sent for the remote-origin top-level script.");
  }, "Importing a remote-origin top-level script with the default referrer policy.");
</script>
<script type="module" referrerpolicy="origin">
  import referrerSame from "./referrer-checker.py?name=sameReferrerPolicyOrigin" with { type: "json"};
  import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py?name=remoteReferrerPolicyOrigin" with { type: "json"};

  const origin = (new URL(location.href)).origin + "/";

  test(t => {
    assert_equals(
        referrerSame.referrer, origin,
        "Referrer origin should be sent for the same-origin top-level script.");
  }, "Importing a same-origin top-level script with the origin policy.");

  test(t => {
    assert_equals(
        referrerRemote.referrer, origin,
        "Referrer origin should be sent for the remote-origin top-level script.");
  }, "Importing a remote-origin top-level script with the origin policy.");

</script>
<script type="module" referrerpolicy="no-referrer">
  import referrerSame from "./referrer-checker.py?name=sameReferrerPolicyNoReferrer" with { type: "json"};
  import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py?name=remoteReferrerPolicyNoReferrer" with { type: "json"};

  test(t => {
    assert_equals(
        referrerSame.referrer, "",
        "No referrer should be sent for the same-origin top-level script.");
  }, "Importing a same-origin top-level script with the no-referrer policy.");

  test(t => {
    assert_equals(
        referrerRemote.referrer, "",
        "No referrer should be sent for the remote-origin top-level script.");
  }, "Importing a remote-origin top-level script with the no-referrer policy.");

</script>
<script type="module" referrerpolicy="unsafe-url">
  import referrerSame from "./referrer-checker.py?name=sameNoReferrerPolicyUnsafeUrl" with { type: "json"};
  import referrerRemote from "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/json-module/referrer-checker.py?name=remoteNoReferrerPolicyUnsafeUrl" with { type: "json"};

  const originUrl = location.href;

  test(t => {
    assert_equals(
        referrerSame.referrer, originUrl,
        "Referrer URL should be sent for the same-origin top-level script.");
  }, "Importing a same-origin top-level script with the unsafe-url referrer policy.");

  test(t => {
    assert_equals(
        referrerRemote.referrer, originUrl,
        "Referrer URL should be sent for the remote-origin top-level script.");
  }, "Importing a remote-origin top-level script with the unsafe-url referrer policy.");
</script>
</body>
</html>