Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / editing / selection / extend-to-line-boundary.html
1 <!DOCTYPE html>
2 <body>
3 <pre id="console"></pre>
4 <script>
5 function log(s) {
6     document.getElementById("console").innerHTML += s + "\n";
7 }
8
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);
16
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;
21
22     var div = document.createElement("div");
23     div.setAttribute("style", "width: " + widthPx + "px");
24     div.contentEditable = true;
25     div.innerHTML = lines;
26
27     return div;
28 }
29
30 function selectSecondLine(element) {
31     getSelection().collapse(element.childNodes[0], 0);
32     getSelection().modify("move", "forward", "line");
33     getSelection().modify("extend", "forward", "lineboundary");
34 }
35
36 function unescapeRtl(rtlText) {
37     var e = document.createElement("span");
38     e.innerHTML = rtlText;
39     return e.innerHTML;
40 }
41
42 ltrText = "the quick brown fox jumps";
43 ltrTextContainer = createEditableMultilineDiv(ltrText, 3);
44 document.body.appendChild(ltrTextContainer);
45 selectSecondLine(ltrTextContainer);
46
47 if (getSelection().toString() === ltrText + " ")
48     log("PASS for LTR");
49 else
50     log("FAIL for LTR, selection is '" + getSelection() + "' but should be '" + ltrText + " '");
51
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);
59
60 if (getSelection().toString() === rtlText + " ")
61     log("PASS for RTL");
62 else
63     log("FAIL for RTL, selection is '" + getSelection() + "' but should be '" + rtlText + " '");
64
65 log("");
66
67 if (window.testRunner)
68     testRunner.dumpAsText();
69 </script>
70 </body>