Skip to content

Commit

Permalink
html: Update autofocus tests in cases of documents with fragments
Browse files Browse the repository at this point in the history
Specification change: whatwg/html#6204
Issue: whatwg/html#5252
  • Loading branch information
tkent-google committed Dec 9, 2020
1 parent 009fb03 commit 0bc38db
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>

<iframe src="resources/frame-with-autofocus-element.html#"></iframe>

<script>
'use strict';

promise_test(async () => {
await waitForLoad(window);
await waitUntilStableAutofocusState();
assert_equals(document.activeElement, document.querySelector('iframe'),
'Autofocus elements in iframes should be focused.');

let input = document.createElement('input');
input.autofocus = true;
document.body.appendChild(input);
await waitUntilStableAutofocusState();
assert_not_equals(document.activeElement, input);
}, 'Autofocus elements in iframed documents with empty fragments should work.');

promise_test(async () => {
let w = window.open('resources/frame-with-autofocus-element.html#');
await waitForLoad(w);
await waitUntilStableAutofocusState(w);
assert_equals(w.document.activeElement, w.document.body);
w.close();
}, 'Autofocus elements in top-level browsing context\'s documents with empty fragments should work.');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>

<iframe src="resources/frame-with-autofocus-element.html#non-existent"></iframe>

<script>
'use strict';

promise_test(async () => {
await waitForLoad(window);
await waitUntilStableAutofocusState();
assert_equals(document.activeElement, document.querySelector('iframe'),
'Autofocus elements in iframes should be focused.');

let input = document.createElement('input');
input.autofocus = true;
document.body.appendChild(input);
await waitUntilStableAutofocusState();
assert_not_equals(document.activeElement, input);
}, 'Autofocus elements in iframed documents with non-existent fragments should work.');

promise_test(async () => {
let w = window.open('resources/frame-with-autofocus-element.html#non-existent');
await waitForLoad(w);
await waitUntilStableAutofocusState(w);
assert_equals(w.document.activeElement, w.document.body);
w.close();
}, 'Autofocus elements in top-level browsing context\'s documents with non-existent fragments should work.');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>

<iframe src="resources/frame-with-autofocus-element.html#top"></iframe>

<script>
'use strict';

promise_test(async () => {
await waitForLoad(window);
await waitUntilStableAutofocusState();
assert_equals(document.activeElement, document.querySelector('iframe'),
'Autofocus elements in iframes should be focused.');

let input = document.createElement('input');
input.autofocus = true;
document.body.appendChild(input);
await waitUntilStableAutofocusState();
assert_not_equals(document.activeElement, input);
}, 'Autofocus elements in iframed documents with "top" fragments should work.');

promise_test(async () => {
let w = window.open('resources/frame-with-autofocus-element.html#top');
await waitForLoad(w);
await waitUntilStableAutofocusState(w);
assert_equals(w.document.activeElement, w.document.body);
w.close();
}, 'Autofocus elements in top-level browsing context\'s documents with "top" fragments should work.');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<script src="resources/utils.js"></script>

<iframe src="resources/frame-with-autofocus-element.html#anchor1"></iframe>
<iframe src="resources/frame-with-autofocus-element.html#non-existent-anchor"></iframe>

<script>
'use strict';
Expand All @@ -23,7 +22,7 @@
}, 'Autofocus elements in iframed documents with URL fragments should be skipped.');

promise_test(async () => {
let w = window.open('resources/frame-with-autofocus-element.html#xpointer(//body)');
let w = window.open('resources/frame-with-autofocus-element.html#anchor1');
await waitForLoad(w);
await waitUntilStableAutofocusState(w);
assert_equals(w.document.activeElement, w.document.body);
Expand Down

0 comments on commit 0bc38db

Please sign in to comment.