This source file includes following definitions.
- filenameExtension
- frameBufferAtIndex
- frameBufferCache
- resetRequiredPreviousFrames
- initFrames
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "config.h"
#include "platform/image-decoders/ImageDecoder.h"
#include "platform/image-decoders/ImageFrame.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/Vector.h"
#include <gtest/gtest.h>
using namespace WebCore;
class TestImageDecoder : public ImageDecoder {
public:
TestImageDecoder()
: ImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied, noDecodedImageByteLimit)
{
}
virtual String filenameExtension() const OVERRIDE { return ""; }
virtual ImageFrame* frameBufferAtIndex(size_t) OVERRIDE { return 0; }
Vector<ImageFrame, 1>& frameBufferCache()
{
return m_frameBufferCache;
}
void resetRequiredPreviousFrames(bool knownOpaque = false)
{
for (size_t i = 0; i < m_frameBufferCache.size(); ++i)
m_frameBufferCache[i].setRequiredPreviousFrameIndex(findRequiredPreviousFrame(i, knownOpaque));
}
void initFrames(size_t numFrames, unsigned width = 100, unsigned height = 100)
{
setSize(width, height);
m_frameBufferCache.resize(numFrames);
for (size_t i = 0; i < numFrames; ++i)
m_frameBufferCache[i].setOriginalFrameRect(IntRect(0, 0, width, height));
}
};
TEST(ImageDecoderTest, sizeCalculationMayOverflow)
{
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
EXPECT_FALSE(decoder->setSize(1 << 29, 1));
EXPECT_FALSE(decoder->setSize(1, 1 << 29));
EXPECT_FALSE(decoder->setSize(1 << 15, 1 << 15));
EXPECT_TRUE(decoder->setSize(1 << 28, 1));
EXPECT_TRUE(decoder->setSize(1, 1 << 28));
EXPECT_TRUE(decoder->setSize(1 << 14, 1 << 14));
}
TEST(ImageDecoderTest, requiredPreviousFrameIndex)
{
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
decoder->initFrames(6);
Vector<ImageFrame, 1>& frameBuffers = decoder->frameBufferCache();
frameBuffers[1].setDisposalMethod(ImageFrame::DisposeKeep);
frameBuffers[2].setDisposalMethod(ImageFrame::DisposeOverwritePrevious);
frameBuffers[3].setDisposalMethod(ImageFrame::DisposeOverwritePrevious);
frameBuffers[4].setDisposalMethod(ImageFrame::DisposeKeep);
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(kNotFound, frameBuffers[0].requiredPreviousFrameIndex());
EXPECT_EQ(0u, frameBuffers[1].requiredPreviousFrameIndex());
EXPECT_EQ(1u, frameBuffers[2].requiredPreviousFrameIndex());
EXPECT_EQ(1u, frameBuffers[3].requiredPreviousFrameIndex());
EXPECT_EQ(1u, frameBuffers[4].requiredPreviousFrameIndex());
EXPECT_EQ(4u, frameBuffers[5].requiredPreviousFrameIndex());
}
TEST(ImageDecoderTest, requiredPreviousFrameIndexDisposeOverwriteBgcolor)
{
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
decoder->initFrames(3);
Vector<ImageFrame, 1>& frameBuffers = decoder->frameBufferCache();
frameBuffers[1].setDisposalMethod(ImageFrame::DisposeOverwriteBgcolor);
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(kNotFound, frameBuffers[2].requiredPreviousFrameIndex());
frameBuffers[1].setOriginalFrameRect(IntRect(50, 50, 50, 50));
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(1u, frameBuffers[2].requiredPreviousFrameIndex());
}
TEST(ImageDecoderTest, requiredPreviousFrameIndexForFrame1)
{
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
decoder->initFrames(2);
Vector<ImageFrame, 1>& frameBuffers = decoder->frameBufferCache();
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(0u, frameBuffers[1].requiredPreviousFrameIndex());
frameBuffers[0].setDisposalMethod(ImageFrame::DisposeOverwritePrevious);
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(kNotFound, frameBuffers[1].requiredPreviousFrameIndex());
frameBuffers[0].setDisposalMethod(ImageFrame::DisposeOverwriteBgcolor);
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(kNotFound, frameBuffers[1].requiredPreviousFrameIndex());
frameBuffers[0].setOriginalFrameRect(IntRect(50, 50, 50, 50));
frameBuffers[0].setDisposalMethod(ImageFrame::DisposeOverwritePrevious);
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(kNotFound, frameBuffers[1].requiredPreviousFrameIndex());
frameBuffers[0].setDisposalMethod(ImageFrame::DisposeOverwriteBgcolor);
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(kNotFound, frameBuffers[1].requiredPreviousFrameIndex());
}
TEST(ImageDecoderTest, requiredPreviousFrameIndexBlendAtopBgcolor)
{
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
decoder->initFrames(3);
Vector<ImageFrame, 1>& frameBuffers = decoder->frameBufferCache();
frameBuffers[1].setOriginalFrameRect(IntRect(25, 25, 50, 50));
frameBuffers[2].setAlphaBlendSource(ImageFrame::BlendAtopBgcolor);
for (int disposeMethod = ImageFrame::DisposeNotSpecified; disposeMethod <= ImageFrame::DisposeOverwritePrevious; ++disposeMethod) {
frameBuffers[1].setDisposalMethod(static_cast<ImageFrame::DisposalMethod>(disposeMethod));
decoder->resetRequiredPreviousFrames();
EXPECT_EQ(kNotFound, frameBuffers[2].requiredPreviousFrameIndex());
}
frameBuffers[2].setOriginalFrameRect(IntRect(50, 50, 50, 50));
for (int disposeMethod = ImageFrame::DisposeNotSpecified; disposeMethod <= ImageFrame::DisposeOverwritePrevious; ++disposeMethod) {
frameBuffers[1].setDisposalMethod(static_cast<ImageFrame::DisposalMethod>(disposeMethod));
decoder->resetRequiredPreviousFrames();
EXPECT_NE(kNotFound, frameBuffers[2].requiredPreviousFrameIndex());
}
}
TEST(ImageDecoderTest, requiredPreviousFrameIndexKnownOpaque)
{
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
decoder->initFrames(3);
Vector<ImageFrame, 1>& frameBuffers = decoder->frameBufferCache();
frameBuffers[1].setOriginalFrameRect(IntRect(25, 25, 50, 50));
for (int disposeMethod = ImageFrame::DisposeNotSpecified; disposeMethod <= ImageFrame::DisposeOverwritePrevious; ++disposeMethod) {
frameBuffers[1].setDisposalMethod(static_cast<ImageFrame::DisposalMethod>(disposeMethod));
decoder->resetRequiredPreviousFrames(true);
EXPECT_EQ(kNotFound, frameBuffers[2].requiredPreviousFrameIndex());
}
frameBuffers[2].setOriginalFrameRect(IntRect(50, 50, 50, 50));
for (int disposeMethod = ImageFrame::DisposeNotSpecified; disposeMethod <= ImageFrame::DisposeOverwritePrevious; ++disposeMethod) {
frameBuffers[1].setDisposalMethod(static_cast<ImageFrame::DisposalMethod>(disposeMethod));
decoder->resetRequiredPreviousFrames(true);
EXPECT_NE(kNotFound, frameBuffers[2].requiredPreviousFrameIndex());
}
}
TEST(ImageDecoderTest, clearCacheExceptFrameDoNothing)
{
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
decoder->clearCacheExceptFrame(0);
decoder->initFrames(20);
decoder->clearCacheExceptFrame(kNotFound);
}
TEST(ImageDecoderTest, clearCacheExceptFrameAll)
{
const size_t numFrames = 10;
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
decoder->initFrames(numFrames);
Vector<ImageFrame, 1>& frameBuffers = decoder->frameBufferCache();
for (size_t i = 0; i < numFrames; ++i)
frameBuffers[i].setStatus(i % 2 ? ImageFrame::FramePartial : ImageFrame::FrameComplete);
decoder->clearCacheExceptFrame(kNotFound);
for (size_t i = 0; i < numFrames; ++i) {
SCOPED_TRACE(testing::Message() << i);
EXPECT_EQ(ImageFrame::FrameEmpty, frameBuffers[i].status());
}
}
TEST(ImageDecoderTest, clearCacheExceptFramePreverveClearExceptFrame)
{
const size_t numFrames = 10;
OwnPtr<TestImageDecoder> decoder(adoptPtr(new TestImageDecoder()));
decoder->initFrames(numFrames);
Vector<ImageFrame, 1>& frameBuffers = decoder->frameBufferCache();
for (size_t i = 0; i < numFrames; ++i)
frameBuffers[i].setStatus(ImageFrame::FrameComplete);
decoder->resetRequiredPreviousFrames();
decoder->clearCacheExceptFrame(5);
for (size_t i = 0; i < numFrames; ++i) {
SCOPED_TRACE(testing::Message() << i);
if (i == 5)
EXPECT_EQ(ImageFrame::FrameComplete, frameBuffers[i].status());
else
EXPECT_EQ(ImageFrame::FrameEmpty, frameBuffers[i].status());
}
}