5 <p id=
"description"></p>
6 <p>To test manually, place the cursor after 'o' in '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 after 'o' in 'word'.
</p>
7 <div id=
"test" style=
"border: 2px solid red;" contenteditable
>This word 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 selectionNode
= document
.getElementById('test').firstChild
;
14 var selectionOffset
= selectionNode
.data
.indexOf('o') + 1;
15 var startOffsetMac
= selectionNode
.data
.indexOf(' ') + 1;
16 var endOffsetMac
= selectionNode
.data
.indexOf('d') + 1;
17 var selection
= window
.getSelection();
19 function undoTest(platform
, expectedStartNode
, expectedStartOffset
, expectedEndNode
, expectedEndOffset
, selectedText
) {
21 internals
.settings
.setEditingBehavior(platform
);
23 selection
.collapse(selectionNode
, selectionOffset
);
24 for (var i
= 0; i
< 2; i
++)
25 document
.execCommand('delete');
26 for (var i
= 0; i
< 2; i
++)
27 document
.execCommand('forwarddelete');
28 document
.execCommand('undo');
30 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode
.data
);
31 shouldBe('selection.anchorOffset', expectedStartOffset
+ '');
32 shouldBeEqualToString('selection.focusNode.data', expectedEndNode
.data
);
33 shouldBe('selection.focusOffset', expectedEndOffset
+ '');
34 shouldBeEqualToString('selection.toString()', selectedText
);
37 if (window
.internals
) {
38 undoTest('mac', selectionNode
, startOffsetMac
, selectionNode
, endOffsetMac
, 'word');
39 undoTest('win', selectionNode
, selectionOffset
, selectionNode
, selectionOffset
, '');
40 undoTest('unix', selectionNode
, selectionOffset
, selectionNode
, selectionOffset
, '');
41 undoTest('android', selectionNode
, selectionOffset
, selectionNode
, selectionOffset
, '');
43 if (window
.testRunner
)
44 document
.getElementById('container').outerHTML
= '';