summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/editing/undo/undo-combined-delete-boundary.html
blob: db18303a3e7021e6bd17a0b38fe44ecf1fd43e13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<body>
<div id="container">
<p id="description"></p>
<p>To test manually, place the cursor after 'o' in 'word' and delete it 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>
<div id="test" style="border: 2px solid red;" contenteditable>This wo<b>rd </b>should be selected only on mac.</div>
</div>
<div id="console"></div>
<script src="../../resources/js-test.js"></script>
<script>
description('Verifies the selection behavior on undoing a text deletion.');
var sampleHTML = 'This wo<b>rd </b>should be selected only on mac.';
var selectionNode = document.getElementById('test').firstChild; // Text node 'This wo'
var selectionOffset = selectionNode.length;
var endNodeMac = document.getElementById('test').childNodes[1].firstChild; // Text node 'rd '
var endOffsetMac = endNodeMac.length - 1;
var startOffsetMac = selectionNode.data.indexOf(' ')+1;
var selection = window.getSelection();

function $(id) { return document.getElementById(id); }

function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndNode, expectedEndOffset, selectedText) {
    debug(platform);
    internals.settings.setEditingBehavior(platform);

    selection.collapse(selectionNode, selectionOffset);
    for (var i = 0; i < 2; i++)
        document.execCommand('delete');
    for (var i = 0; i < 2; i++)
        document.execCommand('forwarddelete');
    document.execCommand('undo');

    shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data);
    shouldBe('selection.anchorOffset', expectedStartOffset + '');
    shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data);
    shouldBe('selection.focusOffset', expectedEndOffset + '');
    shouldBeEqualToString('selection.toString()', selectedText);
    shouldBeEqualToString('$("test").innerHTML', sampleHTML);
}

if (window.internals) {
    undoTest('mac', selectionNode, startOffsetMac, endNodeMac, endOffsetMac, 'word');
    undoTest('win', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
    undoTest('unix', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
    undoTest('android', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
}
if (window.testRunner)
  document.getElementById('container').outerHTML = '';
</script>
</body>
</html>