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

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 ps 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
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 SimpleBubbleView : public BubbleDialogDelegateView {
msw 2016/04/19 18:14:55 ditto q, or why not just use TestBubbleDialogDeleg
Evan Stade 2016/04/19 21:51:32 Done.
71 public:
72 SimpleBubbleView(View* anchor)
73 : BubbleDialogDelegateView(anchor, BubbleBorder::NONE) {}
74 ~SimpleBubbleView() override {}
75
76 private:
77 DISALLOW_COPY_AND_ASSIGN(SimpleBubbleView);
78 };
79
70 using WidgetAutoclosePtr = std::unique_ptr<Widget, WidgetCloser>; 80 using WidgetAutoclosePtr = std::unique_ptr<Widget, WidgetCloser>;
71 81
72 } // namespace 82 } // namespace
73 83
74 // A view that keeps track of the events it receives, and consumes all scroll 84 // A view that keeps track of the events it receives, and consumes all scroll
75 // gesture events and ui::ET_SCROLL events. 85 // gesture events and ui::ET_SCROLL events.
76 class ScrollableEventCountView : public EventCountView { 86 class ScrollableEventCountView : public EventCountView {
77 public: 87 public:
78 ScrollableEventCountView() {} 88 ScrollableEventCountView() {}
79 ~ScrollableEventCountView() override {} 89 ~ScrollableEventCountView() override {}
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 EXPECT_EQ(child1, widget_shown()); 838 EXPECT_EQ(child1, widget_shown());
829 839
830 child2->Show(); 840 child2->Show();
831 EXPECT_EQ(child2, widget_shown()); 841 EXPECT_EQ(child2, widget_shown());
832 } 842 }
833 843
834 TEST_F(WidgetObserverTest, DestroyBubble) { 844 TEST_F(WidgetObserverTest, DestroyBubble) {
835 WidgetAutoclosePtr anchor(CreateTopLevelPlatformWidget()); 845 WidgetAutoclosePtr anchor(CreateTopLevelPlatformWidget());
836 anchor->Show(); 846 anchor->Show();
837 847
838 BubbleDelegateView* bubble_delegate = 848 BubbleDialogDelegateView* bubble_delegate =
839 new BubbleDelegateView(anchor->client_view(), BubbleBorder::NONE); 849 new SimpleBubbleView(anchor->client_view());
840 { 850 {
841 WidgetAutoclosePtr bubble_widget( 851 WidgetAutoclosePtr bubble_widget(
842 BubbleDelegateView::CreateBubble(bubble_delegate)); 852 BubbleDialogDelegateView::CreateBubble(bubble_delegate));
843 bubble_widget->Show(); 853 bubble_widget->Show();
844 } 854 }
845 855
846 anchor->Hide(); 856 anchor->Hide();
847 } 857 }
848 858
849 TEST_F(WidgetObserverTest, WidgetBoundsChanged) { 859 TEST_F(WidgetObserverTest, WidgetBoundsChanged) {
850 WidgetAutoclosePtr child1(NewWidget()); 860 WidgetAutoclosePtr child1(NewWidget());
851 WidgetAutoclosePtr child2(NewWidget()); 861 WidgetAutoclosePtr child2(NewWidget());
852 862
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr); 1223 CreatePlatformDesktopNativeWidgetImpl(init_params, &widget, nullptr);
1214 #endif 1224 #endif
1215 widget.Init(init_params); 1225 widget.Init(init_params);
1216 widget.SetContentsView(contents_view); 1226 widget.SetContentsView(contents_view);
1217 widget.Show(); 1227 widget.Show();
1218 widget.Activate(); 1228 widget.Activate();
1219 contents_view->RequestFocus(); 1229 contents_view->RequestFocus();
1220 EXPECT_TRUE(contents_view->HasFocus()); 1230 EXPECT_TRUE(contents_view->HasFocus());
1221 1231
1222 // Show a bubble. 1232 // Show a bubble.
1223 BubbleDelegateView* bubble_delegate_view = 1233 BubbleDialogDelegateView* bubble_delegate_view =
1224 new BubbleDelegateView(contents_view, BubbleBorder::TOP_LEFT); 1234 new SimpleBubbleView(contents_view);
1225 bubble_delegate_view->SetFocusable(true); 1235 bubble_delegate_view->SetFocusable(true);
1226 BubbleDelegateView::CreateBubble(bubble_delegate_view)->Show(); 1236 BubbleDialogDelegateView::CreateBubble(bubble_delegate_view)->Show();
1227 bubble_delegate_view->RequestFocus(); 1237 bubble_delegate_view->RequestFocus();
1228 1238
1229 // |contents_view_| should no longer have focus. 1239 // |contents_view_| should no longer have focus.
1230 EXPECT_FALSE(contents_view->HasFocus()); 1240 EXPECT_FALSE(contents_view->HasFocus());
1231 EXPECT_TRUE(bubble_delegate_view->HasFocus()); 1241 EXPECT_TRUE(bubble_delegate_view->HasFocus());
1232 1242
1233 bubble_delegate_view->GetWidget()->CloseNow(); 1243 bubble_delegate_view->GetWidget()->CloseNow();
1234 1244
1235 // Closing the bubble should result in focus going back to the contents view. 1245 // Closing the bubble should result in focus going back to the contents view.
1236 EXPECT_TRUE(contents_view->HasFocus()); 1246 EXPECT_TRUE(contents_view->HasFocus());
1237 } 1247 }
1238 1248
1239 class TestBubbleDelegateView : public BubbleDelegateView { 1249 class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
1240 public: 1250 public:
1241 TestBubbleDelegateView(View* anchor) 1251 TestBubbleDialogDelegateView(View* anchor)
1242 : BubbleDelegateView(anchor, BubbleBorder::NONE), 1252 : BubbleDialogDelegateView(anchor, BubbleBorder::NONE),
1243 reset_controls_called_(false) {} 1253 reset_controls_called_(false) {}
1244 ~TestBubbleDelegateView() override {} 1254 ~TestBubbleDialogDelegateView() override {}
1245 1255
1246 bool ShouldShowCloseButton() const override { 1256 bool ShouldShowCloseButton() const override {
1247 reset_controls_called_ = true; 1257 reset_controls_called_ = true;
1248 return true; 1258 return true;
1249 } 1259 }
1250 1260
1251 mutable bool reset_controls_called_; 1261 mutable bool reset_controls_called_;
1252 }; 1262 };
1253 1263
1254 TEST_F(WidgetTest, BubbleControlsResetOnInit) { 1264 TEST_F(WidgetTest, BubbleControlsResetOnInit) {
1255 WidgetAutoclosePtr anchor(CreateTopLevelPlatformWidget()); 1265 WidgetAutoclosePtr anchor(CreateTopLevelPlatformWidget());
1256 anchor->Show(); 1266 anchor->Show();
1257 1267
1258 { 1268 {
1259 TestBubbleDelegateView* bubble_delegate = 1269 TestBubbleDialogDelegateView* bubble_delegate =
1260 new TestBubbleDelegateView(anchor->client_view()); 1270 new TestBubbleDialogDelegateView(anchor->client_view());
1261 WidgetAutoclosePtr bubble_widget( 1271 WidgetAutoclosePtr bubble_widget(
1262 BubbleDelegateView::CreateBubble(bubble_delegate)); 1272 BubbleDialogDelegateView::CreateBubble(bubble_delegate));
1263 EXPECT_TRUE(bubble_delegate->reset_controls_called_); 1273 EXPECT_TRUE(bubble_delegate->reset_controls_called_);
1264 bubble_widget->Show(); 1274 bubble_widget->Show();
1265 } 1275 }
1266 1276
1267 anchor->Hide(); 1277 anchor->Hide();
1268 } 1278 }
1269 1279
1270 #if defined(OS_WIN) 1280 #if defined(OS_WIN)
1271 // Test to ensure that after minimize, view width is set to zero. This is only 1281 // 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 1282 // 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. 3525 // Moving the child to a different widget should call the removals observer.
3516 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); 3526 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget());
3517 widget2->client_view()->AddChildView(child); 3527 widget2->client_view()->AddChildView(child);
3518 EXPECT_TRUE(removals_observer.DidRemoveView(child)); 3528 EXPECT_TRUE(removals_observer.DidRemoveView(child));
3519 3529
3520 widget->RemoveRemovalsObserver(&removals_observer); 3530 widget->RemoveRemovalsObserver(&removals_observer);
3521 } 3531 }
3522 3532
3523 } // namespace test 3533 } // namespace test
3524 } // namespace views 3534 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698