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
: [2, 5, 8]},
14 {content
: "גכ יגכ יגכ יגכ יגכ",
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
;
34 container
.style
.width
= width
+ 'px';
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
]);
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 = '';