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 after 'o' in 'word' and delete it characte
r by character. Do ctrl+z. On Mac, 'word' should be selected. On other platforms
'word' should not be selected and the cursor should be placed after 'o' in 'wor
d'.</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.length; |
| 16 var endNode = document.getElementById('test').childNodes[1].firstChild; // Text
node 'rd ' |
| 17 var endOffset = endNode.length - 1; |
| 18 var startOffset = selectionNode.data.indexOf(' ')+1; |
| 19 var selection = window.getSelection(); |
3 | 20 |
4 <style> | 21 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 | 22 |
13 <script> | 23 function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndN
ode, expectedEndOffset, selectedText) { |
| 24 debug(platform); |
| 25 internals.settings.setEditingBehavior(platform); |
14 | 26 |
15 function editingTest() { | 27 selection.collapse(selectionNode, selectionOffset); |
16 moveSelectionForwardByWordCommand(); | 28 for (var i = 0; i < 2; i++) |
17 moveSelectionForwardByCharacterCommand(); | 29 document.execCommand('delete'); |
18 moveSelectionForwardByCharacterCommand(); | 30 for (var i = 0; i < 2; i++) |
19 moveSelectionForwardByCharacterCommand(); | 31 document.execCommand('forwarddelete'); |
20 deleteCommand(); | 32 document.execCommand('undo'); |
21 deleteCommand(); | 33 |
22 forwardDeleteCommand(); | 34 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data); |
23 forwardDeleteCommand(); | 35 shouldBe('selection.anchorOffset', expectedStartOffset + ''); |
24 undoCommand(); | 36 shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data); |
| 37 shouldBe('selection.focusOffset', expectedEndOffset + ''); |
| 38 shouldBeEqualToString('selection.toString()', selectedText); |
| 39 shouldBeEqualToString('$("test").innerHTML', sampleHTML); |
25 } | 40 } |
26 | 41 |
| 42 if (window.internals) { |
| 43 undoTest('mac', selectionNode, startOffset, endNode, endOffset, 'word'); |
| 44 undoTest('win', selectionNode, startOffset, endNode, endOffset, 'word'); |
| 45 undoTest('unix', selectionNode, startOffset, endNode, endOffset, 'word'); |
| 46 undoTest('android', selectionNode, startOffset, endNode, endOffset, 'word'); |
| 47 } |
| 48 if (window.testRunner) |
| 49 document.getElementById('container').outerHTML = ''; |
27 </script> | 50 </script> |
28 | 51 <script src="../../fast/js/resources/js-test-post.js"></script> |
29 </head> | |
30 <body> | |
31 <div contenteditable id="root" class="editing"> | |
32 <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> | |
33 </div> | |
34 | |
35 <script> | |
36 if (window.internals) | |
37 internals.settings.setEditingBehavior("mac"); | |
38 runEditingTest(); | |
39 </script> | |
40 | |
41 </body> | 52 </body> |
42 </html> | 53 </html> |
OLD | NEW |