fix(ax): preserve native link semantics at URL boundaries

Resolve presentational-role conflicts using DOM focus support and global
ARIA properties, while retaining explicit button semantics. Share native
href capability between role calculation, focus support and URL selection.

Trim only HTML whitespace, keep null-namespace SVG href ahead of XLink,
and avoid exposing MathML navigation targets without native activation.

Preserve namespace/local-name attribute identity in parser merges so
unqualified href and xlink:href coexist. Cover the four regressions, focus
controls, disabled-fieldset legends and parser attribute identity.
This commit is contained in:
ldm0
2026-11-18 05:29:42 +08:00
committed by Donough Liu
parent a36ef01889
commit 866261db45
8 changed files with 505 additions and 91 deletions
+162 -1
View File
@@ -1,4 +1,8 @@
use crate::{NodeId, native::DomHost};
use crate::{
NodeId,
forms::{InputType, parse_html_integer_prefix},
native::{DomHost, Element, NativeDom, Node},
};
pub(super) fn ax_child_ids(
document: &DomHost,
@@ -44,3 +48,160 @@ fn composed_child_ids(document: &DomHost, node_id: NodeId) -> Option<Vec<NodeId>
}
None
}
/// Native href capability shared by role computation and URL publication.
/// Keep this aligned with the HTML/SVG links supported by activation.
pub(super) fn ax_link_href(element: &Element) -> Option<&str> {
if element.is_html_element("a")
|| element.is_html_element("area")
|| element.is_html_element("link")
{
element.attribute_ns("", "href")
} else if element.is_svg_element("a") {
element
.attribute_ns("", "href")
.or_else(|| element.attribute_ns("http://www.w3.org/1999/xlink", "href"))
} else {
None
}
}
/// DOM focus support for presentation-role conflicts. Hidden and inert nodes
/// are handled by the surrounding AX projection, without requesting layout.
pub(super) fn ax_supports_focus(document: &NativeDom, node: &Node) -> bool {
let Some(element) = node.as_element() else {
return false;
};
if element.is_html_input() && element.input_type() == InputType::Hidden {
return false;
}
if element.namespace() == "http://www.w3.org/1999/xhtml"
&& matches!(
element.local_name(),
"button" | "input" | "select" | "textarea"
)
&& ax_control_is_disabled(document, node.id(), element)
{
return false;
}
if element
.attribute_ns("", "tabindex")
.and_then(parse_html_integer_prefix)
.is_some()
{
return true;
}
if element.is_html_element("a")
|| element.is_html_element("area")
|| element.is_svg_element("a")
{
return ax_link_href(element).is_some() || ax_is_editing_host(document, node);
}
if element.namespace() == "http://www.w3.org/1999/xhtml"
&& matches!(
element.local_name(),
"button" | "input" | "select" | "textarea"
)
{
return true;
}
if element.is_html_element("summary")
&& let Some(parent) = document.parent_node(node.id())
&& document
.node(parent)
.and_then(Node::as_element)
.is_some_and(|parent| parent.is_html_element("details"))
{
return document.child_ids(parent).find(|child| {
document
.node(*child)
.and_then(Node::as_element)
.is_some_and(|child| child.is_html_element("summary"))
}) == Some(node.id());
}
ax_is_editing_host(document, node)
}
fn ax_is_editing_host(document: &NativeDom, node: &Node) -> bool {
fn editable(element: &Element) -> Option<bool> {
let value = element.attribute_ns("", "contenteditable")?;
if value.is_empty()
|| value.eq_ignore_ascii_case("true")
|| value.eq_ignore_ascii_case("plaintext-only")
{
Some(true)
} else if value.eq_ignore_ascii_case("false") {
Some(false)
} else {
None
}
}
if node.as_element().and_then(editable) != Some(true) {
return false;
}
let mut ancestor = document.parent_node(node.id());
while let Some(id) = ancestor {
let Some(parent) = document.node(id) else {
break;
};
if let Some(is_editable) = parent.as_element().and_then(editable) {
return !is_editable;
}
ancestor = parent.parent_node_id();
}
true
}
pub(super) fn ax_control_is_disabled(
document: &NativeDom,
node_id: NodeId,
element: &Element,
) -> bool {
if element.has_attribute("disabled") {
return true;
}
if !matches!(
element.local_name(),
"button" | "input" | "select" | "textarea"
) {
return false;
}
let mut ancestor = document.parent_node(node_id);
while let Some(ancestor_id) = ancestor {
let Some(ancestor_node) = document.node(ancestor_id) else {
break;
};
if ancestor_node.as_element().is_some_and(|ancestor| {
ancestor.is_html_fieldset() && ancestor.has_attribute("disabled")
}) && !ax_is_inside_first_legend(document, node_id, ancestor_id)
{
return true;
}
ancestor = ancestor_node.parent_node_id();
}
false
}
fn ax_is_inside_first_legend(document: &NativeDom, node_id: NodeId, fieldset_id: NodeId) -> bool {
let Some(first_legend) = document.child_ids(fieldset_id).find(|child_id| {
document
.node(*child_id)
.and_then(Node::as_element)
.is_some_and(|element| element.is_html_element("legend"))
}) else {
return false;
};
let mut current = Some(node_id);
while let Some(current_id) = current {
if current_id == first_legend {
return true;
}
if current_id == fieldset_id {
return false;
}
current = document.parent_node(current_id);
}
false
}
+15 -75
View File
@@ -7,7 +7,7 @@ use serde_json::{Value, json};
use std::collections::HashSet;
use url::Url;
use super::ax_dom::ax_child_ids;
use super::ax_dom::{ax_child_ids, ax_control_is_disabled, ax_link_href};
use super::ax_projection::{AxTreeProjection, AxUnavailable};
use super::ax_roles::{ax_role, heading_level, is_image, is_link};
@@ -224,7 +224,7 @@ fn ax_element_name(
if matches!(
traversal,
AxNameTraversal::Contents | AxNameTraversal::NativeLabel
) && ax_role(node) == "generic"
) && ax_role(document, node) == "generic"
{
return Ok(AxName::contents(content));
}
@@ -434,7 +434,7 @@ fn ax_is_text_control(element: &Element) -> bool {
}
fn ax_name_comes_from_contents(document: &NativeDom, node: &Node, element: &Element) -> bool {
let role = ax_role(node);
let role = ax_role(document, node);
if role == "row" {
return ax_row_name_comes_from_contents(document, node);
}
@@ -468,7 +468,7 @@ fn ax_row_name_comes_from_contents(document: &NativeDom, node: &Node) -> bool {
let Some(ancestor_node) = document.node(ancestor_id) else {
return false;
};
match ax_role(ancestor_node) {
match ax_role(document, ancestor_node) {
"grid" | "treegrid" => return true,
"generic" | "none" | "group" | "rowgroup" => {
ancestor = ancestor_node.parent_node_id();
@@ -592,7 +592,7 @@ pub(super) fn ax_properties(document: &NativeDom, node_id: NodeId, node: &Node)
properties.push(ax_bool_property("focused", "booleanOrUndefined", true));
}
NodeData::Element(element) => {
let role = ax_role(node);
let role = ax_role(document, node);
if role == "status" {
let live = element
.attribute("aria-live")
@@ -635,7 +635,7 @@ pub(super) fn ax_properties(document: &NativeDom, node_id: NodeId, node: &Node)
if let Some(url) = ax_element_url(document, element, role) {
properties.push(ax_string_property("url", url.as_str()));
}
if element.is_html_element("a") && element.has_attribute("href") {
if element.is_html_element("a") && ax_link_href(element).is_some() {
properties.push(ax_bool_property("focusable", "booleanOrUndefined", true));
}
if element.is_html_element("button") {
@@ -789,56 +789,6 @@ pub(super) fn ax_properties(document: &NativeDom, node_id: NodeId, node: &Node)
properties
}
fn ax_control_is_disabled(document: &NativeDom, node_id: NodeId, element: &Element) -> bool {
if element.has_attribute("disabled") {
return true;
}
if !matches!(
element.local_name(),
"button" | "input" | "select" | "textarea"
) {
return false;
}
let mut ancestor = document.parent_node(node_id);
while let Some(ancestor_id) = ancestor {
let Some(ancestor_node) = document.node(ancestor_id) else {
break;
};
if ancestor_node.as_element().is_some_and(|ancestor| {
ancestor.is_html_fieldset() && ancestor.has_attribute("disabled")
}) && !ax_is_inside_first_legend(document, node_id, ancestor_id)
{
return true;
}
ancestor = ancestor_node.parent_node_id();
}
false
}
fn ax_is_inside_first_legend(document: &NativeDom, node_id: NodeId, fieldset_id: NodeId) -> bool {
let Some(first_legend) = document.child_ids(fieldset_id).find(|child_id| {
document
.node(*child_id)
.and_then(Node::as_element)
.is_some_and(|element| element.is_html_element("legend"))
}) else {
return false;
};
let mut current = Some(node_id);
while let Some(current_id) = current {
if current_id == first_legend {
return true;
}
if current_id == fieldset_id {
return false;
}
current = document.parent_node(current_id);
}
false
}
fn ax_option_is_selected(document: &NativeDom, option_id: NodeId) -> bool {
let Some(option_node) = document.node(option_id) else {
return false;
@@ -973,38 +923,28 @@ fn ax_element_url(document: &NativeDom, element: &Element, role: &str) -> Option
// Follow Blink's AXNodeObject::Url: the computed role selects the kind of
// URL, and the native element must provide that kind of address.
if is_link(role) {
let href = if element.is_html_element("a")
|| element.is_html_element("area")
|| element.is_html_element("link")
|| (element.namespace() == "http://www.w3.org/1998/Math/MathML"
&& element.local_name() == "a")
{
element.attribute("href")
} else if element.is_svg_element("a") {
element
.attribute("href")
.or_else(|| element.attribute_ns("http://www.w3.org/1999/xlink", "href"))
} else {
None
};
return href.and_then(|href| ax_resolve_element_url(document, href));
return ax_link_href(element).and_then(|href| ax_resolve_element_url(document, href));
}
if is_image(role) && element.is_html_element("img") {
return element
.attribute("src")
.filter(|src| !src.trim().is_empty())
.attribute_ns("", "src")
.filter(|src| !trim_html_spaces(src).is_empty())
.and_then(|src| ax_resolve_element_url(document, src));
}
if role == "button" && element.is_html_input() && element.input_type() == InputType::Image {
return element
.attribute("src")
.attribute_ns("", "src")
.and_then(|src| ax_resolve_element_url(document, src));
}
None
}
fn trim_html_spaces(value: &str) -> &str {
value.trim_matches(|character: char| character.is_ascii_whitespace())
}
fn ax_resolve_element_url(document: &NativeDom, value: &str) -> Option<Url> {
let value = value.trim();
let value = trim_html_spaces(value);
let base = document.document().map(|doc| doc.base_url().clone());
base.as_ref()
.and_then(|base| Url::options().base_url(Some(base)).parse(value).ok())
+123 -11
View File
@@ -16,12 +16,12 @@ pub(super) fn is_image(role: &str) -> bool {
matches!(role, "image" | "doc-cover" | "graphics-symbol" | "SvgRoot")
}
pub(super) fn ax_role(node: &Node) -> &'static str {
pub(super) fn ax_role(document: &NativeDom, node: &Node) -> &'static str {
match node.kind() {
NodeData::Document(_) => "RootWebArea",
NodeData::DocumentType(_) => "none",
NodeData::Element(element) => {
explicit_aria_role(element).unwrap_or_else(|| native_ax_role(element))
explicit_aria_role(document, node, element).unwrap_or_else(|| native_ax_role(element))
}
NodeData::Text(_) | NodeData::CDataSection(_) => "StaticText",
NodeData::Comment(_) | NodeData::ProcessingInstruction(_) => "none",
@@ -40,7 +40,13 @@ fn native_ax_role(element: &Element) -> &'static str {
"section" => "region",
"article" | "hgroup" => "article",
"address" => "group",
"a" => "link",
"a" => {
if super::ax_dom::ax_link_href(element).is_some() {
"link"
} else {
"generic"
}
}
"button" => "button",
"input" => match element.attribute("type").unwrap_or("text") {
"text" | "email" | "tel" | "url" | "password" => "textbox",
@@ -117,11 +123,53 @@ fn native_ax_role(element: &Element) -> &'static str {
}
}
fn explicit_aria_role(element: &Element) -> Option<&'static str> {
element
.attribute("role")?
fn explicit_aria_role(
document: &NativeDom,
node: &Node,
element: &Element,
) -> Option<&'static str> {
let role = element
.attribute_ns("", "role")?
.split_whitespace()
.find_map(aria_role_to_ax_role)
.find_map(aria_role_to_ax_role)?;
// Blink resolves presentational-role conflicts before selecting the native
// role. Explicit semantic overrides such as button keep their precedence.
if role == "none"
&& !element.is_html_element("iframe")
&& !element.is_html_element("frame")
&& (super::ax_dom::ax_supports_focus(document, node) || has_global_aria_property(element))
{
None
} else {
Some(role)
}
}
fn has_global_aria_property(element: &Element) -> bool {
// Chromium AXObject::DoesUndoRolePresentation. Deprecated global states
// such as aria-disabled, and aria-hidden, do not undo presentation.
[
"aria-atomic",
"aria-braillelabel",
"aria-brailleroledescription",
"aria-busy",
"aria-controls",
"aria-current",
"aria-describedby",
"aria-description",
"aria-details",
"aria-flowto",
"aria-keyshortcuts",
"aria-label",
"aria-labeledby",
"aria-labelledby",
"aria-live",
"aria-owns",
"aria-relevant",
"aria-roledescription",
]
.into_iter()
.any(|name| element.has_attribute_ns("", name))
}
// Keep this mapping aligned with Blink's generated AriaRoleToInternalRole().
@@ -320,6 +368,61 @@ mod tests {
use super::*;
use url::Url;
#[test]
fn presentation_conflicts_use_focus_support_and_global_aria_properties() {
let cases = [
("a", vec![("href", "/go")], "link"),
("a", vec![], "none"),
("a", vec![("tabindex", "-1")], "generic"),
("button", vec![], "button"),
("button", vec![("disabled", ""), ("tabindex", "0")], "none"),
("input", vec![("type", "hidden"), ("tabindex", "0")], "none"),
("img", vec![("tabindex", "-1")], "image"),
("img", vec![("tabindex", "0tail")], "image"),
("img", vec![("tabindex", "invalid")], "none"),
("img", vec![("tabindex", "\u{a0}0")], "none"),
("img", vec![("aria-label", "")], "image"),
("img", vec![("aria-live", "off")], "image"),
("img", vec![("aria-hidden", "false")], "none"),
("img", vec![("aria-disabled", "true")], "none"),
("div", vec![("contenteditable", "true")], "generic"),
];
let mut document = NativeDom::new_html(Url::parse("https://example.test/").unwrap());
let root = document.create_element("main");
assert!(document.append_child(document.document_node_id(), root));
for role in ["presentation", "none"] {
for (tag, attributes, expected) in &cases {
let element = document.create_element(tag);
assert!(document.append_child(root, element));
for (name, value) in attributes {
assert!(document.set_attribute(element, name, value));
}
assert!(document.set_attribute(element, "role", role));
assert_eq!(
ax_role(&document, document.node(element).unwrap()),
*expected,
"{tag} role={role}, attributes={attributes:?}"
);
}
}
}
#[test]
fn presentation_conflicts_respect_disabled_fieldsets_and_the_first_legend() {
let mut document = NativeDom::new_html(Url::parse("https://example.test/").unwrap());
let fieldset = document.create_element("fieldset");
document.append_child(document.document_node_id(), fieldset);
document.set_attribute(fieldset, "disabled", "");
let legend = document.create_element("legend");
document.append_child(fieldset, legend);
for (parent, expected) in [(legend, "button"), (fieldset, "none")] {
let button = document.create_element("button");
document.append_child(parent, button);
document.set_attribute(button, "role", "presentation");
assert_eq!(ax_role(&document, document.node(button).unwrap()), expected);
}
}
#[test]
fn explicit_aria_role_uses_chromium_fallback_token_order() {
let mut document =
@@ -328,10 +431,16 @@ mod tests {
assert!(document.append_child(document.document_node_id(), element));
assert!(document.set_attribute(element, "role", "unknown STATUS"));
assert_eq!(ax_role(document.node(element).expect("element")), "status");
assert_eq!(
ax_role(&document, document.node(element).expect("element")),
"status"
);
assert!(document.set_attribute(element, "role", "button status"));
assert_eq!(ax_role(document.node(element).expect("element")), "button");
assert_eq!(
ax_role(&document, document.node(element).expect("element")),
"button"
);
}
#[test]
@@ -342,13 +451,16 @@ mod tests {
assert!(document.append_child(document.document_node_id(), password));
assert!(document.set_attribute(password, "type", "password"));
assert_eq!(
ax_role(document.node(password).expect("element")),
ax_role(&document, document.node(password).expect("element")),
"textbox"
);
let hidden = document.create_element("input");
assert!(document.append_child(document.document_node_id(), hidden));
assert!(document.set_attribute(hidden, "type", "hidden"));
assert_eq!(ax_role(document.node(hidden).expect("element")), "none");
assert_eq!(
ax_role(&document, document.node(hidden).expect("element")),
"none"
);
}
}
+5 -1
View File
@@ -293,7 +293,11 @@ fn ax_node_payload(
};
let mut payload = AccessibilityNode::new(
AccessibilityNodeId::Dom(backend_node_id),
if ignored { "none" } else { ax_role(node) },
if ignored {
"none"
} else {
ax_role(document, node)
},
);
payload.ignored = ignored;
payload.name = (!name.is_empty()).then_some(name);
+2
View File
@@ -45,3 +45,5 @@ pub use validity::FormControlValidity;
#[cfg(test)]
mod tests;
pub(crate) use text::parse_html_integer_prefix;
+1 -1
View File
@@ -114,7 +114,7 @@ fn integer_prefix_digits(value: &str) -> &str {
&value[..end]
}
fn parse_html_integer_prefix(value: &str) -> Option<i32> {
pub(crate) fn parse_html_integer_prefix(value: &str) -> Option<i32> {
let value = value.trim_start_matches(|ch: char| ch.is_ascii_whitespace());
let mut chars = value.chars();
let (sign, rest) = match chars.next() {
+60 -2
View File
@@ -193,13 +193,12 @@ impl DomHost {
let already_exists = element.attributes().iter().any(|existing| {
existing.namespace() == attribute.namespace()
&& existing.local_name() == attribute.local_name()
&& existing.prefix() == attribute.prefix()
});
if !already_exists {
named_index_changed |= attribute.local_name().eq_ignore_ascii_case("id")
|| attribute.local_name().eq_ignore_ascii_case("name");
let attribute_changed = element.set_attribute(
let attribute_changed = element.set_attribute_ns(
attribute.local_name().to_owned(),
attribute.namespace().to_owned(),
attribute.prefix().map(str::to_owned),
@@ -247,6 +246,65 @@ mod tests {
))
}
#[test]
fn parser_attribute_merge_preserves_namespace_and_local_name_identity() {
let mut host = test_host();
let element = host.create_parser_element_without_attributes(
"a".to_owned(),
"http://www.w3.org/2000/svg".to_owned(),
None,
);
let xlink = "http://www.w3.org/1999/xlink";
let attribute = |namespace: &str, prefix: Option<&str>, value: &str| {
Attribute::new(
"href".to_owned(),
namespace.to_owned(),
prefix.map(str::to_owned),
value.to_owned(),
)
};
host.add_attrs_if_missing_for_parser(
element,
vec![
attribute("", None, "/primary"),
attribute(xlink, Some("xlink"), "/real"),
],
);
host.add_attrs_if_missing_for_parser(
element,
vec![
attribute(xlink, Some("alias"), "/must-not-replace"),
attribute("urn:example", None, "/foreign"),
],
);
for (namespace, expected) in [
("", "/primary"),
(xlink, "/real"),
("urn:example", "/foreign"),
] {
assert_eq!(
host.get_attribute_ns(element, Some(namespace), "href")
.as_deref(),
Some(expected)
);
}
let attributes = host
.node(element)
.unwrap()
.as_element()
.unwrap()
.attributes();
assert_eq!(attributes.len(), 3);
assert_eq!(
attributes
.iter()
.find(|attr| attr.namespace() == xlink)
.unwrap()
.prefix(),
Some("xlink")
);
}
#[test]
fn parser_element_without_attributes_keeps_parser_setup_separate_from_token_attrs() {
let mut host = test_host();
+137
View File
@@ -350,6 +350,143 @@ async fn semantic_dump_preserves_protocol_json_bytes_and_text_fields() -> Result
Ok(())
}
#[tokio::test]
async fn semantic_presentational_links_keep_native_roles_and_targets() -> Result<()> {
let (_browser, mut page, server) = load_page(
r#"<!doctype html><a href="/go" role="presentation">Go presentation</a>
<a href="/go" role="none" tabindex="-1">Go none</a>
<a href="/go" role="button">Explicit button</a>
<button role="presentation">Native button</button>"#,
)
.await?;
let (nodes, text) = semantic_nodes_and_text(&mut page).await?;
let target = page.final_url().join("/go")?;
for name in ["Go presentation", "Go none"] {
assert_semantic_target(&nodes, &text, name, "link", Some(target.as_str()), true);
}
assert_semantic_target(&nodes, &text, "Explicit button", "button", None, false);
assert_semantic_target(&nodes, &text, "Native button", "button", None, false);
server.abort();
Ok(())
}
#[tokio::test]
async fn semantic_url_trimming_preserves_unicode_path_data() -> Result<()> {
let (_browser, mut page, server) = load_page(
r#"<!doctype html><base href="/assets/">
<a href="&nbsp;">NBSP</a><a href=" &#x2003; ">EM space</a>
<a href="">Empty</a><a href=" &#x9;&#xA; ">HTML spaces</a>"#,
)
.await?;
let (nodes, text) = semantic_nodes_and_text(&mut page).await?;
for (name, path) in [
("NBSP", "/assets/%C2%A0"),
("EM space", "/assets/%E2%80%83"),
("Empty", "/assets/"),
("HTML spaces", "/assets/"),
] {
let target = page.final_url().join(path)?;
assert_semantic_target(&nodes, &text, name, "link", Some(target.as_str()), true);
}
server.abort();
Ok(())
}
#[tokio::test]
async fn semantic_svg_href_ignores_unrelated_namespaces() -> Result<()> {
let (_browser, mut page, server) = load_page(
r#"<!doctype html><base href="/assets/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<a id="legacy" xlink:href="/real" aria-label="Legacy"><text>Legacy</text></a>
<a id="primary" href="/primary" xlink:href="/real" aria-label="Primary"><text>Primary</text></a>
<a id="empty" href="" xlink:href="/real" aria-label="Empty SVG"><text>Empty</text></a>
<a id="foreign" role="link" aria-label="Foreign"><text>Foreign</text></a>
</svg>"#,
).await?;
let result = page.evaluate_runtime_expression_by_value_async(
"(() => { for (const node of document.querySelectorAll('svg a')) node.setAttributeNS('urn:example', 'href', '/wrong'); return document.getElementById('legacy').getAttributeNS('urn:example', 'href'); })()"
).await?;
assert_eq!(result["value"], "/wrong", "{result}");
let (nodes, text) = semantic_nodes_and_text(&mut page).await?;
for (name, path) in [
("Legacy", "/real"),
("Primary", "/primary"),
("Empty SVG", "/assets/"),
] {
let target = page.final_url().join(path)?;
assert_semantic_target(&nodes, &text, name, "link", Some(target.as_str()), true);
}
assert_semantic_target(&nodes, &text, "Foreign", "link", None, false);
server.abort();
Ok(())
}
#[tokio::test]
async fn semantic_mathml_links_do_not_invent_native_targets() -> Result<()> {
let (_browser, mut page, server) = load_page(
r#"<!doctype html><math><a role="link" href="/other" aria-label="Math reference">M</a></math>
<a href="/other">HTML reference</a>"#,
).await?;
let (nodes, text) = semantic_nodes_and_text(&mut page).await?;
assert_semantic_target(&nodes, &text, "Math reference", "link", None, false);
let target = page.final_url().join("/other")?;
assert_semantic_target(
&nodes,
&text,
"HTML reference",
"link",
Some(target.as_str()),
true,
);
server.abort();
Ok(())
}
async fn semantic_nodes_and_text(page: &mut Page) -> Result<(Vec<Value>, String)> {
let nodes = serde_json::from_str(&super::semantic::render_json(page, false).await?)?;
let text = super::semantic::render_text(page, false).await?;
Ok((nodes, text))
}
fn assert_semantic_target(
nodes: &[Value],
text: &str,
name: &str,
role: &str,
target: Option<&str>,
show_target: bool,
) {
let node = nodes
.iter()
.find(|node| node["name"]["value"] == name && node["role"]["value"] == role)
.unwrap_or_else(|| panic!("missing {role}: {name}: {text}"));
let urls = node["properties"]
.as_array()
.expect("AX properties")
.iter()
.filter(|property| property["name"] == "url")
.map(|property| property["value"]["value"].as_str().expect("AX URL"))
.collect::<Vec<_>>();
assert_eq!(
urls,
target.into_iter().collect::<Vec<_>>(),
"{role}: {name} URL"
);
let arrow = if show_target {
format!(" → {}", target.expect("link target"))
} else {
String::new()
};
let expected = format!(
"- {role}: {name}{arrow} [backendNodeId={}]",
node["backendDOMNodeId"]
);
assert!(
text.lines().any(|line| line.trim_start() == expected),
"missing {expected}: {text}"
);
}
#[tokio::test]
async fn semantic_link_urls_follow_computed_roles() -> Result<()> {
let (_browser, mut page, http_server) =