| <!DOCTYPE html> |
| <pre id="log"></pre> |
| |
| <div id="ltrTextContainer" contenteditable>foo bar <span contenteditable=false>baz</span> qux quux</div> |
| <div id="rtlTextContainer" contenteditable dir="rtl">שוּרה שוּרה |
| <span contenteditable=false>שוּרה</span> |
| שוּרה שוּרה</div> |
| |
| <div id="ltrMultiTextContainer" contenteditable>foo bar <span contenteditable=false>baz baz baz</span> qux quux</div> |
| <div id="rtlMultiTextContainer" contenteditable dir="rtl">שוּרה שוּרה |
| <span contenteditable=false>שוּרה שוּרה שוּרה</span> |
| שוּרה שוּרה</div> |
| |
| <script> |
| function log(s) { |
| document.getElementById("log").appendChild(document.createTextNode(s + "\n")); |
| } |
| |
| function placeCursorBeforeFirstNoneditableChild(container) { |
| for (var i = 0; i < container.childNodes.length; i++) { |
| var node = container.childNodes[i]; |
| if (node.isContentEditable !== undefined && !node.isContentEditable) { |
| var previous = node.previousSibling; |
| getSelection().setPosition(previous, previous.textContent.length); |
| return node; |
| } |
| } |
| throw "Couldn't find noneditable child of " + container.textContent; |
| } |
| |
| function extendForwardByWord(container, bidiName) { |
| noneditableChild = placeCursorBeforeFirstNoneditableChild(container); |
| getSelection().modify("extend", "forward", "word"); |
| if (getSelection().toString() === noneditableChild.textContent) |
| log("PASS for " + bidiName); |
| else |
| log("FAIL for " + bidiName + ", selection is \"" + getSelection() + "\" but should be \"" + noneditableChild.textContent + "\""); |
| } |
| |
| if (window.internals) |
| internals.settings.setEditingBehavior("mac"); |
| extendForwardByWord(document.getElementById("ltrTextContainer"), "LTR"); |
| extendForwardByWord(document.getElementById("rtlTextContainer"), "RTL"); |
| extendForwardByWord(document.getElementById("ltrMultiTextContainer"), "LTR-multi"); |
| extendForwardByWord(document.getElementById("rtlMultiTextContainer"), "RTL-multi"); |
| |
| if (window.testRunner) |
| testRunner.dumpAsText(); |
| </script> |