Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: ui/views/widget/native_widget_mac_accessibility_unittest.mm

Issue 2684203002: MacViews/a11y: Allow accessibility clients to set new selections in Textfields. (Closed)
Patch Set: Revert textfield.cc. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 new_string = base::SysUTF16ToNSString(front + replacement + back); 404 new_string = base::SysUTF16ToNSString(front + replacement + back);
405 textfield->SelectRange(test_range); 405 textfield->SelectRange(test_range);
406 [ax_node accessibilitySetValue:base::SysUTF16ToNSString(replacement) 406 [ax_node accessibilitySetValue:base::SysUTF16ToNSString(replacement)
407 forAttribute:NSAccessibilitySelectedTextAttribute]; 407 forAttribute:NSAccessibilitySelectedTextAttribute];
408 EXPECT_NSEQ(new_string, 408 EXPECT_NSEQ(new_string,
409 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); 409 AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
410 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); 410 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text());
411 // Make sure the cursor is at the end of the replacement. 411 // Make sure the cursor is at the end of the replacement.
412 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), 412 EXPECT_EQ(gfx::Range(front.length() + replacement.length()),
413 textfield->GetSelectedRange()); 413 textfield->GetSelectedRange());
414
415 // Check it's not possible to change the selection range when read-only. Note
416 // that this behavior is inconsistent with Cocoa - selections can be set via
417 // a11y in non-editable, selectable NSTextfields. https://crbug.com/692362
tapted 2017/02/15 22:31:51 .. selectable NSTextfields (unless they are passwo
Patti Lor 2017/02/16 00:34:11 Done.
418 textfield->SetReadOnly(true);
419 EXPECT_FALSE([ax_node accessibilityIsAttributeSettable:
420 NSAccessibilitySelectedTextRangeAttribute]);
421 textfield->SetReadOnly(false);
422 EXPECT_TRUE([ax_node accessibilityIsAttributeSettable:
423 NSAccessibilitySelectedTextRangeAttribute]);
424
425 // Change the selection to a valid range within the text.
426 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(2, 5)]
427 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
428 EXPECT_EQ(gfx::Range(2, 7), textfield->GetSelectedRange());
429 // If the length is longer than the value length, default to the max possible.
430 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(0, 1000)]
431 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
432 EXPECT_EQ(gfx::Range(0, textfield->text().length()),
433 textfield->GetSelectedRange());
434 // Check just moving the cursor works, too.
435 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(5, 0)]
436 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
437 EXPECT_EQ(gfx::Range(5, 5), textfield->GetSelectedRange());
414 } 438 }
415 439
416 } // namespace views 440 } // namespace views
OLDNEW
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698