Chromium Code Reviews| 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..c7187a6995c35d923947152817d35c227adecdce 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 {} |
| + |
| + // DialogDelegateView: |
|
tapted
2017/04/21 00:20:31
// BubbleDialogDelegateView:
peter has a preferen
Elly Fong-Jones
2017/04/21 15:47:54
Okay, changed to 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 |