5 <p id=
"description"></p>
6 <p>To test manually, place the cursor before 'w' of 'word' and delete it completely character 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 before 'w' of 'word'.
</p>
7 <div id=
"test" style=
"border: 2px solid red;" contenteditable
>This wo
<b>rd
</b>should be selected only on mac.
</div>
9 <div id=
"console"></div>
10 <script src=
"../../resources/js-test.js"></script>
12 description('Verifies the selection behavior on undoing a text deletion.');
13 var sampleHTML
= 'This wo<b>rd </b>should be selected only on mac.';
14 var selectionNode
= document
.getElementById('test').firstChild
; // Text node 'This wo'
15 var selectionOffset
= selectionNode
.data
.indexOf(' ') + 1;
16 var endNodeMac
= document
.getElementById('test').childNodes
[1].firstChild
; // Text node 'rd '
17 var endOffsetMac
= endNodeMac
.length
- 1;
18 var selection
= window
.getSelection();
20 function $(id
) { return document
.getElementById(id
); }
22 function undoTest(platform
, expectedStartNode
, expectedStartOffset
, expectedEndNode
, expectedEndOffset
, selectedText
) {
24 internals
.settings
.setEditingBehavior(platform
);
26 selection
.collapse(selectionNode
, selectionOffset
);
27 for (var i
= 0; i
< 4; i
++)
28 document
.execCommand('forwarddelete');
29 document
.execCommand('undo');
31 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode
.data
);
32 shouldBe('selection.anchorOffset', expectedStartOffset
+ '');
33 shouldBeEqualToString('selection.focusNode.data', expectedEndNode
.data
);
34 shouldBe('selection.focusOffset', expectedEndOffset
+ '');
35 shouldBeEqualToString('selection.toString()', selectedText
);
36 shouldBeEqualToString('$("test").innerHTML', sampleHTML
);
39 if (window
.internals
) {
40 undoTest('mac', selectionNode
, selectionOffset
, endNodeMac
, endOffsetMac
, 'word');
41 undoTest('win', selectionNode
, selectionOffset
, selectionNode
, selectionOffset
, '');
42 undoTest('unix', selectionNode
, selectionOffset
, selectionNode
, selectionOffset
, '');
43 undoTest('android', selectionNode
, selectionOffset
, selectionNode
, selectionOffset
, '');
45 if (window
.testRunner
)
46 document
.getElementById('container').outerHTML
= '';