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

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: Review comments. Created 4 years, 1 month 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
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 3d641d190f9eab41fa0d4a97d726766736902263..f3e72e9195cf6c2c4aa6c51dd9745ead19629064 100644
--- a/ui/views/widget/native_widget_mac_accessibility_unittest.mm
+++ b/ui/views/widget/native_widget_mac_accessibility_unittest.mm
@@ -6,6 +6,7 @@
#import <Cocoa/Cocoa.h>
+#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "testing/gtest_mac.h"
@@ -14,6 +15,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"
@@ -56,6 +58,20 @@ 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));
+ }
+
+ Label* GetLabel() { return LabelButton::label(); }
tapted 2016/11/30 05:23:17 try `using LabelButton::label;` here Then you sho
Patti Lor 2016/11/30 05:37:36 Sorry >< Made a mistake the first time around doin
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestLabelButton);
+};
+
+
class NativeWidgetMacAccessibilityTest : public test::WidgetTest {
public:
NativeWidgetMacAccessibilityTest() {}
@@ -102,6 +118,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->GetLabel()->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY);
+ EXPECT_EQ(
+ 1u,
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]);
+ EXPECT_EQ(button->GetLabel()->GetNativeViewAccessible(),
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute]
+ objectAtIndex:0]);
+
+ // If the child is disabled, it should be traversable.
tapted 2016/11/30 05:23:17 should be -> should still be
Patti Lor 2016/11/30 05:37:36 Done.
+ button->GetLabel()->SetEnabled(false);
+ EXPECT_EQ(
+ 1u,
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]);
+ EXPECT_EQ(button->GetLabel()->GetNativeViewAccessible(),
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute]
+ objectAtIndex:0]);
+}
+
// Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored
// children from the accessibility tree.
TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) {
« ui/views/accessibility/native_view_accessibility_unittest.cc ('K') | « ui/views/view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698