dialog-close-event.html (1487B)
1 <!DOCTYPE html> 2 <link rel=author href="mailto:jarhar@chromium.org"> 3 <link rel=author href="mailto:falken@chromium.org"> 4 <link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element"> 5 <link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=276785"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <dialog></dialog> 10 11 <script> 12 async_test(t => { 13 document.addEventListener('close', t.step_func_done(() => { 14 t.assert_unreached(`The 'close' event unexpectedly bubbled.`); 15 })); 16 17 closedCount = 0; 18 dialog = document.querySelector('dialog'); 19 dialog.addEventListener('close', function(event) { 20 const selfDialog = this; 21 t.step(() => { 22 closedCount++; 23 assert_equals(selfDialog, dialog); 24 assert_false(dialog.open); 25 assert_false(event.cancelable); 26 event.preventDefault(); 27 28 if (closedCount == 1) { 29 dialog.show(); 30 dialog.close(); 31 assert_equals(closedCount, 1, `dialog's close event handler shouldn't be called synchronously.`); 32 } else if (closedCount == 2) { 33 t.done(); 34 } 35 }); 36 }); 37 38 dialog.show(); 39 dialog.close(); 40 41 // Verify that preventDefault() didn't cancel closing. 42 assert_false(dialog.open); 43 44 // dialog's close event handler shouldn't be called synchronously. 45 assert_equals(closedCount, 0); 46 }, "Test that dialog receives a close event upon closing."); 47 </script>