4 <script src=
"../../../resources/js-test.js"></script>
9 window
.jsTestIsAsync
= true;
13 function testBasic() {
17 debug('Testing basic aspects of cross-document observation.');
20 div
= document
.createElement('div');
21 observer
= new MutationObserver(function(mutations
) {
22 window
.mutations
= mutations
;
25 observer
.observe(div
, {attributes
: true});
26 var newDoc
= document
.implementation
.createDocument('', '', null);
27 newDoc
.appendChild(div
);
29 setTimeout(finish
, 0);
33 shouldBe('mutations.length', '1');
34 shouldBe('mutations[0].type', '"attributes"');
35 shouldBe('mutations[0].target', 'div');
36 shouldBe('mutations[0].attributeName', '"id"');
37 shouldBe('mutations[0].attributeNamespace', 'null');
38 observer
.disconnect();
46 function testSubtree() {
50 debug('Testing that subtree observation works after node is moved.');
53 div
= document
.createElement('div');
54 subDiv
= div
.appendChild(document
.createElement('div'));
55 observer
= new MutationObserver(function(mutations
) {
56 window
.mutations
= mutations
;
59 observer
.observe(div
, {attributes
: true, subtree
: true});
60 var newDoc
= document
.implementation
.createDocument('', '', null);
61 newDoc
.appendChild(div
);
63 setTimeout(finish
, 0);
67 shouldBe('mutations.length', '1');
68 shouldBe('mutations[0].type', '"attributes"');
69 shouldBe('mutations[0].target', 'subDiv');
70 shouldBe('mutations[0].attributeName', '"id"');
71 shouldBe('mutations[0].attributeNamespace', 'null');
72 observer
.disconnect();
80 var tests
= [testBasic
, testSubtree
];
83 function runNextTest() {
84 if (testIndex
< tests
.length
)
90 description('Test that MutationObservers move correctly across documents');