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

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: Add tests. 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 // Check it's not possible to change the selection range when it's read-only.
tapted 2017/02/09 23:09:37 Check that it *is* possible? Which I think is righ
Patti Lor 2017/02/13 23:31:03 Done, thanks. I had to change Textfield::SetSelect
416 textfield->SetReadOnly(true);
417 EXPECT_TRUE([ax_node accessibilityIsAttributeSettable:
418 NSAccessibilitySelectedTextRangeAttribute]);
419 textfield->SetReadOnly(false);
420 EXPECT_TRUE([ax_node accessibilityIsAttributeSettable:
421 NSAccessibilitySelectedTextRangeAttribute]);
422
423 // Change the selection to a valid range within the text.
424 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(2, 5)]
425 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
426 EXPECT_EQ(gfx::Range(2, 7), textfield->GetSelectedRange());
427 // If the length is longer than the value length, default to the max possible.
428 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(0, 1000)]
429 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
430 EXPECT_EQ(gfx::Range(0, textfield->text().length()),
431 textfield->GetSelectedRange());
432 // Check just moving the cursor works, too.
433 [ax_node accessibilitySetValue:[NSValue valueWithRange:NSMakeRange(5, 0)]
434 forAttribute:NSAccessibilitySelectedTextRangeAttribute];
435 EXPECT_EQ(gfx::Range(5, 5), textfield->GetSelectedRange());
414 } 436 }
415 437
416 } // namespace views 438 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698