document-with-fragment-top.html (1244B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="resources/utils.js"></script> 5 6 <iframe src="resources/frame-with-autofocus-element.html#top"></iframe> 7 8 <script> 9 'use strict'; 10 11 promise_test(async () => { 12 await waitForLoad(window); 13 const iframe = document.querySelector('iframe'); 14 await waitUntilStableAutofocusState(); 15 assert_equals(document.activeElement, iframe, 16 'Autofocus elements in iframes should be focused.'); 17 const doc = iframe.contentDocument; 18 assert_true(!doc.querySelector(':target')); 19 20 let input = document.createElement('input'); 21 input.autofocus = true; 22 document.body.appendChild(input); 23 await waitUntilStableAutofocusState(); 24 assert_not_equals(document.activeElement, input); 25 }, 'Autofocus elements in iframed documents with "top" fragments should work.'); 26 27 promise_test(async () => { 28 let w = window.open('resources/frame-with-autofocus-element.html#top'); 29 await waitForLoad(w); 30 await waitUntilStableAutofocusState(w); 31 assert_not_equals(w.document.activeElement, w.document.body); 32 w.close(); 33 }, 'Autofocus elements in top-level browsing context\'s documents with "top" fragments should work.'); 34 </script>