OLD | NEW |
---|---|
1 <html> | 1 <html> |
2 <import src="../resources/chai.sky" /> | 2 <import src="../resources/chai.sky" /> |
3 <import src="../resources/mocha.sky" /> | 3 <import src="../resources/mocha.sky" /> |
4 <script> | 4 <script> |
5 describe('MutationObserver cross document moves', function() { | 5 describe('MutationObserver cross document moves', function() { |
6 it('should handle basic observation', function(done) { | 6 it('should handle basic observation', function(done) { |
7 var mutations; | 7 var mutations; |
8 var div = document.createElement('div'); | 8 var div = document.createElement('div'); |
9 var observer = new MutationObserver(function(records) { | 9 var observer = new MutationObserver(function(records) { |
10 mutations = records; | 10 mutations = records; |
11 }); | 11 }); |
12 | 12 |
13 observer.observe(div, {attributes: true}); | 13 observer.observe(div, {attributes: true}); |
14 var newDoc = document.implementation.createDocument('', '', null); | 14 var newDoc = new Document(); |
ojan
2014/11/04 07:15:47
I wish HTML could have nice things like this.
| |
15 newDoc.appendChild(div); | 15 newDoc.appendChild(div); |
16 div.id = 'foo'; | 16 div.id = 'foo'; |
17 setTimeout(function() { | 17 setTimeout(function() { |
18 assert.equal(mutations.length, 1); | 18 assert.equal(mutations.length, 1); |
19 assert.equal(mutations[0].type, 'attributes'); | 19 assert.equal(mutations[0].type, 'attributes'); |
20 assert.equal(mutations[0].target, div); | 20 assert.equal(mutations[0].target, div); |
21 assert.equal(mutations[0].attributeName, 'id'); | 21 assert.equal(mutations[0].attributeName, 'id'); |
22 observer.disconnect(); | 22 observer.disconnect(); |
23 done(); | 23 done(); |
24 }, 0); | 24 }, 0); |
25 }); | 25 }); |
26 it('should handle subtree observation', function(done) { | 26 it('should handle subtree observation', function(done) { |
27 var mutations; | 27 var mutations; |
28 var div = document.createElement('div'); | 28 var div = document.createElement('div'); |
29 var subDiv = div.appendChild(document.createElement('div')); | 29 var subDiv = div.appendChild(document.createElement('div')); |
30 var observer = new MutationObserver(function(records) { | 30 var observer = new MutationObserver(function(records) { |
31 mutations = records; | 31 mutations = records; |
32 }); | 32 }); |
33 | 33 |
34 observer.observe(div, {attributes: true, subtree: true}); | 34 observer.observe(div, {attributes: true, subtree: true}); |
35 var newDoc = document.implementation.createDocument(); | 35 var newDoc = new Document(); |
36 newDoc.appendChild(div); | 36 newDoc.appendChild(div); |
37 subDiv.id = 'foo'; | 37 subDiv.id = 'foo'; |
38 setTimeout(function() { | 38 setTimeout(function() { |
39 assert.equal(mutations.length, 1); | 39 assert.equal(mutations.length, 1); |
40 assert.equal(mutations[0].type, 'attributes'); | 40 assert.equal(mutations[0].type, 'attributes'); |
41 assert.equal(mutations[0].target, subDiv); | 41 assert.equal(mutations[0].target, subDiv); |
42 assert.equal(mutations[0].attributeName, 'id'); | 42 assert.equal(mutations[0].attributeName, 'id'); |
43 observer.disconnect(); | 43 observer.disconnect(); |
44 done(); | 44 done(); |
45 }, 0); | 45 }, 0); |
46 }); | 46 }); |
47 }); | 47 }); |
48 </script> | 48 </script> |
49 </html> | 49 </html> |
OLD | NEW |