Chromium Code Reviews| Index: ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc |
| diff --git a/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc b/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc |
| index e02a2529307a0847d53b6a0cec5156fea606a5c7..49c5cb98116e5aeb16ee3c21126fa83da08b7d05 100644 |
| --- a/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc |
| +++ b/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc |
| @@ -10,8 +10,12 @@ |
| #include "base/message_loop/message_loop.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/accessibility/ax_action_data.h" |
| +#include "ui/accessibility/ax_enums.h" |
| #include "ui/events/keycodes/keyboard_code_conversion.h" |
| +#include "ui/views/accessibility/native_view_accessibility.h" |
| #include "ui/views/test/views_test_base.h" |
| +#include "ui/views/widget/widget.h" |
| using base::ASCIIToUTF16; |
| @@ -32,6 +36,8 @@ class FixedSizeView : public View { |
| DISALLOW_COPY_AND_ASSIGN(FixedSizeView); |
| }; |
| +base::string16 kTabTitle = ASCIIToUTF16("tab"); |
|
tapted
2017/01/06 04:25:12
This will make a static initializer, which will ge
Patti Lor
2017/01/09 22:39:28
Done.
|
| + |
| typedef ViewsTestBase TabbedPaneTest; |
|
tapted
2017/01/06 04:25:12
I think it's time to upgrade this to a proper test
Patti Lor
2017/01/09 22:39:28
Done.
|
| // Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout(). |
| @@ -69,10 +75,10 @@ TEST_F(TabbedPaneTest, SizeAndLayout) { |
| TEST_F(TabbedPaneTest, AddAndSelect) { |
| std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane()); |
| - // Add several tabs; only the first should be a selected automatically. |
| + // Add several tabs; only the first should be selected automatically. |
| for (int i = 0; i < 3; ++i) { |
| View* tab = new View(); |
| - tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); |
| + tabbed_pane->AddTab(kTabTitle, tab); |
| EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); |
| EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
| } |
| @@ -97,10 +103,10 @@ ui::KeyEvent MakeKeyPressedEvent(ui::KeyboardCode keyboard_code, int flags) { |
| TEST_F(TabbedPaneTest, ArrowKeyBindings) { |
| std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane()); |
| - // Add several tabs; only the first should be a selected automatically. |
| + // Add several tabs; only the first should be selected automatically. |
| for (int i = 0; i < 3; ++i) { |
| View* tab = new View(); |
| - tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); |
| + tabbed_pane->AddTab(kTabTitle, tab); |
| EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); |
| } |
| @@ -127,4 +133,55 @@ TEST_F(TabbedPaneTest, ArrowKeyBindings) { |
| EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
| } |
| +// Use TabbedPane::HandleAccessibleAction() to select tabs and make sure their |
| +// a11y information is correct. |
| +TEST_F(TabbedPaneTest, SelectTabWithAccessibleAction) { |
| + // Testing accessibility information requires the View to have a Widget. |
| + Widget* widget = new Widget; |
| + Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| + widget->Init(params); |
| + TabbedPane* tabbed_pane = new TabbedPane(); |
| + widget->GetContentsView()->AddChildView(tabbed_pane); |
| + widget->Show(); |
| + |
| + const int num_tabs = 2; |
|
tapted
2017/01/06 04:25:12
constexpr int kNumTabs = 2;
(constexpr helps guar
Patti Lor
2017/01/09 22:39:28
Done, thanks I didn't know about constexpr.
|
| + std::vector<Tab*> tab_list; |
| + for (int i = 0; i <= num_tabs; ++i) { |
|
tapted
2017/01/06 04:25:12
this ends up making 3 tabs, which I see is intenti
Patti Lor
2017/01/09 22:39:28
Done.
|
| + tabbed_pane->AddTab(kTabTitle, new View()); |
| + tabbed_pane->SelectTabAt(i); |
| + tab_list.push_back(tabbed_pane->GetSelectedTab()); |
| + } |
| + // Check the last tab added is selected. |
| + EXPECT_EQ(num_tabs, tabbed_pane->GetSelectedTabIndex()); |
| + |
| + // Check the a11y information for each tab. |
| + for (int i = 0; i <= num_tabs; ++i) { |
| + ui::AXNodeData data = |
| + NativeViewAccessibility::Create(tab_list[i])->GetData(); |
| + SCOPED_TRACE(testing::Message() << "Tab at index: " << i); |
| + EXPECT_EQ(ui::AX_ROLE_TAB, data.role); |
| + EXPECT_EQ(kTabTitle, data.GetString16Attribute(ui::AX_ATTR_NAME)); |
| + EXPECT_TRUE(data.HasStateFlag(ui::AX_STATE_SELECTABLE)); |
| + EXPECT_EQ(i == num_tabs, data.HasStateFlag(ui::AX_STATE_SELECTED)); |
|
tapted
2017/01/06 04:25:12
e.g. i == kNumTabs - 1
Patti Lor
2017/01/09 22:39:28
Done.
|
| + } |
| + |
| + ui::AXActionData action; |
| + action.action = ui::AX_ACTION_SET_SELECTION; |
| + // Select the first tab. |
| + NativeViewAccessibility::Create(tab_list[0]) |
|
tapted
2017/01/06 04:25:12
I think this is leaked. It's possible you are actu
Patti Lor
2017/01/09 22:39:28
Yep, I am - I think this change might land first t
|
| + ->AccessibilityPerformAction(action); |
| + EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
| + |
| + // Select the second tab. |
| + NativeViewAccessibility::Create(tab_list[1]) |
| + ->AccessibilityPerformAction(action); |
| + EXPECT_EQ(1, tabbed_pane->GetSelectedTabIndex()); |
| + // Select the second tab again. |
| + NativeViewAccessibility::Create(tab_list[1]) |
| + ->AccessibilityPerformAction(action); |
| + EXPECT_EQ(1, tabbed_pane->GetSelectedTabIndex()); |
| + |
| + widget->Close(); |
|
tapted
2017/01/06 04:25:12
nit: CloseNow()
Patti Lor
2017/01/09 22:39:28
Done.
|
| +} |
| + |
| } // namespace views |