Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / selection-direction.html
blob1fa18d95c396726f4599e477f9ee4e9d9871e981
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
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>
11 <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)
22 testPassed(action);
23 else
24 testFailed(action + ', but expected "' + expectedDirection + '"');
27 function testCache(expectedDirection, element) {
28 dummy.focus();
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);
38 element.focus();
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);
46 element.focus();
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);
63 element.focus();
64 element.selectionDirection = 'backward';
65 assertDirection('backward', element, 'focusing and setting selection by selectionDirection = "backward"');
66 testCache('backward', element);
68 element.focus();
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);
74 element.focus();
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) {
83 if (window.internals)
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);
88 debug('');
92 if (window.internals) {
93 runTestFor('Mac');
94 runTestFor('Win');
95 runTestFor('Unix');
96 } else
97 runTestFor(navigator.platform.indexOf('Mac') >= 0 ? 'Mac' : 'Win');
99 tests.style.display = 'none';
100 dummy.parentNode.style.display = 'none';
102 </script>
103 </body>
104 </html>