Chromium Code Reviews| Index: ui/views/widget/native_widget_mac_accessibility_unittest.mm |
| diff --git a/ui/views/widget/native_widget_mac_accessibility_unittest.mm b/ui/views/widget/native_widget_mac_accessibility_unittest.mm |
| index d1958391749c7af098267155b7104dde4881cbf8..3a0fa0a3177687b31178e2e850406c8f539b06a1 100644 |
| --- a/ui/views/widget/native_widget_mac_accessibility_unittest.mm |
| +++ b/ui/views/widget/native_widget_mac_accessibility_unittest.mm |
| @@ -140,6 +140,79 @@ class NativeWidgetMacAccessibilityTest : public test::WidgetTest { |
| } // namespace |
| +// Test that all methods in the NSAccessibility informal protocol can be called |
| +// on a retained accessibility object after the source view is deleted. |
| +TEST_F(NativeWidgetMacAccessibilityTest, Lifetime) { |
| + Textfield* view = AddChildTextfield(widget()->GetContentsView()->size()); |
| + base::scoped_nsobject<NSObject> ax_node(view->GetNativeViewAccessible(), |
| + base::scoped_policy::RETAIN); |
| + |
| + NSString* kAttribute = NSAccessibilityValueAttribute; |
| + NSString* kAction = NSAccessibilityShowMenuAction; |
| + |
| + EXPECT_TRUE( |
| + [[ax_node accessibilityAttributeNames] containsObject:kAttribute]); |
| + EXPECT_NSEQ(kTestStringValue, |
| + [ax_node accessibilityAttributeValue:kAttribute]); |
| + EXPECT_TRUE([ax_node accessibilityIsAttributeSettable:kAttribute]); |
| + EXPECT_TRUE([[ax_node accessibilityActionNames] containsObject:kAction]); |
| + EXPECT_FALSE([ax_node accessibilityIsIgnored]); |
| + |
| + // Not implemented, but be sure to update this test if it ever is. |
| + EXPECT_FALSE( |
| + [ax_node respondsToSelector:@selector(accessibilityActionDescription:)]); |
| + |
| + // The following are also "not implemented", but the informal protocol |
| + // category provides a default implementation. |
| + EXPECT_EQ(NSNotFound, [ax_node accessibilityIndexOfChild:nil]); |
| + |
| + // Note: Test -accessibilityAttributeValue:forParameter: as well, if there |
| + // ever is a parameterized attribute. Otherwise it's impossible to call |
| + // without throwing an exception. |
| + EXPECT_EQ(@[], [ax_node accessibilityParameterizedAttributeNames]); |
|
tapted
2017/07/04 03:23:41
Since r482502 there now are parameterized attribut
|
| + |
| + // The only usually available array attribute is AXChildren, so go up a level |
| + // to the Widget to test that a bit. The default implementation just gets the |
| + // attribute normally and returns its size (if it's an array). |
| + NSString* kChildren = NSAccessibilityChildrenAttribute; |
| + base::scoped_nsobject<NSObject> ax_parent( |
| + [ax_node accessibilityAttributeValue:NSAccessibilityParentAttribute], |
| + base::scoped_policy::RETAIN); |
| + EXPECT_EQ(1u, [ax_parent accessibilityArrayAttributeCount:kChildren]); |
| + EXPECT_EQ( |
| + ax_node.get(), |
| + [ax_parent accessibilityArrayAttributeValues:kChildren index:0 |
| + maxCount:1][0]); |
| + |
| + // If it is not an array, the default implementation throws an exception, so |
| + // it's impossible to test these methods further on |ax_node|, apart from the |
| + // following, before deleting the view. |
| + EXPECT_EQ(0u, [ax_node accessibilityArrayAttributeCount:kChildren]); |
| + |
| + delete view; |
| + |
| + EXPECT_TRUE( |
| + [ax_node respondsToSelector:@selector(accessibilityAttributeNames)]); |
| + EXPECT_EQ(@[], [ax_node accessibilityAttributeNames]); |
| + EXPECT_EQ(nil, [ax_node accessibilityAttributeValue:kAttribute]); |
| + EXPECT_FALSE([ax_node accessibilityIsAttributeSettable:kAttribute]); |
| + [ax_node accessibilitySetValue:kTestStringValue forAttribute:kAttribute]; |
| + |
| + EXPECT_EQ(@[], [ax_node accessibilityActionNames]); |
| + [ax_node accessibilityPerformAction:kAction]; |
| + |
| + EXPECT_TRUE([ax_node accessibilityIsIgnored]); |
| + EXPECT_EQ(nil, [ax_node accessibilityHitTest:NSZeroPoint]); |
| + EXPECT_EQ(nil, [ax_node accessibilityFocusedUIElement]); |
| + |
| + // Test the attributes with default implementations provided. |
| + EXPECT_EQ(NSNotFound, [ax_node accessibilityIndexOfChild:nil]); |
| + EXPECT_EQ(@[], [ax_node accessibilityParameterizedAttributeNames]); |
| + |
| + // The Widget is currently still around, but the child should be gone. |
| + EXPECT_EQ(0u, [ax_parent accessibilityArrayAttributeCount:kChildren]); |
| +} |
| + |
| // Check that potentially keyboard-focusable elements are always leaf nodes. |
| TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { |
| // LabelButtons will have a label inside the button. The label should be |