tor-browser

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

after-same-document-navigation.html (1737B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>Referrer from Refresh after Same-Document Navigation</title>
      4 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=266554">
      5 <link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#pragma-directives:navigate">
      6 <link rel="author" title="Zach Hoffman" href="mailto:zach@zrhoffman.net">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <body>
     10 <script>
     11 promise_test(async t => {
     12  const refreshTo = new URL("resources/refreshed.txt", location).href;
     13  const refreshFrom = new URL("resources/refresh-with-section.sub.html", location).href + "?" + new URLSearchParams({url: refreshTo});
     14 
     15  const frame = document.createElement("iframe");
     16  const { promise: frameLoaded, resolve: resolveFrameLoaded } = Promise.withResolvers();
     17 
     18  let loadCount = 0;
     19  frame.addEventListener("load", t.step_func(() => {
     20    loadCount++;
     21    try {
     22      if (loadCount === 1) {
     23        assert_equals(frame.contentWindow.location.href, refreshFrom + "#section", "same-document navigation occurred");
     24        assert_equals(frame.contentWindow.referrer.textContent, location.href, "referrer header is parent frame");
     25        assert_equals(frame.contentDocument.referrer, location.href, "document referrer is parent frame");
     26      }
     27    } finally {
     28      if (loadCount === 2) {
     29        resolveFrameLoaded();
     30      }
     31    }
     32  }));
     33 
     34  frame.src = refreshFrom;
     35  document.body.appendChild(frame);
     36  await frameLoaded;
     37 
     38  assert_equals(frame.contentWindow.location.href, refreshTo, "refresh page has expected URL")
     39  assert_equals(frame.contentDocument.referrer, frame.src, "referrer does not include fragment");
     40 });
     41 </script>
     42 </body>