| 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/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 Loading... |
| 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 view->SetSize(GetWidgetBounds().size()); |
| 188 widget()->GetContentsView()->AddChildView(view); |
| 189 // Make sure it's |view| in the hit test by checking its accessibility role. |
| 190 EXPECT_EQ(NSAccessibilityGroupRole, |
| 191 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); |
| 192 EXPECT_NSEQ(widget()->GetNativeWindow(), |
| 193 AttributeValueAtMidpoint(NSAccessibilityWindowAttribute)); |
| 194 EXPECT_NSEQ( |
| 195 widget()->GetNativeWindow(), |
| 196 AttributeValueAtMidpoint(NSAccessibilityTopLevelUIElementAttribute)); |
| 197 } |
| 198 |
| 171 // Tests for accessibility attributes on a views::Textfield. | 199 // Tests for accessibility attributes on a views::Textfield. |
| 172 // TODO(patricialor): Test against Cocoa-provided attributes as well to ensure | 200 // TODO(patricialor): Test against Cocoa-provided attributes as well to ensure |
| 173 // consistency between Cocoa and toolkit-views. | 201 // consistency between Cocoa and toolkit-views. |
| 174 TEST_F(NativeWidgetMacAccessibilityTest, TextfieldGenericAttributes) { | 202 TEST_F(NativeWidgetMacAccessibilityTest, TextfieldGenericAttributes) { |
| 175 Textfield* textfield = AddChildTextfield(GetWidgetBounds().size()); | 203 Textfield* textfield = AddChildTextfield(GetWidgetBounds().size()); |
| 176 | 204 |
| 177 // NSAccessibilityEnabledAttribute. | 205 // NSAccessibilityEnabledAttribute. |
| 178 textfield->SetEnabled(false); | 206 textfield->SetEnabled(false); |
| 179 EXPECT_EQ(NO, [AttributeValueAtMidpoint(NSAccessibilityEnabledAttribute) | 207 EXPECT_EQ(NO, [AttributeValueAtMidpoint(NSAccessibilityEnabledAttribute) |
| 180 boolValue]); | 208 boolValue]); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 gfx::Range([AttributeValueAtMidpoint( | 298 gfx::Range([AttributeValueAtMidpoint( |
| 271 NSAccessibilitySelectedTextRangeAttribute) rangeValue])); | 299 NSAccessibilitySelectedTextRangeAttribute) rangeValue])); |
| 272 | 300 |
| 273 // NSAccessibilityVisibleCharacterRangeAttribute. | 301 // NSAccessibilityVisibleCharacterRangeAttribute. |
| 274 EXPECT_EQ(gfx::Range(0, kTestStringValue.length), | 302 EXPECT_EQ(gfx::Range(0, kTestStringValue.length), |
| 275 gfx::Range([AttributeValueAtMidpoint( | 303 gfx::Range([AttributeValueAtMidpoint( |
| 276 NSAccessibilityVisibleCharacterRangeAttribute) rangeValue])); | 304 NSAccessibilityVisibleCharacterRangeAttribute) rangeValue])); |
| 277 } | 305 } |
| 278 | 306 |
| 279 } // namespace views | 307 } // namespace views |
| OLD | NEW |