summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/history/the-history-interface/history_reload_referrer-2.html
blob: d85517a15f8649417533c03f0d157ef63245710b (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
  <head>
    <title>
      Ensure referrer header persists after
      history.pushState/replaceState/fragment navigation and reload
    </title>
  </head>
  <body>
    <a id="fragment" href="#fragment">fragment</a>
    <noscript><p>Enable JavaScript and reload</p></noscript>
    <div id="log"></div>
    <script type="text/javascript">
      const step = localStorage.getItem("history_reload_referrer_step") || "1";
      localStorage.setItem("history_reload_referrer_step", parseInt(step) + 1);

      var httpReferer = unescape("{{headers[referer]}}");
      var expectedReferrer = location.href.replace(
        /\/[^\/]*$/,
        "\/history_reload_referrer-1.html"
      );

      parent.test(function () {
        parent.assert_equals(httpReferer, expectedReferrer);
      }, `Step ${step}: Checking HTTP referrer (is "${httpReferer}")`);
      parent.test(function () {
        parent.assert_equals(document.referrer, expectedReferrer);
      }, `Step ${step}: Checking document.referrer (is "${httpReferer}")`);

      switch (step) {
        case "1":
          history.pushState("", "", location);
          location.reload();
          break;

        case "2":
          history.replaceState("", "", location);
          location.reload();
          break;

        case "3":
          document.getElementById("fragment").click();
          location.reload();
          break;

        case "4":
          localStorage.removeItem("history_reload_referrer_step");
          parent.done();
          break;

        default:
          throw new Error(`Unexpected step "${step}"`);
      }
    </script>
  </body>
</html>