2 <div contenteditable
dir=
"ltr">זחט יךכ לםמ זחט יךכ לםמ</div>
3 <div contenteditable
dir=
"ltr">this is some ltr text in an rtl container
</div>
4 <div contenteditable
dir=
"rtl">זחט יךכ לםמ זחט יךכ לםמ</div>
5 <div contenteditable
dir=
"rtl">this is some ltr text in an rtl container
</div>
6 <pre id=
"console"></pre>
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
));
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");
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();