Esempio n. 1
0
TEST_F(ImageBitmapTest, ImageResourceConsistency)
{
    const ImageBitmapOptions defaultOptions;
    HTMLImageElement* imageElement = HTMLImageElement::create(*Document::create());
    ImageResource* image = ImageResource::create(StaticBitmapImage::create(m_image).get());
    imageElement->setImageResource(image);

    ImageBitmap* imageBitmapNoCrop = ImageBitmap::create(imageElement,
        IntRect(0, 0, m_image->width(), m_image->height()),
        &(imageElement->document()), defaultOptions);
    ImageBitmap* imageBitmapInteriorCrop = ImageBitmap::create(imageElement,
        IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() / 2, m_image->height() / 2),
        &(imageElement->document()), defaultOptions);
    ImageBitmap* imageBitmapExteriorCrop = ImageBitmap::create(imageElement,
        IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height()),
        &(imageElement->document()), defaultOptions);
    ImageBitmap* imageBitmapOutsideCrop = ImageBitmap::create(imageElement,
        IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image->height()),
        &(imageElement->document()), defaultOptions);

    ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageElement->cachedImage()->getImage()->imageForCurrentFrame());
    ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), imageElement->cachedImage()->getImage()->imageForCurrentFrame());
    ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), imageElement->cachedImage()->getImage()->imageForCurrentFrame());

    StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage();
    ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->getImage()->imageForCurrentFrame());
}
Esempio n. 2
0
// Verifies that ImageBitmaps constructed from HTMLImageElements hold a reference to the original Image if the HTMLImageElement src is changed.
TEST_F(ImageBitmapTest, ImageBitmapSourceChanged)
{
    HTMLImageElement* image = HTMLImageElement::create(*Document::create());
    ImageResource* originalImageResource = ImageResource::create(
        StaticBitmapImage::create(m_image).get());
    image->setImageResource(originalImageResource);

    const ImageBitmapOptions defaultOptions;
    ImageBitmap* imageBitmap = ImageBitmap::create(image,
        IntRect(0, 0, m_image->width(), m_image->height()),
        &(image->document()), defaultOptions);
    ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageResource->getImage()->imageForCurrentFrame());

    ImageResource* newImageResource = ImageResource::create(
        StaticBitmapImage::create(m_image2).get());
    image->setImageResource(newImageResource);

    // The ImageBitmap should contain the same data as the original cached image
    {
        ASSERT_EQ(imageBitmap->bitmapImage()->imageForCurrentFrame(), originalImageResource->getImage()->imageForCurrentFrame());
        SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get();
        ASSERT_NE(image1, nullptr);
        SkImage* image2 = originalImageResource->getImage()->imageForCurrentFrame().get();
        ASSERT_NE(image2, nullptr);
        ASSERT_EQ(image1, image2);
    }

    {
        ASSERT_NE(imageBitmap->bitmapImage()->imageForCurrentFrame(), newImageResource->getImage()->imageForCurrentFrame());
        SkImage* image1 = imageBitmap->bitmapImage()->imageForCurrentFrame().get();
        ASSERT_NE(image1, nullptr);
        SkImage* image2 = newImageResource->getImage()->imageForCurrentFrame().get();
        ASSERT_NE(image2, nullptr);
        ASSERT_NE(image1, image2);
    }
}