| OLD | NEW |
| (Empty) |
| 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> | |
| 7 | |
| 8 if (window.testRunner) | |
| 9 testRunner.dumpAsText(); | |
| 10 | |
| 11 var tests = [ | |
| 12 {content: "ך לכ", expected: [2, 4]}, | |
| 13 {content: "ככ ככככ כככ
", expected: [3, 8, 11]}, | |
| 14 {content: "גכ יגכ יגכ י
;גכ יגכ", width: "5ex", | |
| 15 expected: [3, 7, 11, 15, 18]}, | |
| 16 ]; | |
| 17 | |
| 18 function failed(message) { | |
| 19 console.innerHTML += 'FAIL: ' + message + '\n'; | |
| 20 } | |
| 21 | |
| 22 function passed(message) { | |
| 23 console.innerHTML += 'PASS: ' + message + '\n'; | |
| 24 } | |
| 25 | |
| 26 function runTest(container, test) { | |
| 27 container.style.width = '100%'; | |
| 28 container.innerHTML = test.content; | |
| 29 | |
| 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'; | |
| 38 | |
| 39 var x = 0; | |
| 40 var y = heightOfLine / 2; | |
| 41 var yIncrement = container.offsetHeight / test.expected.length; | |
| 42 var lines = ['st', 'nd', 'rd', 'th']; | |
| 43 | |
| 44 if (!window.eventSender) | |
| 45 return; | |
| 46 | |
| 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); | |
| 53 | |
| 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; | |
| 56 | |
| 57 if (!window.getSelection().isCollapsed) | |
| 58 return failed(action + ' put selection instead of caret'); | |
| 59 | |
| 60 var range = window.getSelection().getRangeAt(0); | |
| 61 if (range.startContainer != container.firstChild) | |
| 62 return failed(action + ' put the caret at a wrong container'); | |
| 63 | |
| 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); | |
| 69 } | |
| 70 | |
| 71 } | |
| 72 | |
| 73 var console = document.getElementById('console'); | |
| 74 | |
| 75 var container = document.createElement('div'); | |
| 76 container.contentEditable = true; | |
| 77 container.setAttribute('dir', 'rtl'); | |
| 78 document.body.appendChild(container); | |
| 79 | |
| 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 = ''; | |
| 86 } | |
| 87 | |
| 88 </script> | |
| 89 </body> | |
| 90 </html> | |
| OLD | NEW |