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" |
| (...skipping 140 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 NativeViewAccessibility* nva = NativeViewAccessibility::Create(GetTabAt(i)); | 161 ui::AXNodeData data = |
| 162 ui::AXNodeData data = nva->GetData(); | 162 NativeViewAccessibility::Create(GetTabAt(i))->GetData(); |
| 163 SCOPED_TRACE(testing::Message() << "Tab at index: " << i); | 163 SCOPED_TRACE(testing::Message() << "Tab at index: " << i); |
| 164 EXPECT_EQ(ui::AX_ROLE_TAB, data.role); | 164 EXPECT_EQ(ui::AX_ROLE_TAB, data.role); |
| 165 EXPECT_EQ(DefaultTabTitle(), data.GetString16Attribute(ui::AX_ATTR_NAME)); | 165 EXPECT_EQ(DefaultTabTitle(), data.GetString16Attribute(ui::AX_ATTR_NAME)); |
| 166 EXPECT_TRUE(data.HasStateFlag(ui::AX_STATE_SELECTABLE)); | 166 EXPECT_TRUE(data.HasStateFlag(ui::AX_STATE_SELECTABLE)); |
| 167 EXPECT_EQ(i == 0, data.HasStateFlag(ui::AX_STATE_SELECTED)); | 167 EXPECT_EQ(i == 0, data.HasStateFlag(ui::AX_STATE_SELECTED)); |
| 168 nva->Destroy(); | |
| 169 } | 168 } |
| 170 | 169 |
| 171 ui::AXActionData action; | 170 ui::AXActionData action; |
| 172 action.action = ui::AX_ACTION_SET_SELECTION; | 171 action.action = ui::AX_ACTION_SET_SELECTION; |
| 173 // Select the first tab. | 172 // Select the first tab. |
| 174 NativeViewAccessibility* nva = NativeViewAccessibility::Create(GetTabAt(0)); | 173 |
| 175 nva->AccessibilityPerformAction(action); | 174 NativeViewAccessibility::Create(GetTabAt(0)) |
| 175 ->AccessibilityPerformAction(action); | |
| 176 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 176 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
| 177 nva->Destroy(); | |
| 178 | 177 |
| 179 // Select the second tab. | 178 // Select the second tab. |
| 180 nva = NativeViewAccessibility::Create(GetTabAt(1)); | 179 std::unique_ptr<NativeViewAccessibility> nva = |
| 180 NativeViewAccessibility::Create(GetTabAt(1)); | |
| 181 nva->AccessibilityPerformAction(action); | 181 nva->AccessibilityPerformAction(action); |
| 182 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 182 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
| 183 // Select the second tab again. | 183 // Select the second tab again. |
| 184 nva->AccessibilityPerformAction(action); | 184 nva->AccessibilityPerformAction(action); |
| 185 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 185 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
| 186 nva->Destroy(); | |
| 187 | 186 |
| 188 widget->CloseNow(); | 187 widget->CloseNow(); |
|
sky
2017/03/01 00:27:07
nva outlives widget (and thus the tab). Is that ok
Patti Lor
2017/03/01 07:13:13
Ah, yeah I think it would be bad if someone tried
| |
| 189 } | 188 } |
| 190 | 189 |
| 191 } // namespace test | 190 } // namespace test |
| 192 } // namespace views | 191 } // namespace views |
| OLD | NEW |