OLD | NEW |
1 <html> | 1 <!DOCTYPE html> |
2 <head> | 2 <html> |
| 3 <body> |
| 4 <div id="container"> |
| 5 <p id="description"></p> |
| 6 <p>To test manually, place the cursor at the end of 'word' and delete it complet
ely character by character. Do ctrl+z. On Mac, 'word' should be selected. On oth
er platforms 'word' should not be selected and the cursor should be placed at th
e end of 'word'.</p> |
| 7 <div id="test" style="border: 2px solid red;" contenteditable>This word should b
e selected.</div> |
| 8 </div> |
| 9 <div id="console"></div> |
| 10 <script src="../../fast/js/resources/js-test-pre.js"></script> |
| 11 <script> |
| 12 description('Verifies the selection behavior on undoing a text deletion.'); |
| 13 var selectionNode = document.getElementById('test').firstChild; |
| 14 var selectionOffset = selectionNode.data.indexOf('d') + 1; |
| 15 var endOffset = selectionNode.data.indexOf(' ') + 1; |
| 16 var selection = window.getSelection(); |
3 | 17 |
4 <style> | 18 function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndN
ode, expectedEndOffset, selectedText) { |
5 .editing { | 19 debug(platform); |
6 border: 2px solid red; | 20 internals.settings.setEditingBehavior(platform); |
7 padding: 12px; | |
8 font-size: 24px; | |
9 } | |
10 </style> | |
11 <script src="../editing.js" language="JavaScript" type="text/JavaScript" ></scri
pt> | |
12 | 21 |
13 <script> | 22 selection.collapse(selectionNode, selectionOffset); |
| 23 for (var i = 0; i < 4; i++) |
| 24 document.execCommand('delete'); |
| 25 document.execCommand('undo'); |
14 | 26 |
15 function editingTest() { | 27 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data); |
16 moveSelectionForwardByWordCommand(); | 28 shouldBe('selection.anchorOffset', expectedStartOffset + ''); |
17 moveSelectionForwardByWordCommand(); | 29 shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data); |
18 deleteCommand(); | 30 shouldBe('selection.focusOffset', expectedEndOffset + ''); |
19 deleteCommand(); | 31 shouldBeEqualToString('selection.toString()', selectedText); |
20 deleteCommand(); | |
21 deleteCommand(); | |
22 undoCommand(); | |
23 } | 32 } |
24 | 33 |
| 34 if (window.internals) { |
| 35 undoTest('mac', selectionNode, selectionOffset, selectionNode, endOffset, 'w
ord'); |
| 36 undoTest('win', selectionNode, selectionOffset, selectionNode, endOffset, 'w
ord'); |
| 37 undoTest('unix', selectionNode, selectionOffset, selectionNode, endOffset, '
word'); |
| 38 undoTest('android', selectionNode, selectionOffset, selectionNode, endOffset
, 'word'); |
| 39 } |
| 40 if (window.testRunner) |
| 41 document.getElementById('container').outerHTML = ''; |
25 </script> | 42 </script> |
26 | 43 <script src="../../fast/js/resources/js-test-post.js"></script> |
27 </head> | |
28 <body> | |
29 <div contenteditable id="root" class="editing"> | |
30 <span id="test">This word should be selected, since the test deleted it a charac
ter at a time and then did an undo.</span> | |
31 </div> | |
32 | |
33 <script> | |
34 if (window.internals) | |
35 internals.settings.setEditingBehavior("mac"); | |
36 runEditingTest(); | |
37 </script> | |
38 | |
39 </body> | 44 </body> |
40 </html> | 45 </html> |
OLD | NEW |