chromium/third_party/blink/web_tests/editing/selection/deleteFromDocument.html

<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="test"><span id="span1">foo<span id="span2">bar</span></span><span id="span3">baz</span></div>
<script>
var s = window.getSelection();
var testDiv = document.getElementById("test");
var span1 = document.getElementById("span1");
var span2 = document.getElementById("span2");
var span3 = document.getElementById("span3");

var r = document.createRange();


// delete a collapsed selection
r.setStart(span2.firstChild, 1);
r.setEnd(span2.firstChild, 1);
s.addRange(r);

s.deleteFromDocument()
shouldBeEqualToString("span1.textContent", "foobar");

// try to delete a collapsed selection at the start
r.setStart(span1.firstChild, 0);
r.setEnd(span1.firstChild, 0);
s.removeAllRanges();
s.addRange(r);

s.deleteFromDocument()
shouldBeEqualToString("span1.textContent", "foobar");


// delete whole contents
r.setStart(span2.firstChild, 0);
r.setEnd(span2.firstChild, 3);
s.removeAllRanges();
s.addRange(r);

s.deleteFromDocument()
shouldBeEqualToString("span1.firstChild.nextSibling.id", "span2");
shouldBeEqualToString("span1.firstChild.nextSibling.firstChild.nodeValue", "");

// partially delete two nodes
r.setStart(span1.firstChild, 1);
r.setEnd(span3.firstChild, 2);
s.removeAllRanges();
s.addRange(r);

s.deleteFromDocument()
shouldBeEqualToString("test.textContent", "fz");

</script>
</body>
</html>