Commit 580b5530 authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

More accessibility browser tests include the HTML element in the tree

This is one more step towards enabling the flag
AccessibilityExposeHTMLElementEnabled to include the HTML element in the
accessibility tree.

Bug: 1063155
Change-Id: I3160bf5f9d39b46e2f7ff08ea81215ee7765e4eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441282
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813373}
parent 528c24cd
......@@ -221,9 +221,11 @@ class ImageAnnotationBrowserTest : public InProcessBrowserTest {
protected:
void SetUp() override {
scoped_feature_list_.InitWithFeatures(
std::vector<base::Feature>({features::kExperimentalAccessibilityLabels,
features::kAugmentExistingImageLabels}),
std::vector<base::Feature>({}));
std::vector<base::Feature>{
features::kEnableAccessibilityExposeHTMLElement,
features::kExperimentalAccessibilityLabels,
features::kAugmentExistingImageLabels},
std::vector<base::Feature>{});
InProcessBrowserTest::SetUp();
}
......
......@@ -28,6 +28,7 @@
#include "content/public/test/content_browser_test_utils.h"
#include "content/shell/browser/shell.h"
#include "third_party/blink/public/common/features.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/accessibility/accessibility_switches.h"
#include "ui/accessibility/ax_node.h"
#include "ui/accessibility/ax_tree.h"
......@@ -64,7 +65,7 @@ class CrossPlatformAccessibilityBrowserTest : public ContentBrowserTest {
RecursiveAssertUniqueIds(child, ids);
}
// ContentBrowserTest
void SetUp() override;
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
......@@ -77,6 +78,10 @@ class CrossPlatformAccessibilityBrowserTest : public ContentBrowserTest {
}
protected:
// Choose which feature flags to enable or disable.
virtual void ChooseFeatures(std::vector<base::Feature>* enabled_features,
std::vector<base::Feature>* disabled_features);
void LoadInitialAccessibilityTreeFromUrl(
const GURL& url,
ui::AXMode accessibility_mode = ui::kAXModeComplete) {
......@@ -139,6 +144,8 @@ class CrossPlatformAccessibilityBrowserTest : public ContentBrowserTest {
bool GetBoolAttr(const ui::AXNode* node, const ax::mojom::BoolAttribute attr);
private:
base::test::ScopedFeatureList scoped_feature_list_;
#if defined(OS_WIN)
std::unique_ptr<base::win::ScopedCOMInitializer> com_initializer_;
#endif
......@@ -146,6 +153,28 @@ class CrossPlatformAccessibilityBrowserTest : public ContentBrowserTest {
DISALLOW_COPY_AND_ASSIGN(CrossPlatformAccessibilityBrowserTest);
};
void CrossPlatformAccessibilityBrowserTest::SetUp() {
std::vector<base::Feature> enabled_features;
std::vector<base::Feature> disabled_features;
ChooseFeatures(&enabled_features, &disabled_features);
scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features);
// The <input type="color"> popup tested in
// AccessibilityInputColorWithPopupOpen requires the ability to read pixels
// from a Canvas, so we need to be able to produce pixel output.
EnablePixelOutput();
ContentBrowserTest::SetUp();
}
void CrossPlatformAccessibilityBrowserTest::ChooseFeatures(
std::vector<base::Feature>* enabled_features,
std::vector<base::Feature>* disabled_features) {
enabled_features->emplace_back(
features::kEnableAccessibilityExposeHTMLElement);
}
void CrossPlatformAccessibilityBrowserTest::SetUpOnMainThread() {
#if defined(OS_WIN)
ui::win::CreateATLModuleIfNeeded();
......@@ -936,14 +965,16 @@ IN_PROC_BROWSER_TEST_F(
const char url_str[] =
"data:text/html,"
"<!doctype html>"
"<fieldset>"
"<input type='text' placeholder='placeholder'>"
"<input type='text' placeholder='placeholder' aria-label='label'>";
"<input type='text' placeholder='placeholder' aria-label='label'>"
"</fieldset>";
GURL url(url_str);
EXPECT_TRUE(NavigateToURL(shell(), url));
const ui::AXTree& tree = GetAXTree();
const ui::AXNode* root = tree.root();
const ui::AXNode* group = root->children().front();
const ui::AXNode* group = root->GetUnignoredChildAtIndex(0);
const ui::AXNode* input1 = group->children()[0];
const ui::AXNode* input2 = group->children()[1];
......@@ -1387,14 +1418,12 @@ IN_PROC_BROWSER_TEST_F(CrossPlatformAccessibilityBrowserTest,
class CrossPlatformAccessibilityBrowserTestWithImplicitRootScrolling
: public CrossPlatformAccessibilityBrowserTest {
void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(
blink::features::kImplicitRootScroller);
CrossPlatformAccessibilityBrowserTest::SetUp();
void ChooseFeatures(std::vector<base::Feature>* enabled_features,
std::vector<base::Feature>* disabled_features) override {
enabled_features->emplace_back(blink::features::kImplicitRootScroller);
CrossPlatformAccessibilityBrowserTest::ChooseFeatures(enabled_features,
disabled_features);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(
......
......@@ -210,7 +210,7 @@ void AXImageAnnotator::MarkDirty(const blink::WebAXObject& image) const {
blink::WebAXObject parent = image.ParentObject();
for (int ancestor_count = 0; !parent.IsDetached() && ancestor_count < 2;
parent = parent.ParentObject()) {
if (parent.AccessibilityIsIncludedInTree()) {
if (!parent.AccessibilityIsIgnored()) {
++ancestor_count;
if (parent.Role() == ax::mojom::Role::kLink ||
parent.Role() == ax::mojom::Role::kRootWebArea) {
......
......@@ -340,15 +340,9 @@ class RenderAccessibilityImplTest : public RenderViewTest {
void SetUp() override {
RenderViewTest::SetUp();
// These flags are enabled in the parent class to make the testing
// environment match the Blink one. But there are some accessibility flags
// that cause some of the tests here to fail such as:
// SendFullAccessibilityTreeOnReload, ShowAccessibilityObject, and
// HideAccessibilityObject. Disabling these flags for now to keep the
// behavior the same as production for these tests. Ideally someone with the
// domain knowledge here should be able keep these features enabled.
blink::WebRuntimeFeatures::EnableExperimentalFeatures(false);
blink::WebRuntimeFeatures::EnableTestOnlyFeatures(false);
blink::WebRuntimeFeatures::EnableAccessibilityExposeHTMLElement(true);
sink_ = &render_thread_->sink();
......@@ -430,7 +424,7 @@ TEST_F(RenderAccessibilityImplTest, SendFullAccessibilityTreeOnReload) {
)HTML";
LoadHTMLAndRefreshAccessibilityTree(html);
EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser());
EXPECT_EQ(6, CountAccessibilityNodesSentToBrowser());
// If we post another event but the tree doesn't change,
// we should only send 1 node to the browser.
......@@ -457,7 +451,7 @@ TEST_F(RenderAccessibilityImplTest, SendFullAccessibilityTreeOnReload) {
GetRenderAccessibilityImpl()->HandleAXEvent(
ui::AXEvent(root_obj.AxID(), ax::mojom::Event::kLayoutComplete));
SendPendingAccessibilityEvents();
EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser());
EXPECT_EQ(6, CountAccessibilityNodesSentToBrowser());
// Even if the first event is sent on an element other than
// the root, the whole tree should be updated because we know
......@@ -470,7 +464,7 @@ TEST_F(RenderAccessibilityImplTest, SendFullAccessibilityTreeOnReload) {
GetRenderAccessibilityImpl()->HandleAXEvent(
ui::AXEvent(first_child.AxID(), ax::mojom::Event::kLiveRegionChanged));
SendPendingAccessibilityEvents();
EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser());
EXPECT_EQ(6, CountAccessibilityNodesSentToBrowser());
}
TEST_F(RenderAccessibilityImplTest, TestDeferred) {
......@@ -544,11 +538,12 @@ TEST_F(RenderAccessibilityImplTest, HideAccessibilityObject) {
</body>
)HTML");
EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser());
EXPECT_EQ(6, CountAccessibilityNodesSentToBrowser());
WebDocument document = GetMainFrame()->GetDocument();
WebAXObject root_obj = WebAXObject::FromWebDocument(document);
WebAXObject body = root_obj.ChildAt(0);
WebAXObject html = root_obj.ChildAt(0);
WebAXObject body = html.ChildAt(0);
WebAXObject node_a = body.ChildAt(0);
WebAXObject node_b = node_a.ChildAt(0);
WebAXObject node_c = node_b.ChildAt(0);
......@@ -593,11 +588,12 @@ TEST_F(RenderAccessibilityImplTest, ShowAccessibilityObject) {
</body>
)HTML");
EXPECT_EQ(5, CountAccessibilityNodesSentToBrowser());
EXPECT_EQ(6, CountAccessibilityNodesSentToBrowser());
WebDocument document = GetMainFrame()->GetDocument();
WebAXObject root_obj = WebAXObject::FromWebDocument(document);
WebAXObject body = root_obj.ChildAt(0);
WebAXObject html = root_obj.ChildAt(0);
WebAXObject body = html.ChildAt(0);
WebAXObject node_a = body.ChildAt(0);
WebAXObject node_b = node_a.ChildAt(0);
WebAXObject node_c = node_b.ChildAt(0);
......@@ -769,7 +765,8 @@ TEST_F(RenderAccessibilityImplTest, TestFocusConsistency) {
WebDocument document = GetMainFrame()->GetDocument();
WebAXObject root_obj = WebAXObject::FromWebDocument(document);
WebAXObject body = root_obj.ChildAt(0);
WebAXObject html_elem = root_obj.ChildAt(0);
WebAXObject body = html_elem.ChildAt(0);
WebAXObject link = body.ChildAt(0);
WebAXObject button = body.ChildAt(1);
......@@ -943,7 +940,8 @@ TEST_F(BlinkAXActionTargetTest, TestMethods) {
WebDocument document = GetMainFrame()->GetDocument();
WebAXObject root_obj = WebAXObject::FromWebDocument(document);
WebAXObject body = root_obj.ChildAt(0);
WebAXObject html_elem = root_obj.ChildAt(0);
WebAXObject body = html_elem.ChildAt(0);
WebAXObject input_checkbox = body.ChildAt(0);
WebAXObject input_range = body.ChildAt(1);
WebAXObject input_text = body.ChildAt(2);
......
......@@ -10,6 +10,16 @@
function printNodes(nodes) {
function printNodeAndChildren(node, leadingSpace = "") {
// TODO(crbug.com/1063155): remove this workaround when
// RuntimeEnabledFeatures::AccessibilityExposeHTMLElementEnabled()
// is enabled everywhere.
if (node.role.value == "generic" &&
node.parent.role.value == "WebArea" &&
node.children.length == 1 &&
node.children[0].role.value == "generic") {
return printNodeAndChildren(node.children[0], leadingSpace);
}
let string = leadingSpace;
if (node.role)
string += node.role.value;
......
......@@ -2,6 +2,16 @@
function dumpAccessibilityNodes(nodes) {
function printNodeAndChildren(node, leadingSpace = "") {
// TODO(crbug.com/1063155): remove this workaround when
// RuntimeEnabledFeatures::AccessibilityExposeHTMLElementEnabled()
// is enabled everywhere.
if (node.role.value == "generic" &&
node.parent.role.value == "WebArea" &&
node.children.length == 1 &&
node.children[0].role.value == "generic") {
return printNodeAndChildren(node.children[0], leadingSpace);
}
let string = leadingSpace;
if (node.role)
string += node.role.value;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment