Commit ef6fd66e authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Simplify BubbleBorderTest.GetBoundsOriginTest

Bubble widgets no longer have a visible arrow, this simplifies
the bounds layout calculation.
This CL removes redundant constants that are either 0 or equal
to other constants in BubbleBorderTest.GetBoundsOriginTest.

Bug: 877032
Change-Id: Icb886704647f926acbf29c23df0695ea36cd9b5b
Reviewed-on: https://chromium-review.googlesource.com/1195244Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587797}
parent 86d4f131
...@@ -303,42 +303,21 @@ TEST_F(BubbleBorderTest, GetBoundsOriginTest) { ...@@ -303,42 +303,21 @@ TEST_F(BubbleBorderTest, GetBoundsOriginTest) {
const gfx::Insets kInsets = border.GetInsets(); const gfx::Insets kInsets = border.GetInsets();
border.set_arrow(BubbleBorder::TOP_LEFT); border.set_arrow(BubbleBorder::TOP_LEFT);
const gfx::Size kTotalSizeWithHorizArrow = const gfx::Size kTotalSize = border.GetSizeForContentsSize(kContentSize);
border.GetSizeForContentsSize(kContentSize);
border.set_arrow(BubbleBorder::RIGHT_BOTTOM); border.set_arrow(BubbleBorder::RIGHT_BOTTOM);
const gfx::Size kTotalSizeWithVertArrow = EXPECT_EQ(kTotalSize, border.GetSizeForContentsSize(kContentSize));
border.GetSizeForContentsSize(kContentSize);
border.set_arrow(BubbleBorder::NONE); border.set_arrow(BubbleBorder::NONE);
const gfx::Size kTotalSizeWithNoArrow = EXPECT_EQ(kTotalSize, border.GetSizeForContentsSize(kContentSize));
border.GetSizeForContentsSize(kContentSize);
const int kArrowOffsetForHorizCenter = kTotalSizeWithHorizArrow.width() / 2;
const int kArrowOffsetForVertCenter = kTotalSizeWithVertArrow.height() / 2;
const int kStrokeWidth = const int kStrokeWidth =
shadow == BubbleBorder::NO_ASSETS ? 0 : BubbleBorder::kStroke; shadow == BubbleBorder::NO_ASSETS ? 0 : BubbleBorder::kStroke;
const int kArrowShift = 0;
const int kHeightDifference =
kTotalSizeWithHorizArrow.height() - kTotalSizeWithNoArrow.height();
const int kWidthDifference =
kTotalSizeWithVertArrow.width() - kTotalSizeWithNoArrow.width();
EXPECT_EQ(kHeightDifference, kWidthDifference);
// The arrow only makes a difference in height if it is longer than the
// shadow.
const int kExpectedHeightDifference = 0;
EXPECT_EQ(kExpectedHeightDifference, kHeightDifference)
<< "Size with arrow: " << kTotalSizeWithHorizArrow.ToString()
<< " vs. size without arrow: " << kTotalSizeWithNoArrow.ToString();
const int kTopHorizArrowY = kAnchor.bottom() + kStrokeWidth - kInsets.top(); const int kTopHorizArrowY = kAnchor.bottom() + kStrokeWidth - kInsets.top();
const int kBottomHorizArrowY = const int kBottomHorizArrowY = kAnchor.y() - kTotalSize.height();
kAnchor.y() - kTotalSizeWithHorizArrow.height(); const int kLeftVertArrowX = kAnchor.x() + kAnchor.width();
const int kLeftVertArrowX = kAnchor.x() + kAnchor.width() + kArrowShift; const int kRightVertArrowX = kAnchor.x() - kTotalSize.width();
const int kRightVertArrowX = kAnchor.x() - kTotalSizeWithHorizArrow.width();
struct TestCase { struct TestCase {
BubbleBorder::Arrow arrow; BubbleBorder::Arrow arrow;
...@@ -351,50 +330,38 @@ TEST_F(BubbleBorderTest, GetBoundsOriginTest) { ...@@ -351,50 +330,38 @@ TEST_F(BubbleBorderTest, GetBoundsOriginTest) {
{BubbleBorder::TOP_LEFT, kAnchor.x() + kStrokeWidth - kInsets.left(), {BubbleBorder::TOP_LEFT, kAnchor.x() + kStrokeWidth - kInsets.left(),
kTopHorizArrowY}, kTopHorizArrowY},
{BubbleBorder::TOP_CENTER, {BubbleBorder::TOP_CENTER,
kAnchor.CenterPoint().x() - kArrowOffsetForHorizCenter, kAnchor.CenterPoint().x() - (kTotalSize.width() / 2), kTopHorizArrowY},
kTopHorizArrowY},
{BubbleBorder::BOTTOM_RIGHT, {BubbleBorder::BOTTOM_RIGHT,
kAnchor.x() + kAnchor.width() - kTotalSizeWithHorizArrow.width() - kAnchor.x() + kAnchor.width() - kTotalSize.width() - kStrokeWidth,
kStrokeWidth,
kBottomHorizArrowY}, kBottomHorizArrowY},
// Vertical arrow tests. // Vertical arrow tests.
{BubbleBorder::LEFT_TOP, kLeftVertArrowX, kAnchor.y() + kStrokeWidth}, {BubbleBorder::LEFT_TOP, kLeftVertArrowX, kAnchor.y() + kStrokeWidth},
{BubbleBorder::LEFT_CENTER, {BubbleBorder::LEFT_CENTER,
kLeftVertArrowX - (kInsets.right() - kStrokeWidth), kLeftVertArrowX - (kInsets.right() - kStrokeWidth),
kAnchor.CenterPoint().y() - kArrowOffsetForVertCenter + kAnchor.CenterPoint().y() - (kTotalSize.height() / 2) +
(2 * kStrokeWidth)}, (2 * kStrokeWidth)},
{BubbleBorder::RIGHT_BOTTOM, kRightVertArrowX, {BubbleBorder::RIGHT_BOTTOM, kRightVertArrowX,
kAnchor.y() + kAnchor.height() - kTotalSizeWithVertArrow.height() - kAnchor.y() + kAnchor.height() - kTotalSize.height() - kStrokeWidth},
kStrokeWidth},
// No arrow tests. // No arrow tests.
{BubbleBorder::NONE, {BubbleBorder::NONE,
kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, kAnchor.x() + (kAnchor.width() - kTotalSize.width()) / 2,
kAnchor.y() + kAnchor.height()}, kAnchor.y() + kAnchor.height()},
{BubbleBorder::FLOAT, {BubbleBorder::FLOAT,
kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, kAnchor.x() + (kAnchor.width() - kTotalSize.width()) / 2,
kAnchor.y() + (kAnchor.height() - kTotalSizeWithNoArrow.height()) / 2}, kAnchor.y() + (kAnchor.height() - kTotalSize.height()) / 2},
}; };
for (size_t i = 0; i < arraysize(cases); ++i) { for (size_t i = 0; i < arraysize(cases); ++i) {
SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d", static_cast<int>(i), SCOPED_TRACE(base::StringPrintf("shadow=%d i=%d arrow=%d",
cases[i].arrow)); static_cast<int>(shadow),
static_cast<int>(i), cases[i].arrow));
const BubbleBorder::Arrow arrow = cases[i].arrow; const BubbleBorder::Arrow arrow = cases[i].arrow;
border.set_arrow(arrow); border.set_arrow(arrow);
gfx::Point origin = border.GetBounds(kAnchor, kContentSize).origin(); gfx::Point origin = border.GetBounds(kAnchor, kContentSize).origin();
int expected_x = cases[i].expected_x; EXPECT_EQ(cases[i].expected_x, origin.x());
int expected_y = cases[i].expected_y; EXPECT_EQ(cases[i].expected_y, origin.y());
if (border.is_arrow_on_horizontal(arrow) &&
!BubbleBorder::is_arrow_on_top(arrow)) {
expected_y += kHeightDifference;
} else if (BubbleBorder::has_arrow(arrow) &&
!border.is_arrow_on_horizontal(arrow) &&
!BubbleBorder::is_arrow_on_left(arrow)) {
expected_x += kWidthDifference;
}
EXPECT_EQ(expected_x, origin.x());
EXPECT_EQ(expected_y, origin.y());
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment