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

Unified Diff: ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc

Issue 2368283002: views: add focus to TabbedPane (Closed)
Patch Set: sed tr sed 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
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..c1cfcbe18613c8bf55ebca71059384014e94d186 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,44 @@ 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());
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
+ }
+
+ // Right arrow should select tab 1:
+ tabbed_pane->GetSelectedTabAsView()->OnKeyPressed(
+ MakeKeyPressedEvent(ui::VKEY_RIGHT, 0));
+ EXPECT_EQ(1, tabbed_pane->selected_tab_index());
+
+ // Left arrow should select tab 0:
+ tabbed_pane->GetSelectedTabAsView()->OnKeyPressed(
+ MakeKeyPressedEvent(ui::VKEY_LEFT, 0));
+ EXPECT_EQ(0, tabbed_pane->selected_tab_index());
+
+ // Left arrow again should wrap to tab 2:
+ tabbed_pane->GetSelectedTabAsView()->OnKeyPressed(
+ MakeKeyPressedEvent(ui::VKEY_LEFT, 0));
+ EXPECT_EQ(2, tabbed_pane->selected_tab_index());
+
+ // Right arrow again should wrap to tab 0:
+ tabbed_pane->GetSelectedTabAsView()->OnKeyPressed(
+ MakeKeyPressedEvent(ui::VKEY_RIGHT, 0));
+ EXPECT_EQ(0, tabbed_pane->selected_tab_index());
+}
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698