| 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" |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 new_string = base::SysUTF16ToNSString(front + replacement + back); | 411 new_string = base::SysUTF16ToNSString(front + replacement + back); |
| 412 textfield->SelectRange(test_range); | 412 textfield->SelectRange(test_range); |
| 413 [ax_node accessibilitySetValue:base::SysUTF16ToNSString(replacement) | 413 [ax_node accessibilitySetValue:base::SysUTF16ToNSString(replacement) |
| 414 forAttribute:NSAccessibilitySelectedTextAttribute]; | 414 forAttribute:NSAccessibilitySelectedTextAttribute]; |
| 415 EXPECT_NSEQ(new_string, | 415 EXPECT_NSEQ(new_string, |
| 416 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | 416 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); |
| 417 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | 417 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); |
| 418 // Make sure the cursor is at the end of the replacement. | 418 // Make sure the cursor is at the end of the replacement. |
| 419 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), | 419 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), |
| 420 textfield->GetSelectedRange()); | 420 textfield->GetSelectedRange()); |
| 421 |
| 422 // Check it's not possible to change the selection range when read-only. Note |
| 423 // that this behavior is inconsistent with Cocoa - selections can be set via |
| 424 // a11y in selectable NSTextfields (unless they are password fields). |
| 425 // https://crbug.com/692362 |
| 426 textfield->SetReadOnly(true); |
| 427 EXPECT_FALSE([ax_node accessibilityIsAttributeSettable: |
| 428 NSAccessibilitySelectedTextRangeAttribute]); |
| 429 textfield->SetReadOnly(false); |
| 430 EXPECT_TRUE([ax_node accessibilityIsAttributeSettable: |
| 431 NSAccessibilitySelectedTextRangeAttribute]); |
| 432 |
| 433 // Change the selection to a valid range within the text. |
| 434 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(2, 5)] |
| 435 forAttribute:NSAccessibilitySelectedTextRangeAttribute]; |
| 436 EXPECT_EQ(gfx::Range(2, 7), textfield->GetSelectedRange()); |
| 437 // If the length is longer than the value length, default to the max possible. |
| 438 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(0, 1000)] |
| 439 forAttribute:NSAccessibilitySelectedTextRangeAttribute]; |
| 440 EXPECT_EQ(gfx::Range(0, textfield->text().length()), |
| 441 textfield->GetSelectedRange()); |
| 442 // Check just moving the cursor works, too. |
| 443 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(5, 0)] |
| 444 forAttribute:NSAccessibilitySelectedTextRangeAttribute]; |
| 445 EXPECT_EQ(gfx::Range(5, 5), textfield->GetSelectedRange()); |
| 421 } | 446 } |
| 422 | 447 |
| 423 // Test performing a 'click' on Views with clickable roles work. | 448 // Test performing a 'click' on Views with clickable roles work. |
| 424 TEST_F(NativeWidgetMacAccessibilityTest, PressAction) { | 449 TEST_F(NativeWidgetMacAccessibilityTest, PressAction) { |
| 425 FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_BUTTON); | 450 FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_BUTTON); |
| 426 widget()->GetContentsView()->AddChildView(view); | 451 widget()->GetContentsView()->AddChildView(view); |
| 427 view->SetSize(GetWidgetBounds().size()); | 452 view->SetSize(GetWidgetBounds().size()); |
| 428 | 453 |
| 429 id ax_node = A11yElementAtMidpoint(); | 454 id ax_node = A11yElementAtMidpoint(); |
| 430 EXPECT_NSEQ(NSAccessibilityButtonRole, | 455 EXPECT_NSEQ(NSAccessibilityButtonRole, |
| 431 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); | 456 AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); |
| 432 | 457 |
| 433 EXPECT_TRUE([[ax_node accessibilityActionNames] | 458 EXPECT_TRUE([[ax_node accessibilityActionNames] |
| 434 containsObject:NSAccessibilityPressAction]); | 459 containsObject:NSAccessibilityPressAction]); |
| 435 [ax_node accessibilityPerformAction:NSAccessibilityPressAction]; | 460 [ax_node accessibilityPerformAction:NSAccessibilityPressAction]; |
| 436 EXPECT_TRUE(view->mouse_was_pressed()); | 461 EXPECT_TRUE(view->mouse_was_pressed()); |
| 437 } | 462 } |
| 438 | 463 |
| 439 } // namespace views | 464 } // namespace views |
| OLD | NEW |