blob: 16bd18442c5945f2e9018266c71e5146a220b81c [file] [log] [blame]
<html>
<body>
<div id="test"><span id="span1">foo<span id="span2">bar</span></span><span id="span3">baz</span></div>
<div id="console"></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");
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
document.getElementById("console").appendChild(li);
}
function shouldBe(expr, expected) {
var actual = eval(expr);
if (actual != expected)
log("Failure: " + expr + " should be " + expected + ", was " + actual + ".");
else
log("Success: " + expr + " is " + expected + ".");
}
if (window.layoutTestController)
layoutTestController.dumpAsText();
var r = document.createRange();
// delete a collapsed selection
r.setStart(span2.firstChild, 1);
r.setEnd(span2.firstChild, 1);
s.addRange(r);
s.deleteFromDocument()
shouldBe('span1.textContent', 'fooar');
try {
s.deleteFromDocument()
shouldBe('span1.textContent', 'foar');
} catch (ex) {
log(ex);
}
// try to delete a collapsed selection at the start
r.setStart(span1.firstChild, 0);
r.setEnd(span1.firstChild, 0);
s.removeAllRanges();
s.addRange(r);
try {
s.deleteFromDocument()
shouldBe('span1.textContent', 'foar');
} catch (ex) {
log(ex);
}
// delete whole contents
r.setStart(span2.firstChild, 0);
r.setEnd(span2.firstChild, 2);
s.removeAllRanges();
s.addRange(r);
s.deleteFromDocument()
shouldBe('span1.firstChild.nextSibling.id', 'span2');
shouldBe('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()
shouldBe('test.textContent', 'fz');
</script>
</body>
</html>