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

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

Issue 2341633006: MacViews/a11y: Allow accessibility clients to update the selected text. (Closed)
Patch Set: Review comments. Created 4 years, 1 month 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/views/controls/textfield/textfield.cc ('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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Make sure the cursor is at the end of the Textfield.
363 EXPECT_EQ(gfx::Range([kTestStringValue length]),
364 textfield->GetSelectedRange());
365
366 // Replace a middle section only (with a backwards selection range).
367 base::string16 front = base::ASCIIToUTF16("Front ");
368 base::string16 middle = base::ASCIIToUTF16("middle");
369 base::string16 back = base::ASCIIToUTF16(" back");
370 base::string16 replacement = base::ASCIIToUTF16("replaced");
371 textfield->SetText(front + middle + back);
372 test_range = gfx::Range(front.length() + middle.length(), front.length());
373 new_string = base::SysUTF16ToNSString(front + replacement + back);
374 textfield->SelectRange(test_range);
375 [ax_node accessibilitySetValue:base::SysUTF16ToNSString(replacement)
376 forAttribute:NSAccessibilitySelectedTextAttribute];
377 EXPECT_NSEQ(new_string,
378 AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
379 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text());
380 // Make sure the cursor is at the end of the replacement.
381 EXPECT_EQ(gfx::Range(front.length() + replacement.length()),
382 textfield->GetSelectedRange());
339 } 383 }
340 384
341 } // namespace views 385 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698