blob: 1e601c84e6b34247a4382248c89bbf0d7b9fe6a2 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<p>Verify that creation of a worker does not leak its creating document.</p>
<div id='console'></div>
<script src='resources/worker-util.js'></script>
<script>
function log(message)
{
document.getElementById("console").innerHTML += message + "<br>";
}
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
// Set this number as high as possible without introducing timeouts in debug builds.
// Reducing it does not require rebaselines.
var numIterations = 6;
var currentIteration = 0;
var iframe = null;
var numLiveAtStart = 0;
var numLiveAtEnd = 0;
window.onmessage = function(event) {
if (event.data == "done") {
runOneIteration();
}
};
function startTest()
{
gc();
if (window.internals && window.internals.numberOfLiveDocuments) {
numLiveAtStart = window.internals.numberOfLiveDocuments();
// Depending on which tests ran before this one in DumpRenderTree,
// their Document instances may not have been fully cleaned up yet.
// When this test is run in isolation, there should be only one
// live document at this point.
runOneIteration();
} else {
log("window.internals.numberOfLiveDocuments not available -- no point in running test");
finishTest();
}
}
function runOneIteration() {
if (currentIteration < numIterations) {
++currentIteration;
var createdIframe = false;
if (!iframe) {
iframe = document.createElement("iframe");
createdIframe = true;
}
iframe.setAttribute("src", "resources/worker-document-leak-iframe.html");
if (createdIframe)
document.body.appendChild(iframe);
} else {
finishTest();
}
}
function finishTest()
{
gc();
if (window.internals && window.internals.numberOfLiveDocuments) {
numLiveAtEnd = window.internals.numberOfLiveDocuments();
// Under no circumstances should the number of live documents
// at the end be more than 1 greater than the number at the
// beginning (because of the iframe).
if (numLiveAtEnd > numLiveAtStart + 1) {
log("FAIL: leaked documents during test run (started with " + numLiveAtStart + ", ended with " + numLiveAtEnd + ")");
} else {
log("PASS: did not leak documents during test run");
}
}
if (window.testRunner)
testRunner.notifyDone();
}
window.onload = startTest;
</script>
</body>
</html>