Chromium Code Reviews| Index: ui/views/bubble/bubble_frame_view_unittest.cc |
| diff --git a/ui/views/bubble/bubble_frame_view_unittest.cc b/ui/views/bubble/bubble_frame_view_unittest.cc |
| index c6f1a5b2cf72bf048f8d8ad9d7abacd4b847ce30..4506050b776b9fc03d5b9aa58b103d2a03287eb3 100644 |
| --- a/ui/views/bubble/bubble_frame_view_unittest.cc |
| +++ b/ui/views/bubble/bubble_frame_view_unittest.cc |
| @@ -14,13 +14,14 @@ namespace views { |
| typedef ViewsTestBase BubbleFrameViewTest; |
| +namespace { |
| + |
| const BubbleBorder::ArrowLocation kArrow = BubbleBorder::TOP_LEFT; |
| const int kBubbleWidth = 200; |
| const int kBubbleHeight = 200; |
| const SkColor kBackgroundColor = SK_ColorRED; |
| const int kDefaultMargin = 6; |
| - |
| -namespace { |
| +const int kIgnore = -1; |
|
msw
2012/09/20 00:07:23
nit: remove
xiyuan
2012/09/20 16:56:51
Done.
|
| class SizedBubbleDelegateView : public BubbleDelegateView { |
| public: |
| @@ -114,7 +115,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(100, 100, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow_location()); |
| EXPECT_GT(window_bounds.x(), xposition); |
| EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for |
| @@ -125,7 +126,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(100, 100, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow_location()); |
| EXPECT_GT(window_bounds.x(), xposition); |
| EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for |
| @@ -136,7 +137,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(100, 100, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow_location()); |
| EXPECT_GT(window_bounds.x(), xposition); |
| EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for |
| @@ -147,7 +148,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(100, 100, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow_location()); |
| EXPECT_GT(window_bounds.x(), xposition); |
| EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for |
| @@ -158,7 +159,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(900, 100, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::TOP_RIGHT, frame.bubble_border()->arrow_location()); |
| EXPECT_LT(window_bounds.x(), 900 + 50 - 500); |
| EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for |
| @@ -169,7 +170,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(900, 100, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::TOP_RIGHT, frame.bubble_border()->arrow_location()); |
| EXPECT_LT(window_bounds.x(), 900 + 50 - 500); |
| EXPECT_GT(window_bounds.y(), 100 + 50 - 10); // -10 to roughly compensate for |
| @@ -180,7 +181,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(900, 900, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::BOTTOM_RIGHT, |
| frame.bubble_border()->arrow_location()); |
| EXPECT_LT(window_bounds.x(), 900 + 50 - 500); |
| @@ -192,7 +193,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(100, 900, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::BOTTOM_LEFT, frame.bubble_border()->arrow_location()); |
| // The window should be right aligned with the anchor_rect. |
| EXPECT_LT(window_bounds.x(), 900 + 50 - 500); |
| @@ -204,7 +205,7 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(100, 900, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::BOTTOM_LEFT, frame.bubble_border()->arrow_location()); |
| // The window should be right aligned with the anchor_rect. |
| EXPECT_LT(window_bounds.x(), 900 + 50 - 500); |
| @@ -220,18 +221,18 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsMirroringFails) { |
| gfx::Rect window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(400, 100, 50, 50), // |anchor_rect| |
| gfx::Size(500, 700), // |client_size| |
| - true); // |try_mirroring_arrow| |
| + true); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow_location()); |
| } |
| -// Test that the arrow will not be mirrored when |try_mirroring_arrow| is false. |
| +// Test that the arrow will not be mirrored when |adjust_if_offscreen| is false. |
| TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsDontTryMirror) { |
| TestBubbleFrameView frame; |
| frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_RIGHT); |
| gfx::Rect window_bounds = frame.GetUpdatedWindowBounds( |
| gfx::Rect(100, 900, 50, 50), // |anchor_rect| |
| gfx::Size(500, 500), // |client_size| |
| - false); // |try_mirroring_arrow| |
| + false); // |adjust_if_offscreen| |
| EXPECT_EQ(BubbleBorder::TOP_RIGHT, frame.bubble_border()->arrow_location()); |
| // The coordinates should be pointing to anchor_rect from TOP_RIGHT. |
| EXPECT_LT(window_bounds.x(), 100 + 50 - 500); |
| @@ -239,4 +240,141 @@ TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsDontTryMirror) { |
| // arrow overlap. |
| } |
| +// Test that the center arrow is moved as needed to fit the screen. |
| +TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsCenterArrows) { |
| + TestBubbleFrameView frame; |
| + gfx::Rect window_bounds; |
| + |
| + // Test that the bubble displays normally when it fits. |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(500, 100, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::TOP_CENTER, frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.x() + window_bounds.width() / 2, 525); |
| + |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::BOTTOM_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(500, 900, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::BOTTOM_CENTER, |
| + frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.x() + window_bounds.width() / 2, 525); |
| + |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::LEFT_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(100, 400, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::LEFT_CENTER, frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.y() + window_bounds.height() / 2, 425); |
| + |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::RIGHT_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(900, 400, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::RIGHT_CENTER, |
| + frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.y() + window_bounds.height() / 2, 425); |
| + |
| + // Test bubble not fitting left screen edge. |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(100, 100, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::TOP_CENTER, frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.x(), 0); |
| + EXPECT_GT(window_bounds.x() + window_bounds.width() / 2, 125); |
|
msw
2012/09/20 00:07:23
GT 125 seems too loose, it's EQ 250, right?
xiyuan
2012/09/20 16:56:51
This is intended to verify that bubble's center is
|
| + EXPECT_EQ(window_bounds.x() + |
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 125); |
| + |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::BOTTOM_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(100, 900, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::BOTTOM_CENTER, |
| + frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.x(), 0); |
| + EXPECT_GT(window_bounds.x() + window_bounds.width() / 2, 125); |
|
msw
2012/09/20 00:07:23
ditto: GT 125 seems too loose, it's EQ 250, right?
|
| + EXPECT_EQ(window_bounds.x() + |
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 125); |
| + |
| + // Test bubble not fitting right screen edge. |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(900, 100, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::TOP_CENTER, frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.right(), 1000); |
| + EXPECT_LT(window_bounds.x() + window_bounds.width() / 2, 925); |
|
msw
2012/09/20 00:07:23
similar: LT 925 seems too loose, it's EQ 750, righ
|
| + EXPECT_EQ(window_bounds.x() + |
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); |
| + |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::BOTTOM_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(900, 900, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::BOTTOM_CENTER, |
| + frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.right(), 1000); |
| + EXPECT_LT(window_bounds.x() + window_bounds.width() / 2, 925); |
|
msw
2012/09/20 00:07:23
ditto: LT 925 seems too loose, it's EQ 750, right?
|
| + EXPECT_EQ(window_bounds.x() + |
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); |
| + |
| + // Test bubble not fitting top screen edge. |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::LEFT_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(100, 100, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::LEFT_CENTER, frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.y(), 0); |
| + EXPECT_GT(window_bounds.y() + window_bounds.height() / 2, 125); |
|
msw
2012/09/20 00:07:23
similar: GT 125 seems too loose, it's EQ 250, righ
|
| + EXPECT_EQ(window_bounds.y() + |
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 125); |
| + |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::RIGHT_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(900, 100, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::RIGHT_CENTER, |
| + frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.y(), 0); |
| + EXPECT_GT(window_bounds.y() + window_bounds.height() / 2, 125); |
|
msw
2012/09/20 00:07:23
ditto: GT 125 seems too loose, it's EQ 250, right?
|
| + EXPECT_EQ(window_bounds.y() + |
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 125); |
| + |
| + // Test bubble not fitting bottom screen edge. |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::LEFT_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(100, 900, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::LEFT_CENTER, frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.bottom(), 1000); |
| + EXPECT_LT(window_bounds.y() + window_bounds.height() / 2, 925); |
|
msw
2012/09/20 00:07:23
similar: LT 925 seems too loose, it's EQ 750, righ
|
| + EXPECT_EQ(window_bounds.y() + |
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); |
| + |
| + frame.bubble_border()->set_arrow_location(BubbleBorder::RIGHT_CENTER); |
| + window_bounds = frame.GetUpdatedWindowBounds( |
| + gfx::Rect(900, 900, 50, 50), // |anchor_rect| |
| + gfx::Size(500, 500), // |client_size| |
| + true); // |adjust_if_offscreen| |
| + EXPECT_EQ(BubbleBorder::RIGHT_CENTER, |
| + frame.bubble_border()->arrow_location()); |
| + EXPECT_EQ(window_bounds.bottom(), 1000); |
| + EXPECT_LT(window_bounds.y() + window_bounds.height() / 2, 925); |
|
msw
2012/09/20 00:07:23
ditto: LT 925 seems too loose, it's EQ 750, right?
|
| + EXPECT_EQ(window_bounds.y() + |
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); |
| +} |
| + |
| } // namespace views |