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

Unified Diff: ui/views/bubble/bubble_frame_view_unittest.cc

Issue 2821413002: views: support dialog width snapping once and for all (Closed)
Patch Set: fix failing unittest Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/layout/layout_provider.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/bubble/bubble_frame_view_unittest.cc
diff --git a/ui/views/bubble/bubble_frame_view_unittest.cc b/ui/views/bubble/bubble_frame_view_unittest.cc
index 3474899d99a83b9c15b20173e5287c20bade7266..705e17744288dfde2b1d9c7989577266a0c4e3ee 100644
--- a/ui/views/bubble/bubble_frame_view_unittest.cc
+++ b/ui/views/bubble/bubble_frame_view_unittest.cc
@@ -12,6 +12,7 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/bubble/bubble_border.h"
+#include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/test/test_views.h"
#include "ui/views/test/views_test_base.h"
@@ -488,4 +489,83 @@ TEST_F(BubbleFrameViewTest, GetMaximumSize) {
#endif
}
+namespace {
+
+class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
+ public:
+ TestBubbleDialogDelegateView()
+ : BubbleDialogDelegateView(nullptr, BubbleBorder::NONE) {
+ set_shadow(BubbleBorder::NO_ASSETS);
+ SetAnchorRect(gfx::Rect());
+ }
+ ~TestBubbleDialogDelegateView() override {}
+
+ using BubbleDialogDelegateView::SetAnchorView;
+
+ // BubbleDialogDelegateView:
+ void DeleteDelegate() override {
+ // This delegate is owned by the test case itself, so it should not delete
+ // itself here.
+ }
+
+ int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; }
+
+ gfx::Size GetPreferredSize() const override { return gfx::Size(200, 200); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestBubbleDialogDelegateView);
+};
+
+class TestLayoutProvider : public LayoutProvider {
+ public:
+ TestLayoutProvider() : LayoutProvider() {}
+ ~TestLayoutProvider() override {}
+
+ // LayoutProvider:
+ int GetSnappedDialogWidth(int min_width) const override {
+ return snap_to_ ? snap_to_ : min_width;
+ }
+
+ void set_snap_to(int width) { snap_to_ = width; }
+
+ private:
+ int snap_to_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(TestLayoutProvider);
+};
+
+} // namespace
+
+// This test ensures that if the installed LayoutProvider snaps dialog widths,
+// BubbleFrameView correctly sizes itself to that width.
+TEST_F(BubbleFrameViewTest, WidthSnaps) {
+ TestLayoutProvider provider;
+ TestBubbleDialogDelegateView delegate;
+
+ Widget anchor;
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ anchor.Init(params);
+ anchor.Show();
+
+ delegate.SetAnchorView(anchor.GetContentsView());
+ delegate.set_margins(gfx::Insets());
+
+ Widget* w0 = BubbleDialogDelegateView::CreateBubble(&delegate);
+ w0->Show();
+ EXPECT_EQ(delegate.GetPreferredSize().width(),
+ w0->GetWindowBoundsInScreen().width());
+ w0->CloseNow();
+
+ constexpr int kTestWidth = 300;
+ provider.set_snap_to(kTestWidth);
+
+ // The Widget's snapped width should exactly match the width returned by the
+ // LayoutProvider.
+ Widget* w1 = BubbleDialogDelegateView::CreateBubble(&delegate);
+ w1->Show();
+ EXPECT_EQ(kTestWidth, w1->GetWindowBoundsInScreen().width());
+ w1->CloseNow();
+}
+
} // namespace views
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/layout/layout_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698