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

Unified Diff: ui/views/focus/focus_manager_unittest.cc

Issue 14827004: cros: Arrow key traversal in views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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/focus/focus_manager_unittest.cc
diff --git a/ui/views/focus/focus_manager_unittest.cc b/ui/views/focus/focus_manager_unittest.cc
index cfef89e74b1f316121699c1f70bcea5446ba8075..63835ac53bd3c0d67a3482ab41b6f3b8a4ab0a1a 100644
--- a/ui/views/focus/focus_manager_unittest.cc
+++ b/ui/views/focus/focus_manager_unittest.cc
@@ -740,4 +740,78 @@ TEST_F(FocusManagerTest, ImplicitlyStoresFocus) {
EXPECT_EQ(v2, GetWidget()->GetFocusManager()->GetStoredFocusView());
}
+namespace {
+
+class FocusManagerArrowKeyTraversalTest : public FocusManagerTest {
+ public:
+ FocusManagerArrowKeyTraversalTest()
+ : previous_arrow_key_traversal_enabled_(false) {
+ }
+ virtual ~FocusManagerArrowKeyTraversalTest() {}
+
+ // FocusManagerTest overrides:
+ virtual void SetUp() OVERRIDE {
+ FocusManagerTest::SetUp();
+
+ previous_arrow_key_traversal_enabled_ =
+ FocusManager::arrow_key_traversal_enabled();
+ }
+ virtual void TearDown() OVERRIDE {
+ FocusManager::set_arrow_key_traversal_enabled(
+ previous_arrow_key_traversal_enabled_);
+ FocusManagerTest::TearDown();
+ }
+
+ private:
+ bool previous_arrow_key_traversal_enabled_;
+
+ DISALLOW_COPY_AND_ASSIGN(FocusManagerArrowKeyTraversalTest);
+};
+
+} // namespace
+
+TEST_F(FocusManagerArrowKeyTraversalTest, ArrowKeyTraversal) {
+ FocusManager* focus_manager = GetFocusManager();
+ const ui::KeyEvent left_key(
+ ui::ET_KEY_PRESSED, ui::VKEY_LEFT, ui::EF_NONE, false);
+ const ui::KeyEvent right_key(
+ ui::ET_KEY_PRESSED, ui::VKEY_RIGHT, ui::EF_NONE, false);
+ const ui::KeyEvent up_key(
+ ui::ET_KEY_PRESSED, ui::VKEY_UP, ui::EF_NONE, false);
+ const ui::KeyEvent down_key(
+ ui::ET_KEY_PRESSED, ui::VKEY_DOWN, ui::EF_NONE, false);
+
+ std::vector<views::View*> v;
+ for (size_t i = 0; i < 2; ++i) {
+ views::View* view = new View;
+ view->set_focusable(true);
+ GetContentsView()->AddChildView(view);
+ v.push_back(view);
+ }
+
+ // Arrow key traversal is off and arrow key does not change focus.
+ FocusManager::set_arrow_key_traversal_enabled(false);
+ v[0]->RequestFocus();
+ focus_manager->OnKeyEvent(right_key);
+ EXPECT_EQ(v[0], focus_manager->GetFocusedView());
+ focus_manager->OnKeyEvent(left_key);
+ EXPECT_EQ(v[0], focus_manager->GetFocusedView());
+ focus_manager->OnKeyEvent(down_key);
+ EXPECT_EQ(v[0], focus_manager->GetFocusedView());
+ focus_manager->OnKeyEvent(up_key);
+ EXPECT_EQ(v[0], focus_manager->GetFocusedView());
+
+ // Turn on arrow key traversal.
+ FocusManager::set_arrow_key_traversal_enabled(true);
+ v[0]->RequestFocus();
+ focus_manager->OnKeyEvent(right_key);
+ EXPECT_EQ(v[1], focus_manager->GetFocusedView());
+ focus_manager->OnKeyEvent(left_key);
+ EXPECT_EQ(v[0], focus_manager->GetFocusedView());
+ focus_manager->OnKeyEvent(down_key);
+ EXPECT_EQ(v[1], focus_manager->GetFocusedView());
+ focus_manager->OnKeyEvent(up_key);
+ EXPECT_EQ(v[0], focus_manager->GetFocusedView());
+}
+
} // namespace views
« ui/views/controls/textfield/native_textfield_views.cc ('K') | « ui/views/focus/focus_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698