Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[html/editing/focus] New test for inserting element with autofocus #9440

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<button id="button3">Button 3</button>
<fieldset id="fieldset1"><button id="button4">Button 4</button></fieldset>
<fieldset id="fieldset2" disabled><legend><button id="button5">Button 5</button></legend></fieldset>
<button id="button6">Button 6</button>
<div id="div" tabindex="0">Div</div>
<div id="editable" contenteditable=true>editor</div>
</div>
Expand Down Expand Up @@ -83,6 +84,25 @@
assert_equals(document.activeElement, document.body, "After changing a legend element, the body must be focused");
}, "Changing the first legend element in disabled <fieldset>");

async_test(t => {
const button = document.querySelector("#button6");
button.focus();

assert_equals(document.activeElement, button, "Sanity check: the button must start focused");

const newButton = document.createElement("button");
newButton.id = "button7";
newButton.innerText = "Button 7";
newButton.autofocus = true;

button.parentElement.insertBefore(newButton, button.nextElementSibling);

t.step_timeout(() => {
assert_equals(document.activeElement, newButton, "After inserting a button with autofocus, that button must be focused");
t.done();
});
}, "Inserting a button with autofocus");

test(() => {
const div = document.querySelector("#div");
div.focus();
Expand Down