| 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" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } | 133 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 Widget* widget_ = nullptr; | 136 Widget* widget_ = nullptr; |
| 137 | 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); | 138 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 } // namespace | 141 } // namespace |
| 142 | 142 |
| 143 // Test that all methods in the NSAccessibility informal protocol can be called |
| 144 // on a retained accessibility object after the source view is deleted. |
| 145 TEST_F(NativeWidgetMacAccessibilityTest, Lifetime) { |
| 146 Textfield* view = AddChildTextfield(widget()->GetContentsView()->size()); |
| 147 base::scoped_nsobject<NSObject> ax_node(view->GetNativeViewAccessible(), |
| 148 base::scoped_policy::RETAIN); |
| 149 |
| 150 NSString* kAttribute = NSAccessibilityValueAttribute; |
| 151 NSString* kParamAttribute = |
| 152 NSAccessibilityStringForRangeParameterizedAttribute; |
| 153 NSString* kAction = NSAccessibilityShowMenuAction; |
| 154 |
| 155 EXPECT_TRUE( |
| 156 [[ax_node accessibilityAttributeNames] containsObject:kAttribute]); |
| 157 EXPECT_NSEQ(kTestStringValue, |
| 158 [ax_node accessibilityAttributeValue:kAttribute]); |
| 159 EXPECT_TRUE([ax_node accessibilityIsAttributeSettable:kAttribute]); |
| 160 EXPECT_TRUE([[ax_node accessibilityActionNames] containsObject:kAction]); |
| 161 EXPECT_FALSE([ax_node accessibilityIsIgnored]); |
| 162 |
| 163 // Not implemented, but be sure to update this test if it ever is. |
| 164 EXPECT_FALSE( |
| 165 [ax_node respondsToSelector:@selector(accessibilityActionDescription:)]); |
| 166 |
| 167 EXPECT_TRUE([[ax_node accessibilityParameterizedAttributeNames] |
| 168 containsObject:kParamAttribute]); |
| 169 NSValue* range = [NSValue valueWithRange:NSMakeRange(0, kTestStringLength)]; |
| 170 EXPECT_NSEQ( |
| 171 kTestStringValue, |
| 172 [ax_node accessibilityAttributeValue:kParamAttribute forParameter:range]); |
| 173 |
| 174 // The following is also "not implemented", but the informal protocol category |
| 175 // provides a default implementation. |
| 176 EXPECT_EQ(NSNotFound, static_cast<NSInteger>( |
| 177 [ax_node accessibilityIndexOfChild:ax_node])); |
| 178 |
| 179 // The only usually available array attribute is AXChildren, so go up a level |
| 180 // to the Widget to test that a bit. The default implementation just gets the |
| 181 // attribute normally and returns its size (if it's an array). |
| 182 NSString* kChildren = NSAccessibilityChildrenAttribute; |
| 183 base::scoped_nsobject<NSObject> ax_parent( |
| 184 [ax_node accessibilityAttributeValue:NSAccessibilityParentAttribute], |
| 185 base::scoped_policy::RETAIN); |
| 186 EXPECT_EQ(1u, [ax_parent accessibilityArrayAttributeCount:kChildren]); |
| 187 EXPECT_EQ( |
| 188 ax_node.get(), |
| 189 [ax_parent accessibilityArrayAttributeValues:kChildren index:0 |
| 190 maxCount:1][0]); |
| 191 |
| 192 // If it is not an array, the default implementation throws an exception, so |
| 193 // it's impossible to test these methods further on |ax_node|, apart from the |
| 194 // following, before deleting the view. |
| 195 EXPECT_EQ(0u, [ax_node accessibilityArrayAttributeCount:kChildren]); |
| 196 |
| 197 delete view; |
| 198 |
| 199 EXPECT_TRUE( |
| 200 [ax_node respondsToSelector:@selector(accessibilityAttributeNames)]); |
| 201 EXPECT_EQ(@[], [ax_node accessibilityAttributeNames]); |
| 202 EXPECT_EQ(nil, [ax_node accessibilityAttributeValue:kAttribute]); |
| 203 EXPECT_FALSE([ax_node accessibilityIsAttributeSettable:kAttribute]); |
| 204 [ax_node accessibilitySetValue:kTestStringValue forAttribute:kAttribute]; |
| 205 |
| 206 EXPECT_EQ(@[], [ax_node accessibilityActionNames]); |
| 207 [ax_node accessibilityPerformAction:kAction]; |
| 208 |
| 209 EXPECT_TRUE([ax_node accessibilityIsIgnored]); |
| 210 EXPECT_EQ(nil, [ax_node accessibilityHitTest:NSZeroPoint]); |
| 211 EXPECT_EQ(nil, [ax_node accessibilityFocusedUIElement]); |
| 212 |
| 213 EXPECT_EQ(@[], [ax_node accessibilityParameterizedAttributeNames]); |
| 214 EXPECT_NSEQ(nil, [ax_node accessibilityAttributeValue:kParamAttribute |
| 215 forParameter:range]); |
| 216 |
| 217 // Test the attributes with default implementations provided. |
| 218 EXPECT_EQ(NSNotFound, static_cast<NSInteger>( |
| 219 [ax_node accessibilityIndexOfChild:ax_node])); |
| 220 |
| 221 // The Widget is currently still around, but the child should be gone. |
| 222 EXPECT_EQ(0u, [ax_parent accessibilityArrayAttributeCount:kChildren]); |
| 223 } |
| 224 |
| 143 // Check that potentially keyboard-focusable elements are always leaf nodes. | 225 // Check that potentially keyboard-focusable elements are always leaf nodes. |
| 144 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { | 226 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { |
| 145 // LabelButtons will have a label inside the button. The label should be | 227 // LabelButtons will have a label inside the button. The label should be |
| 146 // ignored because the button is potentially keyboard focusable. | 228 // ignored because the button is potentially keyboard focusable. |
| 147 TestLabelButton* button = new TestLabelButton(); | 229 TestLabelButton* button = new TestLabelButton(); |
| 148 button->SetSize(widget()->GetContentsView()->size()); | 230 button->SetSize(widget()->GetContentsView()->size()); |
| 149 widget()->GetContentsView()->AddChildView(button); | 231 widget()->GetContentsView()->AddChildView(button); |
| 150 EXPECT_NSEQ(NSAccessibilityButtonRole, | 232 EXPECT_NSEQ(NSAccessibilityButtonRole, |
| 151 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); | 233 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); |
| 152 EXPECT_EQ( | 234 EXPECT_EQ( |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 combobox->SetSelectedIndex(1); | 851 combobox->SetSelectedIndex(1); |
| 770 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]); | 852 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]); |
| 771 | 853 |
| 772 // Expect to see both a press action and a show menu action. This matches | 854 // Expect to see both a press action and a show menu action. This matches |
| 773 // Cocoa behavior. | 855 // Cocoa behavior. |
| 774 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]), | 856 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]), |
| 775 [ax_node accessibilityActionNames]); | 857 [ax_node accessibilityActionNames]); |
| 776 } | 858 } |
| 777 | 859 |
| 778 } // namespace views | 860 } // namespace views |
| OLD | NEW |