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

Add some basic autofocus tests #9804

Merged
merged 3 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions html/semantics/forms/autofocus/first-when-later-but-before.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>The temporally first autofocus in the document wins, even if an element is inserted later that is previous in the document tree</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#autofocusing-a-form-control:-the-autofocus-attribute">
<link rel="author" title="Domenic Denicola" href="d@domenic.me">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<input autofocus>

<script>
"use strict";

const input1 = document.querySelector("input");

const input2 = document.createElement("input");
input2.autofocus = true;
document.body.prepend(input2);

step_timeout(() => {
assert_equals(document.activeElement, input1);
assert_not_equals(document.activeElement, input2);

done();
}, 100);
</script>
27 changes: 27 additions & 0 deletions html/semantics/forms/autofocus/first-when-later.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>The first autofocus in the document wins, even if elements are inserted later</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#autofocusing-a-form-control:-the-autofocus-attribute">
<link rel="author" title="Domenic Denicola" href="d@domenic.me">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<input autofocus>

<script>
"use strict";

const input1 = document.querySelector("input");

const input2 = document.createElement("input");
input2.autofocus = true;
document.body.appendChild(input2);

step_timeout(() => {
assert_equals(document.activeElement, input1);
assert_not_equals(document.activeElement, input2);

done();
}, 100);
</script>
24 changes: 24 additions & 0 deletions html/semantics/forms/autofocus/first.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>The first autofocus in the document wins</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#autofocusing-a-form-control:-the-autofocus-attribute">
<link rel="author" title="Domenic Denicola" href="d@domenic.me">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<input autofocus>
<input autofocus>

<script>
"use strict";

const [input1, input2] = document.querySelectorAll("input");

step_timeout(() => {
assert_equals(document.activeElement, input1);
assert_not_equals(document.activeElement, input2);

done();
}, 100);
</script>
22 changes: 22 additions & 0 deletions html/semantics/forms/autofocus/not-on-first-task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>The element is not focused during the initial parsing task</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/#autofocusing-a-form-control:-the-autofocus-attribute">
<link rel="author" title="Domenic Denicola" href="d@domenic.me">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<input autofocus>
<input autofocus>

<script>
"use strict";

const input = document.querySelector("input");

assert_equals(document.activeElement, document.body);
assert_not_equals(document.activeElement, input);

done();
</script>