OLD | NEW |
---|---|
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 "ui/views/bubble/bubble_frame_view.h" | 5 #include "ui/views/bubble/bubble_frame_view.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "ui/base/test/material_design_controller_test_api.h" | |
11 #include "ui/gfx/geometry/insets.h" | 12 #include "ui/gfx/geometry/insets.h" |
12 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
13 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
14 #include "ui/views/bubble/bubble_border.h" | 15 #include "ui/views/bubble/bubble_border.h" |
15 #include "ui/views/controls/button/label_button.h" | 16 #include "ui/views/controls/button/label_button.h" |
16 #include "ui/views/test/test_views.h" | 17 #include "ui/views/test/test_views.h" |
18 #include "ui/views/test/test_views_delegate.h" | |
17 #include "ui/views/test/views_test_base.h" | 19 #include "ui/views/test/views_test_base.h" |
18 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
19 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
20 | 22 |
21 namespace views { | 23 namespace views { |
22 | 24 |
23 typedef ViewsTestBase BubbleFrameViewTest; | 25 class BubbleFrameViewTest; |
tapted
2017/03/29 23:16:16
nit: forward dec not used?
Elly Fong-Jones
2017/04/05 18:17:53
Done.
| |
26 | |
27 class BubbleFrameViewTestViewsDelegate : public TestViewsDelegate { | |
28 public: | |
29 BubbleFrameViewTestViewsDelegate() {} | |
30 ~BubbleFrameViewTestViewsDelegate() override {} | |
31 | |
32 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.
| |
33 return ((width + width_snapping_unit_ - 1) / width_snapping_unit_) * | |
34 width_snapping_unit_; | |
35 } | |
36 | |
37 void set_width_snapping_unit(int unit) { width_snapping_unit_ = unit; } | |
38 | |
39 private: | |
40 int width_snapping_unit_ = 1; | |
41 }; | |
tapted
2017/03/29 23:16:16
nit: DISALLOW_COPY...
Elly Fong-Jones
2017/04/05 18:17:53
Done.
| |
42 | |
43 class BubbleFrameViewTest : public ViewsTestBase { | |
44 public: | |
45 BubbleFrameViewTest() { | |
46 views_delegate_ = new BubbleFrameViewTestViewsDelegate; | |
47 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.
| |
48 } | |
49 ~BubbleFrameViewTest() override {} | |
50 | |
51 BubbleFrameViewTestViewsDelegate* views_delegate() { return views_delegate_; } | |
52 | |
53 private: | |
54 BubbleFrameViewTestViewsDelegate* views_delegate_; | |
55 }; | |
tapted
2017/03/29 23:16:16
nit: DISALLOW_COPY...
Elly Fong-Jones
2017/04/05 18:17:53
Done.
| |
24 | 56 |
25 namespace { | 57 namespace { |
26 | 58 |
27 const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT; | 59 const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT; |
28 const SkColor kColor = SK_ColorRED; | 60 const SkColor kColor = SK_ColorRED; |
29 const int kMargin = 6; | 61 const int kMargin = 6; |
30 const int kMinimumClientWidth = 100; | 62 const int kMinimumClientWidth = 100; |
31 const int kMinimumClientHeight = 200; | 63 const int kMinimumClientHeight = 200; |
32 const int kMaximumClientWidth = 300; | 64 const int kMaximumClientWidth = 300; |
33 const int kMaximumClientHeight = 300; | 65 const int kMaximumClientHeight = 300; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 #else | 513 #else |
482 maximum_rect.Inset(frame.bubble_border()->GetInsets()); | 514 maximum_rect.Inset(frame.bubble_border()->GetInsets()); |
483 | 515 |
484 // Should ignore the contents view's maximum size and use the preferred size. | 516 // Should ignore the contents view's maximum size and use the preferred size. |
485 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, | 517 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, |
486 kPreferredClientHeight + kExpectedAdditionalHeight); | 518 kPreferredClientHeight + kExpectedAdditionalHeight); |
487 EXPECT_EQ(expected_size, maximum_rect.size()); | 519 EXPECT_EQ(expected_size, maximum_rect.size()); |
488 #endif | 520 #endif |
489 } | 521 } |
490 | 522 |
523 TEST_F(BubbleFrameViewTest, WidthSnapsToUnit) { | |
tapted
2017/03/29 23:16:16
nit: comment before
Elly Fong-Jones
2017/04/05 18:17:53
Done.
| |
524 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
| |
525 | |
526 // The "border width" here is primarily for the bubble shadow, but also for | |
527 // the edge stroke of the bubble. This width is *not* included in the width | |
528 // snapping, so it needs to be subtracted out. | |
529 int border_width = frame.GetPreferredSize().width() - kPreferredClientWidth - | |
530 kExpectedAdditionalWidth; | |
531 | |
532 // Check that changing the snapping unit changes the computed width to be a | |
533 // 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
| |
534 views_delegate()->set_width_snapping_unit(19); | |
535 EXPECT_EQ((frame.GetPreferredSize().width() - border_width) % 19, 0); | |
536 | |
537 views_delegate()->set_width_snapping_unit(17); | |
538 EXPECT_EQ((frame.GetPreferredSize().width() - border_width) % 17, 0); | |
539 } | |
540 | |
491 } // namespace views | 541 } // namespace views |
OLD | NEW |