<!DOCTYPE html>
<html>
<body>
<div id="container">
<div id="sample">foobar</div>baz
</div>
<script>
if (window.testRunner)
    testRunner.dumpAsText();

var sample = document.getElementById('sample');

function removingHandler()
{
    document.removeEventListener('DOMNodeRemovedFromDocument', removingHandler, true);
    var range = document.createRange();
    range.setStart(sample.nextSibling, 1);
    range.insertNode(document.createTextNode('FOO'));
}

document.addEventListener('DOMNodeRemovedFromDocument', removingHandler, true);

var range = document.createRange();
range.setStart(sample, 0);
range.setEnd(sample.nextSibling, 3);
range.deleteContents();

document.body.innerHTML = 'This tests inserting a text node while calling deleteContents. WebKit should not hit an assertion.<br><br>PASS.';
</script>
</body>
</html>
