1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8">
5 <script src=
"../../resources/js-test.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
11 description("Test to make sure left and right arrows keys behave correctly in RTL content.")
13 var testContainer
= document
.createElement("div");
14 testContainer
.contentEditable
= true;
15 testContainer
.style
.padding
= "2px";
16 testContainer
.dir
= "rtl";
17 testContainer
.innerText
= 'מקור השם עברית';
18 document
.body
.insertBefore(testContainer
, document
.body
.firstChild
);
20 var selection
= window
.getSelection();
22 function dragSelection()
24 var text
= testContainer
.firstChild
;
25 selection
.setBaseAndExtent(text
, 0, text
, 0);
26 var middleY
= testContainer
.offsetTop
+ (testContainer
.offsetHeight
/ 2);
27 eventSender
.dragMode
= false;
28 eventSender
.mouseMoveTo(testContainer
.offsetLeft
, middleY
);
29 eventSender
.leapForward(200);
30 eventSender
.mouseDown();
31 eventSender
.leapForward(200);
32 for (var i
= 0; i
<= 10; i
++) {
33 eventSender
.mouseMoveTo(testContainer
.offsetLeft
+ (testContainer
.offsetWidth
* (i
/10)) - 2, middleY
);
34 eventSender
.leapForward(200);
36 eventSender
.mouseUp();
37 eventSender
.leapForward(1000);
40 function setSelection()
42 var text
= testContainer
.firstChild
;
44 selection
.setBaseAndExtent(text
, 5, text
, 8);
47 function testSelectionChange(setupFunction
, mod
, dir
, startDelta
, endDelta
, testName
)
50 var range
= window
.getSelection().getRangeAt(0);
51 var initialStart
= range
.startOffset
;
52 var initialEnd
= range
.endOffset
;
54 selection
.modify(mod
, dir
, "character");
55 range
= window
.getSelection().getRangeAt(0);
56 var start
= range
.startOffset
;
57 var end
= range
.endOffset
;
59 if (initialStart
+ startDelta
!= start
)
60 testFailed(testName
+ ": Selection start is " + start
+ " but should be " + (startDelta
+ initialStart
));
61 else if (initialEnd
+ endDelta
!= end
)
62 testFailed(testName
+ ": Selection end is " + end
+ " but should be " + (endDelta
+ initialEnd
));
69 testSelectionChange(setSelection
, "move", "right", 0, -3, "Move selection right");
70 testSelectionChange(setSelection
, "move", "left", 3, 0, "Move selection left");
71 if (window
.testRunner
&& window
.internals
) {
72 testRunner
.dumpAsText();
73 internals
.settings
.setEditingBehavior("mac");
74 testSelectionChange(dragSelection
, "extend", "right", 0, 0, "Extend dragged selection right (Mac)");
75 testSelectionChange(dragSelection
, "extend", "left", 0, 0, "Extend dragged selection left (Mac)");
76 internals
.settings
.setEditingBehavior("win");
77 testSelectionChange(dragSelection
, "extend", "right", 0, 0, "Extend dragged selection right (Win)");
78 testSelectionChange(dragSelection
, "extend", "left", 1, 0, "Extend dragged selection left (Win)");
79 internals
.settings
.setEditingBehavior("unix");
80 testSelectionChange(dragSelection
, "extend", "right", 0, 0, "Extend dragged selection right (Unix)");
81 testSelectionChange(dragSelection
, "extend", "left", 1, 0, "Extend dragged selection left (Unix)");
82 internals
.settings
.setEditingBehavior("android");
83 testSelectionChange(dragSelection
, "extend", "right", 0, 0, "Extend dragged selection right (Android)");
84 testSelectionChange(dragSelection
, "extend", "left", 1, 0, "Extend dragged selection left (Android)");
89 document
.body
.removeChild(testContainer
);