| 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 EXPECT_EQ(1, imageResource->getImage()->width()); | 601 EXPECT_EQ(1, imageResource->getImage()->width()); |
| 600 EXPECT_EQ(1, imageResource->getImage()->height()); | 602 EXPECT_EQ(1, imageResource->getImage()->height()); |
| 601 EXPECT_TRUE(client1->notifyFinishedCalled()); | 603 EXPECT_TRUE(client1->notifyFinishedCalled()); |
| 602 | 604 |
| 603 client1->removeAsClient(); | 605 client1->removeAsClient(); |
| 604 | 606 |
| 605 EXPECT_FALSE(imageResource->hasClientsOrObservers()); | 607 EXPECT_FALSE(imageResource->hasClientsOrObservers()); |
| 606 | 608 |
| 607 imageResource->prune(); | 609 imageResource->prune(); |
| 608 | 610 |
| 609 EXPECT_FALSE(imageResource->hasImage()); | 611 EXPECT_TRUE(imageResource->hasImage()); |
| 610 | 612 |
| 611 // Re-adds a ResourceClient but not ImageResourceObserver. | 613 // Re-adds a ResourceClient but not ImageResourceObserver. |
| 612 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); | 614 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); |
| 613 | 615 |
| 614 ASSERT_TRUE(imageResource->hasImage()); | 616 ASSERT_TRUE(imageResource->hasImage()); |
| 615 EXPECT_FALSE(imageResource->getImage()->isNull()); | 617 EXPECT_FALSE(imageResource->getImage()->isNull()); |
| 616 EXPECT_EQ(1, imageResource->getImage()->width()); | 618 EXPECT_EQ(1, imageResource->getImage()->width()); |
| 617 EXPECT_EQ(1, imageResource->getImage()->height()); | 619 EXPECT_EQ(1, imageResource->getImage()->height()); |
| 618 EXPECT_TRUE(client2->notifyFinishedCalled()); | 620 EXPECT_TRUE(client2->notifyFinishedCalled()); |
| 619 } | 621 } |
| 620 | 622 |
| 621 } // namespace blink | 623 } // namespace blink |
| OLD | NEW |