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

Unified 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, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/native_widget_mac_accessibility_unittest.mm
diff --git a/ui/views/widget/native_widget_mac_accessibility_unittest.mm b/ui/views/widget/native_widget_mac_accessibility_unittest.mm
index 8f224aa37768d8d07e59c3ae67f668a1fe1c1b1e..a11003c1bcfd47b1724a2e92ac386837d8656651 100644
--- a/ui/views/widget/native_widget_mac_accessibility_unittest.mm
+++ b/ui/views/widget/native_widget_mac_accessibility_unittest.mm
@@ -336,6 +336,50 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldWritableAttributes) {
EXPECT_NSEQ(kTestPlaceholderText,
AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
EXPECT_EQ(base::SysNSStringToUTF16(kTestPlaceholderText), textfield->text());
+ textfield->SetReadOnly(false);
+
+ // Change the selection text when there is no selected text.
+ textfield->SelectRange(gfx::Range(0, 0));
+ EXPECT_TRUE([ax_node
+ accessibilityIsAttributeSettable:NSAccessibilitySelectedTextAttribute]);
+
+ NSString* new_string =
+ [kTestStringValue stringByAppendingString:kTestPlaceholderText];
+ [ax_node accessibilitySetValue:kTestStringValue
+ forAttribute:NSAccessibilitySelectedTextAttribute];
+ EXPECT_NSEQ(new_string,
+ AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
+ EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text());
+
+ // Replace entire selection.
+ gfx::Range test_range(0, [new_string length]);
+ textfield->SelectRange(test_range);
+ [ax_node accessibilitySetValue:kTestStringValue
+ forAttribute:NSAccessibilitySelectedTextAttribute];
+ EXPECT_NSEQ(kTestStringValue,
+ AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
+ EXPECT_EQ(base::SysNSStringToUTF16(kTestStringValue), textfield->text());
+ // Make sure the cursor is at the end of the Textfield.
+ EXPECT_EQ(gfx::Range([kTestStringValue length]),
+ textfield->GetSelectedRange());
+
+ // Replace a middle section only (with a backwards selection range).
+ base::string16 front = base::ASCIIToUTF16("Front ");
+ base::string16 middle = base::ASCIIToUTF16("middle");
+ base::string16 back = base::ASCIIToUTF16(" back");
+ base::string16 replacement = base::ASCIIToUTF16("replaced");
+ textfield->SetText(front + middle + back);
+ test_range = gfx::Range(front.length() + middle.length(), front.length());
+ new_string = base::SysUTF16ToNSString(front + replacement + back);
+ textfield->SelectRange(test_range);
+ [ax_node accessibilitySetValue:base::SysUTF16ToNSString(replacement)
+ forAttribute:NSAccessibilitySelectedTextAttribute];
+ EXPECT_NSEQ(new_string,
+ AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
+ EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text());
+ // Make sure the cursor is at the end of the replacement.
+ EXPECT_EQ(gfx::Range(front.length() + replacement.length()),
+ textfield->GetSelectedRange());
}
} // namespace views
« 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