| 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/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" | 
| 10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" | 
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 529   [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(0, 1000)] | 529   [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(0, 1000)] | 
| 530                     forAttribute:NSAccessibilitySelectedTextRangeAttribute]; | 530                     forAttribute:NSAccessibilitySelectedTextRangeAttribute]; | 
| 531   EXPECT_EQ(gfx::Range(0, textfield->text().length()), | 531   EXPECT_EQ(gfx::Range(0, textfield->text().length()), | 
| 532             textfield->GetSelectedRange()); | 532             textfield->GetSelectedRange()); | 
| 533   // Check just moving the cursor works, too. | 533   // Check just moving the cursor works, too. | 
| 534   [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(5, 0)] | 534   [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(5, 0)] | 
| 535                     forAttribute:NSAccessibilitySelectedTextRangeAttribute]; | 535                     forAttribute:NSAccessibilitySelectedTextRangeAttribute]; | 
| 536   EXPECT_EQ(gfx::Range(5, 5), textfield->GetSelectedRange()); | 536   EXPECT_EQ(gfx::Range(5, 5), textfield->GetSelectedRange()); | 
| 537 } | 537 } | 
| 538 | 538 | 
|  | 539 // Test parameterized text attributes. | 
|  | 540 TEST_F(NativeWidgetMacAccessibilityTest, TextParameterizedAttributes) { | 
|  | 541   AddChildTextfield(GetWidgetBounds().size()); | 
|  | 542   id ax_node = A11yElementAtMidpoint(); | 
|  | 543   EXPECT_TRUE(ax_node); | 
|  | 544 | 
|  | 545   NSArray* attributes = [ax_node accessibilityParameterizedAttributeNames]; | 
|  | 546   ASSERT_TRUE(attributes); | 
|  | 547 | 
|  | 548   // Ensure the method names match. | 
|  | 549   for (NSString* attribute in attributes) { | 
|  | 550     SEL sel = NSSelectorFromString([attribute stringByAppendingString:@":"]); | 
|  | 551     EXPECT_TRUE([ax_node respondsToSelector:sel]); | 
|  | 552   } | 
|  | 553 | 
|  | 554   NSNumber* line = | 
|  | 555       [ax_node accessibilityAttributeValue: | 
|  | 556                    NSAccessibilityLineForIndexParameterizedAttribute | 
|  | 557                               forParameter:@5]; | 
|  | 558   EXPECT_TRUE(line); | 
|  | 559   EXPECT_EQ(0, [line intValue]); | 
|  | 560 | 
|  | 561   EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(0, kTestStringLength)], | 
|  | 562               [ax_node accessibilityAttributeValue: | 
|  | 563                            NSAccessibilityRangeForLineParameterizedAttribute | 
|  | 564                                       forParameter:line]); | 
|  | 565 | 
|  | 566   // The substring "est st" of kTestStringValue. | 
|  | 567   NSValue* test_range = [NSValue valueWithRange:NSMakeRange(1, 6)]; | 
|  | 568   EXPECT_NSEQ(@"est st", | 
|  | 569               [ax_node accessibilityAttributeValue: | 
|  | 570                            NSAccessibilityStringForRangeParameterizedAttribute | 
|  | 571                                       forParameter:test_range]); | 
|  | 572   EXPECT_NSEQ( | 
|  | 573       @"est st", | 
|  | 574       [[ax_node | 
|  | 575           accessibilityAttributeValue: | 
|  | 576               NSAccessibilityAttributedStringForRangeParameterizedAttribute | 
|  | 577                          forParameter:test_range] string]); | 
|  | 578 | 
|  | 579   // Not implemented yet. Update these tests when they are. | 
|  | 580   EXPECT_NSEQ(nil, | 
|  | 581               [ax_node accessibilityAttributeValue: | 
|  | 582                            NSAccessibilityRangeForPositionParameterizedAttribute | 
|  | 583                                       forParameter:@4]); | 
|  | 584   EXPECT_NSEQ(nil, | 
|  | 585               [ax_node accessibilityAttributeValue: | 
|  | 586                            NSAccessibilityRangeForIndexParameterizedAttribute | 
|  | 587                                       forParameter:@4]); | 
|  | 588   EXPECT_NSEQ(nil, | 
|  | 589               [ax_node accessibilityAttributeValue: | 
|  | 590                            NSAccessibilityBoundsForRangeParameterizedAttribute | 
|  | 591                                       forParameter:test_range]); | 
|  | 592   EXPECT_NSEQ(nil, [ax_node accessibilityAttributeValue: | 
|  | 593                                 NSAccessibilityRTFForRangeParameterizedAttribute | 
|  | 594                                            forParameter:test_range]); | 
|  | 595   EXPECT_NSEQ( | 
|  | 596       nil, [ax_node accessibilityAttributeValue: | 
|  | 597                         NSAccessibilityStyleRangeForIndexParameterizedAttribute | 
|  | 598                                    forParameter:@4]); | 
|  | 599 | 
|  | 600   // Non-text shouldn't have any parameterized attributes. | 
|  | 601   id ax_parent = | 
|  | 602       [ax_node accessibilityAttributeValue:NSAccessibilityParentAttribute]; | 
|  | 603   EXPECT_TRUE(ax_parent); | 
|  | 604   EXPECT_FALSE([ax_parent accessibilityParameterizedAttributeNames]); | 
|  | 605 } | 
|  | 606 | 
| 539 // Test performing a 'click' on Views with clickable roles work. | 607 // Test performing a 'click' on Views with clickable roles work. | 
| 540 TEST_F(NativeWidgetMacAccessibilityTest, PressAction) { | 608 TEST_F(NativeWidgetMacAccessibilityTest, PressAction) { | 
| 541   FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_BUTTON); | 609   FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_BUTTON); | 
| 542   widget()->GetContentsView()->AddChildView(view); | 610   widget()->GetContentsView()->AddChildView(view); | 
| 543   view->SetSize(GetWidgetBounds().size()); | 611   view->SetSize(GetWidgetBounds().size()); | 
| 544 | 612 | 
| 545   id ax_node = A11yElementAtMidpoint(); | 613   id ax_node = A11yElementAtMidpoint(); | 
| 546   EXPECT_NSEQ(NSAccessibilityButtonRole, | 614   EXPECT_NSEQ(NSAccessibilityButtonRole, | 
| 547               AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); | 615               AttributeValueAtMidpoint(NSAccessibilityRoleAttribute)); | 
| 548 | 616 | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 659   EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(0, 0)], | 727   EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(0, 0)], | 
| 660               [ax_node AXSelectedTextRange]); | 728               [ax_node AXSelectedTextRange]); | 
| 661 | 729 | 
| 662   EXPECT_EQ(kTestStringLength, [[ax_node AXNumberOfCharacters] intValue]); | 730   EXPECT_EQ(kTestStringLength, [[ax_node AXNumberOfCharacters] intValue]); | 
| 663   EXPECT_NSEQ(([NSValue valueWithRange:{0, kTestStringLength}]), | 731   EXPECT_NSEQ(([NSValue valueWithRange:{0, kTestStringLength}]), | 
| 664               [ax_node AXVisibleCharacterRange]); | 732               [ax_node AXVisibleCharacterRange]); | 
| 665   EXPECT_EQ(0, [[ax_node AXInsertionPointLineNumber] intValue]); | 733   EXPECT_EQ(0, [[ax_node AXInsertionPointLineNumber] intValue]); | 
| 666 } | 734 } | 
| 667 | 735 | 
| 668 }  // namespace views | 736 }  // namespace views | 
| OLD | NEW | 
|---|