| 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_node_data.h" | 13 #include "ui/accessibility/ax_node_data.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/button/label_button.h" |
| 17 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
| 18 #include "ui/views/controls/textfield/textfield.h" | 19 #include "ui/views/controls/textfield/textfield.h" |
| 19 #include "ui/views/test/widget_test.h" | 20 #include "ui/views/test/widget_test.h" |
| 20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 21 | 22 |
| 22 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. | 23 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. |
| 23 @interface AXPlatformNodeCocoa (Testing) | 24 @interface AXPlatformNodeCocoa (Testing) |
| 24 - (NSString*)AXRole; | 25 - (NSString*)AXRole; |
| 25 @end | 26 @end |
| 26 | 27 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } | 96 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } |
| 96 | 97 |
| 97 private: | 98 private: |
| 98 Widget* widget_ = nullptr; | 99 Widget* widget_ = nullptr; |
| 99 | 100 |
| 100 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); | 101 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); |
| 101 }; | 102 }; |
| 102 | 103 |
| 103 } // namespace | 104 } // namespace |
| 104 | 105 |
| 106 // Check that potentially keyboard-focusable elements are always leaf nodes. |
| 107 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { |
| 108 // LabelButtons will have a label inside the button. The label should be |
| 109 // ignored because the button is potentially keyboard focusable. |
| 110 LabelButton* button = |
| 111 new LabelButton(nullptr, base::SysNSStringToUTF16(kTestStringValue)); |
| 112 button->SetSize(widget()->GetContentsView()->size()); |
| 113 widget()->GetContentsView()->AddChildView(button); |
| 114 EXPECT_NSEQ(NSAccessibilityButtonRole, |
| 115 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); |
| 116 EXPECT_EQ( |
| 117 0u, |
| 118 [[button->GetNativeViewAccessible() |
| 119 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); |
| 120 } |
| 121 |
| 105 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored | 122 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored |
| 106 // children from the accessibility tree. | 123 // children from the accessibility tree. |
| 107 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { | 124 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { |
| 108 // Check childless views don't have accessibility children. | 125 // Check childless views don't have accessibility children. |
| 109 EXPECT_EQ(0u, | 126 EXPECT_EQ(0u, |
| 110 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); | 127 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); |
| 111 | 128 |
| 112 const size_t kNumChildren = 3; | 129 const size_t kNumChildren = 3; |
| 113 for (size_t i = 0; i < kNumChildren; ++i) { | 130 for (size_t i = 0; i < kNumChildren; ++i) { |
| 114 // Make sure the labels won't interfere with the hit test. | 131 // Make sure the labels won't interfere with the hit test. |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 forAttribute:NSAccessibilitySelectedTextAttribute]; | 424 forAttribute:NSAccessibilitySelectedTextAttribute]; |
| 408 EXPECT_NSEQ(new_string, | 425 EXPECT_NSEQ(new_string, |
| 409 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | 426 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); |
| 410 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | 427 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); |
| 411 // Make sure the cursor is at the end of the replacement. | 428 // Make sure the cursor is at the end of the replacement. |
| 412 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), | 429 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), |
| 413 textfield->GetSelectedRange()); | 430 textfield->GetSelectedRange()); |
| 414 } | 431 } |
| 415 | 432 |
| 416 } // namespace views | 433 } // namespace views |
| OLD | NEW |