Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 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 | |
|
tapted
2017/01/10 16:22:19
nit: remove blank line
Patti Lor
2017/01/11 05:51:44
Done.
| |
| 17 namespace test { | |
| 18 | |
| 19 class TabbedPaneAccessibilityMacTest : public WidgetTest { | |
| 20 public: | |
| 21 TabbedPaneAccessibilityMacTest() {} | |
| 22 | |
| 23 void SetUp() override { | |
|
tapted
2017/01/10 16:22:19
nit: // WidgetTest:
(or testing::Test, but pkasti
Patti Lor
2017/01/11 05:51:44
Done.
| |
| 24 WidgetTest::SetUp(); | |
| 25 widget_ = CreateTopLevelPlatformWidget(); | |
| 26 widget_->SetBounds(gfx::Rect(50, 50, 100, 100)); | |
| 27 tabbed_pane_ = new TabbedPane(); | |
| 28 tabbed_pane_->SetSize(gfx::Size(100, 100)); | |
| 29 | |
| 30 // Create two tabs and position/size them. | |
| 31 tabbed_pane_->AddTab(base::ASCIIToUTF16("Tab 1"), new View()); | |
| 32 tabbed_pane_->AddTab(base::ASCIIToUTF16("Tab 2"), new View()); | |
| 33 tabbed_pane_->Layout(); | |
| 34 | |
| 35 widget_->GetContentsView()->AddChildView(tabbed_pane_); | |
| 36 widget_->Show(); | |
| 37 } | |
| 38 | |
| 39 void TearDown() override { | |
| 40 widget_->CloseNow(); | |
| 41 WidgetTest::TearDown(); | |
| 42 } | |
| 43 | |
| 44 Tab* GetTabAt(int index) { | |
| 45 return static_cast<Tab*>(tabbed_pane_->tab_strip_->child_at(index)); | |
|
tapted
2017/01/10 16:22:19
So there's something a bit uglier that should work
Patti Lor
2017/01/11 05:51:44
Yeah - this method is also needed in TabbedViewTes
| |
| 46 } | |
| 47 | |
| 48 id AttributeValueAtPoint(NSString* attribute, const gfx::Point& point) { | |
| 49 id value = | |
| 50 [A11yElementAtPoint(point) accessibilityAttributeValue:attribute]; | |
| 51 EXPECT_NE(nil, value); | |
| 52 return value; | |
| 53 } | |
| 54 | |
| 55 id A11yElementAtPoint(const gfx::Point& point) { | |
| 56 // Accessibility hit tests come in Cocoa screen coordinates. | |
| 57 NSPoint ns_point = gfx::ScreenPointToNSPoint(point); | |
| 58 return [widget_->GetNativeWindow() accessibilityHitTest:ns_point]; | |
| 59 } | |
| 60 | |
| 61 gfx::Point TabCenterPoint(int index) { | |
| 62 return GetTabAt(index)->GetBoundsInScreen().CenterPoint(); | |
| 63 } | |
| 64 | |
| 65 protected: | |
| 66 Widget* widget_; | |
|
tapted
2017/01/10 16:22:19
nit: = nullptr (since it's not set in the constru
Patti Lor
2017/01/11 05:51:44
Done.
| |
| 67 TabbedPane* tabbed_pane_; | |
|
tapted
2017/01/10 16:22:19
= nullptr
Patti Lor
2017/01/11 05:51:44
Done.
| |
| 68 | |
| 69 private: | |
| 70 DISALLOW_COPY_AND_ASSIGN(TabbedPaneAccessibilityMacTest); | |
| 71 }; | |
| 72 | |
| 73 // Test the Tab's a11y information compared to a Cocoa NSTabViewItem. | |
| 74 TEST_F(TabbedPaneAccessibilityMacTest, AttributesMatchAppKit) { | |
| 75 // Create a Cocoa NSTabView to test against and select the first tab. | |
| 76 NSTabView* cocoa_tab_group = | |
|
tapted
2017/01/10 16:22:19
this one still needs a scoped_nsobject (you could
Patti Lor
2017/01/11 05:51:44
Done, thanks for the explanation!
| |
| 77 [[NSTabView alloc] initWithFrame:NSMakeRect(50, 50, 100, 100)]; | |
| 78 NSArray* cocoa_tabs = @[ | |
| 79 [[[NSTabViewItem alloc] init] autorelease], | |
| 80 [[[NSTabViewItem alloc] init] autorelease], | |
| 81 ]; | |
| 82 for (size_t i = 0; i < [cocoa_tabs count]; ++i) { | |
| 83 [cocoa_tabs[i] setLabel:[NSString stringWithFormat:@"Tab %zu", i + 1]]; | |
| 84 [cocoa_tab_group addTabViewItem:cocoa_tabs[i]]; | |
| 85 } | |
| 86 | |
| 87 // General a11y information. | |
| 88 EXPECT_NSEQ( | |
| 89 [cocoa_tabs[0] accessibilityAttributeValue:NSAccessibilityRoleAttribute], | |
| 90 AttributeValueAtPoint(NSAccessibilityRoleAttribute, TabCenterPoint(0))); | |
| 91 EXPECT_NSEQ( | |
| 92 [cocoa_tabs[0] | |
| 93 accessibilityAttributeValue:NSAccessibilityRoleDescriptionAttribute], | |
| 94 AttributeValueAtPoint(NSAccessibilityRoleDescriptionAttribute, | |
| 95 TabCenterPoint(0))); | |
| 96 EXPECT_NSEQ( | |
| 97 [cocoa_tabs[0] accessibilityAttributeValue:NSAccessibilityTitleAttribute], | |
| 98 AttributeValueAtPoint(NSAccessibilityTitleAttribute, TabCenterPoint(0))); | |
| 99 | |
| 100 // Check value attribute matches up with whether tabs are actually selected. | |
|
tapted
2017/01/10 16:22:19
nit: Compare against native Cocoa values, and chec
Patti Lor
2017/01/11 05:51:44
Done.
| |
| 101 for (int i : {0, 1}) { | |
| 102 NSNumber* cocoa_value = [cocoa_tabs[i] | |
| 103 accessibilityAttributeValue:NSAccessibilityValueAttribute]; | |
| 104 EXPECT_EQ(i ? 0 : 1, [cocoa_value intValue]); | |
|
tapted
2017/01/10 16:22:19
nit: comment like
// Verify that only the seco
Patti Lor
2017/01/11 05:51:44
Done.
| |
| 105 EXPECT_NSEQ(cocoa_value, | |
| 106 AttributeValueAtPoint(NSAccessibilityValueAttribute, | |
| 107 TabCenterPoint(i))); | |
| 108 } | |
| 109 | |
| 110 // NSTabViewItem doesn't support NSAccessibilitySelectedAttribute, so don't | |
| 111 // compare against Cocoa here. | |
| 112 EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 113 TabCenterPoint(0)) boolValue]); | |
| 114 EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 115 TabCenterPoint(1)) boolValue]); | |
| 116 } | |
| 117 | |
| 118 // Make sure tabs can be selected by writing the value attribute. | |
| 119 TEST_F(TabbedPaneAccessibilityMacTest, WritableValue) { | |
| 120 id tab1_a11y = A11yElementAtPoint(TabCenterPoint(0)); | |
| 121 id tab2_a11y = A11yElementAtPoint(TabCenterPoint(1)); | |
| 122 | |
| 123 // Only unselected tabs should be writable. | |
| 124 EXPECT_FALSE([tab1_a11y | |
| 125 accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]); | |
| 126 EXPECT_TRUE([tab2_a11y | |
| 127 accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]); | |
| 128 | |
| 129 // Select the second tab. Since we are using a field that is actually an | |
| 130 // NSString, any valid string value provided should select the tab. | |
| 131 [tab2_a11y accessibilitySetValue:@"string" | |
| 132 forAttribute:NSAccessibilityValueAttribute]; | |
| 133 EXPECT_EQ(0, [AttributeValueAtPoint(NSAccessibilityValueAttribute, | |
| 134 TabCenterPoint(0)) intValue]); | |
| 135 EXPECT_EQ(1, [AttributeValueAtPoint(NSAccessibilityValueAttribute, | |
| 136 TabCenterPoint(1)) intValue]); | |
| 137 EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 138 TabCenterPoint(0)) boolValue]); | |
| 139 EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 140 TabCenterPoint(1)) boolValue]); | |
| 141 EXPECT_TRUE(GetTabAt(1)->selected()); | |
| 142 | |
| 143 // Try again with an empty string. | |
| 144 [tab1_a11y accessibilitySetValue:@"" | |
|
tapted
2017/01/10 16:22:19
I find this a bit counterintuitive. E.g. maybe set
Patti Lor
2017/01/11 05:51:44
Done - I also updated the comment on line 129, too
| |
| 145 forAttribute:NSAccessibilityValueAttribute]; | |
| 146 EXPECT_EQ(1, [AttributeValueAtPoint(NSAccessibilityValueAttribute, | |
| 147 TabCenterPoint(0)) intValue]); | |
| 148 EXPECT_EQ(0, [AttributeValueAtPoint(NSAccessibilityValueAttribute, | |
| 149 TabCenterPoint(1)) intValue]); | |
| 150 EXPECT_TRUE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 151 TabCenterPoint(0)) boolValue]); | |
| 152 EXPECT_FALSE([AttributeValueAtPoint(NSAccessibilitySelectedAttribute, | |
| 153 TabCenterPoint(1)) boolValue]); | |
| 154 EXPECT_TRUE(GetTabAt(0)->selected()); | |
| 155 } | |
| 156 | |
| 157 } // namespace test | |
| 158 | |
|
tapted
2017/01/10 16:22:19
nit: remove blank line
Patti Lor
2017/01/11 05:51:44
Done.
| |
| 159 } // namespace views | |
| OLD | NEW |