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 bf955dd451c640273688efb5f36fae2e0198a691..d9a513cea006ce2c2af83d6d955b850140c612ef 100644 |
--- a/ui/views/bubble/bubble_frame_view_unittest.cc |
+++ b/ui/views/bubble/bubble_frame_view_unittest.cc |
@@ -8,19 +8,51 @@ |
#include "base/macros.h" |
#include "build/build_config.h" |
+#include "ui/base/test/material_design_controller_test_api.h" |
#include "ui/gfx/geometry/insets.h" |
#include "ui/gfx/geometry/rect.h" |
#include "ui/gfx/geometry/size.h" |
#include "ui/views/bubble/bubble_border.h" |
#include "ui/views/controls/button/label_button.h" |
#include "ui/views/test/test_views.h" |
+#include "ui/views/test/test_views_delegate.h" |
#include "ui/views/test/views_test_base.h" |
#include "ui/views/widget/widget.h" |
#include "ui/views/widget/widget_delegate.h" |
namespace views { |
-typedef ViewsTestBase BubbleFrameViewTest; |
+class BubbleFrameViewTest; |
tapted
2017/03/29 23:16:16
nit: forward dec not used?
Elly Fong-Jones
2017/04/05 18:17:53
Done.
|
+ |
+class BubbleFrameViewTestViewsDelegate : public TestViewsDelegate { |
+ public: |
+ BubbleFrameViewTestViewsDelegate() {} |
+ ~BubbleFrameViewTestViewsDelegate() override {} |
+ |
+ int GetSnappedDialogWidth(int width) const override { |
tapted
2017/03/29 23:16:16
nit: // TestViewsDelegate:
Elly Fong-Jones
2017/04/05 18:17:53
Done.
|
+ return ((width + width_snapping_unit_ - 1) / width_snapping_unit_) * |
+ width_snapping_unit_; |
+ } |
+ |
+ void set_width_snapping_unit(int unit) { width_snapping_unit_ = unit; } |
+ |
+ private: |
+ int width_snapping_unit_ = 1; |
+}; |
tapted
2017/03/29 23:16:16
nit: DISALLOW_COPY...
Elly Fong-Jones
2017/04/05 18:17:53
Done.
|
+ |
+class BubbleFrameViewTest : public ViewsTestBase { |
+ public: |
+ BubbleFrameViewTest() { |
+ views_delegate_ = new BubbleFrameViewTestViewsDelegate; |
+ set_views_delegate(std::unique_ptr<TestViewsDelegate>(views_delegate_)); |
tapted
2017/03/29 23:16:16
base::WrapUnique?
Elly Fong-Jones
2017/04/05 18:17:53
Done.
|
+ } |
+ ~BubbleFrameViewTest() override {} |
+ |
+ BubbleFrameViewTestViewsDelegate* views_delegate() { return views_delegate_; } |
+ |
+ private: |
+ BubbleFrameViewTestViewsDelegate* views_delegate_; |
+}; |
tapted
2017/03/29 23:16:16
nit: DISALLOW_COPY...
Elly Fong-Jones
2017/04/05 18:17:53
Done.
|
namespace { |
@@ -488,4 +520,22 @@ TEST_F(BubbleFrameViewTest, GetMaximumSize) { |
#endif |
} |
+TEST_F(BubbleFrameViewTest, WidthSnapsToUnit) { |
tapted
2017/03/29 23:16:16
nit: comment before
Elly Fong-Jones
2017/04/05 18:17:53
Done.
|
+ TestBubbleFrameView frame(this); |
tapted
2017/03/29 23:16:16
Can we use BubbleDialogDelegateView::CreateBubble(
Elly Fong-Jones
2017/04/05 18:17:53
Which setup code do you mean? There is some in (eg
tapted
2017/04/06 00:24:44
BubbleDialogDelegateView doesn't need a Widget to
|
+ |
+ // The "border width" here is primarily for the bubble shadow, but also for |
+ // the edge stroke of the bubble. This width is *not* included in the width |
+ // snapping, so it needs to be subtracted out. |
+ int border_width = frame.GetPreferredSize().width() - kPreferredClientWidth - |
+ kExpectedAdditionalWidth; |
+ |
+ // Check that changing the snapping unit changes the computed width to be a |
+ // multiple of the snapping unit. |
Peter Kasting
2017/03/29 03:51:16
This feels like you're mostly testing the function
Elly Fong-Jones
2017/04/05 18:17:53
I reworked this test a little bit to be simpler, b
|
+ views_delegate()->set_width_snapping_unit(19); |
+ EXPECT_EQ((frame.GetPreferredSize().width() - border_width) % 19, 0); |
+ |
+ views_delegate()->set_width_snapping_unit(17); |
+ EXPECT_EQ((frame.GetPreferredSize().width() - border_width) % 17, 0); |
+} |
+ |
} // namespace views |