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