2 <script src=
"../../../resources/js-test.js"></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});
16 function createObservedDiv() {
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');
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');
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');