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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); | 292 cachedImage->responseReceived(ResourceResponse(KURL(), "image/jpeg", jpeg.si
ze(), nullAtom, String()), nullptr); |
293 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); | 293 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz
e()); |
294 cachedImage->finish(); | 294 cachedImage->finish(); |
295 ASSERT_FALSE(cachedImage->errorOccurred()); | 295 ASSERT_FALSE(cachedImage->errorOccurred()); |
296 ASSERT_TRUE(cachedImage->hasImage()); | 296 ASSERT_TRUE(cachedImage->hasImage()); |
297 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 297 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
298 ASSERT_TRUE(client->notifyFinishedCalled()); | 298 ASSERT_TRUE(client->notifyFinishedCalled()); |
299 | 299 |
300 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. | 300 // The prune comes when the ImageResource still has clients. The image shoul
d not be deleted. |
301 cachedImage->prune(); | 301 cachedImage->prune(); |
302 ASSERT_TRUE(cachedImage->hasClientsOrObservers()); | 302 ASSERT_TRUE(cachedImage->isAlive()); |
303 ASSERT_TRUE(cachedImage->hasImage()); | 303 ASSERT_TRUE(cachedImage->hasImage()); |
304 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 304 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
305 | 305 |
306 // The ImageResource no longer has clients. The decoded image data should be | 306 // The ImageResource no longer has clients. The decoded image data should be |
307 // deleted by prune. | 307 // deleted by prune. |
308 client->removeAsClient(); | 308 client->removeAsClient(); |
309 cachedImage->prune(); | 309 cachedImage->prune(); |
310 ASSERT_FALSE(cachedImage->hasClientsOrObservers()); | 310 ASSERT_FALSE(cachedImage->isAlive()); |
311 ASSERT_TRUE(cachedImage->hasImage()); | 311 ASSERT_TRUE(cachedImage->hasImage()); |
312 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image | 312 // TODO(hajimehoshi): Should check cachedImage doesn't have decoded image |
313 // data. | 313 // data. |
314 } | 314 } |
315 | 315 |
316 TEST(ImageResourceTest, UpdateBitmapImages) | 316 TEST(ImageResourceTest, UpdateBitmapImages) |
317 { | 317 { |
318 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); | 318 ImageResource* cachedImage = ImageResource::create(ResourceRequest()); |
319 cachedImage->setStatus(Resource::Pending); | 319 cachedImage->setStatus(Resource::Pending); |
320 | 320 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 598 |
599 EXPECT_FALSE(imageResource->errorOccurred()); | 599 EXPECT_FALSE(imageResource->errorOccurred()); |
600 ASSERT_TRUE(imageResource->hasImage()); | 600 ASSERT_TRUE(imageResource->hasImage()); |
601 EXPECT_FALSE(imageResource->getImage()->isNull()); | 601 EXPECT_FALSE(imageResource->getImage()->isNull()); |
602 EXPECT_EQ(1, imageResource->getImage()->width()); | 602 EXPECT_EQ(1, imageResource->getImage()->width()); |
603 EXPECT_EQ(1, imageResource->getImage()->height()); | 603 EXPECT_EQ(1, imageResource->getImage()->height()); |
604 EXPECT_TRUE(client1->notifyFinishedCalled()); | 604 EXPECT_TRUE(client1->notifyFinishedCalled()); |
605 | 605 |
606 client1->removeAsClient(); | 606 client1->removeAsClient(); |
607 | 607 |
608 EXPECT_FALSE(imageResource->hasClientsOrObservers()); | 608 EXPECT_FALSE(imageResource->isAlive()); |
609 | 609 |
610 imageResource->prune(); | 610 imageResource->prune(); |
611 | 611 |
612 EXPECT_TRUE(imageResource->hasImage()); | 612 EXPECT_TRUE(imageResource->hasImage()); |
613 | 613 |
614 // Re-adds a ResourceClient but not ImageResourceObserver. | 614 // Re-adds a ResourceClient but not ImageResourceObserver. |
615 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); | 615 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); |
616 | 616 |
617 ASSERT_TRUE(imageResource->hasImage()); | 617 ASSERT_TRUE(imageResource->hasImage()); |
618 EXPECT_FALSE(imageResource->getImage()->isNull()); | 618 EXPECT_FALSE(imageResource->getImage()->isNull()); |
(...skipping 12 matching lines...) Expand all Loading... |
631 ImageResource* cachedImage = ImageResource::fetch(request, fetcher); | 631 ImageResource* cachedImage = ImageResource::fetch(request, fetcher); |
632 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); | 632 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); |
633 | 633 |
634 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(R
esourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), nullptr); | 634 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(R
esourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), nullptr); |
635 cachedImage->loader()->didReceiveData(nullptr, "notactuallyanimage", 18, 18,
18); | 635 cachedImage->loader()->didReceiveData(nullptr, "notactuallyanimage", 18, 18,
18); |
636 EXPECT_EQ(Resource::DecodeError, cachedImage->getStatus()); | 636 EXPECT_EQ(Resource::DecodeError, cachedImage->getStatus()); |
637 EXPECT_FALSE(cachedImage->isLoading()); | 637 EXPECT_FALSE(cachedImage->isLoading()); |
638 } | 638 } |
639 | 639 |
640 } // namespace blink | 640 } // namespace blink |
OLD | NEW |