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

Unified Diff: ui/views/widget/native_widget_mac_accessibility_unittest.mm

Issue 2106953005: Mac: Add new accessibility attributes for textfields (and some for all views). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ax-attrs
Patch Set: Address review comments. Created 4 years, 6 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 9ae4b70ed71060136ffcf936e08b3cf93a4393b4..1b37e4bcd9d3a921159c6615337e12ad66a1cba6 100644
--- a/ui/views/widget/native_widget_mac_accessibility_unittest.mm
+++ b/ui/views/widget/native_widget_mac_accessibility_unittest.mm
@@ -27,6 +27,7 @@ namespace views {
namespace {
+NSString* const kTestPlaceholderText = @"Test placeholder text";
NSString* const kTestStringValue = @"Test string value";
NSString* const kTestTitle = @"Test textfield";
@@ -170,9 +171,24 @@ TEST_F(NativeWidgetMacAccessibilityTest, PositionAttribute) {
// Tests for accessibility attributes on a views::Textfield.
// TODO(patricialor): Test against Cocoa-provided attributes as well to ensure
// consistency between Cocoa and toolkit-views.
-TEST_F(NativeWidgetMacAccessibilityTest, TextfieldAccessibility) {
+TEST_F(NativeWidgetMacAccessibilityTest, TextfieldGenericAttributes) {
Textfield* textfield = AddChildTextfield(GetWidgetBounds().size());
+ // NSAccessibilityEnabledAttribute.
+ textfield->SetEnabled(false);
+ EXPECT_EQ(NO, [AttributeValueAtMidpoint(NSAccessibilityEnabledAttribute)
+ boolValue]);
+ textfield->SetEnabled(true);
+ EXPECT_EQ(YES, [AttributeValueAtMidpoint(NSAccessibilityEnabledAttribute)
+ boolValue]);
+
+ // NSAccessibilityFocusedAttribute.
+ EXPECT_EQ(NO, [AttributeValueAtMidpoint(NSAccessibilityFocusedAttribute)
+ boolValue]);
+ textfield->RequestFocus();
+ EXPECT_EQ(YES, [AttributeValueAtMidpoint(NSAccessibilityFocusedAttribute)
+ boolValue]);
+
// NSAccessibilityTitleAttribute.
EXPECT_NSEQ(kTestTitle,
AttributeValueAtMidpoint(NSAccessibilityTitleAttribute));
@@ -216,4 +232,48 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldAccessibility) {
NSAccessibilitySizeAttribute) sizeValue]));
}
+TEST_F(NativeWidgetMacAccessibilityTest, TextfieldEditableAttributes) {
+ Textfield* textfield = AddChildTextfield(GetWidgetBounds().size());
+ textfield->set_placeholder_text(
+ base::SysNSStringToUTF16(kTestPlaceholderText));
+
+ // NSAccessibilityInsertionPointLineNumberAttribute.
+ EXPECT_EQ(0, [AttributeValueAtMidpoint(
+ NSAccessibilityInsertionPointLineNumberAttribute) intValue]);
+
+ // NSAccessibilityNumberOfCharactersAttribute.
+ EXPECT_EQ(
+ kTestStringValue.length,
+ [AttributeValueAtMidpoint(NSAccessibilityNumberOfCharactersAttribute)
+ unsignedIntegerValue]);
+
+ // NSAccessibilityPlaceholderAttribute.
+ EXPECT_NSEQ(
+ kTestPlaceholderText,
+ AttributeValueAtMidpoint(NSAccessibilityPlaceholderValueAttribute));
+
+ // NSAccessibilitySelectedTextAttribute and
+ // NSAccessibilitySelectedTextRangeAttribute.
+ EXPECT_NSEQ(@"",
+ AttributeValueAtMidpoint(NSAccessibilitySelectedTextAttribute));
+ // The cursor will be at the end of the textfield, so the selection range will
+ // span 0 characters and be located at the index after the last character.
+ EXPECT_EQ(gfx::Range(kTestStringValue.length, kTestStringValue.length),
+ gfx::Range([AttributeValueAtMidpoint(
+ NSAccessibilitySelectedTextRangeAttribute) rangeValue]));
+ // Select some text in the middle of the textfield.
+ gfx::Range selection_range(2, 6);
+ textfield->SelectRange(selection_range);
+ EXPECT_NSEQ([kTestStringValue substringWithRange:selection_range.ToNSRange()],
+ AttributeValueAtMidpoint(NSAccessibilitySelectedTextAttribute));
+ EXPECT_EQ(selection_range,
+ gfx::Range([AttributeValueAtMidpoint(
+ NSAccessibilitySelectedTextRangeAttribute) rangeValue]));
+
+ // NSAccessibilityVisibleCharacterRangeAttribute.
+ EXPECT_EQ(gfx::Range(0, kTestStringValue.length),
+ gfx::Range([AttributeValueAtMidpoint(
+ NSAccessibilityVisibleCharacterRangeAttribute) rangeValue]));
+}
+
} // 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