4 <script src=
"../../../resources/js-test.js"></script>
5 <script src=
"../../forms/resources/common.js"></script>
7 description('Tests autofocus when a modal dialog is opened.');
10 shouldBe('document.activeElement', 'document.getElementById("outer-button")');
12 var dialog
= document
.getElementById('dialog');
15 autofocusButton
= document
.getElementById('autofocus-button');
16 shouldBe('document.activeElement', 'autofocusButton');
18 anotherButton
= document
.getElementById('another-button');
19 anotherButton
.focus();
20 shouldBe('document.activeElement', 'anotherButton');
22 debug('Test that reattaching does not give focus back to a previously autofocused element.');
23 autofocusButton
.style
.display
= 'none';
24 document
.body
.offsetHeight
;
25 autofocusButton
.style
.display
= 'block';
26 document
.body
.offsetHeight
;
27 shouldBe('document.activeElement', 'anotherButton');
29 debug('Test that reinserting does not give focus back to a previously autofocused element.');
30 var parentNode
= autofocusButton
.parentNode
;
31 parentNode
.removeChild(autofocusButton
);
32 document
.body
.offsetHeight
;
33 parentNode
.appendChild(autofocusButton
);
34 document
.body
.offsetHeight
;
35 shouldBe('document.activeElement', 'anotherButton');
38 debug('Test that autofocus runs again when a dialog is reopened.');
40 shouldBe('document.activeElement', 'autofocusButton');
47 waitUntilLoadedAndAutofocused(test
);
51 <button id=
"outer-button" autofocus
></button>
55 <button autofocus
></button>
59 <button id=
"autofocus-button" autofocus
></button>
62 <button id=
"another-button" autofocus
></button>