2 <script src=
"../../resources/js-test.js"></script>
4 var jsTestIsAsync
= true;
6 description("Tests that document.defaultView on a detached document doesn't crash.");
10 var testFrameUnloaded
= false;
12 // DRT dumps out the number of unload handlers associated with a document once it loads.
13 // Unfortunately, load order is not guaranteed, so wait until the first frame has finished loading
14 // before setting up the rest of the test.
17 var frame2
= document
.createElement('iframe');
18 frame2
.srcdoc
= '<script>window.onunload=function() { window.top.finishTest(); };</scr' + 'ipt>';
19 frame2
.onload
= runTest
;
20 document
.getElementById('frames').appendChild(frame2
);
25 var i
= document
.getElementById("testFrame");
26 // Make sure DOMWindow doesn't get GCed and clear Document's pointer back to it.
27 cachedWindow
= i
.contentWindow
;
28 cachedDocument
= i
.contentDocument
;
29 // This test is structured to catch a document.defaultView crash when all of the following are true:
30 // 1. Document's pointer back to DOMWindow has not yet been cleared by DOMWindow destruction.
31 // 2. DOMWindow's pointer back to its Frame has not yet been cleared by Frame destruction.
32 // 3. The frame is already detached.
33 // One way to satisfy this condition is to test the value of document.defaultView when removing
34 // a DOM node that contains multiple subframes, since ChildFrameDisconnector keeps a ref to the
35 // affected HTMLFrameOwnerElements (and consequently the Frame) on the stack.
36 var frameContainer
= document
.getElementById("frames");
37 frameContainer
.parentNode
.removeChild(frameContainer
);
42 shouldBeTrue("testFrameUnloaded");
43 shouldBeUndefined("cachedDocument.defaultView");
47 <body onload=
"setupTest()">
49 <iframe id=
"testFrame" srcdoc=
"<script>window.onunload=function() { window.top.testFrameUnloaded = true; };</script>"></iframe
>