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/events/keycodes/keyboard_code_conversion.h" | |
| 13 #include "ui/views/test/views_test_base.h" | 14 #include "ui/views/test/views_test_base.h" |
| 14 | 15 |
| 15 using base::ASCIIToUTF16; | 16 using base::ASCIIToUTF16; |
| 16 | 17 |
| 17 namespace views { | 18 namespace views { |
| 18 | 19 |
| 19 namespace { | |
| 20 | |
| 21 // A view for testing that takes a fixed preferred size upon construction. | 20 // A view for testing that takes a fixed preferred size upon construction. |
| 22 class FixedSizeView : public View { | 21 class FixedSizeView : public View { |
| 23 public: | 22 public: |
| 24 explicit FixedSizeView(const gfx::Size& size) | 23 explicit FixedSizeView(const gfx::Size& size) |
| 25 : size_(size) {} | 24 : size_(size) {} |
| 26 | 25 |
| 27 // Overridden from View: | 26 // Overridden from View: |
| 28 gfx::Size GetPreferredSize() const override { return size_; } | 27 gfx::Size GetPreferredSize() const override { return size_; } |
| 29 | 28 |
| 30 private: | 29 private: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 79 |
| 81 // Select each tab. | 80 // Select each tab. |
| 82 for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) { | 81 for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) { |
| 83 tabbed_pane->SelectTabAt(i); | 82 tabbed_pane->SelectTabAt(i); |
| 84 EXPECT_EQ(i, tabbed_pane->selected_tab_index()); | 83 EXPECT_EQ(i, tabbed_pane->selected_tab_index()); |
| 85 } | 84 } |
| 86 | 85 |
| 87 // 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. |
| 88 View* tab0 = new View(); | 87 View* tab0 = new View(); |
| 89 tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0); | 88 tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0); |
| 90 EXPECT_NE(tab0, tabbed_pane->GetSelectedTab()); | 89 EXPECT_NE(tab0, tabbed_pane->GetSelectedTabContentView()); |
| 91 EXPECT_NE(0, tabbed_pane->selected_tab_index()); | 90 EXPECT_NE(0, tabbed_pane->selected_tab_index()); |
| 92 } | 91 } |
| 93 | 92 |
| 94 } // namespace | 93 ui::KeyEvent MakeKeyPressedEvent(ui::KeyboardCode keyboard_code, int flags) { |
| 94 return ui::KeyEvent(ui::ET_KEY_PRESSED, keyboard_code, | |
| 95 ui::UsLayoutKeyboardCodeToDomCode(keyboard_code), flags); | |
| 96 } | |
| 97 | |
| 98 TEST_F(TabbedPaneTest, ArrowKeyBindings) { | |
| 99 std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane()); | |
| 100 // Add several tabs; only the first should be a selected automatically. | |
| 101 for (int i = 0; i < 3; ++i) { | |
| 102 View* tab = new View(); | |
| 103 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); | |
| 104 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); | |
| 105 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); | |
|
sky
2016/10/06 21:14:40
Do you really need to do this assertion every test
Elly Fong-Jones
2016/10/07 17:18:24
No, I don't; it was just cargo-culted off one of t
| |
| 106 } | |
| 107 | |
| 108 // Right arrow should select tab 1: | |
| 109 tabbed_pane->GetSelectedTabAsView()->OnKeyPressed( | |
| 110 MakeKeyPressedEvent(ui::VKEY_RIGHT, 0)); | |
| 111 EXPECT_EQ(1, tabbed_pane->selected_tab_index()); | |
| 112 | |
| 113 // Left arrow should select tab 0: | |
| 114 tabbed_pane->GetSelectedTabAsView()->OnKeyPressed( | |
| 115 MakeKeyPressedEvent(ui::VKEY_LEFT, 0)); | |
| 116 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); | |
| 117 | |
| 118 // Left arrow again should wrap to tab 2: | |
| 119 tabbed_pane->GetSelectedTabAsView()->OnKeyPressed( | |
| 120 MakeKeyPressedEvent(ui::VKEY_LEFT, 0)); | |
| 121 EXPECT_EQ(2, tabbed_pane->selected_tab_index()); | |
| 122 | |
| 123 // Right arrow again should wrap to tab 0: | |
| 124 tabbed_pane->GetSelectedTabAsView()->OnKeyPressed( | |
| 125 MakeKeyPressedEvent(ui::VKEY_RIGHT, 0)); | |
| 126 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); | |
| 127 } | |
| 95 | 128 |
| 96 } // namespace views | 129 } // namespace views |
| OLD | NEW |