OLD | NEW |
| (Empty) |
1 <html> | |
2 <link rel="import" href="../resources/chai.html" /> | |
3 <link rel="import" href="../resources/mocha.html" /> | |
4 <script> | |
5 describe('MutationObserver.takeRecords', function() { | |
6 it('should allow taking records synchronously or getting a notification', func
tion(done) { | |
7 var mutations; | |
8 var div; | |
9 var subDiv; | |
10 var observer; | |
11 | |
12 // Testing takeRecords. | |
13 mutations = null; | |
14 div = document.createElement('div'); | |
15 subDiv = div.appendChild(document.createElement('div')); | |
16 subDiv.textContent = 'hello, world'; | |
17 observer = new MutationObserver(function(records) { | |
18 mutations = records; | |
19 }); | |
20 | |
21 observer.observe(div, {attributes: true, characterData: true, subtree: true}
); | |
22 subDiv.setAttribute('foo', 'bar'); | |
23 subDiv.firstChild.textContent = 'goodbye!'; | |
24 div.removeChild(subDiv); | |
25 | |
26 mutations = observer.takeRecords(); | |
27 | |
28 // ...records are taken synchronously. | |
29 | |
30 assert.equal(mutations.length, 2); | |
31 assert.equal(mutations[0].type, "attributes"); | |
32 assert.equal(mutations[0].target, subDiv); | |
33 assert.equal(mutations[0].attributeName, "foo"); | |
34 assert.equal(mutations[1].type, "characterData"); | |
35 assert.equal(mutations[1].target, subDiv.firstChild); | |
36 | |
37 subDiv.setAttribute('foo', 'baz'); | |
38 | |
39 setTimeout(function() { | |
40 // ...takeRecord took records, but did not clear transient observers. | |
41 | |
42 assert.equal(mutations.length, 1); | |
43 assert.equal(mutations[0].type, "attributes"); | |
44 assert.equal(mutations[0].target, subDiv); | |
45 assert.equal(mutations[0].attributeName, "foo"); | |
46 observer.disconnect(); | |
47 | |
48 done(); | |
49 }, 0); | |
50 }); | |
51 }); | |
52 </script> | |
53 </html> | |
OLD | NEW |