Chromium Code Reviews| 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "ui/gfx/geometry/insets.h" | 8 #include "ui/gfx/geometry/insets.h" |
| 9 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/gfx/geometry/size.h" | 10 #include "ui/gfx/geometry/size.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT; | 24 const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT; |
| 25 const SkColor kColor = SK_ColorRED; | 25 const SkColor kColor = SK_ColorRED; |
| 26 const int kMargin = 6; | 26 const int kMargin = 6; |
| 27 const int kMinimumClientWidth = 100; | 27 const int kMinimumClientWidth = 100; |
| 28 const int kMinimumClientHeight = 200; | 28 const int kMinimumClientHeight = 200; |
| 29 const int kMaximumClientWidth = 300; | 29 const int kMaximumClientWidth = 300; |
| 30 const int kMaximumClientHeight = 300; | 30 const int kMaximumClientHeight = 300; |
| 31 const int kPreferredClientWidth = 150; | 31 const int kPreferredClientWidth = 150; |
| 32 const int kPreferredClientHeight = 250; | 32 const int kPreferredClientHeight = 250; |
| 33 const int kExpectedBorderWidth = 22; | 33 |
| 34 const int kExpectedBorderHeight = 29; | 34 // The following do not take bubble border into consideration. |
|
karandeepb
2016/03/08 23:17:52
The constants kExpectedBorderHeight and kExpectedB
| |
| 35 const int kExpectedNonClientWidth = 12; | |
| 36 const int kExpectedNonClientHeight = 12; | |
| 35 | 37 |
| 36 class TestBubbleFrameViewWidgetDelegate : public WidgetDelegate { | 38 class TestBubbleFrameViewWidgetDelegate : public WidgetDelegate { |
| 37 public: | 39 public: |
| 38 TestBubbleFrameViewWidgetDelegate(Widget* widget) : widget_(widget) {} | 40 TestBubbleFrameViewWidgetDelegate(Widget* widget) : widget_(widget) {} |
| 39 | 41 |
| 40 ~TestBubbleFrameViewWidgetDelegate() override {} | 42 ~TestBubbleFrameViewWidgetDelegate() override {} |
| 41 | 43 |
| 42 // WidgetDelegate overrides: | 44 // WidgetDelegate overrides: |
| 43 Widget* GetWidget() override { return widget_; } | 45 Widget* GetWidget() override { return widget_; } |
| 44 const Widget* GetWidget() const override { return widget_; } | 46 const Widget* GetWidget() const override { return widget_; } |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 gfx::Size(500, 500), // |client_size| | 413 gfx::Size(500, 500), // |client_size| |
| 412 true); // |adjust_if_offscreen| | 414 true); // |adjust_if_offscreen| |
| 413 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow()); | 415 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow()); |
| 414 EXPECT_EQ(window_bounds.bottom(), 1000); | 416 EXPECT_EQ(window_bounds.bottom(), 1000); |
| 415 EXPECT_EQ(window_bounds.y() + | 417 EXPECT_EQ(window_bounds.y() + |
| 416 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); | 418 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); |
| 417 } | 419 } |
| 418 | 420 |
| 419 TEST_F(BubbleFrameViewTest, GetPreferredSize) { | 421 TEST_F(BubbleFrameViewTest, GetPreferredSize) { |
| 420 TestBubbleFrameView frame(this); | 422 TestBubbleFrameView frame(this); |
| 421 gfx::Size preferred_size = frame.GetPreferredSize(); | 423 |
|
tapted
2016/03/08 23:38:09
what about something like
gfx::Rect preferred_siz
karandeepb
2016/03/09 00:06:59
Done.
| |
| 424 gfx::Size client_size(kPreferredClientWidth, kPreferredClientHeight); | |
| 425 gfx::Insets border_insets = frame.bubble_border()->GetInsets(); | |
| 422 // Expect that a border has been added to the preferred size. | 426 // Expect that a border has been added to the preferred size. |
| 423 EXPECT_EQ(kPreferredClientWidth + kExpectedBorderWidth, | 427 gfx::Size expected_size( |
| 424 preferred_size.width()); | 428 client_size.width() + kExpectedNonClientWidth + border_insets.width(), |
| 425 EXPECT_EQ(kPreferredClientHeight + kExpectedBorderHeight, | 429 client_size.height() + kExpectedNonClientHeight + border_insets.height()); |
| 426 preferred_size.height()); | 430 EXPECT_EQ(expected_size, frame.GetPreferredSize()); |
| 427 } | 431 } |
| 428 | 432 |
| 429 TEST_F(BubbleFrameViewTest, GetMinimumSize) { | 433 TEST_F(BubbleFrameViewTest, GetMinimumSize) { |
| 430 TestBubbleFrameView frame(this); | 434 TestBubbleFrameView frame(this); |
| 431 gfx::Size minimum_size = frame.GetMinimumSize(); | 435 |
| 436 gfx::Size client_size(kMinimumClientWidth, kMinimumClientHeight); | |
| 437 gfx::Insets border_insets = frame.bubble_border()->GetInsets(); | |
| 432 // Expect that a border has been added to the minimum size. | 438 // Expect that a border has been added to the minimum size. |
| 433 EXPECT_EQ(kMinimumClientWidth + kExpectedBorderWidth, minimum_size.width()); | 439 gfx::Size expected_size( |
| 434 EXPECT_EQ(kMinimumClientHeight + kExpectedBorderHeight, | 440 client_size.width() + kExpectedNonClientWidth + border_insets.width(), |
| 435 minimum_size.height()); | 441 client_size.height() + kExpectedNonClientHeight + border_insets.height()); |
| 442 EXPECT_EQ(expected_size, frame.GetMinimumSize()); | |
| 436 } | 443 } |
| 437 | 444 |
| 438 TEST_F(BubbleFrameViewTest, GetMaximumSize) { | 445 TEST_F(BubbleFrameViewTest, GetMaximumSize) { |
| 439 TestBubbleFrameView frame(this); | 446 TestBubbleFrameView frame(this); |
| 440 gfx::Size maximum_size = frame.GetMaximumSize(); | 447 gfx::Size maximum_size = frame.GetMaximumSize(); |
| 441 #if defined(OS_WIN) | 448 #if defined(OS_WIN) |
| 442 // On Windows, GetMaximumSize causes problems with DWM, so it should just be 0 | 449 // On Windows, GetMaximumSize causes problems with DWM, so it should just be 0 |
| 443 // (unlimited). See http://crbug.com/506206. | 450 // (unlimited). See http://crbug.com/506206. |
| 444 EXPECT_EQ(0, maximum_size.width()); | 451 EXPECT_EQ(gfx::Size(), maximum_size); |
| 445 EXPECT_EQ(0, maximum_size.height()); | |
| 446 #else | 452 #else |
| 447 // Should ignore the contents view's maximum size and use the preferred size. | 453 // Should ignore the contents view's maximum size and use the preferred size. |
| 448 EXPECT_EQ(kPreferredClientWidth + kExpectedBorderWidth, maximum_size.width()); | 454 gfx::Size client_size(kPreferredClientWidth, kPreferredClientHeight); |
| 449 EXPECT_EQ(kPreferredClientHeight + kExpectedBorderHeight, | 455 gfx::Insets border_insets = frame.bubble_border()->GetInsets(); |
| 450 maximum_size.height()); | 456 gfx::Size expected_size( |
| 457 client_size.width() + kExpectedNonClientWidth + border_insets.width(), | |
| 458 client_size.height() + kExpectedNonClientHeight + border_insets.height()); | |
| 459 EXPECT_EQ(expected_size, maximum_size); | |
| 451 #endif | 460 #endif |
| 452 } | 461 } |
| 453 | 462 |
| 454 } // namespace views | 463 } // namespace views |
| OLD | NEW |