OLD | NEW |
(Empty) | |
| 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 assert_throws("INVALID_STATE_ERR", function() { |
| 40 d1.close(); |
| 41 }); |
| 42 }, "close() on a <dialog> that doesn't have an open attribute throws an Invali
dStateError exception"); |
| 43 |
| 44 test(function(){ |
| 45 assert_true(d2.open); |
| 46 assert_equals(d2.returnValue, ""); |
| 47 d2.close("closedialog"); |
| 48 assert_false(d2.hasAttribute("open")); |
| 49 assert_equals(d2.returnValue, "closedialog"); |
| 50 }, "close() removes the open attribute and set the returnValue to the first ar
gument"); |
| 51 |
| 52 test(function(){ |
| 53 assert_true(d3.open); |
| 54 assert_equals(d3.returnValue, ""); |
| 55 d3.returnValue = "foobar"; |
| 56 d3.close(); |
| 57 assert_false(d3.hasAttribute("open")); |
| 58 assert_equals(d3.returnValue, "foobar"); |
| 59 }, "close() without argument removes the open attribute and there's no returnV
alue"); |
| 60 |
| 61 d4.onclose = t.step_func_done(function(e) { |
| 62 assert_true(was_queued, "close event should be queued"); |
| 63 assert_true(e.isTrusted, "close event is trusted"); |
| 64 assert_false(e.bubbles, "close event doesn't bubble"); |
| 65 assert_false(e.cancelable, "close event is not cancelable"); |
| 66 }); |
| 67 |
| 68 t.step(function() { |
| 69 d4.close(); |
| 70 was_queued = true; |
| 71 }) |
| 72 |
| 73 test(function(){ |
| 74 Object.defineProperty(HTMLDialogElement.prototype, 'returnValue', { set: fun
ction(v) { assert_unreached('JS-defined setter returnValue on the prototype was
invoked'); }, configurable:true }); |
| 75 Object.defineProperty(d5, 'returnValue', { set: function(v) { assert_unreach
ed('JS-defined setter returnValue on the instance was invoked'); }, configurable
:true }); |
| 76 d5.close('foo'); |
| 77 }, "close() should set the returnValue IDL attribute but not the JS property")
; |
| 78 </script> |
OLD | NEW |