Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / click-left-of-rtl-wrapping-text.html
blobf9449b3e2a7c0999f46245aa52ac1128618b42ac
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; &#1499;&#1499;&#1499;", expected: [3, 8, 11]},
14 {content: "&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;", width: "5ex",
15 expected: [3, 7, 11, 15, 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 x = 0;
40 var y = heightOfLine / 2;
41 var yIncrement = container.offsetHeight / test.expected.length;
42 var lines = ['st', 'nd', 'rd', 'th'];
44 if (!window.eventSender)
45 return;
47 for (var i = 0; i < test.expected.length; i++) {
48 eventSender.mouseMoveTo(container.offsetLeft + x, container.offsetTop + y);
49 eventSender.mouseDown();
50 eventSender.leapForward(100);
51 eventSender.mouseUp();
52 eventSender.leapForward(1000);
54 var line = (i + 1) + lines[Math.min(i, lines.length - 1)];
55 var action = 'clicking on the left of the ' + line + ' line of ' + test.content;
57 if (!window.getSelection().isCollapsed)
58 return failed(action + ' put selection instead of caret');
60 var range = window.getSelection().getRangeAt(0);
61 if (range.startContainer != container.firstChild)
62 return failed(action + ' put the caret at a wrong container');
64 action += ' put the caret at ' + range.startOffset;
65 if (range.startOffset != test.expected[i])
66 return failed(action + ' but expected at ' + test.expected[i]);
67 y += yIncrement;
68 passed(action);
73 var console = document.getElementById('console');
75 var container = document.createElement('div');
76 container.contentEditable = true;
77 container.setAttribute('dir', 'rtl');
78 document.body.appendChild(container);
80 if (!window.eventSender)
81 failed('Clicking tests require eventSender');
82 else {
83 for (var i = 0; i < tests.length; i++)
84 runTest(container, tests[i]);
85 container.innerHTML = '';
88 </script>
89 </body>
90 </html>