| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 ASSERT_EQ(client->imageChangedCount(), 0); | 230 ASSERT_EQ(client->imageChangedCount(), 0); |
| 231 ASSERT_FALSE(client->notifyFinishedCalled()); | 231 ASSERT_FALSE(client->notifyFinishedCalled()); |
| 232 | 232 |
| 233 const char thirdPart[] = "--boundary"; | 233 const char thirdPart[] = "--boundary"; |
| 234 cachedImage->appendData(thirdPart, strlen(thirdPart)); | 234 cachedImage->appendData(thirdPart, strlen(thirdPart)); |
| 235 ASSERT_TRUE(cachedImage->resourceBuffer()); | 235 ASSERT_TRUE(cachedImage->resourceBuffer()); |
| 236 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1); | 236 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1); |
| 237 | 237 |
| 238 // This part finishes. The image is created, callbacks are sent, and the dat
a buffer is cleared. | 238 // This part finishes. The image is created, callbacks are sent, and the dat
a buffer is cleared. |
| 239 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0); | 239 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0); |
| 240 ASSERT_FALSE(cachedImage->resourceBuffer()); | 240 ASSERT_TRUE(cachedImage->resourceBuffer()); |
| 241 ASSERT_FALSE(cachedImage->errorOccurred()); | 241 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 242 ASSERT_TRUE(cachedImage->hasImage()); | 242 ASSERT_TRUE(cachedImage->hasImage()); |
| 243 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 243 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 244 ASSERT_EQ(cachedImage->getImage()->width(), 1); | 244 ASSERT_EQ(cachedImage->getImage()->width(), 1); |
| 245 ASSERT_EQ(cachedImage->getImage()->height(), 1); | 245 ASSERT_EQ(cachedImage->getImage()->height(), 1); |
| 246 ASSERT_EQ(client->imageChangedCount(), 1); | 246 ASSERT_EQ(client->imageChangedCount(), 1); |
| 247 ASSERT_TRUE(client->notifyFinishedCalled()); | 247 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 248 } | 248 } |
| 249 | 249 |
| 250 TEST(ImageResourceTest, CancelOnDetach) | 250 TEST(ImageResourceTest, CancelOnDetach) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 ASSERT_TRUE(cachedImage->hasImage()); | 295 ASSERT_TRUE(cachedImage->hasImage()); |
| 296 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 296 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 297 ASSERT_TRUE(client->notifyFinishedCalled()); | 297 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 298 | 298 |
| 299 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. | 299 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. |
| 300 cachedImage->prune(); | 300 cachedImage->prune(); |
| 301 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); | 301 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); |
| 302 ASSERT_TRUE(cachedImage->hasImage()); | 302 ASSERT_TRUE(cachedImage->hasImage()); |
| 303 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 303 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 304 | 304 |
| 305 // The ImageResource no longer has clients. The image should be deleted by p
rune. | 305 // The ImageResource no longer has clients. The decoded image data should be |
| 306 // deleted by prune. |
| 306 client->removeAsClient(); | 307 client->removeAsClient(); |
| 307 cachedImage->prune(); | 308 cachedImage->prune(); |
| 308 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); | 309 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); |
| 309 ASSERT_FALSE(cachedImage->hasImage()); | 310 ASSERT_TRUE(cachedImage->hasImage()); |
| 310 ASSERT_TRUE(cachedImage->getImage()->isNull()); | 311 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image |
| 312 // data. |
| 311 } | 313 } |
| 312 | 314 |
| 313 TEST(ImageResourceTest, UpdateBitmapImages) | 315 TEST(ImageResourceTest, UpdateBitmapImages) |
| 314 { | 316 { |
| 315 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); | 317 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); |
| 316 cachedImage->setStatus(Resource::Pending); | 318 cachedImage->setStatus(Resource::Pending); |
| 317 | 319 |
| 318 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); | 320 Persistent<MockImageResourceClient> client = new MockImageResourceClient(cac
hedImage); |
| 319 | 321 |
| 320 // Send the image response. | 322 // Send the image response. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 350 cachedImage->finish(); | 352 cachedImage->finish(); |
| 351 ASSERT_FALSE(cachedImage->errorOccurred()); | 353 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 352 ASSERT_TRUE(cachedImage->hasImage()); | 354 ASSERT_TRUE(cachedImage->hasImage()); |
| 353 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 355 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 354 ASSERT_EQ(client->imageChangedCount(), 2); | 356 ASSERT_EQ(client->imageChangedCount(), 2); |
| 355 ASSERT_TRUE(client->notifyFinishedCalled()); | 357 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 356 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 358 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 357 | 359 |
| 358 cachedImage->reloadIfLoFi(fetcher); | 360 cachedImage->reloadIfLoFi(fetcher); |
| 359 ASSERT_FALSE(cachedImage->errorOccurred()); | 361 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 360 ASSERT_FALSE(cachedImage->resourceBuffer()); | 362 ASSERT_TRUE(cachedImage->resourceBuffer()); |
| 361 ASSERT_TRUE(cachedImage->hasImage()); | 363 ASSERT_TRUE(cachedImage->hasImage()); |
| 362 ASSERT_EQ(client->imageChangedCount(), 3); | 364 ASSERT_EQ(client->imageChangedCount(), 2); |
| 363 | 365 |
| 364 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r
esourceResponse), nullptr); | 366 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(r
esourceResponse), nullptr); |
| 365 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); | 367 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); |
| 366 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); | 368 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); |
| 367 ASSERT_FALSE(cachedImage->errorOccurred()); | 369 ASSERT_FALSE(cachedImage->errorOccurred()); |
| 368 ASSERT_TRUE(cachedImage->hasImage()); | 370 ASSERT_TRUE(cachedImage->hasImage()); |
| 369 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 371 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
| 370 ASSERT_TRUE(client->notifyFinishedCalled()); | 372 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 371 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 373 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
| 372 } | 374 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 EXPECT_EQ(1, imageResource->getImage()->width()); | 594 EXPECT_EQ(1, imageResource->getImage()->width()); |
| 593 EXPECT_EQ(1, imageResource->getImage()->height()); | 595 EXPECT_EQ(1, imageResource->getImage()->height()); |
| 594 EXPECT_TRUE(client1->notifyFinishedCalled()); | 596 EXPECT_TRUE(client1->notifyFinishedCalled()); |
| 595 | 597 |
| 596 client1->removeAsClient(); | 598 client1->removeAsClient(); |
| 597 | 599 |
| 598 EXPECT_FALSE(imageResource->hasClientsOrObservers()); | 600 EXPECT_FALSE(imageResource->hasClientsOrObservers()); |
| 599 | 601 |
| 600 imageResource->prune(); | 602 imageResource->prune(); |
| 601 | 603 |
| 602 EXPECT_FALSE(imageResource->hasImage()); | 604 EXPECT_TRUE(imageResource->hasImage()); |
| 603 | 605 |
| 604 // Re-adds a ResourceClient but not ImageResourceObserver. | 606 // Re-adds a ResourceClient but not ImageResourceObserver. |
| 605 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); | 607 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); |
| 606 | 608 |
| 607 ASSERT_TRUE(imageResource->hasImage()); | 609 ASSERT_TRUE(imageResource->hasImage()); |
| 608 EXPECT_FALSE(imageResource->getImage()->isNull()); | 610 EXPECT_FALSE(imageResource->getImage()->isNull()); |
| 609 EXPECT_EQ(1, imageResource->getImage()->width()); | 611 EXPECT_EQ(1, imageResource->getImage()->width()); |
| 610 EXPECT_EQ(1, imageResource->getImage()->height()); | 612 EXPECT_EQ(1, imageResource->getImage()->height()); |
| 611 EXPECT_TRUE(client2->notifyFinishedCalled()); | 613 EXPECT_TRUE(client2->notifyFinishedCalled()); |
| 612 } | 614 } |
| 613 | 615 |
| 614 } // namespace blink | 616 } // namespace blink |
| OLD | NEW |