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

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

Issue 2141013004: Mac a11y: Add Help, TopLevelUIElement, and Window accessibility attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test views without tooltips set. Created 4 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
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/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #import "testing/gtest_mac.h" 11 #import "testing/gtest_mac.h"
12 #include "ui/accessibility/ax_enums.h" 12 #include "ui/accessibility/ax_enums.h"
13 #include "ui/accessibility/ax_view_state.h" 13 #include "ui/accessibility/ax_view_state.h"
14 #import "ui/accessibility/platform/ax_platform_node_mac.h" 14 #import "ui/accessibility/platform/ax_platform_node_mac.h"
15 #include "ui/base/ime/text_input_type.h" 15 #include "ui/base/ime/text_input_type.h"
16 #import "ui/gfx/mac/coordinate_conversion.h" 16 #import "ui/gfx/mac/coordinate_conversion.h"
17 #include "ui/views/controls/label.h"
17 #include "ui/views/controls/textfield/textfield.h" 18 #include "ui/views/controls/textfield/textfield.h"
18 #include "ui/views/test/widget_test.h" 19 #include "ui/views/test/widget_test.h"
19 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
20 21
21 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. 22 // Expose some methods from AXPlatformNodeCocoa for testing purposes only.
22 @interface AXPlatformNodeCocoa (Testing) 23 @interface AXPlatformNodeCocoa (Testing)
23 - (NSString*)AXRole; 24 - (NSString*)AXRole;
24 @end 25 @end
25 26
26 namespace views { 27 namespace views {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 162
162 // Check the attribute is updated when the Widget is moved. 163 // Check the attribute is updated when the Widget is moved.
163 gfx::Rect new_bounds(60, 80, 100, 100); 164 gfx::Rect new_bounds(60, 80, 100, 100);
164 widget()->SetBounds(new_bounds); 165 widget()->SetBounds(new_bounds);
165 widget_origin = [NSValue 166 widget_origin = [NSValue
166 valueWithPoint:gfx::ScreenPointToNSPoint(new_bounds.bottom_left())]; 167 valueWithPoint:gfx::ScreenPointToNSPoint(new_bounds.bottom_left())];
167 EXPECT_NSEQ(widget_origin, 168 EXPECT_NSEQ(widget_origin,
168 AttributeValueAtMidpoint(NSAccessibilityPositionAttribute)); 169 AttributeValueAtMidpoint(NSAccessibilityPositionAttribute));
169 } 170 }
170 171
172 // Test for NSAccessibilityHelpAttribute.
173 TEST_F(NativeWidgetMacAccessibilityTest, HelpAttribute) {
174 Label* label = new Label(base::SysNSStringToUTF16(kTestPlaceholderText));
175 label->SetSize(GetWidgetBounds().size());
176 EXPECT_NSEQ(nil, AttributeValueAtMidpoint(NSAccessibilityHelpAttribute));
177 label->SetTooltipText(base::SysNSStringToUTF16(kTestPlaceholderText));
178 widget()->GetContentsView()->AddChildView(label);
179 EXPECT_NSEQ(kTestPlaceholderText,
180 AttributeValueAtMidpoint(NSAccessibilityHelpAttribute));
181 }
182
183 // Test for NSAccessibilityWindowAttribute and
184 // NSAccessibilityTopLevelUIElementAttribute.
185 TEST_F(NativeWidgetMacAccessibilityTest, WindowAndTopLevelUIElementAttributes) {
186 FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_GROUP);
187 widget()->GetContentsView()->AddChildView(view);
tapted 2016/07/18 03:38:49 will this be sized correctly to hit the view? (may
Patti Lor 2016/07/19 01:14:10 You're right, I forgot to size it! Have added this
188 EXPECT_NSEQ(widget()->GetNativeWindow(),
189 AttributeValueAtMidpoint(NSAccessibilityWindowAttribute));
190 EXPECT_NSEQ(
191 widget()->GetNativeWindow(),
192 AttributeValueAtMidpoint(NSAccessibilityTopLevelUIElementAttribute));
193 }
194
171 // Tests for accessibility attributes on a views::Textfield. 195 // Tests for accessibility attributes on a views::Textfield.
172 // TODO(patricialor): Test against Cocoa-provided attributes as well to ensure 196 // TODO(patricialor): Test against Cocoa-provided attributes as well to ensure
173 // consistency between Cocoa and toolkit-views. 197 // consistency between Cocoa and toolkit-views.
174 TEST_F(NativeWidgetMacAccessibilityTest, TextfieldGenericAttributes) { 198 TEST_F(NativeWidgetMacAccessibilityTest, TextfieldGenericAttributes) {
175 Textfield* textfield = AddChildTextfield(GetWidgetBounds().size()); 199 Textfield* textfield = AddChildTextfield(GetWidgetBounds().size());
176 200
177 // NSAccessibilityEnabledAttribute. 201 // NSAccessibilityEnabledAttribute.
178 textfield->SetEnabled(false); 202 textfield->SetEnabled(false);
179 EXPECT_EQ(NO, [AttributeValueAtMidpoint(NSAccessibilityEnabledAttribute) 203 EXPECT_EQ(NO, [AttributeValueAtMidpoint(NSAccessibilityEnabledAttribute)
180 boolValue]); 204 boolValue]);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 gfx::Range([AttributeValueAtMidpoint( 294 gfx::Range([AttributeValueAtMidpoint(
271 NSAccessibilitySelectedTextRangeAttribute) rangeValue])); 295 NSAccessibilitySelectedTextRangeAttribute) rangeValue]));
272 296
273 // NSAccessibilityVisibleCharacterRangeAttribute. 297 // NSAccessibilityVisibleCharacterRangeAttribute.
274 EXPECT_EQ(gfx::Range(0, kTestStringValue.length), 298 EXPECT_EQ(gfx::Range(0, kTestStringValue.length),
275 gfx::Range([AttributeValueAtMidpoint( 299 gfx::Range([AttributeValueAtMidpoint(
276 NSAccessibilityVisibleCharacterRangeAttribute) rangeValue])); 300 NSAccessibilityVisibleCharacterRangeAttribute) rangeValue]));
277 } 301 }
278 302
279 } // namespace views 303 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698