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

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

Issue 2821413002: views: support dialog width snapping once and for all (Closed)
Patch Set: DialogDelegateView -> BubbleDialogDelegateView 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
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..59d5d4ce671a7bc374e843bf8a9f6e0e757b18c9 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,75 @@ 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 {}
+
+ // 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;
+
+ delegate.set_margins(gfx::Insets());
+
+ constexpr int kTestWidth = 300;
+
+ Widget* w0 = BubbleDialogDelegateView::CreateBubble(&delegate);
+ w0->Show();
+ EXPECT_EQ(delegate.GetPreferredSize().width(),
+ w0->GetWindowBoundsInScreen().width());
+ w0->CloseNow();
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698