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> 3 <hr> 4 <pre id="log"></pre> 5 6 <!-- The test: --> 7 <iframe id="iframe" src="data:text/html,<script>;</script>" style="display:none"></iframe> 8 <script> 9 function log(s) 10 { 11 document.getElementById("log").appendChild(document.createTextNode(s)); 12 } 13 14 var wiggleRoom = 20; 15 16 window.onload = function main() 17 { 18 if (!window.layoutTestController || !window.GCController) { 19 log("FAIL: This test uses the layoutTestController and the GCController, so it can only run in DumpRenderTree.\n"); 20 return; 21 } 22 23 layoutTestController.dumpAsText(); 24 layoutTestController.waitUntilDone(); 25 26 // Start with no garbage, so GC doesn't run automatically during the test. 27 GCController.collect(); 28 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 = [ { }, { }, { }, { }, { }, { }, { }, { }, { }, { } ]; 32 garbage = null; 33 34 // Destroy a frame that has a JavaScript interpreter. 35 var iframe = document.getElementById("iframe"); 36 iframe.parentNode.removeChild(iframe); 37 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() 41 { 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; 47 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"); 53 } else { 54 log("PASS: " + wiggleRoom + " garbage JS objects or fewer left uncollected after destroying a frame.\n"); 55 } 56 57 layoutTestController.notifyDone(); 58 } 59 setTimeout(continueTest, 10); 60 } 61 </script> 62