blob: 8c9677c8c4d6a2a5d7cd0206475013c5b7d84c9f [file] [log] [blame]
<script>
if (window.layoutTestController)
layoutTestController.dumpEditingCallbacks();
</script>
<script>
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
function assert(bool) {
if (!bool)
log("Failure");
else
log("Success");
}
</script>
<p>This tests the endpoints of a DOM Range object made from a selection around certain types elements. These endpoints shouldn't be at offsets inside nodes that aren't containers or text nodes.</p>
<div id="test">Hello <img src="../resources/abe.png"><object width="100"></object>world!<br>Hello World!</div>
<ul id="console"></ul>
<script>
var s = window.getSelection();
var e = document.getElementById("test");
var r;
if (window.layoutTestController)
window.layoutTestController.dumpAsText();
// The textnode
s.setBaseAndExtent(e, 0, e, 1);
r = s.getRangeAt(0);
assert(r.startContainer == e.childNodes[0]);
assert(r.startOffset == 0);
assert(r.endContainer == e.childNodes[0]);
assert(r.endOffset == r.endContainer.length);
// The image
s.setBaseAndExtent(e, 1, e, 2);
r = s.getRangeAt(0);
assert(r.startContainer == e);
assert(r.startOffset == 1);
assert(r.endContainer == e);
assert(r.endOffset == 2);
// The <object>
s.setBaseAndExtent(e, 2, e, 3);
r = s.getRangeAt(0);
assert(r.startContainer == e);
assert(r.startOffset == 2);
assert(r.endContainer == e);
assert(r.endOffset == 3);
// The <br>
s.setBaseAndExtent(e, 4, e, 5);
r = s.getRangeAt(0);
assert(r.startContainer == e);
assert(r.startOffset == 4);
assert(r.endContainer == e);
assert(r.endOffset == 5);
</script>