diff --git a/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_text_node.txt b/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_text_node.txt
new file mode 100644
index 00000000000..f3b922f4489
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/accname/name/comp_text_node.txt
@@ -0,0 +1,60 @@
+Summary
+
+Harness status: OK
+
+Rerun
+
+Found 50 tests
+
+50 Pass
+Details
+Result Test Name MessagePass span[role=button] with text/element/text nodes, no space
+Pass div[role=heading] with text/element/text nodes, no space
+Pass button with text/element/text nodes, no space
+Pass heading with text/element/text nodes, no space
+Pass link with text/element/text nodes, no space
+Pass span[role=button] with text/comment/text nodes, no space
+Pass div[role=heading] with text/comment/text nodes, no space
+Pass button with text/comment/text nodes, no space
+Pass heading with text/comment/text nodes, no space
+Pass link with text/comment/text nodes, no space
+Pass span[role=button] with text/comment/text nodes, with space
+Pass div[role=heading] with text/comment/text nodes, with space
+Pass button with text/comment/text nodes, with space
+Pass heading with text/comment/text nodes, with space
+Pass link with text/comment/text nodes, with space
+Pass span[role=button] with text node, with tab char
+Pass div[role=heading] with text node, with tab char
+Pass button with text node, with tab char
+Pass heading with text node, with tab char
+Pass link with text node, with tab char
+Pass span[role=button] with text node, with non-breaking space
+Pass div[role=heading] with text node, with non-breaking space
+Pass button with text node, with non-breaking space
+Pass heading with text node, with non-breaking space
+Pass link with text node, with non-breaking space
+Pass span[role=button] with text node, with extra non-breaking space
+Pass div[role=heading] with text node, with extra non-breaking space
+Pass button with text node, with extra non-breaking space
+Pass heading with text node, with extra non-breaking space
+Pass link with text node, with extra non-breaking space
+Pass span[role=button] with text node, with leading/trailing non-breaking space
+Pass div[role=heading] with text node, with leading/trailing non-breaking space
+Pass button with text node, with leading/trailing non-breaking space
+Pass heading with text node, with leading/trailing non-breaking space
+Pass link with text node, with leading/trailing non-breaking space
+Pass span[role=button] with text node, with mixed space and non-breaking space
+Pass div[role=heading] with text node, with mixed space and non-breaking space
+Pass button with text node, with mixed space and non-breaking space
+Pass heading with text node, with mixed space and non-breaking space
+Pass link with text node, with mixed space and non-breaking space
+Pass span[role=button] with text node, with deeply nested space
+Pass div[role=heading] with text node, with deeply nested space
+Pass button with text node, with deeply nested space
+Pass heading with text node, with deeply nested space
+Pass link with text node, with deeply nested space
+Pass span[role=button] with text node, with single line break
+Pass div[role=heading] with text node, with single line break
+Pass button with text node, with single line break
+Pass heading with text node, with single line break
+Pass link with text node, with single line break
diff --git a/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_text_node.html b/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_text_node.html
new file mode 100644
index 00000000000..d40801ca541
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/accname/name/comp_text_node.html
@@ -0,0 +1,141 @@
+
+
+
+Name Comp: Text Node
+
+
+
+
+
+
+
+
+
Tests the #comp_text_node portions of the AccName Name Computation algorithm.
+link
+label
+
+
+
+
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp
index 52d8d22a742..0d50c148209 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Node.cpp
@@ -2181,7 +2181,7 @@ void Node::build_accessibility_tree(AccessibilityTreeNode& parent)
}
// https://www.w3.org/TR/accname-1.2/#mapping_additional_nd_te
-ErrorOr Node::name_or_description(NameOrDescription target, Document const& document, HashTable& visited_nodes) const
+ErrorOr Node::name_or_description(NameOrDescription target, Document const& document, HashTable& visited_nodes, IsDescendant is_descendant) const
{
// The text alternative for a given element is computed as follows:
// 1. Set the root node to the given element, the current node to the root node, and the total accumulated text to the empty string (""). If the root node's role prohibits naming, return the empty string ("").
@@ -2321,7 +2321,7 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con
// F. Otherwise, if the current node's role allows name from content, or if the current node is referenced by aria-labelledby, aria-describedby, or is a native host language text alternative element (e.g. label in HTML), or is a descendant of a native host language text alternative element:
auto role = element->role_or_default();
- if (role.has_value() && ARIA::allows_name_from_content(role.value())) {
+ if ((role.has_value() && ARIA::allows_name_from_content(role.value())) || is_descendant == IsDescendant::Yes) {
// i. Set the accumulated text to the empty string.
total_accumulated_text.clear();
// ii. Check for CSS generated textual content associated with the current node and include it in the accumulated text. The CSS :before and :after pseudo elements [CSS2] can provide textual content for elements that have a content model.
@@ -2345,7 +2345,7 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con
current_node = &child_node;
// b. Compute the text alternative of the current node beginning with step 2. Set the result to that text alternative.
- auto result = MUST(current_node->name_or_description(target, document, visited_nodes));
+ auto result = MUST(current_node->name_or_description(target, document, visited_nodes, IsDescendant::Yes));
// c. Append the result to the accumulated text.
total_accumulated_text.append(result);
diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h
index f7d45c6b33a..ca4d17ed09f 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.h
+++ b/Userland/Libraries/LibWeb/DOM/Node.h
@@ -53,6 +53,11 @@ enum class FragmentSerializationMode {
Outer,
};
+enum class IsDescendant {
+ No,
+ Yes,
+};
+
#define ENUMERATE_STYLE_INVALIDATION_REASONS(X) \
X(AdoptedStyleSheetsList) \
X(CSSFontLoaded) \
@@ -761,7 +766,7 @@ protected:
void build_accessibility_tree(AccessibilityTreeNode& parent);
- ErrorOr name_or_description(NameOrDescription, Document const&, HashTable&) const;
+ ErrorOr name_or_description(NameOrDescription, Document const&, HashTable&, IsDescendant = IsDescendant::No) const;
private:
void queue_tree_mutation_record(Vector> added_nodes, Vector> removed_nodes, Node* previous_sibling, Node* next_sibling);