| 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/accessibility/ax_node_data.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 using base::ASCIIToUTF16; | 21 using base::ASCIIToUTF16; |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 namespace test { | 24 namespace test { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 constexpr int kNumTabs = 3; | 152 constexpr int kNumTabs = 3; |
| 153 for (int i = 0; i < kNumTabs; ++i) { | 153 for (int i = 0; i < kNumTabs; ++i) { |
| 154 tabbed_pane_->AddTab(DefaultTabTitle(), new View()); | 154 tabbed_pane_->AddTab(DefaultTabTitle(), new View()); |
| 155 } | 155 } |
| 156 // Check the first tab is selected. | 156 // Check the first tab is selected. |
| 157 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 157 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
| 158 | 158 |
| 159 // Check the a11y information for each tab. | 159 // Check the a11y information for each tab. |
| 160 for (int i = 0; i < kNumTabs; ++i) { | 160 for (int i = 0; i < kNumTabs; ++i) { |
| 161 ui::AXNodeData data = | 161 ui::AXNodeData data; |
| 162 NativeViewAccessibility::Create(GetTabAt(i))->GetData(); | 162 |
| 163 // AXViewObjWrapper::Serialize() and NativeViewAccessibilityBase::GetData() |
| 164 // are normally responsible for clearing the state from the default |
| 165 // AXNodeData constructor. Do the same here. |
| 166 data.state = 0; |
| 167 |
| 168 GetTabAt(i)->GetAccessibleNodeData(&data); |
| 163 SCOPED_TRACE(testing::Message() << "Tab at index: " << i); | 169 SCOPED_TRACE(testing::Message() << "Tab at index: " << i); |
| 164 EXPECT_EQ(ui::AX_ROLE_TAB, data.role); | 170 EXPECT_EQ(ui::AX_ROLE_TAB, data.role); |
| 165 EXPECT_EQ(DefaultTabTitle(), data.GetString16Attribute(ui::AX_ATTR_NAME)); | 171 EXPECT_EQ(DefaultTabTitle(), data.GetString16Attribute(ui::AX_ATTR_NAME)); |
| 166 EXPECT_TRUE(data.HasStateFlag(ui::AX_STATE_SELECTABLE)); | 172 EXPECT_TRUE(data.HasStateFlag(ui::AX_STATE_SELECTABLE)); |
| 167 EXPECT_EQ(i == 0, data.HasStateFlag(ui::AX_STATE_SELECTED)); | 173 EXPECT_EQ(i == 0, data.HasStateFlag(ui::AX_STATE_SELECTED)); |
| 168 } | 174 } |
| 169 | 175 |
| 170 ui::AXActionData action; | 176 ui::AXActionData action; |
| 171 action.action = ui::AX_ACTION_SET_SELECTION; | 177 action.action = ui::AX_ACTION_SET_SELECTION; |
| 172 // Select the first tab. | 178 // Select the first tab. |
| 173 | 179 |
| 174 NativeViewAccessibility::Create(GetTabAt(0)) | 180 GetTabAt(0)->HandleAccessibleAction(action); |
| 175 ->AccessibilityPerformAction(action); | |
| 176 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 181 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
| 177 | 182 |
| 178 // Select the second tab. | 183 // Select the second tab. |
| 179 std::unique_ptr<NativeViewAccessibility> nva = | 184 GetTabAt(1)->HandleAccessibleAction(action); |
| 180 NativeViewAccessibility::Create(GetTabAt(1)); | |
| 181 nva->AccessibilityPerformAction(action); | |
| 182 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 185 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
| 183 // Select the second tab again. | 186 // Select the second tab again. |
| 184 nva->AccessibilityPerformAction(action); | 187 GetTabAt(1)->HandleAccessibleAction(action); |
| 185 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 188 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
| 186 | 189 |
| 187 nva.reset(); | |
| 188 widget->CloseNow(); | 190 widget->CloseNow(); |
| 189 } | 191 } |
| 190 | 192 |
| 191 } // namespace test | 193 } // namespace test |
| 192 } // namespace views | 194 } // namespace views |
| OLD | NEW |