| 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 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/fetch/ImageResource.h" | 31 #include "core/fetch/ImageResource.h" |
| 32 | 32 |
| 33 #include "core/fetch/ImageResourceClient.h" | |
| 34 #include "core/fetch/MemoryCache.h" | 33 #include "core/fetch/MemoryCache.h" |
| 35 #include "core/fetch/MockImageResourceClient.h" | 34 #include "core/fetch/MockResourceClients.h" |
| 36 #include "core/fetch/ResourceFetcher.h" | 35 #include "core/fetch/ResourceFetcher.h" |
| 37 #include "core/fetch/ResourceLoader.h" | 36 #include "core/fetch/ResourceLoader.h" |
| 38 #include "core/fetch/UniqueIdentifier.h" | 37 #include "core/fetch/UniqueIdentifier.h" |
| 39 #include "platform/SharedBuffer.h" | 38 #include "platform/SharedBuffer.h" |
| 40 #include "platform/exported/WrappedResourceResponse.h" | 39 #include "platform/exported/WrappedResourceResponse.h" |
| 41 #include "platform/graphics/Image.h" | 40 #include "platform/graphics/Image.h" |
| 42 #include "platform/testing/URLTestHelpers.h" | 41 #include "platform/testing/URLTestHelpers.h" |
| 43 #include "platform/testing/UnitTestHelpers.h" | 42 #include "platform/testing/UnitTestHelpers.h" |
| 44 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 45 #include "public/platform/WebURL.h" | 44 #include "public/platform/WebURL.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); | 183 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
| 185 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 184 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 186 cachedImage->finish(); | 185 cachedImage->finish(); |
| 187 ASSERT_FALSE(cachedImage->errorOccurred()); | 186 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 188 ASSERT_TRUE(cachedImage->hasImage()); | 187 ASSERT_TRUE(cachedImage->hasImage()); |
| 189 ASSERT_FALSE(cachedImage->image()->isNull()); | 188 ASSERT_FALSE(cachedImage->image()->isNull()); |
| 190 ASSERT_TRUE(client.notifyFinishedCalled()); | 189 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 191 | 190 |
| 192 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. | 191 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. |
| 193 cachedImage->prune(); | 192 cachedImage->prune(); |
| 194 ASSERT_TRUE(cachedImage->hasClients()); | 193 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); |
| 195 ASSERT_TRUE(cachedImage->hasImage()); | 194 ASSERT_TRUE(cachedImage->hasImage()); |
| 196 ASSERT_FALSE(cachedImage->image()->isNull()); | 195 ASSERT_FALSE(cachedImage->image()->isNull()); |
| 197 | 196 |
| 198 // The ImageResource no longer has clients. The image should be deleted by p
rune. | 197 // The ImageResource no longer has clients. The image should be deleted by p
rune. |
| 199 client.removeAsClient(); | 198 client.removeAsClient(); |
| 200 cachedImage->prune(); | 199 cachedImage->prune(); |
| 201 ASSERT_FALSE(cachedImage->hasClients()); | 200 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); |
| 202 ASSERT_FALSE(cachedImage->hasImage()); | 201 ASSERT_FALSE(cachedImage->hasImage()); |
| 203 ASSERT_TRUE(cachedImage->image()->isNull()); | 202 ASSERT_TRUE(cachedImage->image()->isNull()); |
| 204 } | 203 } |
| 205 | 204 |
| 206 TEST(ImageResourceTest, UpdateBitmapImages) | 205 TEST(ImageResourceTest, UpdateBitmapImages) |
| 207 { | 206 { |
| 208 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); | 207 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); |
| 209 cachedImage->setLoading(true); | 208 cachedImage->setLoading(true); |
| 210 | 209 |
| 211 MockImageResourceClient client(cachedImage); | 210 MockImageResourceClient client(cachedImage); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 257 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
| 259 cachedImage->finish(); | 258 cachedImage->finish(); |
| 260 ASSERT_FALSE(cachedImage->errorOccurred()); | 259 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 261 ASSERT_TRUE(cachedImage->hasImage()); | 260 ASSERT_TRUE(cachedImage->hasImage()); |
| 262 ASSERT_FALSE(cachedImage->image()->isNull()); | 261 ASSERT_FALSE(cachedImage->image()->isNull()); |
| 263 ASSERT_TRUE(client.notifyFinishedCalled()); | 262 ASSERT_TRUE(client.notifyFinishedCalled()); |
| 264 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); | 263 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); |
| 265 } | 264 } |
| 266 | 265 |
| 267 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |