<p>Test some cases of Range.deleteContents() behavior (namely, examples from DOM Range spec).</p>
<pre id="console"></pre>

<div style="visibility:hidden">
<FOO>AB<MOO>CD</MOO>CD</FOO>
<FOO>A<MOO>BC</MOO>DE</FOO>
<FOO>XY<BAR>ZW</BAR>Q</FOO>
<FOO><BAR1>AB</BAR1><BAR2></BAR2><BAR3>CD</BAR3></FOO>
</div>
<script>
if (window.testRunner)
    testRunner.dumpAsText();

function log(message)
{
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
}

// Simple recursive "give me a string to represent this tree" function
function treeAsString(node) {
    var string = node.nodeName;
    if (string[0] != "#")
        string = "<" + string + ">";
    if (string == "#text")
        string = node.textContent;
    if (node.childNodes.length) {
        string += " [";
    }
    for (var x = 0; x < node.childNodes.length; x++) {
        if (x != 0) {
            string += ", ";
        }
        string += treeAsString(node.childNodes[x]);
    }

    if (node.childNodes.length) {
        string += "]";
    }
    return string;
}

var range = document.createRange();

var foo = document.getElementsByTagName("FOO")[0];
range.setStart(foo.firstChild, 1);
range.setEnd(foo, 2);
range.deleteContents();
log(treeAsString(foo) + ". Final range (" + range.startContainer.nodeName + ", " + range.startOffset + ") - (" + range.endContainer.nodeName + ", " + range.endOffset + ")");

var foo = document.getElementsByTagName("FOO")[1];
range.setStart(foo.firstChild.nextSibling.firstChild, 1);
range.setEnd(foo.lastChild, 1);
range.deleteContents();
log(treeAsString(foo) + ". Final range (" + range.startContainer.nodeName + ", " + range.startOffset + ") - (" + range.endContainer.nodeName + ", " + range.endOffset + ")");

var foo = document.getElementsByTagName("FOO")[2];
range.setStart(foo.firstChild, 1);
range.setEnd(foo.firstChild.nextSibling.firstChild, 1);
range.deleteContents();
log(treeAsString(foo) + ". Final range (" + range.startContainer.nodeName + ", " + range.startOffset + ") - (" + range.endContainer.nodeName + ", " + range.endOffset + ")");

var foo = document.getElementsByTagName("FOO")[3];
range.setStart(foo.firstChild.firstChild, 1);
range.setEnd(foo.lastChild.firstChild, 1);
range.deleteContents();
log(treeAsString(foo) + ". Final range (" + range.startContainer.nodeName + ", " + range.startOffset + ") - (" + range.endContainer.nodeName + ", " + range.endOffset + ")");

</script>
