OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "ui/gfx/image/image.h" | 6 #include "ui/gfx/image/image.h" |
7 #include "ui/gfx/image/image_skia.h" | 7 #include "ui/gfx/image/image_skia.h" |
8 #include "ui/gfx/image/image_unittest_util.h" | 8 #include "ui/gfx/image/image_unittest_util.h" |
9 | 9 |
10 #if defined(TOOLKIT_GTK) | 10 #if defined(TOOLKIT_GTK) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 const SkBitmap* bitmap1 = image.ToSkBitmap(); | 87 const SkBitmap* bitmap1 = image.ToSkBitmap(); |
88 EXPECT_FALSE(bitmap1->isNull()); | 88 EXPECT_FALSE(bitmap1->isNull()); |
89 EXPECT_EQ(1U, image.RepresentationCount()); | 89 EXPECT_EQ(1U, image.RepresentationCount()); |
90 | 90 |
91 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 91 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
92 if (!kUsesSkiaNatively) | 92 if (!kUsesSkiaNatively) |
93 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 93 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
94 } | 94 } |
95 | 95 |
| 96 TEST_F(ImageTest, SkiaToPNGEncodeAndDecode) { |
| 97 gfx::Image image(gt::CreateBitmap(25, 25)); |
| 98 const std::vector<unsigned char>* png = image.ToImagePNG(); |
| 99 EXPECT_TRUE(png); |
| 100 EXPECT_FALSE(png->empty()); |
| 101 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG)); |
| 102 |
| 103 gfx::Image from_png(&png->front(), png->size()); |
| 104 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG)); |
| 105 EXPECT_TRUE(gt::IsEqual(from_png, image)); |
| 106 } |
| 107 |
| 108 TEST_F(ImageTest, PlatformToPNGEncodeAndDecode) { |
| 109 gfx::Image image(gt::CreatePlatformImage()); |
| 110 const std::vector<unsigned char>* png = image.ToImagePNG(); |
| 111 EXPECT_TRUE(png); |
| 112 EXPECT_FALSE(png->empty()); |
| 113 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG)); |
| 114 |
| 115 gfx::Image from_png(&png->front(), png->size()); |
| 116 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepPNG)); |
| 117 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); |
| 118 } |
| 119 |
| 120 // The platform types use the platform provided encoding/decoding of PNGs. Make |
| 121 // sure these work with the Skia Encode/Decode. |
| 122 TEST_F(ImageTest, PNGEncodeFromSkiaDecodeToPlatform) { |
| 123 // Force the conversion sequence skia to png to platform_type. |
| 124 gfx::Image from_skia(gt::CreateBitmap(25, 25)); |
| 125 const std::vector<unsigned char>* png = from_skia.ToImagePNG(); |
| 126 gfx::Image from_png(&png->front(), png->size()); |
| 127 gfx::Image from_platform(gt::CopyPlatformType(from_png)); |
| 128 |
| 129 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(from_platform))); |
| 130 EXPECT_TRUE(gt::IsEqual(from_skia, from_platform)); |
| 131 } |
| 132 |
| 133 TEST_F(ImageTest, PNGEncodeFromPlatformDecodeToSkia) { |
| 134 // Force the conversion sequence platform_type to png to skia. |
| 135 gfx::Image from_platform(gt::CreatePlatformImage()); |
| 136 const std::vector<unsigned char>* png = from_platform.ToImagePNG(); |
| 137 gfx::Image from_png(&png->front(), png->size()); |
| 138 gfx::Image from_skia(*from_png.ToImageSkia()); |
| 139 |
| 140 EXPECT_TRUE(gt::IsEqual(from_skia, from_platform)); |
| 141 } |
| 142 |
| 143 |
96 TEST_F(ImageTest, SkiaToPlatform) { | 144 TEST_F(ImageTest, SkiaToPlatform) { |
97 gfx::Image image(gt::CreateBitmap(25, 25)); | 145 gfx::Image image(gt::CreateBitmap(25, 25)); |
98 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 146 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
99 | 147 |
100 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 148 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
101 if (!kUsesSkiaNatively) | 149 if (!kUsesSkiaNatively) |
102 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 150 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
103 | 151 |
104 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); | 152 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); |
105 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 153 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); | 363 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); |
316 } | 364 } |
317 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); | 365 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); |
318 } | 366 } |
319 | 367 |
320 // Integration tests with UI toolkit frameworks require linking against the | 368 // Integration tests with UI toolkit frameworks require linking against the |
321 // Views library and cannot be here (gfx_unittests doesn't include it). They | 369 // Views library and cannot be here (gfx_unittests doesn't include it). They |
322 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 370 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
323 | 371 |
324 } // namespace | 372 } // namespace |
OLD | NEW |