blob: c21a915f0f3cb9dfa438d51eb5f7b2d12de9e63f [file] [log] [blame]
<svg id="svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" onload="load()">
<defs>
<rect id="rect" width="100" height="100" />
</defs>
<g id="g"/>
<text x="50" y="50" id="log"/>
<script id="script">
<![CDATA[
var g = document.getElementById("g");
function log(message) {
var logDiv = document.getElementById('log');
logDiv.appendChild(document.createTextNode(message));
}
function createAnimatedRectInstance() {
var use = document.createElementNS("http://www.w3.org/2000/svg", "use");
use.setAttributeNS("http://www.w3.org/1999/xlink", "href", "#rect");
var anim = document.createElementNS("http://www.w3.org/2000/svg", "animate");
anim.setAttribute("attributeType", "XML");
anim.setAttribute("attributeName", "x");
anim.setAttribute("from", "100");
anim.setAttribute("to", "0");
anim.setAttribute("begin", "0s");
anim.setAttribute("dur", "10.0s");
anim.setAttribute("repeatCount", 1);
use.appendChild(anim);
return use;
}
function runTest() {
// Collect garbage before recording starting live node count, in case there are live elements from previous tests.
GCController.collect();
var originalLiveElements = window.internals.numberOfLiveNodes();
for (var i = 0; i < 1000; i++)
g.appendChild(createAnimatedRectInstance());
while (g.hasChildNodes())
g.removeChild(g.lastChild);
GCController.collect();
var liveDelta = window.internals.numberOfLiveNodes() - originalLiveElements;
// The goal of this test is to verify allocating lots and lots of objects will not
// grow the allocated memory a lot once they are removed.
if (liveDelta <= 5)
log("PASS");
else
log("FAIL: " + liveDelta + " extra live node(s)");
testRunner.notifyDone();
}
function load() {
if (window.testRunner && window.GCController && window.internals) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
} else {
log("This test only works when run with the testRunner, GCController, and internals available.");
return;
}
setTimeout(runTest, 0);
}
]]>
</script>
</svg>