1 <p>This test verifies that garbage collection successfully cleans up after the destruction
2 of a frame containing a JavaScript interpreter. If the test passes, you'll see a PASS message below.</p>
7 <iframe id="iframe" src="data:text/html,<script>;</script>" style="display:none"></iframe>
11 document.getElementById("log").appendChild(document.createTextNode(s));
16 window.onload = function main()
18 if (!window.testRunner || !window.GCController) {
19 log("FAIL: This test uses the testRunner and the GCController, so it can only run in DumpRenderTree.\n");
23 testRunner.dumpAsText();
24 testRunner.waitUntilDone();
26 // Start with no garbage, so GC doesn't run automatically during the test.
27 GCController.collect();
29 // Create a little garbage, so we can detect failure in the case where the
30 // test doesn't produce any garbage because it fails to destroy the frame.
31 var garbage = [ { }, { }, { }, { }, { }, { }, { }, { }, { }, { } ];
34 // Destroy a frame that has a JavaScript interpreter.
35 var iframe = document.getElementById("iframe");
36 iframe.parentNode.removeChild(iframe);
38 // Finish the test on a time-out, to allow the Frame keepAlive timer to fire
39 // and release the frame before we generate results.
40 var continueTest = function continueTest()
42 // Measure how many garbage JS objects are still around.
43 var jsObjectCountStart = GCController.getJSObjectCount();
44 GCController.collect();
45 var jsObjectCountDelta = jsObjectCountStart - GCController.getJSObjectCount();
46 var garbageCount = jsObjectCountDelta > 0 ? jsObjectCountDelta : 0;
48 // Fail if a lot of garbage was left behind. This can mean one of many things:
49 // the frame was not destroyed; the frame destruction did not trigger GC; or
50 // GC was not effective.
51 if (garbageCount > wiggleRoom) {
52 log("FAIL: " + garbageCount + " garbage JS objects left uncollected.\n");
54 log("PASS: " + wiggleRoom + " garbage JS objects or fewer left uncollected after destroying a frame.\n");
57 testRunner.notifyDone();
59 setTimeout(continueTest, 10);