| Index: Source/core/fetch/ImageResourceTest.cpp
|
| diff --git a/Source/core/fetch/ImageResourceTest.cpp b/Source/core/fetch/ImageResourceTest.cpp
|
| index 5b311ad4cda58f17ae276c1ad8cb307f4c35e08f..ee4728eb3fd64b4522f0484aeaaccd956b1487ab 100644
|
| --- a/Source/core/fetch/ImageResourceTest.cpp
|
| +++ b/Source/core/fetch/ImageResourceTest.cpp
|
| @@ -51,6 +51,38 @@ using namespace blink;
|
|
|
| namespace {
|
|
|
| +static Vector<unsigned char> jpegImage()
|
| +{
|
| + Vector<unsigned char> jpeg;
|
| +
|
| + static const unsigned char data[] = {
|
| + 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00,
|
| + 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
|
| + 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0xff, 0xdb, 0x00, 0x43,
|
| + 0x00, 0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06,
|
| + 0x07, 0x0c, 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, 0x09, 0x0c, 0x11, 0x0f, 0x12,
|
| + 0x12, 0x11, 0x0f, 0x11, 0x11, 0x13, 0x16, 0x1c, 0x17, 0x13, 0x14, 0x1a, 0x15, 0x11, 0x11,
|
| + 0x18, 0x21, 0x18, 0x1a, 0x1d, 0x1d, 0x1f, 0x1f, 0x1f, 0x13, 0x17, 0x22, 0x24, 0x22, 0x1e,
|
| + 0x24, 0x1c, 0x1e, 0x1f, 0x1e, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x05, 0x05, 0x05, 0x07, 0x06,
|
| + 0x07, 0x0e, 0x08, 0x08, 0x0e, 0x1e, 0x14, 0x11, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
|
| + 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
|
| + 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
|
| + 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0xff,
|
| + 0xc0, 0x00, 0x11, 0x08, 0x00, 0x01, 0x00, 0x01, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01,
|
| + 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00, 0x15, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xff, 0xc4, 0x00, 0x14,
|
| + 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| + 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11,
|
| + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| + 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f,
|
| + 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9
|
| + };
|
| +
|
| + jpeg.append(data, sizeof(data));
|
| + return jpeg;
|
| +}
|
| +
|
| TEST(ImageResourceTest, MultipartImage)
|
| {
|
| ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest());
|
| @@ -138,33 +170,10 @@ TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
|
|
|
| // Send the image response.
|
| cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-replace", 0, nullAtom, String()));
|
| - static const unsigned char jpegData[] = {
|
| - 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00,
|
| - 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
|
| - 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0xff, 0xdb, 0x00, 0x43,
|
| - 0x00, 0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x06,
|
| - 0x07, 0x0c, 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, 0x09, 0x0c, 0x11, 0x0f, 0x12,
|
| - 0x12, 0x11, 0x0f, 0x11, 0x11, 0x13, 0x16, 0x1c, 0x17, 0x13, 0x14, 0x1a, 0x15, 0x11, 0x11,
|
| - 0x18, 0x21, 0x18, 0x1a, 0x1d, 0x1d, 0x1f, 0x1f, 0x1f, 0x13, 0x17, 0x22, 0x24, 0x22, 0x1e,
|
| - 0x24, 0x1c, 0x1e, 0x1f, 0x1e, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x05, 0x05, 0x05, 0x07, 0x06,
|
| - 0x07, 0x0e, 0x08, 0x08, 0x0e, 0x1e, 0x14, 0x11, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
|
| - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
|
| - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
|
| - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0xff,
|
| - 0xc0, 0x00, 0x11, 0x08, 0x00, 0x01, 0x00, 0x01, 0x03, 0x01, 0x22, 0x00, 0x02, 0x11, 0x01,
|
| - 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00, 0x15, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xff, 0xc4, 0x00, 0x14,
|
| - 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| - 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x11,
|
| - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
| - 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f,
|
| - 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9
|
| - };
|
|
|
| - unsigned jpegDataLength = sizeof(jpegData);
|
| - cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpegDataLength, nullAtom, String()));
|
| - cachedImage->appendData(reinterpret_cast<const char*>(jpegData), jpegDataLength);
|
| + Vector<unsigned char> jpeg = jpegImage();
|
| + cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAtom, String()));
|
| + cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.size());
|
| cachedImage->finish();
|
| ASSERT_FALSE(cachedImage->errorOccurred());
|
| ASSERT_TRUE(cachedImage->hasImage());
|
| @@ -185,4 +194,36 @@ TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
|
| ASSERT_TRUE(cachedImage->image()->isNull());
|
| }
|
|
|
| +TEST(ImageResourceTest, UpdateBitmapImages)
|
| +{
|
| + ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest());
|
| + cachedImage->setLoading(true);
|
| +
|
| + MockImageResourceClient client;
|
| + cachedImage->addClient(&client);
|
| +
|
| + // Send the image response.
|
| + cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-replace", 0, nullAtom, String()));
|
| +
|
| + Vector<unsigned char> jpeg = jpegImage();
|
| + cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.size(), nullAtom, String()));
|
| + cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.size());
|
| + cachedImage->finish();
|
| + ASSERT_FALSE(cachedImage->errorOccurred());
|
| + ASSERT_TRUE(cachedImage->hasImage());
|
| + ASSERT_FALSE(cachedImage->image()->isNull());
|
| + ASSERT_EQ(client.imageChangedCount(), 1);
|
| + ASSERT_TRUE(client.notifyFinishedCalled());
|
| +
|
| + HashSet<ImageResource*> bitmapImages;
|
| + ASSERT_TRUE(cachedImage->image()->isBitmapImage());
|
| + bitmapImages.add(cachedImage.get());
|
| +
|
| + // Updating bitmap resources produces image changed callbacks on their clients.
|
| + ImageResource::updateBitmapImages(bitmapImages);
|
| + ASSERT_EQ(client.imageChangedCount(), 2);
|
| + ImageResource::updateBitmapImages(bitmapImages, true);
|
| + ASSERT_EQ(client.imageChangedCount(), 3);
|
| +}
|
| +
|
| } // namespace
|
|
|