<html>
<head>
<script>
if (window.testRunner)
    testRunner.dumpAsText();

handler = function()
{
    this.removeEventListener("DOMNodeRemoved", handler, false);
    doc.adoptNode(this.parentElement);
}

showFailure = function(s)
{
    document.body.innerHTML = "FAILURE: " + s;
}

window.onload = function()
{
    element1 = document.createElement(undefined);
    element2 = document.createElement(undefined);
    element3 = document.createElement(undefined);
    parent   = document.createElement(undefined);
    dummy    = document.createElement(undefined);
    
    doc = document.implementation.createHTMLDocument();
    
    parent.appendChild(element1);
    element1.addEventListener("DOMNodeRemoved", handler, false);
    try {
        document.body.appendChild(element1);
    } catch (e) { }
    if (element1.ownerDocument != element1.parentElement.ownerDocument)
        return showFailure("appendChild");
    
    document.adoptNode(parent);
    parent.appendChild(element2);
    try {
        doc.body.insertBefore(element2, dummy);
    } catch (e) { }
    if (element2.ownerDocument != element2.parentElement.ownerDocument)
        return showFailure("insertBefore");
    
    parent.appendChild(element3);
    try {
        doc.body.replaceChild(element3, dummy);
    } catch (e) { }
    if (element3.ownerDocument != element3.parentElement.ownerDocument)
        return showFailure("replaceChild");
}
</script>
</head>
<body>SUCCESS</body>
</html>
