diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute')
8 files changed, 377 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html new file mode 100644 index 0000000000..25e359c2a2 --- /dev/null +++ b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - default value of tabindex</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<button id="test1">TEST1</button> +<div id="test2">TEST2</div> +<script> + +test(function() { + assert_equals(document.getElementById("test1").tabIndex, 0, "The value of tabIndex attribute should be 0."); +}, "The default value of tabIndex attribute must be 0 for elements that are focusable"); + +test(function() { + assert_equals(document.getElementById("test2").tabIndex, -1, "The value of tabIndex attribute should be -1."); +}, "The default value of tabIndex attribute must be -1 for elements that are not focusable"); + +</script> diff --git a/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-negative.html b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-negative.html new file mode 100644 index 0000000000..859de94517 --- /dev/null +++ b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-negative.html @@ -0,0 +1,45 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - negative tabindex</title> +<meta name="timeout" content="long"> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check if the tabindex attribute controls whether an element is supposed to be focusable"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<div id="log"></div> +<form id="fm"> + <input id="test1" tabindex="-1"> + <input id="test2" tabindex="0"> +</form> +<script> + +var t = async_test("The element with a negative tabindex must not be focused by press 'Tab' key"); + +setup({timeout: 10000}); + +document.forms.fm.addEventListener("focus", function (evt) { + t.step(function () { + var testEle = document.getElementById("test1"); + assert_equals(testEle.tabIndex, -1, "The tabIndex attribute of the first input element should be -1."); + assert_not_equals(evt.target, testEle, "The second input element must be focused."); + assert_equals(document.activeElement, document.getElementById("test2"), "The second input element must be activated."); + }); + t.done(); +}, true); + +document.addEventListener("keydown", function (evt) { + t.step(function () { + assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); + }); +}, true); + +t.step(function () { + // TAB = '\ue004' + test_driver.send_keys(document.body, "\ue004"); +}); + +</script> diff --git a/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-order.html b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-order.html new file mode 100644 index 0000000000..d2ca0a6224 --- /dev/null +++ b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-order.html @@ -0,0 +1,65 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - the sequential focus navigation order</title> +<meta name="timeout" content="long"> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check the sequential focus navigation order"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<div id="log"></div> +<form id="fm"> + <button id="btn0">tabindex(omitted)</button> + <button id="btn1" tabindex="">tabindex(empty)</button> + <button id="btn2" tabindex="a">tabindex(a)</button> + <button id="btn3" tabindex="-1">tabindex(-1)</button> + <button id="btn4" tabindex="0">tabindex(0)</button> + <button id="btn5" tabindex="3">tabindex(3)</button> + <button id="btn6" tabindex="2">tabindex(2)</button> + <button id="btn7" tabindex="2">tabindex(2)</button> + <button id="btn8" tabindex="2">tabindex(2)</button> + <button id="btn9" tabindex="1">tabindex(1)</button> +</form> +<script> + +var i = 0, + expectation = ["btn9", "btn6", "btn7", "btn8", "btn5", "btn0", "btn1", "btn2", "btn4"], + results = [], + t = async_test("Elements with different tabindex must be focused sequentially when pressing 'Tab' keys"); + +setup(function () { + document.body.focus(); +}); + + + +document.forms.fm.addEventListener("focus", function (evt) { + results.push(evt.target.id); + if (i >= 8) { + t.step(function () { + assert_array_equals(results, expectation); + }); + t.done(); + } else { + t.step(function () { + // TAB = '\ue004' + test_driver.send_keys(document.body, "\ue004"); + }); + } + i++; +}, true); + +document.addEventListener("keydown", function (evt) { + t.step(function () { + assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); + }); +}, true); + +t.step(function () { + // TAB = '\ue004' + test_driver.send_keys(document.body, "\ue004"); +}); +</script> diff --git a/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-positive.html b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-positive.html new file mode 100644 index 0000000000..1fab1f3adb --- /dev/null +++ b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-positive.html @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: focus - positive tabindex</title> +<meta name="timeout" content="long"> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check if the tabindex attribute controls whether an element is supposed to be focusable"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<div id="log"></div> +<form id="fm"> + <input id="test" tabindex="1"> +</form> +<script> + +var t = async_test("The element with a positive tabindex must be focused by press 'Tab' key"); + +setup({timeout: 10000}); + +document.forms.fm.addEventListener("focus", function (evt) { + t.step(function () { + var testEle = document.getElementById("test"); + assert_equals(testEle.tabIndex, 1, "The tabIndex attribute of the input element should be 1."); + assert_equals(evt.target, testEle, "The input element must be focused."); + assert_equals(document.activeElement, testEle, "The input element must be activated."); + }); + t.done(); +}, true); + +document.addEventListener("keydown", function (evt) { + t.step(function () { + assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); + }); +}, true); + +t.step(function () { + // TAB = '\ue004' + test_driver.send_keys(document.body, "\ue004"); +}); + +</script> diff --git a/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-zero.html b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-zero.html new file mode 100644 index 0000000000..bda7c84687 --- /dev/null +++ b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-zero.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<head> +<meta charset="utf-8"> +<title>HTML Test: focus - zero tabindex</title> +<meta name="timeout" content="long"> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#sequential-focus-navigation-and-the-tabindex-attribute"> +<meta assert="flag" content="interact"> +<meta assert="assert" content="Check if the tabindex attribute controls whether an element is supposed to be focusable"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +</head> +<div id="log"></div> +<form id="fm"> + <input id="test" tabindex="0"> +</form> +<script> + +var t = async_test("The element with a zero tabindex must be focused by press 'Tab' key"); + +setup({timeout: 10000}); + +document.forms.fm.addEventListener("focus", function (evt) { + t.step(function () { + var testEle = document.getElementById("test"); + assert_equals(testEle.tabIndex, 0, "The tabIndex attribute of the input element should be 0."); + assert_equals(evt.target, testEle, "The input element must be focused."); + assert_equals(document.activeElement, testEle, "The input element must be activated."); + }); + t.done(); +}, true); + +document.addEventListener("keydown", function (evt) { + t.step(function () { + assert_equals(evt.keyCode, 9, "Please press 'Tab' key."); + }); +}, true); + +t.step(function () { + // TAB = '\ue004' + test_driver.send_keys(document.body, "\ue004"); +}); + +</script> diff --git a/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/resources/frameset-using-page.html b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/resources/frameset-using-page.html new file mode 100644 index 0000000000..e3aedea246 --- /dev/null +++ b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/resources/frameset-using-page.html @@ -0,0 +1,6 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>We'll grab a frame from this page to test its tabIndex</title> +<frameset> + <frame></frame> +</frameset> diff --git a/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/tabindex-getter-frame.html b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/tabindex-getter-frame.html new file mode 100644 index 0000000000..27a92f76ab --- /dev/null +++ b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/tabindex-getter-frame.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: tabIndex getter return value for frames</title> +<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<!-- <frame> elements are harder to test than the rest so they get their own file --> + +<body> + +<script> +"use strict"; +test(() => { + const frame = document.createElement("frame"); + assert_equals(frame.tabIndex, 0); +}, "disconnected frame element .tabIndex should return 0 by default"); + +for (const setValue of [-1, 0, 1]) { + test(() => { + const frame = document.createElement("frame"); + frame.setAttribute("tabindex", setValue); + assert_equals(frame.tabIndex, setValue); + }, `disconnected frame element .tabIndex should return ${setValue} when set to ${setValue}`); +} + +promise_test(async t => { + const frame = await getFrame(t); + assert_equals(frame.tabIndex, 0); +}, "connected frame element inside frameset .tabIndex should return 0 by default"); + +for (const setValue of [-1, 0, 1]) { + promise_test(async t => { + const frame = await getFrame(t); + frame.setAttribute("tabindex", setValue); + assert_equals(frame.tabIndex, setValue); + }, `connected frame element inside frameset .tabIndex should return ${setValue} when set to ${setValue}`); +} + + +function getFrame(t) { + return new Promise((resolve, reject) => { + const iframe = document.createElement("iframe"); + t.add_cleanup(() => iframe.remove()); + + iframe.src = "resources/frameset-using-page.html"; + iframe.onload = () => { + resolve(iframe.contentDocument.querySelector("frame")); + }; + iframe.onerror = () => reject(new Error("Could not load frameset page")); + + document.body.append(iframe); + }); +} +</script> diff --git a/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/tabindex-getter.html b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/tabindex-getter.html new file mode 100644 index 0000000000..785e8c91ff --- /dev/null +++ b/testing/web-platform/tests/html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/tabindex-getter.html @@ -0,0 +1,95 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: tabIndex getter return value</title> +<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<style> +#scrollable { + width: 100px; + height: 100px; + overflow: scroll; +} +#scrollable-inner { + width: 1024px; + height: 2048px; +} +</style> +<body> +<input> +<input type="hidden"> +<button>button</button> +<button disabled>button</button> +<button hidden>button</button> +<a>a</a> +<a href="#">a</a> +<svg><a>svg a</a></svg> +<svg><a>svg a</a></svg> +<link id="nohref"> +<textarea></textarea> +<select><optgroup><option>option</option></optgroup></select> +<select multiple></select> +<iframe width="10" height="10"></iframe> +<embed width="10" height="10"></embed> +<object width="10" height="10"></object> +<span></span> +<div></div> +<details><summary>summary</summary><summary id="secondsummary">second summary</summary>details</details> +<div id="hostDelegatesFocus"></div> +<div id="hostNonDelegatesFocus"></div> +<div contenteditable="true"></div> +<div id="scrollable"><div id="scrollable-inner"></div></div> +<fieldset></fieldset> +<output></output> +<slot></slot> +<script> +document.getElementById("hostDelegatesFocus").attachShadow({ mode: "open", delegatesFocus: true }); +document.getElementById("hostNonDelegatesFocus").attachShadow({ mode: "open", delegatesFocus: false }); +const defaultList = [ + ["input", 0], + ["input[type='hidden']", 0], + ["button", 0], + ["button[disabled]", 0], + ["button[hidden]", 0], + ["a", 0], + ["a[href]", 0], + ["svg a", 0], + ["textarea", 0], + ["select", 0], + ["select[multiple]", 0], + ["option", -1], + ["optgroup", -1], + ["iframe", 0], + ["embed", -1], + ["object", 0], + ["span", -1], + ["div", -1], + ["link#nohref", -1], + ["link[href]", -1], + ["details", -1], + ["summary", 0], + ["summary#secondsummary", -1], + ["#hostDelegatesFocus", -1], + ["#hostNonDelegatesFocus", -1], + ["div[contenteditable]", -1], + ["#scrollable", -1], + ["fieldset", -1], + ["output", -1], + ["slot", -1], +]; +const tabIndexValue = [-1, 0, 1]; +for (const entry of defaultList) { + const element = document.querySelector(entry[0]); + test(() => { + assert_equals(element.tabIndex, entry[1]); + }, entry[0] + ".tabIndex should return " + entry[1] + " by default"); + for (const setValue of tabIndexValue ) { + test(() => { + element.setAttribute("tabindex", setValue); + assert_equals(element.tabIndex, setValue); + }, entry[0] + ".tabIndex should return " + setValue + " when set to " + setValue); + } +} +</script> +</body> + |