Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(970)

Unified Diff: ui/gfx/image/image_util_unittest.cc

Issue 1836483002: Fix up and rename VisibleMargins() in preparation for making use of it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resync Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/image/image_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_util_unittest.cc
diff --git a/ui/gfx/image/image_util_unittest.cc b/ui/gfx/image/image_util_unittest.cc
index 4816891cda183b294e1beb01f7807d1d68ac8161..2cde9c402b44062f0283f5fa5a2dd8e1da50b15c 100644
--- a/ui/gfx/image/image_util_unittest.cc
+++ b/ui/gfx/image/image_util_unittest.cc
@@ -26,73 +26,110 @@ TEST(ImageUtilTest, JPEGEncodeAndDecode) {
EXPECT_FALSE(decoded.IsEmpty());
}
-TEST(ImageUtilTest, TestVisibleMargins) {
- // Image with non-transparent piece should return margins at those
- // columns.
- SkBitmap bitmap1;
- bitmap1.allocN32Pixels(16, 16);
- bitmap1.eraseColor(SK_ColorTRANSPARENT);
- bitmap1.eraseArea(SkIRect::MakeLTRB(3, 3, 14, 14), SK_ColorYELLOW);
- gfx::ImageSkia img = gfx::ImageSkia::CreateFrom1xBitmap(bitmap1);
- int x = 0;
- int y = 0;
- gfx::VisibleMargins(img, &x, &y);
- EXPECT_EQ(3, x);
- EXPECT_EQ(13, y);
- EXPECT_EQ(16, img.width());
-
- // Full-width-transparent image should return margins in the center
- // of the image.
- SkBitmap bitmap2;
- bitmap2.allocN32Pixels(16, 16);
- bitmap2.eraseColor(SK_ColorTRANSPARENT);
- gfx::ImageSkia img_transparent = gfx::ImageSkia::CreateFrom1xBitmap(bitmap2);
- x = 0;
- y = 0;
- gfx::VisibleMargins(img_transparent, &x, &y);
- EXPECT_EQ(8, x);
- EXPECT_EQ(9, y);
- EXPECT_EQ(16, img_transparent.width());
-
- // Image with non-transparent piece that is skewed to one side should
- // return margins at those columns.
- SkBitmap bitmap3;
- bitmap3.allocN32Pixels(16, 16);
- bitmap3.eraseColor(SK_ColorTRANSPARENT);
- bitmap3.eraseArea(SkIRect::MakeLTRB(3, 3, 5, 5), SK_ColorYELLOW);
- gfx::ImageSkia img3 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap3);
- x = 0;
- y = 0;
- gfx::VisibleMargins(img3, &x, &y);
- EXPECT_EQ(3, x);
- EXPECT_EQ(4, y);
- EXPECT_EQ(16, img3.width());
-
- // Image with non-transparent piece that is at one edge should
- // return margins at those columns.
- SkBitmap bitmap4;
- bitmap4.allocN32Pixels(16, 16);
- bitmap4.eraseColor(SK_ColorTRANSPARENT);
- bitmap4.eraseArea(SkIRect::MakeLTRB(0, 3, 5, 5), SK_ColorYELLOW);
- gfx::ImageSkia img4 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap4);
- x = 0;
- y = 0;
- gfx::VisibleMargins(img4, &x, &y);
- EXPECT_EQ(0, x);
- EXPECT_EQ(4, y);
- EXPECT_EQ(16, img4.width());
-
- // Image with non-transparent piece that is at trailing edge should
- // return margins at those columns.
- SkBitmap bitmap5;
- bitmap5.allocN32Pixels(16, 16);
- bitmap5.eraseColor(SK_ColorTRANSPARENT);
- bitmap5.eraseArea(SkIRect::MakeLTRB(4, 3, 16, 16), SK_ColorYELLOW);
- gfx::ImageSkia img5 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap5);
- x = 0;
- y = 0;
- gfx::VisibleMargins(img5, &x, &y);
- EXPECT_EQ(4, x);
- EXPECT_EQ(15, y);
- EXPECT_EQ(16, img5.width());
+TEST(ImageUtilTest, GetVisibleMargins) {
+ int left, right;
+
+ // Fully transparent image.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 14);
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(8, left);
+ EXPECT_EQ(8, right);
+ }
+
+ // Fully non-transparent image.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 14);
+ bitmap.eraseColor(SK_ColorYELLOW);
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(0, left);
+ EXPECT_EQ(0, right);
+ }
+
+ // Image with non-transparent section in center.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 14);
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ bitmap.eraseArea(SkIRect::MakeLTRB(3, 2, 13, 13), SK_ColorYELLOW);
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(3, left);
+ EXPECT_EQ(3, right);
+ }
+
+ // Image with non-transparent section skewed to one side.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 14);
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ bitmap.eraseArea(SkIRect::MakeLTRB(3, 2, 5, 5), SK_ColorYELLOW);
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(3, left);
+ EXPECT_EQ(11, right);
+ }
+
+ // Image with non-transparent section at leading edge.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 14);
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ bitmap.eraseArea(SkIRect::MakeLTRB(0, 3, 5, 5), SK_ColorYELLOW);
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(0, left);
+ EXPECT_EQ(11, right);
+ }
+
+ // Image with non-transparent section at trailing edge.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 14);
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ bitmap.eraseArea(SkIRect::MakeLTRB(4, 3, 16, 13), SK_ColorYELLOW);
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(4, left);
+ EXPECT_EQ(0, right);
+ }
+
+ // Image with narrow non-transparent section.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 14);
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ bitmap.eraseArea(SkIRect::MakeLTRB(8, 3, 9, 5), SK_ColorYELLOW);
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(8, left);
+ EXPECT_EQ(7, right);
+ }
+
+ // Image with faint pixels.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 14);
+ bitmap.eraseColor(SkColorSetA(SK_ColorYELLOW, 0x02));
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(8, left);
+ EXPECT_EQ(8, right);
+ }
+
+ // Fully transparent image with odd width.
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(17, 14);
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ gfx::ImageSkia img(gfx::ImageSkia::CreateFrom1xBitmap(bitmap));
+ gfx::GetVisibleMargins(img, &left, &right);
+ EXPECT_EQ(9, left);
+ EXPECT_EQ(8, right);
+ }
}
« no previous file with comments | « ui/gfx/image/image_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698