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

Side by Side 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, 7 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 | Annotate | Revision Log
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 <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "ui/base/accelerators/accelerator.h" 9 #include "ui/base/accelerators/accelerator.h"
10 #include "ui/base/keycodes/keyboard_codes.h" 10 #include "ui/base/keycodes/keyboard_codes.h"
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 v1->RequestFocus(); 733 v1->RequestFocus();
734 EXPECT_TRUE(v1->HasFocus()); 734 EXPECT_TRUE(v1->HasFocus());
735 EXPECT_EQ(v1, GetWidget()->GetFocusManager()->GetStoredFocusView()); 735 EXPECT_EQ(v1, GetWidget()->GetFocusManager()->GetStoredFocusView());
736 736
737 // Verify a focus request on |v2| implicitly updates the stored focus view. 737 // Verify a focus request on |v2| implicitly updates the stored focus view.
738 v2->RequestFocus(); 738 v2->RequestFocus();
739 EXPECT_TRUE(v2->HasFocus()); 739 EXPECT_TRUE(v2->HasFocus());
740 EXPECT_EQ(v2, GetWidget()->GetFocusManager()->GetStoredFocusView()); 740 EXPECT_EQ(v2, GetWidget()->GetFocusManager()->GetStoredFocusView());
741 } 741 }
742 742
743 namespace {
744
745 class FocusManagerArrowKeyTraversalTest : public FocusManagerTest {
746 public:
747 FocusManagerArrowKeyTraversalTest()
748 : previous_arrow_key_traversal_enabled_(false) {
749 }
750 virtual ~FocusManagerArrowKeyTraversalTest() {}
751
752 // FocusManagerTest overrides:
753 virtual void SetUp() OVERRIDE {
754 FocusManagerTest::SetUp();
755
756 previous_arrow_key_traversal_enabled_ =
757 FocusManager::arrow_key_traversal_enabled();
758 }
759 virtual void TearDown() OVERRIDE {
760 FocusManager::set_arrow_key_traversal_enabled(
761 previous_arrow_key_traversal_enabled_);
762 FocusManagerTest::TearDown();
763 }
764
765 private:
766 bool previous_arrow_key_traversal_enabled_;
767
768 DISALLOW_COPY_AND_ASSIGN(FocusManagerArrowKeyTraversalTest);
769 };
770
771 } // namespace
772
773 TEST_F(FocusManagerArrowKeyTraversalTest, ArrowKeyTraversal) {
774 FocusManager* focus_manager = GetFocusManager();
775 const ui::KeyEvent left_key(
776 ui::ET_KEY_PRESSED, ui::VKEY_LEFT, ui::EF_NONE, false);
777 const ui::KeyEvent right_key(
778 ui::ET_KEY_PRESSED, ui::VKEY_RIGHT, ui::EF_NONE, false);
779 const ui::KeyEvent up_key(
780 ui::ET_KEY_PRESSED, ui::VKEY_UP, ui::EF_NONE, false);
781 const ui::KeyEvent down_key(
782 ui::ET_KEY_PRESSED, ui::VKEY_DOWN, ui::EF_NONE, false);
783
784 std::vector<views::View*> v;
785 for (size_t i = 0; i < 2; ++i) {
786 views::View* view = new View;
787 view->set_focusable(true);
788 GetContentsView()->AddChildView(view);
789 v.push_back(view);
790 }
791
792 // Arrow key traversal is off and arrow key does not change focus.
793 FocusManager::set_arrow_key_traversal_enabled(false);
794 v[0]->RequestFocus();
795 focus_manager->OnKeyEvent(right_key);
796 EXPECT_EQ(v[0], focus_manager->GetFocusedView());
797 focus_manager->OnKeyEvent(left_key);
798 EXPECT_EQ(v[0], focus_manager->GetFocusedView());
799 focus_manager->OnKeyEvent(down_key);
800 EXPECT_EQ(v[0], focus_manager->GetFocusedView());
801 focus_manager->OnKeyEvent(up_key);
802 EXPECT_EQ(v[0], focus_manager->GetFocusedView());
803
804 // Turn on arrow key traversal.
805 FocusManager::set_arrow_key_traversal_enabled(true);
806 v[0]->RequestFocus();
807 focus_manager->OnKeyEvent(right_key);
808 EXPECT_EQ(v[1], focus_manager->GetFocusedView());
809 focus_manager->OnKeyEvent(left_key);
810 EXPECT_EQ(v[0], focus_manager->GetFocusedView());
811 focus_manager->OnKeyEvent(down_key);
812 EXPECT_EQ(v[1], focus_manager->GetFocusedView());
813 focus_manager->OnKeyEvent(up_key);
814 EXPECT_EQ(v[0], focus_manager->GetFocusedView());
815 }
816
743 } // namespace views 817 } // namespace views
OLDNEW
« 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