blob: 113661fd3d9445abc5f9883b21e6c42aa2c5db86 [file] [log] [blame]
<div class="buckets"
><p id="bucket1" class="z"></p
><p id="bucket2" class="z"></p
><p id="bucket3" class="z"></p
><p id="bucket4" class="z"></p
><p id="bucket5" class="z"></p
><p id="bucket6" class="z"></p>
</div>
<p>There should be no assertion failures below, but the word DONE should show up.</p>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
}
</script>
<script>
function fail(message) {
document.write(message + "<br>");
}
function assert(condition, message) {
if (!condition)
fail(message);
}
function assertEquals(expression, value, message) {
if (expression != value) {
expression = (""+expression).replace(/[\r\n]+/g, "\\n");
value = (""+value).replace(/\r?\n/g, "\\n");
fail("expected: " + value + ", got: " + expression + " - " + message);
}
}
var d;
// e1 - an element that's in a document
d = document.implementation.createDocument(null, null, null);
var e1 = d.createElement('test1');
d.appendChild(d.createElement('root'));
d.documentElement.appendChild(e1);
assert(e1.parentNode, "e1 - parent element doesn't exist");
assert(e1.parentNode.ownerDocument, "e1 - document doesn't exist");
// e2 - an element that's not in a document
d = document.implementation.createDocument(null, null, null);
var e2 = d.createElement('test2');
d.createElement('root').appendChild(e2);
assert(e2.parentNode, "e2 - parent element doesn't exist");
assert(e2.parentNode.ownerDocument, "e2 - document doesn't exist");
// now try to decouple them
d = null;
kungFuDeathGrip = [e1, e2];
assert(e1.parentNode, "e1 - parent element doesn't exist after dropping reference to document");
assert(e1.parentNode.ownerDocument, "e1 - document doesn't exist after dropping reference to document");
assert(e2.parentNode, "e2 - parent element doesn't exist after dropping reference to document");
assert(e2.parentNode.ownerDocument, "e2 - document doesn't exist after dropping reference to document");
var loops = ((new Date().valueOf() - 1.1e12) / 32e9) * 0x500; // increases linearly over time
for (var i = 0; i < loops; i += 1) {
// we want to force a GC here, so we use up lots of memory
// we take the opportunity to sneak in a perf test to make DOM and JS stuff faster...
d = new Date();
d = new (function (x) { return { toString: function () { return x.toString() } } })(d.valueOf());
d = document.createTextNode("iteration " + i + " at " + d);
document.createElement('a').appendChild(d);
d = d.parentNode;
document.body.insertBefore(d, document.getElementById('bucket1').parentNode);
assert(document.getElementById('bucket2').nextSibling.parentNode.previousSibling.firstChild.data.match(/AT\W/i), "iteration " + i + " failed");
d.setAttribute('class', d.textContent);
document.body.removeChild(d);
}
assert(e1.parentNode, "e1 - parent element doesn't exist after looping");
assert(e1.parentNode.ownerDocument, "e1 - document doesn't exist after looping");
assertEquals(e1.parentNode.ownerDocument.nodeType, 9, "e1 - document node type has wrong node type");
assert(e2.parentNode, "e2 - parent element doesn't exist after looping");
assert(e2.parentNode.ownerDocument, "e2 - document doesn't exist after looping");
assertEquals(e2.parentNode.ownerDocument.nodeType, 9, "e2 - document node type has wrong node type");
</script>
<p>DONE</p>