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/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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 | 329 |
| 330 // Test a read-only textfield. | 330 // Test a read-only textfield. |
| 331 textfield->SetReadOnly(true); | 331 textfield->SetReadOnly(true); |
| 332 EXPECT_FALSE( | 332 EXPECT_FALSE( |
| 333 [ax_node accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]); | 333 [ax_node accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]); |
| 334 [ax_node accessibilitySetValue:kTestStringValue | 334 [ax_node accessibilitySetValue:kTestStringValue |
| 335 forAttribute:NSAccessibilityValueAttribute]; | 335 forAttribute:NSAccessibilityValueAttribute]; |
| 336 EXPECT_NSEQ(kTestPlaceholderText, | 336 EXPECT_NSEQ(kTestPlaceholderText, |
| 337 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | 337 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); |
| 338 EXPECT_EQ(base::SysNSStringToUTF16(kTestPlaceholderText), textfield->text()); | 338 EXPECT_EQ(base::SysNSStringToUTF16(kTestPlaceholderText), textfield->text()); |
| 339 textfield->SetReadOnly(false); | |
| 340 | |
| 341 // Change the selection text when there is no selected text. | |
| 342 textfield->SelectRange(gfx::Range(0, 0)); | |
| 343 EXPECT_TRUE([ax_node | |
| 344 accessibilityIsAttributeSettable:NSAccessibilitySelectedTextAttribute]); | |
| 345 | |
| 346 NSString* new_string = | |
| 347 [kTestStringValue stringByAppendingString:kTestPlaceholderText]; | |
| 348 [ax_node accessibilitySetValue:kTestStringValue | |
| 349 forAttribute:NSAccessibilitySelectedTextAttribute]; | |
| 350 EXPECT_NSEQ(new_string, | |
| 351 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | |
| 352 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | |
| 353 | |
| 354 // Replace entire selection. | |
| 355 gfx::Range test_range(0, [new_string length]); | |
| 356 textfield->SelectRange(test_range); | |
| 357 [ax_node accessibilitySetValue:kTestStringValue | |
| 358 forAttribute:NSAccessibilitySelectedTextAttribute]; | |
| 359 EXPECT_NSEQ(kTestStringValue, | |
| 360 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | |
| 361 EXPECT_EQ(base::SysNSStringToUTF16(kTestStringValue), textfield->text()); | |
| 362 | |
| 363 // Replace a section only. | |
| 364 test_range = gfx::Range(5, [kTestStringValue length]); | |
| 365 new_string = [[kTestStringValue substringWithRange:NSMakeRange(0, 5)] | |
| 366 stringByAppendingString:kTestPlaceholderText]; | |
| 367 textfield->SelectRange(test_range); | |
| 368 [ax_node accessibilitySetValue:kTestPlaceholderText | |
| 369 forAttribute:NSAccessibilitySelectedTextAttribute]; | |
| 370 EXPECT_NSEQ(new_string, | |
| 371 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | |
| 372 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | |
| 339 } | 373 } |
|
tapted
2016/09/27 07:16:30
are there cross-platform tests for AccessibilitySe
Patti Lor
2016/10/20 04:19:34
No, I don't think so - I can add some? Not sure wh
tapted
2016/10/20 05:54:58
Hm - there's a windows-specific test in NativeView
Patti Lor
2016/10/24 04:31:48
Ok :) I missed the Windows one - thanks for invest
| |
| 340 | 374 |
| 341 } // namespace views | 375 } // namespace views |
| OLD | NEW |