OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>dialog element: showModal()</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 <button id="b0">OK</button> |
| 10 <dialog id="d1"> |
| 11 <p>foobar</p> |
| 12 <button id="b1">OK</button> |
| 13 </dialog> |
| 14 <dialog id="d2" open> |
| 15 <p>foobar</p> |
| 16 <button>OK</button> |
| 17 </dialog> |
| 18 <dialog id="d3"> |
| 19 <p>foobar</p> |
| 20 <button id="b3">OK</button> |
| 21 </dialog> |
| 22 <dialog id="d4"> |
| 23 <p>foobar</p> |
| 24 <button id="b4">OK</button> |
| 25 </dialog> |
| 26 <dialog id="d5"> |
| 27 <p>foobar</p> |
| 28 <button id="b5">OK</button> |
| 29 </dialog> |
| 30 <dialog id="d6"></dialog> |
| 31 <dialog id="d7"> |
| 32 <input id="i71" value="foobar"> |
| 33 <input id="i72" value="foobar"> |
| 34 <button id="b7">OK</button> |
| 35 </dialog> |
| 36 <dialog id="d8"> |
| 37 <input id="i81" value="foobar"> |
| 38 <input id="i82" value="foobar" autofocus> |
| 39 <button id="b8">OK</button> |
| 40 </dialog> |
| 41 <script> |
| 42 var d1 = document.getElementById('d1'), |
| 43 d2 = document.getElementById('d2'), |
| 44 d3 = document.getElementById('d3'), |
| 45 d4 = document.getElementById('d4'), |
| 46 d5 = document.getElementById('d5'), |
| 47 d6 = document.getElementById('d6'), |
| 48 d7 = document.getElementById('d7'), |
| 49 d8 = document.getElementById('d8'), |
| 50 b0 = document.getElementById('b0'), |
| 51 b1 = document.getElementById('b1'), |
| 52 b3 = document.getElementById('b3'), |
| 53 b4 = document.getElementById('b4'), |
| 54 b5 = document.getElementById('b5'); |
| 55 |
| 56 test(function(){ |
| 57 assert_false(d1.open); |
| 58 assert_false(b0.commandDisabled); |
| 59 d1.showModal(); |
| 60 this.add_cleanup(function() { d1.close(); }); |
| 61 assert_true(d1.open); |
| 62 assert_true(b0.commandDisabled); |
| 63 assert_equals(document.activeElement, b1); |
| 64 }); |
| 65 |
| 66 test(function(){ |
| 67 assert_throws("INVALID_STATE_ERR", function() { |
| 68 d2.showModal(); |
| 69 this.add_cleanup(function() { d2.close(); }); |
| 70 }); |
| 71 }, "showModal() on a <dialog> that already has an open attribute throws an Inv
alidStateError exception"); |
| 72 |
| 73 test(function(){ |
| 74 var d = document.createElement("dialog"); |
| 75 assert_throws("INVALID_STATE_ERR", function() { |
| 76 d.showModal(); |
| 77 this.add_cleanup(function() { d.close(); }); |
| 78 }); |
| 79 }, "showModal() on a <dialog> not in a Document throws an InvalidStateError ex
ception"); |
| 80 |
| 81 test(function(){ |
| 82 assert_false(d3.open); |
| 83 assert_false(b3.commandDisabled); |
| 84 assert_false(d4.open); |
| 85 assert_false(b4.commandDisabled); |
| 86 assert_false(d5.open); |
| 87 assert_false(b5.commandDisabled); |
| 88 d3.showModal(); |
| 89 this.add_cleanup(function() { d3.close(); }); |
| 90 d4.showModal(); |
| 91 this.add_cleanup(function() { d4.close(); }); |
| 92 d5.showModal(); |
| 93 this.add_cleanup(function() { d5.close(); }); |
| 94 assert_true(d3.open); |
| 95 assert_true(b3.commandDisabled); |
| 96 assert_true(d4.open); |
| 97 assert_true(b4.commandDisabled); |
| 98 assert_true(d5.open); |
| 99 assert_false(b5.commandDisabled); |
| 100 }, "when opening multiple dialogs, only the newest one is non-inert"); |
| 101 |
| 102 test(function(){ |
| 103 assert_false(d6.open); |
| 104 d6.showModal(); |
| 105 this.add_cleanup(function() { d6.close(); }); |
| 106 assert_true(d6.open); |
| 107 assert_equals(document.activeElement, d6); |
| 108 }, "opening dialog without focusable children"); |
| 109 |
| 110 test(function(){ |
| 111 assert_false(d7.open); |
| 112 d7.showModal(); |
| 113 this.add_cleanup(function() { d7.close(); }); |
| 114 assert_true(d7.open); |
| 115 assert_equals(document.activeElement, document.getElementById("i71")); |
| 116 }, "opening dialog with multiple focusable children"); |
| 117 |
| 118 test(function(){ |
| 119 assert_false(d8.open); |
| 120 d8.showModal(); |
| 121 this.add_cleanup(function() { d8.close(); }); |
| 122 assert_true(d8.open); |
| 123 assert_equals(document.activeElement, document.getElementById("i82")); |
| 124 }, "opening dialog with multiple focusable children, one having the autofocus
attribute"); |
| 125 </script> |
OLD | NEW |