summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_current_inner_window.html
blob: 3e7a700e635c56a15d62b36a152af495b2ebe60a (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
59
60
61
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test that current inner window checks are correct after navigations/discards</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>

<iframe id="frame"></iframe>

<script type="application/javascript">
"use strict";

const TEST_FILE = "file_current_inner_window.html";
const BASE_PATH = location.pathname.replace(/[^\/]+$/, "");

let frame = document.getElementById("frame");

function loadInFrame(url) {
  return new Promise(resolve => {
    frame.addEventListener("load", resolve, { once: true });
    frame.contentWindow.location = url;
  });
}

add_task(async function() {
  await loadInFrame(TEST_FILE);

  // Store the check function from the window before we navigate. After that,
  // its bare word property accesses will continue referring to the same inner
  // window no matter how many times the frame navigates.
  let check1 = frame.contentWindow.isCurrentWinnerWindow;
  ok(check1(),
     "Initial inner window should be current before we navigate away");

  await loadInFrame(`http://example.com/${BASE_PATH}/${TEST_FILE}`);
  ok(!check1(),
     "Initial inner window should no longer be current after we navigate away");
  await SpecialPowers.spawn(frame, [], () => {
    Assert.ok(this.content.wrappedJSObject.isCurrentWinnerWindow(),
              "Remote inner window should be current after before we navigate away");
  });

  await loadInFrame(TEST_FILE);
  ok(!check1(),
     "Initial inner window should still not be current after we back to current process");
  let check2 = frame.contentWindow.isCurrentWinnerWindow;
  ok(check2(),
     "Second in-process inner window should be current before we remove the frame");

  frame.remove();
  ok(!check1(),
     "Initial inner window should still not be current after we remove the frame");
  ok(check2(),
     "Second in-process inner window should still be current after we remove the frame");
});
</script>
</body>
</html>