MutationObserver-sanity.html (3444B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title></title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <script> 7 test(() => { 8 var m = new MutationObserver(() => {}); 9 assert_throws_js(TypeError, () => { 10 m.observe(document, {}); 11 }); 12 }, "Should throw if none of childList, attributes, characterData are true"); 13 14 test(() => { 15 var m = new MutationObserver(() => {}); 16 m.observe(document, { childList: true }); 17 m.disconnect(); 18 }, "Should not throw if childList is true"); 19 20 test(() => { 21 var m = new MutationObserver(() => {}); 22 m.observe(document, { attributes: true }); 23 m.disconnect(); 24 }, "Should not throw if attributes is true"); 25 26 test(() => { 27 var m = new MutationObserver(() => {}); 28 m.observe(document, { characterData: true }); 29 m.disconnect(); 30 }, "Should not throw if characterData is true"); 31 32 test(() => { 33 var m = new MutationObserver(() => {}); 34 m.observe(document, { attributeOldValue: true }); 35 m.disconnect(); 36 }, "Should not throw if attributeOldValue is true and attributes is omitted"); 37 38 test(() => { 39 var m = new MutationObserver(() => {}); 40 m.observe(document, { characterDataOldValue: true }); 41 m.disconnect(); 42 }, "Should not throw if characterDataOldValue is true and characterData is omitted"); 43 44 test(() => { 45 var m = new MutationObserver(() => {}); 46 m.observe(document, { attributes: ["abc"] }); 47 m.disconnect(); 48 }, "Should not throw if attributeFilter is present and attributes is omitted"); 49 50 test(() => { 51 var m = new MutationObserver(() => {}); 52 assert_throws_js(TypeError, () => { 53 m.observe(document, { childList: true, attributeOldValue: true, 54 attributes: false }); 55 }); 56 }, "Should throw if attributeOldValue is true and attributes is false"); 57 58 test(() => { 59 var m = new MutationObserver(() => {}); 60 m.observe(document, { childList: true, attributeOldValue: true, 61 attributes: true }); 62 m.disconnect(); 63 }, "Should not throw if attributeOldValue and attributes are both true"); 64 65 test(() => { 66 var m = new MutationObserver(() => {}); 67 assert_throws_js(TypeError, () => { 68 m.observe(document, { childList: true, attributeFilter: ["abc"], 69 attributes: false }); 70 }); 71 }, "Should throw if attributeFilter is present and attributes is false"); 72 73 test(() => { 74 var m = new MutationObserver(() => {}); 75 m.observe(document, { childList: true, attributeFilter: ["abc"], 76 attributes: true }); 77 m.disconnect(); 78 }, "Should not throw if attributeFilter is present and attributes is true"); 79 80 test(() => { 81 var m = new MutationObserver(() => {}); 82 assert_throws_js(TypeError, () => { 83 m.observe(document, { childList: true, characterDataOldValue: true, 84 characterData: false }); 85 }); 86 }, "Should throw if characterDataOldValue is true and characterData is false"); 87 88 test(() => { 89 var m = new MutationObserver(() => {}); 90 m.observe(document, { childList: true, characterDataOldValue: true, 91 characterData: true }); 92 m.disconnect(); 93 }, "Should not throw if characterDataOldValue is true and characterData is true"); 94 95 </script>