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

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

Issue 2878363003: Revert of Fix ImageAnimation constant names after Blink renaming (Closed)
Patch Set: Created 3 years, 7 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/image-decoders/png/PNGImageDecoder.h" 5 #include "platform/image-decoders/png/PNGImageDecoder.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "platform/image-decoders/ImageDecoderTestHelpers.h" 8 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
9 #include "png.h" 9 #include "png.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 164
165 // Verify that a decoder with a parse error converts to a static image. 165 // Verify that a decoder with a parse error converts to a static image.
166 static void ExpectStatic(ImageDecoder* decoder) { 166 static void ExpectStatic(ImageDecoder* decoder) {
167 EXPECT_EQ(1u, decoder->FrameCount()); 167 EXPECT_EQ(1u, decoder->FrameCount());
168 EXPECT_FALSE(decoder->Failed()); 168 EXPECT_FALSE(decoder->Failed());
169 169
170 ImageFrame* frame = decoder->FrameBufferAtIndex(0); 170 ImageFrame* frame = decoder->FrameBufferAtIndex(0);
171 ASSERT_NE(nullptr, frame); 171 ASSERT_NE(nullptr, frame);
172 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus()); 172 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
173 EXPECT_FALSE(decoder->Failed()); 173 EXPECT_FALSE(decoder->Failed());
174 EXPECT_EQ(kAnimationNone, decoder->RepetitionCount()); 174 EXPECT_EQ(kCAnimationNone, decoder->RepetitionCount());
175 } 175 }
176 176
177 // Decode up to the indicated fcTL offset and then provide an fcTL with the 177 // Decode up to the indicated fcTL offset and then provide an fcTL with the
178 // wrong chunk size (20 instead of 26). 178 // wrong chunk size (20 instead of 26).
179 void TestInvalidFctlSize(const char* png_file, 179 void TestInvalidFctlSize(const char* png_file,
180 size_t offset_fctl, 180 size_t offset_fctl,
181 size_t expected_frame_count, 181 size_t expected_frame_count,
182 bool should_fail) { 182 bool should_fail) {
183 auto data = ReadFile(png_file); 183 auto data = ReadFile(png_file);
184 ASSERT_FALSE(data->IsEmpty()); 184 ASSERT_FALSE(data->IsEmpty());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 TestRepetitionCount( 305 TestRepetitionCount(
306 "/LayoutTests/images/resources/" 306 "/LayoutTests/images/resources/"
307 "png-animated-idat-part-of-animation.png", 307 "png-animated-idat-part-of-animation.png",
308 6u); 308 6u);
309 // This is an "animated" image with only one frame, that is, the IDAT is 309 // This is an "animated" image with only one frame, that is, the IDAT is
310 // ignored and there is one fdAT frame. so it should be considered 310 // ignored and there is one fdAT frame. so it should be considered
311 // non-animated. 311 // non-animated.
312 TestRepetitionCount( 312 TestRepetitionCount(
313 "/LayoutTests/images/resources/" 313 "/LayoutTests/images/resources/"
314 "png-animated-idat-not-part-of-animation.png", 314 "png-animated-idat-not-part-of-animation.png",
315 kAnimationNone); 315 kCAnimationNone);
316 } 316 }
317 317
318 // Test if the decoded metdata corresponds to the defined expectations 318 // Test if the decoded metdata corresponds to the defined expectations
319 TEST(AnimatedPNGTests, MetaDataTest) { 319 TEST(AnimatedPNGTests, MetaDataTest) {
320 const char* png_file = 320 const char* png_file =
321 "/LayoutTests/images/resources/" 321 "/LayoutTests/images/resources/"
322 "png-animated-idat-part-of-animation.png"; 322 "png-animated-idat-part-of-animation.png";
323 constexpr size_t kExpectedFrameCount = 4; 323 constexpr size_t kExpectedFrameCount = 4;
324 324
325 auto decoder = CreateDecoderWithPngData(png_file); 325 auto decoder = CreateDecoderWithPngData(png_file);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // Remove the acTL chunk from the stream. This results in a static image. 449 // Remove the acTL chunk from the stream. This results in a static image.
450 RefPtr<SharedBuffer> no_actl_data = 450 RefPtr<SharedBuffer> no_actl_data =
451 SharedBuffer::Create(data->Data(), kOffsetActl); 451 SharedBuffer::Create(data->Data(), kOffsetActl);
452 no_actl_data->Append(data->Data() + kOffsetActl + kAcTLSize, 452 no_actl_data->Append(data->Data() + kOffsetActl + kAcTLSize,
453 data->size() - kOffsetActl - kAcTLSize); 453 data->size() - kOffsetActl - kAcTLSize);
454 454
455 auto decoder = CreateDecoder(); 455 auto decoder = CreateDecoder();
456 decoder->SetData(no_actl_data, true); 456 decoder->SetData(no_actl_data, true);
457 EXPECT_EQ(1u, decoder->FrameCount()); 457 EXPECT_EQ(1u, decoder->FrameCount());
458 EXPECT_FALSE(decoder->Failed()); 458 EXPECT_FALSE(decoder->Failed());
459 EXPECT_EQ(kAnimationNone, decoder->RepetitionCount()); 459 EXPECT_EQ(kCAnimationNone, decoder->RepetitionCount());
460 } 460 }
461 461
462 // Store the acTL for more tests. 462 // Store the acTL for more tests.
463 char ac_tl[kAcTLSize]; 463 char ac_tl[kAcTLSize];
464 memcpy(ac_tl, data->Data() + kOffsetActl, kAcTLSize); 464 memcpy(ac_tl, data->Data() + kOffsetActl, kAcTLSize);
465 465
466 // Insert an extra acTL at a couple of different offsets. 466 // Insert an extra acTL at a couple of different offsets.
467 // Prior to the IDAT, this should result in a static image. After, this 467 // Prior to the IDAT, this should result in a static image. After, this
468 // should fail. 468 // should fail.
469 const struct { 469 const struct {
(...skipping 29 matching lines...) Expand all
499 SharedBuffer::Create(data2->Data(), kPostIDATOffset); 499 SharedBuffer::Create(data2->Data(), kPostIDATOffset);
500 for (size_t i = 0; i < times; i++) 500 for (size_t i = 0; i < times; i++)
501 extra_actl_data->Append(ac_tl, kAcTLSize); 501 extra_actl_data->Append(ac_tl, kAcTLSize);
502 extra_actl_data->Append(data2->Data() + kPostIDATOffset, 502 extra_actl_data->Append(data2->Data() + kPostIDATOffset,
503 data2->size() - kPostIDATOffset); 503 data2->size() - kPostIDATOffset);
504 504
505 auto decoder = CreateDecoder(); 505 auto decoder = CreateDecoder();
506 decoder->SetData(extra_actl_data, true); 506 decoder->SetData(extra_actl_data, true);
507 EXPECT_EQ(1u, decoder->FrameCount()); 507 EXPECT_EQ(1u, decoder->FrameCount());
508 EXPECT_FALSE(decoder->Failed()); 508 EXPECT_FALSE(decoder->Failed());
509 EXPECT_EQ(kAnimationNone, decoder->RepetitionCount()); 509 EXPECT_EQ(kCAnimationNone, decoder->RepetitionCount());
510 EXPECT_NE(nullptr, decoder->FrameBufferAtIndex(0)); 510 EXPECT_NE(nullptr, decoder->FrameBufferAtIndex(0));
511 EXPECT_FALSE(decoder->Failed()); 511 EXPECT_FALSE(decoder->Failed());
512 } 512 }
513 } 513 }
514 } 514 }
515 515
516 TEST(AnimatedPNGTests, fdatBeforeIdat) { 516 TEST(AnimatedPNGTests, fdatBeforeIdat) {
517 const char* png_file = 517 const char* png_file =
518 "/LayoutTests/images/resources/" 518 "/LayoutTests/images/resources/"
519 "png-animated-idat-not-part-of-animation.png"; 519 "png-animated-idat-not-part-of-animation.png";
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 data->Append(reinterpret_cast<const char*>(fc_tl), kFcTLSize); 929 data->Append(reinterpret_cast<const char*>(fc_tl), kFcTLSize);
930 930
931 // Append the rest of the data. 931 // Append the rest of the data.
932 // Note: If PNGImageDecoder changes to reject an image with too many 932 // Note: If PNGImageDecoder changes to reject an image with too many
933 // rows, the fdAT data will need to be modified as well. 933 // rows, the fdAT data will need to be modified as well.
934 data->Append(original_data->Data() + kFcTLOffset + kFcTLSize, 934 data->Append(original_data->Data() + kFcTLOffset + kFcTLSize,
935 original_data->size() - data->size()); 935 original_data->size() - data->size());
936 ASSERT_EQ(original_data->size(), data->size()); 936 ASSERT_EQ(original_data->size(), data->size());
937 937
938 // This will test both byte by byte and using the full data, and compare. 938 // This will test both byte by byte and using the full data, and compare.
939 TestByteByByteDecode(CreateDecoder, data.Get(), 1, kAnimationNone); 939 TestByteByByteDecode(CreateDecoder, data.Get(), 1, kCAnimationNone);
940 } 940 }
941 941
942 // Static PNG tests 942 // Static PNG tests
943 943
944 TEST(StaticPNGTests, repetitionCountTest) { 944 TEST(StaticPNGTests, repetitionCountTest) {
945 TestRepetitionCount("/LayoutTests/images/resources/png-simple.png", 945 TestRepetitionCount("/LayoutTests/images/resources/png-simple.png",
946 kAnimationNone); 946 kCAnimationNone);
947 } 947 }
948 948
949 TEST(StaticPNGTests, sizeTest) { 949 TEST(StaticPNGTests, sizeTest) {
950 TestSize("/LayoutTests/images/resources/png-simple.png", IntSize(111, 29)); 950 TestSize("/LayoutTests/images/resources/png-simple.png", IntSize(111, 29));
951 } 951 }
952 952
953 TEST(StaticPNGTests, MetaDataTest) { 953 TEST(StaticPNGTests, MetaDataTest) {
954 const size_t kExpectedFrameCount = 1; 954 const size_t kExpectedFrameCount = 1;
955 const size_t kExpectedDuration = 0; 955 const size_t kExpectedDuration = 0;
956 auto decoder = 956 auto decoder =
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 } 1050 }
1051 1051
1052 TEST(PNGTests, sizeMayOverflow) { 1052 TEST(PNGTests, sizeMayOverflow) {
1053 auto decoder = 1053 auto decoder =
1054 CreateDecoderWithPngData("/LayoutTests/images/resources/crbug702934.png"); 1054 CreateDecoderWithPngData("/LayoutTests/images/resources/crbug702934.png");
1055 EXPECT_FALSE(decoder->IsSizeAvailable()); 1055 EXPECT_FALSE(decoder->IsSizeAvailable());
1056 EXPECT_TRUE(decoder->Failed()); 1056 EXPECT_TRUE(decoder->Failed());
1057 } 1057 }
1058 1058
1059 }; // namespace blink 1059 }; // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698