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 before 'w' 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 befor
e 'w' of 'word'.</p> |
| 7 <div id="test" style="border: 2px solid red;" contenteditable>This wo<b>rd </b>s
hould be 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 sampleHTML = 'This wo<b>rd </b>should be selected.'; |
| 14 var selectionNode = document.getElementById('test').firstChild; // Text node 'Th
is wo' |
| 15 var selectionOffset = selectionNode.data.indexOf(' ') + 1; |
| 16 var endNode = document.getElementById('test').childNodes[1].firstChild; // Text
node 'rd ' |
| 17 var endOffset = endNode.length - 1; |
| 18 var selection = window.getSelection(); |
3 | 19 |
4 <style> | 20 function $(id) { return document.getElementById(id); } |
5 .editing { | |
6 border: 2px solid red; | |
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 function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndN
ode, expectedEndOffset, selectedText) { |
| 23 debug(platform); |
| 24 internals.settings.setEditingBehavior(platform); |
14 | 25 |
15 function editingTest() { | 26 selection.collapse(selectionNode, selectionOffset); |
16 moveSelectionForwardByWordCommand(); | 27 for (var i = 0; i < 4; i++) |
17 moveSelectionForwardByCharacterCommand(); | 28 document.execCommand('forwarddelete'); |
18 forwardDeleteCommand(); | 29 document.execCommand('undo'); |
19 forwardDeleteCommand(); | 30 |
20 forwardDeleteCommand(); | 31 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data); |
21 forwardDeleteCommand(); | 32 shouldBe('selection.anchorOffset', expectedStartOffset + ''); |
22 undoCommand(); | 33 shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data); |
| 34 shouldBe('selection.focusOffset', expectedEndOffset + ''); |
| 35 shouldBeEqualToString('selection.toString()', selectedText); |
| 36 shouldBeEqualToString('$("test").innerHTML', sampleHTML); |
23 } | 37 } |
24 | 38 |
| 39 if (window.internals) { |
| 40 undoTest('mac', selectionNode, selectionOffset, endNode, endOffset, 'word'); |
| 41 undoTest('win', selectionNode, selectionOffset, endNode, endOffset, 'word'); |
| 42 undoTest('unix', selectionNode, selectionOffset, endNode, endOffset, 'word')
; |
| 43 undoTest('android', selectionNode, selectionOffset, endNode, endOffset, 'wor
d'); |
| 44 } |
| 45 if (window.testRunner) |
| 46 document.getElementById('container').outerHTML = ''; |
25 </script> | 47 </script> |
26 | 48 <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 wo<b>rd </b>should be selected, since the test deleted it a
character 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> | 49 </body> |
40 </html> | 50 </html> |
OLD | NEW |