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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); | 187 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
189 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 188 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
190 cachedImage->finish(); | 189 cachedImage->finish(); |
191 ASSERT_FALSE(cachedImage->errorOccurred()); | 190 ASSERT_FALSE(cachedImage->errorOccurred()); |
192 ASSERT_TRUE(cachedImage->hasImage()); | 191 ASSERT_TRUE(cachedImage->hasImage()); |
193 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 192 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
194 ASSERT_TRUE(client.notifyFinishedCalled()); | 193 ASSERT_TRUE(client.notifyFinishedCalled()); |
195 | 194 |
196 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. | 195 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. |
197 cachedImage->prune(); | 196 cachedImage->prune(); |
198 ASSERT_TRUE(cachedImage->hasClients()); | 197 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); |
199 ASSERT_TRUE(cachedImage->hasImage()); | 198 ASSERT_TRUE(cachedImage->hasImage()); |
200 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 199 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
201 | 200 |
202 // The ImageResource no longer has clients. The image should be deleted by p
rune. | 201 // The ImageResource no longer has clients. The image should be deleted by p
rune. |
203 client.removeAsClient(); | 202 client.removeAsClient(); |
204 cachedImage->prune(); | 203 cachedImage->prune(); |
205 ASSERT_FALSE(cachedImage->hasClients()); | 204 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); |
206 ASSERT_FALSE(cachedImage->hasImage()); | 205 ASSERT_FALSE(cachedImage->hasImage()); |
207 ASSERT_TRUE(cachedImage->getImage()->isNull()); | 206 ASSERT_TRUE(cachedImage->getImage()->isNull()); |
208 } | 207 } |
209 | 208 |
210 TEST(ImageResourceTest, UpdateBitmapImages) | 209 TEST(ImageResourceTest, UpdateBitmapImages) |
211 { | 210 { |
212 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); | 211 RefPtrWillBeRawPtr<ImageResource> cachedImage = ImageResource::create(Resour
ceRequest(), nullptr); |
213 cachedImage->setStatus(Resource::Pending); | 212 cachedImage->setStatus(Resource::Pending); |
214 | 213 |
215 MockImageResourceClient client(cachedImage); | 214 MockImageResourceClient client(cachedImage); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 261 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
263 cachedImage->finish(); | 262 cachedImage->finish(); |
264 ASSERT_FALSE(cachedImage->errorOccurred()); | 263 ASSERT_FALSE(cachedImage->errorOccurred()); |
265 ASSERT_TRUE(cachedImage->hasImage()); | 264 ASSERT_TRUE(cachedImage->hasImage()); |
266 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 265 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
267 ASSERT_TRUE(client.notifyFinishedCalled()); | 266 ASSERT_TRUE(client.notifyFinishedCalled()); |
268 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 267 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
269 } | 268 } |
270 | 269 |
271 } // namespace blink | 270 } // namespace blink |
OLD | NEW |