Chromium Code Reviews| Index: ui/gfx/image/image_unittest.cc |
| diff --git a/ui/gfx/image/image_unittest.cc b/ui/gfx/image/image_unittest.cc |
| index 0cdc237fabb3c356077697b766f71facb7b98cb4..239bc9b91249ae0b3af26cd8146abdd3cd1cdb75 100644 |
| --- a/ui/gfx/image/image_unittest.cc |
| +++ b/ui/gfx/image/image_unittest.cc |
| @@ -93,6 +93,54 @@ 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)); |
| +} |
| + |
|
Robert Sesek
2012/07/31 14:07:17
nit: extra blank lines. Also, do you think it's po
cjhopman
2012/08/03 22:15:25
Done. Added tests for the failure cases also.
|
| + |
| TEST_F(ImageTest, SkiaToPlatform) { |
| gfx::Image image(gt::CreateBitmap(25, 25)); |
| const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |