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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp

Issue 2386453003: WIP: Implement APNG (Closed)
Patch Set: Implemented feedback on patch set 9 Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/image-decoders/png/PNGImageDecoder.h"
6
7 #include "png.h"
8 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include <memory>
11
12 // @TODO(joostouwerling) test decoding failure on frame |n|, and check if the
13 // decoder reports having |n-1| frames.
14 // @TODO(joostouwerling) verify IEND before IDAT fails the decode.
15
16 namespace blink {
17
18 namespace {
19
20 std::unique_ptr<ImageDecoder> createDecoder(ImageDecoder::AlphaOption alphaOptio n)
21 {
22 return wrapUnique(new PNGImageDecoder(alphaOption,
23 ImageDecoder::ColorSpaceApplied,
24 ImageDecoder::noDecodedImageByteLimit));
25 }
26
27 std::unique_ptr<ImageDecoder> createDecoder()
28 {
29 return createDecoder(ImageDecoder::AlphaNotPremultiplied);
30 }
31
32 std::unique_ptr<ImageDecoder> createDecoderWithPngData(const char* pngFile)
33 {
34 auto decoder = createDecoder();
35 auto data = readFile(pngFile);
36 EXPECT_FALSE(data->isEmpty());
37 decoder->setData(data.get(), true);
38 return decoder;
39 }
40
41 void testSize(const char* pngFile, IntSize expectedSize)
42 {
43 auto decoder = createDecoderWithPngData(pngFile);
44 EXPECT_TRUE(decoder->isSizeAvailable());
45 EXPECT_EQ(expectedSize, decoder->size());
46 }
47
48 void writeUint32(uint32_t val, png_byte* data)
49 {
50 data[0] = val >> 24;
51 data[1] = val >> 16;
52 data[2] = val >> 8;
53 data[3] = val;
54 }
55
56 void testRepetitionCount(const char* pngFile, int expectedRepetitionCount)
57 {
58 auto decoder = createDecoderWithPngData(pngFile);
59 // Decode frame count should see the number of repetitions as well.
60 decoder->frameCount();
61 EXPECT_FALSE(decoder->failed());
62 EXPECT_EQ(expectedRepetitionCount, decoder->repetitionCount());
63 }
64
65 // Test whether querying for the size of the image works if we present the
66 // data byte by byte.
67 void testSizeByteByByte(const char *pngFile, size_t bytesNeededToDecodeSize,
68 IntSize expectedSize)
69 {
70 auto decoder = createDecoder();
71 auto data = readFile(pngFile);
72 ASSERT_FALSE(data->isEmpty());
73 ASSERT_LT(bytesNeededToDecodeSize, data->size());
74
75 for (size_t length = 1; length <= bytesNeededToDecodeSize; length++) {
76 RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(),
77 length);
78 decoder->setData(tempData.get(), false);
79
80 if (length < bytesNeededToDecodeSize) {
81 EXPECT_FALSE(decoder->isSizeAvailable());
82 EXPECT_TRUE(decoder->size().isEmpty());
83 EXPECT_FALSE(decoder->failed());
84 } else {
85 EXPECT_TRUE(decoder->isSizeAvailable());
86 EXPECT_EQ(expectedSize, decoder->size());
87 }
88 }
89 EXPECT_FALSE(decoder->failed());
90 }
91
92 struct PublicFrameInfo {
93 size_t duration;
94 IntRect frameRect;
95 ImageFrame::AlphaBlendSource alphaBlend;
96 ImageFrame::DisposalMethod disposalMethod;
97 };
98
99 // This is the frame data for the following PNG image:
100 // /LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png
101 static PublicFrameInfo pngAnimatedFrameInfo[] = {
102 {500, {IntPoint(0, 0), IntSize(5, 5)}, ImageFrame::BlendAtopBgcolor,
103 ImageFrame::DisposeKeep},
104 {900, {IntPoint(1, 1), IntSize(3, 1)}, ImageFrame::BlendAtopBgcolor,
105 ImageFrame::DisposeOverwriteBgcolor},
106 {2000, {IntPoint(1, 2), IntSize(3, 2)}, ImageFrame::BlendAtopPreviousFrame,
107 ImageFrame::DisposeKeep},
108 {1500, {IntPoint(1, 2), IntSize(3, 1)}, ImageFrame::BlendAtopBgcolor,
109 ImageFrame::DisposeKeep},
110 };
111
112 void compareFrameWithExpectation(const PublicFrameInfo& expected,
113 const ImageFrame* frame)
114 {
115 EXPECT_EQ(expected.duration, frame->duration());
116 EXPECT_EQ(expected.frameRect, frame->originalFrameRect());
117 EXPECT_EQ(expected.disposalMethod, frame->getDisposalMethod());
118 EXPECT_EQ(expected.alphaBlend, frame->getAlphaBlendSource());
119 }
120
121 // This function removes |length| bytes at |offset|, and then calls frameCount.
122 // It assumes the missing bytes should result in a failed decode.
123 void testMissingDataBreaksDecoding(const char* pngFile, size_t offset,
124 size_t length)
125 {
126 auto decoder = createDecoder();
127 auto data = readFile(pngFile);
128 ASSERT_FALSE(data->isEmpty());
129
130 RefPtr<SharedBuffer> invalidData = SharedBuffer::create(data->data(),
131 offset);
132 invalidData->append(SharedBuffer::create(data->data() + offset + length,
133 data->size() - offset - length));
134 ASSERT_EQ(data->size() - length, invalidData->size());
135
136 decoder->setData(invalidData, true);
137 decoder->frameCount();
138 EXPECT_TRUE(decoder->failed());
139 }
140
141 // Decoding up to the indicated fcTL offset and then provide an fcTL with
142 // the wrong chunk size (20 instead of 26). It should break the decoder.
143 void testInvalidFctlSize(const char* pngFile, size_t offsetFctl,
144 size_t expectedFrameCountBeforeFail)
145 {
146 auto data = readFile(pngFile);
147 ASSERT_FALSE(data->isEmpty());
148
149 auto decoder = createDecoder();
150 RefPtr<SharedBuffer> invalidData = SharedBuffer::create(data->data(),
151 offsetFctl);
152
153 // Test if this gives the correct frame count, before the fcTL is parsed.
154 decoder->setData(invalidData, false);
155 EXPECT_EQ(expectedFrameCountBeforeFail, decoder->frameCount());
156 ASSERT_FALSE(decoder->failed());
157
158 // Append the wrong size to the data stream
159 png_byte sizeChunk[4];
160 writeUint32(20, sizeChunk);
161 invalidData->append(reinterpret_cast<char*>(sizeChunk), 4u);
162
163 // Skip the size in the original data, but provide the rest of the fcTL,
164 // which is 4B of tag, 26B of data and 4B of CRC, totalling 34B.
165 invalidData->append(data->data() + offsetFctl + 4, 34u);
166
167 decoder->setData(invalidData, false);
168 decoder->frameCount();
169 EXPECT_TRUE(decoder->failed());
170 }
171
172 void testDifferentActlFrameCountIsIgnored(const char* pngFile,
173 size_t offsetActl,
174 size_t injectedFrameCount,
175 size_t expectedFrameCount)
176 {
177 // First make sure that this tests makes sense.
178 ASSERT_NE(injectedFrameCount, expectedFrameCount);
179
180 auto data = readFile(pngFile);
181 auto decoder = createDecoder();
182 ASSERT_FALSE(data->isEmpty());
183
184 RefPtr<SharedBuffer> diffActlData = SharedBuffer::create(data->data(),
185 offsetActl + 8);
186 // Write the injectedFrameCount to the stream
187 png_byte sizeChunk[4];
188 writeUint32(injectedFrameCount, sizeChunk);
189 diffActlData->append(reinterpret_cast<char*>(sizeChunk), 4u);
190 // Append the rest of the data. The first |offsetActl + 12| bytes that are
191 // already in diffActlData should not be appended again.
192 diffActlData->append(data->data() + offsetActl + 12,
193 data->size() - offsetActl - 12);
194
195 decoder->setData(diffActlData, true);
196 EXPECT_EQ(expectedFrameCount, decoder->frameCount());
197 }
198
199 // Test if the frame bitmap hashes of truncated decoding are equal to the
200 // hashes found by incremental decoding.
201 void testProgressiveDecoding(const char *pngFile)
202 {
203 RefPtr<SharedBuffer> fullData = readFile(pngFile);
204 ASSERT_TRUE(fullData.get());
205 const size_t fullLength = fullData->size();
206
207 std::unique_ptr<ImageDecoder> decoder;
208 ImageFrame* frame;
209
210 Vector<unsigned> truncatedHashes;
211 Vector<unsigned> progressiveHashes;
212
213 // Compute hashes when the file is truncated.
214 const size_t increment = 13;
215 for (size_t i = 1; i <= fullLength; i += increment) {
216 decoder = createDecoder();
217 RefPtr<SharedBuffer> data = SharedBuffer::create(fullData->data(), i);
218 decoder->setData(data.get(), i == fullLength);
219 size_t frameCount = decoder->frameCount();
220 ASSERT_FALSE(decoder->failed());
221 if (frameCount == 0) {
222 truncatedHashes.append(0);
223 continue;
224 }
225 frame = decoder->frameBufferAtIndex(frameCount - 1);
226 if (!frame) {
227 truncatedHashes.append(0);
228 continue;
229 }
230 truncatedHashes.append(hashBitmap(frame->bitmap()));
231 }
232
233 // Compute hashes when the file is progressively decoded.
234 decoder = createDecoder();
235 for (size_t i = 1; i <= fullLength; i += increment) {
236 RefPtr<SharedBuffer> data = SharedBuffer::create(fullData->data(), i);
237 decoder->setData(data.get(), i == fullLength);
238 ASSERT_FALSE(decoder->failed());
239 size_t frameCount = decoder->frameCount();
240 if (frameCount == 0) {
241 progressiveHashes.append(0);
242 continue;
243 }
244 frame = decoder->frameBufferAtIndex(frameCount - 1);
245 if (!frame) {
246 progressiveHashes.append(0);
247 continue;
248 }
249 progressiveHashes.append(hashBitmap(frame->bitmap()));
250 }
251
252 for (size_t i = 0; i < truncatedHashes.size(); ++i)
253 ASSERT_EQ(truncatedHashes[i], progressiveHashes[i]);
254 }
255
256 // Check that providing the full data after the first frame was partially
257 // decoded properly continues where it left off.
258 void testProgressiveDecodingContinuesAfterFullData(const char* pngFile,
259 size_t offsetMidFirstFrame)
260 {
261 auto fullData = readFile(pngFile);
262 auto decoder = createDecoder();
263 ASSERT_FALSE(fullData->isEmpty());
264
265 RefPtr<SharedBuffer> partialData =
266 SharedBuffer::create(fullData->data(), offsetMidFirstFrame);
267 decoder->setData(partialData, false);
268
269 EXPECT_EQ(1u, decoder->frameCount());
270 ImageFrame* frame = decoder->frameBufferAtIndex(0);
271 EXPECT_EQ(frame->getStatus(), ImageFrame::FramePartial);
272 unsigned hashPartial = hashBitmap(frame->bitmap());
273
274 decoder->setData(fullData.get(), true);
275 frame = decoder->frameBufferAtIndex(0);
276 EXPECT_EQ(frame->getStatus(), ImageFrame::FrameComplete);
277 unsigned hashFull = hashBitmap(frame->bitmap());
278
279 EXPECT_FALSE(decoder->failed());
280 EXPECT_NE(hashFull, hashPartial);
281 }
282
283 // This test verifies that the frame buffer contents change when progressively
284 // decoding the first frame. It should change more than 1 time: once for the
285 // first data, and at least once more thereafter. If |offsetFirstFrameEnd| == 0,
286 // the test uses the full data size of the image for its value.
287 void testProgressiveDecodingChangesFrameBuffer(const char* pngFile,
288 size_t offsetFirstFrameEnd,
289 size_t step = 1u)
290 {
291 auto fullData = readFile(pngFile);
292 auto decoder = createDecoder();
293 ASSERT_FALSE(fullData->isEmpty());
294
295 if (offsetFirstFrameEnd == 0)
296 offsetFirstFrameEnd = fullData->size();
297
298 size_t numTimesBufferChanged = 0;
299 unsigned lastHash;
300
301 for (size_t length = 1; length <= offsetFirstFrameEnd; length += step) {
302 RefPtr<SharedBuffer> data = SharedBuffer::create(fullData->data(),
303 length);
304 decoder->setData(data, false);
305 ImageFrame* frame = decoder->frameBufferAtIndex(0);
306 if (!frame)
307 continue;
308 unsigned newHash = hashBitmap(frame->bitmap());
309 if (newHash != lastHash) {
310 lastHash = newHash;
311 numTimesBufferChanged++;
312 }
313 }
314 EXPECT_GT(numTimesBufferChanged, 1u);
315 }
316
317 } // Anonymous namespace
318
319 // Animated PNG Tests
320
321 TEST(AnimatedPNGTests, sizeTest)
322 {
323 testSize("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animati on.png", IntSize(5, 5));
324 testSize("/LayoutTests/fast/images/resources/png-animated-idat-not-part-of-ani mation.png", IntSize(227, 35));
325 }
326
327 TEST(AnimatedPNGTests, repetitionCountTest)
328 {
329 testRepetitionCount("/LayoutTests/fast/images/resources/png-animated-idat-part -of-animation.png", 7u);
330 // This is an "animated" image with only one frame, that is, the IDAT is
331 // ignored and there is one fdAT frame. so it should be considered
332 // non-animated.
333 testRepetitionCount("/LayoutTests/fast/images/resources/png-animated-idat-not- part-of-animation.png", cAnimationNone);
334 }
335
336 // Test if the decoded metdata corresponds to the defined expectations
337 TEST(AnimatedPNGTests, MetaDataTest)
338 {
339 const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-pa rt-of-animation.png";
340 constexpr size_t expectedFrameCount = 4;
341
342 auto decoder = createDecoderWithPngData(pngFile);
343 ASSERT_EQ(expectedFrameCount, decoder->frameCount());
344 for (size_t i = 0; i < expectedFrameCount; i++)
345 compareFrameWithExpectation(pngAnimatedFrameInfo[i],
346 decoder->frameBufferAtIndex(i));
347 }
348
349 TEST(AnimatedPNGTests, ByteByByteSizeAvailable)
350 {
351 testSizeByteByByte("/LayoutTests/fast/images/resources/png-animated-idat-part- of-animation.png",
352 141u, IntSize(5, 5));
353 testSizeByteByByte("/LayoutTests/fast/images/resources/png-animated-idat-not-p art-of-animation.png",
354 79u, IntSize(227, 35));
355 }
356
357 // Test whether the frame metadata decoding also works when we provide the data
358 // byte by byte. This should cover the case when the client does not provide
359 // all data at once. At given offsets, we expect frames to become available.
360 // This test checks whether that is the case, and if so, if the frame data is
361 // equal to what we expected.
362 TEST(AnimatedPNGTests, ByteByByteMetaData)
363 {
364 const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-pa rt-of-animation.png";
365 constexpr size_t expectedFrameCount = 4;
366
367 // These are the byte offsets where each frame should have been parsed.
368 // It boils down to the offset of the first fcTL / IEND after the last
369 // frame data chunk, plus 8 bytes for recognition. The exception on this is
370 // the first frame, which is reported when its first framedata is seen.
371 size_t frameOffsets[expectedFrameCount] = {141, 249, 322, 430};
372
373 auto decoder = createDecoder();
374 auto data = readFile(pngFile);
375 ASSERT_FALSE(data->isEmpty());
376 size_t framesParsed = 0;
377
378 for (size_t length = 1; length <= frameOffsets[expectedFrameCount - 1]; length ++) {
379 RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(),
380 length);
381 decoder->setData(tempData.get(), false);
382 EXPECT_FALSE(decoder->failed());
383 if (length < frameOffsets[framesParsed]) {
384 EXPECT_EQ(framesParsed, decoder->frameCount());
385 } else {
386 ASSERT_EQ(framesParsed + 1, decoder->frameCount());
387 compareFrameWithExpectation(pngAnimatedFrameInfo[framesParsed],
388 decoder->frameBufferAtIndex(framesParsed));
389 framesParsed++;
390 }
391 }
392 EXPECT_EQ(expectedFrameCount, decoder->frameCount());
393 EXPECT_FALSE(decoder->failed());
394 }
395
396 // This tests if the frame count gets set correctly when parsing frameCount
397 // fails in one of the parsing queries.
398 //
399 // First, enough data is provided such that two frames should be registered.
400 // The decoder should at this point not be in the failed status.
401 //
402 // Then, we provide the rest of the data except for the last IEND chunk, but
403 // tell the decoder that this is all the data we have. Now, the decoder should
404 // be in the failed state since all data is provided but no IEND chunk has been
405 // seen. The frame count should be three, since one extra frame should be
406 // discovered. The fourth frame should *not* be registered since the reader
407 // should not be able to determine where the frame ends.
408 TEST(AnimatedPNGTests, FrameCountWithTruncatedData)
409 {
410 const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-pa rt-of-animation.png";
411 auto decoder = createDecoder();
412 auto data = readFile(pngFile);
413 ASSERT_FALSE(data->isEmpty());
414
415 // Parse up to and including the first two frames
416 const size_t offsetTwoFrames = 249;
417 const size_t expectedFramesAfter249Bytes = 2;
418 RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(),
419 offsetTwoFrames);
420 decoder->setData(tempData.get(), false);
421 EXPECT_EQ(expectedFramesAfter249Bytes, decoder->frameCount());
422 EXPECT_FALSE(decoder->failed());
423
424 // Provide the rest of the data except for the last IEND chunk.
425 const size_t expectedFramesAfterAllExpect12Bytes = 3;
426 tempData = SharedBuffer::create(data->data(), data->size() - 12);
427 decoder->setData(tempData.get(), true);
428 EXPECT_EQ(expectedFramesAfterAllExpect12Bytes, decoder->frameCount());
429 EXPECT_TRUE(decoder->failed());
430 }
431
432 TEST(AnimatedPNGTests, TestRandomFrameDecode)
433 {
434 RefPtr<SharedBuffer> fullData = readFile("/LayoutTests/fast/images/resources/p ng-animated-idat-part-of-animation.png");
435 ASSERT_TRUE(fullData.get());
436 Vector<unsigned> baselineHashes;
437 createDecodingBaseline(&createDecoder, fullData.get(), &baselineHashes);
438 size_t frameCount = baselineHashes.size();
439
440 // Random decoding should get the same results as sequential decoding.
441 std::unique_ptr<ImageDecoder> decoder = createDecoder();
442 decoder->setData(fullData.get(), true);
443 const size_t skippingStep = 2;
444 for (size_t i = 0; i < skippingStep; ++i) {
445 for (size_t j = i; j < frameCount; j += skippingStep) {
446 SCOPED_TRACE(testing::Message() << "Random i:" << i << " j:" << j);
447 ImageFrame* frame = decoder->frameBufferAtIndex(j);
448 EXPECT_EQ(baselineHashes[j], hashBitmap(frame->bitmap()));
449 }
450 }
451
452 // Decoding in reverse order.
453 decoder = createDecoder();
454 decoder->setData(fullData.get(), true);
455 for (size_t i = frameCount; i; --i) {
456 SCOPED_TRACE(testing::Message() << "Reverse i:" << i);
457 ImageFrame* frame = decoder->frameBufferAtIndex(i - 1);
458 EXPECT_EQ(baselineHashes[i - 1], hashBitmap(frame->bitmap()));
459 }
460
461 }
462
463 TEST(AnimatedPNGTests, TestDecodeAfterReallocation)
464 {
465 std::unique_ptr<ImageDecoder> decoder = createDecoder();
466 RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/png-a nimated-idat-part-of-animation.png");
467 ASSERT_TRUE(data.get());
468
469 // Parse from |data|.
470 decoder->setData(data.get(), true);
471 size_t frameCount = decoder->frameCount();
472
473 // ... and then decode frames from |reallocatedData|.
474 RefPtr<SharedBuffer> reallocatedData = data.get()->copy();
475 ASSERT_TRUE(reallocatedData.get());
476 data.clear();
477 decoder->setData(reallocatedData.get(), true);
478
479 for (size_t i = 0; i < frameCount; ++i) {
480 const ImageFrame* const frame = decoder->frameBufferAtIndex(i);
481 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
482 }
483 }
484
485 TEST(AnimatedPNGTests, ProgressiveDecode)
486 {
487 testProgressiveDecoding("/LayoutTests/fast/images/resources/png-animated-idat- part-of-animation.png");
488 }
489
490 TEST(AnimatedPNGTests, ParseAndDecodeByteByByte)
491 {
492 testByteByByteDecode(&createDecoder,
493 "/LayoutTests/fast/images/resources/png-animated-idat-part-of-anima tion.png",
494 4u, 7u);
495 }
496
497 TEST(AnimatedPNGTests, FctlWrongSizeBreaksDecoding)
498 {
499 const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-pa rt-of-animation.png";
500 auto data = readFile(pngFile);
501 ASSERT_FALSE(data->isEmpty());
502
503 // Test the first fcTL in the stream. Because no frame data has been set
504 // at this point, the expected frame count is zero.
505 testInvalidFctlSize("/LayoutTests/fast/images/resources/png-animated-idat-part -of-animation.png",
506 95u, 0u);
507
508 // Test for the third fcTL in the stream. This should be tested as well,
509 // since the first fcTL is parsed in PNGImageReader::parseSize() whereas
510 // later fcTLs are parsed in PNGImageReader::parse() as part of framecount.
511 // The expected frame count before the fcTL chunk is 1u, since the second
512 // frame is registered when the third fcTL (or IEND) is seen.
513 testInvalidFctlSize("/LayoutTests/fast/images/resources/png-animated-idat-part -of-animation.png",
514 241u, 1u);
515
516 }
517
518 TEST(AnimatedPNGTests, MissingFctlDataBreaksDecoding)
519 {
520 // The fcTL chunk starts at 95u, add 10u to get to the content data, and
521 // remove 5 bytes of data.
522 testMissingDataBreaksDecoding(
523 "/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png" ,
524 105u, 5u);
525 }
526
527 TEST(AnimatedPNGTests, MissingActlResultsInNonAnimated)
528 {
529 const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-pa rt-of-animation.png";
530 auto data = readFile(pngFile);
531 auto decoder = createDecoder();
532 ASSERT_FALSE(data->isEmpty());
533
534 // Remove the acTL chunk from the stream.
535 size_t offsetActl = 33;
536 RefPtr<SharedBuffer> noActlData = SharedBuffer::create(data->data(),
537 offsetActl);
538 noActlData->append(data->data() + offsetActl + 20,
539 data->size() - offsetActl - 20);
540
541 decoder->setData(noActlData, true);
542 EXPECT_EQ(1u, decoder->frameCount());
543 EXPECT_FALSE(decoder->failed());
544 }
545
546 // Test if the indicated frame count by the acTL is ignored if the actual
547 // number of frames is different. Test for higher and lower indicated number.
548 TEST(AnimatedPNGTests, differentActlFrameCountIsIgnored)
549 {
550 const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-pa rt-of-animation.png";
551 testDifferentActlFrameCountIsIgnored(pngFile, 33u, 2u, 4u);
552 testDifferentActlFrameCountIsIgnored(pngFile, 33u, 8u, 4u);
553 }
554
555 // Check if a frame rectangle, that is larger than the image width, gets
556 // clipped correctly.
557 // @TODO(joostouwerling) use an image that also has data that needs to be
558 // clipped, not just report larger dimensions.
559 // @TODO(joostouwerling) determine how libpng handles larger / smaller images
560 // than indicated.
561 TEST(AnimatedPNGTests, frameRectIsClipped)
562 {
563 const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-pa rt-of-animation.png";
564 auto data = readFile(pngFile);
565 auto decoder = createDecoder();
566 ASSERT_FALSE(data->isEmpty());
567
568 // Change the width and height of the frame so it falls outside the image.
569 size_t offsetThirdFctl = 241 + 12;
570 RefPtr<SharedBuffer> modifiedData = SharedBuffer::create(data->data(),
571 offsetThirdFctl);
572 png_byte sizeChunk[8];
573 writeUint32(10, sizeChunk);
574 writeUint32(15, sizeChunk + 4);
575 modifiedData->append(const_cast<const char*>(
576 reinterpret_cast<char*>(sizeChunk)), 8u);
577 modifiedData->append(data->data() + offsetThirdFctl + 8,
578 data->size() - offsetThirdFctl - 8);
579
580 decoder->setData(modifiedData, true);
581
582 IntSize expectedSize(5, 5);
583 size_t expectedFrameCount = 4;
584 IntRect expectedFrameRect(IntPoint(1, 2), IntSize(4, 3));
585
586 EXPECT_TRUE(decoder->isSizeAvailable());
587 EXPECT_EQ(expectedSize, decoder->size());
588 EXPECT_EQ(expectedFrameCount, decoder->frameCount());
589 ASSERT_FALSE(decoder->failed());
590 EXPECT_EQ(expectedFrameRect,
591 decoder->frameBufferAtIndex(2)->originalFrameRect());
592 }
593
594 TEST(AnimatedPNGTests, ProgressiveDecodingChangesFrameBuffer)
595 {
596 testProgressiveDecodingChangesFrameBuffer(
597 "/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png" , 249u);
598 }
599
600 TEST(AnimatedPNGTests, ProgressiveDecodingContinuesAfterFullData)
601 {
602 testProgressiveDecodingContinuesAfterFullData(
603 "/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png" , 160u);
604 }
605
606 // Static PNG tests
607
608 TEST(StaticPNGTests, repetitionCountTest)
609 {
610 testRepetitionCount("/LayoutTests/fast/images/resources/png-simple.png",
611 cAnimationNone);
612 }
613
614 TEST(StaticPNGTests, sizeTest)
615 {
616 testSize("/LayoutTests/fast/images/resources/png-simple.png",
617 IntSize(111, 29));
618 }
619
620 TEST(StaticPNGTests, MetaDataTest)
621 {
622 const size_t expectedFrameCount = 1;
623 const size_t expectedDuration = 0;
624 auto decoder = createDecoderWithPngData("/LayoutTests/fast/images/resources/pn g-simple.png");
625 EXPECT_EQ(expectedFrameCount, decoder->frameCount());
626 EXPECT_EQ(expectedDuration, decoder->frameDurationAtIndex(0));
627 }
628
629 TEST(StaticPNGTests, InvalidIHDRChunk)
630 {
631 testMissingDataBreaksDecoding(
632 "/LayoutTests/fast/images/resources/png-simple.png", 20u, 2u);
633 }
634
635 TEST(StaticPNGTests, ProgressiveDecoding)
636 {
637 testProgressiveDecoding("/LayoutTests/fast/images/resources/png-simple.png");
638 }
639
640 TEST(StaticPNGTests, ProgressiveDecodingChangesFrameBuffer)
641 {
642 testProgressiveDecodingChangesFrameBuffer(
643 "/LayoutTests/fast/images/resources/png-simple.png", 0u, 5u);
644 }
645
646 TEST(StaticPNGTests, ProgressiveDecodingContinuesAfterFullData)
647 {
648 testProgressiveDecodingContinuesAfterFullData(
649 "/LayoutTests/fast/images/resources/png-simple.png", 1000u);
650 }
651
652 }; // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698