Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / extend-to-line-boundary.html
blob6df731c22a58636211a216de9a946967d70e107f
1 <!DOCTYPE html>
2 <body>
3 <pre id="console"></pre>
4 <script>
5 function log(s) {
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.
18 var lines = text;
19 for (var i = 1; i < numLines; i++)
20 lines += " " + text;
22 var div = document.createElement("div");
23 div.setAttribute("style", "width: " + widthPx + "px");
24 div.contentEditable = true;
25 div.innerHTML = lines;
27 return div;
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;
39 return e.innerHTML;
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 + " ")
48 log("PASS for LTR");
49 else
50 log("FAIL for LTR, selection is '" + getSelection() + "' but should be '" + ltrText + " '");
52 rtlText = unescapeRtl("&#x05E9;&#x05D5;&#x05BC;&#x05E8;&#x05D4; " +
53 "&#x05E9;&#x05D5;&#x05BC;&#x05E8;&#x05D4; " +
54 "&#x05E9;&#x05D5;&#x05BC;&#x05E8;&#x05D4;");
55 rtlTextContainer = createEditableMultilineDiv(rtlText, 3);
56 rtlTextContainer.setAttribute("dir", "rtl");
57 document.body.appendChild(rtlTextContainer);
58 selectSecondLine(rtlTextContainer);
60 if (getSelection().toString() === rtlText + " ")
61 log("PASS for RTL");
62 else
63 log("FAIL for RTL, selection is '" + getSelection() + "' but should be '" + rtlText + " '");
65 log("");
67 if (window.testRunner)
68 testRunner.dumpAsText();
69 </script>
70 </body>