tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

referrer-policy-for-descendants.sub.html (6766B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>Module script descendants use the referrer policy on their ancestor, if one exists</title>
      5 <link rel=help href="https://github.com/whatwg/html/pull/9210">
      6 <meta name="referrer" content="no-referrer">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 </head>
     10 <body>
     11 <script type="module">
     12 
     13 // "name" parameter is necessary for bypassing the module map.
     14 //
     15 // The case where the parent module script is sent with no referrer policy at
     16 // all is covered in `referrer-no-referrer.sub.html` (and others like it). In
     17 // that case, the parent module inherits its referencing document's referrer
     18 // policy for use in descendant imports.
     19 
     20 import { referrer as parentWithNoReferrerWhenDowngrade } from
     21    "./resources/import-referrer-checker.sub.js?name=same_same&pipe=header(Referrer-Policy,no-referrer-when-downgrade)";
     22 
     23 import { referrer as parentWithOrigin} from
     24    "./resources/import-referrer-checker.sub.js?name=same_remote&pipe=header(Referrer-Policy,origin)";
     25 
     26 import { referrer as parentWithSameOrigin} from
     27    "./resources/import-referrer-checker.sub.js?name=same_remote_so&pipe=header(Referrer-Policy,same-origin)";
     28 
     29 import { referrer as parentWithOriginWhenCrossOriginRemoteDescendant} from
     30    "./resources/import-remote-origin-referrer-checker.sub.js?name=same_remote_owco&pipe=header(Referrer-Policy,origin-when-cross-origin)";
     31 
     32 import { referrer as remoteParentWithOriginWhenCrossOriginSameOriginDescendant} from
     33    "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/resources/import-referrer-checker.sub.js?name=remote_same&pipe=header(Referrer-Policy,origin-when-cross-origin)";
     34 
     35 import { referrer as remoteParentWithSameOriginWhenCrossOriginSameOriginDescendant} from
     36    "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/resources/import-referrer-checker.sub.js?name=remote_same_so&pipe=header(Referrer-Policy,same-origin)";
     37 
     38 import { referrer as remoteParentWithOriginWhenCrossOriginRemoteDescendant} from
     39    "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/resources/import-same-origin-referrer-checker-from-remote-origin.sub.js?name=remote_remote&pipe=header(Referrer-Policy,origin-when-cross-origin)";
     40 
     41 import { referrer as remoteParentWithSameOriginWhenCrossOriginRemoteDescendant} from
     42    "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/resources/import-same-origin-referrer-checker-from-remote-origin.sub.js?name=remote_remote_so&pipe=header(Referrer-Policy,same-origin)";
     43 
     44 import { referrer as parentWithInvalidPolicy } from
     45    "http://{{domains[www1]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/resources/import-referrer-checker.sub.js?name=remote_same_invalid&pipe=header(Referrer-Policy,invalid-policy)";
     46 
     47 test(t => {
     48  const expected_url =
     49      new URL("html/semantics/scripting-1/the-script-element/module/resources/import-referrer-checker.sub.js?name=same_same&pipe=header(Referrer-Policy,no-referrer-when-downgrade)",
     50              window.origin);
     51  assert_equals(
     52      parentWithNoReferrerWhenDowngrade, expected_url.toString(),
     53      "Descendant referrer should be the parent's full URL.");
     54 }, "Parent module delivered with `no-referrer-when-downgrade` policy importing a same-origin descendant script.");
     55 
     56 test(t => {
     57  assert_equals(
     58      parentWithOrigin, window.origin + "/",
     59      "Descendant referrer should be the parent's origin.");
     60 }, "Parent module delivered with `origin` policy importing a same-origin descendant script.");
     61 
     62 test(t => {
     63  const expected_url =
     64      new URL("html/semantics/scripting-1/the-script-element/module/resources/import-referrer-checker.sub.js?name=same_remote_so&pipe=header(Referrer-Policy,same-origin)",
     65              window.origin);
     66  assert_equals(
     67      parentWithSameOrigin, expected_url.toString(),
     68      "Descendant referrer should be the parent's full URL.");
     69 }, "Parent module delivered with `same-origin` policy importing a same-origin descendant script.");
     70 
     71 test(t => {
     72  assert_equals(
     73      parentWithOriginWhenCrossOriginRemoteDescendant, window.origin + "/",
     74      "Remote descendant referrer should be the parent's origin.");
     75 }, "Parent module delivered with `origin-when-cross-origin` policy importing a cross-origin descendant script.");
     76 
     77 test(t => {
     78  const expected_url =
     79      new URL("/html/semantics/scripting-1/the-script-element/module/resources/import-referrer-checker.sub.js?name=remote_same&pipe=header(Referrer-Policy,origin-when-cross-origin)",
     80              "http://{{domains[www1]}}:{{ports[http][0]}}/");
     81  assert_equals(
     82      remoteParentWithOriginWhenCrossOriginSameOriginDescendant, expected_url.toString(),
     83      "Same-origin descendant referrer should be the parent's full URL.");
     84 }, "Remote parent module delivered with `origin-when-cross-origin` policy importing a same-origin-to-parent-module descendant script.");
     85 
     86 test(t => {
     87  const expected_url =
     88      new URL("/html/semantics/scripting-1/the-script-element/module/resources/import-referrer-checker.sub.js?name=remote_same_so&pipe=header(Referrer-Policy,same-origin)",
     89              "http://{{domains[www1]}}:{{ports[http][0]}}/");
     90  assert_equals(
     91      remoteParentWithSameOriginWhenCrossOriginSameOriginDescendant, expected_url.toString(),
     92      "Same-origin descendant referrer should be the parent's full URL.");
     93 }, "Remote parent module delivered with `same-origin` policy importing a same-origin-to-parent-module descendant script.");
     94 
     95 test(t => {
     96  assert_equals(
     97      remoteParentWithOriginWhenCrossOriginRemoteDescendant, "http://{{domains[www1]}}:{{ports[http][0]}}/",
     98      "Remote-origin descendant referrer should be the parent's origin.");
     99 }, "Remote parent module delivered with `origin-when-cross-origin` policy importing a cross-origin-to-parent-module descendant script.");
    100 
    101 test(t => {
    102  assert_equals(
    103      remoteParentWithSameOriginWhenCrossOriginRemoteDescendant, "");
    104 }, "Remote parent module delivered with `same-origin` policy importing a cross-origin-to-parent-module descendant script.");
    105 
    106 // This tests the following spec line:
    107 //
    108 // "If referrerPolicy is not the empty string, set options's referrer policy to
    109 //  referrerPolicy."
    110 //
    111 // In other words, invalid referrer policies are ignored, so the referrer policy
    112 // from the referencing document is inherited as usual, which is `no-referrer`
    113 // in this case.
    114 test(t => {
    115  assert_equals(
    116      parentWithInvalidPolicy, "",
    117      "Descendant referrer should be empty.");
    118 }, "Parent module delivered with invalid policy importing a same-origin descendant script.");
    119 
    120 </script>
    121 </body>
    122 </html>