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) { |