| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 if (parse_error_expected) { | 69 if (parse_error_expected) { |
| 70 EXPECT_EQ(0u, decoder->FrameCount()); | 70 EXPECT_EQ(0u, decoder->FrameCount()); |
| 71 EXPECT_FALSE(decoder->FrameBufferAtIndex(0)); | 71 EXPECT_FALSE(decoder->FrameBufferAtIndex(0)); |
| 72 } else { | 72 } else { |
| 73 EXPECT_GT(decoder->FrameCount(), 0u); | 73 EXPECT_GT(decoder->FrameCount(), 0u); |
| 74 ImageFrame* frame = decoder->FrameBufferAtIndex(0); | 74 ImageFrame* frame = decoder->FrameBufferAtIndex(0); |
| 75 ASSERT_TRUE(frame); | 75 ASSERT_TRUE(frame); |
| 76 EXPECT_EQ(ImageFrame::kFramePartial, frame->GetStatus()); | 76 EXPECT_EQ(ImageFrame::kFramePartial, frame->GetStatus()); |
| 77 } | 77 } |
| 78 EXPECT_EQ(kAnimationLoopOnce, decoder->RepetitionCount()); | 78 EXPECT_EQ(kCAnimationLoopOnce, decoder->RepetitionCount()); |
| 79 EXPECT_TRUE(decoder->Failed()); | 79 EXPECT_TRUE(decoder->Failed()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // anonymous namespace | 82 } // anonymous namespace |
| 83 | 83 |
| 84 TEST(AnimatedWebPTests, uniqueGenerationIDs) { | 84 TEST(AnimatedWebPTests, uniqueGenerationIDs) { |
| 85 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); | 85 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); |
| 86 | 86 |
| 87 RefPtr<SharedBuffer> data = | 87 RefPtr<SharedBuffer> data = |
| 88 ReadFile("/LayoutTests/images/resources/webp-animated.webp"); | 88 ReadFile("/LayoutTests/images/resources/webp-animated.webp"); |
| 89 ASSERT_TRUE(data.Get()); | 89 ASSERT_TRUE(data.Get()); |
| 90 decoder->SetData(data.Get(), true); | 90 decoder->SetData(data.Get(), true); |
| 91 | 91 |
| 92 ImageFrame* frame = decoder->FrameBufferAtIndex(0); | 92 ImageFrame* frame = decoder->FrameBufferAtIndex(0); |
| 93 uint32_t generation_id0 = frame->Bitmap().getGenerationID(); | 93 uint32_t generation_id0 = frame->Bitmap().getGenerationID(); |
| 94 frame = decoder->FrameBufferAtIndex(1); | 94 frame = decoder->FrameBufferAtIndex(1); |
| 95 uint32_t generation_id1 = frame->Bitmap().getGenerationID(); | 95 uint32_t generation_id1 = frame->Bitmap().getGenerationID(); |
| 96 | 96 |
| 97 EXPECT_TRUE(generation_id0 != generation_id1); | 97 EXPECT_TRUE(generation_id0 != generation_id1); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST(AnimatedWebPTests, verifyAnimationParametersTransparentImage) { | 100 TEST(AnimatedWebPTests, verifyAnimationParametersTransparentImage) { |
| 101 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); | 101 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); |
| 102 EXPECT_EQ(kAnimationLoopOnce, decoder->RepetitionCount()); | 102 EXPECT_EQ(kCAnimationLoopOnce, decoder->RepetitionCount()); |
| 103 | 103 |
| 104 RefPtr<SharedBuffer> data = | 104 RefPtr<SharedBuffer> data = |
| 105 ReadFile("/LayoutTests/images/resources/webp-animated.webp"); | 105 ReadFile("/LayoutTests/images/resources/webp-animated.webp"); |
| 106 ASSERT_TRUE(data.Get()); | 106 ASSERT_TRUE(data.Get()); |
| 107 decoder->SetData(data.Get(), true); | 107 decoder->SetData(data.Get(), true); |
| 108 | 108 |
| 109 const int kCanvasWidth = 11; | 109 const int kCanvasWidth = 11; |
| 110 const int kCanvasHeight = 29; | 110 const int kCanvasHeight = 29; |
| 111 const struct AnimParam { | 111 const struct AnimParam { |
| 112 int x_offset, y_offset, width, height; | 112 int x_offset, y_offset, width, height; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 133 EXPECT_EQ(kFrameParameters[i].width, frame->OriginalFrameRect().Width()); | 133 EXPECT_EQ(kFrameParameters[i].width, frame->OriginalFrameRect().Width()); |
| 134 EXPECT_EQ(kFrameParameters[i].height, frame->OriginalFrameRect().Height()); | 134 EXPECT_EQ(kFrameParameters[i].height, frame->OriginalFrameRect().Height()); |
| 135 EXPECT_EQ(kFrameParameters[i].disposal_method, frame->GetDisposalMethod()); | 135 EXPECT_EQ(kFrameParameters[i].disposal_method, frame->GetDisposalMethod()); |
| 136 EXPECT_EQ(kFrameParameters[i].alpha_blend_source, | 136 EXPECT_EQ(kFrameParameters[i].alpha_blend_source, |
| 137 frame->GetAlphaBlendSource()); | 137 frame->GetAlphaBlendSource()); |
| 138 EXPECT_EQ(kFrameParameters[i].duration, frame->Duration()); | 138 EXPECT_EQ(kFrameParameters[i].duration, frame->Duration()); |
| 139 EXPECT_EQ(kFrameParameters[i].has_alpha, frame->HasAlpha()); | 139 EXPECT_EQ(kFrameParameters[i].has_alpha, frame->HasAlpha()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 EXPECT_EQ(WTF_ARRAY_LENGTH(kFrameParameters), decoder->FrameCount()); | 142 EXPECT_EQ(WTF_ARRAY_LENGTH(kFrameParameters), decoder->FrameCount()); |
| 143 EXPECT_EQ(kAnimationLoopInfinite, decoder->RepetitionCount()); | 143 EXPECT_EQ(kCAnimationLoopInfinite, decoder->RepetitionCount()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST(AnimatedWebPTests, | 146 TEST(AnimatedWebPTests, |
| 147 verifyAnimationParametersOpaqueFramesTransparentBackground) { | 147 verifyAnimationParametersOpaqueFramesTransparentBackground) { |
| 148 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); | 148 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); |
| 149 EXPECT_EQ(kAnimationLoopOnce, decoder->RepetitionCount()); | 149 EXPECT_EQ(kCAnimationLoopOnce, decoder->RepetitionCount()); |
| 150 | 150 |
| 151 RefPtr<SharedBuffer> data = | 151 RefPtr<SharedBuffer> data = |
| 152 ReadFile("/LayoutTests/images/resources/webp-animated-opaque.webp"); | 152 ReadFile("/LayoutTests/images/resources/webp-animated-opaque.webp"); |
| 153 ASSERT_TRUE(data.Get()); | 153 ASSERT_TRUE(data.Get()); |
| 154 decoder->SetData(data.Get(), true); | 154 decoder->SetData(data.Get(), true); |
| 155 | 155 |
| 156 const int kCanvasWidth = 94; | 156 const int kCanvasWidth = 94; |
| 157 const int kCanvasHeight = 87; | 157 const int kCanvasHeight = 87; |
| 158 const struct AnimParam { | 158 const struct AnimParam { |
| 159 int x_offset, y_offset, width, height; | 159 int x_offset, y_offset, width, height; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 182 EXPECT_EQ(kFrameParameters[i].width, frame->OriginalFrameRect().Width()); | 182 EXPECT_EQ(kFrameParameters[i].width, frame->OriginalFrameRect().Width()); |
| 183 EXPECT_EQ(kFrameParameters[i].height, frame->OriginalFrameRect().Height()); | 183 EXPECT_EQ(kFrameParameters[i].height, frame->OriginalFrameRect().Height()); |
| 184 EXPECT_EQ(kFrameParameters[i].disposal_method, frame->GetDisposalMethod()); | 184 EXPECT_EQ(kFrameParameters[i].disposal_method, frame->GetDisposalMethod()); |
| 185 EXPECT_EQ(kFrameParameters[i].alpha_blend_source, | 185 EXPECT_EQ(kFrameParameters[i].alpha_blend_source, |
| 186 frame->GetAlphaBlendSource()); | 186 frame->GetAlphaBlendSource()); |
| 187 EXPECT_EQ(kFrameParameters[i].duration, frame->Duration()); | 187 EXPECT_EQ(kFrameParameters[i].duration, frame->Duration()); |
| 188 EXPECT_EQ(kFrameParameters[i].has_alpha, frame->HasAlpha()); | 188 EXPECT_EQ(kFrameParameters[i].has_alpha, frame->HasAlpha()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 EXPECT_EQ(WTF_ARRAY_LENGTH(kFrameParameters), decoder->FrameCount()); | 191 EXPECT_EQ(WTF_ARRAY_LENGTH(kFrameParameters), decoder->FrameCount()); |
| 192 EXPECT_EQ(kAnimationLoopInfinite, decoder->RepetitionCount()); | 192 EXPECT_EQ(kCAnimationLoopInfinite, decoder->RepetitionCount()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 TEST(AnimatedWebPTests, verifyAnimationParametersBlendOverwrite) { | 195 TEST(AnimatedWebPTests, verifyAnimationParametersBlendOverwrite) { |
| 196 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); | 196 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); |
| 197 EXPECT_EQ(kAnimationLoopOnce, decoder->RepetitionCount()); | 197 EXPECT_EQ(kCAnimationLoopOnce, decoder->RepetitionCount()); |
| 198 | 198 |
| 199 RefPtr<SharedBuffer> data = | 199 RefPtr<SharedBuffer> data = |
| 200 ReadFile("/LayoutTests/images/resources/webp-animated-no-blend.webp"); | 200 ReadFile("/LayoutTests/images/resources/webp-animated-no-blend.webp"); |
| 201 ASSERT_TRUE(data.Get()); | 201 ASSERT_TRUE(data.Get()); |
| 202 decoder->SetData(data.Get(), true); | 202 decoder->SetData(data.Get(), true); |
| 203 | 203 |
| 204 const int kCanvasWidth = 94; | 204 const int kCanvasWidth = 94; |
| 205 const int kCanvasHeight = 87; | 205 const int kCanvasHeight = 87; |
| 206 const struct AnimParam { | 206 const struct AnimParam { |
| 207 int x_offset, y_offset, width, height; | 207 int x_offset, y_offset, width, height; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 230 EXPECT_EQ(kFrameParameters[i].width, frame->OriginalFrameRect().Width()); | 230 EXPECT_EQ(kFrameParameters[i].width, frame->OriginalFrameRect().Width()); |
| 231 EXPECT_EQ(kFrameParameters[i].height, frame->OriginalFrameRect().Height()); | 231 EXPECT_EQ(kFrameParameters[i].height, frame->OriginalFrameRect().Height()); |
| 232 EXPECT_EQ(kFrameParameters[i].disposal_method, frame->GetDisposalMethod()); | 232 EXPECT_EQ(kFrameParameters[i].disposal_method, frame->GetDisposalMethod()); |
| 233 EXPECT_EQ(kFrameParameters[i].alpha_blend_source, | 233 EXPECT_EQ(kFrameParameters[i].alpha_blend_source, |
| 234 frame->GetAlphaBlendSource()); | 234 frame->GetAlphaBlendSource()); |
| 235 EXPECT_EQ(kFrameParameters[i].duration, frame->Duration()); | 235 EXPECT_EQ(kFrameParameters[i].duration, frame->Duration()); |
| 236 EXPECT_EQ(kFrameParameters[i].has_alpha, frame->HasAlpha()); | 236 EXPECT_EQ(kFrameParameters[i].has_alpha, frame->HasAlpha()); |
| 237 } | 237 } |
| 238 | 238 |
| 239 EXPECT_EQ(WTF_ARRAY_LENGTH(kFrameParameters), decoder->FrameCount()); | 239 EXPECT_EQ(WTF_ARRAY_LENGTH(kFrameParameters), decoder->FrameCount()); |
| 240 EXPECT_EQ(kAnimationLoopInfinite, decoder->RepetitionCount()); | 240 EXPECT_EQ(kCAnimationLoopInfinite, decoder->RepetitionCount()); |
| 241 } | 241 } |
| 242 | 242 |
| 243 TEST(AnimatedWebPTests, parseAndDecodeByteByByte) { | 243 TEST(AnimatedWebPTests, parseAndDecodeByteByByte) { |
| 244 TestByteByByteDecode(&CreateDecoder, | 244 TestByteByByteDecode(&CreateDecoder, |
| 245 "/LayoutTests/images/resources/webp-animated.webp", 3u, | 245 "/LayoutTests/images/resources/webp-animated.webp", 3u, |
| 246 kAnimationLoopInfinite); | 246 kCAnimationLoopInfinite); |
| 247 TestByteByByteDecode( | 247 TestByteByByteDecode( |
| 248 &CreateDecoder, | 248 &CreateDecoder, |
| 249 "/LayoutTests/images/resources/webp-animated-icc-xmp.webp", 13u, 32000); | 249 "/LayoutTests/images/resources/webp-animated-icc-xmp.webp", 13u, 32000); |
| 250 } | 250 } |
| 251 | 251 |
| 252 TEST(AnimatedWebPTests, invalidImages) { | 252 TEST(AnimatedWebPTests, invalidImages) { |
| 253 // ANMF chunk size is smaller than ANMF header size. | 253 // ANMF chunk size is smaller than ANMF header size. |
| 254 TestInvalidImage("/LayoutTests/images/resources/invalid-animated-webp.webp", | 254 TestInvalidImage("/LayoutTests/images/resources/invalid-animated-webp.webp", |
| 255 true); | 255 true); |
| 256 // One of the frame rectangles extends outside the image boundary. | 256 // One of the frame rectangles extends outside the image boundary. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 ASSERT_TRUE(frame); | 320 ASSERT_TRUE(frame); |
| 321 EXPECT_EQ(ImageFrame::kFramePartial, frame->GetStatus()); | 321 EXPECT_EQ(ImageFrame::kFramePartial, frame->GetStatus()); |
| 322 EXPECT_FALSE(decoder->Failed()); | 322 EXPECT_FALSE(decoder->Failed()); |
| 323 | 323 |
| 324 // Parse full data now. The error in bitstream should now be detected. | 324 // Parse full data now. The error in bitstream should now be detected. |
| 325 decoder->SetData(full_data.Get(), true); | 325 decoder->SetData(full_data.Get(), true); |
| 326 EXPECT_EQ(1u, decoder->FrameCount()); | 326 EXPECT_EQ(1u, decoder->FrameCount()); |
| 327 frame = decoder->FrameBufferAtIndex(0); | 327 frame = decoder->FrameBufferAtIndex(0); |
| 328 ASSERT_TRUE(frame); | 328 ASSERT_TRUE(frame); |
| 329 EXPECT_EQ(ImageFrame::kFramePartial, frame->GetStatus()); | 329 EXPECT_EQ(ImageFrame::kFramePartial, frame->GetStatus()); |
| 330 EXPECT_EQ(kAnimationLoopOnce, decoder->RepetitionCount()); | 330 EXPECT_EQ(kCAnimationLoopOnce, decoder->RepetitionCount()); |
| 331 EXPECT_TRUE(decoder->Failed()); | 331 EXPECT_TRUE(decoder->Failed()); |
| 332 } | 332 } |
| 333 | 333 |
| 334 TEST(AnimatedWebPTests, progressiveDecode) { | 334 TEST(AnimatedWebPTests, progressiveDecode) { |
| 335 TestProgressiveDecoding(&CreateDecoder, | 335 TestProgressiveDecoding(&CreateDecoder, |
| 336 "/LayoutTests/images/resources/webp-animated.webp"); | 336 "/LayoutTests/images/resources/webp-animated.webp"); |
| 337 } | 337 } |
| 338 | 338 |
| 339 TEST(AnimatedWebPTests, frameIsCompleteAndDuration) { | 339 TEST(AnimatedWebPTests, frameIsCompleteAndDuration) { |
| 340 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); | 340 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 &CreateDecoder, | 425 &CreateDecoder, |
| 426 "/LayoutTests/images/resources/webp-animated-semitransparent3.webp"); | 426 "/LayoutTests/images/resources/webp-animated-semitransparent3.webp"); |
| 427 TestAlphaBlending( | 427 TestAlphaBlending( |
| 428 &CreateDecoder, | 428 &CreateDecoder, |
| 429 "/LayoutTests/images/resources/webp-animated-semitransparent4.webp"); | 429 "/LayoutTests/images/resources/webp-animated-semitransparent4.webp"); |
| 430 } | 430 } |
| 431 | 431 |
| 432 TEST(AnimatedWebPTests, isSizeAvailable) { | 432 TEST(AnimatedWebPTests, isSizeAvailable) { |
| 433 TestByteByByteSizeAvailable( | 433 TestByteByByteSizeAvailable( |
| 434 &CreateDecoder, "/LayoutTests/images/resources/webp-animated.webp", 142u, | 434 &CreateDecoder, "/LayoutTests/images/resources/webp-animated.webp", 142u, |
| 435 false, kAnimationLoopInfinite); | 435 false, kCAnimationLoopInfinite); |
| 436 // FIXME: Add color profile support for animated webp images. | 436 // FIXME: Add color profile support for animated webp images. |
| 437 TestByteByByteSizeAvailable( | 437 TestByteByByteSizeAvailable( |
| 438 &CreateDecoder, | 438 &CreateDecoder, |
| 439 "/LayoutTests/images/resources/webp-animated-icc-xmp.webp", 1404u, false, | 439 "/LayoutTests/images/resources/webp-animated-icc-xmp.webp", 1404u, false, |
| 440 32000); | 440 32000); |
| 441 } | 441 } |
| 442 | 442 |
| 443 TEST(AnimatedWEBPTests, clearCacheExceptFrameWithAncestors) { | 443 TEST(AnimatedWEBPTests, clearCacheExceptFrameWithAncestors) { |
| 444 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); | 444 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); |
| 445 | 445 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 TestInvalidImage("/LayoutTests/images/resources/truncated.webp", false); | 521 TestInvalidImage("/LayoutTests/images/resources/truncated.webp", false); |
| 522 // Chunk size in RIFF header doesn't match the file size. | 522 // Chunk size in RIFF header doesn't match the file size. |
| 523 TestInvalidImage("/LayoutTests/images/resources/truncated2.webp", true); | 523 TestInvalidImage("/LayoutTests/images/resources/truncated2.webp", true); |
| 524 } | 524 } |
| 525 | 525 |
| 526 // Regression test for a bug where some valid images were failing to decode | 526 // Regression test for a bug where some valid images were failing to decode |
| 527 // incrementally. | 527 // incrementally. |
| 528 TEST(StaticWebPTests, incrementalDecode) { | 528 TEST(StaticWebPTests, incrementalDecode) { |
| 529 TestByteByByteDecode(&CreateDecoder, | 529 TestByteByByteDecode(&CreateDecoder, |
| 530 "/LayoutTests/images/resources/crbug.364830.webp", 1u, | 530 "/LayoutTests/images/resources/crbug.364830.webp", 1u, |
| 531 kAnimationNone); | 531 kCAnimationNone); |
| 532 } | 532 } |
| 533 | 533 |
| 534 TEST(StaticWebPTests, isSizeAvailable) { | 534 TEST(StaticWebPTests, isSizeAvailable) { |
| 535 TestByteByByteSizeAvailable( | 535 TestByteByByteSizeAvailable( |
| 536 &CreateDecoder, | 536 &CreateDecoder, |
| 537 "/LayoutTests/images/resources/webp-color-profile-lossy.webp", 520u, true, | 537 "/LayoutTests/images/resources/webp-color-profile-lossy.webp", 520u, true, |
| 538 kAnimationNone); | 538 kCAnimationNone); |
| 539 TestByteByByteSizeAvailable(&CreateDecoder, | 539 TestByteByByteSizeAvailable(&CreateDecoder, |
| 540 "/LayoutTests/images/resources/test.webp", 30u, | 540 "/LayoutTests/images/resources/test.webp", 30u, |
| 541 false, kAnimationNone); | 541 false, kCAnimationNone); |
| 542 } | 542 } |
| 543 | 543 |
| 544 TEST(StaticWebPTests, notAnimated) { | 544 TEST(StaticWebPTests, notAnimated) { |
| 545 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); | 545 std::unique_ptr<ImageDecoder> decoder = CreateDecoder(); |
| 546 RefPtr<SharedBuffer> data = | 546 RefPtr<SharedBuffer> data = |
| 547 ReadFile("/LayoutTests/images/resources/webp-color-profile-lossy.webp"); | 547 ReadFile("/LayoutTests/images/resources/webp-color-profile-lossy.webp"); |
| 548 ASSERT_TRUE(data.Get()); | 548 ASSERT_TRUE(data.Get()); |
| 549 decoder->SetData(data.Get(), true); | 549 decoder->SetData(data.Get(), true); |
| 550 EXPECT_EQ(1u, decoder->FrameCount()); | 550 EXPECT_EQ(1u, decoder->FrameCount()); |
| 551 EXPECT_EQ(kAnimationNone, decoder->RepetitionCount()); | 551 EXPECT_EQ(kCAnimationNone, decoder->RepetitionCount()); |
| 552 } | 552 } |
| 553 | 553 |
| 554 } // namespace blink | 554 } // namespace blink |
| OLD | NEW |