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/gfx/geometry/insets.h" | 11 #include "ui/gfx/geometry/insets.h" |
12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
14 #include "ui/views/bubble/bubble_border.h" | 14 #include "ui/views/bubble/bubble_border.h" |
15 #include "ui/views/controls/button/image_button.h" | |
16 #include "ui/views/test/test_views.h" | 15 #include "ui/views/test/test_views.h" |
17 #include "ui/views/test/views_test_base.h" | 16 #include "ui/views/test/views_test_base.h" |
18 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
19 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
20 | 19 |
21 namespace views { | 20 namespace views { |
22 | 21 |
23 typedef ViewsTestBase BubbleFrameViewTest; | 22 typedef ViewsTestBase BubbleFrameViewTest; |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT; | 26 const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT; |
28 const SkColor kColor = SK_ColorRED; | 27 const SkColor kColor = SK_ColorRED; |
29 const int kMargin = 6; | 28 const int kMargin = 6; |
30 const int kMinimumClientWidth = 100; | 29 const int kMinimumClientWidth = 100; |
31 const int kMinimumClientHeight = 200; | 30 const int kMinimumClientHeight = 200; |
32 const int kMaximumClientWidth = 300; | 31 const int kMaximumClientWidth = 300; |
33 const int kMaximumClientHeight = 300; | 32 const int kMaximumClientHeight = 300; |
34 const int kPreferredClientWidth = 150; | 33 const int kPreferredClientWidth = 150; |
35 const int kPreferredClientHeight = 250; | 34 const int kPreferredClientHeight = 250; |
36 | 35 |
37 // These account for non-client areas like the title bar, footnote etc. However | 36 // These account for non-client areas like the title bar, footnote etc. However |
38 // these do not take the bubble border into consideration. | 37 // these do not take the bubble border into consideration. |
39 const int kExpectedAdditionalWidth = 12; | 38 const int kExpectedAdditionalWidth = 12; |
40 // 12 for the builtin margin, 14 for the close button margin | 39 const int kExpectedAdditionalHeight = 12; |
41 const int kExpectedAdditionalHeight = 12 + 14; | |
42 | 40 |
43 class TestBubbleFrameViewWidgetDelegate : public WidgetDelegate { | 41 class TestBubbleFrameViewWidgetDelegate : public WidgetDelegate { |
44 public: | 42 public: |
45 TestBubbleFrameViewWidgetDelegate(Widget* widget) : widget_(widget) {} | 43 TestBubbleFrameViewWidgetDelegate(Widget* widget) : widget_(widget) {} |
46 | 44 |
47 ~TestBubbleFrameViewWidgetDelegate() override {} | 45 ~TestBubbleFrameViewWidgetDelegate() override {} |
48 | 46 |
49 // WidgetDelegate overrides: | 47 // WidgetDelegate overrides: |
50 Widget* GetWidget() override { return widget_; } | 48 Widget* GetWidget() override { return widget_; } |
51 const Widget* GetWidget() const override { return widget_; } | 49 const Widget* GetWidget() const override { return widget_; } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 112 |
115 } // namespace | 113 } // namespace |
116 | 114 |
117 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { | 115 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { |
118 TestBubbleFrameView frame(this); | 116 TestBubbleFrameView frame(this); |
119 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); | 117 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); |
120 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); | 118 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); |
121 | 119 |
122 int margin_x = frame.content_margins().left(); | 120 int margin_x = frame.content_margins().left(); |
123 int margin_y = frame.content_margins().top(); | 121 int margin_y = frame.content_margins().top(); |
124 int close_y = frame.GetCloseButtonForTest()->height(); | |
125 gfx::Insets insets = frame.bubble_border()->GetInsets(); | 122 gfx::Insets insets = frame.bubble_border()->GetInsets(); |
126 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); | 123 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); |
127 EXPECT_EQ(insets.top() + margin_y + close_y, | 124 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); |
128 frame.GetBoundsForClientView().y()); | |
129 } | 125 } |
130 | 126 |
131 // Tests that the arrow is mirrored as needed to better fit the screen. | 127 // Tests that the arrow is mirrored as needed to better fit the screen. |
132 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { | 128 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
133 TestBubbleFrameView frame(this); | 129 TestBubbleFrameView frame(this); |
134 gfx::Rect window_bounds; | 130 gfx::Rect window_bounds; |
135 | 131 |
136 gfx::Insets insets = frame.bubble_border()->GetInsets(); | 132 gfx::Insets insets = frame.bubble_border()->GetInsets(); |
137 int xposition = 95 - insets.width(); | 133 int xposition = 95 - insets.width(); |
138 | 134 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 kPreferredClientHeight + kExpectedAdditionalHeight); | 430 kPreferredClientHeight + kExpectedAdditionalHeight); |
435 EXPECT_EQ(expected_size, preferred_rect.size()); | 431 EXPECT_EQ(expected_size, preferred_rect.size()); |
436 } | 432 } |
437 | 433 |
438 TEST_F(BubbleFrameViewTest, GetMinimumSize) { | 434 TEST_F(BubbleFrameViewTest, GetMinimumSize) { |
439 TestBubbleFrameView frame(this); | 435 TestBubbleFrameView frame(this); |
440 gfx::Rect minimum_rect(frame.GetMinimumSize()); | 436 gfx::Rect minimum_rect(frame.GetMinimumSize()); |
441 // Expect that a border has been added to the minimum size. | 437 // Expect that a border has been added to the minimum size. |
442 minimum_rect.Inset(frame.bubble_border()->GetInsets()); | 438 minimum_rect.Inset(frame.bubble_border()->GetInsets()); |
443 | 439 |
444 ImageButton* button = frame.GetCloseButtonForTest(); | |
445 EXPECT_EQ(button->height(), 14); | |
446 EXPECT_EQ(nullptr, frame.GetCloseButtonForTest()->border()); | |
447 gfx::Size expected_size(kMinimumClientWidth + kExpectedAdditionalWidth, | 440 gfx::Size expected_size(kMinimumClientWidth + kExpectedAdditionalWidth, |
448 kMinimumClientHeight + kExpectedAdditionalHeight); | 441 kMinimumClientHeight + kExpectedAdditionalHeight); |
449 EXPECT_EQ(expected_size, minimum_rect.size()); | 442 EXPECT_EQ(expected_size, minimum_rect.size()); |
450 } | 443 } |
451 | 444 |
452 TEST_F(BubbleFrameViewTest, GetMaximumSize) { | 445 TEST_F(BubbleFrameViewTest, GetMaximumSize) { |
453 TestBubbleFrameView frame(this); | 446 TestBubbleFrameView frame(this); |
454 gfx::Rect maximum_rect(frame.GetMaximumSize()); | 447 gfx::Rect maximum_rect(frame.GetMaximumSize()); |
455 #if defined(OS_WIN) | 448 #if defined(OS_WIN) |
456 // On Windows, GetMaximumSize causes problems with DWM, so it should just be 0 | 449 // On Windows, GetMaximumSize causes problems with DWM, so it should just be 0 |
457 // (unlimited). See http://crbug.com/506206. | 450 // (unlimited). See http://crbug.com/506206. |
458 EXPECT_EQ(gfx::Size(), maximum_rect.size()); | 451 EXPECT_EQ(gfx::Size(), maximum_rect.size()); |
459 #else | 452 #else |
460 maximum_rect.Inset(frame.bubble_border()->GetInsets()); | 453 maximum_rect.Inset(frame.bubble_border()->GetInsets()); |
461 | 454 |
462 // Should ignore the contents view's maximum size and use the preferred size. | 455 // Should ignore the contents view's maximum size and use the preferred size. |
463 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, | 456 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, |
464 kPreferredClientHeight + kExpectedAdditionalHeight); | 457 kPreferredClientHeight + kExpectedAdditionalHeight); |
465 EXPECT_EQ(expected_size, maximum_rect.size()); | 458 EXPECT_EQ(expected_size, maximum_rect.size()); |
466 #endif | 459 #endif |
467 } | 460 } |
468 | 461 |
469 } // namespace views | 462 } // namespace views |
OLD | NEW |