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

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

Issue 2969293002: Revert of Fix lifetime problems in AXPlatformNodeCocoa. (Closed)
Patch Set: 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* 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, [ax_node accessibilityIndexOfChild:nil]);
177
178 // The only usually available array attribute is AXChildren, so go up a level
179 // to the Widget to test that a bit. The default implementation just gets the
180 // attribute normally and returns its size (if it's an array).
181 NSString* kChildren = NSAccessibilityChildrenAttribute;
182 base::scoped_nsobject<NSObject> ax_parent(
183 [ax_node accessibilityAttributeValue:NSAccessibilityParentAttribute],
184 base::scoped_policy::RETAIN);
185 EXPECT_EQ(1u, [ax_parent accessibilityArrayAttributeCount:kChildren]);
186 EXPECT_EQ(
187 ax_node.get(),
188 [ax_parent accessibilityArrayAttributeValues:kChildren index:0
189 maxCount:1][0]);
190
191 // If it is not an array, the default implementation throws an exception, so
192 // it's impossible to test these methods further on |ax_node|, apart from the
193 // following, before deleting the view.
194 EXPECT_EQ(0u, [ax_node accessibilityArrayAttributeCount:kChildren]);
195
196 delete view;
197
198 EXPECT_TRUE(
199 [ax_node respondsToSelector:@selector(accessibilityAttributeNames)]);
200 EXPECT_EQ(@[], [ax_node accessibilityAttributeNames]);
201 EXPECT_EQ(nil, [ax_node accessibilityAttributeValue:kAttribute]);
202 EXPECT_FALSE([ax_node accessibilityIsAttributeSettable:kAttribute]);
203 [ax_node accessibilitySetValue:kTestStringValue forAttribute:kAttribute];
204
205 EXPECT_EQ(@[], [ax_node accessibilityActionNames]);
206 [ax_node accessibilityPerformAction:kAction];
207
208 EXPECT_TRUE([ax_node accessibilityIsIgnored]);
209 EXPECT_EQ(nil, [ax_node accessibilityHitTest:NSZeroPoint]);
210 EXPECT_EQ(nil, [ax_node accessibilityFocusedUIElement]);
211
212 EXPECT_EQ(@[], [ax_node accessibilityParameterizedAttributeNames]);
213 EXPECT_NSEQ(nil, [ax_node accessibilityAttributeValue:kParamAttribute
214 forParameter:range]);
215
216 // Test the attributes with default implementations provided.
217 EXPECT_EQ(NSNotFound, [ax_node accessibilityIndexOfChild:nil]);
218
219 // The Widget is currently still around, but the child should be gone.
220 EXPECT_EQ(0u, [ax_parent accessibilityArrayAttributeCount:kChildren]);
221 }
222
223 // Check that potentially keyboard-focusable elements are always leaf nodes. 143 // Check that potentially keyboard-focusable elements are always leaf nodes.
224 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { 144 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) {
225 // LabelButtons will have a label inside the button. The label should be 145 // LabelButtons will have a label inside the button. The label should be
226 // ignored because the button is potentially keyboard focusable. 146 // ignored because the button is potentially keyboard focusable.
227 TestLabelButton* button = new TestLabelButton(); 147 TestLabelButton* button = new TestLabelButton();
228 button->SetSize(widget()->GetContentsView()->size()); 148 button->SetSize(widget()->GetContentsView()->size());
229 widget()->GetContentsView()->AddChildView(button); 149 widget()->GetContentsView()->AddChildView(button);
230 EXPECT_NSEQ(NSAccessibilityButtonRole, 150 EXPECT_NSEQ(NSAccessibilityButtonRole,
231 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); 151 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
232 EXPECT_EQ( 152 EXPECT_EQ(
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 combobox->SetSelectedIndex(1); 769 combobox->SetSelectedIndex(1);
850 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]); 770 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]);
851 771
852 // Expect to see both a press action and a show menu action. This matches 772 // Expect to see both a press action and a show menu action. This matches
853 // Cocoa behavior. 773 // Cocoa behavior.
854 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]), 774 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]),
855 [ax_node accessibilityActionNames]); 775 [ax_node accessibilityActionNames]);
856 } 776 }
857 777
858 } // namespace views 778 } // 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