summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/dom/defaultView-on-detached-document.html
blob: b5095d2d88625b93ecceacb3f528a750baa59396 (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
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script>
var jsTestIsAsync = true;

description("Tests that document.defaultView on a detached document doesn't crash.");

var cachedWindow;
var cachedDocument;
var testFrameUnloaded = false;

// DRT dumps out the number of unload handlers associated with a document once it loads.
// Unfortunately, load order is not guaranteed, so wait until the first frame has finished loading
// before setting up the rest of the test.
function setupTest()
{
    var frame2 = document.createElement('iframe');
    frame2.srcdoc = '<script>window.onunload=function() { window.top.finishTest(); };</scr' + 'ipt>';
    frame2.onload = runTest;
    document.getElementById('frames').appendChild(frame2);
}

function runTest()
{
    var i = document.getElementById("testFrame");
    // Make sure DOMWindow doesn't get GCed and clear Document's pointer back to it.
    cachedWindow = i.contentWindow;
    cachedDocument = i.contentDocument;
    // This test is structured to catch a document.defaultView crash when all of the following are true:
    // 1. Document's pointer back to DOMWindow has not yet been cleared by DOMWindow destruction.
    // 2. DOMWindow's pointer back to its Frame has not yet been cleared by Frame destruction.
    // 3. The frame is already detached.
    // One way to satisfy this condition is to test the value of document.defaultView when removing
    // a DOM node that contains multiple subframes, since ChildFrameDisconnector keeps a ref to the
    // affected HTMLFrameOwnerElements (and consequently the Frame) on the stack.
    var frameContainer = document.getElementById("frames");
    frameContainer.parentNode.removeChild(frameContainer);
}

function finishTest()
{
    shouldBeTrue("testFrameUnloaded");
    shouldBeUndefined("cachedDocument.defaultView");
    finishJSTest();
}
</script>
<body onload="setupTest()">
  <div id="frames">
    <iframe id="testFrame" srcdoc="<script>window.onunload=function() { window.top.testFrameUnloaded = true; };</script>"></iframe>
  </div>
</body>