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

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

Issue 1895203004: Update sundry BubbleDelegateView references to BubbleDialogDelegateView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: relative again Created 4 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 unified diff | Download patch
« no previous file with comments | « ui/views/widget/native_widget_mac_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 6 #include <memory>
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/base/hit_test.h" 16 #include "ui/base/hit_test.h"
17 #include "ui/compositor/layer_animation_observer.h" 17 #include "ui/compositor/layer_animation_observer.h"
18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
20 #include "ui/events/event_utils.h" 20 #include "ui/events/event_utils.h"
21 #include "ui/events/test/event_generator.h" 21 #include "ui/events/test/event_generator.h"
22 #include "ui/gfx/geometry/point.h" 22 #include "ui/gfx/geometry/point.h"
23 #include "ui/gfx/native_widget_types.h" 23 #include "ui/gfx/native_widget_types.h"
24 #include "ui/views/bubble/bubble_delegate.h" 24 #include "ui/views/bubble/bubble_dialog_delegate.h"
25 #include "ui/views/controls/textfield/textfield.h" 25 #include "ui/views/controls/textfield/textfield.h"
26 #include "ui/views/test/native_widget_factory.h" 26 #include "ui/views/test/native_widget_factory.h"
27 #include "ui/views/test/test_views.h" 27 #include "ui/views/test/test_views.h"
28 #include "ui/views/test/test_widget_observer.h" 28 #include "ui/views/test/test_widget_observer.h"
29 #include "ui/views/test/widget_test.h" 29 #include "ui/views/test/widget_test.h"
30 #include "ui/views/widget/native_widget_delegate.h" 30 #include "ui/views/widget/native_widget_delegate.h"
31 #include "ui/views/widget/native_widget_private.h" 31 #include "ui/views/widget/native_widget_private.h"
32 #include "ui/views/widget/root_view.h" 32 #include "ui/views/widget/root_view.h"
33 #include "ui/views/widget/widget_deletion_observer.h" 33 #include "ui/views/widget/widget_deletion_observer.h"
34 #include "ui/views/widget/widget_removals_observer.h" 34 #include "ui/views/widget/widget_removals_observer.h"
(...skipping 25 matching lines...) Expand all
60 View::ConvertPointToTarget(view->GetWidget()->GetRootView(), view, &tmp); 60 View::ConvertPointToTarget(view->GetWidget()->GetRootView(), view, &tmp);
61 return tmp; 61 return tmp;
62 } 62 }
63 63
64 // This class can be used as a deleter for std::unique_ptr<Widget> 64 // This class can be used as a deleter for std::unique_ptr<Widget>
65 // to call function Widget::CloseNow automatically. 65 // to call function Widget::CloseNow automatically.
66 struct WidgetCloser { 66 struct WidgetCloser {
67 inline void operator()(Widget* widget) const { widget->CloseNow(); } 67 inline void operator()(Widget* widget) const { widget->CloseNow(); }
68 }; 68 };
69 69
70 class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
71 public:
72 TestBubbleDialogDelegateView(View* anchor)
73 : BubbleDialogDelegateView(anchor, BubbleBorder::NONE),
74 reset_controls_called_(false) {}
75 ~TestBubbleDialogDelegateView() override {}
76
77 bool ShouldShowCloseButton() const override {
78 reset_controls_called_ = true;
79 return true;
80 }
81
82 mutable bool reset_controls_called_;
83 };
84
70 using WidgetAutoclosePtr = std::unique_ptr<Widget, WidgetCloser>; 85 using WidgetAutoclosePtr = std::unique_ptr<Widget, WidgetCloser>;
71 86
72 } // namespace 87 } // namespace
73 88
74 // A view that keeps track of the events it receives, and consumes all scroll 89 // A view that keeps track of the events it receives, and consumes all scroll
75 // gesture events and ui::ET_SCROLL events. 90 // gesture events and ui::ET_SCROLL events.
76 class ScrollableEventCountView : public EventCountView { 91 class ScrollableEventCountView : public EventCountView {
77 public: 92 public:
78 ScrollableEventCountView() {} 93 ScrollableEventCountView() {}
79 ~ScrollableEventCountView() override {} 94 ~ScrollableEventCountView() override {}
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 EXPECT_EQ(child1, widget_shown()); 843 EXPECT_EQ(child1, widget_shown());
829 844
830 child2->Show(); 845 child2->Show();
831 EXPECT_EQ(child2, widget_shown()); 846 EXPECT_EQ(child2, widget_shown());
832 } 847 }
833 848
834 TEST_F(WidgetObserverTest, DestroyBubble) { 849 TEST_F(WidgetObserverTest, DestroyBubble) {
835 WidgetAutoclosePtr anchor(CreateTopLevelPlatformWidget()); 850 WidgetAutoclosePtr anchor(CreateTopLevelPlatformWidget());
836 anchor->Show(); 851 anchor->Show();
837 852
838 BubbleDelegateView* bubble_delegate = 853 BubbleDialogDelegateView* bubble_delegate =
839 new BubbleDelegateView(anchor->client_view(), BubbleBorder::NONE); 854 new TestBubbleDialogDelegateView(anchor->client_view());
840 { 855 {
841 WidgetAutoclosePtr bubble_widget( 856 WidgetAutoclosePtr bubble_widget(
842 BubbleDelegateView::CreateBubble(bubble_delegate)); 857 BubbleDialogDelegateView::CreateBubble(bubble_delegate));
843 bubble_widget->Show(); 858 bubble_widget->Show();
844 } 859 }
845 860
846 anchor->Hide(); 861 anchor->Hide();
847 } 862 }
848 863
849 TEST_F(WidgetObserverTest, WidgetBoundsChanged) { 864 TEST_F(WidgetObserverTest, WidgetBoundsChanged) {
850 WidgetAutoclosePtr child1(NewWidget()); 865 WidgetAutoclosePtr child1(NewWidget());
851 WidgetAutoclosePtr child2(NewWidget()); 866 WidgetAutoclosePtr child2(NewWidget());
852 867
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr); 1228 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr);
1214 #endif 1229 #endif
1215 widget.Init(init_params); 1230 widget.Init(init_params);
1216 widget.SetContentsView(contents_view); 1231 widget.SetContentsView(contents_view);
1217 widget.Show(); 1232 widget.Show();
1218 widget.Activate(); 1233 widget.Activate();
1219 contents_view->RequestFocus(); 1234 contents_view->RequestFocus();
1220 EXPECT_TRUE(contents_view->HasFocus()); 1235 EXPECT_TRUE(contents_view->HasFocus());
1221 1236
1222 // Show a bubble. 1237 // Show a bubble.
1223 BubbleDelegateView* bubble_delegate_view = 1238 BubbleDialogDelegateView* bubble_delegate_view =
1224 new BubbleDelegateView(contents_view, BubbleBorder::TOP_LEFT); 1239 new TestBubbleDialogDelegateView(contents_view);
1225 bubble_delegate_view->SetFocusable(true); 1240 bubble_delegate_view->SetFocusable(true);
1226 BubbleDelegateView::CreateBubble(bubble_delegate_view)->Show(); 1241 BubbleDialogDelegateView::CreateBubble(bubble_delegate_view)->Show();
1227 bubble_delegate_view->RequestFocus(); 1242 bubble_delegate_view->RequestFocus();
1228 1243
1229 // |contents_view_| should no longer have focus. 1244 // |contents_view_| should no longer have focus.
1230 EXPECT_FALSE(contents_view->HasFocus()); 1245 EXPECT_FALSE(contents_view->HasFocus());
1231 EXPECT_TRUE(bubble_delegate_view->HasFocus()); 1246 EXPECT_TRUE(bubble_delegate_view->HasFocus());
1232 1247
1233 bubble_delegate_view->GetWidget()->CloseNow(); 1248 bubble_delegate_view->GetWidget()->CloseNow();
1234 1249
1235 // Closing the bubble should result in focus going back to the contents view. 1250 // Closing the bubble should result in focus going back to the contents view.
1236 EXPECT_TRUE(contents_view->HasFocus()); 1251 EXPECT_TRUE(contents_view->HasFocus());
1237 } 1252 }
1238 1253
1239 class TestBubbleDelegateView : public BubbleDelegateView {
1240 public:
1241 TestBubbleDelegateView(View* anchor)
1242 : BubbleDelegateView(anchor, BubbleBorder::NONE),
1243 reset_controls_called_(false) {}
1244 ~TestBubbleDelegateView() override {}
1245
1246 bool ShouldShowCloseButton() const override {
1247 reset_controls_called_ = true;
1248 return true;
1249 }
1250
1251 mutable bool reset_controls_called_;
1252 };
1253
1254 TEST_F(WidgetTest, BubbleControlsResetOnInit) { 1254 TEST_F(WidgetTest, BubbleControlsResetOnInit) {
1255 WidgetAutoclosePtr anchor(CreateTopLevelPlatformWidget()); 1255 WidgetAutoclosePtr anchor(CreateTopLevelPlatformWidget());
1256 anchor->Show(); 1256 anchor->Show();
1257 1257
1258 { 1258 {
1259 TestBubbleDelegateView* bubble_delegate = 1259 TestBubbleDialogDelegateView* bubble_delegate =
1260 new TestBubbleDelegateView(anchor->client_view()); 1260 new TestBubbleDialogDelegateView(anchor->client_view());
1261 WidgetAutoclosePtr bubble_widget( 1261 WidgetAutoclosePtr bubble_widget(
1262 BubbleDelegateView::CreateBubble(bubble_delegate)); 1262 BubbleDialogDelegateView::CreateBubble(bubble_delegate));
1263 EXPECT_TRUE(bubble_delegate->reset_controls_called_); 1263 EXPECT_TRUE(bubble_delegate->reset_controls_called_);
1264 bubble_widget->Show(); 1264 bubble_widget->Show();
1265 } 1265 }
1266 1266
1267 anchor->Hide(); 1267 anchor->Hide();
1268 } 1268 }
1269 1269
1270 #if defined(OS_WIN) 1270 #if defined(OS_WIN)
1271 // Test to ensure that after minimize, view width is set to zero. This is only 1271 // Test to ensure that after minimize, view width is set to zero. This is only
1272 // the case for desktop widgets on Windows. Other platforms retain the window 1272 // the case for desktop widgets on Windows. Other platforms retain the window
(...skipping 2242 matching lines...) Expand 10 before | Expand all | Expand 10 after
3515 // Moving the child to a different widget should call the removals observer. 3515 // Moving the child to a different widget should call the removals observer.
3516 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); 3516 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget());
3517 widget2->client_view()->AddChildView(child); 3517 widget2->client_view()->AddChildView(child);
3518 EXPECT_TRUE(removals_observer.DidRemoveView(child)); 3518 EXPECT_TRUE(removals_observer.DidRemoveView(child));
3519 3519
3520 widget->RemoveRemovalsObserver(&removals_observer); 3520 widget->RemoveRemovalsObserver(&removals_observer);
3521 } 3521 }
3522 3522
3523 } // namespace test 3523 } // namespace test
3524 } // namespace views 3524 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_mac_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698