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

Side by Side Diff: ui/views/bubble/bubble_frame_view_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698