OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 void SetUp() override { | 136 void SetUp() override { |
137 m_imageObserver = new FakeImageObserver; | 137 m_imageObserver = new FakeImageObserver; |
138 m_image = BitmapImage::create(m_imageObserver.get()); | 138 m_image = BitmapImage::create(m_imageObserver.get()); |
139 } | 139 } |
140 | 140 |
141 Persistent<FakeImageObserver> m_imageObserver; | 141 Persistent<FakeImageObserver> m_imageObserver; |
142 RefPtr<BitmapImage> m_image; | 142 RefPtr<BitmapImage> m_image; |
143 }; | 143 }; |
144 | 144 |
145 TEST_F(BitmapImageTest, destroyDecodedData) { | 145 TEST_F(BitmapImageTest, destroyDecodedData) { |
146 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); | 146 loadImage("/LayoutTests/images/resources/animated-10color.gif"); |
147 size_t totalSize = decodedSize(); | 147 size_t totalSize = decodedSize(); |
148 EXPECT_GT(totalSize, 0u); | 148 EXPECT_GT(totalSize, 0u); |
149 destroyDecodedData(); | 149 destroyDecodedData(); |
150 EXPECT_EQ(-static_cast<int>(totalSize), lastDecodedSizeChange()); | 150 EXPECT_EQ(-static_cast<int>(totalSize), lastDecodedSizeChange()); |
151 EXPECT_EQ(0u, decodedSize()); | 151 EXPECT_EQ(0u, decodedSize()); |
152 } | 152 } |
153 | 153 |
154 TEST_F(BitmapImageTest, maybeAnimated) { | 154 TEST_F(BitmapImageTest, maybeAnimated) { |
155 loadImage("/LayoutTests/fast/images/resources/gif-loop-count.gif"); | 155 loadImage("/LayoutTests/images/resources/gif-loop-count.gif"); |
156 for (size_t i = 0; i < frameCount(); ++i) { | 156 for (size_t i = 0; i < frameCount(); ++i) { |
157 EXPECT_TRUE(m_image->maybeAnimated()); | 157 EXPECT_TRUE(m_image->maybeAnimated()); |
158 advanceAnimation(); | 158 advanceAnimation(); |
159 } | 159 } |
160 EXPECT_FALSE(m_image->maybeAnimated()); | 160 EXPECT_FALSE(m_image->maybeAnimated()); |
161 } | 161 } |
162 | 162 |
163 TEST_F(BitmapImageTest, animationRepetitions) { | 163 TEST_F(BitmapImageTest, animationRepetitions) { |
164 loadImage("/LayoutTests/fast/images/resources/full2loop.gif"); | 164 loadImage("/LayoutTests/images/resources/full2loop.gif"); |
165 int expectedRepetitionCount = 2; | 165 int expectedRepetitionCount = 2; |
166 EXPECT_EQ(expectedRepetitionCount, repetitionCount()); | 166 EXPECT_EQ(expectedRepetitionCount, repetitionCount()); |
167 | 167 |
168 // We actually loop once more than stored repetition count. | 168 // We actually loop once more than stored repetition count. |
169 for (int repeat = 0; repeat < expectedRepetitionCount + 1; ++repeat) { | 169 for (int repeat = 0; repeat < expectedRepetitionCount + 1; ++repeat) { |
170 for (size_t i = 0; i < frameCount(); ++i) { | 170 for (size_t i = 0; i < frameCount(); ++i) { |
171 EXPECT_FALSE(animationFinished()); | 171 EXPECT_FALSE(animationFinished()); |
172 advanceAnimation(); | 172 advanceAnimation(); |
173 } | 173 } |
174 } | 174 } |
175 EXPECT_TRUE(animationFinished()); | 175 EXPECT_TRUE(animationFinished()); |
176 } | 176 } |
177 | 177 |
178 TEST_F(BitmapImageTest, isAllDataReceived) { | 178 TEST_F(BitmapImageTest, isAllDataReceived) { |
179 RefPtr<SharedBuffer> imageData = | 179 RefPtr<SharedBuffer> imageData = |
180 readFile("/LayoutTests/fast/images/resources/green.jpg"); | 180 readFile("/LayoutTests/images/resources/green.jpg"); |
181 ASSERT_TRUE(imageData.get()); | 181 ASSERT_TRUE(imageData.get()); |
182 | 182 |
183 RefPtr<BitmapImage> image = BitmapImage::create(); | 183 RefPtr<BitmapImage> image = BitmapImage::create(); |
184 EXPECT_FALSE(image->isAllDataReceived()); | 184 EXPECT_FALSE(image->isAllDataReceived()); |
185 | 185 |
186 image->setData(imageData, false); | 186 image->setData(imageData, false); |
187 EXPECT_FALSE(image->isAllDataReceived()); | 187 EXPECT_FALSE(image->isAllDataReceived()); |
188 | 188 |
189 image->setData(imageData, true); | 189 image->setData(imageData, true); |
190 EXPECT_TRUE(image->isAllDataReceived()); | 190 EXPECT_TRUE(image->isAllDataReceived()); |
191 | 191 |
192 image->setData(SharedBuffer::create("data", sizeof("data")), false); | 192 image->setData(SharedBuffer::create("data", sizeof("data")), false); |
193 EXPECT_FALSE(image->isAllDataReceived()); | 193 EXPECT_FALSE(image->isAllDataReceived()); |
194 | 194 |
195 image->setData(imageData, true); | 195 image->setData(imageData, true); |
196 EXPECT_TRUE(image->isAllDataReceived()); | 196 EXPECT_TRUE(image->isAllDataReceived()); |
197 } | 197 } |
198 | 198 |
199 TEST_F(BitmapImageTest, noColorProfile) { | 199 TEST_F(BitmapImageTest, noColorProfile) { |
200 loadImage("/LayoutTests/fast/images/resources/green.jpg"); | 200 loadImage("/LayoutTests/images/resources/green.jpg"); |
201 EXPECT_EQ(1u, decodedFramesCount()); | 201 EXPECT_EQ(1u, decodedFramesCount()); |
202 EXPECT_EQ(1024u, decodedSize()); | 202 EXPECT_EQ(1024u, decodedSize()); |
203 EXPECT_FALSE(m_image->hasColorProfile()); | 203 EXPECT_FALSE(m_image->hasColorProfile()); |
204 } | 204 } |
205 | 205 |
206 TEST_F(BitmapImageTest, jpegHasColorProfile) { | 206 TEST_F(BitmapImageTest, jpegHasColorProfile) { |
207 loadImage("/LayoutTests/fast/images/resources/icc-v2-gbr.jpg"); | 207 loadImage("/LayoutTests/images/resources/icc-v2-gbr.jpg"); |
208 EXPECT_EQ(1u, decodedFramesCount()); | 208 EXPECT_EQ(1u, decodedFramesCount()); |
209 EXPECT_EQ(227700u, decodedSize()); | 209 EXPECT_EQ(227700u, decodedSize()); |
210 EXPECT_TRUE(m_image->hasColorProfile()); | 210 EXPECT_TRUE(m_image->hasColorProfile()); |
211 } | 211 } |
212 | 212 |
213 TEST_F(BitmapImageTest, pngHasColorProfile) { | 213 TEST_F(BitmapImageTest, pngHasColorProfile) { |
214 loadImage( | 214 loadImage( |
215 "/LayoutTests/fast/images/resources/" | 215 "/LayoutTests/images/resources/" |
216 "palatted-color-png-gamma-one-color-profile.png"); | 216 "palatted-color-png-gamma-one-color-profile.png"); |
217 EXPECT_EQ(1u, decodedFramesCount()); | 217 EXPECT_EQ(1u, decodedFramesCount()); |
218 EXPECT_EQ(65536u, decodedSize()); | 218 EXPECT_EQ(65536u, decodedSize()); |
219 EXPECT_TRUE(m_image->hasColorProfile()); | 219 EXPECT_TRUE(m_image->hasColorProfile()); |
220 } | 220 } |
221 | 221 |
222 TEST_F(BitmapImageTest, webpHasColorProfile) { | 222 TEST_F(BitmapImageTest, webpHasColorProfile) { |
223 loadImage("/LayoutTests/fast/images/resources/webp-color-profile-lossy.webp"); | 223 loadImage("/LayoutTests/images/resources/webp-color-profile-lossy.webp"); |
224 EXPECT_EQ(1u, decodedFramesCount()); | 224 EXPECT_EQ(1u, decodedFramesCount()); |
225 EXPECT_EQ(2560000u, decodedSize()); | 225 EXPECT_EQ(2560000u, decodedSize()); |
226 EXPECT_TRUE(m_image->hasColorProfile()); | 226 EXPECT_TRUE(m_image->hasColorProfile()); |
227 } | 227 } |
228 | 228 |
229 TEST_F(BitmapImageTest, icoHasWrongFrameDimensions) { | 229 TEST_F(BitmapImageTest, icoHasWrongFrameDimensions) { |
230 loadImage("/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico"); | 230 loadImage("/LayoutTests/images/resources/wrong-frame-dimensions.ico"); |
231 // This call would cause crash without fix for 408026 | 231 // This call would cause crash without fix for 408026 |
232 imageForDefaultFrame(); | 232 imageForDefaultFrame(); |
233 } | 233 } |
234 | 234 |
235 TEST_F(BitmapImageTest, correctDecodedDataSize) { | 235 TEST_F(BitmapImageTest, correctDecodedDataSize) { |
236 // Requesting any one frame shouldn't result in decoding any other frames. | 236 // Requesting any one frame shouldn't result in decoding any other frames. |
237 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); | 237 loadImage("/LayoutTests/images/resources/anim_none.gif", false); |
238 frameAtIndex(1); | 238 frameAtIndex(1); |
239 int frameSize = | 239 int frameSize = |
240 static_cast<int>(m_image->size().area() * sizeof(ImageFrame::PixelData)); | 240 static_cast<int>(m_image->size().area() * sizeof(ImageFrame::PixelData)); |
241 EXPECT_EQ(frameSize, lastDecodedSizeChange()); | 241 EXPECT_EQ(frameSize, lastDecodedSizeChange()); |
242 } | 242 } |
243 | 243 |
244 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) { | 244 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) { |
245 loadImage("/LayoutTests/fast/images/resources/green.jpg"); | 245 loadImage("/LayoutTests/images/resources/green.jpg"); |
246 setFirstFrameNotComplete(); | 246 setFirstFrameNotComplete(); |
247 EXPECT_GT(lastDecodedSizeChange(), 0); | 247 EXPECT_GT(lastDecodedSizeChange(), 0); |
248 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; | 248 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; |
249 | 249 |
250 // Calling dataChanged causes the cache to flush, but doesn't affect the | 250 // Calling dataChanged causes the cache to flush, but doesn't affect the |
251 // source's decoded frames. It shouldn't affect decoded size. | 251 // source's decoded frames. It shouldn't affect decoded size. |
252 m_image->dataChanged(true); | 252 m_image->dataChanged(true); |
253 EXPECT_EQ(0, lastDecodedSizeChange()); | 253 EXPECT_EQ(0, lastDecodedSizeChange()); |
254 // Recaching the first frame also shouldn't affect decoded size. | 254 // Recaching the first frame also shouldn't affect decoded size. |
255 m_image->imageForCurrentFrame(); | 255 m_image->imageForCurrentFrame(); |
(...skipping 20 matching lines...) Expand all Loading... |
276 | 276 |
277 using DecodedImageTypeHistogramTest = | 277 using DecodedImageTypeHistogramTest = |
278 BitmapHistogramTest<BitmapImageMetrics::DecodedImageType>; | 278 BitmapHistogramTest<BitmapImageMetrics::DecodedImageType>; |
279 | 279 |
280 TEST_P(DecodedImageTypeHistogramTest, ImageType) { | 280 TEST_P(DecodedImageTypeHistogramTest, ImageType) { |
281 runTest("Blink.DecodedImageType"); | 281 runTest("Blink.DecodedImageType"); |
282 } | 282 } |
283 | 283 |
284 DecodedImageTypeHistogramTest::ParamType | 284 DecodedImageTypeHistogramTest::ParamType |
285 kDecodedImageTypeHistogramTestParams[] = { | 285 kDecodedImageTypeHistogramTestParams[] = { |
286 {"/LayoutTests/fast/images/resources/green.jpg", | 286 {"/LayoutTests/images/resources/green.jpg", |
287 BitmapImageMetrics::ImageJPEG}, | 287 BitmapImageMetrics::ImageJPEG}, |
288 {"/LayoutTests/fast/images/resources/" | 288 {"/LayoutTests/images/resources/" |
289 "palatted-color-png-gamma-one-color-profile.png", | 289 "palatted-color-png-gamma-one-color-profile.png", |
290 BitmapImageMetrics::ImagePNG}, | 290 BitmapImageMetrics::ImagePNG}, |
291 {"/LayoutTests/fast/images/resources/animated-10color.gif", | 291 {"/LayoutTests/images/resources/animated-10color.gif", |
292 BitmapImageMetrics::ImageGIF}, | 292 BitmapImageMetrics::ImageGIF}, |
293 {"/LayoutTests/fast/images/resources/webp-color-profile-lossy.webp", | 293 {"/LayoutTests/images/resources/webp-color-profile-lossy.webp", |
294 BitmapImageMetrics::ImageWebP}, | 294 BitmapImageMetrics::ImageWebP}, |
295 {"/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", | 295 {"/LayoutTests/images/resources/wrong-frame-dimensions.ico", |
296 BitmapImageMetrics::ImageICO}, | 296 BitmapImageMetrics::ImageICO}, |
297 {"/LayoutTests/fast/images/resources/lenna.bmp", | 297 {"/LayoutTests/images/resources/lenna.bmp", |
298 BitmapImageMetrics::ImageBMP}}; | 298 BitmapImageMetrics::ImageBMP}}; |
299 | 299 |
300 INSTANTIATE_TEST_CASE_P( | 300 INSTANTIATE_TEST_CASE_P( |
301 DecodedImageTypeHistogramTest, | 301 DecodedImageTypeHistogramTest, |
302 DecodedImageTypeHistogramTest, | 302 DecodedImageTypeHistogramTest, |
303 ::testing::ValuesIn(kDecodedImageTypeHistogramTestParams)); | 303 ::testing::ValuesIn(kDecodedImageTypeHistogramTestParams)); |
304 | 304 |
305 using DecodedImageOrientationHistogramTest = | 305 using DecodedImageOrientationHistogramTest = |
306 BitmapHistogramTest<ImageOrientationEnum>; | 306 BitmapHistogramTest<ImageOrientationEnum>; |
307 | 307 |
308 TEST_P(DecodedImageOrientationHistogramTest, ImageOrientation) { | 308 TEST_P(DecodedImageOrientationHistogramTest, ImageOrientation) { |
309 runTest("Blink.DecodedImage.Orientation"); | 309 runTest("Blink.DecodedImage.Orientation"); |
310 } | 310 } |
311 | 311 |
312 DecodedImageOrientationHistogramTest::ParamType | 312 DecodedImageOrientationHistogramTest::ParamType |
313 kDecodedImageOrientationHistogramTestParams[] = { | 313 kDecodedImageOrientationHistogramTestParams[] = { |
314 {"/LayoutTests/fast/images/resources/exif-orientation-1-ul.jpg", | 314 {"/LayoutTests/images/resources/exif-orientation-1-ul.jpg", |
315 OriginTopLeft}, | 315 OriginTopLeft}, |
316 {"/LayoutTests/fast/images/resources/exif-orientation-2-ur.jpg", | 316 {"/LayoutTests/images/resources/exif-orientation-2-ur.jpg", |
317 OriginTopRight}, | 317 OriginTopRight}, |
318 {"/LayoutTests/fast/images/resources/exif-orientation-3-lr.jpg", | 318 {"/LayoutTests/images/resources/exif-orientation-3-lr.jpg", |
319 OriginBottomRight}, | 319 OriginBottomRight}, |
320 {"/LayoutTests/fast/images/resources/exif-orientation-4-lol.jpg", | 320 {"/LayoutTests/images/resources/exif-orientation-4-lol.jpg", |
321 OriginBottomLeft}, | 321 OriginBottomLeft}, |
322 {"/LayoutTests/fast/images/resources/exif-orientation-5-lu.jpg", | 322 {"/LayoutTests/images/resources/exif-orientation-5-lu.jpg", |
323 OriginLeftTop}, | 323 OriginLeftTop}, |
324 {"/LayoutTests/fast/images/resources/exif-orientation-6-ru.jpg", | 324 {"/LayoutTests/images/resources/exif-orientation-6-ru.jpg", |
325 OriginRightTop}, | 325 OriginRightTop}, |
326 {"/LayoutTests/fast/images/resources/exif-orientation-7-rl.jpg", | 326 {"/LayoutTests/images/resources/exif-orientation-7-rl.jpg", |
327 OriginRightBottom}, | 327 OriginRightBottom}, |
328 {"/LayoutTests/fast/images/resources/exif-orientation-8-llo.jpg", | 328 {"/LayoutTests/images/resources/exif-orientation-8-llo.jpg", |
329 OriginLeftBottom}}; | 329 OriginLeftBottom}}; |
330 | 330 |
331 INSTANTIATE_TEST_CASE_P( | 331 INSTANTIATE_TEST_CASE_P( |
332 DecodedImageOrientationHistogramTest, | 332 DecodedImageOrientationHistogramTest, |
333 DecodedImageOrientationHistogramTest, | 333 DecodedImageOrientationHistogramTest, |
334 ::testing::ValuesIn(kDecodedImageOrientationHistogramTestParams)); | 334 ::testing::ValuesIn(kDecodedImageOrientationHistogramTestParams)); |
335 | 335 |
336 } // namespace blink | 336 } // namespace blink |
OLD | NEW |