dialog-open.html (1517B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>dialog element: open</title> 4 <link rel=help href="https://html.spec.whatwg.org/multipage/forms.html#dom-dialog-open"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <dialog id="d1"> 8 <p>foobar</p> 9 <button>OK</button> 10 </dialog> 11 <dialog id="d2" open> 12 <p>foobar</p> 13 <button>OK</button> 14 </dialog> 15 <script> 16 var d1 = document.getElementById('d1'); 17 var d2 = document.getElementById('d2'); 18 19 test(function(){ 20 assert_false(d1.open); 21 assert_true(d2.open); 22 }, "On getting, the IDL open attribute must return true if the content open attribute is set, and false if it is absent."); 23 24 test(function(){ 25 d1.open = true; 26 assert_true(d1.hasAttribute("open")); 27 d2.open = false; 28 assert_false(d2.hasAttribute("open")); 29 }, "On setting, the content open attribute must be removed if the IDL open attribute is set to false, and must be present if the IDL open attribute is set to true."); 30 31 async_test(function(t){ 32 d2.open = true; 33 assert_true(d2.hasAttribute("open")); 34 d2.onclose = t.unreached_func("close event should not be fired when just setting the open attribute"); 35 d2.open = false; 36 assert_false(d2.hasAttribute("open")); 37 38 // close event is async, give it a chance to be fired 39 t.step_timeout(function() { 40 requestAnimationFrame(() => { 41 t.done(); 42 }); 43 }, 0); 44 }, "On setting it to false, the close event should not be fired"); 45 </script>