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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7152f7eb4f081205e4716b629db38ed46ec291e1..9b1fb8cf562d5761af8b4760f33a15494a43cd52 100644
--- a/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc
+++ b/ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc
@@ -10,14 +10,13 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/events/keycodes/keyboard_code_conversion.h"
#include "ui/views/test/views_test_base.h"
using base::ASCIIToUTF16;
namespace views {
-namespace {
-
// A view for testing that takes a fixed preferred size upon construction.
class FixedSizeView : public View {
public:
@@ -87,10 +86,45 @@ TEST_F(TabbedPaneTest, AddAndSelect) {
// Add a tab at index 0, it should not be selected automatically.
View* tab0 = new View();
tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0);
- EXPECT_NE(tab0, tabbed_pane->GetSelectedTab());
+ EXPECT_NE(tab0, tabbed_pane->GetSelectedTabContentView());
EXPECT_NE(0, tabbed_pane->selected_tab_index());
}
-} // namespace
+ui::KeyEvent MakeKeyPressedEvent(ui::KeyboardCode keyboard_code, int flags) {
+ return ui::KeyEvent(ui::ET_KEY_PRESSED, keyboard_code,
+ ui::UsLayoutKeyboardCodeToDomCode(keyboard_code), flags);
+}
+
+TEST_F(TabbedPaneTest, ArrowKeyBindings) {
+ std::unique_ptr<TabbedPane> tabbed_pane(new TabbedPane());
+ // Add several tabs; only the first should be a selected automatically.
+ for (int i = 0; i < 3; ++i) {
+ View* tab = new View();
+ tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab);
+ EXPECT_EQ(i + 1, tabbed_pane->GetTabCount());
+ }
+
+ EXPECT_EQ(0, tabbed_pane->selected_tab_index());
+
+ // Right arrow should select tab 1:
+ tabbed_pane->GetSelectedTab()->OnKeyPressed(
+ MakeKeyPressedEvent(ui::VKEY_RIGHT, 0));
+ EXPECT_EQ(1, tabbed_pane->selected_tab_index());
+
+ // Left arrow should select tab 0:
+ tabbed_pane->GetSelectedTab()->OnKeyPressed(
+ MakeKeyPressedEvent(ui::VKEY_LEFT, 0));
+ EXPECT_EQ(0, tabbed_pane->selected_tab_index());
+
+ // Left arrow again should wrap to tab 2:
+ tabbed_pane->GetSelectedTab()->OnKeyPressed(
+ MakeKeyPressedEvent(ui::VKEY_LEFT, 0));
+ EXPECT_EQ(2, tabbed_pane->selected_tab_index());
+
+ // Right arrow again should wrap to tab 0:
+ tabbed_pane->GetSelectedTab()->OnKeyPressed(
+ MakeKeyPressedEvent(ui::VKEY_RIGHT, 0));
+ EXPECT_EQ(0, tabbed_pane->selected_tab_index());
+}
} // namespace views
« 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