[go: up one dir, main page]

m96: Ensure that <math> is properly exposed when MathMLCore is disabled

After [1], the MathML <math> element is no longer exposed with role
ROLE_SYSTEM_EQUATION on MSAA, causing regressions for Windows
assistive technologies on Chrome 96. This CL restores the original check
in AXNodeObject::NativeRoleIgnoringAria when MathMLCore is disabled. It
also extends test mathml/math.html so that the role of the <math>
element is tested on Windows APIs; as well as when MathMLCore is
disabled.

Cherry picked from commits b7d91d91fc1cfd152880fbd83a28aa4d0a6765a6 and
ded169f97902cf3e59a01da3058462651cf650e4, but because the branch 4664
does not contain most of the MathML accessibility changes that happened
later, it is tweaked a bit:
- dump_accessibility_node_browsertest.cc: Rely on RunHtmlTest since
  RunMathMLTest does not exist. Add missing content_switches.h header to
  be able to use switches::kDisableBlinkFeatures.
- content/test/data/accessibility/mathml/math-disabled*: Related to the
  previous point, put these into content/test/data/accessibility/html/.
- content/test/data/accessibility/mathml/math-node-expected-win.txt: Do
  not add this expectation since mathml/math.html does not exist and
  this is not necessary to test the regression anyway.
- third_party/blink/renderer/modules/accessibility/ax_node_object.cc:
  Always do the check of namespace and local name by casting to an
  Element instance, since the section handling MathMLElement instances
  does not exist. This method works independently of whether MathMLCore
  is enabled or disabled.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/3168497

Bug: 1272563
Test: CI (math-disabled-node-expected-win.txt) and manually with JAWS/NVDA.
Change-Id: Ia39bee5d596b004594612f133bc860ba8b411c5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3298016
Commit-Queue: Frédéric Wang <fwang@igalia.com>
Reviewed-by: David Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/branch-heads/4664@{#1147}
Cr-Branched-From: 24dc4ee75e01a29d390d43c9c264372a169273a7-refs/heads/main@{#929512}
diff --git a/content/browser/accessibility/dump_accessibility_node_browsertest.cc b/content/browser/accessibility/dump_accessibility_node_browsertest.cc
index e1dd49b..eb61dd0a 100644
--- a/content/browser/accessibility/dump_accessibility_node_browsertest.cc
+++ b/content/browser/accessibility/dump_accessibility_node_browsertest.cc
@@ -5,6 +5,7 @@
 #include "base/files/file_util.h"
 #include "content/browser/accessibility/dump_accessibility_browsertest_base.h"
 #include "content/browser/web_contents/web_contents_impl.h"
+#include "content/public/common/content_switches.h"
 #include "content/public/test/browser_test.h"
 #include "content/public/test/content_browser_test_utils.h"
 #include "content/shell/browser/shell.h"
@@ -88,6 +89,16 @@
   }
 };
 
+class DumpAccessibilityNodeWithoutMathMLTest
+    : public DumpAccessibilityNodeTest {
+ public:
+  void SetUpCommandLine(base::CommandLine* command_line) override {
+    DumpAccessibilityNodeTest::SetUpCommandLine(command_line);
+    command_line->AppendSwitchASCII(switches::kDisableBlinkFeatures,
+                                    "MathMLCore");
+  }
+};
+
 class DumpAccessibilityAccNameTest : public DumpAccessibilityNodeTest {
  public:
   std::vector<ui::AXPropertyFilter> DefaultFilters() const override {
@@ -138,6 +149,12 @@
 
 INSTANTIATE_TEST_SUITE_P(
     All,
+    DumpAccessibilityNodeWithoutMathMLTest,
+    ::testing::ValuesIn(DumpAccessibilityTestHelper::TreeTestPasses()),
+    TestPassToString());
+
+INSTANTIATE_TEST_SUITE_P(
+    All,
     DumpAccessibilityAccNameTest,
     ::testing::ValuesIn(DumpAccessibilityTestHelper::TreeTestPasses()),
     TestPassToString());
@@ -153,6 +170,10 @@
   RunHtmlTest(FILE_PATH_LITERAL("table-th-colheader.html"));
 }
 
+IN_PROC_BROWSER_TEST_P(DumpAccessibilityNodeWithoutMathMLTest, MathMLMath) {
+  RunHtmlTest(FILE_PATH_LITERAL("math-disabled.html"));
+}
+
 // AccName tests.
 IN_PROC_BROWSER_TEST_P(DumpAccessibilityAccNameTest, DescComboboxFocusable) {
   RunAccNameTest(FILE_PATH_LITERAL("desc-combobox-focusable.html"));
diff --git a/content/test/data/accessibility/html/math-disabled-node-expected-auralinux.txt b/content/test/data/accessibility/html/math-disabled-node-expected-auralinux.txt
new file mode 100644
index 0000000..29eaf0d
--- /dev/null
+++ b/content/test/data/accessibility/html/math-disabled-node-expected-auralinux.txt
@@ -0,0 +1 @@
+[math] tag:math
diff --git a/content/test/data/accessibility/html/math-disabled-node-expected-blink.txt b/content/test/data/accessibility/html/math-disabled-node-expected-blink.txt
new file mode 100644
index 0000000..ede10ab
--- /dev/null
+++ b/content/test/data/accessibility/html/math-disabled-node-expected-blink.txt
@@ -0,0 +1 @@
+math
diff --git a/content/test/data/accessibility/html/math-disabled-node-expected-mac.txt b/content/test/data/accessibility/html/math-disabled-node-expected-mac.txt
new file mode 100644
index 0000000..4b732ad
--- /dev/null
+++ b/content/test/data/accessibility/html/math-disabled-node-expected-mac.txt
@@ -0,0 +1 @@
+AXGroup AXSubrole=AXDocumentMath
diff --git a/content/test/data/accessibility/html/math-disabled-node-expected-win.txt b/content/test/data/accessibility/html/math-disabled-node-expected-win.txt
new file mode 100644
index 0000000..3c7575c
--- /dev/null
+++ b/content/test/data/accessibility/html/math-disabled-node-expected-win.txt
@@ -0,0 +1 @@
+ROLE_SYSTEM_EQUATION
diff --git a/content/test/data/accessibility/html/math-disabled.html b/content/test/data/accessibility/html/math-disabled.html
new file mode 100644
index 0000000..6ffd736
--- /dev/null
+++ b/content/test/data/accessibility/html/math-disabled.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<!--
+@MAC-ALLOW:AXSubrole
+@AURALINUX-ALLOW:tag:*
+-->
+<math class="test">
+</math>
diff --git a/third_party/blink/renderer/modules/accessibility/ax_node_object.cc b/third_party/blink/renderer/modules/accessibility/ax_node_object.cc
index 002635dd..675ce0b 100644
--- a/third_party/blink/renderer/modules/accessibility/ax_node_object.cc
+++ b/third_party/blink/renderer/modules/accessibility/ax_node_object.cc
@@ -1051,8 +1051,15 @@
   if (GetNode()->HasTagName(html_names::kDtTag))
     return ax::mojom::blink::Role::kDescriptionListTerm;
 
-  if (GetNode()->HasTagName(mathml_names::kMathTag))
-    return ax::mojom::blink::Role::kMath;
+  // MathMLElement instances are not created when MathMLCore is disabled, so one
+  // cannot rely on Node::HasTagName(const MathMLQualifiedName&) to test the
+  // <math> tag. See crbug.com/1272556.
+  if (auto* element = DynamicTo<Element>(GetNode())) {
+    if (element->namespaceURI() == mathml_names::kNamespaceURI &&
+        element->nodeName() == mathml_names::kMathTag.LocalName()) {
+      return ax::mojom::blink::Role::kMath;
+    }
+  }
 
   if (GetNode()->HasTagName(html_names::kRpTag) ||
       GetNode()->HasTagName(html_names::kRtTag)) {