4 <script src=
"../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div><input id=
"dummy"></div>
9 <div id=
"tests"><input value=
"hello"><textarea>hello
</textarea></div>
10 <div id=
"console"></div>
12 <script type=
"text/javascript">
13 description('Tests for selectionDirection');
15 var dummy
= document
.getElementById('dummy');
17 function assertDirection(expectedDirection
, element
, description
) {
18 var action
= 'selectionDirection was "' + element
.selectionDirection
19 + '" after ' + description
;
21 if (element
.selectionDirection
== expectedDirection
)
24 testFailed(action
+ ', but expected "' + expectedDirection
+ '"');
27 function testCache(expectedDirection
, element
) {
29 assertDirection(expectedDirection
, element
, 'focusing on another element');
31 element
.style
.display
= 'none';
32 assertDirection(expectedDirection
, element
, 'hiding the element');
33 element
.style
.display
= null;
36 function runTest(element
, platform
) {
37 debug(element
.localName
+ ' on ' + platform
);
40 var noneOnMacAndForwardOnOthers
= (platform
== 'Mac') ? 'none' : 'forward';
42 element
.setSelectionRange(1, 2);
43 assertDirection(noneOnMacAndForwardOnOthers
, element
, 'focusing and setting selection by setSelectionRange(1, 2)');
44 testCache(noneOnMacAndForwardOnOthers
, element
);
47 element
.setSelectionRange(1, 2, 'forward');
48 assertDirection('forward', element
, 'focusing and setting selection by setSelectionRange(1, 2, "forward")');
49 testCache('forward', element
);
51 element
.setSelectionRange(1, 2, 'backward');
52 assertDirection('backward', element
, 'setting selection by setSelectionRange(1, 2, "backward") without focus');
53 testCache('backward', element
);
55 element
.selectionDirection
= 'none';
56 assertDirection(noneOnMacAndForwardOnOthers
, element
, 'setting selection by selectionDirection = "none" without focus');
57 testCache(noneOnMacAndForwardOnOthers
, element
);
59 element
.selectionDirection
= 'forward';
60 assertDirection('forward', element
, 'focusing and setting selection by selectionDirection = "forward" without focus');
61 testCache('forward', element
);
64 element
.selectionDirection
= 'backward';
65 assertDirection('backward', element
, 'focusing and setting selection by selectionDirection = "backward"');
66 testCache('backward', element
);
69 element
.setSelectionRange(1, 1);
70 window
.getSelection().modify('extend', 'forward', 'character');
71 assertDirection('forward', element
, 'extending selection forward by character');
72 testCache('forward', element
);
75 element
.setSelectionRange(1, 1);
76 window
.getSelection().modify('extend', 'backward', 'character');
77 assertDirection('backward', element
, 'extending selection backward by character');
78 testCache('backward', element
);
82 function runTestFor(platform
) {
84 internals
.settings
.setEditingBehavior(platform
.toLowerCase());
85 var tests
= document
.getElementById('tests');
86 for (var i
= 0; i
< tests
.childNodes
.length
; i
++) {
87 runTest(tests
.childNodes
[i
], platform
);
92 if (window
.internals
) {
97 runTestFor(navigator
.platform
.indexOf('Mac') >= 0 ? 'Mac' : 'Win');
99 tests
.style
.display
= 'none';
100 dummy
.parentNode
.style
.display
= 'none';