Chromium Code Reviews| Index: cc/layers/nine_patch_layer_impl_unittest.cc |
| diff --git a/cc/layers/nine_patch_layer_impl_unittest.cc b/cc/layers/nine_patch_layer_impl_unittest.cc |
| index d1396dbadfe09ea8b846f885e7c293295483f972..ac0ce53d36d42ddd2f8813f99c33da636284ce3a 100644 |
| --- a/cc/layers/nine_patch_layer_impl_unittest.cc |
| +++ b/cc/layers/nine_patch_layer_impl_unittest.cc |
| @@ -31,6 +31,30 @@ gfx::Rect ToRoundedIntRect(const gfx::RectF& rect_f) { |
| gfx::ToRoundedInt(rect_f.height())); |
| } |
| +bool ShouldUseOcclusion(const gfx::Size& bitmap_size, |
|
aelias_OOO_until_Jul13
2016/05/05 04:17:57
It's a bad practice to copy-paste production code
llandwerlin-old
2016/05/06 16:26:48
Done.
|
| + const gfx::Rect& aperture_rect, |
| + const gfx::Size& layer_size, |
| + const gfx::Rect& border, |
| + const gfx::Rect& occlusion, |
| + bool fill_center) { |
| + if (occlusion.IsEmpty()) |
| + return false; |
| + |
| + if (fill_center) |
| + return false; |
| + |
| + if (border.x() == 0 || border.y() == 0 || |
| + (border.width() - border.x()) == 0 || (border.height() - border.y()) == 0) |
| + return false; |
| + |
| + if (occlusion.x() == 0 || occlusion.y() == 0 || |
| + occlusion.right() == layer_size.width() || |
| + occlusion.bottom() == layer_size.height()) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, |
| const gfx::Rect& aperture_rect, |
| const gfx::Size& layer_size, |
| @@ -43,14 +67,31 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size, |
| gfx::Rect expected_layer_remaining; |
| gfx::Rect expected_tex_remaining; |
| - if (!occlusion.IsEmpty()) { |
| - expected_layer_remaining = occlusion; |
| + if (ShouldUseOcclusion(bitmap_size, aperture_rect, layer_size, border, |
| + occlusion, fill_center)) { |
| + expected_layer_remaining.SetRect( |
|
aelias_OOO_until_Jul13
2016/05/05 04:17:57
All this is too much logic for a test, this makes
llandwerlin-old
2016/05/06 16:26:48
Done.
|
| + std::min(border.x(), occlusion.x()), |
| + std::min(border.y(), occlusion.y()), |
| + std::max(layer_size.width() - border.width(), occlusion.width()), |
| + std::max(layer_size.height() - border.height(), occlusion.height())); |
| + float ratio_left = aperture_rect.x() / border.x(), |
| + ratio_top = aperture_rect.y() / border.y(), |
| + ratio_right = (bitmap_size.width() - aperture_rect.right()) / |
| + (border.width() - border.x()), |
| + ratio_bottom = (bitmap_size.height() - aperture_rect.bottom()) / |
| + (border.height() - border.y()); |
| + int image_remaining_left = expected_layer_remaining.x() * ratio_left, |
| + image_remaining_top = expected_layer_remaining.y() * ratio_top, |
| + image_remaining_right = |
| + (layer_size.width() - expected_layer_remaining.right()) * |
| + ratio_right, |
| + image_remaining_bottom = |
| + (layer_size.height() - expected_layer_remaining.bottom()) * |
| + ratio_bottom; |
| expected_tex_remaining.SetRect( |
| - occlusion.x(), occlusion.y(), |
| - (bitmap_size.width() - occlusion.x()) - |
| - (layer_size.width() - occlusion.right()), |
| - (bitmap_size.height() - occlusion.y()) - |
| - (layer_size.height() - occlusion.bottom())); |
| + image_remaining_left, image_remaining_top, |
| + bitmap_size.width() - image_remaining_right - image_remaining_left, |
| + bitmap_size.height() - image_remaining_bottom - image_remaining_top); |
| } else { |
| expected_layer_remaining.SetRect(border.x(), border.y(), |
| layer_size.width() - border.width(), |
| @@ -159,15 +200,36 @@ TEST(NinePatchLayerImplTest, VerifyDrawQuads) { |
| } |
| TEST(NinePatchLayerImplTest, VerifyDrawQuadsWithOcclusion) { |
| - // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30. |
| + // Input is a 100x100 bitmap with a 40x40 aperture at x=30, y=30. |
| // The bounds of the layer are set to 400x400. |
| gfx::Size bitmap_size(100, 100); |
| gfx::Rect aperture_rect(30, 30, 40, 40); |
| gfx::Size layer_size(400, 400); |
| gfx::Rect occlusion(20, 20, 360, 360); |
| + gfx::Rect border(30, 30, 60, 60); |
| bool fill_center = false; |
| size_t expected_quad_size = 12; |
| - NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, gfx::Rect(), |
| + NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
| + occlusion, fill_center, expected_quad_size); |
| + |
| + bitmap_size = gfx::Size(100, 100); |
| + aperture_rect = gfx::Rect(0, 0, 100, 100); |
| + layer_size = gfx::Size(400, 400); |
| + occlusion = gfx::Rect(20, 20, 360, 360); |
| + border = gfx::Rect(0, 0, 0, 0); |
| + fill_center = false; |
| + expected_quad_size = 0; |
| + NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
| + occlusion, fill_center, expected_quad_size); |
| + |
| + bitmap_size = gfx::Size(100, 100); |
| + aperture_rect = gfx::Rect(20, 30, 60, 40); |
| + layer_size = gfx::Size(400, 400); |
| + occlusion = gfx::Rect(10, 10, 380, 380); |
| + border = gfx::Rect(20, 30, 360, 340); |
| + fill_center = false; |
| + expected_quad_size = 12; |
| + NinePatchLayerLayoutTest(bitmap_size, aperture_rect, layer_size, border, |
| occlusion, fill_center, expected_quad_size); |
| } |