[A11y] AX_FAIL_FAST_BUILD() as precompiled function
Avoids incorrect result when developer forgets to include ax_common.h.
Bug: none
Change-Id: Id7a4fe2213ea2db17b940c46d10a2069f50e6bf7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6068266
Reviewed-by: Jocelyn Tran <[email protected]>
Commit-Queue: Ken Buchanan <[email protected]>
Auto-Submit: Aaron Leventhal <[email protected]>
Reviewed-by: Ken Buchanan <[email protected]>
Reviewed-by: Nektarios Paisios <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1392519}
diff --git a/ui/accessibility/ax_common.h b/ui/accessibility/ax_common.h
index c8cfe2a..045da97 100644
--- a/ui/accessibility/ax_common.h
+++ b/ui/accessibility/ax_common.h
@@ -11,7 +11,9 @@
#if (DCHECK_IS_ON() || !defined(OFFICIAL_BUILD)) && BUILDFLAG(USE_BLINK)
// Enable fast fails on clusterfuzz and other builds used to debug Chrome,
// in order to help narrow down illegal states more quickly.
-#define AX_FAIL_FAST_BUILD
+#define AX_FAIL_FAST_BUILD() (1)
+#else
+#define AX_FAIL_FAST_BUILD() (0)
#endif
// SANITIZER_CHECK's use case is severe, but recoverable situations that need
@@ -20,7 +22,7 @@
// TODO(pbos): Transition callers to CHECK/NOTREACHED with base::NotFatalUntil
// parameters as that provides non-fatal ways of generating bug reports with
// better diagnostics until a problem has been resolved.
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD() && !DCHECK_IS_ON()
#define SANITIZER_CHECK(val) CHECK(val)
#define SANITIZER_CHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
#define SANITIZER_CHECK_NE(val1, val2) CHECK_NE(val1, val2)
@@ -48,6 +50,6 @@
#define SANITIZER_CHECK_GE(val1, val2) DCHECK_GE(val1, val2)
#define SANITIZER_CHECK_GT(val1, val2) DCHECK_GT(val1, val2)
#define SANITIZER_NOTREACHED() DCHECK(false)
-#endif // AX_FAIL_FAST_BUILD && !DCHECK_IS_ON()
+#endif // AX_FAIL_FAST_BUILD() && !DCHECK_IS_ON()
#endif // UI_ACCESSIBILITY_AX_COMMON_H_
diff --git a/ui/accessibility/ax_node.cc b/ui/accessibility/ax_node.cc
index 761c2d5f..d1df7a3 100644
--- a/ui/accessibility/ax_node.cc
+++ b/ui/accessibility/ax_node.cc
@@ -67,7 +67,7 @@
return children_.size();
}
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
size_t AXNode::GetSubtreeCount() const {
DCHECK(!tree_->GetTreeUpdateInProgressState());
size_t count = 1; // |this| counts as one.
@@ -76,7 +76,7 @@
}
return count;
}
-#endif // defined(AX_FAIL_FAST_BUILD)
+#endif // AX_FAIL_FAST_BUILD()
size_t AXNode::GetChildCountCrossingTreeBoundary() const {
DCHECK(!tree_->GetTreeUpdateInProgressState());
diff --git a/ui/accessibility/ax_node.h b/ui/accessibility/ax_node.h
index b23d175a..dff66d40 100644
--- a/ui/accessibility/ax_node.h
+++ b/ui/accessibility/ax_node.h
@@ -124,7 +124,7 @@
const std::vector<raw_ptr<AXNode, VectorExperimental>>& GetAllChildren()
const;
size_t GetChildCount() const;
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
size_t GetSubtreeCount() const;
#endif
size_t GetChildCountCrossingTreeBoundary() const;
diff --git a/ui/accessibility/ax_tree.cc b/ui/accessibility/ax_tree.cc
index 303e7e4..6f34a88e 100644
--- a/ui/accessibility/ax_tree.cc
+++ b/ui/accessibility/ax_tree.cc
@@ -1098,7 +1098,7 @@
}
bool AXTree::Unserialize(const AXTreeUpdate& update) {
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
for (const auto& new_data : update.nodes)
CHECK(new_data.id != kInvalidAXNodeID)
<< "AXTreeUpdate contains invalid node: " << update.ToString();
@@ -1107,7 +1107,7 @@
CHECK_EQ(update.tree_data.tree_id, data_.tree_id)
<< "Tree id mismatch between tree update and this tree.";
}
-#endif // defined(AX_FAIL_FAST_BUILD)
+#endif // AX_FAIL_FAST_BUILD()
event_data_ = std::make_unique<AXEvent>();
event_data_->event_from = update.event_from;
@@ -1469,14 +1469,14 @@
observers_.Notify(&AXTreeObserver::OnAtomicUpdateFinished, this,
root_->id() != old_root_id, changes);
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
CheckTreeConsistency(update);
#endif
return true;
}
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
void AXTree::CheckTreeConsistency(const AXTreeUpdate& update) {
// Return early if no expected node count was supplied.
if (!update.tree_checks || !update.tree_checks->node_count) {
@@ -1499,7 +1499,7 @@
NOTREACHED() << msg.str();
}
-#endif // defined(AX_FAIL_FAST_BUILD)
+#endif // AX_FAIL_FAST_BUILD()
AXTableInfo* AXTree::GetTableInfo(const AXNode* const_table_node) const {
DCHECK(!GetTreeUpdateInProgressState());
@@ -2888,7 +2888,7 @@
// Suppress fatal error logging in builds that target fuzzing, as fuzzers
// generate invalid trees by design to shake out bugs.
is_fatal = false;
-#elif defined(AX_FAIL_FAST_BUILD)
+#elif AX_FAIL_FAST_BUILD()
// In fast-failing-builds, crash immediately with a full message, otherwise
// rely on UnrecoverableAccessibilityError(), which will not crash until
// multiple errors occur.
diff --git a/ui/accessibility/ax_tree.h b/ui/accessibility/ax_tree.h
index d6efc60..f4254848 100644
--- a/ui/accessibility/ax_tree.h
+++ b/ui/accessibility/ax_tree.h
@@ -269,7 +269,7 @@
// `SetFocusedNodeShouldNeverBeIgnored` above).
static bool is_focused_node_always_unignored_;
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
void CheckTreeConsistency(const AXTreeUpdate& update);
#endif
diff --git a/ui/accessibility/ax_tree_manager.cc b/ui/accessibility/ax_tree_manager.cc
index c76e081..71fad7e 100644
--- a/ui/accessibility/ax_tree_manager.cc
+++ b/ui/accessibility/ax_tree_manager.cc
@@ -169,7 +169,7 @@
// static
void AXTreeManager::SetLastFocusedNode(AXNode* node) {
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
static auto* const ax_crash_key_focus = base::debug::AllocateCrashKeyString(
"ax_focus", base::debug::CrashKeySize::Size256);
#endif
@@ -184,7 +184,7 @@
// Only set specific focused node info in fail fast builds, in order to
// avoid extra processing for every focus move.
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
node_info_focus << node;
base::debug::SetCrashKeyString(ax_crash_key_focus, node_info_focus.str());
#endif
@@ -210,7 +210,7 @@
DCHECK(last_focused_node_tree_id_);
DCHECK(last_focused_node_tree_id_ != AXTreeIDUnknown());
} else {
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
base::debug::ClearCrashKeyString(ax_crash_key_focus);
#endif
base::debug::ClearCrashKeyString(ax_crash_key_focus_top_frame);
diff --git a/ui/accessibility/ax_tree_serializer.h b/ui/accessibility/ax_tree_serializer.h
index 2495a66..e9547ab6 100644
--- a/ui/accessibility/ax_tree_serializer.h
+++ b/ui/accessibility/ax_tree_serializer.h
@@ -147,7 +147,7 @@
// as explored by the serializer.
size_t ClientTreeNodeCount() const;
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
std::vector<AXNodeID> ClientTreeNodeIds() const;
AXSourceNode ParentOf(AXNodeID id);
@@ -386,7 +386,7 @@
return client_id_map_.size();
}
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
template <typename AXSourceNode,
typename AXSourceNodeVectorType,
typename AXTreeUpdateType,
@@ -421,7 +421,7 @@
}
return tree_->GetFromId(node->parent->id);
}
-#endif // defined(AX_FAIL_FAST_BUILD)
+#endif // AX_FAIL_FAST_BUILD()
template <typename AXSourceNode,
typename AXSourceNodeVectorType,
@@ -860,7 +860,7 @@
// caller makes it difficult to debug whether extra resets / lost virtual
// buffer positions are occurring because of this code. Therefore, a DCHECK
// has been added in order to debug if or when this condition may occur.
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
CHECK(!crash_on_error_)
<< "Attempt to delete entire client subtree, including the root.";
#else
diff --git a/ui/accessibility/ax_tree_unittest.cc b/ui/accessibility/ax_tree_unittest.cc
index 59cb682..533c3d8 100644
--- a/ui/accessibility/ax_tree_unittest.cc
+++ b/ui/accessibility/ax_tree_unittest.cc
@@ -468,7 +468,7 @@
update.node_id_to_clear = 2;
update.nodes.resize(1);
update.nodes[0].id = 3;
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
EXPECT_DEATH_IF_SUPPORTED(tree.Unserialize(update),
"Nodes left pending by the update: 2");
#else
@@ -499,7 +499,7 @@
update.nodes.resize(1);
update.nodes[0].id = 1;
update.nodes[0].child_ids.push_back(2);
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
EXPECT_DEATH_IF_SUPPORTED(tree.Unserialize(update),
"Nodes left pending by the update: 2");
#else
@@ -531,7 +531,7 @@
update.nodes[0].child_ids.push_back(2);
update.nodes[0].child_ids.push_back(2);
update.nodes[1].id = 2;
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
EXPECT_DEATH_IF_SUPPORTED(tree.Unserialize(update),
"Node 1 has duplicate child id 2");
#else
@@ -570,7 +570,7 @@
update.nodes[0].child_ids.push_back(2);
update.nodes[1].id = 2;
update.nodes[2].id = 3;
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
EXPECT_DEATH_IF_SUPPORTED(
tree.Unserialize(update),
"Node 3 is not marked for destruction, would be reparented to 1");
@@ -1263,7 +1263,7 @@
node2.child_ids.push_back(1);
initial_state.nodes.push_back(node2);
AXTree tree;
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
EXPECT_DEATH_IF_SUPPORTED(tree.Unserialize(initial_state),
"Node 1 has duplicate child id 1");
#else
@@ -1287,7 +1287,7 @@
initial_state.nodes.push_back(node2);
AXTree tree;
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
EXPECT_DEATH_IF_SUPPORTED(tree.Unserialize(initial_state),
"Node 1 has duplicate child id 2");
#else
@@ -5043,7 +5043,7 @@
AXNodeData disconnected_node;
disconnected_node.id = 2;
tree_update_3.nodes.push_back(disconnected_node);
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
EXPECT_DEATH_IF_SUPPORTED(
tree.Unserialize(tree_update_3),
"2 will not be in the tree and is not the new root");
diff --git a/ui/accessibility/platform/browser_accessibility_manager.cc b/ui/accessibility/platform/browser_accessibility_manager.cc
index 335da1c..16faeed 100644
--- a/ui/accessibility/platform/browser_accessibility_manager.cc
+++ b/ui/accessibility/platform/browser_accessibility_manager.cc
@@ -466,7 +466,7 @@
DCHECK(root_manager) << "Cannot have detached document here, as "
"CanFireEvents() must return false in that case.";
-#if defined(AX_FAIL_FAST_BUILD)
+#if AX_FAIL_FAST_BUILD()
AXTreeID parent_id = GetParentTreeID();
bool has_parent_id = parent_id != AXTreeIDUnknown();
BrowserAccessibilityManager* parent_manager =