Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Document / replace-child.html
blob33c0495bf2b22b797a0e9396e52ec5f3d04b062d
1 <!DOCTYPE html>
2 <script src="../../../resources/js-test.js"></script>
3 <script>
4 var parser = new DOMParser();
5 var serializer = new XMLSerializer();
6 var doc, newChild, fragment;
8 function dumpDocument() {
9 debug(escapeHTML(serializer.serializeToString(doc)) + '<br>');
12 function test(name, fn) {
13 debug(name);
14 fn();
15 dumpDocument();
18 description('This tests that various combinations of replaceChild on the document works as specified.');
20 test('replacing element with element', function() {
21 doc = parser.parseFromString('<!DOCTYPE html><body/>', 'text/xml');
22 newChild = doc.createElement('div');
24 shouldNotThrow('doc.replaceChild(newChild, doc.documentElement)');
25 });
27 test('replacing element with element in fragment', function() {
28 doc = parser.parseFromString('<!DOCTYPE html><body/>', 'text/xml');
29 fragment = doc.createDocumentFragment();
30 fragment.appendChild(doc.createElement('div'));
32 shouldNotThrow('doc.replaceChild(fragment, doc.documentElement);');
33 });
35 test('replacing element with multiple elements in fragment', function() {
36 doc = parser.parseFromString('<!DOCTYPE html><body/>', 'text/xml');
37 fragment = doc.createDocumentFragment();
38 fragment.appendChild(doc.createElement('div'));
39 fragment.appendChild(doc.createElement('span'));
41 shouldThrow('doc.replaceChild(fragment, doc.documentElement);');
42 });
44 test('replacing element with doctype', function() {
45 doc = parser.parseFromString('<body/>', 'text/xml');
46 newChild = doc.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
48 shouldNotThrow('doc.replaceChild(newChild, doc.documentElement)');
49 });
51 test('replacing element with doctype when a doctype already exists', function() {
52 doc = parser.parseFromString('<!DOCTYPE html><body/>', 'text/xml');
53 newChild = doc.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
55 shouldThrow('doc.replaceChild(newChild, doc.documentElement)');
56 });
58 test('replacing doctype with doctype', function() {
59 doc = parser.parseFromString('<!DOCTYPE html><body/>', 'text/xml');
60 newChild = doc.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
62 shouldNotThrow('doc.replaceChild(newChild, doc.doctype)');
63 });
65 test('replacing doctype with element', function() {
66 doc = parser.parseFromString('<!DOCTYPE html><body/>', 'text/xml');
67 doc.removeChild(doc.documentElement);
68 newChild = doc.createElement('bar');
70 shouldNotThrow('doc.replaceChild(newChild, doc.doctype)');
71 });
73 test('replacing element with doctype when an element already exists', function() {
74 doc = parser.parseFromString('<!DOCTYPE html><body/>', 'text/xml');
75 newChild = doc.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
77 shouldThrow('doc.replaceChild(newChild, doc.documentElement)');
78 });
79 </script>