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

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

Issue 10830207: Add support for PNG representation in gfx::Image (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Missed small change from previous CL. Created 8 years, 4 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_mac.mm ('k') | ui/gfx/image/image_unittest_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_unittest.cc
diff --git a/ui/gfx/image/image_unittest.cc b/ui/gfx/image/image_unittest.cc
index c0ee6c96af13b1c9371c063777116263d6bf1d66..73e98363256ee8e8c4c80461ee17e2908dd7250d 100644
--- a/ui/gfx/image/image_unittest.cc
+++ b/ui/gfx/image/image_unittest.cc
@@ -93,6 +93,68 @@ TEST_F(ImageTest, SkiaToSkiaRef) {
EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType()));
}
+TEST_F(ImageTest, SkiaToPNGEncodeAndDecode) {
+ gfx::Image image(gt::CreateBitmap(25, 25));
+ const std::vector<unsigned char>* png = image.ToImagePNG();
+ EXPECT_TRUE(png);
+ EXPECT_FALSE(png->empty());
+ EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
+
+ gfx::Image from_png(&png->front(), png->size());
+ EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
+ EXPECT_TRUE(gt::IsEqual(from_png, image));
+}
+
+TEST_F(ImageTest, PlatformToPNGEncodeAndDecode) {
+ gfx::Image image(gt::CreatePlatformImage());
+ const std::vector<unsigned char>* png = image.ToImagePNG();
+ EXPECT_TRUE(png);
+ EXPECT_FALSE(png->empty());
+ EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
+
+ gfx::Image from_png(&png->front(), png->size());
+ EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG));
+ EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image)));
+}
+
+// The platform types use the platform provided encoding/decoding of PNGs. Make
+// sure these work with the Skia Encode/Decode.
+TEST_F(ImageTest, PNGEncodeFromSkiaDecodeToPlatform) {
+ // Force the conversion sequence skia to png to platform_type.
+ gfx::Image from_skia(gt::CreateBitmap(25, 25));
+ const std::vector<unsigned char>* png = from_skia.ToImagePNG();
+ gfx::Image from_png(&png->front(), png->size());
+ gfx::Image from_platform(gt::CopyPlatformType(from_png));
+
+ EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(from_platform)));
+ EXPECT_TRUE(gt::IsEqual(from_skia, from_platform));
+}
+
+TEST_F(ImageTest, PNGEncodeFromPlatformDecodeToSkia) {
+ // Force the conversion sequence platform_type to png to skia.
+ gfx::Image from_platform(gt::CreatePlatformImage());
+ const std::vector<unsigned char>* png = from_platform.ToImagePNG();
+ gfx::Image from_png(&png->front(), png->size());
+ gfx::Image from_skia(*from_png.ToImageSkia());
+
+ EXPECT_TRUE(gt::IsEqual(from_skia, from_platform));
+}
+
+TEST_F(ImageTest, PNGDecodeToSkiaFailure) {
+ std::vector<unsigned char> png(100, 0);
+ gfx::Image image(&png.front(), png.size());
+ const SkBitmap* bitmap = image.ToSkBitmap();
+
+ SkAutoLockPixels auto_lock(*bitmap);
+ gt::CheckColor(bitmap->getColor(10, 10), true);
+}
+
+TEST_F(ImageTest, PNGDecodeToPlatformFailure) {
+ std::vector<unsigned char> png(100, 0);
+ gfx::Image image(&png.front(), png.size());
+ gt::CheckColor(gt::GetPlatformImageColor(gt::ToPlatformType(image)), true);
+}
+
TEST_F(ImageTest, SkiaToPlatform) {
gfx::Image image(gt::CreateBitmap(25, 25));
const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U;
@@ -196,11 +258,10 @@ TEST_F(ImageTest, SkiaToCocoaCopy) {
TEST_F(ImageTest, CheckSkiaColor) {
gfx::Image image(gt::CreatePlatformImage());
- const SkBitmap* bitmap = image.ToSkBitmap();
+ const SkBitmap* bitmap = image.ToSkBitmap();
SkAutoLockPixels auto_lock(*bitmap);
- uint32_t* pixel = bitmap->getAddr32(10, 10);
- EXPECT_EQ(SK_ColorRED, *pixel);
+ gt::CheckColor(bitmap->getColor(10, 10), false);
}
TEST_F(ImageTest, SwapRepresentations) {
« no previous file with comments | « ui/gfx/image/image_mac.mm ('k') | ui/gfx/image/image_unittest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698