| 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..042e7ce484403789e94e1471443a7a70c129919a 100644
|
| --- a/ui/views/bubble/bubble_frame_view_unittest.cc
|
| +++ b/ui/views/bubble/bubble_frame_view_unittest.cc
|
| @@ -14,14 +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 {
|
| -
|
| class SizedBubbleDelegateView : public BubbleDelegateView {
|
| public:
|
| SizedBubbleDelegateView();
|
| @@ -114,7 +114,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 +125,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 +136,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 +147,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 +158,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 +169,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 +180,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 +192,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 +204,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 +220,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 +239,133 @@ 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_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_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_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_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_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_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_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_EQ(window_bounds.y() +
|
| + frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925);
|
| +}
|
| +
|
| } // namespace views
|
|
|