OLD | NEW |
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/focus/focus_manager.h" | 5 #include "ui/views/focus/focus_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); | 777 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); |
778 focus_manager->OnKeyEvent(left_key); | 778 focus_manager->OnKeyEvent(left_key); |
779 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); | 779 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); |
780 focus_manager->OnKeyEvent(down_key); | 780 focus_manager->OnKeyEvent(down_key); |
781 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); | 781 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); |
782 focus_manager->OnKeyEvent(up_key); | 782 focus_manager->OnKeyEvent(up_key); |
783 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); | 783 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); |
784 } | 784 } |
785 | 785 |
786 TEST_F(FocusManagerTest, StoreFocusedView) { | 786 TEST_F(FocusManagerTest, StoreFocusedView) { |
787 View view; | 787 View* view = new View; |
788 GetFocusManager()->SetFocusedView(&view); | 788 // Add view to the view hierarchy and make it focusable. |
| 789 GetWidget()->GetRootView()->AddChildView(view); |
| 790 view->SetFocusable(true); |
| 791 |
| 792 GetFocusManager()->SetFocusedView(view); |
789 GetFocusManager()->StoreFocusedView(false); | 793 GetFocusManager()->StoreFocusedView(false); |
790 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); | 794 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); |
791 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | 795 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
792 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 796 EXPECT_EQ(view, GetFocusManager()->GetStoredFocusView()); |
793 | 797 |
794 // Repeat with |true|. | 798 // Repeat with |true|. |
795 GetFocusManager()->SetFocusedView(&view); | 799 GetFocusManager()->SetFocusedView(view); |
796 GetFocusManager()->StoreFocusedView(true); | 800 GetFocusManager()->StoreFocusedView(true); |
797 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); | 801 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); |
798 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | 802 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
799 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 803 EXPECT_EQ(view, GetFocusManager()->GetStoredFocusView()); |
800 } | 804 } |
801 | 805 |
802 namespace { | 806 namespace { |
803 | 807 |
804 // Trivial WidgetDelegate implementation that allows setting return value of | 808 // Trivial WidgetDelegate implementation that allows setting return value of |
805 // ShouldAdvanceFocusToTopLevelWidget(). | 809 // ShouldAdvanceFocusToTopLevelWidget(). |
806 class AdvanceFocusWidgetDelegate : public WidgetDelegate { | 810 class AdvanceFocusWidgetDelegate : public WidgetDelegate { |
807 public: | 811 public: |
808 explicit AdvanceFocusWidgetDelegate(Widget* widget) | 812 explicit AdvanceFocusWidgetDelegate(Widget* widget) |
809 : widget_(widget), | 813 : widget_(widget), |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 878 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
875 | 879 |
876 // Allow focus to go to the parent, and focus backwards which should now move | 880 // Allow focus to go to the parent, and focus backwards which should now move |
877 // up |widget_view| (in the parent). | 881 // up |widget_view| (in the parent). |
878 delegate->set_should_advance_focus_to_parent(true); | 882 delegate->set_should_advance_focus_to_parent(true); |
879 GetFocusManager()->AdvanceFocus(true); | 883 GetFocusManager()->AdvanceFocus(true); |
880 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 884 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
881 } | 885 } |
882 | 886 |
883 } // namespace views | 887 } // namespace views |
OLD | NEW |