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

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: Update to allow selection range changes when read-only. 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
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 EXPECT_TRUE([ax_node accessibilityIsAttributeSettable:
416 NSAccessibilitySelectedTextRangeAttribute]);
417 // Check it's still possible to change the selection range when read-only.
418 textfield->SetReadOnly(true);
419 EXPECT_TRUE([ax_node accessibilityIsAttributeSettable:
420 NSAccessibilitySelectedTextRangeAttribute]);
421
422 // Change the selection to a valid range within the text.
423 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(2, 5)]
424 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
425 EXPECT_EQ(gfx::Range(2, 7), textfield->GetSelectedRange());
426 // If the length is longer than the value length, default to the max possible.
427 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(0, 1000)]
428 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
429 EXPECT_EQ(gfx::Range(0, textfield->text().length()),
430 textfield->GetSelectedRange());
431 // Check just moving the cursor works, too.
432 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(5, 0)]
433 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
434 EXPECT_EQ(gfx::Range(5, 5), textfield->GetSelectedRange());
414 } 435 }
415 436
416 } // namespace views 437 } // namespace views
OLDNEW
« ui/views/controls/textfield/textfield.cc ('K') | « ui/views/controls/textfield/textfield.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698