OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/bubble/border_contents.h" | 5 #include "ui/views/bubble/border_contents_view.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 typedef testing::Test BorderContentsTest; | 8 typedef testing::Test BorderContentsTest; |
9 | 9 |
10 class TestBorderContents : public BorderContents { | 10 class TestBorderContentsView : public views::BorderContentsView { |
11 public: | 11 public: |
12 TestBorderContents() {} | 12 TestBorderContentsView() {} |
13 | 13 |
14 void set_monitor_bounds(const gfx::Rect& bounds) { | 14 void set_monitor_bounds(const gfx::Rect& bounds) { |
15 monitor_bounds_ = bounds; | 15 monitor_bounds_ = bounds; |
16 } | 16 } |
17 | 17 |
18 views::BubbleBorder* bubble_border() const { | 18 views::BubbleBorder* bubble_border() const { |
19 return BorderContents::bubble_border(); | 19 return BorderContentsView::bubble_border(); |
20 } | 20 } |
21 | 21 |
22 protected: | 22 protected: |
23 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) { | 23 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) { |
24 return monitor_bounds_; | 24 return monitor_bounds_; |
25 } | 25 } |
26 | 26 |
27 private: | 27 private: |
28 gfx::Rect monitor_bounds_; | 28 gfx::Rect monitor_bounds_; |
29 | 29 |
30 DISALLOW_COPY_AND_ASSIGN(TestBorderContents); | 30 DISALLOW_COPY_AND_ASSIGN(TestBorderContentsView); |
31 }; | 31 }; |
32 | 32 |
33 // Tests that the arrow is moved appropriately when the info-bubble does not fit | 33 // Tests that the arrow is moved appropriately when the info-bubble does not fit |
34 // the screen. | 34 // the screen. |
35 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBounds) { | 35 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBounds) { |
36 TestBorderContents border_contents; | 36 TestBorderContentsView border_contents; |
37 border_contents.Init(); | 37 border_contents.Init(); |
38 | 38 |
39 gfx::Insets insets; | 39 gfx::Insets insets; |
40 border_contents.bubble_border()->GetInsets(&insets); | 40 border_contents.bubble_border()->GetInsets(&insets); |
41 int xposition = 95 - insets.width(); | 41 int xposition = 95 - insets.width(); |
42 | 42 |
43 // Test that the info bubble displays normally when it fits. | 43 // Test that the info bubble displays normally when it fits. |
44 gfx::Rect contents_bounds; | 44 gfx::Rect contents_bounds; |
45 gfx::Rect window_bounds; | 45 gfx::Rect window_bounds; |
46 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000)); | 46 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000)); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location)); | 187 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location)); |
188 // The window should be right aligned with the position_relative_to. | 188 // The window should be right aligned with the position_relative_to. |
189 EXPECT_LT(window_bounds.x(), 900 + 50 - 500); | 189 EXPECT_LT(window_bounds.x(), 900 + 50 - 500); |
190 EXPECT_LT(window_bounds.y(), 900 - 500 - 15); // -15 to roughly compensate | 190 EXPECT_LT(window_bounds.y(), 900 - 500 - 15); // -15 to roughly compensate |
191 // for arrow height. | 191 // for arrow height. |
192 } | 192 } |
193 | 193 |
194 // Tests that the arrow is not moved when the info-bubble does not fit the | 194 // Tests that the arrow is not moved when the info-bubble does not fit the |
195 // screen but moving it would make matter worse. | 195 // screen but moving it would make matter worse. |
196 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBoundsDontMoveArrow) { | 196 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBoundsDontMoveArrow) { |
197 TestBorderContents border_contents; | 197 TestBorderContentsView border_contents; |
198 border_contents.Init(); | 198 border_contents.Init(); |
199 gfx::Rect contents_bounds; | 199 gfx::Rect contents_bounds; |
200 gfx::Rect window_bounds; | 200 gfx::Rect window_bounds; |
201 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000)); | 201 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000)); |
202 border_contents.SizeAndGetBounds( | 202 border_contents.SizeAndGetBounds( |
203 gfx::Rect(400, 100, 50, 50), // |position_relative_to| | 203 gfx::Rect(400, 100, 50, 50), // |position_relative_to| |
204 views::BubbleBorder::TOP_LEFT, | 204 views::BubbleBorder::TOP_LEFT, |
205 false, // |allow_bubble_offscreen| | 205 false, // |allow_bubble_offscreen| |
206 gfx::Size(500, 700), // |contents_size| | 206 gfx::Size(500, 700), // |contents_size| |
207 &contents_bounds, &window_bounds); | 207 &contents_bounds, &window_bounds); |
208 | 208 |
209 // The arrow should not have changed, as it would make it the bubble even more | 209 // The arrow should not have changed, as it would make it the bubble even more |
210 // offscreen. | 210 // offscreen. |
211 views::BubbleBorder::ArrowLocation arrow_location = | 211 views::BubbleBorder::ArrowLocation arrow_location = |
212 border_contents.bubble_border()->arrow_location(); | 212 border_contents.bubble_border()->arrow_location(); |
213 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location)); | 213 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location)); |
214 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location)); | 214 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location)); |
215 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location)); | 215 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_left(arrow_location)); |
216 } | 216 } |
217 | 217 |
218 // Test that the 'allow offscreen' prevents the bubble from moving. | 218 // Test that the 'allow offscreen' prevents the bubble from moving. |
219 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBoundsAllowOffscreen) { | 219 TEST_F(BorderContentsTest, BorderContentsSizeAndGetBoundsAllowOffscreen) { |
220 TestBorderContents border_contents; | 220 TestBorderContentsView border_contents; |
221 border_contents.Init(); | 221 border_contents.Init(); |
222 gfx::Rect contents_bounds; | 222 gfx::Rect contents_bounds; |
223 gfx::Rect window_bounds; | 223 gfx::Rect window_bounds; |
224 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000)); | 224 border_contents.set_monitor_bounds(gfx::Rect(0, 0, 1000, 1000)); |
225 border_contents.SizeAndGetBounds( | 225 border_contents.SizeAndGetBounds( |
226 gfx::Rect(100, 900, 50, 50), // |position_relative_to| | 226 gfx::Rect(100, 900, 50, 50), // |position_relative_to| |
227 views::BubbleBorder::TOP_RIGHT, | 227 views::BubbleBorder::TOP_RIGHT, |
228 true, // |allow_bubble_offscreen| | 228 true, // |allow_bubble_offscreen| |
229 gfx::Size(500, 500), // |contents_size| | 229 gfx::Size(500, 500), // |contents_size| |
230 &contents_bounds, &window_bounds); | 230 &contents_bounds, &window_bounds); |
231 | 231 |
232 // The arrow should not have changed (eventhough the bubble does not fit). | 232 // The arrow should not have changed (eventhough the bubble does not fit). |
233 views::BubbleBorder::ArrowLocation arrow_location = | 233 views::BubbleBorder::ArrowLocation arrow_location = |
234 border_contents.bubble_border()->arrow_location(); | 234 border_contents.bubble_border()->arrow_location(); |
235 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location)); | 235 EXPECT_TRUE(views::BubbleBorder::has_arrow(arrow_location)); |
236 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location)); | 236 EXPECT_TRUE(views::BubbleBorder::is_arrow_on_top(arrow_location)); |
237 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_left(arrow_location)); | 237 EXPECT_FALSE(views::BubbleBorder::is_arrow_on_left(arrow_location)); |
238 // The coordinates should be pointing to 'positive relative to' from | 238 // The coordinates should be pointing to 'positive relative to' from |
239 // TOP_RIGHT. | 239 // TOP_RIGHT. |
240 EXPECT_LT(window_bounds.x(), 100 + 50 - 500); | 240 EXPECT_LT(window_bounds.x(), 100 + 50 - 500); |
241 EXPECT_GT(window_bounds.y(), 900 + 50 - 10); // -10 to roughly compensate for | 241 EXPECT_GT(window_bounds.y(), 900 + 50 - 10); // -10 to roughly compensate for |
242 // arrow overlap. | 242 // arrow overlap. |
243 } | 243 } |
OLD | NEW |