Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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!
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <Cocoa/Cocoa.h> | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "ui/gfx/geometry/point.h" | |
| 9 #import "ui/gfx/mac/coordinate_conversion.h" | |
| 10 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" | |
| 11 #include "ui/views/test/widget_test.h" | |
| 12 #include "ui/views/widget/widget.h" | |
| 13 #import "testing/gtest_mac.h" | |
| 14 | |
| 15 namespace views { | |
| 16 | |
| 17 class TabbedPaneMacAccessibilityTest : public test::WidgetTest { | |
| 18 public: | |
| 19 TabbedPaneMacAccessibilityTest() {} | |
| 20 | |
| 21 void SetUp() override { | |
| 22 test::WidgetTest::SetUp(); | |
| 23 widget_ = CreateTopLevelPlatformWidget(); | |
| 24 widget_->SetBounds(gfx::Rect(50, 50, 100, 100)); | |
| 25 tabbed_pane_ = new TabbedPane(); | |
| 26 tabbed_pane_->SetSize(gfx::Size(100, 100)); | |
| 27 | |
| 28 // Create two tabs and position/size them. | |
| 29 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.
| |
| 30 View* tab2_contents = new View(); | |
| 31 tabbed_pane_->AddTab(base::ASCIIToUTF16("Tab 1"), tab1_contents); | |
| 32 tabbed_pane_->AddTab(base::ASCIIToUTF16("Tab 2"), tab2_contents); | |
| 33 tabbed_pane_->Layout(); | |
| 34 | |
| 35 // Keep references to each Tab and select the first tab for tests. | |
| 36 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.
| |
| 37 tab1_ = tabbed_pane_->GetSelectedTab(); | |
| 38 tabbed_pane_->SelectTabAt(1); | |
| 39 tab2_ = tabbed_pane_->GetSelectedTab(); | |
| 40 tabbed_pane_->SelectTabAt(0); | |
| 41 | |
| 42 widget_->GetContentsView()->AddChildView(tabbed_pane_); | |
| 43 widget_->Show(); | |
| 44 | |
| 45 tab1_center_ = tab1_->GetBoundsInScreen().CenterPoint(); | |
| 46 tab2_center_ = tab2_->GetBoundsInScreen().CenterPoint(); | |
| 47 } | |
| 48 | |
| 49 void TearDown() override { | |
| 50 widget_->CloseNow(); | |
| 51 test::WidgetTest::TearDown(); | |
| 52 } | |
| 53 | |
| 54 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.
| |
| 55 id value = | |
| 56 [A11yElementAtPoint(point) accessibilityAttributeValue:attribute]; | |
| 57 return value; | |
| 58 } | |
| 59 | |
| 60 id A11yElementAtPoint(gfx::Point point) { | |
|
tapted
2017/01/06 04:25:12
const-ref
Patti Lor
2017/01/09 22:39:27
Done.
| |
| 61 // Accessibility hit tests come in Cocoa screen coordinates. | |
| 62 NSPoint ns_point = gfx::ScreenPointToNSPoint(point); | |
| 63 return [widget_->GetNativeWindow() accessibilityHitTest:ns_point]; | |
| 64 } | |
| 65 | |
| 66 Widget* widget_; | |
|
tapted
2017/01/06 04:25:12
these should be protected:
Patti Lor
2017/01/09 22:39:27
Done.
| |
| 67 TabbedPane* tabbed_pane_; | |
| 68 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.
| |
| 69 Tab* tab2_; | |
| 70 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.
| |
| 71 gfx::Point tab2_center_; | |
| 72 | |
| 73 private: | |
| 74 DISALLOW_COPY_AND_ASSIGN(TabbedPaneMacAccessibilityTest); | |
| 75 }; | |
| 76 | |
| 77 // Test the Tab's a11y information compared to a Cocoa NSTabViewItem. | |
| 78 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
| |
| 79 // Create a Cocoa NSTabView to test against and select the first tab. | |
| 80 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.
| |
| 81 [[NSTabView alloc] initWithFrame:NSMakeRect(50, 50, 100, 100)]; | |
| 82 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.
| |
| 83 NSTabViewItem* cocoa_tab2 = [[NSTabViewItem alloc] init]; | |
| 84 [cocoa_tab1 setLabel:@"Tab 1"]; | |
| 85 [cocoa_tab2 setLabel:@"Tab 2"]; | |
| 86 [cocoa_tab_group addTabViewItem:cocoa_tab1]; | |
| 87 [cocoa_tab_group addTabViewItem:cocoa_tab2]; | |
| 88 [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.
| |
| 89 | |
| 90 // General a11y information. | |
| 91 EXPECT_NSEQ( | |
| 92 [cocoa_tab1 accessibilityAttributeValue:NSAccessibilityRoleAttribute], | |
| 93 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.
| |
| 94 EXPECT_NSEQ( | |
| 95 [cocoa_tab1 | |
| 96 accessibilityAttributeValue:NSAccessibilityRoleDescriptionAttribute], | |
| 97 AttributeValueAtPoint(NSAccessibilityRoleDescriptionAttribute, | |
| 98 tab1_center_)); | |
| 99 EXPECT_NSEQ( | |
| 100 [cocoa_tab1 accessibilityAttributeValue:NSAccessibilityTitleAttribute], | |
| 101 AttributeValueAtPoint(NSAccessibilityTitleAttribute, tab1_center_)); | |
| 102 | |
| 103 // Check value attribute matches up with whether tabs are actually selected. | |
| 104 // 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
| |
| 105 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.
| |
| 106 [[cocoa_tab1 accessibilityAttributeValue:NSAccessibilityValueAttribute] | |
| 107 stringValue], | |
| 108 AttributeValueAtPoint(NSAccessibilityValueAttribute, tab1_center_)); | |
| 109 EXPECT_NSEQ( | |
| 110 [[cocoa_tab2 accessibilityAttributeValue:NSAccessibilityValueAttribute] | |
| 111 stringValue], | |
| 112 AttributeValueAtPoint(NSAccessibilityValueAttribute, tab2_center_)); | |
| 113 | |
| 114 // NSTabViewItem doesn't support NSAccessibilitySelectedAttribute, so don't | |
| 115 // compare against Cocoa here. | |
| 116 EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 117 tab1_center_) boolValue]); | |
| 118 EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 119 tab2_center_) boolValue]); | |
| 120 } | |
| 121 | |
| 122 // Make sure tabs can be selected by writing the value attribute. | |
| 123 TEST_F(TabbedPaneMacAccessibilityTest, WritableValue) { | |
| 124 id tab1_a11y = A11yElementAtPoint(tab1_center_); | |
| 125 id tab2_a11y = A11yElementAtPoint(tab2_center_); | |
| 126 | |
| 127 // Only unselected tabs should be writable. | |
| 128 EXPECT_FALSE([tab1_a11y | |
| 129 accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]); | |
| 130 EXPECT_TRUE([tab2_a11y | |
| 131 accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]); | |
| 132 | |
| 133 // Select the second tab. Since we are using a field that is actually an | |
| 134 // NSString, any valid string value provided should select the tab. | |
| 135 [tab2_a11y accessibilitySetValue:@"string" | |
| 136 forAttribute:NSAccessibilityValueAttribute]; | |
| 137 EXPECT_NSEQ( | |
| 138 @"0", AttributeValueAtPoint(NSAccessibilityValueAttribute, tab1_center_)); | |
| 139 EXPECT_NSEQ( | |
| 140 @"1", AttributeValueAtPoint(NSAccessibilityValueAttribute, tab2_center_)); | |
| 141 EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 142 tab1_center_) boolValue]); | |
| 143 EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 144 tab2_center_) boolValue]); | |
| 145 EXPECT_TRUE(tab2_->selected()); | |
| 146 | |
| 147 // Try again with an empty string. | |
| 148 [tab1_a11y accessibilitySetValue:@"" | |
| 149 forAttribute:NSAccessibilityValueAttribute]; | |
| 150 EXPECT_NSEQ( | |
| 151 @"1", AttributeValueAtPoint(NSAccessibilityValueAttribute, tab1_center_)); | |
| 152 EXPECT_NSEQ( | |
| 153 @"0", AttributeValueAtPoint(NSAccessibilityValueAttribute, tab2_center_)); | |
| 154 EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 155 tab1_center_) boolValue]); | |
| 156 EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 157 tab2_center_) boolValue]); | |
| 158 EXPECT_TRUE(tab1_->selected()); | |
| 159 } | |
|
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
| |
| 160 | |
| 161 } // namespace views | |
| OLD | NEW |