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

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

Issue 2386453003: WIP: Implement APNG (Closed)
Patch Set: Tests for size and repetition count. Decoder stores repetition count for APNG 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..cad67788caadd830ae03c2cbcbcdc95c391c5c6e
--- /dev/null
+++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoderTest.cpp
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2016 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "platform/image-decoders/png/PNGImageDecoder.h"
+
+#include "platform/RuntimeEnabledFeatures.h"
+#include "platform/SharedBuffer.h"
+#include "platform/image-decoders/ImageDecoderTestHelpers.h"
+#include "public/platform/WebData.h"
+#include "public/platform/WebSize.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/PtrUtil.h"
+#include "wtf/Vector.h"
+#include "wtf/dtoa/utils.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);
+ decoder->setData(data.get(), true);
+ EXPECT_EQ(false, data.get()->isEmpty());
joostouwerling 2016/10/01 19:59:05 Line 65 is a little weird, changed it to data()->i
+ return decoder;
+}
+
+void testFrameCount(const char* pngFile, size_t expectedFrameCount)
+{
+ auto decoder = createDecoderWithPngData(pngFile);
+ EXPECT_EQ(expectedFrameCount, decoder->frameCount());
+}
+
+void testSize(const char* pngFile, IntSize expectedSize)
+{
+ auto decoder = createDecoderWithPngData(pngFile);
+ EXPECT_EQ(true, decoder->isSizeAvailable());
+ EXPECT_EQ(expectedSize, decoder->size());
+}
+
+void testRepetitionCount(const char* pngFile, int expectedRepetitions)
+{
+ auto decoder = createDecoderWithPngData(pngFile);
+ // Decode frame count should see the number of repetitions as well.
+ decoder->frameCount();
+ EXPECT_EQ(false, decoder->failed());
+ EXPECT_EQ(expectedRepetitions, decoder->repetitionCount());
+}
+
+
+} // Anonymous namespace
+
+// Animated PNG Tests
+
+TEST(AnimatedPNGTests, FrameCountTest)
+{
+ testFrameCount("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png", 20);
+ testFrameCount("/LayoutTests/fast/images/resources/png-animated-idat-not-part-of-animation.png", 1);
+}
+
+// TODO(joostouwerling): make animated PNG's with a non-infinite rep count.
+TEST(AnimatedPNGTests, repetitionCountTest)
+{
+ testRepetitionCount("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png", cAnimationLoopInfinite);
+ testRepetitionCount("/LayoutTests/fast/images/resources/png-animated-idat-not-part-of-animation.png", cAnimationLoopInfinite);
+}
+
+TEST(AnimatedPNGTests, sizeTest)
+{
+ testSize("/LayoutTests/fast/images/resources/png-animated-idat-part-of-animation.png", IntSize(100, 100));
+ testSize("/LayoutTests/fast/images/resources/png-animated-idat-not-part-of-animation.png", IntSize(227, 35));
+}
+
+// Static PNG tests
+
+TEST(StaticPNGTests, FrameCountTest)
+{
+ testFrameCount("/LayoutTests/fast/images/resources/png-simple.png", 1);
+}
+
+TEST(StaticPNGTests, repetitionCountTest)
+{
+ testRepetitionCount("/LayoutTests/fast/images/resources/png-simple.png", cAnimationNone);
+}
+
+TEST(StaticPNGTests, sizeTest)
+{
+ testSize("/LayoutTests/fast/images/resources/png-simple.png", IntSize(272, 92));
+}
+}; // namespace blink

Powered by Google App Engine
This is Rietveld 408576698