Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: ui/views/widget/native_widget_mac_accessibility_unittest.mm

Issue 2119413004: a11y: Exclude children of nested keyboard accessible controls from a11y tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/native_widget_mac_accessibility_unittest.mm
diff --git a/ui/views/widget/native_widget_mac_accessibility_unittest.mm b/ui/views/widget/native_widget_mac_accessibility_unittest.mm
index 24ffdb15515eaf214e3381c730dd42cf0d829efc..34f61e10abcc55953a2c82349d54506ac0d75f98 100644
--- a/ui/views/widget/native_widget_mac_accessibility_unittest.mm
+++ b/ui/views/widget/native_widget_mac_accessibility_unittest.mm
@@ -8,6 +8,7 @@
#include "base/mac/mac_util.h"
#import "base/mac/sdk_forward_declarations.h"
+#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
@@ -17,6 +18,7 @@
#import "ui/accessibility/platform/ax_platform_node_mac.h"
#include "ui/base/ime/text_input_type.h"
#import "ui/gfx/mac/coordinate_conversion.h"
+#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/widget_test.h"
@@ -67,6 +69,19 @@ class FlexibleRoleTestView : public View {
DISALLOW_COPY_AND_ASSIGN(FlexibleRoleTestView);
};
+class TestLabelButton : public LabelButton {
+ public:
+ TestLabelButton() : LabelButton(nullptr, base::string16()) {
+ // Make sure the label doesn't cover the hit test co-ordinates.
+ label()->SetSize(gfx::Size(1, 1));
+ }
+
+ using LabelButton::label;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestLabelButton);
+};
+
class NativeWidgetMacAccessibilityTest : public test::WidgetTest {
public:
NativeWidgetMacAccessibilityTest() {}
@@ -115,6 +130,43 @@ class NativeWidgetMacAccessibilityTest : public test::WidgetTest {
} // namespace
+// Check that potentially keyboard-focusable elements are always leaf nodes.
+TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) {
+ // LabelButtons will have a label inside the button. The label should be
+ // ignored because the button is potentially keyboard focusable.
+ TestLabelButton* button = new TestLabelButton();
+ button->SetSize(widget()->GetContentsView()->size());
+ widget()->GetContentsView()->AddChildView(button);
+ EXPECT_NSEQ(NSAccessibilityButtonRole,
+ AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
+ EXPECT_EQ(
+ 0u,
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]);
+
+ // The exception is if the child is explicitly marked accessibility focusable.
+ button->label()->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY);
+ EXPECT_EQ(
+ 1u,
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]);
+ EXPECT_EQ(button->label()->GetNativeViewAccessible(),
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute]
+ objectAtIndex:0]);
+
+ // If the child is disabled, it should still be traversable.
+ button->label()->SetEnabled(false);
+ EXPECT_EQ(
+ 1u,
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]);
+ EXPECT_EQ(button->label()->GetNativeViewAccessible(),
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute]
+ objectAtIndex:0]);
+}
+
// Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored
// children from the accessibility tree.
TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) {
« no previous file with comments | « ui/views/view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698