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/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #import "testing/gtest_mac.h" | 14 #import "testing/gtest_mac.h" |
15 #include "ui/accessibility/ax_enums.h" | 15 #include "ui/accessibility/ax_enums.h" |
16 #include "ui/accessibility/ax_node_data.h" | 16 #include "ui/accessibility/ax_node_data.h" |
17 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 17 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
18 #include "ui/base/ime/text_input_type.h" | 18 #include "ui/base/ime/text_input_type.h" |
19 #import "ui/gfx/mac/coordinate_conversion.h" | 19 #import "ui/gfx/mac/coordinate_conversion.h" |
| 20 #include "ui/views/controls/button/label_button.h" |
20 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
21 #include "ui/views/controls/textfield/textfield.h" | 22 #include "ui/views/controls/textfield/textfield.h" |
22 #include "ui/views/test/widget_test.h" | 23 #include "ui/views/test/widget_test.h" |
23 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
24 | 25 |
25 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. | 26 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. |
26 @interface AXPlatformNodeCocoa (Testing) | 27 @interface AXPlatformNodeCocoa (Testing) |
27 - (NSString*)AXRole; | 28 - (NSString*)AXRole; |
28 @end | 29 @end |
29 | 30 |
(...skipping 30 matching lines...) Expand all Loading... |
60 return false; | 61 return false; |
61 } | 62 } |
62 | 63 |
63 private: | 64 private: |
64 ui::AXRole role_; | 65 ui::AXRole role_; |
65 bool mouse_was_pressed_ = false; | 66 bool mouse_was_pressed_ = false; |
66 | 67 |
67 DISALLOW_COPY_AND_ASSIGN(FlexibleRoleTestView); | 68 DISALLOW_COPY_AND_ASSIGN(FlexibleRoleTestView); |
68 }; | 69 }; |
69 | 70 |
| 71 class TestLabelButton : public LabelButton { |
| 72 public: |
| 73 TestLabelButton() : LabelButton(nullptr, base::string16()) { |
| 74 // Make sure the label doesn't cover the hit test co-ordinates. |
| 75 label()->SetSize(gfx::Size(1, 1)); |
| 76 } |
| 77 |
| 78 using LabelButton::label; |
| 79 |
| 80 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(TestLabelButton); |
| 82 }; |
| 83 |
70 class NativeWidgetMacAccessibilityTest : public test::WidgetTest { | 84 class NativeWidgetMacAccessibilityTest : public test::WidgetTest { |
71 public: | 85 public: |
72 NativeWidgetMacAccessibilityTest() {} | 86 NativeWidgetMacAccessibilityTest() {} |
73 | 87 |
74 void SetUp() override { | 88 void SetUp() override { |
75 test::WidgetTest::SetUp(); | 89 test::WidgetTest::SetUp(); |
76 widget_ = CreateTopLevelPlatformWidget(); | 90 widget_ = CreateTopLevelPlatformWidget(); |
77 widget_->SetBounds(gfx::Rect(50, 50, 100, 100)); | 91 widget_->SetBounds(gfx::Rect(50, 50, 100, 100)); |
78 widget()->Show(); | 92 widget()->Show(); |
79 } | 93 } |
(...skipping 28 matching lines...) Expand all Loading... |
108 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } | 122 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } |
109 | 123 |
110 private: | 124 private: |
111 Widget* widget_ = nullptr; | 125 Widget* widget_ = nullptr; |
112 | 126 |
113 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); | 127 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); |
114 }; | 128 }; |
115 | 129 |
116 } // namespace | 130 } // namespace |
117 | 131 |
| 132 // Check that potentially keyboard-focusable elements are always leaf nodes. |
| 133 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { |
| 134 // LabelButtons will have a label inside the button. The label should be |
| 135 // ignored because the button is potentially keyboard focusable. |
| 136 TestLabelButton* button = new TestLabelButton(); |
| 137 button->SetSize(widget()->GetContentsView()->size()); |
| 138 widget()->GetContentsView()->AddChildView(button); |
| 139 EXPECT_NSEQ(NSAccessibilityButtonRole, |
| 140 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); |
| 141 EXPECT_EQ( |
| 142 0u, |
| 143 [[button->GetNativeViewAccessible() |
| 144 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); |
| 145 |
| 146 // The exception is if the child is explicitly marked accessibility focusable. |
| 147 button->label()->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY); |
| 148 EXPECT_EQ( |
| 149 1u, |
| 150 [[button->GetNativeViewAccessible() |
| 151 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); |
| 152 EXPECT_EQ(button->label()->GetNativeViewAccessible(), |
| 153 [[button->GetNativeViewAccessible() |
| 154 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] |
| 155 objectAtIndex:0]); |
| 156 |
| 157 // If the child is disabled, it should still be traversable. |
| 158 button->label()->SetEnabled(false); |
| 159 EXPECT_EQ( |
| 160 1u, |
| 161 [[button->GetNativeViewAccessible() |
| 162 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); |
| 163 EXPECT_EQ(button->label()->GetNativeViewAccessible(), |
| 164 [[button->GetNativeViewAccessible() |
| 165 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] |
| 166 objectAtIndex:0]); |
| 167 } |
| 168 |
118 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored | 169 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored |
119 // children from the accessibility tree. | 170 // children from the accessibility tree. |
120 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { | 171 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { |
121 // Check childless views don't have accessibility children. | 172 // Check childless views don't have accessibility children. |
122 EXPECT_EQ(0u, | 173 EXPECT_EQ(0u, |
123 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); | 174 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); |
124 | 175 |
125 const size_t kNumChildren = 3; | 176 const size_t kNumChildren = 3; |
126 for (size_t i = 0; i < kNumChildren; ++i) { | 177 for (size_t i = 0; i < kNumChildren; ++i) { |
127 // Make sure the labels won't interfere with the hit test. | 178 // Make sure the labels won't interfere with the hit test. |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 565 |
515 for (NSString* attribute_name in expected_unsupported_attributes) { | 566 for (NSString* attribute_name in expected_unsupported_attributes) { |
516 SCOPED_TRACE(base::SysNSStringToUTF8([NSString | 567 SCOPED_TRACE(base::SysNSStringToUTF8([NSString |
517 stringWithFormat:@"Missing attribute is: %@", attribute_name])); | 568 stringWithFormat:@"Missing attribute is: %@", attribute_name])); |
518 EXPECT_FALSE([views_attributes containsObject:attribute_name]); | 569 EXPECT_FALSE([views_attributes containsObject:attribute_name]); |
519 EXPECT_FALSE([cocoa_attributes containsObject:attribute_name]); | 570 EXPECT_FALSE([cocoa_attributes containsObject:attribute_name]); |
520 } | 571 } |
521 } | 572 } |
522 | 573 |
523 } // namespace views | 574 } // namespace views |
OLD | NEW |