OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <memory> | 5 #include <memory> |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #import "testing/gtest_mac.h" | 11 #import "testing/gtest_mac.h" |
12 #include "ui/accessibility/ax_enums.h" | 12 #include "ui/accessibility/ax_enums.h" |
13 #include "ui/accessibility/ax_node_data.h" | 13 #include "ui/accessibility/ax_node_data.h" |
14 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 14 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
15 #include "ui/base/ime/text_input_type.h" | 15 #include "ui/base/ime/text_input_type.h" |
16 #import "ui/gfx/mac/coordinate_conversion.h" | 16 #import "ui/gfx/mac/coordinate_conversion.h" |
17 #include "ui/views/controls/button/label_button.h" | |
17 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
18 #include "ui/views/controls/textfield/textfield.h" | 19 #include "ui/views/controls/textfield/textfield.h" |
19 #include "ui/views/test/widget_test.h" | 20 #include "ui/views/test/widget_test.h" |
20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
21 | 22 |
22 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. | 23 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. |
23 @interface AXPlatformNodeCocoa (Testing) | 24 @interface AXPlatformNodeCocoa (Testing) |
24 - (NSString*)AXRole; | 25 - (NSString*)AXRole; |
25 @end | 26 @end |
26 | 27 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } | 96 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } |
96 | 97 |
97 private: | 98 private: |
98 Widget* widget_ = nullptr; | 99 Widget* widget_ = nullptr; |
99 | 100 |
100 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); | 101 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); |
101 }; | 102 }; |
102 | 103 |
103 } // namespace | 104 } // namespace |
104 | 105 |
106 // Check that potentially keyboard-focusable elements are always leaf nodes. | |
107 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { | |
108 // LabelButtons will have a label inside the button. The label should be | |
109 // ignored because the button is potentially keyboard focusable. | |
110 LabelButton* button = | |
111 new LabelButton(nullptr, base::SysNSStringToUTF16(kTestStringValue)); | |
112 button->SetSize(widget()->GetContentsView()->size()); | |
113 widget()->GetContentsView()->AddChildView(button); | |
114 EXPECT_NSEQ(NSAccessibilityButtonRole, | |
115 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); | |
116 EXPECT_EQ( | |
117 0u, | |
118 [[button->GetNativeViewAccessible() | |
119 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); | |
120 | |
121 // 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.
| |
122 LabelButton* child_button = new LabelButton(nullptr, base::string16()); | |
123 // Make sure it's size 0 so we can hit test |button|. | |
124 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 -
| |
125 button->AddChildView(child_button); | |
126 EXPECT_EQ( | |
127 1u, | |
128 [[button->GetNativeViewAccessible() | |
129 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); | |
130 EXPECT_EQ(child_button->GetNativeViewAccessible(), | |
131 [[button->GetNativeViewAccessible() | |
132 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] | |
133 objectAtIndex:0]); | |
134 | |
135 // 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.
| |
136 child_button->SetEnabled(false); | |
137 EXPECT_EQ( | |
138 1u, | |
139 [[button->GetNativeViewAccessible() | |
140 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); | |
141 EXPECT_EQ(child_button->GetNativeViewAccessible(), | |
142 [[button->GetNativeViewAccessible() | |
143 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] | |
144 objectAtIndex:0]); | |
145 } | |
146 | |
105 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored | 147 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored |
106 // children from the accessibility tree. | 148 // children from the accessibility tree. |
107 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { | 149 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { |
108 // Check childless views don't have accessibility children. | 150 // Check childless views don't have accessibility children. |
109 EXPECT_EQ(0u, | 151 EXPECT_EQ(0u, |
110 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); | 152 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); |
111 | 153 |
112 const size_t kNumChildren = 3; | 154 const size_t kNumChildren = 3; |
113 for (size_t i = 0; i < kNumChildren; ++i) { | 155 for (size_t i = 0; i < kNumChildren; ++i) { |
114 // Make sure the labels won't interfere with the hit test. | 156 // Make sure the labels won't interfere with the hit test. |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 forAttribute:NSAccessibilitySelectedTextAttribute]; | 449 forAttribute:NSAccessibilitySelectedTextAttribute]; |
408 EXPECT_NSEQ(new_string, | 450 EXPECT_NSEQ(new_string, |
409 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | 451 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); |
410 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | 452 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); |
411 // Make sure the cursor is at the end of the replacement. | 453 // Make sure the cursor is at the end of the replacement. |
412 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), | 454 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), |
413 textfield->GetSelectedRange()); | 455 textfield->GetSelectedRange()); |
414 } | 456 } |
415 | 457 |
416 } // namespace views | 458 } // namespace views |
OLD | NEW |