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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp

Issue 2385993002: Rewrap comments to 80 columns in Source/platform/image-decoders/. (Closed)
Patch Set: Rewrite comment 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
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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 hashBitmap(testFrame->bitmap())); 356 hashBitmap(testFrame->bitmap()));
357 } 357 }
358 358
359 TEST(GIFImageDecoderTest, updateRequiredPreviousFrameAfterFirstDecode) { 359 TEST(GIFImageDecoderTest, updateRequiredPreviousFrameAfterFirstDecode) {
360 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 360 std::unique_ptr<ImageDecoder> decoder = createDecoder();
361 361
362 RefPtr<SharedBuffer> fullData = 362 RefPtr<SharedBuffer> fullData =
363 readFile(layoutTestResourcesDir, "animated-10color.gif"); 363 readFile(layoutTestResourcesDir, "animated-10color.gif");
364 ASSERT_TRUE(fullData.get()); 364 ASSERT_TRUE(fullData.get());
365 365
366 // Give it data that is enough to parse but not decode in order to check the s tatus 366 // Give it data that is enough to parse but not decode in order to check the
367 // status.
367 // of requiredPreviousFrameIndex before decoding. 368 // of requiredPreviousFrameIndex before decoding.
368 size_t partialSize = 1; 369 size_t partialSize = 1;
369 do { 370 do {
370 RefPtr<SharedBuffer> data = 371 RefPtr<SharedBuffer> data =
371 SharedBuffer::create(fullData->data(), partialSize); 372 SharedBuffer::create(fullData->data(), partialSize);
372 decoder->setData(data.get(), false); 373 decoder->setData(data.get(), false);
373 ++partialSize; 374 ++partialSize;
374 } while (!decoder->frameCount() || 375 } while (!decoder->frameCount() ||
375 decoder->frameBufferAtIndex(0)->getStatus() == 376 decoder->frameBufferAtIndex(0)->getStatus() ==
376 ImageFrame::FrameEmpty); 377 ImageFrame::FrameEmpty);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 EXPECT_EQ(baselineHashes[frameCount - 1], hashBitmap(lastFrame->bitmap())); 436 EXPECT_EQ(baselineHashes[frameCount - 1], hashBitmap(lastFrame->bitmap()));
436 decoder->clearCacheExceptFrame(kNotFound); 437 decoder->clearCacheExceptFrame(kNotFound);
437 438
438 // Resume decoding of the first frame. 439 // Resume decoding of the first frame.
439 ImageFrame* firstFrame = decoder->frameBufferAtIndex(0); 440 ImageFrame* firstFrame = decoder->frameBufferAtIndex(0);
440 EXPECT_EQ(ImageFrame::FrameComplete, firstFrame->getStatus()); 441 EXPECT_EQ(ImageFrame::FrameComplete, firstFrame->getStatus());
441 EXPECT_EQ(baselineHashes[0], hashBitmap(firstFrame->bitmap())); 442 EXPECT_EQ(baselineHashes[0], hashBitmap(firstFrame->bitmap()));
442 } 443 }
443 444
444 // The first LZW codes in the image are invalid values that try to create a loop 445 // The first LZW codes in the image are invalid values that try to create a loop
445 // in the dictionary. Decoding should fail, but not infinitely loop or corrupt m emory. 446 // in the dictionary. Decoding should fail, but not infinitely loop or corrupt
447 // memory.
446 TEST(GIFImageDecoderTest, badInitialCode) { 448 TEST(GIFImageDecoderTest, badInitialCode) {
447 RefPtr<SharedBuffer> testData = 449 RefPtr<SharedBuffer> testData =
448 readFile(decodersTestingDir, "bad-initial-code.gif"); 450 readFile(decodersTestingDir, "bad-initial-code.gif");
449 ASSERT_TRUE(testData.get()); 451 ASSERT_TRUE(testData.get());
450 452
451 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); 453 std::unique_ptr<ImageDecoder> testDecoder = createDecoder();
452 testDecoder->setData(testData.get(), true); 454 testDecoder->setData(testData.get(), true);
453 EXPECT_EQ(1u, testDecoder->frameCount()); 455 EXPECT_EQ(1u, testDecoder->frameCount());
454 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); 456 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0));
455 EXPECT_TRUE(testDecoder->failed()); 457 EXPECT_TRUE(testDecoder->failed());
456 } 458 }
457 459
458 // The image has an invalid LZW code that exceeds dictionary size. Decoding shou ld fail. 460 // The image has an invalid LZW code that exceeds dictionary size. Decoding
461 // should fail.
459 TEST(GIFImageDecoderTest, badCode) { 462 TEST(GIFImageDecoderTest, badCode) {
460 RefPtr<SharedBuffer> testData = readFile(decodersTestingDir, "bad-code.gif"); 463 RefPtr<SharedBuffer> testData = readFile(decodersTestingDir, "bad-code.gif");
461 ASSERT_TRUE(testData.get()); 464 ASSERT_TRUE(testData.get());
462 465
463 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); 466 std::unique_ptr<ImageDecoder> testDecoder = createDecoder();
464 testDecoder->setData(testData.get(), true); 467 testDecoder->setData(testData.get(), true);
465 EXPECT_EQ(1u, testDecoder->frameCount()); 468 EXPECT_EQ(1u, testDecoder->frameCount());
466 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); 469 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0));
467 EXPECT_TRUE(testDecoder->failed()); 470 EXPECT_TRUE(testDecoder->failed());
468 } 471 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 545
543 std::unique_ptr<ImageDecoder> premulDecoder = 546 std::unique_ptr<ImageDecoder> premulDecoder =
544 wrapUnique(new GIFImageDecoder(ImageDecoder::AlphaPremultiplied, 547 wrapUnique(new GIFImageDecoder(ImageDecoder::AlphaPremultiplied,
545 ImageDecoder::GammaAndColorProfileApplied, 548 ImageDecoder::GammaAndColorProfileApplied,
546 ImageDecoder::noDecodedImageByteLimit)); 549 ImageDecoder::noDecodedImageByteLimit));
547 std::unique_ptr<ImageDecoder> unpremulDecoder = 550 std::unique_ptr<ImageDecoder> unpremulDecoder =
548 wrapUnique(new GIFImageDecoder(ImageDecoder::AlphaNotPremultiplied, 551 wrapUnique(new GIFImageDecoder(ImageDecoder::AlphaNotPremultiplied,
549 ImageDecoder::GammaAndColorProfileApplied, 552 ImageDecoder::GammaAndColorProfileApplied,
550 ImageDecoder::noDecodedImageByteLimit)); 553 ImageDecoder::noDecodedImageByteLimit));
551 554
552 // Partially decoded frame => the frame alpha type is unknown and should refle ct the requested format. 555 // Partially decoded frame => the frame alpha type is unknown and should
556 // reflect the requested format.
553 premulDecoder->setData(partialData.get(), false); 557 premulDecoder->setData(partialData.get(), false);
554 ASSERT_TRUE(premulDecoder->frameCount()); 558 ASSERT_TRUE(premulDecoder->frameCount());
555 unpremulDecoder->setData(partialData.get(), false); 559 unpremulDecoder->setData(partialData.get(), false);
556 ASSERT_TRUE(unpremulDecoder->frameCount()); 560 ASSERT_TRUE(unpremulDecoder->frameCount());
557 ImageFrame* premulFrame = premulDecoder->frameBufferAtIndex(0); 561 ImageFrame* premulFrame = premulDecoder->frameBufferAtIndex(0);
558 EXPECT_TRUE(premulFrame && 562 EXPECT_TRUE(premulFrame &&
559 premulFrame->getStatus() != ImageFrame::FrameComplete); 563 premulFrame->getStatus() != ImageFrame::FrameComplete);
560 EXPECT_EQ(premulFrame->bitmap().alphaType(), kPremul_SkAlphaType); 564 EXPECT_EQ(premulFrame->bitmap().alphaType(), kPremul_SkAlphaType);
561 ImageFrame* unpremulFrame = unpremulDecoder->frameBufferAtIndex(0); 565 ImageFrame* unpremulFrame = unpremulDecoder->frameBufferAtIndex(0);
562 EXPECT_TRUE(unpremulFrame && 566 EXPECT_TRUE(unpremulFrame &&
563 unpremulFrame->getStatus() != ImageFrame::FrameComplete); 567 unpremulFrame->getStatus() != ImageFrame::FrameComplete);
564 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kUnpremul_SkAlphaType); 568 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kUnpremul_SkAlphaType);
565 569
566 // Fully decoded frame => the frame alpha type is known (opaque). 570 // Fully decoded frame => the frame alpha type is known (opaque).
567 premulDecoder->setData(fullData.get(), true); 571 premulDecoder->setData(fullData.get(), true);
568 ASSERT_TRUE(premulDecoder->frameCount()); 572 ASSERT_TRUE(premulDecoder->frameCount());
569 unpremulDecoder->setData(fullData.get(), true); 573 unpremulDecoder->setData(fullData.get(), true);
570 ASSERT_TRUE(unpremulDecoder->frameCount()); 574 ASSERT_TRUE(unpremulDecoder->frameCount());
571 premulFrame = premulDecoder->frameBufferAtIndex(0); 575 premulFrame = premulDecoder->frameBufferAtIndex(0);
572 EXPECT_TRUE(premulFrame && 576 EXPECT_TRUE(premulFrame &&
573 premulFrame->getStatus() == ImageFrame::FrameComplete); 577 premulFrame->getStatus() == ImageFrame::FrameComplete);
574 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); 578 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
575 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0); 579 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0);
576 EXPECT_TRUE(unpremulFrame && 580 EXPECT_TRUE(unpremulFrame &&
577 unpremulFrame->getStatus() == ImageFrame::FrameComplete); 581 unpremulFrame->getStatus() == ImageFrame::FrameComplete);
578 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); 582 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
579 } 583 }
580 584
581 } // namespace blink 585 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698