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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ASSERT_EQ(client->imageChangedCount(), 0); | 160 ASSERT_EQ(client->imageChangedCount(), 0); |
161 ASSERT_FALSE(client->notifyFinishedCalled()); | 161 ASSERT_FALSE(client->notifyFinishedCalled()); |
162 | 162 |
163 const char thirdPart[] = "--boundary"; | 163 const char thirdPart[] = "--boundary"; |
164 cachedImage->appendData(thirdPart, strlen(thirdPart)); | 164 cachedImage->appendData(thirdPart, strlen(thirdPart)); |
165 ASSERT_TRUE(cachedImage->resourceBuffer()); | 165 ASSERT_TRUE(cachedImage->resourceBuffer()); |
166 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1); | 166 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1); |
167 | 167 |
168 // This part finishes. The image is created, callbacks are sent, and the dat
a buffer is cleared. | 168 // This part finishes. The image is created, callbacks are sent, and the dat
a buffer is cleared. |
169 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0); | 169 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0); |
170 ASSERT_FALSE(cachedImage->resourceBuffer()); | 170 ASSERT_TRUE(cachedImage->resourceBuffer()); |
171 ASSERT_FALSE(cachedImage->errorOccurred()); | 171 ASSERT_FALSE(cachedImage->errorOccurred()); |
172 ASSERT_TRUE(cachedImage->hasImage()); | 172 ASSERT_TRUE(cachedImage->hasImage()); |
173 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 173 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
174 ASSERT_EQ(cachedImage->getImage()->width(), 1); | 174 ASSERT_EQ(cachedImage->getImage()->width(), 1); |
175 ASSERT_EQ(cachedImage->getImage()->height(), 1); | 175 ASSERT_EQ(cachedImage->getImage()->height(), 1); |
176 ASSERT_EQ(client->imageChangedCount(), 1); | 176 ASSERT_EQ(client->imageChangedCount(), 1); |
177 ASSERT_TRUE(client->notifyFinishedCalled()); | 177 ASSERT_TRUE(client->notifyFinishedCalled()); |
178 } | 178 } |
179 | 179 |
180 TEST(ImageResourceTest, CancelOnDetach) | 180 TEST(ImageResourceTest, CancelOnDetach) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 ASSERT_TRUE(cachedImage->hasImage()); | 225 ASSERT_TRUE(cachedImage->hasImage()); |
226 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 226 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
227 ASSERT_TRUE(client->notifyFinishedCalled()); | 227 ASSERT_TRUE(client->notifyFinishedCalled()); |
228 | 228 |
229 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. | 229 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. |
230 cachedImage->prune(); | 230 cachedImage->prune(); |
231 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); | 231 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); |
232 ASSERT_TRUE(cachedImage->hasImage()); | 232 ASSERT_TRUE(cachedImage->hasImage()); |
233 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 233 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
234 | 234 |
235 // The ImageResource no longer has clients. The image should be deleted by p
rune. | 235 // The ImageResource no longer has clients. The decoded image data should be |
| 236 // deleted by prune. |
236 client->removeAsClient(); | 237 client->removeAsClient(); |
237 cachedImage->prune(); | 238 cachedImage->prune(); |
238 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); | 239 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); |
239 ASSERT_FALSE(cachedImage->hasImage()); | 240 ASSERT_TRUE(cachedImage->hasImage()); |
240 ASSERT_TRUE(cachedImage->getImage()->isNull()); | 241 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image |
| 242 // data. |
241 } | 243 } |
242 | 244 |
243 TEST(ImageResourceTest, UpdateBitmapImages) | 245 TEST(ImageResourceTest, UpdateBitmapImages) |
244 { | 246 { |
245 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); | 247 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); |
246 cachedImage->setStatus(Resource::Pending); | 248 cachedImage->setStatus(Resource::Pending); |
247 | 249 |
248 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); | 250 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); |
249 | 251 |
250 // Send the image response. | 252 // Send the image response. |
(...skipping 29 matching lines...) Expand all Loading... |
280 cachedImage->finish(); | 282 cachedImage->finish(); |
281 ASSERT_FALSE(cachedImage->errorOccurred()); | 283 ASSERT_FALSE(cachedImage->errorOccurred()); |
282 ASSERT_TRUE(cachedImage->hasImage()); | 284 ASSERT_TRUE(cachedImage->hasImage()); |
283 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 285 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
284 ASSERT_EQ(client->imageChangedCount(), 2); | 286 ASSERT_EQ(client->imageChangedCount(), 2); |
285 ASSERT_TRUE(client->notifyFinishedCalled()); | 287 ASSERT_TRUE(client->notifyFinishedCalled()); |
286 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 288 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
287 | 289 |
288 cachedImage->reloadIfLoFi(fetcher); | 290 cachedImage->reloadIfLoFi(fetcher); |
289 ASSERT_FALSE(cachedImage->errorOccurred()); | 291 ASSERT_FALSE(cachedImage->errorOccurred()); |
290 ASSERT_FALSE(cachedImage->resourceBuffer()); | 292 ASSERT_TRUE(cachedImage->resourceBuffer()); |
291 ASSERT_TRUE(cachedImage->hasImage()); | 293 ASSERT_TRUE(cachedImage->hasImage()); |
292 ASSERT_EQ(client->imageChangedCount(), 3); | 294 ASSERT_EQ(client->imageChangedCount(), 2); |
293 | 295 |
294 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r
esourceResponse), nullptr); | 296 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r
esourceResponse), nullptr); |
295 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); | 297 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); |
296 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); | 298 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); |
297 ASSERT_FALSE(cachedImage->errorOccurred()); | 299 ASSERT_FALSE(cachedImage->errorOccurred()); |
298 ASSERT_TRUE(cachedImage->hasImage()); | 300 ASSERT_TRUE(cachedImage->hasImage()); |
299 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 301 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
300 ASSERT_TRUE(client->notifyFinishedCalled()); | 302 ASSERT_TRUE(client->notifyFinishedCalled()); |
301 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 303 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
302 } | 304 } |
303 | 305 |
304 } // namespace blink | 306 } // namespace blink |
OLD | NEW |