Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / undo / undo-delete-boundary.html
blob1e5da235428282e06f63b5775306c3b5821a6a77
1 <!DOCTYPE html>
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 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 at the end 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>
8 </div>
9 <div id="console"></div>
10 <script src="../../resources/js-test.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 only on mac.';
14 var selectionNode = document.getElementById('test').childNodes[1].firstChild; // Text node 'rd '
15 var selectionOffset = selectionNode.length - 1;
16 var endNodeMac = document.getElementById('test').firstChild; // Text node 'This wo'
17 var endOffsetMac = endNodeMac.data.indexOf(' ') + 1;
18 var selection = window.getSelection();
20 function $(id) { return document.getElementById(id); }
22 function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndNode, expectedEndOffset, selectedText) {
23 debug(platform);
24 internals.settings.setEditingBehavior(platform);
26 selection.collapse(selectionNode, selectionOffset);
27 for (var i = 0; i < 4; i++)
28 document.execCommand('delete');
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 = '';
47 </script>
48 </body>
49 </html>