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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2016 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "platform/image-decoders/png/PNGImageDecoder.h"
32
33 #include "platform/RuntimeEnabledFeatures.h"
34 #include "platform/SharedBuffer.h"
35 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
36 #include "public/platform/WebData.h"
37 #include "public/platform/WebSize.h"
38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "wtf/PtrUtil.h"
40 #include "wtf/Vector.h"
41 #include "wtf/dtoa/utils.h"
42 #include <memory>
43
44 namespace blink {
45
46 namespace {
47
48 std::unique_ptr<ImageDecoder> createDecoder(ImageDecoder::AlphaOption alphaOptio n)
49 {
50 return wrapUnique(new PNGImageDecoder(alphaOption,
51 ImageDecoder::GammaAndColorProfileAppl ied,
52 ImageDecoder::noDecodedImageByteLimit) );
53 }
54
55 std::unique_ptr<ImageDecoder> createDecoder()
56 {
57 return createDecoder(ImageDecoder::AlphaNotPremultiplied);
58 }
59
60 std::unique_ptr<ImageDecoder> createDecoderWithPngData(const char* pngFile)
61 {
62 auto decoder = createDecoder();
63 auto data = readFile(pngFile);
64 decoder->setData(data.get(), true);
65 EXPECT_EQ(false, data.get()->isEmpty());
joostouwerling 2016/10/01 19:59:05 Line 65 is a little weird, changed it to data()->i
66 return decoder;
67 }
68
69 void testFrameCount(const char* pngFile, size_t expectedFrameCount)
70 {
71 auto decoder = createDecoderWithPngData(pngFile);
72 EXPECT_EQ(expectedFrameCount, decoder->frameCount());
73 }
74
75 void testSize(const char* pngFile, IntSize expectedSize)
76 {
77 auto decoder = createDecoderWithPngData(pngFile);
78 EXPECT_EQ(true, decoder->isSizeAvailable());
79 EXPECT_EQ(expectedSize, decoder->size());
80 }
81
82 void testRepetitionCount(const char* pngFile, int expectedRepetitions)
83 {
84 auto decoder = createDecoderWithPngData(pngFile);
85 // Decode frame count should see the number of repetitions as well.
86 decoder->frameCount();
87 EXPECT_EQ(false, decoder->failed());
88 EXPECT_EQ(expectedRepetitions, decoder->repetitionCount());
89 }
90
91
92 } // Anonymous namespace
93
94 // Animated PNG Tests
95
96 TEST(AnimatedPNGTests, FrameCountTest)
97 {
98 testFrameCount("/LayoutTests/fast/images/resources/png-animated-idat-part-of -animation.png", 20);
99 testFrameCount("/LayoutTests/fast/images/resources/png-animated-idat-not-par t-of-animation.png", 1);
100 }
101
102 // TODO(joostouwerling): make animated PNG's with a non-infinite rep count.
103 TEST(AnimatedPNGTests, repetitionCountTest)
104 {
105 testRepetitionCount("/LayoutTests/fast/images/resources/png-animated-idat-pa rt-of-animation.png", cAnimationLoopInfinite);
106 testRepetitionCount("/LayoutTests/fast/images/resources/png-animated-idat-no t-part-of-animation.png", cAnimationLoopInfinite);
107 }
108
109 TEST(AnimatedPNGTests, sizeTest)
110 {
111 testSize("/LayoutTests/fast/images/resources/png-animated-idat-part-of-anima tion.png", IntSize(100, 100));
112 testSize("/LayoutTests/fast/images/resources/png-animated-idat-not-part-of-a nimation.png", IntSize(227, 35));
113 }
114
115 // Static PNG tests
116
117 TEST(StaticPNGTests, FrameCountTest)
118 {
119 testFrameCount("/LayoutTests/fast/images/resources/png-simple.png", 1);
120 }
121
122 TEST(StaticPNGTests, repetitionCountTest)
123 {
124 testRepetitionCount("/LayoutTests/fast/images/resources/png-simple.png", cAn imationNone);
125 }
126
127 TEST(StaticPNGTests, sizeTest)
128 {
129 testSize("/LayoutTests/fast/images/resources/png-simple.png", IntSize(272, 9 2));
130 }
131 }; // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698