| 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/string16.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #import "testing/gtest_mac.h" | 12 #import "testing/gtest_mac.h" |
| 12 #include "ui/accessibility/ax_enums.h" | 13 #include "ui/accessibility/ax_enums.h" |
| 13 #include "ui/accessibility/ax_node_data.h" | 14 #include "ui/accessibility/ax_node_data.h" |
| 14 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 15 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
| 15 #include "ui/base/ime/text_input_type.h" | 16 #include "ui/base/ime/text_input_type.h" |
| 16 #import "ui/gfx/mac/coordinate_conversion.h" | 17 #import "ui/gfx/mac/coordinate_conversion.h" |
| 18 #include "ui/views/controls/button/label_button.h" |
| 17 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 18 #include "ui/views/controls/textfield/textfield.h" | 20 #include "ui/views/controls/textfield/textfield.h" |
| 19 #include "ui/views/test/widget_test.h" | 21 #include "ui/views/test/widget_test.h" |
| 20 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 21 | 23 |
| 22 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. | 24 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. |
| 23 @interface AXPlatformNodeCocoa (Testing) | 25 @interface AXPlatformNodeCocoa (Testing) |
| 24 - (NSString*)AXRole; | 26 - (NSString*)AXRole; |
| 25 @end | 27 @end |
| 26 | 28 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 49 View::GetAccessibleNodeData(node_data); | 51 View::GetAccessibleNodeData(node_data); |
| 50 node_data->role = role_; | 52 node_data->role = role_; |
| 51 } | 53 } |
| 52 | 54 |
| 53 private: | 55 private: |
| 54 ui::AXRole role_; | 56 ui::AXRole role_; |
| 55 | 57 |
| 56 DISALLOW_COPY_AND_ASSIGN(FlexibleRoleTestView); | 58 DISALLOW_COPY_AND_ASSIGN(FlexibleRoleTestView); |
| 57 }; | 59 }; |
| 58 | 60 |
| 61 class TestLabelButton : public LabelButton { |
| 62 public: |
| 63 TestLabelButton() : LabelButton(nullptr, base::string16()) { |
| 64 // Make sure the label doesn't cover the hit test co-ordinates. |
| 65 label()->SetSize(gfx::Size(1, 1)); |
| 66 } |
| 67 |
| 68 using LabelButton::label; |
| 69 |
| 70 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(TestLabelButton); |
| 72 }; |
| 73 |
| 59 class NativeWidgetMacAccessibilityTest : public test::WidgetTest { | 74 class NativeWidgetMacAccessibilityTest : public test::WidgetTest { |
| 60 public: | 75 public: |
| 61 NativeWidgetMacAccessibilityTest() {} | 76 NativeWidgetMacAccessibilityTest() {} |
| 62 | 77 |
| 63 void SetUp() override { | 78 void SetUp() override { |
| 64 test::WidgetTest::SetUp(); | 79 test::WidgetTest::SetUp(); |
| 65 widget_ = CreateTopLevelPlatformWidget(); | 80 widget_ = CreateTopLevelPlatformWidget(); |
| 66 widget_->SetBounds(gfx::Rect(50, 50, 100, 100)); | 81 widget_->SetBounds(gfx::Rect(50, 50, 100, 100)); |
| 67 widget()->Show(); | 82 widget()->Show(); |
| 68 } | 83 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 95 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } | 110 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } |
| 96 | 111 |
| 97 private: | 112 private: |
| 98 Widget* widget_ = nullptr; | 113 Widget* widget_ = nullptr; |
| 99 | 114 |
| 100 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); | 115 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); |
| 101 }; | 116 }; |
| 102 | 117 |
| 103 } // namespace | 118 } // namespace |
| 104 | 119 |
| 120 // Check that potentially keyboard-focusable elements are always leaf nodes. |
| 121 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { |
| 122 // LabelButtons will have a label inside the button. The label should be |
| 123 // ignored because the button is potentially keyboard focusable. |
| 124 TestLabelButton* button = new TestLabelButton(); |
| 125 button->SetSize(widget()->GetContentsView()->size()); |
| 126 widget()->GetContentsView()->AddChildView(button); |
| 127 EXPECT_NSEQ(NSAccessibilityButtonRole, |
| 128 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); |
| 129 EXPECT_EQ( |
| 130 0u, |
| 131 [[button->GetNativeViewAccessible() |
| 132 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); |
| 133 |
| 134 // The exception is if the child is explicitly marked accessibility focusable. |
| 135 button->label()->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY); |
| 136 EXPECT_EQ( |
| 137 1u, |
| 138 [[button->GetNativeViewAccessible() |
| 139 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); |
| 140 EXPECT_EQ(button->label()->GetNativeViewAccessible(), |
| 141 [[button->GetNativeViewAccessible() |
| 142 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] |
| 143 objectAtIndex:0]); |
| 144 |
| 145 // If the child is disabled, it should still be traversable. |
| 146 button->label()->SetEnabled(false); |
| 147 EXPECT_EQ( |
| 148 1u, |
| 149 [[button->GetNativeViewAccessible() |
| 150 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); |
| 151 EXPECT_EQ(button->label()->GetNativeViewAccessible(), |
| 152 [[button->GetNativeViewAccessible() |
| 153 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] |
| 154 objectAtIndex:0]); |
| 155 } |
| 156 |
| 105 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored | 157 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored |
| 106 // children from the accessibility tree. | 158 // children from the accessibility tree. |
| 107 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { | 159 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { |
| 108 // Check childless views don't have accessibility children. | 160 // Check childless views don't have accessibility children. |
| 109 EXPECT_EQ(0u, | 161 EXPECT_EQ(0u, |
| 110 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); | 162 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); |
| 111 | 163 |
| 112 const size_t kNumChildren = 3; | 164 const size_t kNumChildren = 3; |
| 113 for (size_t i = 0; i < kNumChildren; ++i) { | 165 for (size_t i = 0; i < kNumChildren; ++i) { |
| 114 // Make sure the labels won't interfere with the hit test. | 166 // 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]; | 459 forAttribute:NSAccessibilitySelectedTextAttribute]; |
| 408 EXPECT_NSEQ(new_string, | 460 EXPECT_NSEQ(new_string, |
| 409 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | 461 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); |
| 410 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | 462 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); |
| 411 // Make sure the cursor is at the end of the replacement. | 463 // Make sure the cursor is at the end of the replacement. |
| 412 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), | 464 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), |
| 413 textfield->GetSelectedRange()); | 465 textfield->GetSelectedRange()); |
| 414 } | 466 } |
| 415 | 467 |
| 416 } // namespace views | 468 } // namespace views |
| OLD | NEW |