| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../../../resources/js-test.js"></script> |
| 5 <script> |
| 6 description('Tests focus when a modal dialog is opened.'); |
| 7 |
| 8 function test() |
| 9 { |
| 10 outerButton = document.getElementById('outer-button'); |
| 11 shouldBe('document.activeElement', 'outerButton'); |
| 12 |
| 13 debug('Test that focus goes to body if the dialog has no focusable elements,
including itself'); |
| 14 var outerDialog = document.getElementById('outer-dialog'); |
| 15 outerDialog.showModal(); |
| 16 shouldBe('document.activeElement', 'document.body'); |
| 17 |
| 18 debug('Test that an autofocus element in the dialog gets focus.'); |
| 19 var dialog = document.getElementById('dialog'); |
| 20 dialog.showModal(); |
| 21 autofocusButton = document.getElementById('autofocus-button'); |
| 22 shouldBe('document.activeElement', 'autofocusButton'); |
| 23 dialog.close(); |
| 24 |
| 25 debug('... or else first focusable element in the dialog gets focus.'); |
| 26 autofocusButton.parentNode.removeChild(autofocusButton); |
| 27 dialog.showModal(); |
| 28 firstButton = document.getElementById('first-button'); |
| 29 shouldBe('document.activeElement', 'firstButton'); |
| 30 dialog.close(); |
| 31 |
| 32 debug('... or else the dialog itself gets focus.'); |
| 33 var buttons = dialog.querySelectorAll('button'); |
| 34 for (var i = 0; i < buttons.length; ++i) |
| 35 buttons[i].hidden = true; |
| 36 dialog.showModal(); |
| 37 shouldBe('document.activeElement', 'dialog'); |
| 38 dialog.close(); |
| 39 |
| 40 document.getElementById('outer-dialog').close(); |
| 41 finishJSTest(); |
| 42 } |
| 43 </script> |
| 44 </head> |
| 45 <body onload="test();"> |
| 46 <button id="outer-button" autofocus></button> |
| 47 <dialog id="outer-dialog"> |
| 48 <dialog id="dialog" tabindex=0> |
| 49 <button disabled></button> |
| 50 <dialog> |
| 51 <button autofocus></button> |
| 52 </dialog> |
| 53 <button id="first-button"></button> |
| 54 <div> |
| 55 <span> |
| 56 <button id="autofocus-button" autofocus></button> |
| 57 </span> |
| 58 </div> |
| 59 <button id="final-button"></button> |
| 60 </dialog> |
| 61 </dialog> |
| 62 </body> |
| 63 </html> |
| OLD | NEW |