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

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

Issue 2386453003: WIP: Implement APNG (Closed)
Patch Set: Basic frame decoding with tests, no alpha blending and disposal yet Created 4 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4ecabe272a782eeea22f5c2d9aa405c8a0c84792
--- /dev/null
+++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
@@ -0,0 +1,565 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/image-decoders/png/PNGImageDecoder.h"
+
+#include "png.h"
+#include "platform/image-decoders/ImageDecoderTestHelpers.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include <memory>
+
+namespace blink {
+
+namespace {
+
+std::unique_ptr<ImageDecoder> createDecoder(ImageDecoder::AlphaOption alphaOption)
+{
+ return wrapUnique(new PNGImageDecoder(alphaOption,
+ ImageDecoder::GammaAndColorProfileApplied,
+ ImageDecoder::noDecodedImageByteLimit));
+}
+
+std::unique_ptr<ImageDecoder> createDecoder()
+{
+ return createDecoder(ImageDecoder::AlphaNotPremultiplied);
+}
+
+std::unique_ptr<ImageDecoder> createDecoderWithPngData(const char* pngFile)
+{
+ auto decoder = createDecoder();
+ auto data = readFile(pngFile);
+ EXPECT_FALSE(data->isEmpty());
+ decoder->setData(data.get(), true);
+ return decoder;
+}
+
+void testSize(const char* pngFile, IntSize expectedSize)
+{
+ auto decoder = createDecoderWithPngData(pngFile);
+ EXPECT_TRUE(decoder->isSizeAvailable());
+ EXPECT_EQ(expectedSize, decoder->size());
+}
+
+void writeUint32(uint32_t val, png_byte* data)
+{
+ data[0] = val >> 24;
+ data[1] = val >> 16;
+ data[2] = val >> 8;
+ data[3] = val;
+}
+
+void testRepetitionCount(const char* pngFile, int expectedRepetitionCount)
+{
+ auto decoder = createDecoderWithPngData(pngFile);
+ // Decode frame count should see the number of repetitions as well.
+ decoder->frameCount();
+ EXPECT_FALSE(decoder->failed());
+ EXPECT_EQ(expectedRepetitionCount, decoder->repetitionCount());
+}
+
+// Test whether querying for the size of the image works if we present the
+// data byte by byte.
+void testSizeByteByByte(const char *pngFile, size_t bytesNeededToDecodeSize,
+ IntSize expectedSize)
+{
+ auto decoder = createDecoder();
+ auto data = readFile(pngFile);
+ ASSERT_FALSE(data->isEmpty());
+ ASSERT_LT(bytesNeededToDecodeSize, data->size());
+
+ for (size_t length = 1; length <= bytesNeededToDecodeSize; length++) {
+ RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(),
+ length);
+ decoder->setData(tempData.get(), false);
+
+ if (length < bytesNeededToDecodeSize) {
+ EXPECT_FALSE(decoder->isSizeAvailable());
+ EXPECT_TRUE(decoder->size().isEmpty());
+ EXPECT_FALSE(decoder->failed());
+ } else {
+ EXPECT_TRUE(decoder->isSizeAvailable());
+ EXPECT_EQ(expectedSize, decoder->size());
+ }
+ }
+ EXPECT_FALSE(decoder->failed());
+}
+
+struct PublicFrameInfo {
+ size_t duration;
+ IntRect frameRect;
+ ImageFrame::AlphaBlendSource alphaBlend;
+ ImageFrame::DisposalMethod disposalMethod;
+};
+
+// This is the frame data for the following PNG image:
+// /LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png
+static PublicFrameInfo pngAnimatedFrameInfo[] = {
+ {500, {IntPoint(0, 0), IntSize(5, 5)}, ImageFrame::BlendAtopBgcolor,
+ ImageFrame::DisposeKeep},
+ {900, {IntPoint(1, 1), IntSize(3, 1)}, ImageFrame::BlendAtopBgcolor,
+ ImageFrame::DisposeOverwriteBgcolor},
+ {2000, {IntPoint(1, 2), IntSize(3, 2)}, ImageFrame::BlendAtopPreviousFrame,
+ ImageFrame::DisposeKeep},
+ {1500, {IntPoint(1, 2), IntSize(3, 1)}, ImageFrame::BlendAtopBgcolor,
+ ImageFrame::DisposeKeep},
+};
+
+void compareFrameWithExpectation(const PublicFrameInfo& expected,
+ const ImageFrame* frame)
+{
+ EXPECT_EQ(expected.duration, frame->duration());
+ EXPECT_EQ(expected.frameRect, frame->originalFrameRect());
+ EXPECT_EQ(expected.disposalMethod, frame->getDisposalMethod());
+ EXPECT_EQ(expected.alphaBlend, frame->getAlphaBlendSource());
+}
+
+// This function removes |length| bytes at |offset|, and then calls frameCount.
+// It assumes the missing bytes should return in a failed decoding.
scroggo_chromium 2016/10/25 14:59:06 I think you mean "result" instead of "return"? (A
+void testMissingDataBreaksDecoding(const char* pngFile, size_t offset,
+ size_t length)
+{
+ auto decoder = createDecoder();
+ auto data = readFile(pngFile);
+ ASSERT_FALSE(data->isEmpty());
+
+ RefPtr<SharedBuffer> invalidData = SharedBuffer::create(data->data(),
+ offset);
+ invalidData->append(SharedBuffer::create(data->data() + offset + length,
+ data->size() - offset - length));
+ ASSERT_EQ(data->size() - length, invalidData->size());
+
+ decoder->setData(invalidData, true);
+ decoder->frameCount();
+ EXPECT_TRUE(decoder->failed());
+}
+
+// Decoding up to the indicated fcTL offset and then provide an fcTL with
+// the wrong chunk size (20 instead of 26). It should break the decoder.
+void testInvalidFctlSize(const char *pngFile, size_t offsetFctl,
scroggo_chromium 2016/10/25 14:59:06 * should go next to the type (although I think Mat
+ size_t expectedFrameCountBeforeFail)
+{
+ auto data = readFile(pngFile);
+ ASSERT_FALSE(data->isEmpty());
+
+ auto decoder = createDecoder();
+ RefPtr<SharedBuffer> invalidData = SharedBuffer::create(data->data(),
+ offsetFctl);
+
+ // Test if this gives the correct frame count, before the fcTL is parsed.
+ decoder->setData(invalidData, false);
+ EXPECT_EQ(expectedFrameCountBeforeFail, decoder->frameCount());
+ ASSERT_FALSE(decoder->failed());
+
+ // Append the wrong size to the data stream
+ png_byte sizeChunk[4];
+ writeUint32(20, sizeChunk);
+ invalidData->append(const_cast<const char*>(
scroggo_chromium 2016/10/25 14:59:06 I don't think you should need a const cast to cast
+ reinterpret_cast<char*>(sizeChunk)), 4u);
+
+ // Skip the size in the original data, but provide the rest of the fcTL
+ invalidData->append(data->data() + offsetFctl + 4, 34u);
scroggo_chromium 2016/10/25 14:59:06 Where did 34u come from? Is fcTL 38 bytes?
joostouwerling 2016/10/26 15:44:17 Yes, 26 bytes of data and 12 for length, tag and c
+
+ decoder->setData(invalidData, false);
+ decoder->frameCount();
+ EXPECT_TRUE(decoder->failed());
+}
+
+void testDifferentActlFrameCountIsIgnored(const char* pngFile,
+ size_t offsetActl,
+ size_t injectedFrameCount,
+ size_t expectedFrameCount)
+{
+ auto data = readFile(pngFile);
+ auto decoder = createDecoder();
+ ASSERT_FALSE(data->isEmpty());
+
+ RefPtr<SharedBuffer> diffActlData = SharedBuffer::create(data->data(),
+ offsetActl + 8);
+ // Write the injectedFrameCount to the stream
+ png_byte sizeChunk[4];
+ writeUint32(injectedFrameCount, sizeChunk);
+ diffActlData->append(const_cast<const char*>(
+ reinterpret_cast<char*>(sizeChunk)), 4u);
+ // Append the rest of the data
+ diffActlData->append(data->data() + offsetActl + 12,
scroggo_chromium 2016/10/25 14:59:06 I take it the acTL chunk is 16 bytes? It would be
+ data->size() - offsetActl - 12);
+
+ decoder->setData(diffActlData, true);
+ EXPECT_EQ(expectedFrameCount, decoder->frameCount());
scroggo_chromium 2016/10/25 14:59:06 Maybe assert that expectedFrameCount != injectedFr
+}
+
+// Test if the frame bitmap hashes of truncated decoding are equal to the
+// hashes found by incremental decoding.
+void testProgressiveDecoding(const char *pngFile)
+{
+ RefPtr<SharedBuffer> fullData = readFile(pngFile);
+ ASSERT_TRUE(fullData.get());
+ const size_t fullLength = fullData->size();
+
+ std::unique_ptr<ImageDecoder> decoder;
scroggo_chromium 2016/10/25 14:59:06 nit: extra space
+ ImageFrame* frame;
+
+ Vector<unsigned> truncatedHashes;
+ Vector<unsigned> progressiveHashes;
+
+ // Compute hashes when the file is truncated.
+ const size_t increment = 10;
+ for (size_t i = 1; i <= fullLength; i += increment) {
+ decoder = createDecoder();
+ RefPtr<SharedBuffer> data = SharedBuffer::create(fullData->data(), i);
+ decoder->setData(data.get(), i == fullLength);
+ size_t frameCount = decoder->frameCount();
+ ASSERT_FALSE(decoder->failed());
+ if (frameCount == 0) {
+ truncatedHashes.append(0);
+ continue;
+ }
+ frame = decoder->frameBufferAtIndex(frameCount - 1);
+ if (!frame) {
+ truncatedHashes.append(0);
+ continue;
+ }
+ truncatedHashes.append(hashBitmap(frame->bitmap()));
+ }
+
+ // Compute hashes when the file is progressively decoded.
+ decoder = createDecoder();
+ for (size_t i = 1; i <= fullLength; i += increment) {
+ RefPtr<SharedBuffer> data = SharedBuffer::create(fullData->data(), i);
+ decoder->setData(data.get(), i == fullLength);
+ ASSERT_FALSE(decoder->failed());
+ size_t frameCount = decoder->frameCount();
+ if (frameCount == 0) {
+ progressiveHashes.append(0);
+ continue;
+ }
+ frame = decoder->frameBufferAtIndex(frameCount - 1);
+ if (!frame) {
+ progressiveHashes.append(0);
+ continue;
+ }
+ progressiveHashes.append(hashBitmap(frame->bitmap()));
+ }
+
+ bool match = true;
+ for (size_t i = 0; i < truncatedHashes.size(); ++i) {
+ if (truncatedHashes[i] != progressiveHashes[i]) {
+ match = false;
scroggo_chromium 2016/10/25 14:59:06 Alternatively, could this just be something like
+ break;
+ }
+ }
+ EXPECT_TRUE(match);
+
+}
+
+} // Anonymous namespace
+
+// Animated PNG Tests
+
+TEST(AnimatedPNGTests, sizeTest)
+{
+ testSize("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png", IntSize(5, 5));
+ testSize("/LayoutTests/fast/images/resources/png-animated-idat-not-part-of-animation.png", IntSize(227, 35));
+}
+
+TEST(AnimatedPNGTests, repetitionCountTest)
+{
+ testRepetitionCount("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png", 7u);
+ // This is an "animated" image with only one frame, that is, the IDAT is
+ // ignored and there is one fdAT frame. so it should be considered
+ // non-animated.
+ testRepetitionCount("/LayoutTests/fast/images/resources/png-animated-idat-not-part-of-animation.png", cAnimationNone);
+}
+
+// Test if the decoded metdata corresponds to the defined expectations
+TEST(AnimatedPNGTests, MetaDataTest)
+{
+ const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png";
+ constexpr size_t expectedFrameCount = 4;
+
+ auto decoder = createDecoderWithPngData(pngFile);
+ ASSERT_EQ(expectedFrameCount, decoder->frameCount());
+ for (size_t i = 0; i < expectedFrameCount; i++)
+ compareFrameWithExpectation(pngAnimatedFrameInfo[i],
+ decoder->frameBufferAtIndex(i));
+}
+
+TEST(AnimatedPNGTests, ByteByByteSizeAvailable)
+{
+ testSizeByteByByte("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png",
+ 141u, IntSize(5, 5));
+ testSizeByteByByte("/LayoutTests/fast/images/resources/png-animated-idat-not-part-of-animation.png",
+ 79u, IntSize(227, 35));
+}
+
+// Test whether the frame metadata decoding also works when we provide the data
+// byte by byte. This should cover the case when the client does not provide
+// all data at once. At given offsets, we expect frames to become available.
+// This test checks whether that is the case, and if so, if the frame data is
+// equal to what we expected.
+TEST(AnimatedPNGTests, ByteByByteMetaData)
+{
+ const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png";
+ constexpr size_t expectedFrameCount = 4;
+
+ // These are the byte offsets where each frame should have been parsed.
+ // It boils down to the offset of the first fcTL / IEND after the last
+ // frame data chunk, plus 8 bytes for recognition.
+ size_t frameOffsets[expectedFrameCount] = {180, 249, 322, 430};
+
+ auto decoder = createDecoder();
+ auto data = readFile(pngFile);
+ ASSERT_FALSE(data->isEmpty());
+ size_t framesParsed = 0;
+
+ for (size_t length = 1; length <= frameOffsets[expectedFrameCount - 1]; length++) {
+ RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(),
+ length);
+ decoder->setData(tempData.get(), false);
+ EXPECT_FALSE(decoder->failed());
+ if (length < frameOffsets[framesParsed]) {
+ EXPECT_EQ(framesParsed, decoder->frameCount());
+ } else {
+ ASSERT_EQ(framesParsed + 1, decoder->frameCount());
+ compareFrameWithExpectation(pngAnimatedFrameInfo[framesParsed],
+ decoder->frameBufferAtIndex(framesParsed));
+ framesParsed++;
+ }
+ }
+ EXPECT_EQ(expectedFrameCount, decoder->frameCount());
+ EXPECT_FALSE(decoder->failed());
+}
+
+// This tests if the frame count gets set correctly when parsing frameCount
+// fails in one of the parsing queries.
+//
+// First, enough data is provided such that two frames should be registered.
+// The decoder should at this point not be in the failed status.
+//
+// Then, we provide the rest of the data except for the last IEND chunk, but
+// tell the decoder that this is all the data we have. Now, the decoder should
+// be in the failed state since all data is provided but no IEND chunk has been
+// seen. The frame count should be three, since one extra frame should be
+// discovered. The fourth frame should *not* be registered since the reader
+// should not be able to determine where the frame ends.
+TEST(AnimatedPNGTests, FrameCountWithTruncatedData)
+{
+ const char* pngFile = "/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png";
+ auto decoder = createDecoder();
+ auto data = readFile(pngFile);
+ ASSERT_FALSE(data->isEmpty());
+
+ // Parse up to and including the first two frames
+ const size_t offsetTwoFrames = 249;
+ const size_t expectedFramesAfter249Bytes = 2;
+ RefPtr<SharedBuffer> tempData = SharedBuffer::create(data->data(),
+ offsetTwoFrames);
+ decoder->setData(tempData.get(), false);
+ EXPECT_EQ(expectedFramesAfter249Bytes, decoder->frameCount());
+ EXPECT_FALSE(decoder->failed());
+
+ // Provide the rest of the data except for the last IEND chunk.
+ const size_t expectedFramesAfterAllExpect12Bytes = 3;
+ tempData = SharedBuffer::create(data->data(), data->size() - 12);
+ decoder->setData(tempData.get(), true);
+ EXPECT_EQ(expectedFramesAfterAllExpect12Bytes, decoder->frameCount());
+ EXPECT_TRUE(decoder->failed());
+}
+
+TEST(AnimatedPNGTests, TestRandomFrameDecode)
+{
+ RefPtr<SharedBuffer> fullData = readFile("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png");
+ ASSERT_TRUE(fullData.get());
+ Vector<unsigned> baselineHashes;
+ createDecodingBaseline(&createDecoder, fullData.get(), &baselineHashes);
+ size_t frameCount = baselineHashes.size();
+
+ // Random decoding should get the same results as sequential decoding.
+ std::unique_ptr<ImageDecoder> decoder = createDecoder();
+ decoder->setData(fullData.get(), true);
+ const size_t skippingStep = 2;
+ for (size_t i = 0; i < skippingStep; ++i) {
+ for (size_t j = i; j < frameCount; j += skippingStep) {
+ SCOPED_TRACE(testing::Message() << "Random i:" << i << " j:" << j);
+ ImageFrame* frame = decoder->frameBufferAtIndex(j);
+ EXPECT_EQ(baselineHashes[j], hashBitmap(frame->bitmap()));
+ }
+ }
+
+ // Decoding in reverse order.
+ decoder = createDecoder();
+ decoder->setData(fullData.get(), true);
+ for (size_t i = frameCount; i; --i) {
+ SCOPED_TRACE(testing::Message() << "Reverse i:" << i);
+ ImageFrame* frame = decoder->frameBufferAtIndex(i - 1);
+ EXPECT_EQ(baselineHashes[i - 1], hashBitmap(frame->bitmap()));
+ }
+
+}
+
+TEST(AnimatedPNGTests, TestDecodeAfterReallocation)
+{
+ std::unique_ptr<ImageDecoder> decoder = createDecoder();
+ RefPtr<SharedBuffer> data = readFile("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png");
+ ASSERT_TRUE(data.get());
+
+ // Parse from |data|.
+ decoder->setData(data.get(), true);
+ size_t frameCount = decoder->frameCount();
+
+ // ... and then decode frames from |reallocatedData|.
scroggo_chromium 2016/10/25 14:59:06 What is interesting about this test? (Will PNGIma
joostouwerling 2016/10/26 15:44:17 It should have the frame meta data cached, not the
scroggo_chromium 2016/10/26 18:25:58 Ok, that makes sense. You asked me a question in p
joostouwerling 2016/10/31 18:40:19 I will consolidate the tests when this CL is done,
+ RefPtr<SharedBuffer> reallocatedData = data.get()->copy();
+ ASSERT_TRUE(reallocatedData.get());
+ data.clear();
+ decoder->setData(reallocatedData.get(), true);
+
+ for (size_t i = 0; i < frameCount; ++i) {
+ const ImageFrame* const frame = decoder->frameBufferAtIndex(i);
+ EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
+ }
+}
+
+TEST(AnimatedPNGTests, ProgressiveDecode)
+{
+ testProgressiveDecoding("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png");
+}
+
+TEST(AnimatedPNGTests, ParseAndDecodeByteByByte)
+{
+ testByteByByteDecode(&createDecoder,
+ "/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png",
+ 4u, 7u);
+}
+
+TEST(AnimatedPNGTests, FctlWrongSizeBreaksDecoding)
+{
+ const char* pngFile = "//LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png";
+ auto data = readFile(pngFile);
+ ASSERT_FALSE(data->isEmpty());
+
+ // Test the first fcTL in the stream. Because no frame data has been set
+ // at this point, the expected frame count is zero.
+ testInvalidFctlSize("//LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png",
+ 95u, 0u);
+
+ // Test for the third fcTL in the stream. This should be tested as well,
+ // since the first fcTL is parsed in PNGImageReader::parseSize() whereas
+ // later fcTLs are parsed in PNGImageReader::parse() as part of framecount.
+ // The expected frame count before the fcTL chunk is 1u, since the second
+ // frame is registered when the third fcTL (or IEND) is seen.
+ testInvalidFctlSize("//LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png",
+ 241u, 1u);
+
+}
+
+TEST(AnimatedPNGTests, MissingFctlDataBreaksDecoding)
+{
+ // The fcTL chunk starts at 95u, add 10u to get to the content data, and
+ // remove 5 bytes of data.
+ testMissingDataBreaksDecoding(
+ "//LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png",
+ 105u, 5u);
+}
+
+TEST(AnimatedPNGTests, MissingActlResultsInNonAnimated)
+{
+ const char* pngFile = "//LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png";
+ auto data = readFile(pngFile);
+ auto decoder = createDecoder();
+ ASSERT_FALSE(data->isEmpty());
+
+ // Remove the acTL chunk from the stream.
+ size_t offsetActl = 33;
+ RefPtr<SharedBuffer> noActlData = SharedBuffer::create(data->data(),
+ offsetActl);
+ noActlData->append(data->data() + offsetActl + 20,
+ data->size() - offsetActl - 20);
+
+ decoder->setData(noActlData, true);
+ EXPECT_EQ(1u, decoder->frameCount());
+ EXPECT_FALSE(decoder->failed());
+}
+
+// Test if the indicated frame count by the acTL is ignored if the actual
+// number of frames is different. Test for higher and lower indicated number.
+TEST(AnimatedPNGTests, differentActlFrameCountIsIgnored)
+{
+ const char* pngFile = "//LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png";
+ testDifferentActlFrameCountIsIgnored(pngFile, 33u, 2u, 4u);
+ testDifferentActlFrameCountIsIgnored(pngFile, 33u, 8u, 4u);
+}
+
+// Check if a frame rectangle, that is larger than the image width, gets
+// clipped correctly.
+TEST(AnimatedPNGTests, frameRectIsClipped)
+{
+ const char* pngFile = "//LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png";
+ auto data = readFile(pngFile);
+ auto decoder = createDecoder();
+ ASSERT_FALSE(data->isEmpty());
+
+ // Change the width and height of the frame so it falls outside the image.
+ size_t offsetThirdFctl = 241 + 12;
+ RefPtr<SharedBuffer> modifiedData = SharedBuffer::create(data->data(),
+ offsetThirdFctl);
+ png_byte sizeChunk[8];
+ writeUint32(10, sizeChunk);
+ writeUint32(15, sizeChunk + 4);
+ modifiedData->append(const_cast<const char*>(
+ reinterpret_cast<char*>(sizeChunk)), 8u);
+ modifiedData->append(data->data() + offsetThirdFctl + 8,
+ data->size() - offsetThirdFctl - 8);
+
+ decoder->setData(modifiedData, true);
+
+ IntSize expectedSize(5, 5);
+ size_t expectedFrameCount = 4;
+ IntRect expectedFrameRect(IntPoint(1, 2), IntSize(4, 3));
+
+ EXPECT_TRUE(decoder->isSizeAvailable());
+ EXPECT_EQ(expectedSize, decoder->size());
+ EXPECT_EQ(expectedFrameCount, decoder->frameCount());
+ ASSERT_FALSE(decoder->failed());
+ EXPECT_EQ(expectedFrameRect,
+ decoder->frameBufferAtIndex(2)->originalFrameRect());
+
+}
+
+// Static PNG tests
+
+TEST(StaticPNGTests, repetitionCountTest)
+{
+ testRepetitionCount("/LayoutTests/fast/images/resources/png-simple.png",
+ cAnimationNone);
+}
+
+TEST(StaticPNGTests, sizeTest)
+{
+ testSize("/LayoutTests/fast/images/resources/png-simple.png",
+ IntSize(111, 29));
+}
+
+TEST(StaticPNGTests, MetaDataTest)
+{
+ const size_t expectedFrameCount = 1;
+ const size_t expectedDuration = 0;
+ auto decoder = createDecoderWithPngData("/LayoutTests/fast/images/resources/png-simple.png");
+ EXPECT_EQ(expectedFrameCount, decoder->frameCount());
+ EXPECT_EQ(expectedDuration, decoder->frameDurationAtIndex(0));
+}
+
+// This test removes two random byets from the IHDR chunk. The decoder should
+// fail on this since all IHDR data is necessary to decode a PNG image.
+TEST(StaticPNGTests, InvalidIHDRChunk)
+{
+ testMissingDataBreaksDecoding(
+ "//LayoutTests/fast/images/resources/png-simple.png", 20u, 2u);
+}
+
+TEST(StaticPNGTests, ProgressiveDecoding)
+{
+ testProgressiveDecoding("/LayoutTests/fast/images/resources/png-simple.png");
+}
+
+}; // namespace blink

Powered by Google App Engine
This is Rietveld 408576698