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

Unified Diff: ui/views/controls/tabbed_pane/tabbed_pane_mac_accessibility_unittest.mm

Issue 2578303003: a11y: Add a11y information to views::Tab and manually ignore its a11y children. (Closed)
Patch Set: Add tests. Created 3 years, 11 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
Index: ui/views/controls/tabbed_pane/tabbed_pane_mac_accessibility_unittest.mm
diff --git a/ui/views/controls/tabbed_pane/tabbed_pane_mac_accessibility_unittest.mm b/ui/views/controls/tabbed_pane/tabbed_pane_mac_accessibility_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..7819046e48fe2b086c9b8b9b2a25714531e5088f
--- /dev/null
+++ b/ui/views/controls/tabbed_pane/tabbed_pane_mac_accessibility_unittest.mm
@@ -0,0 +1,161 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
tapted 2017/01/06 04:25:12 nit: 2017 :)
Patti Lor 2017/01/09 22:39:27 :O Thanks!
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/strings/utf_string_conversions.h"
+#include "ui/gfx/geometry/point.h"
+#import "ui/gfx/mac/coordinate_conversion.h"
+#include "ui/views/controls/tabbed_pane/tabbed_pane.h"
+#include "ui/views/test/widget_test.h"
+#include "ui/views/widget/widget.h"
+#import "testing/gtest_mac.h"
+
+namespace views {
+
+class TabbedPaneMacAccessibilityTest : public test::WidgetTest {
+ public:
+ TabbedPaneMacAccessibilityTest() {}
+
+ void SetUp() override {
+ test::WidgetTest::SetUp();
+ widget_ = CreateTopLevelPlatformWidget();
+ widget_->SetBounds(gfx::Rect(50, 50, 100, 100));
+ tabbed_pane_ = new TabbedPane();
+ tabbed_pane_->SetSize(gfx::Size(100, 100));
+
+ // Create two tabs and position/size them.
+ View* tab1_contents = new View();
tapted 2017/01/06 04:25:11 nit: move `new View()` into the AddTab calls - no
Patti Lor 2017/01/09 22:39:27 Done.
+ View* tab2_contents = new View();
+ tabbed_pane_->AddTab(base::ASCIIToUTF16("Tab 1"), tab1_contents);
+ tabbed_pane_->AddTab(base::ASCIIToUTF16("Tab 2"), tab2_contents);
+ tabbed_pane_->Layout();
+
+ // Keep references to each Tab and select the first tab for tests.
+ tabbed_pane_->SelectTabAt(0);
tapted 2017/01/06 04:25:12 why not tab1_ = tabbed_pane_->GetTabAt(0); tab2_
Patti Lor 2017/01/09 22:39:27 Deleted as suggested below.
+ tab1_ = tabbed_pane_->GetSelectedTab();
+ tabbed_pane_->SelectTabAt(1);
+ tab2_ = tabbed_pane_->GetSelectedTab();
+ tabbed_pane_->SelectTabAt(0);
+
+ widget_->GetContentsView()->AddChildView(tabbed_pane_);
+ widget_->Show();
+
+ tab1_center_ = tab1_->GetBoundsInScreen().CenterPoint();
+ tab2_center_ = tab2_->GetBoundsInScreen().CenterPoint();
+ }
+
+ void TearDown() override {
+ widget_->CloseNow();
+ test::WidgetTest::TearDown();
+ }
+
+ id AttributeValueAtPoint(NSString* attribute, gfx::Point point) {
tapted 2017/01/06 04:25:12 nit: const-ref point
Patti Lor 2017/01/09 22:39:27 Done.
+ id value =
+ [A11yElementAtPoint(point) accessibilityAttributeValue:attribute];
+ return value;
+ }
+
+ id A11yElementAtPoint(gfx::Point point) {
tapted 2017/01/06 04:25:12 const-ref
Patti Lor 2017/01/09 22:39:27 Done.
+ // Accessibility hit tests come in Cocoa screen coordinates.
+ NSPoint ns_point = gfx::ScreenPointToNSPoint(point);
+ return [widget_->GetNativeWindow() accessibilityHitTest:ns_point];
+ }
+
+ Widget* widget_;
tapted 2017/01/06 04:25:12 these should be protected:
Patti Lor 2017/01/09 22:39:27 Done.
+ TabbedPane* tabbed_pane_;
+ Tab* tab1_;
tapted 2017/01/06 04:25:12 Actually I don't think we need these - can we add
Patti Lor 2017/01/09 22:39:27 Done.
+ Tab* tab2_;
+ gfx::Point tab1_center_;
tapted 2017/01/06 04:25:12 same here, gfx::Point TabCenterPoint(int index) {
Patti Lor 2017/01/09 22:39:27 Done.
+ gfx::Point tab2_center_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TabbedPaneMacAccessibilityTest);
+};
+
+// Test the Tab's a11y information compared to a Cocoa NSTabViewItem.
+TEST_F(TabbedPaneMacAccessibilityTest, Attributes) {
tapted 2017/01/06 04:25:11 Maybe Attributes -> AppKitAtributes -- i.e. someth
Patti Lor 2017/01/09 22:39:27 Went for AttributesMatchAppKit, let me know if you
+ // Create a Cocoa NSTabView to test against and select the first tab.
+ NSTabView* cocoa_tab_group =
tapted 2017/01/06 04:25:11 any `alloc` typically needs to go into a scoped_ns
Patti Lor 2017/01/09 22:39:27 Used autorelease as suggested below.
+ [[NSTabView alloc] initWithFrame:NSMakeRect(50, 50, 100, 100)];
+ NSTabViewItem* cocoa_tab1 = [[NSTabViewItem alloc] init];
tapted 2017/01/06 04:25:12 we'd need scoped_nsobject for these too, but inste
Patti Lor 2017/01/09 22:39:27 Done.
+ NSTabViewItem* cocoa_tab2 = [[NSTabViewItem alloc] init];
+ [cocoa_tab1 setLabel:@"Tab 1"];
+ [cocoa_tab2 setLabel:@"Tab 2"];
+ [cocoa_tab_group addTabViewItem:cocoa_tab1];
+ [cocoa_tab_group addTabViewItem:cocoa_tab2];
+ [cocoa_tab_group selectFirstTabViewItem:nil];
tapted 2017/01/06 04:25:12 was this necessary? perhaps either a comment // C
Patti Lor 2017/01/09 22:39:27 Oops, no - removed now.
+
+ // General a11y information.
+ EXPECT_NSEQ(
+ [cocoa_tab1 accessibilityAttributeValue:NSAccessibilityRoleAttribute],
+ AttributeValueAtPoint(NSAccessibilityRoleAttribute, tab1_center_));
tapted 2017/01/06 04:25:12 we should probably guard against the possibility t
Patti Lor 2017/01/09 22:39:27 Done.
+ EXPECT_NSEQ(
+ [cocoa_tab1
+ accessibilityAttributeValue:NSAccessibilityRoleDescriptionAttribute],
+ AttributeValueAtPoint(NSAccessibilityRoleDescriptionAttribute,
+ tab1_center_));
+ EXPECT_NSEQ(
+ [cocoa_tab1 accessibilityAttributeValue:NSAccessibilityTitleAttribute],
+ AttributeValueAtPoint(NSAccessibilityTitleAttribute, tab1_center_));
+
+ // Check value attribute matches up with whether tabs are actually selected.
+ // Cocoa uses an int, so convert it back into a NSString.
tapted 2017/01/06 04:25:12 I'm not sure the conversion step makes sense. I.e.
Patti Lor 2017/01/09 22:39:27 Ooh, thanks for mentioning this. I'd already check
+ EXPECT_NSEQ(
tapted 2017/01/06 04:25:12 We should check the actual value too e.g. for (
Patti Lor 2017/01/09 22:39:27 Done.
+ [[cocoa_tab1 accessibilityAttributeValue:NSAccessibilityValueAttribute]
+ stringValue],
+ AttributeValueAtPoint(NSAccessibilityValueAttribute, tab1_center_));
+ EXPECT_NSEQ(
+ [[cocoa_tab2 accessibilityAttributeValue:NSAccessibilityValueAttribute]
+ stringValue],
+ AttributeValueAtPoint(NSAccessibilityValueAttribute, tab2_center_));
+
+ // NSTabViewItem doesn't support NSAccessibilitySelectedAttribute, so don't
+ // compare against Cocoa here.
+ EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute,
+ tab1_center_) boolValue]);
+ EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute,
+ tab2_center_) boolValue]);
+}
+
+// Make sure tabs can be selected by writing the value attribute.
+TEST_F(TabbedPaneMacAccessibilityTest, WritableValue) {
+ id tab1_a11y = A11yElementAtPoint(tab1_center_);
+ id tab2_a11y = A11yElementAtPoint(tab2_center_);
+
+ // Only unselected tabs should be writable.
+ EXPECT_FALSE([tab1_a11y
+ accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]);
+ EXPECT_TRUE([tab2_a11y
+ accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]);
+
+ // Select the second tab. Since we are using a field that is actually an
+ // NSString, any valid string value provided should select the tab.
+ [tab2_a11y accessibilitySetValue:@"string"
+ forAttribute:NSAccessibilityValueAttribute];
+ EXPECT_NSEQ(
+ @"0", AttributeValueAtPoint(NSAccessibilityValueAttribute, tab1_center_));
+ EXPECT_NSEQ(
+ @"1", AttributeValueAtPoint(NSAccessibilityValueAttribute, tab2_center_));
+ EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute,
+ tab1_center_) boolValue]);
+ EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute,
+ tab2_center_) boolValue]);
+ EXPECT_TRUE(tab2_->selected());
+
+ // Try again with an empty string.
+ [tab1_a11y accessibilitySetValue:@""
+ forAttribute:NSAccessibilityValueAttribute];
+ EXPECT_NSEQ(
+ @"1", AttributeValueAtPoint(NSAccessibilityValueAttribute, tab1_center_));
+ EXPECT_NSEQ(
+ @"0", AttributeValueAtPoint(NSAccessibilityValueAttribute, tab2_center_));
+ EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute,
+ tab1_center_) boolValue]);
+ EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute,
+ tab2_center_) boolValue]);
+ EXPECT_TRUE(tab1_->selected());
+}
tapted 2017/01/06 04:25:12 Can we also test the AXAction "press" - this seems
Patti Lor 2017/01/09 22:39:27 NSAccessibilityActions aren't hooked up yet to Vie
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698