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

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: Don't ignore children if they're accessibility focusable, regardless of enabled state. 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
« ui/views/view.h ('K') | « 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 3d641d190f9eab41fa0d4a97d726766736902263..24a9def68b8e6e039be69aeea926cbbbe8bd5bf3 100644
--- a/ui/views/widget/native_widget_mac_accessibility_unittest.mm
+++ b/ui/views/widget/native_widget_mac_accessibility_unittest.mm
@@ -14,6 +14,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"
@@ -102,6 +103,47 @@ 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.
+ LabelButton* button =
+ new LabelButton(nullptr, base::SysNSStringToUTF16(kTestStringValue));
+ 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.
tapted 2016/11/29 03:12:49 it seems odd to say this but to not call SetFocusB
Patti Lor 2016/11/29 23:26:18 Done.
+ LabelButton* child_button = new LabelButton(nullptr, base::string16());
+ // Make sure it's size 0 so we can hit test |button|.
+ child_button->SetSize(gfx::Size());
tapted 2016/11/29 03:12:49 Is there an neat alternative to setting the size t
Patti Lor 2016/11/29 23:26:18 Not sure, I think we could potentially use SetBoun
tapted 2016/11/29 23:43:20 yeah - I like this better. thanks.
Patti Lor 2016/11/30 05:13:25 Updated the comment to reflect the new size too -
+ button->AddChildView(child_button);
+ EXPECT_EQ(
+ 1u,
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]);
+ EXPECT_EQ(child_button->GetNativeViewAccessible(),
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute]
+ objectAtIndex:0]);
+
+ // If the child is disabled, it should still work.
tapted 2016/11/29 03:12:49 nit: work -> be traversable?
Patti Lor 2016/11/29 23:26:18 Done.
+ child_button->SetEnabled(false);
+ EXPECT_EQ(
+ 1u,
+ [[button->GetNativeViewAccessible()
+ accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]);
+ EXPECT_EQ(child_button->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/view.h ('K') | « ui/views/view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698