4 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8">
5 <script src=
"../../resources/js-test.js"></script>
6 <style type=
"text/css">
7 #tests { font-size: 2.5em; padding: 0px; margin: 0px; }
8 dt
{ width: 15ex; padding: 0px 10px; margin: 0px; }
9 dd
{ font-size: 0.6em; margin: 0px; padding: 0px 10px; }
10 .target { background-color: #bbeeff; }
14 <p>This test ensures WebKit lets user place caret around bidirectional text properly.
</p>
15 <div>Current offset:
<span id=
"log"></span></div>
17 <dt contenteditable
>abcאבג
</dt>
18 <dd>0 1 2 3 5 4 6</dd>
20 <dt contenteditable
>נת
12</dt>
21 <dd>2 3 4 1 4 (There is a bug. Clicking on the left of
12 should result in offset
0.)
</dd>
23 <dt contenteditable
>לש
<b>נ
</b>ת
</dt>
26 <dt contenteditable
>aקל
12יםd
</dt>
27 <dd>0 1 6 3 4 5 2 7 8</dd>
29 <dt><span dir=
"rtl">12<b>קל
43</b></span>ab
</dt>
30 <dd>4 5 6 3 0 1 2 7 8</dd>
32 <dt dir=
"rtl"><span dir=
"ltr">abcלשנ
</span></dt>
33 <dd>6 1 2 6 5 4 3</dd>
36 <div id=
"console"></div>
39 // This function converts (node, offset) pair to a global offset (like TextIterator index).
40 function globalOffsetFromNodeOffsetPair(node
, offsetInNode
) {
41 var tests
= document
.getElementById('tests');
42 var testContainer
= node
;
43 while (testContainer
&& testContainer
.parentNode
!= tests
)
44 testContainer
= testContainer
.parentNode
;
46 return 'a node outside of tests';
48 return testContainer
.textContent
.indexOf(node
.textContent
) + offsetInNode
;
51 function runTest(target
, expectations
) {
52 var y
= target
.offsetTop
+ target
.offsetHeight
/ 2;
54 var previousOffset
= -1;
56 for (var x
= 5; x
<= target
.offsetWidth
- 5; x
++) {
57 // Reset the click count
58 eventSender
.mouseMoveTo(1, 1);
59 eventSender
.mouseDown();
60 eventSender
.mouseUp();
62 eventSender
.mouseMoveTo(target
.offsetLeft
+ x
, y
);
63 eventSender
.mouseDown();
64 eventSender
.mouseUp();
66 var currentOffset
= globalOffsetFromNodeOffsetPair(getSelection().baseNode
, getSelection().baseOffset
);
67 if (!getSelection().isCollapsed
)
68 testFailed('selection was not collapsed');
69 else if (previousOffset
== currentOffset
)
72 previousOffset
= currentOffset
;
74 if (expectations
[j
] != currentOffset
)
75 testFailed('caret was at ' + currentOffset
+ ' but expected to be at ' + expectations
[j
]);
77 testPassed('caret is at ' + currentOffset
);
83 if (j
< expectations
.length
)
84 testFailed('caret never reached offset' + expectations
[j
]);
87 if (window
.testRunner
) {
88 testRunner
.dumpAsText();
90 var tests
= document
.getElementById('tests').getElementsByTagName('dt');
91 var testExpectations
= document
.getElementById('tests').getElementsByTagName('dd');
92 for (var i
= 0; i
< tests
.length
; i
++) {
93 debug('Test "' + tests
[i
].textContent
+ '":');
94 runTest(tests
[i
], testExpectations
[i
].textContent
.replace(/\s*\(.+\)\s*/, '').split(/\s+/).map(function (x
) {return parseInt(x
);}));
98 debug('This test requires eventSender');
99 document
.onselectionchange = function () {
100 var selection
= window
.getSelection();
101 document
.getElementById('log').textContent
= globalOffsetFromNodeOffsetPair(selection
.baseNode
, selection
.baseOffset
) + ', ' +
102 globalOffsetFromNodeOffsetPair(selection
.extentNode
, selection
.extentOffset
);