| OLD | NEW |
| 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" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); | 161 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); |
| 162 | 162 |
| 163 gfx::Insets frame_insets = frame.GetInsets(); | 163 gfx::Insets frame_insets = frame.GetInsets(); |
| 164 gfx::Insets border_insets = frame.bubble_border()->GetInsets(); | 164 gfx::Insets border_insets = frame.bubble_border()->GetInsets(); |
| 165 EXPECT_EQ(border_insets.left() + frame_insets.left(), | 165 EXPECT_EQ(border_insets.left() + frame_insets.left(), |
| 166 frame.GetBoundsForClientView().x()); | 166 frame.GetBoundsForClientView().x()); |
| 167 EXPECT_EQ(border_insets.top() + frame_insets.top(), | 167 EXPECT_EQ(border_insets.top() + frame_insets.top(), |
| 168 frame.GetBoundsForClientView().y()); | 168 frame.GetBoundsForClientView().y()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(BubbleFrameViewTest, |
| 172 FootnoteContainerViewShouldMatchVisibilityOfFirstChild) { |
| 173 TestBubbleFrameView frame(this); |
| 174 View* footnote_dummy_view = new StaticSizedView(gfx::Size(200, 200)); |
| 175 footnote_dummy_view->SetVisible(false); |
| 176 frame.SetFootnoteView(footnote_dummy_view); |
| 177 View* footnote_container_view = footnote_dummy_view->parent(); |
| 178 EXPECT_FALSE(footnote_container_view->visible()); |
| 179 footnote_dummy_view->SetVisible(true); |
| 180 EXPECT_TRUE(footnote_container_view->visible()); |
| 181 footnote_dummy_view->SetVisible(false); |
| 182 EXPECT_FALSE(footnote_container_view->visible()); |
| 183 } |
| 184 |
| 171 // Tests that the arrow is mirrored as needed to better fit the screen. | 185 // Tests that the arrow is mirrored as needed to better fit the screen. |
| 172 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { | 186 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { |
| 173 TestBubbleFrameView frame(this); | 187 TestBubbleFrameView frame(this); |
| 174 gfx::Rect window_bounds; | 188 gfx::Rect window_bounds; |
| 175 | 189 |
| 176 gfx::Insets insets = frame.bubble_border()->GetInsets(); | 190 gfx::Insets insets = frame.bubble_border()->GetInsets(); |
| 177 int xposition = 95 - insets.width(); | 191 int xposition = 95 - insets.width(); |
| 178 | 192 |
| 179 // Test that the info bubble displays normally when it fits. | 193 // Test that the info bubble displays normally when it fits. |
| 180 frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT); | 194 frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 gfx::Rect(900, 900, 50, 50), // |anchor_rect| | 472 gfx::Rect(900, 900, 50, 50), // |anchor_rect| |
| 459 gfx::Size(500, 500), // |client_size| | 473 gfx::Size(500, 500), // |client_size| |
| 460 true); // |adjust_if_offscreen| | 474 true); // |adjust_if_offscreen| |
| 461 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow()); | 475 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow()); |
| 462 EXPECT_EQ(window_bounds.bottom(), 1000); | 476 EXPECT_EQ(window_bounds.bottom(), 1000); |
| 463 EXPECT_EQ(window_bounds.y() + | 477 EXPECT_EQ(window_bounds.y() + |
| 464 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); | 478 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); |
| 465 } | 479 } |
| 466 | 480 |
| 467 TEST_F(BubbleFrameViewTest, GetPreferredSize) { | 481 TEST_F(BubbleFrameViewTest, GetPreferredSize) { |
| 482 // Test border/insets. |
| 468 TestBubbleFrameView frame(this); | 483 TestBubbleFrameView frame(this); |
| 469 gfx::Rect preferred_rect(frame.GetPreferredSize()); | 484 gfx::Rect preferred_rect(frame.GetPreferredSize()); |
| 470 // Expect that a border has been added to the preferred size. | 485 // Expect that a border has been added to the preferred size. |
| 471 preferred_rect.Inset(frame.bubble_border()->GetInsets()); | 486 preferred_rect.Inset(frame.bubble_border()->GetInsets()); |
| 472 | 487 |
| 473 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, | 488 gfx::Size expected_size(kPreferredClientWidth + kExpectedAdditionalWidth, |
| 474 kPreferredClientHeight + kExpectedAdditionalHeight); | 489 kPreferredClientHeight + kExpectedAdditionalHeight); |
| 475 EXPECT_EQ(expected_size, preferred_rect.size()); | 490 EXPECT_EQ(expected_size, preferred_rect.size()); |
| 476 } | 491 } |
| 477 | 492 |
| 493 TEST_F(BubbleFrameViewTest, GetPreferredSizeWithFootnote) { |
| 494 // Test footnote view: adding a footnote should increase the preferred size, |
| 495 // but only when the footnote is visible. |
| 496 TestBubbleFrameView frame(this); |
| 497 |
| 498 constexpr int kFootnoteHeight = 20; |
| 499 const gfx::Size no_footnote_size = frame.GetPreferredSize(); |
| 500 View* footnote = new StaticSizedView(gfx::Size(10, kFootnoteHeight)); |
| 501 footnote->SetVisible(false); |
| 502 frame.SetFootnoteView(footnote); |
| 503 EXPECT_EQ(no_footnote_size, frame.GetPreferredSize()); // No change. |
| 504 |
| 505 footnote->SetVisible(true); |
| 506 gfx::Size with_footnote_size = no_footnote_size; |
| 507 constexpr int kFootnoteTopBorderThickness = 1; |
| 508 with_footnote_size.Enlarge(0, kFootnoteHeight + kFootnoteTopBorderThickness + |
| 509 frame.content_margins().height()); |
| 510 EXPECT_EQ(with_footnote_size, frame.GetPreferredSize()); |
| 511 |
| 512 footnote->SetVisible(false); |
| 513 EXPECT_EQ(no_footnote_size, frame.GetPreferredSize()); |
| 514 } |
| 515 |
| 478 TEST_F(BubbleFrameViewTest, GetMinimumSize) { | 516 TEST_F(BubbleFrameViewTest, GetMinimumSize) { |
| 479 TestBubbleFrameView frame(this); | 517 TestBubbleFrameView frame(this); |
| 480 gfx::Rect minimum_rect(frame.GetMinimumSize()); | 518 gfx::Rect minimum_rect(frame.GetMinimumSize()); |
| 481 // Expect that a border has been added to the minimum size. | 519 // Expect that a border has been added to the minimum size. |
| 482 minimum_rect.Inset(frame.bubble_border()->GetInsets()); | 520 minimum_rect.Inset(frame.bubble_border()->GetInsets()); |
| 483 | 521 |
| 484 gfx::Size expected_size(kMinimumClientWidth + kExpectedAdditionalWidth, | 522 gfx::Size expected_size(kMinimumClientWidth + kExpectedAdditionalWidth, |
| 485 kMinimumClientHeight + kExpectedAdditionalHeight); | 523 kMinimumClientHeight + kExpectedAdditionalHeight); |
| 486 EXPECT_EQ(expected_size, minimum_rect.size()); | 524 EXPECT_EQ(expected_size, minimum_rect.size()); |
| 487 } | 525 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 // If the DialogDelegate asks not to snap, it should not snap. | 612 // If the DialogDelegate asks not to snap, it should not snap. |
| 575 delegate.set_override_snap(false); | 613 delegate.set_override_snap(false); |
| 576 Widget* w2 = BubbleDialogDelegateView::CreateBubble(&delegate); | 614 Widget* w2 = BubbleDialogDelegateView::CreateBubble(&delegate); |
| 577 w2->Show(); | 615 w2->Show(); |
| 578 EXPECT_EQ(delegate.GetPreferredSize().width(), | 616 EXPECT_EQ(delegate.GetPreferredSize().width(), |
| 579 w2->GetWindowBoundsInScreen().width()); | 617 w2->GetWindowBoundsInScreen().width()); |
| 580 w2->CloseNow(); | 618 w2->CloseNow(); |
| 581 } | 619 } |
| 582 | 620 |
| 583 } // namespace views | 621 } // namespace views |
| OLD | NEW |