Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc

Issue 2368283002: views: add focus to TabbedPane (Closed)
Patch Set: rename some stuff, move Tab class Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 }
106
107 EXPECT_EQ(0, tabbed_pane->selected_tab_index());
108
109 // Right arrow should select tab 1:
110 tabbed_pane->GetSelectedTab()->OnKeyPressed(
111 MakeKeyPressedEvent(ui::VKEY_RIGHT, 0));
112 EXPECT_EQ(1, tabbed_pane->selected_tab_index());
113
114 // Left arrow should select tab 0:
115 tabbed_pane->GetSelectedTab()->OnKeyPressed(
116 MakeKeyPressedEvent(ui::VKEY_LEFT, 0));
117 EXPECT_EQ(0, tabbed_pane->selected_tab_index());
118
119 // Left arrow again should wrap to tab 2:
120 tabbed_pane->GetSelectedTab()->OnKeyPressed(
121 MakeKeyPressedEvent(ui::VKEY_LEFT, 0));
122 EXPECT_EQ(2, tabbed_pane->selected_tab_index());
123
124 // Right arrow again should wrap to tab 0:
125 tabbed_pane->GetSelectedTab()->OnKeyPressed(
126 MakeKeyPressedEvent(ui::VKEY_RIGHT, 0));
127 EXPECT_EQ(0, tabbed_pane->selected_tab_index());
128 }
95 129
96 } // namespace views 130 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/tabbed_pane/tabbed_pane.cc ('k') | ui/views/focus/focus_traversal_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698