Chromium Code Reviews| 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 Label* GetLabel() { return LabelButton::label(); } | |
|
tapted
2016/11/30 05:23:17
try `using LabelButton::label;` here
Then you sho
Patti Lor
2016/11/30 05:37:36
Sorry >< Made a mistake the first time around doin
| |
| 69 | |
| 70 private: | |
| 71 DISALLOW_COPY_AND_ASSIGN(TestLabelButton); | |
| 72 }; | |
| 73 | |
| 74 | |
| 59 class NativeWidgetMacAccessibilityTest : public test::WidgetTest { | 75 class NativeWidgetMacAccessibilityTest : public test::WidgetTest { |
| 60 public: | 76 public: |
| 61 NativeWidgetMacAccessibilityTest() {} | 77 NativeWidgetMacAccessibilityTest() {} |
| 62 | 78 |
| 63 void SetUp() override { | 79 void SetUp() override { |
| 64 test::WidgetTest::SetUp(); | 80 test::WidgetTest::SetUp(); |
| 65 widget_ = CreateTopLevelPlatformWidget(); | 81 widget_ = CreateTopLevelPlatformWidget(); |
| 66 widget_->SetBounds(gfx::Rect(50, 50, 100, 100)); | 82 widget_->SetBounds(gfx::Rect(50, 50, 100, 100)); |
| 67 widget()->Show(); | 83 widget()->Show(); |
| 68 } | 84 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 95 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } | 111 gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); } |
| 96 | 112 |
| 97 private: | 113 private: |
| 98 Widget* widget_ = nullptr; | 114 Widget* widget_ = nullptr; |
| 99 | 115 |
| 100 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); | 116 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest); |
| 101 }; | 117 }; |
| 102 | 118 |
| 103 } // namespace | 119 } // namespace |
| 104 | 120 |
| 121 // Check that potentially keyboard-focusable elements are always leaf nodes. | |
| 122 TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) { | |
| 123 // LabelButtons will have a label inside the button. The label should be | |
| 124 // ignored because the button is potentially keyboard focusable. | |
| 125 TestLabelButton* button = new TestLabelButton(); | |
| 126 button->SetSize(widget()->GetContentsView()->size()); | |
| 127 widget()->GetContentsView()->AddChildView(button); | |
| 128 EXPECT_NSEQ(NSAccessibilityButtonRole, | |
| 129 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); | |
| 130 EXPECT_EQ( | |
| 131 0u, | |
| 132 [[button->GetNativeViewAccessible() | |
| 133 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); | |
| 134 | |
| 135 // The exception is if the child is explicitly marked accessibility focusable. | |
| 136 button->GetLabel()->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY); | |
| 137 EXPECT_EQ( | |
| 138 1u, | |
| 139 [[button->GetNativeViewAccessible() | |
| 140 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); | |
| 141 EXPECT_EQ(button->GetLabel()->GetNativeViewAccessible(), | |
| 142 [[button->GetNativeViewAccessible() | |
| 143 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] | |
| 144 objectAtIndex:0]); | |
| 145 | |
| 146 // If the child is disabled, it should be traversable. | |
|
tapted
2016/11/30 05:23:17
should be -> should still be
Patti Lor
2016/11/30 05:37:36
Done.
| |
| 147 button->GetLabel()->SetEnabled(false); | |
| 148 EXPECT_EQ( | |
| 149 1u, | |
| 150 [[button->GetNativeViewAccessible() | |
| 151 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] count]); | |
| 152 EXPECT_EQ(button->GetLabel()->GetNativeViewAccessible(), | |
| 153 [[button->GetNativeViewAccessible() | |
| 154 accessibilityAttributeValue:NSAccessibilityChildrenAttribute] | |
| 155 objectAtIndex:0]); | |
| 156 } | |
| 157 | |
| 105 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored | 158 // Test for NSAccessibilityChildrenAttribute, and ensure it excludes ignored |
| 106 // children from the accessibility tree. | 159 // children from the accessibility tree. |
| 107 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { | 160 TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) { |
| 108 // Check childless views don't have accessibility children. | 161 // Check childless views don't have accessibility children. |
| 109 EXPECT_EQ(0u, | 162 EXPECT_EQ(0u, |
| 110 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); | 163 [AttributeValueAtMidpoint(NSAccessibilityChildrenAttribute) count]); |
| 111 | 164 |
| 112 const size_t kNumChildren = 3; | 165 const size_t kNumChildren = 3; |
| 113 for (size_t i = 0; i < kNumChildren; ++i) { | 166 for (size_t i = 0; i < kNumChildren; ++i) { |
| 114 // Make sure the labels won't interfere with the hit test. | 167 // 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]; | 460 forAttribute:NSAccessibilitySelectedTextAttribute]; |
| 408 EXPECT_NSEQ(new_string, | 461 EXPECT_NSEQ(new_string, |
| 409 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | 462 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); |
| 410 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | 463 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); |
| 411 // Make sure the cursor is at the end of the replacement. | 464 // Make sure the cursor is at the end of the replacement. |
| 412 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), | 465 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), |
| 413 textfield->GetSelectedRange()); | 466 textfield->GetSelectedRange()); |
| 414 } | 467 } |
| 415 | 468 |
| 416 } // namespace views | 469 } // namespace views |
| OLD | NEW |