Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / modify-up-on-rtl-wrapping-text.html
blob36a1a653a4174f798ce1ee2d5338f6515e640b7c
1 <!DOCTYPE html>
2 <html charset="utf-8">
3 <body>
4 <p>This tests clicking on the left of RTL text puts the caret at the end of the line.</p>
5 <pre id="console"></pre>
6 <script>
8 if (window.testRunner)
9 testRunner.dumpAsText();
11 var tests = [
12 {content: "&#1498; &#1500;&#1499;", expected: [2, 4]},
13 {content: "&#1499; &#1499;&#1499; &#1499;&#1499;&#1499;", expected: [2, 5, 8]},
14 {content: "&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;",
15 expected: [3, 6, 10, 14, 18]},
18 function failed(message) {
19 console.innerHTML += 'FAIL: ' + message + '\n';
22 function passed(message) {
23 console.innerHTML += 'PASS: ' + message + '\n';
26 function runTest(container, test) {
27 container.style.width = '100%';
28 container.innerHTML = test.content;
30 // Starting from 5px, slowly increase the width until each word fits in one line.
31 var heightOfLine = container.offsetHeight;
32 var width = 5;
33 do {
34 container.style.width = width + 'px';
35 width++;
36 } while (container.offsetHeight > heightOfLine * test.expected.length);
37 container.style.width = (width + 1) + 'px';
39 var lines = ['st', 'nd', 'rd', 'th'];
40 window.getSelection().collapse(container.lastChild, container.lastChild.length);
42 for (var i = 0; i < test.expected.length; i++) {
43 if (!window.getSelection().isCollapsed)
44 return failed('the selection was not collapsed');
46 var range = window.getSelection().getRangeAt(0);
47 if (range.startContainer != container.firstChild)
48 return failed('caret was at a wrong container');
50 var action = 'on ' + test.content + ', caret is at ' + range.startOffset;
51 if (i == 0) action += ' initially';
52 else if (i == 1) action += ' after moving upwards once';
53 else if (i == 2) action += ' after moving upwards twice';
54 else action += ' after moving upwards ' + i + ' times';
55 if (range.startOffset != test.expected[test.expected.length - i - 1])
56 return failed(action + ' but expected at ' + test.expected[i]);
57 passed(action);
58 window.getSelection().modify('move', 'backward', 'line')
62 var console = document.getElementById('console');
64 var container = document.createElement('div');
65 container.contentEditable = true;
66 container.setAttribute('dir', 'rtl');
67 document.body.appendChild(container);
69 for (var i = 0; i < tests.length; i++)
70 runTest(container, tests[i]);
71 //container.innerHTML = '';
73 </script>
74 </body>
75 </html>