summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/leaks/003.html-disabled
blob: dc7b0ba39d1c78078c731e126b0414e483c77e42 (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
<p>This test verifies that garbage collection successfully cleans up after the destruction
of a frame containing a JavaScript interpreter. If the test passes, you'll see a PASS message below.</p>
<hr>
<pre id="log"></pre>

<!-- The test: -->
<iframe id="iframe" src="data:text/html,<script>;</script>" style="display:none"></iframe>
<script>
function log(s)
{
    document.getElementById("log").appendChild(document.createTextNode(s));
}

var wiggleRoom = 20;

window.onload = function main()
{
    if (!window.layoutTestController || !window.GCController) {
        log("FAIL: This test uses the layoutTestController and the GCController, so it can only run in DumpRenderTree.\n");
        return;
    }
    
    layoutTestController.dumpAsText();
    layoutTestController.waitUntilDone();

    // Start with no garbage, so GC doesn't run automatically during the test.
    GCController.collect();
    
    // Create a little garbage, so we can detect failure in the case where the 
    // test doesn't produce any garbage because it fails to destroy the frame.
    var garbage = [ { }, { }, { }, { }, { }, { }, { }, { }, { }, { } ];
    garbage = null;

    // Destroy a frame that has a JavaScript interpreter.
    var iframe = document.getElementById("iframe");
    iframe.parentNode.removeChild(iframe);

    // Finish the test on a time-out, to allow the Frame keepAlive timer to fire
    // and release the frame before we generate results.
    var continueTest = function continueTest()
    {
        // Measure how many garbage JS objects are still around.
        var jsObjectCountStart = GCController.getJSObjectCount();
        GCController.collect();
        var jsObjectCountDelta = jsObjectCountStart - GCController.getJSObjectCount();
        var garbageCount = jsObjectCountDelta > 0 ? jsObjectCountDelta : 0;
        
        // Fail if a lot of garbage was left behind. This can mean one of many things:
        // the frame was not destroyed; the frame destruction did not trigger GC; or
        // GC was not effective.
        if (garbageCount > wiggleRoom) {
            log("FAIL: " + garbageCount + " garbage JS objects left uncollected.\n");
        } else {
            log("PASS: " + wiggleRoom + " garbage JS objects or fewer left uncollected after destroying a frame.\n");
        }

        layoutTestController.notifyDone();
    }
    setTimeout(continueTest, 10);
}
</script>