5 <script src=
"../../../resources/js-test.js"></script>
10 <div id=
"console"></div>
13 window
.jsTestIsAsync
= true;
16 function testBasic() {
20 debug('Testing takeRecords.');
23 div
= document
.createElement('div');
24 subDiv
= div
.appendChild(document
.createElement('div'));
25 subDiv
.innerHTML
= 'hello, world';
26 observer
= new MutationObserver(function(mutations
) {
27 window
.mutations
= mutations
;
30 observer
.observe(div
, {attributes
: true, characterData
: true, subtree
: true});
31 subDiv
.setAttribute('foo', 'bar');
32 subDiv
.firstChild
.textContent
= 'goodbye!';
33 div
.removeChild(subDiv
);
35 mutations
= observer
.takeRecords();
37 debug('...records are taken synchronously.');
39 shouldBe('mutations.length', '2');
40 shouldBe('mutations[0].type', '"attributes"');
41 shouldBe('mutations[0].target', 'subDiv');
42 shouldBe('mutations[0].attributeName', '"foo"');
43 shouldBe('mutations[0].attributeNamespace', 'null');
44 shouldBe('mutations[1].type', '"characterData"');
45 shouldBe('mutations[1].target', 'subDiv.firstChild');
47 subDiv
.setAttribute('foo', 'baz');
48 setTimeout(finish
, 0);
52 debug('...takeRecord took records, but did not clear transient observers');
54 shouldBe('mutations.length', '1');
55 shouldBe('mutations[0].type', '"attributes"');
56 shouldBe('mutations[0].target', 'subDiv');
57 shouldBe('mutations[0].attributeName', '"foo"');
58 observer
.disconnect();
66 var tests
= [testBasic
];
69 function runNextTest() {
70 if (testIndex
< tests
.length
)
76 description('Testing WebKitMutationObserver.takeRecords');