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>
9 testRunner
.dumpAsText();
12 {content
: "ך לכ", expected
: [2, 4]},
13 {content
: "ככ ככככ כככ", expected
: [3, 8, 11]},
14 {content
: "גכ יגכ יגכ יגכ יגכ", 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
;
34 container
.style
.width
= width
+ 'px';
36 } while (container
.offsetHeight
> heightOfLine
* test
.expected
.length
);
37 container
.style
.width
= (width
+ 1) + 'px';
40 var y
= heightOfLine
/ 2;
41 var yIncrement
= container
.offsetHeight
/ test
.expected
.length
;
42 var lines
= ['st', 'nd', 'rd', 'th'];
44 if (!window
.eventSender
)
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
]);
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');
83 for (var i
= 0; i
< tests
.length
; i
++)
84 runTest(container
, tests
[i
]);
85 container
.innerHTML
= '';