summaryrefslogtreecommitdiffstats
path: root/dom/security/test/referrer-policy/test_referrer_header_current_document.html
blob: 27dc54a21f1a00f80378f2b88038bd02ceec197a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test referrer header not affecting document.referrer for current document for Bug 1601743</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>

  <!--
  Testing that navigating to a document with Referrer-Policy:same-origin doesn't affect
  the value of document.referrer for that document.
  https://bugzilla.mozilla.org/show_bug.cgi?id=1601743
  -->

  <script type="application/javascript">
    function getExpectedReferrer(referrer) {
      let defaultPolicy = SpecialPowers.getIntPref("network.http.referer.defaultPolicy");
      SimpleTest.ok([2, 3].indexOf(defaultPolicy) > -1, "default referrer policy should be either strict-origin-when-cross-origin(2) or no-referrer-when-downgrade(3)");
      if (defaultPolicy == 2) {
        return referrer.match(/https?:\/\/[^\/]+\/?/i)[0];
      }
      return referrer;
    }
    const IFRAME_URL = `${location.origin}/tests/dom/security/test/referrer-policy/referrer_header_current_document_iframe.html`;

    SimpleTest.waitForExplicitFinish();
    window.addEventListener("message", (event) => {
      SimpleTest.is(event.data, getExpectedReferrer(IFRAME_URL), "Must have the original iframe as the referrer!");
      SimpleTest.finish();
    }, { once: true });
  </script>
</head>

<body>
<iframe src="referrer_header_current_document_iframe.html"></iframe>
</body>