3 <pre id=
"console"></pre>
6 document
.getElementById("console").innerHTML
+= s
+ "\n";
9 function createEditableMultilineDiv(text
, numLines
) {
10 // Put text in a span so that the width can be measured.
11 var span
= document
.createElement("span");
12 span
.innerHTML
= text
;
13 document
.body
.appendChild(span
);
14 var widthPx
= span
.offsetWidth
;
15 document
.body
.removeChild(span
);
17 // Make div with those dimensions so that the text wraps predictably regardless of platform.
19 for (var i
= 1; i
< numLines
; i
++)
22 var div
= document
.createElement("div");
23 div
.setAttribute("style", "width: " + widthPx
+ "px");
24 div
.contentEditable
= true;
25 div
.innerHTML
= lines
;
30 function selectSecondLine(element
) {
31 getSelection().collapse(element
.childNodes
[0], 0);
32 getSelection().modify("move", "forward", "line");
33 getSelection().modify("extend", "forward", "lineboundary");
36 function unescapeRtl(rtlText
) {
37 var e
= document
.createElement("span");
38 e
.innerHTML
= rtlText
;
42 ltrText
= "the quick brown fox jumps";
43 ltrTextContainer
= createEditableMultilineDiv(ltrText
, 3);
44 document
.body
.appendChild(ltrTextContainer
);
45 selectSecondLine(ltrTextContainer
);
47 if (getSelection().toString() === ltrText
+ " ")
50 log("FAIL for LTR, selection is '" + getSelection() + "' but should be '" + ltrText
+ " '");
52 rtlText
= unescapeRtl("שוּרה " +
53 "שוּרה " +
54 "שוּרה");
55 rtlTextContainer
= createEditableMultilineDiv(rtlText
, 3);
56 rtlTextContainer
.setAttribute("dir", "rtl");
57 document
.body
.appendChild(rtlTextContainer
);
58 selectSecondLine(rtlTextContainer
);
60 if (getSelection().toString() === rtlText
+ " ")
63 log("FAIL for RTL, selection is '" + getSelection() + "' but should be '" + rtlText
+ " '");
67 if (window
.testRunner
)
68 testRunner
.dumpAsText();