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

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

Issue 2565323003: Move gif image decoder to SkCodec (Closed)
Patch Set: Remove invalid disposal method test Created 3 years, 11 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 73
74 } // anonymous namespace 74 } // anonymous namespace
75 75
76 TEST(GIFImageDecoderTest, decodeTwoFrames) { 76 TEST(GIFImageDecoderTest, decodeTwoFrames) {
77 std::unique_ptr<ImageDecoder> decoder = createDecoder(); 77 std::unique_ptr<ImageDecoder> decoder = createDecoder();
78 78
79 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif"); 79 RefPtr<SharedBuffer> data = readFile(layoutTestResourcesDir, "animated.gif");
80 ASSERT_TRUE(data.get()); 80 ASSERT_TRUE(data.get());
81 decoder->setData(data.get(), true); 81 decoder->setData(data.get(), true);
82 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
83 82
84 ImageFrame* frame = decoder->frameBufferAtIndex(0); 83 ImageFrame* frame = decoder->frameBufferAtIndex(0);
85 uint32_t generationID0 = frame->bitmap().getGenerationID(); 84 uint32_t generationID0 = frame->bitmap().getGenerationID();
86 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); 85 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
87 EXPECT_EQ(16, frame->bitmap().width()); 86 EXPECT_EQ(16, frame->bitmap().width());
88 EXPECT_EQ(16, frame->bitmap().height()); 87 EXPECT_EQ(16, frame->bitmap().height());
89 88
90 frame = decoder->frameBufferAtIndex(1); 89 frame = decoder->frameBufferAtIndex(1);
91 uint32_t generationID1 = frame->bitmap().getGenerationID(); 90 uint32_t generationID1 = frame->bitmap().getGenerationID();
92 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus()); 91 EXPECT_EQ(ImageFrame::FrameComplete, frame->getStatus());
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 RefPtr<SharedBuffer> testData = readFile(decodersTestingDir, "bad-code.gif"); 299 RefPtr<SharedBuffer> testData = readFile(decodersTestingDir, "bad-code.gif");
301 ASSERT_TRUE(testData.get()); 300 ASSERT_TRUE(testData.get());
302 301
303 std::unique_ptr<ImageDecoder> testDecoder = createDecoder(); 302 std::unique_ptr<ImageDecoder> testDecoder = createDecoder();
304 testDecoder->setData(testData.get(), true); 303 testDecoder->setData(testData.get(), true);
305 EXPECT_EQ(1u, testDecoder->frameCount()); 304 EXPECT_EQ(1u, testDecoder->frameCount());
306 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0)); 305 ASSERT_TRUE(testDecoder->frameBufferAtIndex(0));
307 EXPECT_TRUE(testDecoder->failed()); 306 EXPECT_TRUE(testDecoder->failed());
308 } 307 }
309 308
310 TEST(GIFImageDecoderTest, invalidDisposalMethod) {
311 std::unique_ptr<ImageDecoder> decoder = createDecoder();
312
313 // The image has 2 frames, with disposal method 4 and 5, respectively.
314 RefPtr<SharedBuffer> data =
315 readFile(decodersTestingDir, "invalid-disposal-method.gif");
316 ASSERT_TRUE(data.get());
317 decoder->setData(data.get(), true);
318
319 EXPECT_EQ(2u, decoder->frameCount());
320 // Disposal method 4 is converted to ImageFrame::DisposeOverwritePrevious.
321 EXPECT_EQ(ImageFrame::DisposeOverwritePrevious,
322 decoder->frameBufferAtIndex(0)->getDisposalMethod());
323 // Disposal method 5 is ignored.
324 EXPECT_EQ(ImageFrame::DisposeNotSpecified,
325 decoder->frameBufferAtIndex(1)->getDisposalMethod());
326 }
327
328 TEST(GIFImageDecoderTest, firstFrameHasGreaterSizeThanScreenSize) { 309 TEST(GIFImageDecoderTest, firstFrameHasGreaterSizeThanScreenSize) {
329 RefPtr<SharedBuffer> fullData = readFile( 310 RefPtr<SharedBuffer> fullData = readFile(
330 decodersTestingDir, "first-frame-has-greater-size-than-screen-size.gif"); 311 decodersTestingDir, "first-frame-has-greater-size-than-screen-size.gif");
331 ASSERT_TRUE(fullData.get()); 312 ASSERT_TRUE(fullData.get());
332 313
333 std::unique_ptr<ImageDecoder> decoder; 314 std::unique_ptr<ImageDecoder> decoder;
334 IntSize frameSize; 315 IntSize frameSize;
335 316
336 // Compute hashes when the file is truncated. 317 // Compute hashes when the file is truncated.
337 for (size_t i = 1; i <= fullData->size(); ++i) { 318 for (size_t i = 1; i <= fullData->size(); ++i) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 EXPECT_TRUE(premulFrame && 381 EXPECT_TRUE(premulFrame &&
401 premulFrame->getStatus() == ImageFrame::FrameComplete); 382 premulFrame->getStatus() == ImageFrame::FrameComplete);
402 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); 383 EXPECT_EQ(premulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
403 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0); 384 unpremulFrame = unpremulDecoder->frameBufferAtIndex(0);
404 EXPECT_TRUE(unpremulFrame && 385 EXPECT_TRUE(unpremulFrame &&
405 unpremulFrame->getStatus() == ImageFrame::FrameComplete); 386 unpremulFrame->getStatus() == ImageFrame::FrameComplete);
406 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); 387 EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType);
407 } 388 }
408 389
409 } // namespace blink 390 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698