Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / deleting / delete-character-003.html
blob87029a342ad359b26a015d68880425d3067ac3dc
1 <div id="container">
2 <div id="sample" contenteditable="true"></div>
3 </div>
4 <script src="../../resources/js-test.js"></script>
5 <script>
6 function $(id) { return document.getElementById(id); }
7 var sample = $('sample');
8 var selection = window.getSelection();
9 function testIt(sourceHTML, expectedHTML, expectedNode, expectedOffset)
11 var sourceText = sourceHTML.replace(/<br>/g, '\n');
12 var caretPos = sourceText.indexOf('|');
13 sample.innerHTML = sourceHTML.replace('|', '');
14 sample.focus();
15 var range = document.createRange();
16 if (caretPos == sample.childNodes.length) {
17 range.selectNodeContents(sample);
18 range.collapse(false);
19 } else {
20 range.setStartBefore(sample.childNodes[caretPos]);
22 selection.removeAllRanges();
23 selection.addRange(range);
24 document.execCommand('Delete', false);
26 debug(sourceHTML.replace(/</g, '&lt;'));
27 shouldBeEqualToString('sample.innerHTML', expectedHTML);
28 shouldBeEqualToString('selection.type', 'Caret');
29 shouldBe('selection.focusNode', expectedNode);
30 shouldBe('selection.focusOffset', expectedOffset.toString());
31 debug('');
34 testIt('a|<br>', '<br>', 'sample', 0);
35 testIt('a<br>|<br>', 'a<br>', 'sample.firstChild', 1);
36 testIt('a<br><br>|<br>', 'a<br><br>', 'sample', 2);
38 testIt('a|<br><br>', '<br><br>', 'sample', 0);
39 testIt('a<br>|<br><br>', 'a<br><br>', 'sample.firstChild', 1);
40 testIt('a<br><br>|<br><br>', 'a<br><br><br>', 'sample', 2);
42 testIt('a<br>|b', 'ab', 'sample.firstChild', 1);
43 testIt('a<br><br>|b', 'a<br>b', 'sample.lastChild', 0);
44 testIt('a<br><br><br>|b', 'a<br><br>b', 'sample.lastChild', 0);
46 testIt('a<br>b|', 'a<br><br>', 'sample', 2);
47 testIt('a<br><br>b|', 'a<br><br><br>', 'sample', 3);
48 testIt('a<br><br><br>b|', 'a<br><br><br><br>', 'sample', 4);
50 if (window.testRunner)
51 $('container').outerHTML = '';
52 </script>