Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / MutationObserver / document-fragment-insertion.html
blobc2bcc40658bc669d4f73c7575ad71f4054da3d3c
1 <!DOCTYPE html>
2 <script src="../../../resources/js-test.js"></script>
3 <script>
4 description('Inserting DocumentFragments should remove all children of the fragment before inserting the children.');
6 window.jsTestIsAsync = true;
8 function createObservedFragment() {
9 var fragment = document.createDocumentFragment();
10 fragment.appendChild(document.createElement('b'));
11 fragment.appendChild(document.createElement('i'));
12 observer.observe(fragment, {childList: true});
13 return fragment;
16 function createObservedDiv() {
17 return div;
20 function callback(mutations) {
21 window.mutations = mutations;
23 var observer = new MutationObserver(callback);
25 function testAppendChild() {
26 debug('Testing appendChild');
27 var div = document.createElement('div');
28 observer.observe(div, {childList: true});
29 div.appendChild(createObservedFragment());
30 setTimeout(function() {
31 shouldBe('mutations.length', '2');
32 shouldBe('mutations[0].addedNodes.length', '0');
33 shouldBe('mutations[0].removedNodes.length', '2');
34 shouldBe('mutations[1].addedNodes.length', '2');
35 shouldBe('mutations[1].removedNodes.length', '0');
36 debug('');
37 testInsertBefore();
38 }, 0);
41 function testInsertBefore() {
42 debug('Testing insertBefore');
43 var div = document.createElement('div');
44 div.appendChild(document.createElement('span'));
45 observer.observe(div, {childList: true});
46 div.insertBefore(createObservedFragment(), div.firstChild);
47 setTimeout(function() {
48 shouldBe('mutations.length', '2');
49 shouldBe('mutations[0].addedNodes.length', '0');
50 shouldBe('mutations[0].removedNodes.length', '2');
51 shouldBe('mutations[1].addedNodes.length', '2');
52 shouldBe('mutations[1].removedNodes.length', '0');
53 debug('');
54 testReplaceChild();
55 }, 0);
58 function testReplaceChild() {
59 debug('Testing replaceChild');
60 var div = document.createElement('div');
61 div.appendChild(document.createElement('span'));
62 observer.observe(div, {childList: true});
63 div.replaceChild(createObservedFragment(), div.firstChild);
64 setTimeout(function() {
65 shouldBe('mutations.length', '2');
66 shouldBe('mutations[0].addedNodes.length', '0');
67 shouldBe('mutations[0].removedNodes.length', '2');
68 shouldBe('mutations[1].addedNodes.length', '2');
69 shouldBe('mutations[1].removedNodes.length', '1');
70 debug('');
71 finishJSTest();
72 }, 0);
75 testAppendChild();
76 </script>