messageerror.html (1556B)
1 <!DOCTYPE html> 2 <title>onmessageerror content attribute</title> 3 <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> 4 <link rel="help" href="https://html.spec.whatwg.org/multipage/#handler-onmessageerror"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 8 <body> 9 10 <script> 11 "use strict"; 12 window.messageErrorHappened = false; 13 14 function cleanup() { 15 window.messageErrorHappened = false; 16 document.body.removeAttribute("onmessageerror"); 17 } 18 19 test(() => { 20 assert_equals(document.body.onmessageerror, null, "body"); 21 assert_equals(window.onmessageerror, null, "window"); 22 }, "The default value of onmessageerror is null"); 23 24 test(t => { 25 t.add_cleanup(cleanup); 26 27 document.body.setAttribute("onmessageerror", "window.messageErrorHappened = true;") 28 const compiledHandler = document.body.onmessageerror; 29 30 assert_equals(typeof compiledHandler, "function", "The onmessageerror property must be a function"); 31 compiledHandler(); 32 assert_true(window.messageErrorHappened, "Calling the handler must run the code"); 33 }, "The onmessageerror content attribute must be compiled into the onmessageerror property"); 34 35 test(t => { 36 t.add_cleanup(cleanup); 37 38 document.body.setAttribute("onmessageerror", "window.messageErrorHappened = true;") 39 40 window.dispatchEvent(new Event("messageerror")); 41 42 assert_true(window.messageErrorHappened, "Dispatching the event must run the code"); 43 }, "The onmessageerror content attribute must execute when an event is dispatched on the window"); 44 </script>