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