OLD | NEW |
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 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 // Frame is not complete, even after decoding partially. | 1019 // Frame is not complete, even after decoding partially. |
1020 EXPECT_FALSE(decoder->FrameIsCompleteAtIndex(0)); | 1020 EXPECT_FALSE(decoder->FrameIsCompleteAtIndex(0)); |
1021 auto* frame = decoder->FrameBufferAtIndex(0); | 1021 auto* frame = decoder->FrameBufferAtIndex(0); |
1022 ASSERT_TRUE(frame); | 1022 ASSERT_TRUE(frame); |
1023 EXPECT_NE(ImageFrame::kFrameComplete, frame->GetStatus()); | 1023 EXPECT_NE(ImageFrame::kFrameComplete, frame->GetStatus()); |
1024 EXPECT_FALSE(decoder->FrameIsCompleteAtIndex(0)); | 1024 EXPECT_FALSE(decoder->FrameIsCompleteAtIndex(0)); |
1025 | 1025 |
1026 decoder->SetData(full_data.Get(), true); | 1026 decoder->SetData(full_data.Get(), true); |
1027 | 1027 |
1028 // With full data, parsing the size still does not mark a frame as | 1028 // With full data, parsing the size still does not mark a frame as |
1029 // complete. | 1029 // complete for animated images. |
1030 EXPECT_TRUE(decoder->IsSizeAvailable()); | 1030 EXPECT_TRUE(decoder->IsSizeAvailable()); |
1031 EXPECT_FALSE(decoder->FrameIsCompleteAtIndex(0)); | 1031 if (rec.expected_frame_count > 1) |
| 1032 EXPECT_FALSE(decoder->FrameIsCompleteAtIndex(0)); |
| 1033 else |
| 1034 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(0)); |
1032 | 1035 |
1033 const auto frame_count = decoder->FrameCount(); | 1036 const auto frame_count = decoder->FrameCount(); |
1034 ASSERT_EQ(rec.expected_frame_count, frame_count); | 1037 ASSERT_EQ(rec.expected_frame_count, frame_count); |
1035 | 1038 |
1036 if (frame_count > 1u) { | 1039 // After parsing (the full file), all frames are complete. |
1037 // After parsing (the full file), all frames are complete. | 1040 for (size_t i = 0; i < frame_count; ++i) |
1038 for (size_t i = 0; i < frame_count; ++i) | 1041 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(i)); |
1039 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(i)); | |
1040 } else { | |
1041 // A single frame image is not reported complete until decoding. | |
1042 EXPECT_FALSE(decoder->FrameIsCompleteAtIndex(0)); | |
1043 } | |
1044 | 1042 |
1045 frame = decoder->FrameBufferAtIndex(0); | 1043 frame = decoder->FrameBufferAtIndex(0); |
1046 ASSERT_TRUE(frame); | 1044 ASSERT_TRUE(frame); |
1047 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus()); | 1045 EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus()); |
1048 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(0)); | 1046 EXPECT_TRUE(decoder->FrameIsCompleteAtIndex(0)); |
1049 } | 1047 } |
1050 } | 1048 } |
1051 | 1049 |
1052 TEST(PNGTests, sizeMayOverflow) { | 1050 TEST(PNGTests, sizeMayOverflow) { |
1053 auto decoder = | 1051 auto decoder = |
1054 CreateDecoderWithPngData("/LayoutTests/images/resources/crbug702934.png"); | 1052 CreateDecoderWithPngData("/LayoutTests/images/resources/crbug702934.png"); |
1055 EXPECT_FALSE(decoder->IsSizeAvailable()); | 1053 EXPECT_FALSE(decoder->IsSizeAvailable()); |
1056 EXPECT_TRUE(decoder->Failed()); | 1054 EXPECT_TRUE(decoder->Failed()); |
1057 } | 1055 } |
1058 | 1056 |
1059 }; // namespace blink | 1057 }; // namespace blink |
OLD | NEW |