| 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_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/label.h" | 17 #include "ui/views/controls/label.h" |
| 18 #include "ui/views/controls/textfield/textfield.h" | 18 #include "ui/views/controls/textfield/textfield.h" |
| 19 #include "ui/views/test/widget_test.h" | 19 #include "ui/views/test/widget_test.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 | 21 |
| 22 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. | 22 // Expose some methods from AXPlatformNodeCocoa for testing purposes only. |
| 23 @interface AXPlatformNodeCocoa (Testing) | 23 @interface AXPlatformNodeCocoa (Testing) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 void set_role(ui::AXRole role) { role_ = role; } | 38 void set_role(ui::AXRole role) { role_ = role; } |
| 39 | 39 |
| 40 // Add a child view and resize to fit the child. | 40 // Add a child view and resize to fit the child. |
| 41 void FitBoundsToNewChild(View* view) { | 41 void FitBoundsToNewChild(View* view) { |
| 42 View::AddChildView(view); | 42 View::AddChildView(view); |
| 43 // Fit the parent widget to the size of the child for accurate hit tests. | 43 // Fit the parent widget to the size of the child for accurate hit tests. |
| 44 SetBoundsRect(view->bounds()); | 44 SetBoundsRect(view->bounds()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // View: | 47 // View: |
| 48 void GetAccessibleState(ui::AXViewState* state) override { | 48 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { |
| 49 View::GetAccessibleState(state); | 49 View::GetAccessibleNodeData(node_data); |
| 50 state->role = role_; | 50 node_data->role = role_; |
| 51 } | 51 } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 ui::AXRole role_; | 54 ui::AXRole role_; |
| 55 | 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(FlexibleRoleTestView); | 56 DISALLOW_COPY_AND_ASSIGN(FlexibleRoleTestView); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 class NativeWidgetMacAccessibilityTest : public test::WidgetTest { | 59 class NativeWidgetMacAccessibilityTest : public test::WidgetTest { |
| 60 public: | 60 public: |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 widget_origin = [NSValue | 166 widget_origin = [NSValue |
| 167 valueWithPoint:gfx::ScreenPointToNSPoint(new_bounds.bottom_left())]; | 167 valueWithPoint:gfx::ScreenPointToNSPoint(new_bounds.bottom_left())]; |
| 168 EXPECT_NSEQ(widget_origin, | 168 EXPECT_NSEQ(widget_origin, |
| 169 AttributeValueAtMidpoint(NSAccessibilityPositionAttribute)); | 169 AttributeValueAtMidpoint(NSAccessibilityPositionAttribute)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 // Test for NSAccessibilityHelpAttribute. | 172 // Test for NSAccessibilityHelpAttribute. |
| 173 TEST_F(NativeWidgetMacAccessibilityTest, HelpAttribute) { | 173 TEST_F(NativeWidgetMacAccessibilityTest, HelpAttribute) { |
| 174 Label* label = new Label(base::SysNSStringToUTF16(kTestPlaceholderText)); | 174 Label* label = new Label(base::SysNSStringToUTF16(kTestPlaceholderText)); |
| 175 label->SetSize(GetWidgetBounds().size()); | 175 label->SetSize(GetWidgetBounds().size()); |
| 176 EXPECT_NSEQ(nil, AttributeValueAtMidpoint(NSAccessibilityHelpAttribute)); | 176 EXPECT_NSEQ(@"", AttributeValueAtMidpoint(NSAccessibilityHelpAttribute)); |
| 177 label->SetTooltipText(base::SysNSStringToUTF16(kTestPlaceholderText)); | 177 label->SetTooltipText(base::SysNSStringToUTF16(kTestPlaceholderText)); |
| 178 widget()->GetContentsView()->AddChildView(label); | 178 widget()->GetContentsView()->AddChildView(label); |
| 179 EXPECT_NSEQ(kTestPlaceholderText, | 179 EXPECT_NSEQ(kTestPlaceholderText, |
| 180 AttributeValueAtMidpoint(NSAccessibilityHelpAttribute)); | 180 AttributeValueAtMidpoint(NSAccessibilityHelpAttribute)); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Test for NSAccessibilityWindowAttribute and | 183 // Test for NSAccessibilityWindowAttribute and |
| 184 // NSAccessibilityTopLevelUIElementAttribute. | 184 // NSAccessibilityTopLevelUIElementAttribute. |
| 185 TEST_F(NativeWidgetMacAccessibilityTest, WindowAndTopLevelUIElementAttributes) { | 185 TEST_F(NativeWidgetMacAccessibilityTest, WindowAndTopLevelUIElementAttributes) { |
| 186 FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_GROUP); | 186 FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_GROUP); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 forAttribute:NSAccessibilitySelectedTextAttribute]; | 376 forAttribute:NSAccessibilitySelectedTextAttribute]; |
| 377 EXPECT_NSEQ(new_string, | 377 EXPECT_NSEQ(new_string, |
| 378 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | 378 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); |
| 379 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | 379 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); |
| 380 // Make sure the cursor is at the end of the replacement. | 380 // Make sure the cursor is at the end of the replacement. |
| 381 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), | 381 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), |
| 382 textfield->GetSelectedRange()); | 382 textfield->GetSelectedRange()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace views | 385 } // namespace views |
| OLD | NEW |