| 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* kAction = NSAccessibilityShowMenuAction; |
| 152 |
| 153 EXPECT_TRUE( |
| 154 [[ax_node accessibilityAttributeNames] containsObject:kAttribute]); |
| 155 EXPECT_NSEQ(kTestStringValue, |
| 156 [ax_node accessibilityAttributeValue:kAttribute]); |
| 157 EXPECT_TRUE([ax_node accessibilityIsAttributeSettable:kAttribute]); |
| 158 EXPECT_TRUE([[ax_node accessibilityActionNames] containsObject:kAction]); |
| 159 EXPECT_FALSE([ax_node accessibilityIsIgnored]); |
| 160 |
| 161 // Not implemented, but be sure to update this test if it ever is. |
| 162 EXPECT_FALSE( |
| 163 [ax_node respondsToSelector:@selector(accessibilityActionDescription:)]); |
| 164 |
| 165 // The following are also "not implemented", but the informal protocol |
| 166 // category provides a default implementation. |
| 167 EXPECT_EQ(NSNotFound, [ax_node accessibilityIndexOfChild:nil]); |
| 168 |
| 169 // Note: Test -accessibilityAttributeValue:forParameter: as well, if there |
| 170 // ever is a parameterized attribute. Otherwise it's impossible to call |
| 171 // without throwing an exception. |
| 172 EXPECT_EQ(@[], [ax_node accessibilityParameterizedAttributeNames]); |
| 173 |
| 174 // The only usually available array attribute is AXChildren, so go up a level |
| 175 // to the Widget to test that a bit. The default implementation just gets the |
| 176 // attribute normally and returns its size (if it's an array). |
| 177 NSString* kChildren = NSAccessibilityChildrenAttribute; |
| 178 base::scoped_nsobject<NSObject> ax_parent( |
| 179 [ax_node accessibilityAttributeValue:NSAccessibilityParentAttribute], |
| 180 base::scoped_policy::RETAIN); |
| 181 EXPECT_EQ(1u, [ax_parent accessibilityArrayAttributeCount:kChildren]); |
| 182 EXPECT_EQ( |
| 183 ax_node.get(), |
| 184 [ax_parent accessibilityArrayAttributeValues:kChildren index:0 |
| 185 maxCount:1][0]); |
| 186 |
| 187 // If it is not an array, the default implementation throws an exception, so |
| 188 // it's impossible to test these methods further on |ax_node|, apart from the |
| 189 // following, before deleting the view. |
| 190 EXPECT_EQ(0u, [ax_node accessibilityArrayAttributeCount:kChildren]); |
| 191 |
| 192 delete view; |
| 193 |
| 194 EXPECT_TRUE( |
| 195 [ax_node respondsToSelector:@selector(accessibilityAttributeNames)]); |
| 196 EXPECT_EQ(@[], [ax_node accessibilityAttributeNames]); |
| 197 EXPECT_EQ(nil, [ax_node accessibilityAttributeValue:kAttribute]); |
| 198 EXPECT_FALSE([ax_node accessibilityIsAttributeSettable:kAttribute]); |
| 199 [ax_node accessibilitySetValue:kTestStringValue forAttribute:kAttribute]; |
| 200 |
| 201 EXPECT_EQ(@[], [ax_node accessibilityActionNames]); |
| 202 [ax_node accessibilityPerformAction:kAction]; |
| 203 |
| 204 EXPECT_TRUE([ax_node accessibilityIsIgnored]); |
| 205 EXPECT_EQ(nil, [ax_node accessibilityHitTest:NSZeroPoint]); |
| 206 EXPECT_EQ(nil, [ax_node accessibilityFocusedUIElement]); |
| 207 |
| 208 // Test the attributes with default implementations provided. |
| 209 EXPECT_EQ(NSNotFound, [ax_node accessibilityIndexOfChild:nil]); |
| 210 EXPECT_EQ(@[], [ax_node accessibilityParameterizedAttributeNames]); |
| 211 |
| 212 // The Widget is currently still around, but the child should be gone. |
| 213 EXPECT_EQ(0u, [ax_parent accessibilityArrayAttributeCount:kChildren]); |
| 214 } |
| 215 |
| 143 // Check that potentially keyboard-focusable elements are always leaf nodes. | 216 // Check that potentially keyboard-focusable elements are always leaf nodes. |
| 144 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { | 217 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { |
| 145 // LabelButtons will have a label inside the button. The label should be | 218 // LabelButtons will have a label inside the button. The label should be |
| 146 // ignored because the button is potentially keyboard focusable. | 219 // ignored because the button is potentially keyboard focusable. |
| 147 TestLabelButton* button = new TestLabelButton(); | 220 TestLabelButton* button = new TestLabelButton(); |
| 148 button->SetSize(widget()->GetContentsView()->size()); | 221 button->SetSize(widget()->GetContentsView()->size()); |
| 149 widget()->GetContentsView()->AddChildView(button); | 222 widget()->GetContentsView()->AddChildView(button); |
| 150 EXPECT_NSEQ(NSAccessibilityButtonRole, | 223 EXPECT_NSEQ(NSAccessibilityButtonRole, |
| 151 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); | 224 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); |
| 152 EXPECT_EQ( | 225 EXPECT_EQ( |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 combobox->SetSelectedIndex(1); | 774 combobox->SetSelectedIndex(1); |
| 702 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]); | 775 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]); |
| 703 | 776 |
| 704 // Expect to see both a press action and a show menu action. This matches | 777 // Expect to see both a press action and a show menu action. This matches |
| 705 // Cocoa behavior. | 778 // Cocoa behavior. |
| 706 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]), | 779 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]), |
| 707 [ax_node accessibilityActionNames]); | 780 [ax_node accessibilityActionNames]); |
| 708 } | 781 } |
| 709 | 782 |
| 710 } // namespace views | 783 } // namespace views |
| OLD | NEW |