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

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

Issue 2944103005: Fix lifetime problems in AXPlatformNodeCocoa. (Closed)
Patch Set: rebase Created 3 years, 5 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
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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]);
tapted 2017/07/04 03:23:41 Since r482502 there now are parameterized attribut
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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 combobox->SetSelectedIndex(1); 842 combobox->SetSelectedIndex(1);
770 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]); 843 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]);
771 844
772 // Expect to see both a press action and a show menu action. This matches 845 // Expect to see both a press action and a show menu action. This matches
773 // Cocoa behavior. 846 // Cocoa behavior.
774 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]), 847 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]),
775 [ax_node accessibilityActionNames]); 848 [ax_node accessibilityActionNames]);
776 } 849 }
777 850
778 } // namespace views 851 } // namespace views
OLDNEW
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698