summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/bugs/test_bug534149.html
blob: 8c1a8b7e4d654d16ae64f56b452391e46f5f0970 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=534149
-->
<head>
  <title>Test for Bug 534149</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=534149">Mozilla Bug 534149</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 534149 **/
function getIDs(iframe) {
  var win = iframe.contentWindow;
  // Force inner creation
  win.document;

  let wgc = SpecialPowers.wrap(win).windowGlobalChild;
  return [wgc.outerWindowId, wgc.innerWindowId];
}

var i1 = document.createElement("iframe");
var i2 = document.createElement("iframe");

document.body.appendChild(i1);
var [i1outer, i1inner] = getIDs(i1);

document.body.appendChild(i2);
var [i2outer, i2inner] = getIDs(i2);

is(i1inner, i1outer + 1, "For frame 1, inner should come right after outer");
is(i2inner, i2outer + 1, "For frame 2, inner should come right after outer");
is(i2outer, i1inner + 1, "Frame 2 comes right after frame 1");

var innerWindowDestroyID = null;
var outerWindowDestroyID = null;

var outerObserver = {
  observe(id) {
    outerWindowDestroyID =
      SpecialPowers.wrap(id).QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
    SpecialPowers.removeObserver(outerObserver, "outer-window-destroyed");
    maybeContinueTest();
  }
};
var innerObserver = {
  observe(id) {
    innerWindowDestroyID =
      SpecialPowers.wrap(id).QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
    SpecialPowers.removeObserver(innerObserver, "inner-window-destroyed");
    maybeContinueTest();
  }
};

function removeFrame(iframe) {
  SpecialPowers.addObserver(outerObserver, "outer-window-destroyed");
  SpecialPowers.addObserver(innerObserver, "inner-window-destroyed");

  iframe.remove();
}

function maybeContinueTest() {
  if (innerWindowDestroyID != null &&
      outerWindowDestroyID != null) {
    is(innerWindowDestroyID, i1inner, "inner window of frame 1 should be destroyed");
    is(outerWindowDestroyID, i1outer, "outer window of frame 1 should be destroyed");
    SimpleTest.finish();
  }
}

removeFrame(i1);
SimpleTest.waitForExplicitFinish();

</script>
</pre>
</body>
</html>