interestevent-interface.tentative.html (2987B)
1 <!doctype html> 2 <meta charset="utf-8" /> 3 <link rel="author" title="Keith Cirkel" href="mailto:keithamus@github.com" > 4 <link rel="author" title="Luke Warlow" href="mailto:lwarlow@igalia.com" > 5 <link rel="help" href="https://open-ui.org/components/interest-invokers.explainer/" /> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-actions.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 <script src="resources/invoker-utils.js"></script> 12 13 <div id="div"></div> 14 <button id="button"></button> 15 16 <script> 17 test(function () { 18 const event = new InterestEvent("test"); 19 assert_equals(event.source, null); 20 assert_readonly(event, "source", "readonly attribute value"); 21 }, "source is readonly defaulting to null"); 22 23 test(function () { 24 const eventInit = { source: document.body }; 25 const event = new InterestEvent("test", eventInit); 26 assert_equals(event.source, document.body); 27 }, "InterestEventInit properties set value (manual event)"); 28 29 test(function () { 30 const eventInit = { 31 source: document.getElementById("div"), 32 }; 33 const event = new InterestEvent("beforetoggle", eventInit); 34 assert_equals(event.source, document.getElementById("div")); 35 }, "InterestEventInit properties set value (beforetoggle event)"); 36 37 test(function () { 38 const eventInit = { 39 source: document.getElementById("button"), 40 }; 41 const event = new InterestEvent("toggle", eventInit); 42 assert_equals(event.source, document.getElementById("button")); 43 }, "InterestEventInit properties set value (toggle event)"); 44 45 test(function () { 46 const event = new InterestEvent("test", { source: undefined }); 47 assert_equals(event.source, null); 48 }, "source set to undefined"); 49 50 test(function () { 51 const event = new InterestEvent("test", { source: null }); 52 assert_equals(event.source, null); 53 }, "source set to null"); 54 55 test(function () { 56 assert_throws_js( 57 TypeError, 58 function () { 59 new InterestEvent("test", { source: false }); 60 }, 61 "source is not an object", 62 ); 63 }, "source set to false"); 64 65 test(function () { 66 assert_throws_js( 67 TypeError, 68 function () { 69 const event = new InterestEvent("test", { source: true }); 70 }, 71 "source is not an object", 72 ); 73 }, "source set to true"); 74 75 test(function () { 76 assert_throws_js( 77 TypeError, 78 function () { 79 const event = new InterestEvent("test", { source: {} }); 80 }, 81 "source is not an object", 82 ); 83 }, "source set to {}"); 84 85 test(function () { 86 assert_throws_js( 87 TypeError, 88 function () { 89 const eventInit = { source: new XMLHttpRequest() }; 90 const event = new InterestEvent("toggle", eventInit); 91 }, 92 "source is not an Element", 93 ); 94 }, "source set to non-Element EventTarget"); 95 </script>