dialog-close.html (2635B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>dialog element: close()</title> 4 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> 5 <link rel=help href="https://html.spec.whatwg.org/multipage/#the-dialog-element"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <div id="log"></div> 9 <dialog id="d1"> 10 <p>foobar</p> 11 <button>OK</button> 12 </dialog> 13 <dialog id="d2" open> 14 <p>foobar</p> 15 <button>OK</button> 16 </dialog> 17 <dialog id="d3" open> 18 <p>foobar</p> 19 <button>OK</button> 20 </dialog> 21 <dialog id="d4" open> 22 <p>foobar</p> 23 <button>OK</button> 24 </dialog> 25 <dialog id="d5" open> 26 <p>foobar</p> 27 <button>OK</button> 28 </dialog> 29 <script> 30 var d1 = document.getElementById('d1'), 31 d2 = document.getElementById('d2'), 32 d3 = document.getElementById('d3'), 33 d4 = document.getElementById('d4'), 34 d5 = document.getElementById('d5'), 35 t = async_test("close() fires a close event"), 36 was_queued = false; 37 38 test(function(){ 39 d1.close("closedialog"); 40 assert_equals(d1.returnValue, ""); 41 }, "close() on a <dialog> that doesn't have an open attribute aborts the steps"); 42 43 test(function(){ 44 assert_true(d2.open); 45 assert_equals(d2.returnValue, ""); 46 d2.close("closedialog"); 47 assert_false(d2.hasAttribute("open")); 48 assert_equals(d2.returnValue, "closedialog"); 49 }, "close() removes the open attribute and set the returnValue to the first argument"); 50 51 test(function(){ 52 assert_true(d3.open); 53 assert_equals(d3.returnValue, ""); 54 d3.returnValue = "foobar"; 55 d3.close(); 56 assert_false(d3.hasAttribute("open")); 57 assert_equals(d3.returnValue, "foobar"); 58 }, "close() without argument removes the open attribute and there's no returnValue"); 59 60 d4.onclose = t.step_func_done(function(e) { 61 assert_true(was_queued, "close event should be queued"); 62 assert_true(e.isTrusted, "close event is trusted"); 63 assert_false(e.bubbles, "close event doesn't bubble"); 64 assert_false(e.cancelable, "close event is not cancelable"); 65 }); 66 67 t.step(function() { 68 d4.close(); 69 was_queued = true; 70 }) 71 72 test(function(){ 73 Object.defineProperty(HTMLDialogElement.prototype, 'returnValue', { set: function(v) { assert_unreached('JS-defined setter returnValue on the prototype was invoked'); }, configurable:true }); 74 Object.defineProperty(d5, 'returnValue', { set: function(v) { assert_unreached('JS-defined setter returnValue on the instance was invoked'); }, configurable:true }); 75 d5.close('foo'); 76 }, "close() should set the returnValue IDL attribute but not the JS property"); 77 </script>