Index: third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp |
diff --git a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp |
index 8c4e988b4ca6653476eb4df645c89a6ac8288843..d7ff80ed8abbd1d06688ce880514bd98bcf0a116 100644 |
--- a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp |
+++ b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoderTest.cpp |
@@ -406,4 +406,34 @@ TEST(GIFImageDecoderTest, bitmapAlphaType) { |
EXPECT_EQ(unpremulFrame->bitmap().alphaType(), kOpaque_SkAlphaType); |
} |
+namespace { |
+// Needed to exercise ImageDecoder::setMemoryAllocator, but still does the |
+// default allocation. |
+class Allocator final : public SkBitmap::Allocator { |
+ bool allocPixelRef(SkBitmap* dst, SkColorTable* ctable) override { |
+ return dst->tryAllocPixels(ctable); |
+ } |
+}; |
+} |
+ |
+// Ensure that calling setMemoryAllocator does not short-circuit |
+// initializeNewFrame. |
+TEST(GIFImageDecoderTest, externalAllocator) { |
+ auto data = readFile(layoutTestResourcesDir, "boston.gif"); |
+ ASSERT_TRUE(data.get()); |
+ |
+ auto decoder = createDecoder(); |
+ decoder->setData(data.get(), true); |
+ |
+ Allocator allocator; |
+ decoder->setMemoryAllocator(&allocator); |
+ EXPECT_EQ(1u, decoder->frameCount()); |
+ ImageFrame* frame = decoder->frameBufferAtIndex(0); |
+ decoder->setMemoryAllocator(nullptr); |
+ |
+ ASSERT_TRUE(frame); |
+ EXPECT_EQ(IntRect(IntPoint(), decoder->size()), frame->originalFrameRect()); |
+ EXPECT_FALSE(frame->hasAlpha()); |
+} |
+ |
} // namespace blink |