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/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" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #import "testing/gtest_mac.h" | 14 #import "testing/gtest_mac.h" |
15 #include "ui/accessibility/ax_enums.h" | 15 #include "ui/accessibility/ax_enums.h" |
16 #include "ui/accessibility/ax_node_data.h" | 16 #include "ui/accessibility/ax_node_data.h" |
17 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 17 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
18 #include "ui/base/ime/text_input_type.h" | 18 #include "ui/base/ime/text_input_type.h" |
19 #import "ui/gfx/mac/coordinate_conversion.h" | 19 #import "ui/gfx/mac/coordinate_conversion.h" |
20 #include "ui/views/controls/button/label_button.h" | 20 #include "ui/views/controls/button/label_button.h" |
| 21 #include "ui/views/controls/combobox/combobox.h" |
21 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
22 #include "ui/views/controls/textfield/textfield.h" | 23 #include "ui/views/controls/textfield/textfield.h" |
23 #include "ui/views/test/widget_test.h" | 24 #include "ui/views/test/widget_test.h" |
24 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
25 | 26 |
26 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. | 27 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. |
27 @interface AXPlatformNodeCocoa (Testing) | 28 @interface AXPlatformNodeCocoa (Testing) |
28 - (NSString*)AXRole; | 29 - (NSString*)AXRole; |
29 - (id)AXValue; | 30 - (id)AXValue; |
30 | 31 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 314 |
314 // Test accessibility clients can see subroles as well. | 315 // Test accessibility clients can see subroles as well. |
315 textfield->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 316 textfield->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
316 EXPECT_NSEQ(NSAccessibilitySecureTextFieldSubrole, | 317 EXPECT_NSEQ(NSAccessibilitySecureTextFieldSubrole, |
317 AttributeValueAtMidpoint(NSAccessibilitySubroleAttribute)); | 318 AttributeValueAtMidpoint(NSAccessibilitySubroleAttribute)); |
318 role_description = NSAccessibilityRoleDescription( | 319 role_description = NSAccessibilityRoleDescription( |
319 NSAccessibilityTextFieldRole, NSAccessibilitySecureTextFieldSubrole); | 320 NSAccessibilityTextFieldRole, NSAccessibilitySecureTextFieldSubrole); |
320 EXPECT_NSEQ(role_description, AttributeValueAtMidpoint( | 321 EXPECT_NSEQ(role_description, AttributeValueAtMidpoint( |
321 NSAccessibilityRoleDescriptionAttribute)); | 322 NSAccessibilityRoleDescriptionAttribute)); |
322 | 323 |
| 324 // Expect to see the action to show a context menu. |
| 325 EXPECT_NSEQ(@[ NSAccessibilityShowMenuAction ], |
| 326 [A11yElementAtMidpoint() accessibilityActionNames]); |
| 327 |
323 // Prevent the textfield from interfering with hit tests on the widget itself. | 328 // Prevent the textfield from interfering with hit tests on the widget itself. |
324 widget()->GetContentsView()->RemoveChildView(textfield); | 329 widget()->GetContentsView()->RemoveChildView(textfield); |
325 | 330 |
326 // NSAccessibilitySizeAttribute. | 331 // NSAccessibilitySizeAttribute. |
327 EXPECT_EQ(GetWidgetBounds().size(), | 332 EXPECT_EQ(GetWidgetBounds().size(), |
328 gfx::Size([AttributeValueAtMidpoint(NSAccessibilitySizeAttribute) | 333 gfx::Size([AttributeValueAtMidpoint(NSAccessibilitySizeAttribute) |
329 sizeValue])); | 334 sizeValue])); |
330 // Check the attribute is updated when the Widget is resized. | 335 // Check the attribute is updated when the Widget is resized. |
331 gfx::Size new_size(200, 40); | 336 gfx::Size new_size(200, 40); |
332 widget()->SetSize(new_size); | 337 widget()->SetSize(new_size); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 EXPECT_NSEQ(@"", [ax_node AXSelectedText]); | 731 EXPECT_NSEQ(@"", [ax_node AXSelectedText]); |
727 EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(0, 0)], | 732 EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(0, 0)], |
728 [ax_node AXSelectedTextRange]); | 733 [ax_node AXSelectedTextRange]); |
729 | 734 |
730 EXPECT_EQ(kTestStringLength, [[ax_node AXNumberOfCharacters] intValue]); | 735 EXPECT_EQ(kTestStringLength, [[ax_node AXNumberOfCharacters] intValue]); |
731 EXPECT_NSEQ(([NSValue valueWithRange:{0, kTestStringLength}]), | 736 EXPECT_NSEQ(([NSValue valueWithRange:{0, kTestStringLength}]), |
732 [ax_node AXVisibleCharacterRange]); | 737 [ax_node AXVisibleCharacterRange]); |
733 EXPECT_EQ(0, [[ax_node AXInsertionPointLineNumber] intValue]); | 738 EXPECT_EQ(0, [[ax_node AXInsertionPointLineNumber] intValue]); |
734 } | 739 } |
735 | 740 |
| 741 class TestComboboxModel : public ui::ComboboxModel { |
| 742 public: |
| 743 TestComboboxModel() = default; |
| 744 |
| 745 // ui::ComboboxModel: |
| 746 int GetItemCount() const override { return 2; } |
| 747 base::string16 GetItemAt(int index) override { |
| 748 return index == 0 ? base::SysNSStringToUTF16(kTestStringValue) |
| 749 : base::ASCIIToUTF16("Second Item"); |
| 750 } |
| 751 |
| 752 private: |
| 753 DISALLOW_COPY_AND_ASSIGN(TestComboboxModel); |
| 754 }; |
| 755 |
| 756 // Test a11y attributes of Comboboxes. |
| 757 TEST_F(NativeWidgetMacAccessibilityTest, Combobox) { |
| 758 Combobox* combobox = new Combobox(base::MakeUnique<TestComboboxModel>()); |
| 759 combobox->SetSize(GetWidgetBounds().size()); |
| 760 widget()->GetContentsView()->AddChildView(combobox); |
| 761 |
| 762 id ax_node = A11yElementAtMidpoint(); |
| 763 EXPECT_TRUE(ax_node); |
| 764 |
| 765 EXPECT_NSEQ(NSAccessibilityPopUpButtonRole, [ax_node AXRole]); |
| 766 |
| 767 // The initial value should be the first item in the menu. |
| 768 EXPECT_NSEQ(kTestStringValue, [ax_node AXValue]); |
| 769 combobox->SetSelectedIndex(1); |
| 770 EXPECT_NSEQ(@"Second Item", [ax_node AXValue]); |
| 771 |
| 772 // Expect to see both a press action and a show menu action. This matches |
| 773 // Cocoa behavior. |
| 774 EXPECT_NSEQ((@[ NSAccessibilityPressAction, NSAccessibilityShowMenuAction ]), |
| 775 [ax_node accessibilityActionNames]); |
| 776 } |
| 777 |
736 } // namespace views | 778 } // namespace views |
OLD | NEW |