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

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

Issue 2189123002: BubbleFrameView: add padding if platform dislikes close buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test coverage! Created 4 years, 4 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
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/widget/widget_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/label_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 {
(...skipping 29 matching lines...) Expand all
54 gfx::Size(kPreferredClientWidth, kPreferredClientHeight)); 55 gfx::Size(kPreferredClientWidth, kPreferredClientHeight));
55 contents_view->set_minimum_size( 56 contents_view->set_minimum_size(
56 gfx::Size(kMinimumClientWidth, kMinimumClientHeight)); 57 gfx::Size(kMinimumClientWidth, kMinimumClientHeight));
57 contents_view->set_maximum_size( 58 contents_view->set_maximum_size(
58 gfx::Size(kMaximumClientWidth, kMaximumClientHeight)); 59 gfx::Size(kMaximumClientWidth, kMaximumClientHeight));
59 contents_view_ = contents_view; 60 contents_view_ = contents_view;
60 } 61 }
61 return contents_view_; 62 return contents_view_;
62 } 63 }
63 64
65 bool ShouldShowCloseButton() const override { return should_show_close_; }
66 bool should_show_close_ = false;
msw 2016/07/29 19:38:39 Make this private and add a setter.
Elly Fong-Jones 2016/08/02 17:49:29 Done.
67
64 private: 68 private:
65 Widget* widget_; 69 Widget* widget_;
66 View* contents_view_ = nullptr; // Owned by |widget_|. 70 View* contents_view_ = nullptr; // Owned by |widget_|.
67 }; 71 };
68 72
69 class TestBubbleFrameView : public BubbleFrameView { 73 class TestBubbleFrameView : public BubbleFrameView {
70 public: 74 public:
71 TestBubbleFrameView(ViewsTestBase* test_base) 75 TestBubbleFrameView(ViewsTestBase* test_base)
72 : BubbleFrameView(gfx::Insets(), gfx::Insets(kMargin)), 76 : BubbleFrameView(gfx::Insets(), gfx::Insets(kMargin)),
73 test_base_(test_base), 77 test_base_(test_base),
(...skipping 17 matching lines...) Expand all
91 } 95 }
92 96
93 return widget_.get(); 97 return widget_.get();
94 } 98 }
95 99
96 // BubbleFrameView overrides: 100 // BubbleFrameView overrides:
97 gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override { 101 gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override {
98 return available_bounds_; 102 return available_bounds_;
99 } 103 }
100 104
105 TestBubbleFrameViewWidgetDelegate* widget_delegate() {
106 return widget_delegate_.get();
107 }
108
101 private: 109 private:
102 ViewsTestBase* test_base_; 110 ViewsTestBase* test_base_;
103 111
104 gfx::Rect available_bounds_; 112 gfx::Rect available_bounds_;
105 113
106 // Widget returned by GetWidget(). Only created if GetWidget() is called. 114 // Widget returned by GetWidget(). Only created if GetWidget() is called.
107 mutable std::unique_ptr<TestBubbleFrameViewWidgetDelegate> widget_delegate_; 115 mutable std::unique_ptr<TestBubbleFrameViewWidgetDelegate> widget_delegate_;
108 mutable std::unique_ptr<Widget> widget_; 116 mutable std::unique_ptr<Widget> widget_;
109 117
110 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); 118 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView);
111 }; 119 };
112 120
113 } // namespace 121 } // namespace
114 122
115 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { 123 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) {
116 TestBubbleFrameView frame(this); 124 TestBubbleFrameView frame(this);
117 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); 125 EXPECT_EQ(kArrow, frame.bubble_border()->arrow());
118 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); 126 EXPECT_EQ(kColor, frame.bubble_border()->background_color());
119 127
120 int margin_x = frame.content_margins().left(); 128 int margin_x = frame.content_margins().left();
121 int margin_y = frame.content_margins().top(); 129 int margin_y = frame.content_margins().top();
122 gfx::Insets insets = frame.bubble_border()->GetInsets(); 130 gfx::Insets insets = frame.bubble_border()->GetInsets();
123 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); 131 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x());
124 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); 132 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y());
125 } 133 }
126 134
135 TEST_F(BubbleFrameViewTest, GetBoundsForClientViewWithClose) {
136 TestBubbleFrameView frame(this);
137 // TestBubbleFrameView::GetWidget() is responsible for creating the widget and
138 // widget delegate at first call, so it is called here for that side-effect.
139 (void)frame.GetWidget();
msw 2016/07/29 19:38:39 I think there's a more chrome-standard way of doin
msw 2016/07/29 19:40:59 Found it: https://cs.chromium.org/chromium/src/bas
Elly Fong-Jones 2016/08/02 17:49:29 Done.
Elly Fong-Jones 2016/08/02 17:49:29 Done.
140 frame.widget_delegate()->should_show_close_ = true;
141 frame.OnThemeChanged();
142 EXPECT_EQ(kArrow, frame.bubble_border()->arrow());
143 EXPECT_EQ(kColor, frame.bubble_border()->background_color());
144
145 int margin_x = frame.content_margins().left();
146 int margin_y = frame.content_margins().top() +
147 frame.GetCloseButtonForTest()->height();
148 gfx::Insets insets = frame.bubble_border()->GetInsets();
149 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x());
150 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y());
151 }
152
127 // Tests that the arrow is mirrored as needed to better fit the screen. 153 // Tests that the arrow is mirrored as needed to better fit the screen.
128 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { 154 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) {
129 TestBubbleFrameView frame(this); 155 TestBubbleFrameView frame(this);
130 gfx::Rect window_bounds; 156 gfx::Rect window_bounds;
131 157
132 gfx::Insets insets = frame.bubble_border()->GetInsets(); 158 gfx::Insets insets = frame.bubble_border()->GetInsets();
133 int xposition = 95 - insets.width(); 159 int xposition = 95 - insets.width();
134 160
135 // Test that the info bubble displays normally when it fits. 161 // Test that the info bubble displays normally when it fits.
136 frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT); 162 frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 maximum_rect.Inset(frame.bubble_border()->GetInsets()); 479 maximum_rect.Inset(frame.bubble_border()->GetInsets());
454 480
455 // Should ignore the contents view's maximum size and use the preferred size. 481 // Should ignore the contents view's maximum size and use the preferred size.
456 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, 482 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth,
457 kPreferredClientHeight + kExpectedAdditionalHeight); 483 kPreferredClientHeight + kExpectedAdditionalHeight);
458 EXPECT_EQ(expected_size, maximum_rect.size()); 484 EXPECT_EQ(expected_size, maximum_rect.size());
459 #endif 485 #endif
460 } 486 }
461 487
462 } // namespace views 488 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | ui/views/widget/widget_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698