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 TEST_F(ImageTest, PNGDecodeToSkiaFailure) { | |
144 std::vector<unsigned char> png(100, 0); | |
145 gfx::Image image(&png.front(), png.size()); | |
146 const SkBitmap* bitmap = image.ToSkBitmap(); | |
147 | |
148 SkAutoLockPixels auto_lock(*bitmap); | |
149 gt::CheckColor(bitmap->getColor(10, 10), true); | |
150 } | |
151 | |
152 TEST_F(ImageTest, PNGDecodeToPlatformFailure) { | |
153 std::vector<unsigned char> png(100, 0); | |
154 gfx::Image image(&png.front(), png.size()); | |
155 gt::CheckColor(gt::GetPlatformImageColor(gt::ToPlatformType(image)), true); | |
156 } | |
157 | |
158 TEST_F(ImageTest, SkiaToPlatform) { | 96 TEST_F(ImageTest, SkiaToPlatform) { |
159 gfx::Image image(gt::CreateBitmap(25, 25)); | 97 gfx::Image image(gt::CreateBitmap(25, 25)); |
160 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 98 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
161 | 99 |
162 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); | 100 EXPECT_TRUE(image.HasRepresentation(gfx::Image::kImageRepSkia)); |
163 if (!kUsesSkiaNatively) | 101 if (!kUsesSkiaNatively) |
164 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); | 102 EXPECT_FALSE(image.HasRepresentation(gt::GetPlatformRepresentationType())); |
165 | 103 |
166 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); | 104 EXPECT_TRUE(gt::IsPlatformImageValid(gt::ToPlatformType(image))); |
167 EXPECT_EQ(kRepCount, image.RepresentationCount()); | 105 EXPECT_EQ(kRepCount, image.RepresentationCount()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 ns_image = image.CopyNSImage(); | 189 ns_image = image.CopyNSImage(); |
252 } | 190 } |
253 | 191 |
254 EXPECT_TRUE(ns_image); | 192 EXPECT_TRUE(ns_image); |
255 base::mac::NSObjectRelease(ns_image); | 193 base::mac::NSObjectRelease(ns_image); |
256 } | 194 } |
257 #endif | 195 #endif |
258 | 196 |
259 TEST_F(ImageTest, CheckSkiaColor) { | 197 TEST_F(ImageTest, CheckSkiaColor) { |
260 gfx::Image image(gt::CreatePlatformImage()); | 198 gfx::Image image(gt::CreatePlatformImage()); |
| 199 const SkBitmap* bitmap = image.ToSkBitmap(); |
261 | 200 |
262 const SkBitmap* bitmap = image.ToSkBitmap(); | |
263 SkAutoLockPixels auto_lock(*bitmap); | 201 SkAutoLockPixels auto_lock(*bitmap); |
264 gt::CheckColor(bitmap->getColor(10, 10), false); | 202 uint32_t* pixel = bitmap->getAddr32(10, 10); |
| 203 EXPECT_EQ(SK_ColorRED, *pixel); |
265 } | 204 } |
266 | 205 |
267 TEST_F(ImageTest, SwapRepresentations) { | 206 TEST_F(ImageTest, SwapRepresentations) { |
268 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; | 207 const size_t kRepCount = kUsesSkiaNatively ? 1U : 2U; |
269 | 208 |
270 gfx::Image image1(gt::CreateBitmap(25, 25)); | 209 gfx::Image image1(gt::CreateBitmap(25, 25)); |
271 const SkBitmap* bitmap1 = image1.ToSkBitmap(); | 210 const SkBitmap* bitmap1 = image1.ToSkBitmap(); |
272 EXPECT_EQ(1U, image1.RepresentationCount()); | 211 EXPECT_EQ(1U, image1.RepresentationCount()); |
273 | 212 |
274 gfx::Image image2(gt::CreatePlatformImage()); | 213 gfx::Image image2(gt::CreatePlatformImage()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); | 315 image = gfx::Image(gfx::ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); |
377 } | 316 } |
378 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); | 317 EXPECT_TRUE(!image.ToSkBitmap()->isNull()); |
379 } | 318 } |
380 | 319 |
381 // Integration tests with UI toolkit frameworks require linking against the | 320 // Integration tests with UI toolkit frameworks require linking against the |
382 // Views library and cannot be here (ui_unittests doesn't include it). They | 321 // Views library and cannot be here (ui_unittests doesn't include it). They |
383 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. | 322 // instead live in /chrome/browser/ui/tests/ui_gfx_image_unittest.cc. |
384 | 323 |
385 } // namespace | 324 } // namespace |
OLD | NEW |