| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 EXPECT_EQ(bounds, child2->bounds()); | 67 EXPECT_EQ(bounds, child2->bounds()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(TabbedPaneTest, AddAndSelect) { | 70 TEST_F(TabbedPaneTest, AddAndSelect) { |
| 71 std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane()); | 71 std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane()); |
| 72 // Add several tabs; only the first should be a selected automatically. | 72 // Add several tabs; only the first should be a selected automatically. |
| 73 for (int i = 0; i < 3; ++i) { | 73 for (int i = 0; i < 3; ++i) { |
| 74 View* tab = new View(); | 74 View* tab = new View(); |
| 75 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); | 75 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); |
| 76 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); | 76 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); |
| 77 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); | 77 EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Select each tab. | 80 // Select each tab. |
| 81 for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) { | 81 for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) { |
| 82 tabbed_pane->SelectTabAt(i); | 82 tabbed_pane->SelectTabAt(i); |
| 83 EXPECT_EQ(i, tabbed_pane->selected_tab_index()); | 83 EXPECT_EQ(i, tabbed_pane->GetSelectedTabIndex()); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Add a tab at index 0, it should not be selected automatically. | 86 // Add a tab at index 0, it should not be selected automatically. |
| 87 View* tab0 = new View(); | 87 View* tab0 = new View(); |
| 88 tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0); | 88 tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0); |
| 89 EXPECT_NE(tab0, tabbed_pane->GetSelectedTabContentView()); | 89 EXPECT_NE(tab0, tabbed_pane->GetSelectedTabContentView()); |
| 90 EXPECT_NE(0, tabbed_pane->selected_tab_index()); | 90 EXPECT_NE(0, tabbed_pane->GetSelectedTabIndex()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 ui::KeyEvent MakeKeyPressedEvent(ui::KeyboardCode keyboard_code, int flags) { | 93 ui::KeyEvent MakeKeyPressedEvent(ui::KeyboardCode keyboard_code, int flags) { |
| 94 return ui::KeyEvent(ui::ET_KEY_PRESSED, keyboard_code, | 94 return ui::KeyEvent(ui::ET_KEY_PRESSED, keyboard_code, |
| 95 ui::UsLayoutKeyboardCodeToDomCode(keyboard_code), flags); | 95 ui::UsLayoutKeyboardCodeToDomCode(keyboard_code), flags); |
| 96 } | 96 } |
| 97 | 97 |
| 98 TEST_F(TabbedPaneTest, ArrowKeyBindings) { | 98 TEST_F(TabbedPaneTest, ArrowKeyBindings) { |
| 99 std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane()); | 99 std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane()); |
| 100 // Add several tabs; only the first should be a selected automatically. | 100 // Add several tabs; only the first should be a selected automatically. |
| 101 for (int i = 0; i < 3; ++i) { | 101 for (int i = 0; i < 3; ++i) { |
| 102 View* tab = new View(); | 102 View* tab = new View(); |
| 103 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); | 103 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); |
| 104 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); | 104 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); | 107 EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
| 108 | 108 |
| 109 // Right arrow should select tab 1: | 109 // Right arrow should select tab 1: |
| 110 tabbed_pane->GetSelectedTab()->OnKeyPressed( | 110 tabbed_pane->GetSelectedTab()->OnKeyPressed( |
| 111 MakeKeyPressedEvent(ui::VKEY_RIGHT, 0)); | 111 MakeKeyPressedEvent(ui::VKEY_RIGHT, 0)); |
| 112 EXPECT_EQ(1, tabbed_pane->selected_tab_index()); | 112 EXPECT_EQ(1, tabbed_pane->GetSelectedTabIndex()); |
| 113 | 113 |
| 114 // Left arrow should select tab 0: | 114 // Left arrow should select tab 0: |
| 115 tabbed_pane->GetSelectedTab()->OnKeyPressed( | 115 tabbed_pane->GetSelectedTab()->OnKeyPressed( |
| 116 MakeKeyPressedEvent(ui::VKEY_LEFT, 0)); | 116 MakeKeyPressedEvent(ui::VKEY_LEFT, 0)); |
| 117 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); | 117 EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
| 118 | 118 |
| 119 // Left arrow again should wrap to tab 2: | 119 // Left arrow again should wrap to tab 2: |
| 120 tabbed_pane->GetSelectedTab()->OnKeyPressed( | 120 tabbed_pane->GetSelectedTab()->OnKeyPressed( |
| 121 MakeKeyPressedEvent(ui::VKEY_LEFT, 0)); | 121 MakeKeyPressedEvent(ui::VKEY_LEFT, 0)); |
| 122 EXPECT_EQ(2, tabbed_pane->selected_tab_index()); | 122 EXPECT_EQ(2, tabbed_pane->GetSelectedTabIndex()); |
| 123 | 123 |
| 124 // Right arrow again should wrap to tab 0: | 124 // Right arrow again should wrap to tab 0: |
| 125 tabbed_pane->GetSelectedTab()->OnKeyPressed( | 125 tabbed_pane->GetSelectedTab()->OnKeyPressed( |
| 126 MakeKeyPressedEvent(ui::VKEY_RIGHT, 0)); | 126 MakeKeyPressedEvent(ui::VKEY_RIGHT, 0)); |
| 127 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); | 127 EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 } // namespace views | 130 } // namespace views |
| OLD | NEW |