OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <style type="text/css"> | 4 <style type="text/css"> |
5 | 5 |
6 #test:first-letter { | 6 #test:first-letter { |
7 color: red; | 7 color: red; |
8 } | 8 } |
9 | 9 |
10 </style> | 10 </style> |
11 </head> | 11 </head> |
12 <body> | 12 <body> |
13 <p>This tests moving caret around a word with a first-letter rule. WebKit should
not crash. | 13 <p>This tests moving caret around a word with a first-letter rule. WebKit should
not crash. |
14 This test also demonstrates a bug that word position is incorrectly reported.</p
> | 14 This test also demonstrates a bug that word position is incorrectly reported.</p
> |
15 <div id="test" contenteditable> hello world'</div> | 15 <div id="test" contenteditable> hello world'</div> |
16 <pre id="console"></pre> | 16 <pre id="console"></pre> |
17 <script> | 17 <script> |
18 | 18 |
19 if (window.layoutTestController) | 19 if (window.layoutTestController) |
20 layoutTestController.dumpAsText(); | 20 layoutTestController.dumpAsText(); |
21 | 21 |
22 function runTest(actor, expectedOffset) { | 22 function runTest(actor, expectedOffset) { |
23 var action = actor() + ' put caret at offset '; | 23 window.getSelection().setPosition(test.firstChild, 4); |
| 24 var action = actor() + ' from offset ' + 4 + ' put caret at offset '; |
24 var startOffset = window.getSelection().getRangeAt(0).startOffset; | 25 var startOffset = window.getSelection().getRangeAt(0).startOffset; |
25 action += startOffset; | 26 action += startOffset; |
26 if (startOffset == expectedOffset) | 27 if (startOffset == expectedOffset) |
27 console.innerHTML += 'PASS: ' + action + '\n'; | 28 console.innerHTML += 'PASS: ' + action + '\n'; |
28 else | 29 else |
29 console.innerHTML += 'FAIL: ' + action + ' but expected ' + expectedOffs
et + '\n'; | 30 console.innerHTML += 'FAIL: ' + action + ' but expected ' + expectedOffs
et + '\n'; |
30 } | 31 } |
31 | 32 |
32 var test = document.getElementById('test'); | 33 var test = document.getElementById('test'); |
33 var console = document.getElementById('console'); | 34 var console = document.getElementById('console'); |
34 window.getSelection().setPosition(test, 0); | |
35 | 35 |
36 console.innerHTML += 'white-space: normal;\n'; | 36 console.innerHTML += 'white-space: normal;\n'; |
37 runTest(function () {window.getSelection().modify('move', 'forward', 'word'); re
turn 'moving forward by word';}, 6); | 37 runTest(function () {window.getSelection().modify('move', 'forward', 'word'); re
turn 'moving forward by word';}, 6); |
38 runTest(function () {window.getSelection().modify('move', 'backward', 'word'); r
eturn 'moving backward by word';}, 0); | 38 runTest(function () {window.getSelection().modify('move', 'backward', 'word'); r
eturn 'moving backward by word';}, 1); |
39 | 39 |
40 console.innerHTML += 'white-space: pre;\n'; | 40 console.innerHTML += 'white-space: pre;\n'; |
41 test.style.whiteSpace = 'pre'; | 41 test.style.whiteSpace = 'pre'; |
42 runTest(function () {window.getSelection().modify('move', 'forward', 'word'); re
turn 'moving forward by word';}, 6); | 42 runTest(function () {window.getSelection().modify('move', 'forward', 'word'); re
turn 'moving forward by word';}, 6); |
43 runTest(function () {window.getSelection().modify('move', 'backward', 'word'); r
eturn 'moving backward by word';}, 0); | 43 runTest(function () {window.getSelection().modify('move', 'backward', 'word'); r
eturn 'moving backward by word';}, 1); |
44 | 44 |
45 </script> | 45 </script> |
46 </body> | 46 </body> |
47 </html> | 47 </html> |
OLD | NEW |