Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / extend-left-right-by-lineboundary.html
blobd528320c2ab1776522b1fa9f7853cf9e3a97f870
1 <!DOCTYPE html>
2 <div contenteditable dir="ltr">&#1494;&#1495;&#1496; &#1497;&#1498;&#1499; &#1500;&#1501;&#1502; &#1494;&#1495;&#1496; &#1497;&#1498;&#1499; &#1500;&#1501;&#1502;</div>
3 <div contenteditable dir="ltr">this is some ltr text in an rtl container</div>
4 <div contenteditable dir="rtl">&#1494;&#1495;&#1496; &#1497;&#1498;&#1499; &#1500;&#1501;&#1502; &#1494;&#1495;&#1496; &#1497;&#1498;&#1499; &#1500;&#1501;&#1502;</div>
5 <div contenteditable dir="rtl">this is some ltr text in an rtl container</div>
6 <pre id="console"></pre>
8 <script>
9 function log(text)
11 document.getElementById("console").appendChild(document.createTextNode(text + "\n"));
14 function showNode(node)
16 var tagName = node.tagName ? node.tagName : "TEXT";
17 return "<" + tagName + ">" + node.textContent + "</" + tagName + ">";
20 function assertSelectionEquals(expectedNode, expectedBaseOffset, expectedExtentOffset, message)
22 var selection = getSelection();
23 if (selection.baseNode !== expectedNode
24 || selection.baseOffset !== expectedBaseOffset
25 || selection.extentNode !== expectedNode
26 || selection.extentOffset !== expectedExtentOffset)
27 log("FAIL (" + message + "):\n" +
28 " expected base offset " + expectedBaseOffset + " in node " + showNode(expectedNode) + "\n" +
29 " and extent offset " + expectedExtentOffset + " in node " + showNode(expectedNode) + "\n" +
30 " ... but got base offset " + selection.baseOffset + " in node " + showNode(selection.baseNode) + "\n" +
31 " and extent offset " + selection.extentOffset + " in node " + showNode(selection.extentNode));
32 else
33 log("PASS (" + message + ")");
36 function runTestForContainer(container)
38 log("Testing " + container.dir + " container with contents \"" + container.textContent + "\":");
40 var textNode = container.childNodes[0];
41 var rightmostOffset = container.dir === "rtl" ? 0 : textNode.length;
42 var leftmostOffset = container.dir === "rtl" ? textNode.length : 0;
44 getSelection().collapse(textNode, leftmostOffset);
45 getSelection().modify("extend", "left", "lineboundary");
46 assertSelectionEquals(textNode, leftmostOffset, leftmostOffset, "extend left from left");
47 getSelection().modify("extend", "left", "lineboundary");
48 assertSelectionEquals(textNode, leftmostOffset, leftmostOffset, "extend left from left again");
50 getSelection().collapse(textNode, leftmostOffset);
51 getSelection().modify("extend", "right", "lineboundary");
52 assertSelectionEquals(textNode, leftmostOffset, rightmostOffset, "extend right from left");
53 getSelection().modify("extend", "right", "lineboundary");
54 assertSelectionEquals(textNode, leftmostOffset, rightmostOffset, "extend right from left again");
56 getSelection().collapse(textNode, rightmostOffset);
57 getSelection().modify("extend", "right", "lineboundary");
58 assertSelectionEquals(textNode, rightmostOffset, rightmostOffset, "extend right from right");
59 getSelection().modify("extend", "right", "lineboundary");
60 assertSelectionEquals(textNode, rightmostOffset, rightmostOffset, "extend right from right again");
62 getSelection().collapse(textNode, rightmostOffset);
63 getSelection().modify("extend", "left", "lineboundary");
64 assertSelectionEquals(textNode, rightmostOffset, leftmostOffset, "extend left from right");
65 getSelection().modify("extend", "left", "lineboundary");
66 assertSelectionEquals(textNode, rightmostOffset, leftmostOffset, "extend left from right again");
68 log("");
71 var testContainers = document.getElementsByTagName("div");
72 for (var i = 0; i < testContainers.length; i++)
73 runTestForContainer(testContainers[i]);
75 if (window.testRunner) {
76 while (testContainers.length > 0)
77 document.body.removeChild(testContainers[0]);
78 testRunner.dumpAsText();
80 </script>