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

Side by Side Diff: ui/views/focus/focus_manager_unittest.cc

Issue 2371113003: Do not give instant focus if a view's toplevelwidget is not active (Closed)
Patch Set: new patch 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 unified diff | Download patch
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 "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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 params.delegate = delegate.get(); 871 params.delegate = delegate.get();
872 child_widget.Init(params); 872 child_widget.Init(params);
873 View* view1 = new View; 873 View* view1 = new View;
874 view1->SetFocusBehavior(View::FocusBehavior::ALWAYS); 874 view1->SetFocusBehavior(View::FocusBehavior::ALWAYS);
875 view1->SetBounds(0, 0, 20, 20); 875 view1->SetBounds(0, 0, 20, 20);
876 View* view2 = new View; 876 View* view2 = new View;
877 view2->SetFocusBehavior(View::FocusBehavior::ALWAYS); 877 view2->SetFocusBehavior(View::FocusBehavior::ALWAYS);
878 view2->SetBounds(20, 0, 20, 20); 878 view2->SetBounds(20, 0, 20, 20);
879 child_widget.client_view()->AddChildView(view1); 879 child_widget.client_view()->AddChildView(view1);
880 child_widget.client_view()->AddChildView(view2); 880 child_widget.client_view()->AddChildView(view2);
881 child_widget.Show(); 881 GetWidget()->Show();
882 view2->RequestFocus(); 882 view2->RequestFocus();
883 EXPECT_EQ(view2, GetFocusManager()->GetFocusedView()); 883 EXPECT_EQ(view2, GetFocusManager()->GetFocusedView());
884 884
885 // Advance focus backwards, which should focus the first. 885 // Advance focus backwards, which should focus the first.
886 GetFocusManager()->AdvanceFocus(false); 886 GetFocusManager()->AdvanceFocus(false);
887 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); 887 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView());
888 888
889 // Focus forward to |view2|. 889 // Focus forward to |view2|.
890 GetFocusManager()->AdvanceFocus(true); 890 GetFocusManager()->AdvanceFocus(true);
891 EXPECT_EQ(view2, GetFocusManager()->GetFocusedView()); 891 EXPECT_EQ(view2, GetFocusManager()->GetFocusedView());
892 892
893 // And forward again, wrapping back to |view1|. 893 // And forward again, wrapping back to |view1|.
894 GetFocusManager()->AdvanceFocus(true); 894 GetFocusManager()->AdvanceFocus(true);
895 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); 895 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView());
896 896
897 // Allow focus to go to the parent, and focus backwards which should now move 897 // Allow focus to go to the parent, and focus backwards which should now move
898 // up |widget_view| (in the parent). 898 // up |widget_view| (in the parent).
899 delegate->set_should_advance_focus_to_parent(true); 899 delegate->set_should_advance_focus_to_parent(true);
900 GetFocusManager()->AdvanceFocus(true); 900 GetFocusManager()->AdvanceFocus(true);
901 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); 901 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView());
902 } 902 }
903 903
904 } // namespace views 904 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698