Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / character-data-mutation.html
blob2b3e50bc611461eb0ac02f5820a7c36e45b834cf
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <p>This test ensures WebKit adjusts or clears the selection when either the start or the end container was modified.</p>
5 <div id="test" contenteditable></div>
6 <pre>
7 <script>
9 var test = document.getElementById('test');
10 test.focus();
12 if (window.testRunner)
13 testRunner.dumpAsText();
15 var baseIsFirst = true;
17 function runSingleTest(actor, isStart, expectedOffset) {
18 test.innerHTML = '<span>hello</span> world';
20 // Select "llo wo"
21 var selection = window.getSelection();
22 if (baseIsFirst)
23 selection.setBaseAndExtent(test.firstChild.firstChild, 2, test.lastChild, 3);
24 else
25 selection.setBaseAndExtent(test.lastChild, 3, test.firstChild.firstChild, 2);
26 var originalOffset = isStart ? selection.getRangeAt(0).startOffset : selection.getRangeAt(0).endOffset;
27 var action = isStart ? actor(test.firstChild.firstChild, 'startContainer') : actor(test.lastChild, 'endContainer');
28 var message = null;
29 var passed = false;
30 if (typeof(expectedOffset) == 'undefined') {
31 if (selection.rangeCount)
32 message = 'did not clear selection';
33 else {
34 message = 'cleared selection';
35 passed = true;
37 } else if (!selection.rangeCount)
38 message = 'cleared selection unexpectedly';
39 else if ((selection.getRangeAt(0).startContainer == selection.baseNode
40 && selection.getRangeAt(0).startOffset == selection.baseOffset) ^ baseIsFirst)
41 message = 'exchanged base and extent';
42 else {
43 var actualOffset = isStart ? selection.getRangeAt(0).startOffset : selection.getRangeAt(0).endOffset;
44 message = actualOffset == originalOffset ? 'did not move selection' : 'moved the offset from ' +
45 originalOffset + ' to ' + actualOffset;
47 if (actualOffset != expectedOffset)
48 message += ' but expected ' + expectedOffset;
49 else
50 passed = true;
53 document.write((passed ? 'PASS: ' : 'FAIL: ') + action + ' ' + message + '\n');
56 function runTestPairs(actor, expectedStartOffset, expectedEndOffset, skipEnd) {
57 runSingleTest(actor, true, expectedStartOffset);
58 if (!skipEnd)
59 runSingleTest(actor, false, expectedEndOffset);
62 function runTests() {
63 runTestPairs(function() { test.removeChild(test.firstChild); return 'Removing the parent of startContainer'; }, 0, undefined, true);
64 runTestPairs(function(node, nodeName) { node.nodeValue = 'a'; return 'Replacing nodeValue of ' + nodeName; }, 0, 0);
65 runTestPairs(function(node, nodeName) { node.appendData(' WebKit'); return 'Appending " WebKit" to ' + nodeName; }, 2, 3);
67 runTestPairs(function(node, nodeName) { node.insertData(2, 'WebKit ');
68 return 'Inserting " WebKit" to ' + nodeName + ' before the end point'; }, 2, 10);
69 runTestPairs(function(node, nodeName) { node.insertData(3, 'WebKit ');
70 return 'Inserting " WebKit" to ' + nodeName + ' after the end point'; }, 2, 3);
72 runTestPairs(function(node, nodeName) { node.deleteData(1, 4);
73 return 'Removing text in ' + nodeName + ' containing the end point'; }, 1, 1);
74 runTestPairs(function(node, nodeName) { node.deleteData(0, 3);
75 return 'Removing text in ' + nodeName + ' containing the start point'; }, 0, 0);
76 runTestPairs(function(node, nodeName) { node.deleteData(0, 2);
77 return 'Removing 2 characters in ' + nodeName + ' before the end point'; }, 0, 1);
78 runTestPairs(function(node, nodeName) { node.deleteData(0, 3);
79 return 'Removing 3 characters at the beginning of ' + nodeName; }, 0, 0);
80 runTestPairs(function(node, nodeName) { node.deleteData(3, 2);
81 return 'Removing text in ' + nodeName + ' after the end point'; }, 2, 3);
83 runTestPairs(function(node, nodeName) { node.replaceData(1, 4, '1234');
84 return 'Replacing text in ' + nodeName + ' containing the end point'; }, 1, 1);
85 runTestPairs(function(node, nodeName) { node.replaceData(0, 2, '12');
86 return 'Replacing 2 characters in ' + nodeName + ' by 2 characters before the end point'; }, 0, 3);
87 runTestPairs(function(node, nodeName) { node.replaceData(0, 2, '1');
88 return 'Replacing 2 characters in ' + nodeName + ' by 1 characters before the end point'; }, 0, 2);
89 runTestPairs(function(node, nodeName) { node.replaceData(3, 2, '12');
90 return 'Replacing 2 characters in ' + nodeName + ' by 2 characters after the end point'; }, 2, 3);
93 document.write('Base is first:\n');
94 runTests();
96 baseIsFirst = false;
98 document.write('\nExtent is first:\n');
99 runTests();
101 test.style.display = 'none';
103 document.write('\nDONE');
104 </script>
105 </pre>
106 </body>
107 </html>