Commit 12c25dec authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Fixed color API bug in ExtraInsetsBorder.

Fixed a bug in ExtraInsetsBorder where the ExtraInsetsBorder was
composing the original border but neglecting to set the color in
its own Border superclass.
This resulted in the border painting correctly but returning the
incorrect placeholder color when asked for its color through the
Border's API.
Added unit test to guard against regression.

Bug: None
Change-Id: I71613ed468384dc3780e2acb76a43351e96d3bac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2069498
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745246}
parent c3836b87
......@@ -168,7 +168,9 @@ class ExtraInsetsBorder : public Border {
ExtraInsetsBorder::ExtraInsetsBorder(std::unique_ptr<Border> border,
const gfx::Insets& insets)
: border_(std::move(border)), extra_insets_(insets) {}
: Border(border->color()),
border_(std::move(border)),
extra_insets_(insets) {}
void ExtraInsetsBorder::Paint(const View& view, gfx::Canvas* canvas) {
border_->Paint(view, canvas);
......
......@@ -230,7 +230,7 @@ TEST_F(BorderTest, RoundedRectBorder) {
}
TEST_F(BorderTest, EmptyBorder) {
const gfx::Insets kInsets(1, 2, 3, 4);
constexpr gfx::Insets kInsets(1, 2, 3, 4);
std::unique_ptr<Border> border(CreateEmptyBorder(
kInsets.top(), kInsets.left(), kInsets.bottom(), kInsets.right()));
......@@ -245,8 +245,8 @@ TEST_F(BorderTest, EmptyBorder) {
}
TEST_F(BorderTest, SolidSidedBorder) {
const SkColor kBorderColor = SK_ColorMAGENTA;
const gfx::Insets kInsets(1, 2, 3, 4);
constexpr SkColor kBorderColor = SK_ColorMAGENTA;
constexpr gfx::Insets kInsets(1, 2, 3, 4);
std::unique_ptr<Border> border(
CreateSolidSidedBorder(kInsets.top(), kInsets.left(), kInsets.bottom(),
......@@ -263,12 +263,12 @@ TEST_F(BorderTest, SolidSidedBorder) {
bounds.Inset(border->GetInsets());
ASSERT_EQ(1u, mock->draw_paint_calls().size());
EXPECT_EQ(kBorderColor, mock->draw_paint_calls()[0].getColor());
EXPECT_EQ(kBorderColor, mock->draw_paint_calls().front().getColor());
EXPECT_EQ(gfx::RectF(bounds), gfx::SkRectToRectF(mock->last_clip_bounds()));
}
TEST_F(BorderTest, BorderPainter) {
const gfx::Insets kInsets(1, 2, 3, 4);
constexpr gfx::Insets kInsets(1, 2, 3, 4);
std::unique_ptr<MockPainter> painter(new MockPainter());
MockPainter* painter_ptr = painter.get();
......@@ -284,4 +284,39 @@ TEST_F(BorderTest, BorderPainter) {
EXPECT_EQ(view_->size(), painter_ptr->given_size());
}
TEST_F(BorderTest, ExtraInsetsBorder) {
constexpr SkColor kBorderColor = SK_ColorMAGENTA;
constexpr int kOriginalInset = 3;
std::unique_ptr<Border> border =
CreateSolidBorder(kOriginalInset, kBorderColor);
constexpr gfx::Insets kOriginalInsets(kOriginalInset);
EXPECT_EQ(kOriginalInsets.size(), border->GetMinimumSize());
EXPECT_EQ(kOriginalInsets, border->GetInsets());
EXPECT_EQ(kBorderColor, border->color());
constexpr int kExtraInset = 2;
constexpr gfx::Insets kExtraInsets(kExtraInset);
std::unique_ptr<Border> extra_insets_border =
CreatePaddedBorder(std::move(border), kExtraInsets);
constexpr gfx::Insets kTotalInsets(kOriginalInset + kExtraInset);
EXPECT_EQ(kTotalInsets.size(), extra_insets_border->GetMinimumSize());
EXPECT_EQ(kTotalInsets, extra_insets_border->GetInsets());
EXPECT_EQ(kBorderColor, extra_insets_border->color());
extra_insets_border->Paint(*view_, canvas_.get());
std::unique_ptr<MockCanvas> mock = DrawIntoMockCanvas();
std::vector<MockCanvas::DrawRectCall> draw_rect_calls =
mock->draw_rect_calls();
gfx::Rect bounds = view_->GetLocalBounds();
// We only use the wrapped border's insets for painting the border. The extra
// insets of the ExtraInsetsBorder are applied within the wrapped border.
bounds.Inset(extra_insets_border->GetInsets() - gfx::Insets(kExtraInset));
ASSERT_EQ(1u, mock->draw_paint_calls().size());
EXPECT_EQ(kBorderColor, mock->draw_paint_calls().front().getColor());
EXPECT_EQ(gfx::RectF(bounds), gfx::SkRectToRectF(mock->last_clip_bounds()));
}
} // namespace views
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