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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); | 301 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
302 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 302 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
303 cachedImage->finish(); | 303 cachedImage->finish(); |
304 ASSERT_FALSE(cachedImage->errorOccurred()); | 304 ASSERT_FALSE(cachedImage->errorOccurred()); |
305 ASSERT_TRUE(cachedImage->hasImage()); | 305 ASSERT_TRUE(cachedImage->hasImage()); |
306 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 306 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
307 ASSERT_TRUE(client->notifyFinishedCalled()); | 307 ASSERT_TRUE(client->notifyFinishedCalled()); |
308 | 308 |
309 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. | 309 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. |
310 cachedImage->prune(); | 310 cachedImage->prune(); |
311 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); | 311 ASSERT_TRUE(cachedImage->isAlive()); |
312 ASSERT_TRUE(cachedImage->hasImage()); | 312 ASSERT_TRUE(cachedImage->hasImage()); |
313 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 313 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
314 | 314 |
315 // The ImageResource no longer has clients. The decoded image data should be | 315 // The ImageResource no longer has clients. The decoded image data should be |
316 // deleted by prune. | 316 // deleted by prune. |
317 client->removeAsClient(); | 317 client->removeAsClient(); |
318 cachedImage->prune(); | 318 cachedImage->prune(); |
319 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); | 319 ASSERT_FALSE(cachedImage->isAlive()); |
320 ASSERT_TRUE(cachedImage->hasImage()); | 320 ASSERT_TRUE(cachedImage->hasImage()); |
321 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image | 321 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image |
322 // data. | 322 // data. |
323 } | 323 } |
324 | 324 |
325 TEST(ImageResourceTest, UpdateBitmapImages) | 325 TEST(ImageResourceTest, UpdateBitmapImages) |
326 { | 326 { |
327 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); | 327 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); |
328 cachedImage->setStatus(Resource::Pending); | 328 cachedImage->setStatus(Resource::Pending); |
329 | 329 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 607 |
608 EXPECT_FALSE(imageResource->errorOccurred()); | 608 EXPECT_FALSE(imageResource->errorOccurred()); |
609 ASSERT_TRUE(imageResource->hasImage()); | 609 ASSERT_TRUE(imageResource->hasImage()); |
610 EXPECT_FALSE(imageResource->getImage()->isNull()); | 610 EXPECT_FALSE(imageResource->getImage()->isNull()); |
611 EXPECT_EQ(1, imageResource->getImage()->width()); | 611 EXPECT_EQ(1, imageResource->getImage()->width()); |
612 EXPECT_EQ(1, imageResource->getImage()->height()); | 612 EXPECT_EQ(1, imageResource->getImage()->height()); |
613 EXPECT_TRUE(client1->notifyFinishedCalled()); | 613 EXPECT_TRUE(client1->notifyFinishedCalled()); |
614 | 614 |
615 client1->removeAsClient(); | 615 client1->removeAsClient(); |
616 | 616 |
617 EXPECT_FALSE(imageResource->hasClientsOrObservers()); | 617 EXPECT_FALSE(imageResource->isAlive()); |
618 | 618 |
619 imageResource->prune(); | 619 imageResource->prune(); |
620 | 620 |
621 EXPECT_TRUE(imageResource->hasImage()); | 621 EXPECT_TRUE(imageResource->hasImage()); |
622 | 622 |
623 // Re-adds a ResourceClient but not ImageResourceObserver. | 623 // Re-adds a ResourceClient but not ImageResourceObserver. |
624 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); | 624 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); |
625 | 625 |
626 ASSERT_TRUE(imageResource->hasImage()); | 626 ASSERT_TRUE(imageResource->hasImage()); |
627 EXPECT_FALSE(imageResource->getImage()->isNull()); | 627 EXPECT_FALSE(imageResource->getImage()->isNull()); |
(...skipping 12 matching lines...) Expand all Loading... |
640 ImageResource* cachedImage = ImageResource::fetch(request, fetcher); | 640 ImageResource* cachedImage = ImageResource::fetch(request, fetcher); |
641 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); | 641 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); |
642 | 642 |
643 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(R
esourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), nullptr); | 643 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(R
esourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), nullptr); |
644 cachedImage->loader()->didReceiveData(nullptr, "notactuallyanimage", 18, 18,
18); | 644 cachedImage->loader()->didReceiveData(nullptr, "notactuallyanimage", 18, 18,
18); |
645 EXPECT_EQ(Resource::DecodeError, cachedImage->getStatus()); | 645 EXPECT_EQ(Resource::DecodeError, cachedImage->getStatus()); |
646 EXPECT_FALSE(cachedImage->isLoading()); | 646 EXPECT_FALSE(cachedImage->isLoading()); |
647 } | 647 } |
648 | 648 |
649 } // namespace blink | 649 } // namespace blink |
OLD | NEW |