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

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

Issue 2119413004: a11y: Exclude children of nested keyboard accessible controls from a11y tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Before revert of cross-platform ignored a11y elements. 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/view.cc ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | 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..8cfc4b5c8383a58547f32be16aca9f35428438dd 100644
--- a/ui/views/widget/native_widget_mac_accessibility_unittest.mm
+++ b/ui/views/widget/native_widget_mac_accessibility_unittest.mm
@@ -14,6 +14,7 @@
#import "ui/accessibility/platform/ax_platform_node_mac.h"
#include "ui/base/ime/text_input_type.h"
#import "ui/gfx/mac/coordinate_conversion.h"
+#include "ui/views/accessibility/native_view_accessibility.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/widget_test.h"
@@ -34,7 +35,10 @@ NSString* const kTestTitle = @"Test textfield";
class FlexibleRoleTestView : public View {
public:
- explicit FlexibleRoleTestView(ui::AXRole role) : role_(role) {}
+ explicit FlexibleRoleTestView(ui::AXRole role) : role_(role) {
+ SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
+ }
+
void set_role(ui::AXRole role) { role_ = role; }
// Add a child view and resize to fit the child.
@@ -111,7 +115,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) {
const size_t kNumChildren = 3;
for (size_t i = 0; i < kNumChildren; ++i) {
- // Make sure the labels won't interfere with the hit test.
+ // Add children sized 0x0 to ensure they won't interfere with the hit tests.
AddChildTextfield(gfx::Size());
}
@@ -130,12 +134,14 @@ TEST_F(NativeWidgetMacAccessibilityTest, ChildrenAttribute) {
TEST_F(NativeWidgetMacAccessibilityTest, ParentAttribute) {
Textfield* child = AddChildTextfield(widget()->GetContentsView()->size());
- // Views with Widget parents will have a NSWindow parent.
- EXPECT_NSEQ(
- NSAccessibilityWindowRole,
- [AttributeValueAtMidpoint(NSAccessibilityParentAttribute) AXRole]);
+ // Views with Widget parents will have a RootView (BridgedContentView) parent,
+ // which doesn't use the legacy NSAccessibility Informal Protocol Reference,
+ // so retrieve the AXRole via accessibilityAttributeValue instead.
+ EXPECT_NSEQ(NSAccessibilityWindowRole,
+ [AttributeValueAtMidpoint(NSAccessibilityParentAttribute)
+ accessibilityAttributeValue:NSAccessibilityRoleAttribute]);
- // Views with non-Widget parents will have the role of the parent view.
+ // Children of other Views will report their View parent's role.
widget()->GetContentsView()->RemoveChildView(child);
FlexibleRoleTestView* parent = new FlexibleRoleTestView(ui::AX_ROLE_GROUP);
parent->FitBoundsToNewChild(child);
@@ -146,9 +152,9 @@ TEST_F(NativeWidgetMacAccessibilityTest, ParentAttribute) {
// Test an ignored role parent is skipped in favor of the grandparent.
parent->set_role(ui::AX_ROLE_IGNORED);
- EXPECT_NSEQ(
- NSAccessibilityWindowRole,
- [AttributeValueAtMidpoint(NSAccessibilityParentAttribute) AXRole]);
+ EXPECT_NSEQ(NSAccessibilityWindowRole,
+ [AttributeValueAtMidpoint(NSAccessibilityParentAttribute)
+ accessibilityAttributeValue:NSAccessibilityRoleAttribute]);
}
// Test for NSAccessibilityPositionAttribute, including on Widget movement
@@ -167,11 +173,22 @@ TEST_F(NativeWidgetMacAccessibilityTest, PositionAttribute) {
valueWithPoint:gfx::ScreenPointToNSPoint(new_bounds.bottom_left())];
EXPECT_NSEQ(widget_origin,
AttributeValueAtMidpoint(NSAccessibilityPositionAttribute));
+
+ // Check the attribute is correct for a View.
+ Textfield* textfield = AddChildTextfield(gfx::Size(70, 70));
+ widget_origin = [NSValue
+ valueWithPoint:gfx::ScreenPointToNSPoint(
+ textfield->GetBoundsInScreen().bottom_left())];
+ EXPECT_NSEQ(NSAccessibilityTextFieldRole,
+ AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
+ EXPECT_NSEQ(widget_origin,
+ AttributeValueAtMidpoint(NSAccessibilityPositionAttribute));
}
// Test for NSAccessibilityHelpAttribute.
TEST_F(NativeWidgetMacAccessibilityTest, HelpAttribute) {
Label* label = new Label(base::SysNSStringToUTF16(kTestPlaceholderText));
+ label->SetFocusBehavior(ClientView::FocusBehavior::ACCESSIBLE_ONLY);
label->SetSize(GetWidgetBounds().size());
EXPECT_NSEQ(nil, AttributeValueAtMidpoint(NSAccessibilityHelpAttribute));
label->SetTooltipText(base::SysNSStringToUTF16(kTestPlaceholderText));
@@ -204,6 +221,9 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldGenericAttributes) {
// NSAccessibilityEnabledAttribute.
textfield->SetEnabled(false);
+ // Disabled items should be unfocusable but shouldn't be ignored.
+ EXPECT_FALSE(textfield->IsAccessibilityFocusable());
+ EXPECT_FALSE(textfield->GetNativeViewAccessibility()->IsIgnored());
EXPECT_EQ(NO, [AttributeValueAtMidpoint(NSAccessibilityEnabledAttribute)
boolValue]);
textfield->SetEnabled(true);
« no previous file with comments | « ui/views/view.cc ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698