tor-browser

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

same-document-refresh.html (2179B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>Same-Document Referrer from Refresh</title>
      4 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=266554">
      5 <link rel="help" href="https://github.com/whatwg/html/issues/6451">
      6 <link rel="help" href="https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate-fragid-step">
      7 <link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#pragma-directives:navigate">
      8 <link rel="author" title="Zach Hoffman" href="mailto:zach@zrhoffman.net">
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 <body>
     12 <script>
     13 promise_test(async t => {
     14  const fragment = "#section";
     15  const refreshFrom = new URL("resources/refresh-with-section.sub.html", location).href + "?" + new URLSearchParams({url: fragment});
     16 
     17  const frame = document.createElement("iframe");
     18  const { promise: frameLoaded, resolve: resolveFrameLoaded } = Promise.withResolvers();
     19  const { promise: messageHandled, resolve: resolveMessageHandled } = Promise.withResolvers();
     20 
     21  let loadCount = 0;
     22  frame.addEventListener("load", t.step_func(() => {
     23    loadCount++;
     24    try {
     25      if (loadCount === 1) {
     26        assert_equals(frame.contentWindow.location.href, refreshFrom, "original page loads");
     27        assert_equals(frame.contentWindow.referrer.textContent, location.href, "referrer header is parent frame");
     28        assert_equals(frame.contentDocument.referrer, location.href, "document referrer is parent frame");
     29      }
     30    } finally {
     31      if (loadCount === 1) {
     32        resolveFrameLoaded();
     33      }
     34    }
     35  }));
     36 
     37  addEventListener("message", t.step_func(msg => {
     38    const {referrer, documentReferrer, url} = msg.data;
     39    try {
     40      assert_equals(url, refreshFrom + fragment, "refresh page has expected URL");
     41      assert_equals(referrer, location.href, "referrer header is unchanged");
     42      assert_equals(documentReferrer, location.href, "document referrer is unchanged");
     43    } finally {
     44      resolveMessageHandled();
     45    }
     46  }));
     47 
     48  frame.src = refreshFrom;
     49  document.body.appendChild(frame);
     50  await frameLoaded;
     51  await messageHandled;
     52 });
     53 </script>
     54 </body>