1<!DOCTYPE html>
2<pre id="log"></pre>
3
4<div id="ltrTextContainer" contenteditable>foo bar <span contenteditable=false>baz</span> qux quux</div>
5<div id="rtlTextContainer" contenteditable dir="rtl">שוּרה שוּרה
6<span contenteditable=false>שוּרה</span>
7שוּרה שוּרה</div>
8
9<script>
10function log(s) {
11 document.getElementById("log").appendChild(document.createTextNode(s + "\n"));
12}
13
14function placeCursorAfterFirstNoneditableChild(container) {
15 for (var i = 0; i < container.childNodes.length; i++) {
16 var node = container.childNodes[i];
17 if (node.isContentEditable !== undefined && !node.isContentEditable) {
18 getSelection().setPosition(node.nextSibling, 0);
19 return node;
20 }
21 }
22 throw "Couldn't find noneditable child of " + container.textContent;
23}
24
25ltrTextContainer = document.getElementById("ltrTextContainer");
26noneditableChild = placeCursorAfterFirstNoneditableChild(ltrTextContainer);
27getSelection().modify("extend", "backward", "word");
28
29if (getSelection().toString() === noneditableChild.textContent)
30 log("PASS for LTR");
31else
32 log("FAIL for LTR, selection is \"" + getSelection() + "\" but should be \"" + noneditableChild.textContent + "\"");
33
34rtlTextContainer = document.getElementById("rtlTextContainer");
35noneditableChild = placeCursorAfterFirstNoneditableChild(rtlTextContainer);
36getSelection().modify("extend", "backward", "word");
37
38if (getSelection().toString() === noneditableChild.textContent)
39 log("PASS for RTL");
40else
41 log("FAIL for RTL, selection is \"" + getSelection() + "\" but should be \"" + noneditableChild.textContent + "\"");
42
43log("");
44
45if (window.layoutTestController)
46 layoutTestController.dumpAsText();
47</script>