Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: ui/views/widget/native_widget_mac_accessibility_unittest.mm

Issue 2119413004: a11y: Exclude children of nested keyboard accessible controls from a11y tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix CrOS. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 EXPECT_NSEQ(NSAccessibilityButtonRole, 482 EXPECT_NSEQ(NSAccessibilityButtonRole,
431 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); 483 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
432 484
433 EXPECT_TRUE([[ax_node accessibilityActionNames] 485 EXPECT_TRUE([[ax_node accessibilityActionNames]
434 containsObject:NSAccessibilityPressAction]); 486 containsObject:NSAccessibilityPressAction]);
435 [ax_node accessibilityPerformAction:NSAccessibilityPressAction]; 487 [ax_node accessibilityPerformAction:NSAccessibilityPressAction];
436 EXPECT_TRUE(view->mouse_was_pressed()); 488 EXPECT_TRUE(view->mouse_was_pressed());
437 } 489 }
438 490
439 } // namespace views 491 } // namespace views
OLDNEW
« ui/views/accessibility/native_view_accessibility.cc ('K') | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698