summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/mochitest/test_inspector-mutations-frameload.html
blob: 54966cea74c89d7fb6b2fd43283671dc9986a669 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug </title>

  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
  <script type="application/javascript;version=1.8">
const inspector = require("devtools/shared/fronts/inspector");

window.onload = function() {
  SimpleTest.waitForExplicitFinish();
  runNextTest();
}

var gInspectee = null;
var gWalker = null;
var gClient = null;
var gChildFrame = null;
var gChildDocument = null;
var gCleanupConnection = null;

function setup(callback) {
  let url = document.getElementById("inspectorContent").href;
  gCleanupConnection = attachURL(url, function(err, client, tab, doc) {
    gInspectee = doc;
    let {InspectorFront} = require("devtools/shared/fronts/inspector");
    let inspector = InspectorFront(client, tab);
    promiseDone(inspector.getWalker().then(walker => {
      gClient = client;
      gWalker = walker;
    }).then(callback));
  });
}

function teardown() {
  gWalker = null;
  gClient = null;
  gInspectee = null;
  gChildFrame = null;
  if (gCleanupConnection) {
    gCleanupConnection();
    gCleanupConnection = null;
  }
}

function assertOwnership() {
  return assertOwnershipTrees(gWalker);
}

function loadChildSelector(selector) {
  return gWalker.querySelector(gWalker.rootNode, "#childFrame").then(frame => {
    ok(frame.numChildren > 0, "Child frame should consider its loaded document as a child.");
    gChildFrame = frame;
    return gWalker.children(frame);
  }).then(children => {
    return gWalker.querySelectorAll(children.nodes[0], selector);
  }).then(nodeList => {
    return nodeList.items();
  });
}

function getUnloadedDoc(mutations) {
  for (let change of mutations) {
    if (isUnload(change)) {
      return change.target;
    }
  }
  return null;
}

addTest(function loadNewChild() {
  setup(() => {
    let beforeUnloadSize = 0;
    // Load a bunch of fronts for actors inside the child frame.
    promiseDone(loadChildSelector("#longlist div").then(() => {
      let childFrame = gInspectee.querySelector("#childFrame");
      childFrame.src = "data:text/html,<html>new child</html>";
      return waitForMutation(gWalker, isChildList);
    }).then(mutations => {
      let unloaded = getUnloadedDoc(mutations);
      mutations = assertSrcChange(mutations);
      mutations = assertUnload(mutations);
      mutations = assertFrameLoad(mutations);
      mutations = assertChildList(mutations);

      is(mutations.length, 0, "Got the expected mutations.");

      assertOwnership();

      return checkMissing(gClient, unloaded);
    }).then(() => {
      teardown();
    }).then(runNextTest));
  });
});

addTest(function loadNewChildTwice() {
  setup(() => {
    let beforeUnloadSize = 0;
    // Load a bunch of fronts for actors inside the child frame.
    promiseDone(loadChildSelector("#longlist div").then(() => {
      let childFrame = gInspectee.querySelector("#childFrame");
      childFrame.src = "data:text/html,<html>new child</html>";
      return waitForMutation(gWalker, isChildList);
    }).then(mutations => {
      // The first load went through as expected (as tested in loadNewChild)
      // Now change the source again, but this time we *don't* expect
      // an unload, because we haven't seen the new child document yet.
      let childFrame = gInspectee.querySelector("#childFrame");
      childFrame.src = "data:text/html,<html>second new child</html>";
      return waitForMutation(gWalker, isChildList);
    }).then(mutations => {
      mutations = assertSrcChange(mutations);
      mutations = assertFrameLoad(mutations);
      mutations = assertChildList(mutations);
      ok(!getUnloadedDoc(mutations), "Should not have gotten an unload.");

      is(mutations.length, 0, "Got the expected mutations.");

      assertOwnership();
    }).then(() => {
      teardown();
    }).then(runNextTest));
  });
});


addTest(function loadNewChildTwiceAndCareAboutIt() {
  setup(() => {
    let beforeUnloadSize = 0;
    // Load a bunch of fronts for actors inside the child frame.
    promiseDone(loadChildSelector("#longlist div").then(() => {
      let childFrame = gInspectee.querySelector("#childFrame");
      childFrame.src = "data:text/html,<html>new child</html>";
      return waitForMutation(gWalker, isChildList);
    }).then(mutations => {
      // Read the new child
      return loadChildSelector("#longlist div");
    }).then(() => {
      // Now change the source again, and expect the same results as loadNewChild.
      let childFrame = gInspectee.querySelector("#childFrame");
      childFrame.src = "data:text/html,<html>second new child</html>";
      return waitForMutation(gWalker, isChildList);
    }).then(mutations => {
      let unloaded = getUnloadedDoc(mutations);

      mutations = assertSrcChange(mutations);
      mutations = assertUnload(mutations);
      mutations = assertFrameLoad(mutations);
      mutations = assertChildList(mutations);

      is(mutations.length, 0, "Got the expected mutations.");

      assertOwnership();

      return checkMissing(gClient, unloaded);
    }).then(() => {
      teardown();
    }).then(runNextTest));
  });
});

addTest(function testBack() {
  setup(() => {
    let beforeUnloadSize = 0;
    // Load a bunch of fronts for actors inside the child frame.
    promiseDone(loadChildSelector("#longlist div").then(() => {
      let childFrame = gInspectee.querySelector("#childFrame");
      childFrame.src = "data:text/html,<html>new child</html>";
      return waitForMutation(gWalker, isChildList);
    }).then(mutations => {
      // Read the new child
      return loadChildSelector("#longlist div");
    }).then(() => {
      // Now use history.back to change the source, and expect the same results as loadNewChild.
      let childFrame = gInspectee.querySelector("#childFrame");
      childFrame.contentWindow.history.back();
      return waitForMutation(gWalker, isChildList);
    }).then(mutations => {
      let unloaded = getUnloadedDoc(mutations);
      mutations = assertSrcChange(mutations);
      mutations = assertUnload(mutations);
      mutations = assertFrameLoad(mutations);
      mutations = assertChildList(mutations);
      is(mutations.length, 0, "Got the expected mutations.");

      assertOwnership();

      return checkMissing(gClient, unloaded);
    }).then(() => {
      teardown();
    }).then(runNextTest));
  });
});

  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
<a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>
</body>
</html>