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