|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id= |
|
5 --> |
|
6 <head> |
|
7 <meta charset="utf-8"> |
|
8 <title>Test for Bug </title> |
|
9 |
|
10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
|
12 <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script> |
|
13 <script type="application/javascript;version=1.8"> |
|
14 Components.utils.import("resource://gre/modules/devtools/Loader.jsm"); |
|
15 const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {}); |
|
16 |
|
17 const inspector = devtools.require("devtools/server/actors/inspector"); |
|
18 |
|
19 window.onload = function() { |
|
20 SimpleTest.waitForExplicitFinish(); |
|
21 runNextTest(); |
|
22 } |
|
23 |
|
24 var gInspectee = null; |
|
25 var gWalker = null; |
|
26 var gClient = null; |
|
27 var gChildFrame = null; |
|
28 var gChildDocument = null; |
|
29 var gCleanupConnection = null; |
|
30 |
|
31 function setup(callback) { |
|
32 let url = document.getElementById("inspectorContent").href; |
|
33 gCleanupConnection = attachURL(url, function(err, client, tab, doc) { |
|
34 gInspectee = doc; |
|
35 let {InspectorFront} = devtools.require("devtools/server/actors/inspector"); |
|
36 let inspector = InspectorFront(client, tab); |
|
37 promiseDone(inspector.getWalker().then(walker => { |
|
38 gClient = client; |
|
39 gWalker = walker; |
|
40 }).then(callback)); |
|
41 }); |
|
42 } |
|
43 |
|
44 function teardown() { |
|
45 gWalker = null; |
|
46 gClient = null; |
|
47 gInspectee = null; |
|
48 gChildFrame = null; |
|
49 if (gCleanupConnection) { |
|
50 gCleanupConnection(); |
|
51 gCleanupConnection = null; |
|
52 } |
|
53 } |
|
54 |
|
55 function assertOwnership() { |
|
56 return assertOwnershipTrees(gWalker); |
|
57 } |
|
58 |
|
59 function loadChildSelector(selector) { |
|
60 return gWalker.querySelector(gWalker.rootNode, "#childFrame").then(frame => { |
|
61 ok(frame.numChildren > 0, "Child frame should consider its loaded document as a child."); |
|
62 gChildFrame = frame; |
|
63 return gWalker.children(frame); |
|
64 }).then(children => { |
|
65 return gWalker.querySelectorAll(children.nodes[0], selector); |
|
66 }).then(nodeList => { |
|
67 return nodeList.items(); |
|
68 }); |
|
69 } |
|
70 |
|
71 function getUnloadedDoc(mutations) { |
|
72 for (let change of mutations) { |
|
73 if (isUnload(change)) { |
|
74 return change.target; |
|
75 } |
|
76 } |
|
77 return null; |
|
78 } |
|
79 |
|
80 addTest(function loadNewChild() { |
|
81 setup(() => { |
|
82 let beforeUnloadSize = 0; |
|
83 // Load a bunch of fronts for actors inside the child frame. |
|
84 promiseDone(loadChildSelector("#longlist div").then(() => { |
|
85 let childFrame = gInspectee.querySelector("#childFrame"); |
|
86 childFrame.src = "data:text/html,<html>new child</html>"; |
|
87 return waitForMutation(gWalker, isChildList); |
|
88 }).then(mutations => { |
|
89 let unloaded = getUnloadedDoc(mutations); |
|
90 mutations = assertSrcChange(mutations); |
|
91 mutations = assertUnload(mutations); |
|
92 mutations = assertFrameLoad(mutations); |
|
93 mutations = assertChildList(mutations); |
|
94 |
|
95 is(mutations.length, 0, "Got the expected mutations."); |
|
96 |
|
97 assertOwnership(); |
|
98 |
|
99 return checkMissing(gClient, unloaded); |
|
100 }).then(() => { |
|
101 teardown(); |
|
102 }).then(runNextTest)); |
|
103 }); |
|
104 }); |
|
105 |
|
106 addTest(function loadNewChildTwice() { |
|
107 setup(() => { |
|
108 let beforeUnloadSize = 0; |
|
109 // Load a bunch of fronts for actors inside the child frame. |
|
110 promiseDone(loadChildSelector("#longlist div").then(() => { |
|
111 let childFrame = gInspectee.querySelector("#childFrame"); |
|
112 childFrame.src = "data:text/html,<html>new child</html>"; |
|
113 return waitForMutation(gWalker, isChildList); |
|
114 }).then(mutations => { |
|
115 // The first load went through as expected (as tested in loadNewChild) |
|
116 // Now change the source again, but this time we *don't* expect |
|
117 // an unload, because we haven't seen the new child document yet. |
|
118 let childFrame = gInspectee.querySelector("#childFrame"); |
|
119 childFrame.src = "data:text/html,<html>second new child</html>"; |
|
120 return waitForMutation(gWalker, isChildList); |
|
121 }).then(mutations => { |
|
122 mutations = assertSrcChange(mutations); |
|
123 mutations = assertFrameLoad(mutations); |
|
124 mutations = assertChildList(mutations); |
|
125 ok(!getUnloadedDoc(mutations), "Should not have gotten an unload."); |
|
126 |
|
127 is(mutations.length, 0, "Got the expected mutations."); |
|
128 |
|
129 assertOwnership(); |
|
130 }).then(() => { |
|
131 teardown(); |
|
132 }).then(runNextTest)); |
|
133 }); |
|
134 }); |
|
135 |
|
136 |
|
137 addTest(function loadNewChildTwiceAndCareAboutIt() { |
|
138 setup(() => { |
|
139 let beforeUnloadSize = 0; |
|
140 // Load a bunch of fronts for actors inside the child frame. |
|
141 promiseDone(loadChildSelector("#longlist div").then(() => { |
|
142 let childFrame = gInspectee.querySelector("#childFrame"); |
|
143 childFrame.src = "data:text/html,<html>new child</html>"; |
|
144 return waitForMutation(gWalker, isChildList); |
|
145 }).then(mutations => { |
|
146 // Read the new child |
|
147 return loadChildSelector("#longlist div"); |
|
148 }).then(() => { |
|
149 // Now change the source again, and expect the same results as loadNewChild. |
|
150 let childFrame = gInspectee.querySelector("#childFrame"); |
|
151 childFrame.src = "data:text/html,<html>second new child</html>"; |
|
152 return waitForMutation(gWalker, isChildList); |
|
153 }).then(mutations => { |
|
154 let unloaded = getUnloadedDoc(mutations); |
|
155 |
|
156 mutations = assertSrcChange(mutations); |
|
157 mutations = assertUnload(mutations); |
|
158 mutations = assertFrameLoad(mutations); |
|
159 mutations = assertChildList(mutations); |
|
160 |
|
161 is(mutations.length, 0, "Got the expected mutations."); |
|
162 |
|
163 assertOwnership(); |
|
164 |
|
165 return checkMissing(gClient, unloaded); |
|
166 }).then(() => { |
|
167 teardown(); |
|
168 }).then(runNextTest)); |
|
169 }); |
|
170 }); |
|
171 |
|
172 addTest(function testBack() { |
|
173 setup(() => { |
|
174 let beforeUnloadSize = 0; |
|
175 // Load a bunch of fronts for actors inside the child frame. |
|
176 promiseDone(loadChildSelector("#longlist div").then(() => { |
|
177 let childFrame = gInspectee.querySelector("#childFrame"); |
|
178 childFrame.src = "data:text/html,<html>new child</html>"; |
|
179 return waitForMutation(gWalker, isChildList); |
|
180 }).then(mutations => { |
|
181 // Read the new child |
|
182 return loadChildSelector("#longlist div"); |
|
183 }).then(() => { |
|
184 // Now use history.back to change the source, and expect the same results as loadNewChild. |
|
185 let childFrame = gInspectee.querySelector("#childFrame"); |
|
186 childFrame.contentWindow.history.back(); |
|
187 return waitForMutation(gWalker, isChildList); |
|
188 }).then(mutations => { |
|
189 let unloaded = getUnloadedDoc(mutations); |
|
190 mutations = assertSrcChange(mutations); |
|
191 mutations = assertUnload(mutations); |
|
192 mutations = assertFrameLoad(mutations); |
|
193 mutations = assertChildList(mutations); |
|
194 is(mutations.length, 0, "Got the expected mutations."); |
|
195 |
|
196 assertOwnership(); |
|
197 |
|
198 return checkMissing(gClient, unloaded); |
|
199 }).then(() => { |
|
200 teardown(); |
|
201 }).then(runNextTest)); |
|
202 }); |
|
203 }); |
|
204 |
|
205 </script> |
|
206 </head> |
|
207 <body> |
|
208 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> |
|
209 <a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a> |
|
210 <p id="display"></p> |
|
211 <div id="content" style="display: none"> |
|
212 |
|
213 </div> |
|
214 <pre id="test"> |
|
215 </pre> |
|
216 </body> |
|
217 </html> |