summaryrefslogtreecommitdiffstats
path: root/docshell/test/mochitest/test_redirect_history.html
blob: a67c808405fc6852bb7eeb6b0348bb52c9875adf (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
57
58
<!doctype html>
<html>
  <head>
    <title>Test for redirect from POST</title>
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <script src="/tests/SimpleTest/EventUtils.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  </head>
  <body>
    <script>
      "use strict";

      info("Starting tests");

      let tests = new Map([
        ["sameorigin", window.location.origin],
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        ["crossorigin", "http://test1.example.com"],
      ]);
      for (let [kind, origin] of tests) {
        add_task(async function runTest() {
          info(`Submitting to ${origin}`);

          let win;
          await new Promise(resolve => {
            addEventListener("message", resolve, { once: true });
            info("Loading file_redirect_history.html");
            win = window.open("file_redirect_history.html");
          });
          info("Done loading file_redirect_history.html");

          let length = win.history.length;
          let loc = win.location.toString();

          await new Promise(resolve => {
            addEventListener("message", resolve, { once: true });
            info("Posting");
            win.postMessage(`${origin}/tests/docshell/test/mochitest/form_submit_redirect.sjs?redirectTo=${loc}`, "*")
          });
          info("Done posting\n");
          is(win.history.length, length, `Test ${kind}: history length should not change.`);
          info(`Length=${win.history.length}`);
          is(win.location.toString(), loc, `Test ${kind}: location should not change.`);

          await new Promise(resolve => {
            addEventListener("message", resolve, { once: true });
            info("Reloading");
            win.location.reload();
          });
          info("Done reloading\n");
          is(win.location.toString(), loc, `Test ${kind}: location should not change after reload.`);

          win.close();
        });
      }
    </script>
  </body>
</html>