Skip to content

Truly independent web browser

LibWeb: Make MathML a elements with an href attribute focusable

Tim Ledbetter827e0d4f894d
diff --git a/Libraries/LibWeb/MathML/MathMLAnchorElement.cpp b/Libraries/LibWeb/MathML/MathMLAnchorElement.cpp
index 410260adf65..c6a62b15132 100644
--- a/Libraries/LibWeb/MathML/MathMLAnchorElement.cpp
+++ b/Libraries/LibWeb/MathML/MathMLAnchorElement.cpp
@@ -27,4 +27,16 @@ void MathMLAnchorElement::attribute_changed(Utf16FlyString const& name, Optional
href_content_attribute_changed();
}
+bool MathMLAnchorElement::is_focusable() const
+{
+ return (Base::is_focusable() || has_attribute(AttributeNames::href)) && meets_focusable_area_rendering_requirements();
+}
+
+// https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
+i32 MathMLAnchorElement::default_tab_index_value() const
+{
+ // 3. Return 0 if this is [...] MathML a element [...]; otherwise −1.
+ return 0;
+}
+
}
diff --git a/Libraries/LibWeb/MathML/MathMLAnchorElement.h b/Libraries/LibWeb/MathML/MathMLAnchorElement.h
index c1b219fa3ec..c2f6a650dcd 100644
--- a/Libraries/LibWeb/MathML/MathMLAnchorElement.h
+++ b/Libraries/LibWeb/MathML/MathMLAnchorElement.h
@@ -24,11 +24,15 @@ public:
virtual bool is_mathml_anchor_element() const override { return true; }
+ // ^EventTarget
+ virtual bool is_focusable() const override;
+
private:
MathMLAnchorElement(DOM::Document&, DOM::QualifiedName);
// ^DOM::Element
virtual void attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_) override;
+ virtual i32 default_tab_index_value() const override;
// ^HTML::HTMLHyperlinkElementUtils
virtual DOM::Element& hyperlink_element_utils_element() override { return *this; }
diff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-001.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-001.txt
new file mode 100644
index 00000000000..899494dc8f1
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-001.txt
@@ -0,0 +1,69 @@
+Harness status: OK
+
+Found 64 tests
+
+64 Pass
+Pass default and invalid values for a without href
+Pass default and invalid values for a with href
+Pass default and invalid values for annotation without href
+Pass default and invalid values for annotation with href
+Pass default and invalid values for annotation-xml without href
+Pass default and invalid values for annotation-xml with href
+Pass default and invalid values for maction without href
+Pass default and invalid values for maction with href
+Pass default and invalid values for menclose without href
+Pass default and invalid values for menclose with href
+Pass default and invalid values for merror without href
+Pass default and invalid values for merror with href
+Pass default and invalid values for mfrac without href
+Pass default and invalid values for mfrac with href
+Pass default and invalid values for mi without href
+Pass default and invalid values for mi with href
+Pass default and invalid values for mmultiscripts without href
+Pass default and invalid values for mmultiscripts with href
+Pass default and invalid values for mn without href
+Pass default and invalid values for mn with href
+Pass default and invalid values for mo without href
+Pass default and invalid values for mo with href
+Pass default and invalid values for mover without href
+Pass default and invalid values for mover with href
+Pass default and invalid values for mpadded without href
+Pass default and invalid values for mpadded with href
+Pass default and invalid values for mphantom without href
+Pass default and invalid values for mphantom with href
+Pass default and invalid values for mprescripts without href
+Pass default and invalid values for mprescripts with href
+Pass default and invalid values for mroot without href
+Pass default and invalid values for mroot with href
+Pass default and invalid values for mrow without href
+Pass default and invalid values for mrow with href
+Pass default and invalid values for ms without href
+Pass default and invalid values for ms with href
+Pass default and invalid values for mspace without href
+Pass default and invalid values for mspace with href
+Pass default and invalid values for msqrt without href
+Pass default and invalid values for msqrt with href
+Pass default and invalid values for mstyle without href
+Pass default and invalid values for mstyle with href
+Pass default and invalid values for msub without href
+Pass default and invalid values for msub with href
+Pass default and invalid values for msubsup without href
+Pass default and invalid values for msubsup with href
+Pass default and invalid values for msup without href
+Pass default and invalid values for msup with href
+Pass default and invalid values for mtable without href
+Pass default and invalid values for mtable with href
+Pass default and invalid values for mtd without href
+Pass default and invalid values for mtd with href
+Pass default and invalid values for mtext without href
+Pass default and invalid values for mtext with href
+Pass default and invalid values for mtr without href
+Pass default and invalid values for mtr with href
+Pass default and invalid values for munder without href
+Pass default and invalid values for munder with href
+Pass default and invalid values for munderover without href
+Pass default and invalid values for munderover with href
+Pass default and invalid values for none without href
+Pass default and invalid values for none with href
+Pass default and invalid values for semantics without href
+Pass default and invalid values for semantics with href
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-003.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-003.txt
new file mode 100644
index 00000000000..17b7adb89c0
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-003.txt
@@ -0,0 +1,229 @@
+Harness status: OK
+
+Found 224 tests
+
+224 Pass
+Pass changing tabindex from "3" to "" resets a.tabIndex
+Pass changing tabindex from "3" to "invalid" resets a.tabIndex
+Pass changing tabindex from "3" to " " resets a.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets a.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets a.tabIndex
+Pass trailing garbage after the digits of a's tabindex is ignored
+Pass removing tabindex resets a.tabIndex
+Pass changing tabindex from "3" to "" resets annotation.tabIndex
+Pass changing tabindex from "3" to "invalid" resets annotation.tabIndex
+Pass changing tabindex from "3" to " " resets annotation.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets annotation.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets annotation.tabIndex
+Pass trailing garbage after the digits of annotation's tabindex is ignored
+Pass removing tabindex resets annotation.tabIndex
+Pass changing tabindex from "3" to "" resets annotation-xml.tabIndex
+Pass changing tabindex from "3" to "invalid" resets annotation-xml.tabIndex
+Pass changing tabindex from "3" to " " resets annotation-xml.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets annotation-xml.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets annotation-xml.tabIndex
+Pass trailing garbage after the digits of annotation-xml's tabindex is ignored
+Pass removing tabindex resets annotation-xml.tabIndex
+Pass changing tabindex from "3" to "" resets maction.tabIndex
+Pass changing tabindex from "3" to "invalid" resets maction.tabIndex
+Pass changing tabindex from "3" to " " resets maction.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets maction.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets maction.tabIndex
+Pass trailing garbage after the digits of maction's tabindex is ignored
+Pass removing tabindex resets maction.tabIndex
+Pass changing tabindex from "3" to "" resets menclose.tabIndex
+Pass changing tabindex from "3" to "invalid" resets menclose.tabIndex
+Pass changing tabindex from "3" to " " resets menclose.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets menclose.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets menclose.tabIndex
+Pass trailing garbage after the digits of menclose's tabindex is ignored
+Pass removing tabindex resets menclose.tabIndex
+Pass changing tabindex from "3" to "" resets merror.tabIndex
+Pass changing tabindex from "3" to "invalid" resets merror.tabIndex
+Pass changing tabindex from "3" to " " resets merror.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets merror.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets merror.tabIndex
+Pass trailing garbage after the digits of merror's tabindex is ignored
+Pass removing tabindex resets merror.tabIndex
+Pass changing tabindex from "3" to "" resets mfrac.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mfrac.tabIndex
+Pass changing tabindex from "3" to " " resets mfrac.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mfrac.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mfrac.tabIndex
+Pass trailing garbage after the digits of mfrac's tabindex is ignored
+Pass removing tabindex resets mfrac.tabIndex
+Pass changing tabindex from "3" to "" resets mi.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mi.tabIndex
+Pass changing tabindex from "3" to " " resets mi.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mi.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mi.tabIndex
+Pass trailing garbage after the digits of mi's tabindex is ignored
+Pass removing tabindex resets mi.tabIndex
+Pass changing tabindex from "3" to "" resets mmultiscripts.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mmultiscripts.tabIndex
+Pass changing tabindex from "3" to " " resets mmultiscripts.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mmultiscripts.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mmultiscripts.tabIndex
+Pass trailing garbage after the digits of mmultiscripts's tabindex is ignored
+Pass removing tabindex resets mmultiscripts.tabIndex
+Pass changing tabindex from "3" to "" resets mn.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mn.tabIndex
+Pass changing tabindex from "3" to " " resets mn.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mn.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mn.tabIndex
+Pass trailing garbage after the digits of mn's tabindex is ignored
+Pass removing tabindex resets mn.tabIndex
+Pass changing tabindex from "3" to "" resets mo.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mo.tabIndex
+Pass changing tabindex from "3" to " " resets mo.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mo.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mo.tabIndex
+Pass trailing garbage after the digits of mo's tabindex is ignored
+Pass removing tabindex resets mo.tabIndex
+Pass changing tabindex from "3" to "" resets mover.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mover.tabIndex
+Pass changing tabindex from "3" to " " resets mover.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mover.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mover.tabIndex
+Pass trailing garbage after the digits of mover's tabindex is ignored
+Pass removing tabindex resets mover.tabIndex
+Pass changing tabindex from "3" to "" resets mpadded.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mpadded.tabIndex
+Pass changing tabindex from "3" to " " resets mpadded.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mpadded.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mpadded.tabIndex
+Pass trailing garbage after the digits of mpadded's tabindex is ignored
+Pass removing tabindex resets mpadded.tabIndex
+Pass changing tabindex from "3" to "" resets mphantom.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mphantom.tabIndex
+Pass changing tabindex from "3" to " " resets mphantom.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mphantom.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mphantom.tabIndex
+Pass trailing garbage after the digits of mphantom's tabindex is ignored
+Pass removing tabindex resets mphantom.tabIndex
+Pass changing tabindex from "3" to "" resets mprescripts.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mprescripts.tabIndex
+Pass changing tabindex from "3" to " " resets mprescripts.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mprescripts.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mprescripts.tabIndex
+Pass trailing garbage after the digits of mprescripts's tabindex is ignored
+Pass removing tabindex resets mprescripts.tabIndex
+Pass changing tabindex from "3" to "" resets mroot.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mroot.tabIndex
+Pass changing tabindex from "3" to " " resets mroot.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mroot.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mroot.tabIndex
+Pass trailing garbage after the digits of mroot's tabindex is ignored
+Pass removing tabindex resets mroot.tabIndex
+Pass changing tabindex from "3" to "" resets mrow.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mrow.tabIndex
+Pass changing tabindex from "3" to " " resets mrow.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mrow.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mrow.tabIndex
+Pass trailing garbage after the digits of mrow's tabindex is ignored
+Pass removing tabindex resets mrow.tabIndex
+Pass changing tabindex from "3" to "" resets ms.tabIndex
+Pass changing tabindex from "3" to "invalid" resets ms.tabIndex
+Pass changing tabindex from "3" to " " resets ms.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets ms.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets ms.tabIndex
+Pass trailing garbage after the digits of ms's tabindex is ignored
+Pass removing tabindex resets ms.tabIndex
+Pass changing tabindex from "3" to "" resets mspace.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mspace.tabIndex
+Pass changing tabindex from "3" to " " resets mspace.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mspace.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mspace.tabIndex
+Pass trailing garbage after the digits of mspace's tabindex is ignored
+Pass removing tabindex resets mspace.tabIndex
+Pass changing tabindex from "3" to "" resets msqrt.tabIndex
+Pass changing tabindex from "3" to "invalid" resets msqrt.tabIndex
+Pass changing tabindex from "3" to " " resets msqrt.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets msqrt.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets msqrt.tabIndex
+Pass trailing garbage after the digits of msqrt's tabindex is ignored
+Pass removing tabindex resets msqrt.tabIndex
+Pass changing tabindex from "3" to "" resets mstyle.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mstyle.tabIndex
+Pass changing tabindex from "3" to " " resets mstyle.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mstyle.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mstyle.tabIndex
+Pass trailing garbage after the digits of mstyle's tabindex is ignored
+Pass removing tabindex resets mstyle.tabIndex
+Pass changing tabindex from "3" to "" resets msub.tabIndex
+Pass changing tabindex from "3" to "invalid" resets msub.tabIndex
+Pass changing tabindex from "3" to " " resets msub.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets msub.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets msub.tabIndex
+Pass trailing garbage after the digits of msub's tabindex is ignored
+Pass removing tabindex resets msub.tabIndex
+Pass changing tabindex from "3" to "" resets msubsup.tabIndex
+Pass changing tabindex from "3" to "invalid" resets msubsup.tabIndex
+Pass changing tabindex from "3" to " " resets msubsup.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets msubsup.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets msubsup.tabIndex
+Pass trailing garbage after the digits of msubsup's tabindex is ignored
+Pass removing tabindex resets msubsup.tabIndex
+Pass changing tabindex from "3" to "" resets msup.tabIndex
+Pass changing tabindex from "3" to "invalid" resets msup.tabIndex
+Pass changing tabindex from "3" to " " resets msup.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets msup.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets msup.tabIndex
+Pass trailing garbage after the digits of msup's tabindex is ignored
+Pass removing tabindex resets msup.tabIndex
+Pass changing tabindex from "3" to "" resets mtable.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mtable.tabIndex
+Pass changing tabindex from "3" to " " resets mtable.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mtable.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mtable.tabIndex
+Pass trailing garbage after the digits of mtable's tabindex is ignored
+Pass removing tabindex resets mtable.tabIndex
+Pass changing tabindex from "3" to "" resets mtd.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mtd.tabIndex
+Pass changing tabindex from "3" to " " resets mtd.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mtd.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mtd.tabIndex
+Pass trailing garbage after the digits of mtd's tabindex is ignored
+Pass removing tabindex resets mtd.tabIndex
+Pass changing tabindex from "3" to "" resets mtext.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mtext.tabIndex
+Pass changing tabindex from "3" to " " resets mtext.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mtext.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mtext.tabIndex
+Pass trailing garbage after the digits of mtext's tabindex is ignored
+Pass removing tabindex resets mtext.tabIndex
+Pass changing tabindex from "3" to "" resets mtr.tabIndex
+Pass changing tabindex from "3" to "invalid" resets mtr.tabIndex
+Pass changing tabindex from "3" to " " resets mtr.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets mtr.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets mtr.tabIndex
+Pass trailing garbage after the digits of mtr's tabindex is ignored
+Pass removing tabindex resets mtr.tabIndex
+Pass changing tabindex from "3" to "" resets munder.tabIndex
+Pass changing tabindex from "3" to "invalid" resets munder.tabIndex
+Pass changing tabindex from "3" to " " resets munder.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets munder.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets munder.tabIndex
+Pass trailing garbage after the digits of munder's tabindex is ignored
+Pass removing tabindex resets munder.tabIndex
+Pass changing tabindex from "3" to "" resets munderover.tabIndex
+Pass changing tabindex from "3" to "invalid" resets munderover.tabIndex
+Pass changing tabindex from "3" to " " resets munderover.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets munderover.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets munderover.tabIndex
+Pass trailing garbage after the digits of munderover's tabindex is ignored
+Pass removing tabindex resets munderover.tabIndex
+Pass changing tabindex from "3" to "" resets none.tabIndex
+Pass changing tabindex from "3" to "invalid" resets none.tabIndex
+Pass changing tabindex from "3" to " " resets none.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets none.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets none.tabIndex
+Pass trailing garbage after the digits of none's tabindex is ignored
+Pass removing tabindex resets none.tabIndex
+Pass changing tabindex from "3" to "" resets semantics.tabIndex
+Pass changing tabindex from "3" to "invalid" resets semantics.tabIndex
+Pass changing tabindex from "3" to " " resets semantics.tabIndex
+Pass changing tabindex from "3" to "9999999999" resets semantics.tabIndex
+Pass changing tabindex from "3" to "-9999999999" resets semantics.tabIndex
+Pass trailing garbage after the digits of semantics's tabindex is ignored
+Pass removing tabindex resets semantics.tabIndex
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-focus-001.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-focus-001.txt
new file mode 100644
index 00000000000..329006cca4d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/tabindex-focus-001.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass invalid tabindex attribute does not make the element focusable
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-001.html b/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-001.html
new file mode 100644
index 00000000000..ca32c7c7bd1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-001.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8"/>
+<title>MathML tabIndex attribute</title>
+<link rel="help" href="https://w3c.github.io/mathml-core/#css-styling">
+<link rel="help" href="https://w3c.github.io/mathml-core/#the-top-level-math-element">
+<meta name="assert" content="Verify default values for the tabIndex attribute">
+
+<script src="../../../mathml/support/mathml-fragments.js"></script>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+</head>
+<body>
+ <div id="log"></div>
+ <math>
+ </math>
+ <script>
+ Object.keys(MathMLFragments).forEach(elName => {
+ const mathEl = document.querySelector('math');
+
+ mathEl.innerHTML = `
+ <${elName} id="el" onfocus="alert('fail')"></${elName}>
+ <${elName} id="el-link" href="javascript:alert('fail')" onfocus="alert('fail')"></${elName}>
+ `;
+
+ const el = mathEl.querySelector('#el');
+ const elLink = mathEl.querySelector('#el-link');
+
+ const expectedDefault = elName == 'a' ? 0 : -1;
+
+ test(() => {
+ assert_equals(el.tabIndex, expectedDefault, "no attribute");
+ el.setAttribute("tabindex", "invalid");
+ assert_equals(el.getAttribute("tabindex"), "invalid");
+ assert_equals(el.tabIndex, expectedDefault, "invalid");
+ el.setAttribute("tabindex", "9999999999");
+ assert_equals(el.getAttribute("tabindex"), "9999999999");
+ assert_equals(el.tabIndex, expectedDefault, "too large integer");
+ }, `default and invalid values for ${elName} without href`);
+ test(() => {
+ assert_equals(elLink.tabIndex, expectedDefault, "no attribute");
+ elLink.setAttribute("tabindex", "invalid");
+ assert_equals(elLink.getAttribute("tabindex"), "invalid");
+ assert_equals(elLink.tabIndex, expectedDefault, "invalid");
+ elLink.setAttribute("tabindex", "9999999999");
+ assert_equals(elLink.getAttribute("tabindex"), "9999999999");
+ assert_equals(elLink.tabIndex, expectedDefault, "too large integer");
+ }, `default and invalid values for ${elName} with href`);
+ });
+ </script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-003.html b/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-003.html
new file mode 100644
index 00000000000..d8647604a62
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-003.html
@@ -0,0 +1,70 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8"/>
+<title>MathML tabIndex attribute: resetting an explicitly set value</title>
+<link rel="help" href="https://w3c.github.io/mathml-core/#attributes-common-to-html-and-mathml-elements">
+<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex">
+<meta name="assert" content="Verify that an explicitly set tabIndex is reset to the default value when the tabindex attribute is changed to a value that is not a valid integer, or removed">
+
+<script src="../../../mathml/support/mathml-fragments.js"></script>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+</head>
+<body>
+ <div id="log"></div>
+ <math>
+ </math>
+ <script>
+ // tabindex is defined by HTML, which parses the attribute as an integer and
+ // falls back to the default tab index for any value that fails to parse.
+ // That includes the empty string, garbage, and out-of-range integers.
+ const invalidValues = ["", "invalid", " ", "9999999999", "-9999999999"];
+
+ // The HTML rules for parsing integers stop at the first non-digit and keep
+ // the digits collected so far, so these are valid despite the trailing junk.
+ const valuesWithTrailingGarbage = [["1.5", 1], ["4abc", 4], ["-2 ", -2]];
+
+ Object.keys(MathMLFragments).forEach(elName => {
+ const mathEl = document.querySelector('math');
+
+ // <a> needs an href to be focusable by default, and so to have a
+ // default tab index of 0 rather than -1.
+ const href = elName == 'a' ? ' href="#"' : '';
+ mathEl.innerHTML = `<${elName} id="el"${href}></${elName}>`;
+ const el = mathEl.querySelector('#el');
+ const expectedDefault = elName == 'a' ? 0 : -1;
+
+ invalidValues.forEach(invalidValue => {
+ test(() => {
+ el.setAttribute("tabindex", "3");
+ assert_equals(el.tabIndex, 3, "valid value");
+
+ el.setAttribute("tabindex", invalidValue);
+ assert_equals(el.getAttribute("tabindex"), invalidValue);
+ assert_equals(el.tabIndex, expectedDefault, "invalid value");
+ }, `changing tabindex from "3" to "${invalidValue}" resets ${elName}.tabIndex`);
+ });
+
+ test(() => {
+ valuesWithTrailingGarbage.forEach(([value, expectedTabIndex]) => {
+ el.setAttribute("tabindex", "3");
+ assert_equals(el.tabIndex, 3, "valid value");
+
+ el.setAttribute("tabindex", value);
+ assert_equals(el.tabIndex, expectedTabIndex, `"${value}"`);
+ });
+ el.removeAttribute("tabindex");
+ }, `trailing garbage after the digits of ${elName}'s tabindex is ignored`);
+
+ test(() => {
+ el.setAttribute("tabindex", "3");
+ assert_equals(el.tabIndex, 3, "valid value");
+
+ el.removeAttribute("tabindex");
+ assert_equals(el.tabIndex, expectedDefault, "attribute removed");
+ }, `removing tabindex resets ${elName}.tabIndex`);
+ });
+ </script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-focus-001.html b/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-focus-001.html
new file mode 100644
index 00000000000..d7cb3a22503
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/mathml/relations/html5-tree/tabindex-focus-001.html
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<title>Invalid tabindex</title>
+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1128054">
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+
+<!-- Test default focusability -->
+<math data-focusable="false"></math>
+<math href="#" data-focusable="false"></math>
+<math><a data-focusable="false"></a></math>
+<math><a href="#" data-focusable="true"></a></math>
+
+<!-- Test tabindex=0 focusability -->
+<math tabindex="0" data-focusable="true"></math>
+<math><a tabindex="0" data-focusable="true"></a></math>
+
+<!-- Test tabindex=-1 focusability -->
+<math tabindex="-1" data-focusable="true"></math>
+<math><a tabindex="-1" data-focusable="true"></a></math>
+
+<!-- Test tabindex=invalid focusability -->
+<math tabindex="invalid" data-focusable="false"></math>
+<math href="#" tabindex="invalid" data-focusable="false"></math>
+<math><a tabindex="invalid" data-focusable="false"></a></math>
+<math><a href="#" tabindex="invalid" data-focusable="true"></a></math>
+
+<script>
+ test(() => {
+ for (let element of document.querySelectorAll("[data-focusable]")) {
+ let focusable = element.dataset.focusable === "true";
+ let desc = "<" + element.tagName;
+ for (let attr of ["href", "tabindex"]) {
+ if (element.hasAttribute(attr)) {
+ desc += ` ${attr}=${element.getAttribute(attr)}`;
+ }
+ }
+ desc += ">";
+ element.focus();
+ focusable ? assert_equals(document.activeElement, element, desc + " should be focusable")
+ : assert_not_equals(document.activeElement, element, desc + " should not be focusable");
+ }
+ }, "invalid tabindex attribute does not make the element focusable");
+</script>