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

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try to advance focus first Created 7 years 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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 944
945 toplevel->Close(); 945 toplevel->Close();
946 } 946 }
947 947
948 // Verifies bubbles result in a focus lost when shown. 948 // Verifies bubbles result in a focus lost when shown.
949 // TODO(msw): this tests relies on focus, it needs to be in 949 // TODO(msw): this tests relies on focus, it needs to be in
950 // interactive_ui_tests. 950 // interactive_ui_tests.
951 TEST_F(WidgetTest, DISABLED_FocusChangesOnBubble) { 951 TEST_F(WidgetTest, DISABLED_FocusChangesOnBubble) {
952 // Create a widget, show and activate it and focus the contents view. 952 // Create a widget, show and activate it and focus the contents view.
953 View* contents_view = new View; 953 View* contents_view = new View;
954 contents_view->set_focusable(true); 954 contents_view->SetFocusable(true);
955 Widget widget; 955 Widget widget;
956 Widget::InitParams init_params = 956 Widget::InitParams init_params =
957 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 957 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
958 init_params.bounds = gfx::Rect(0, 0, 200, 200); 958 init_params.bounds = gfx::Rect(0, 0, 200, 200);
959 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 959 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
960 #if !defined(OS_CHROMEOS) 960 #if !defined(OS_CHROMEOS)
961 init_params.native_widget = new DesktopNativeWidgetAura(&widget); 961 init_params.native_widget = new DesktopNativeWidgetAura(&widget);
962 #endif 962 #endif
963 widget.Init(init_params); 963 widget.Init(init_params);
964 widget.SetContentsView(contents_view); 964 widget.SetContentsView(contents_view);
965 widget.Show(); 965 widget.Show();
966 widget.Activate(); 966 widget.Activate();
967 contents_view->RequestFocus(); 967 contents_view->RequestFocus();
968 EXPECT_TRUE(contents_view->HasFocus()); 968 EXPECT_TRUE(contents_view->HasFocus());
969 969
970 // Show a bubble. 970 // Show a bubble.
971 BubbleDelegateView* bubble_delegate_view = 971 BubbleDelegateView* bubble_delegate_view =
972 new BubbleDelegateView(contents_view, BubbleBorder::TOP_LEFT); 972 new BubbleDelegateView(contents_view, BubbleBorder::TOP_LEFT);
973 bubble_delegate_view->set_focusable(true); 973 bubble_delegate_view->SetFocusable(true);
974 BubbleDelegateView::CreateBubble(bubble_delegate_view)->Show(); 974 BubbleDelegateView::CreateBubble(bubble_delegate_view)->Show();
975 bubble_delegate_view->RequestFocus(); 975 bubble_delegate_view->RequestFocus();
976 976
977 // |contents_view_| should no longer have focus. 977 // |contents_view_| should no longer have focus.
978 EXPECT_FALSE(contents_view->HasFocus()); 978 EXPECT_FALSE(contents_view->HasFocus());
979 EXPECT_TRUE(bubble_delegate_view->HasFocus()); 979 EXPECT_TRUE(bubble_delegate_view->HasFocus());
980 980
981 bubble_delegate_view->GetWidget()->CloseNow(); 981 bubble_delegate_view->GetWidget()->CloseNow();
982 982
983 // Closing the bubble should result in focus going back to the contents view. 983 // Closing the bubble should result in focus going back to the contents view.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 return received_paint_while_hidden_; 1045 return received_paint_while_hidden_;
1046 } 1046 }
1047 1047
1048 private: 1048 private:
1049 bool expect_paint_; 1049 bool expect_paint_;
1050 bool received_paint_while_hidden_; 1050 bool received_paint_while_hidden_;
1051 }; 1051 };
1052 1052
1053 TEST_F(WidgetTest, DesktopNativeWidgetAuraNoPaintAfterCloseTest) { 1053 TEST_F(WidgetTest, DesktopNativeWidgetAuraNoPaintAfterCloseTest) {
1054 View* contents_view = new View; 1054 View* contents_view = new View;
1055 contents_view->set_focusable(true); 1055 contents_view->SetFocusable(true);
1056 DesktopAuraTestValidPaintWidget widget; 1056 DesktopAuraTestValidPaintWidget widget;
1057 Widget::InitParams init_params = 1057 Widget::InitParams init_params =
1058 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 1058 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1059 init_params.bounds = gfx::Rect(0, 0, 200, 200); 1059 init_params.bounds = gfx::Rect(0, 0, 200, 200);
1060 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 1060 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1061 init_params.native_widget = new DesktopNativeWidgetAura(&widget); 1061 init_params.native_widget = new DesktopNativeWidgetAura(&widget);
1062 widget.Init(init_params); 1062 widget.Init(init_params);
1063 widget.SetContentsView(contents_view); 1063 widget.SetContentsView(contents_view);
1064 widget.Show(); 1064 widget.Show();
1065 widget.Activate(); 1065 widget.Activate();
1066 RunPendingMessages(); 1066 RunPendingMessages();
1067 widget.SchedulePaintInRect(init_params.bounds); 1067 widget.SchedulePaintInRect(init_params.bounds);
1068 widget.Close(); 1068 widget.Close();
1069 RunPendingMessages(); 1069 RunPendingMessages();
1070 EXPECT_FALSE(widget.received_paint_while_hidden()); 1070 EXPECT_FALSE(widget.received_paint_while_hidden());
1071 } 1071 }
1072 1072
1073 TEST_F(WidgetTest, DesktopNativeWidgetAuraNoPaintAfterHideTest) { 1073 TEST_F(WidgetTest, DesktopNativeWidgetAuraNoPaintAfterHideTest) {
1074 View* contents_view = new View; 1074 View* contents_view = new View;
1075 contents_view->set_focusable(true); 1075 contents_view->SetFocusable(true);
1076 DesktopAuraTestValidPaintWidget widget; 1076 DesktopAuraTestValidPaintWidget widget;
1077 Widget::InitParams init_params = 1077 Widget::InitParams init_params =
1078 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 1078 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1079 init_params.bounds = gfx::Rect(0, 0, 200, 200); 1079 init_params.bounds = gfx::Rect(0, 0, 200, 200);
1080 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 1080 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
1081 init_params.native_widget = new DesktopNativeWidgetAura(&widget); 1081 init_params.native_widget = new DesktopNativeWidgetAura(&widget);
1082 widget.Init(init_params); 1082 widget.Init(init_params);
1083 widget.SetContentsView(contents_view); 1083 widget.SetContentsView(contents_view);
1084 widget.Show(); 1084 widget.Show();
1085 widget.Activate(); 1085 widget.Activate();
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 EXPECT_EQ(activate_result, MA_ACTIVATE); 2201 EXPECT_EQ(activate_result, MA_ACTIVATE);
2202 2202
2203 modal_dialog_widget->CloseNow(); 2203 modal_dialog_widget->CloseNow();
2204 top_level_widget.CloseNow(); 2204 top_level_widget.CloseNow();
2205 } 2205 }
2206 #endif 2206 #endif
2207 #endif 2207 #endif
2208 2208
2209 } // namespace test 2209 } // namespace test
2210 } // namespace views 2210 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698