Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" | 5 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/accessibility/ax_action_data.h" | 13 #include "ui/accessibility/ax_action_data.h" |
| 14 #include "ui/accessibility/ax_enums.h" | 14 #include "ui/accessibility/ax_enums.h" |
| 15 #include "ui/base/ui_features.h" | |
| 15 #include "ui/events/keycodes/keyboard_code_conversion.h" | 16 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 16 #include "ui/views/accessibility/native_view_accessibility.h" | |
| 17 #include "ui/views/test/test_views.h" | 17 #include "ui/views/test/test_views.h" |
| 18 #include "ui/views/test/views_test_base.h" | 18 #include "ui/views/test/views_test_base.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 #if BUILDFLAG(HAS_PLATFORM_ACCESSIBILITY) | |
| 22 #include "ui/views/accessibility/native_view_accessibility.h" | |
| 23 #endif | |
| 24 | |
| 21 using base::ASCIIToUTF16; | 25 using base::ASCIIToUTF16; |
| 22 | 26 |
| 23 namespace views { | 27 namespace views { |
| 24 namespace test { | 28 namespace test { |
| 25 namespace { | 29 namespace { |
| 26 | 30 |
| 27 base::string16 DefaultTabTitle() { | 31 base::string16 DefaultTabTitle() { |
| 28 return ASCIIToUTF16("tab"); | 32 return ASCIIToUTF16("tab"); |
| 29 } | 33 } |
| 30 | 34 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 136 |
| 133 // Left arrow again should wrap to tab 2: | 137 // Left arrow again should wrap to tab 2: |
| 134 SendKeyPressToSelectedTab(ui::VKEY_LEFT); | 138 SendKeyPressToSelectedTab(ui::VKEY_LEFT); |
| 135 EXPECT_EQ(2, tabbed_pane_->GetSelectedTabIndex()); | 139 EXPECT_EQ(2, tabbed_pane_->GetSelectedTabIndex()); |
| 136 | 140 |
| 137 // Right arrow again should wrap to tab 0: | 141 // Right arrow again should wrap to tab 0: |
| 138 SendKeyPressToSelectedTab(ui::VKEY_RIGHT); | 142 SendKeyPressToSelectedTab(ui::VKEY_RIGHT); |
| 139 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 143 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
| 140 } | 144 } |
| 141 | 145 |
| 146 #if BUILDFLAG(HAS_PLATFORM_ACCESSIBILITY) | |
|
dmazzoni
2017/03/20 15:44:06
Hmmm, I understand why you did this, but the Views
tapted
2017/03/21 02:27:49
Done.
| |
| 147 | |
| 142 // Use TabbedPane::HandleAccessibleAction() to select tabs and make sure their | 148 // Use TabbedPane::HandleAccessibleAction() to select tabs and make sure their |
| 143 // a11y information is correct. | 149 // a11y information is correct. |
| 144 TEST_F(TabbedPaneTest, SelectTabWithAccessibleAction) { | 150 TEST_F(TabbedPaneTest, SelectTabWithAccessibleAction) { |
| 145 // Testing accessibility information requires the View to have a Widget. | 151 // Testing accessibility information requires the View to have a Widget. |
| 146 Widget* widget = new Widget; | 152 Widget* widget = new Widget; |
| 147 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 153 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 148 widget->Init(params); | 154 widget->Init(params); |
| 149 widget->GetContentsView()->AddChildView(tabbed_pane_.get()); | 155 widget->GetContentsView()->AddChildView(tabbed_pane_.get()); |
| 150 widget->Show(); | 156 widget->Show(); |
| 151 | 157 |
| 152 constexpr int kNumTabs = 3; | 158 constexpr int kNumTabs = 3; |
| 153 for (int i = 0; i < kNumTabs; ++i) { | 159 for (int i = 0; i < kNumTabs; ++i) { |
| 154 tabbed_pane_->AddTab(DefaultTabTitle(), new View()); | 160 tabbed_pane_->AddTab(DefaultTabTitle(), new View()); |
| 155 } | 161 } |
| 156 // Check the first tab is selected. | 162 // Check the first tab is selected. |
| 157 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 163 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
| 158 | 164 |
| 165 // Usually these are owned by a View. Put them on the stack so they can be | |
| 166 // accessed for testing. | |
| 167 std::unique_ptr<NativeViewAccessibilityBase> nva[kNumTabs]; | |
| 168 NativeViewAccessibility* pnva[kNumTabs]; | |
| 169 | |
| 159 // Check the a11y information for each tab. | 170 // Check the a11y information for each tab. |
| 160 for (int i = 0; i < kNumTabs; ++i) { | 171 for (int i = 0; i < kNumTabs; ++i) { |
| 161 ui::AXNodeData data = | 172 nva[i] = NativeViewAccessibilityBase::Create(GetTabAt(i)); |
| 162 NativeViewAccessibility::Create(GetTabAt(i))->GetData(); | 173 pnva[i] = static_cast<NativeViewAccessibility*>(nva[i].get()); |
| 174 ui::AXNodeData data = pnva[i]->GetData(); | |
|
dmazzoni
2017/03/20 15:44:06
How about GetTabAt(i)->GetAccessibleNodeData() ins
tapted
2017/03/21 02:27:49
Done.
| |
| 163 SCOPED_TRACE(testing::Message() << "Tab at index: " << i); | 175 SCOPED_TRACE(testing::Message() << "Tab at index: " << i); |
| 164 EXPECT_EQ(ui::AX_ROLE_TAB, data.role); | 176 EXPECT_EQ(ui::AX_ROLE_TAB, data.role); |
| 165 EXPECT_EQ(DefaultTabTitle(), data.GetString16Attribute(ui::AX_ATTR_NAME)); | 177 EXPECT_EQ(DefaultTabTitle(), data.GetString16Attribute(ui::AX_ATTR_NAME)); |
| 166 EXPECT_TRUE(data.HasStateFlag(ui::AX_STATE_SELECTABLE)); | 178 EXPECT_TRUE(data.HasStateFlag(ui::AX_STATE_SELECTABLE)); |
| 167 EXPECT_EQ(i == 0, data.HasStateFlag(ui::AX_STATE_SELECTED)); | 179 EXPECT_EQ(i == 0, data.HasStateFlag(ui::AX_STATE_SELECTED)); |
| 168 } | 180 } |
| 169 | 181 |
| 170 ui::AXActionData action; | 182 ui::AXActionData action; |
| 171 action.action = ui::AX_ACTION_SET_SELECTION; | 183 action.action = ui::AX_ACTION_SET_SELECTION; |
| 172 // Select the first tab. | 184 // Select the first tab. |
| 173 | 185 |
| 174 NativeViewAccessibility::Create(GetTabAt(0)) | 186 pnva[0]->AccessibilityPerformAction(action); |
|
dmazzoni
2017/03/20 15:44:06
Same here: GetTabAt(i)->HandleAccessibleAction. If
tapted
2017/03/21 02:27:49
Done.
| |
| 175 ->AccessibilityPerformAction(action); | |
| 176 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 187 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
| 177 | 188 |
| 178 // Select the second tab. | 189 // Select the second tab. |
| 179 std::unique_ptr<NativeViewAccessibility> nva = | 190 pnva[1]->AccessibilityPerformAction(action); |
| 180 NativeViewAccessibility::Create(GetTabAt(1)); | |
| 181 nva->AccessibilityPerformAction(action); | |
| 182 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 191 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
| 183 // Select the second tab again. | 192 // Select the second tab again. |
| 184 nva->AccessibilityPerformAction(action); | 193 pnva[1]->AccessibilityPerformAction(action); |
| 185 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 194 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
| 186 | 195 |
| 187 nva.reset(); | 196 for (auto& ptr : nva) |
| 197 ptr.reset(); | |
| 198 | |
| 188 widget->CloseNow(); | 199 widget->CloseNow(); |
| 189 } | 200 } |
| 190 | 201 |
| 202 #endif // HAS_PLATFORM_ACCESSIBILITY | |
| 203 | |
| 191 } // namespace test | 204 } // namespace test |
| 192 } // namespace views | 205 } // namespace views |
| OLD | NEW |