| OLD | NEW |
| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 TEST(ImageResourceTest, MultipartImage) | 86 TEST(ImageResourceTest, MultipartImage) |
| 87 { | 87 { |
| 88 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest()
); | 88 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest()
); |
| 89 cachedImage->setLoading(true); | 89 cachedImage->setLoading(true); |
| 90 | 90 |
| 91 MockImageResourceClient client; | 91 MockImageResourceClient client; |
| 92 cachedImage->addClient(&client); | 92 cachedImage->addClient(&client); |
| 93 | 93 |
| 94 // Send the multipart response. No image or data buffer is created. | 94 // Send the multipart response. No image or data buffer is created. |
| 95 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String())); | 95 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String()), nullptr); |
| 96 ASSERT_FALSE(cachedImage->resourceBuffer()); | 96 ASSERT_FALSE(cachedImage->resourceBuffer()); |
| 97 ASSERT_FALSE(cachedImage->hasImage()); | 97 ASSERT_FALSE(cachedImage->hasImage()); |
| 98 ASSERT_EQ(client.imageChangedCount(), 0); | 98 ASSERT_EQ(client.imageChangedCount(), 0); |
| 99 ASSERT_FALSE(client.notifyFinishedCalled()); | 99 ASSERT_FALSE(client.notifyFinishedCalled()); |
| 100 | 100 |
| 101 // Send the response for the first real part. No image or data buffer is cre
ated. | 101 // Send the response for the first real part. No image or data buffer is cre
ated. |
| 102 const char* svgData = "<svg xmlns='http://www.w3.org/2000/svg' width='1' hei
ght='1'><rect width='1' height='1' fill='green'/></svg>"; | 102 const char* svgData = "<svg xmlns='http://www.w3.org/2000/svg' width='1' hei
ght='1'><rect width='1' height='1' fill='green'/></svg>"; |
| 103 unsigned svgDataLength = strlen(svgData); | 103 unsigned svgDataLength = strlen(svgData); |
| 104 cachedImage->responseReceived(ResourceResponse(KURL(), "image/svg+xml", svgD
ataLength, nullAtom, String())); | 104 cachedImage->responseReceived(ResourceResponse(KURL(), "image/svg+xml", svgD
ataLength, nullAtom, String()), nullptr); |
| 105 ASSERT_FALSE(cachedImage->resourceBuffer()); | 105 ASSERT_FALSE(cachedImage->resourceBuffer()); |
| 106 ASSERT_FALSE(cachedImage->hasImage()); | 106 ASSERT_FALSE(cachedImage->hasImage()); |
| 107 ASSERT_EQ(client.imageChangedCount(), 0); | 107 ASSERT_EQ(client.imageChangedCount(), 0); |
| 108 ASSERT_FALSE(client.notifyFinishedCalled()); | 108 ASSERT_FALSE(client.notifyFinishedCalled()); |
| 109 | 109 |
| 110 // The first bytes arrive. The data buffer is created, but no image is creat
ed. | 110 // The first bytes arrive. The data buffer is created, but no image is creat
ed. |
| 111 cachedImage->appendData(svgData, svgDataLength); | 111 cachedImage->appendData(svgData, svgDataLength); |
| 112 ASSERT_TRUE(cachedImage->resourceBuffer()); | 112 ASSERT_TRUE(cachedImage->resourceBuffer()); |
| 113 ASSERT_EQ(cachedImage->resourceBuffer()->size(), svgDataLength); | 113 ASSERT_EQ(cachedImage->resourceBuffer()->size(), svgDataLength); |
| 114 ASSERT_FALSE(cachedImage->hasImage()); | 114 ASSERT_FALSE(cachedImage->hasImage()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) | 163 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) |
| 164 { | 164 { |
| 165 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest()
); | 165 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest()
); |
| 166 cachedImage->setLoading(true); | 166 cachedImage->setLoading(true); |
| 167 | 167 |
| 168 MockImageResourceClient client; | 168 MockImageResourceClient client; |
| 169 cachedImage->addClient(&client); | 169 cachedImage->addClient(&client); |
| 170 | 170 |
| 171 // Send the image response. | 171 // Send the image response. |
| 172 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String())); | 172 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String()), nullptr); |
| 173 | 173 |
| 174 Vector<unsigned char> jpeg = jpegImage(); | 174 Vector<unsigned char> jpeg = jpegImage(); |
| 175 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String())); | 175 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
| 176 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 176 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 177 cachedImage->finish(); | 177 cachedImage->finish(); |
| 178 ASSERT_FALSE(cachedImage->errorOccurred()); | 178 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 179 ASSERT_TRUE(cachedImage->hasImage()); | 179 ASSERT_TRUE(cachedImage->hasImage()); |
| 180 ASSERT_FALSE(cachedImage->image()->isNull()); | 180 ASSERT_FALSE(cachedImage->image()->isNull()); |
| 181 ASSERT_TRUE(client.notifyFinishedCalled()); | 181 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 182 | 182 |
| 183 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. | 183 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. |
| 184 cachedImage->prune(); | 184 cachedImage->prune(); |
| 185 ASSERT_TRUE(cachedImage->hasClients()); | 185 ASSERT_TRUE(cachedImage->hasClients()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 | 196 |
| 197 TEST(ImageResourceTest, UpdateBitmapImages) | 197 TEST(ImageResourceTest, UpdateBitmapImages) |
| 198 { | 198 { |
| 199 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest()
); | 199 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest()
); |
| 200 cachedImage->setLoading(true); | 200 cachedImage->setLoading(true); |
| 201 | 201 |
| 202 MockImageResourceClient client; | 202 MockImageResourceClient client; |
| 203 cachedImage->addClient(&client); | 203 cachedImage->addClient(&client); |
| 204 | 204 |
| 205 // Send the image response. | 205 // Send the image response. |
| 206 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String())); | 206 cachedImage->responseReceived(ResourceResponse(KURL(), "multipart/x-mixed-re
place", 0, nullAtom, String()), nullptr); |
| 207 | 207 |
| 208 Vector<unsigned char> jpeg = jpegImage(); | 208 Vector<unsigned char> jpeg = jpegImage(); |
| 209 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String())); | 209 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
| 210 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 210 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 211 cachedImage->finish(); | 211 cachedImage->finish(); |
| 212 ASSERT_FALSE(cachedImage->errorOccurred()); | 212 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 213 ASSERT_TRUE(cachedImage->hasImage()); | 213 ASSERT_TRUE(cachedImage->hasImage()); |
| 214 ASSERT_FALSE(cachedImage->image()->isNull()); | 214 ASSERT_FALSE(cachedImage->image()->isNull()); |
| 215 ASSERT_EQ(client.imageChangedCount(), 1); | 215 ASSERT_EQ(client.imageChangedCount(), 1); |
| 216 ASSERT_TRUE(client.notifyFinishedCalled()); | 216 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 217 | 217 |
| 218 HashSet<ImageResource*> bitmapImages; | 218 HashSet<ImageResource*> bitmapImages; |
| 219 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); | 219 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); |
| 220 bitmapImages.add(cachedImage.get()); | 220 bitmapImages.add(cachedImage.get()); |
| 221 | 221 |
| 222 // Updating bitmap resources produces image changed callbacks on their clien
ts. | 222 // Updating bitmap resources produces image changed callbacks on their clien
ts. |
| 223 ImageResource::updateBitmapImages(bitmapImages); | 223 ImageResource::updateBitmapImages(bitmapImages); |
| 224 ASSERT_EQ(client.imageChangedCount(), 2); | 224 ASSERT_EQ(client.imageChangedCount(), 2); |
| 225 ImageResource::updateBitmapImages(bitmapImages, true); | 225 ImageResource::updateBitmapImages(bitmapImages, true); |
| 226 ASSERT_EQ(client.imageChangedCount(), 3); | 226 ASSERT_EQ(client.imageChangedCount(), 3); |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace | 229 } // namespace |
| OLD | NEW |