4 <script src=
"../../../resources/js-test.js"></script>
5 <script src=
"../../forms/resources/common.js"></script>
7 description('Tests focus when a modal dialog is opened.');
11 outerButton
= document
.getElementById('outer-button');
12 shouldBe('document.activeElement', 'outerButton');
14 debug('Test that focus goes to body if the dialog has no focusable elements, including itself');
15 var outerDialog
= document
.getElementById('outer-dialog');
16 outerDialog
.showModal();
17 shouldBe('document.activeElement', 'document.body');
19 debug('Test that an autofocus element in the dialog gets focus.');
20 var dialog
= document
.getElementById('dialog');
22 autofocusButton
= document
.getElementById('autofocus-button');
23 shouldBe('document.activeElement', 'autofocusButton');
26 debug('... or else first focusable element in the dialog gets focus.');
27 autofocusButton
.parentNode
.removeChild(autofocusButton
);
29 firstButton
= document
.getElementById('first-button');
30 shouldBe('document.activeElement', 'firstButton');
33 debug('... or else the dialog itself gets focus.');
34 var buttons
= dialog
.querySelectorAll('button');
35 for (var i
= 0; i
< buttons
.length
; ++i
)
36 buttons
[i
].hidden
= true;
38 shouldBe('document.activeElement', 'dialog');
41 document
.getElementById('outer-dialog').close();
46 waitUntilLoadedAndAutofocused(test
);
50 <button id=
"outer-button" autofocus
></button>
51 <dialog id=
"outer-dialog">
52 <dialog id=
"dialog" tabindex=
0>
53 <button disabled
></button>
55 <button autofocus
></button>
57 <button id=
"first-button"></button>
60 <button id=
"autofocus-button" autofocus
></button>
63 <button id=
"final-button"></button>