OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <body> | 2 <body> |
3 <input type="range"> | 3 <input type="range"> |
4 <script src="../../js/resources/js-test-pre.js"></script> | 4 <script src="../../js/resources/js-test-pre.js"></script> |
5 <script> | 5 <script> |
6 description('Test that MutationObservers operate in Shadow DOM'); | 6 description('Test that MutationObservers operate in Shadow DOM'); |
7 | 7 |
8 function doTest() | 8 function doTest() |
9 { | 9 { |
10 function mutate(elt) | 10 function mutate(elt) |
11 { | 11 { |
12 elt.setAttribute('data-foo', 'bar'); | 12 elt.setAttribute('data-foo', 'bar'); |
13 elt.insertBefore(document.createTextNode('hello'), elt.firstChild); | 13 elt.insertBefore(document.createTextNode('hello'), elt.firstChild); |
14 elt.firstChild.textContent = 'goodbye'; | 14 elt.firstChild.textContent = 'goodbye'; |
15 elt.removeChild(elt.firstChild); | 15 elt.removeChild(elt.firstChild); |
16 } | 16 } |
17 | 17 |
18 var shadowRoot = internals.shadowRoot(document.querySelector('input')); | 18 var shadowRoot = internals.shadowRoot(document.querySelector('input')); |
19 var observer = new WebKitMutationObserver(function() { }); | 19 var observer = new MutationObserver(function() { }); |
20 | 20 |
21 observer.observe(shadowRoot.firstChild, {attributes: true, childList: true,
characterData: true, subtree: true}); | 21 observer.observe(shadowRoot.firstChild, {attributes: true, childList: true,
characterData: true, subtree: true}); |
22 mutate(shadowRoot.firstChild); | 22 mutate(shadowRoot.firstChild); |
23 | 23 |
24 window.mutations = observer.takeRecords(); | 24 window.mutations = observer.takeRecords(); |
25 debug('Mutations in shadow DOM should have been observed:'); | 25 debug('Mutations in shadow DOM should have been observed:'); |
26 shouldBe('mutations.length', '4'); | 26 shouldBe('mutations.length', '4'); |
27 shouldBe('mutations[0].type', '"attributes"'); | 27 shouldBe('mutations[0].type', '"attributes"'); |
28 shouldBe('mutations[1].type', '"childList"'); | 28 shouldBe('mutations[1].type', '"childList"'); |
29 shouldBe('mutations[2].type', '"characterData"'); | 29 shouldBe('mutations[2].type', '"characterData"'); |
30 shouldBe('mutations[3].type', '"childList"'); | 30 shouldBe('mutations[3].type', '"childList"'); |
31 observer.disconnect(); | 31 observer.disconnect(); |
32 | 32 |
33 window.mutations = observer.takeRecords(); | 33 window.mutations = observer.takeRecords(); |
34 observer.observe(document, {attributes: true, childList: true, characterData
: true, subtree: true}); | 34 observer.observe(document, {attributes: true, childList: true, characterData
: true, subtree: true}); |
35 mutate(shadowRoot.firstChild); | 35 mutate(shadowRoot.firstChild); |
36 debug('\nObserving from outside shadow DOM should not see mutations in the s
hadow:'); | 36 debug('\nObserving from outside shadow DOM should not see mutations in the s
hadow:'); |
37 shouldBe('mutations.length', '0'); | 37 shouldBe('mutations.length', '0'); |
38 } | 38 } |
39 | 39 |
40 if (window.internals) | 40 if (window.internals) |
41 doTest(); | 41 doTest(); |
42 else | 42 else |
43 testFailed('This test only runs in DRT'); | 43 testFailed('This test only runs in DRT'); |
44 </script> | 44 </script> |
45 <script src="../../js/resources/js-test-post.js"></script> | 45 <script src="../../js/resources/js-test-post.js"></script> |
46 </body> | 46 </body> |
OLD | NEW |