[go: nahoru, domu]

Create AXNodeData::SetNameChecked

There are two desires / expectations regarding AXNodeData::SetName:

1. Callers should call AXNodeData::SetNameExplicitlyEmpty rather than
   SetName to remove the accessible name (e.g. from a View).

2. Callers are expected to set a valid role prior to calling SetName.

With respect to the former, nothing enforces that. The latter is
now enforced by crrev.com/c/3816142. This change:

* Creates AXNodeData::SetNameChecked with DCHECKs for empty names
* Marks AXNodeData::SetName as deprecated

Follow-up changes will migrate Views from SetName to SetNameChecked,
fixing any unmet expectations in the process.

AX-Relnotes: n/a

Bug: 1348081
Change-Id: I610172ae339f767b1d430dc410ccf71e54e9d604
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3789984
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Reviewed-by: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1053061}
diff --git a/ui/accessibility/ax_node_data_unittest.cc b/ui/accessibility/ax_node_data_unittest.cc
index e7072fae..e3e3d8f 100644
--- a/ui/accessibility/ax_node_data_unittest.cc
+++ b/ui/accessibility/ax_node_data_unittest.cc
@@ -401,6 +401,10 @@
   EXPECT_EQ("baz", data.GetStringAttribute(ax::mojom::StringAttribute::kName));
   EXPECT_EQ(data.GetNameFrom(), ax::mojom::NameFrom::kContents);
 
+  // Setting the name to the empty string should not be done by
+  // `SetNameChecked`, which enforces that expectation with a DCHECK.
+  EXPECT_DCHECK_DEATH(data.SetNameChecked(""));
+
   data.SetNameExplicitlyEmpty();
   EXPECT_EQ("", data.GetStringAttribute(ax::mojom::StringAttribute::kName));
   EXPECT_EQ(data.GetNameFrom(), ax::mojom::NameFrom::kAttributeExplicitlyEmpty);