Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp

Issue 2527353002: Phase II Step 3: Reload LoFi/placeholder images via new ImageResource
Patch Set: reloadLoFiImages test Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
diff --git a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
index 2213c24b4bb9c9373a849374bbae5a3e31666bd7..71781c8849b1e62ade1ce9ad90a9b2f539899858 100644
--- a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
@@ -58,6 +58,10 @@
namespace blink {
+// TODO(hiroshige): Cleanup variable names for ImageResource.
+// TODO(hiroshige): Cleanup usage of ImageResource::fetch(), create(), and
+// URLLoaderMock.
+
namespace {
// An image of size 1x1.
@@ -318,7 +322,7 @@ TEST(ImageResourceTest, CancelOnDetach) {
// The load should still be alive, but a timer should be started to cancel the
// load inside removeClient().
- client->removeAsClient();
+ client->removeAsClientAndObserver();
EXPECT_EQ(Resource::Pending, cachedImage->getStatus());
EXPECT_TRUE(memoryCache()->resourceForURL(testURL));
@@ -365,7 +369,7 @@ TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) {
// The ImageResource no longer has clients. The decoded image data should be
// deleted by prune.
- client->removeAsClient();
+ client->removeAsClientAndObserver();
cachedImage->prune();
EXPECT_FALSE(cachedImage->isAlive());
EXPECT_TRUE(cachedImage->getContent()->hasImage());
@@ -402,6 +406,7 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
ResourceRequest request = ResourceRequest(testURL);
request.setLoFiState(WebURLRequest::LoFiOn);
ImageResource* cachedImage = ImageResource::create(request);
+ ImageResourceContent* content = cachedImage->getContent();
cachedImage->setStatus(Resource::Pending);
Persistent<MockImageResourceClient> client =
@@ -419,9 +424,9 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage),
sizeof(kJpegImage));
cachedImage->finish();
- EXPECT_FALSE(cachedImage->errorOccurred());
- ASSERT_TRUE(cachedImage->getContent()->hasImage());
- EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull());
+ EXPECT_FALSE(content->errorOccurred());
+ ASSERT_TRUE(content->hasImage());
+ EXPECT_FALSE(content->getImage()->isNull());
EXPECT_EQ(2, client->imageChangedCount());
EXPECT_EQ(1, client->imageNotifyFinishedCount());
EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged());
@@ -429,37 +434,93 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
EXPECT_TRUE(client->notifyFinishedCalled());
EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished());
EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished());
- EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage());
- EXPECT_EQ(1, cachedImage->getContent()->getImage()->width());
- EXPECT_EQ(1, cachedImage->getContent()->getImage()->height());
+ EXPECT_TRUE(content->getImage()->isBitmapImage());
+ EXPECT_EQ(1, content->getImage()->width());
+ EXPECT_EQ(1, content->getImage()->height());
// Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading.
- cachedImage->reloadIfLoFiOrPlaceholderImage(fetcher, Resource::kReloadAlways);
- EXPECT_FALSE(cachedImage->errorOccurred());
- EXPECT_FALSE(cachedImage->resourceBuffer());
- EXPECT_FALSE(cachedImage->getContent()->hasImage());
- EXPECT_EQ(3, client->imageChangedCount());
+ ImageResource* reloadingResource =
+ cachedImage->reloadIfLoFiOrPlaceholderImage(fetcher,
+ Resource::kReloadAlways);
+ ASSERT_TRUE(reloadingResource);
+ EXPECT_NE(cachedImage, reloadingResource);
+ EXPECT_EQ(content, reloadingResource->getContent());
+ EXPECT_FALSE(cachedImage->getContent());
+ EXPECT_EQ(reloadingResource, fetcher->cachedResource(testURL));
+ EXPECT_EQ(reloadingResource, memoryCache()->resourceForURL(testURL));
+ EXPECT_FALSE(reloadingResource->isPlaceholder());
+
+ EXPECT_FALSE(content->errorOccurred());
+ EXPECT_TRUE(content->hasImage());
+ EXPECT_EQ(2, client->imageChangedCount());
EXPECT_EQ(1, client->imageNotifyFinishedCount());
+ EXPECT_TRUE(content->getImage()->isBitmapImage());
+ EXPECT_EQ(1, content->getImage()->width());
+ EXPECT_EQ(1, content->getImage()->height());
- cachedImage->loader()->didReceiveResponse(
+ reloadingResource->loader()->didReceiveResponse(
WrappedResourceResponse(resourceResponse), nullptr);
- cachedImage->loader()->didReceiveData(
+ reloadingResource->loader()->didReceiveData(
reinterpret_cast<const char*>(kJpegImage2), sizeof(kJpegImage2));
- cachedImage->loader()->didFinishLoading(0.0, sizeof(kJpegImage2),
- sizeof(kJpegImage2));
- EXPECT_FALSE(cachedImage->errorOccurred());
- ASSERT_TRUE(cachedImage->getContent()->hasImage());
- EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull());
+ reloadingResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage2),
+ sizeof(kJpegImage2));
+ EXPECT_FALSE(content->errorOccurred());
+ ASSERT_TRUE(content->hasImage());
+ EXPECT_FALSE(content->getImage()->isNull());
+ EXPECT_EQ(3, client->imageChangedCount());
EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnLastImageChanged());
- EXPECT_TRUE(client->notifyFinishedCalled());
- // The client should not have been notified of completion again.
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished());
+ // The observer should not have been notified of completion again.
+ EXPECT_EQ(1, client->imageNotifyFinishedCount());
EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished());
- EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage());
- EXPECT_EQ(50, cachedImage->getContent()->getImage()->width());
- EXPECT_EQ(50, cachedImage->getContent()->getImage()->height());
+ EXPECT_TRUE(content->getImage()->isBitmapImage());
+ EXPECT_EQ(50, content->getImage()->width());
+ EXPECT_EQ(50, content->getImage()->height());
+}
+
+TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderViaResourceFetcher) {
+ ResourceFetcher* fetcher =
+ ResourceFetcher::create(ImageResourceTestMockFetchContext::create());
+
+ KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
+ ScopedRegisteredURL scopedRegisteredURL(testURL);
+
+ ResourceRequest request = ResourceRequest(testURL);
+ request.setLoFiState(WebURLRequest::LoFiOn);
+ FetchRequest fetchRequest(request, FetchInitiatorInfo());
+ ImageResource* cachedImage = ImageResource::fetch(fetchRequest, fetcher);
+ ImageResourceContent* content = cachedImage->getContent();
+
+ Persistent<MockImageResourceClient> client =
+ new MockImageResourceClient(cachedImage);
+
+ // Send the image response.
+ ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage),
+ nullAtom, String());
+ resourceResponse.addHTTPHeaderField("chrome-proxy-content-transform",
+ "empty-image");
+
+ cachedImage->loader()->didReceiveResponse(
+ WrappedResourceResponse(resourceResponse));
+ cachedImage->loader()->didReceiveData(
+ reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
+ cachedImage->loader()->didFinishLoading(0.0, sizeof(kJpegImage),
+ sizeof(kJpegImage));
+
+ EXPECT_EQ(cachedImage, fetcher->cachedResource(testURL));
+ fetcher->reloadLoFiImages();
+ const ImageResource* reloadingResource = content->resourceForTest();
+
+ ASSERT_TRUE(reloadingResource);
+ EXPECT_NE(cachedImage, reloadingResource);
+ EXPECT_EQ(content, reloadingResource->getContent());
+ EXPECT_FALSE(cachedImage->getContent());
+ EXPECT_EQ(reloadingResource, fetcher->cachedResource(testURL));
+ EXPECT_EQ(reloadingResource, memoryCache()->resourceForURL(testURL));
+ EXPECT_FALSE(reloadingResource->isPlaceholder());
+
+ reloadingResource->loader()->cancel();
}
TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) {
@@ -473,9 +534,15 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) {
ResourceFetcher::create(ImageResourceTestMockFetchContext::create());
ImageResource* cachedImage = ImageResource::fetch(fetchRequest, fetcher);
+ ImageResourceContent* content = cachedImage->getContent();
Persistent<MockImageResourceClient> client =
new MockImageResourceClient(cachedImage);
+ // To test that the old ImageResource is cancelled if it has no
+ // ResourceClient when reloading is started, we remove |client| as client
+ // here, but not as observer.
+ client->removeAsClient();
+
// Send the image response.
ResourceResponse initialResourceResponse(
testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String());
@@ -486,48 +553,67 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) {
cachedImage->loader()->didReceiveData(
reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
- EXPECT_FALSE(cachedImage->errorOccurred());
- ASSERT_TRUE(cachedImage->getContent()->hasImage());
- EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull());
+ EXPECT_FALSE(content->errorOccurred());
+ ASSERT_TRUE(content->hasImage());
+ EXPECT_FALSE(content->getImage()->isNull());
EXPECT_EQ(1, client->imageChangedCount());
EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged());
- EXPECT_FALSE(client->notifyFinishedCalled());
- EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage());
- EXPECT_EQ(1, cachedImage->getContent()->getImage()->width());
- EXPECT_EQ(1, cachedImage->getContent()->getImage()->height());
+ EXPECT_TRUE(content->getImage()->isBitmapImage());
+ EXPECT_EQ(1, content->getImage()->width());
+ EXPECT_EQ(1, content->getImage()->height());
// Call reloadIfLoFiOrPlaceholderImage() while the image is still loading.
- cachedImage->reloadIfLoFiOrPlaceholderImage(fetcher, Resource::kReloadAlways);
- EXPECT_FALSE(cachedImage->errorOccurred());
- EXPECT_FALSE(cachedImage->resourceBuffer());
- EXPECT_FALSE(cachedImage->getContent()->hasImage());
- EXPECT_EQ(2, client->imageChangedCount());
- EXPECT_EQ(0U, client->encodedSizeOnLastImageChanged());
+ ImageResource* reloadingResource =
+ cachedImage->reloadIfLoFiOrPlaceholderImage(fetcher,
+ Resource::kReloadAlways);
+
+ ASSERT_TRUE(reloadingResource);
+ EXPECT_NE(cachedImage, reloadingResource);
+ EXPECT_EQ(content, reloadingResource->getContent());
+ EXPECT_FALSE(cachedImage->getContent());
+ EXPECT_EQ(reloadingResource, fetcher->cachedResource(testURL));
+ EXPECT_EQ(reloadingResource, memoryCache()->resourceForURL(testURL));
+ EXPECT_FALSE(reloadingResource->isPlaceholder());
+
+ EXPECT_FALSE(content->errorOccurred());
+ // ImageResourceContent is not notified of the start of LoFi reloading.
+ EXPECT_TRUE(content->hasImage());
+ EXPECT_EQ(1, client->imageChangedCount());
+ EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged());
+ EXPECT_EQ(1, content->getImage()->width());
+ EXPECT_EQ(1, content->getImage()->height());
// The client should not have been notified of completion yet, since the image
// is still loading.
- EXPECT_FALSE(client->notifyFinishedCalled());
+ EXPECT_EQ(0, client->imageNotifyFinishedCount());
- cachedImage->loader()->didReceiveResponse(
+ reloadingResource->loader()->didReceiveResponse(
WrappedResourceResponse(ResourceResponse(
testURL, "image/jpeg", sizeof(kJpegImage2), nullAtom, String())),
nullptr);
- cachedImage->loader()->didReceiveData(
+ reloadingResource->loader()->didReceiveData(
reinterpret_cast<const char*>(kJpegImage2), sizeof(kJpegImage2));
- cachedImage->loader()->didFinishLoading(0.0, sizeof(kJpegImage2),
- sizeof(kJpegImage2));
+ reloadingResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage2),
+ sizeof(kJpegImage2));
- EXPECT_FALSE(cachedImage->errorOccurred());
- ASSERT_TRUE(cachedImage->getContent()->hasImage());
- EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull());
+ EXPECT_FALSE(content->errorOccurred());
+ // ImageResourceContent is notified of reloaded response.
+ ASSERT_TRUE(content->hasImage());
+ EXPECT_EQ(1, client->imageNotifyFinishedCount());
+ EXPECT_EQ(2, client->imageChangedCount());
+ EXPECT_FALSE(content->getImage()->isNull());
EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnLastImageChanged());
- // The client should have been notified of completion only after the reload
+ // The observer should have been notified of completion only after the reload
// completed.
- EXPECT_TRUE(client->notifyFinishedCalled());
- EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnNotifyFinished());
EXPECT_EQ(sizeof(kJpegImage2), client->encodedSizeOnImageNotifyFinished());
- EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage());
- EXPECT_EQ(50, cachedImage->getContent()->getImage()->width());
- EXPECT_EQ(50, cachedImage->getContent()->getImage()->height());
+ EXPECT_TRUE(content->getImage()->isBitmapImage());
+ EXPECT_EQ(50, content->getImage()->width());
+ EXPECT_EQ(50, content->getImage()->height());
+
+ // Trigger the cancel timer, ensure the load for the first ImageResource
+ // was cancelled because reloading is started using another ImageResource.
+ EXPECT_EQ(Resource::Pending, cachedImage->getStatus());
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(Resource::LoadError, cachedImage->getStatus());
}
TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) {
@@ -539,11 +625,14 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) {
FetchRequest request(testURL, FetchInitiatorInfo());
request.setAllowImagePlaceholder();
ImageResource* image = ImageResource::fetch(request, fetcher);
+ ImageResourceContent* content = image->getContent();
+ ASSERT_TRUE(content);
+ Persistent<MockImageResourceClient> client =
+ new MockImageResourceClient(image);
+
EXPECT_EQ(FetchRequest::AllowPlaceholder,
request.placeholderImageRequestType());
EXPECT_EQ("bytes=0-2047", image->resourceRequest().httpHeaderField("range"));
- Persistent<MockImageResourceClient> client =
- new MockImageResourceClient(image);
ResourceResponse response(testURL, "image/jpeg",
kJpegImageSubrangeWithDimensionsLength, nullAtom,
@@ -561,15 +650,25 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderForPlaceholder) {
EXPECT_EQ(Resource::Cached, image->getStatus());
EXPECT_TRUE(image->isPlaceholder());
- image->reloadIfLoFiOrPlaceholderImage(fetcher, Resource::kReloadAlways);
+ ImageResource* reloadingResource =
+ image->reloadIfLoFiOrPlaceholderImage(fetcher, Resource::kReloadAlways);
- EXPECT_EQ(Resource::Pending, image->getStatus());
- EXPECT_FALSE(image->isPlaceholder());
- EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range"));
- EXPECT_EQ(static_cast<int>(WebCachePolicy::BypassingCache),
- static_cast<int>(image->resourceRequest().getCachePolicy()));
+ ASSERT_TRUE(reloadingResource);
+ EXPECT_NE(image, reloadingResource);
+ EXPECT_EQ(content, reloadingResource->getContent());
+ EXPECT_FALSE(image->getContent());
+ EXPECT_EQ(reloadingResource, fetcher->cachedResource(testURL));
+ EXPECT_EQ(reloadingResource, memoryCache()->resourceForURL(testURL));
+ EXPECT_FALSE(reloadingResource->isPlaceholder());
- image->loader()->cancel();
+ EXPECT_EQ(Resource::Pending, content->getStatus());
+ EXPECT_EQ(nullAtom,
+ reloadingResource->resourceRequest().httpHeaderField("range"));
+ EXPECT_EQ(
+ static_cast<int>(WebCachePolicy::BypassingCache),
+ static_cast<int>(reloadingResource->resourceRequest().getCachePolicy()));
+
+ reloadingResource->loader()->cancel();
}
TEST(ImageResourceTest, SVGImage) {
@@ -1004,9 +1103,10 @@ TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) {
FetchRequest request(testURL, FetchInitiatorInfo());
request.setAllowImagePlaceholder();
- ImageResource* image = ImageResource::fetch(
- request,
- ResourceFetcher::create(ImageResourceTestMockFetchContext::create()));
+ ResourceFetcher* fetcher =
+ ResourceFetcher::create(ImageResourceTestMockFetchContext::create());
+ ImageResource* image = ImageResource::fetch(request, fetcher);
+ ImageResourceContent* content = image->getContent();
EXPECT_EQ(FetchRequest::AllowPlaceholder,
request.placeholderImageRequestType());
EXPECT_EQ("bytes=0-2047", image->resourceRequest().httpHeaderField("range"));
@@ -1020,37 +1120,46 @@ TEST(ImageResourceTest, FetchAllowPlaceholderUnsuccessful) {
testURL, "image/jpeg", sizeof(kBadData), nullAtom, String())));
image->loader()->didReceiveData(kBadData, sizeof(kBadData));
+ const ImageResource* reloadingResource = content->resourceForTest();
+
+ ASSERT_TRUE(reloadingResource);
+ EXPECT_NE(image, reloadingResource);
+ EXPECT_EQ(content, reloadingResource->getContent());
+ EXPECT_FALSE(image->getContent());
+ EXPECT_EQ(reloadingResource, fetcher->cachedResource(testURL));
+ EXPECT_EQ(reloadingResource, memoryCache()->resourceForURL(testURL));
+ EXPECT_FALSE(reloadingResource->isPlaceholder());
+
// The dimensions could not be extracted, so the full original image should be
// loading.
- EXPECT_EQ(Resource::Pending, image->getStatus());
- EXPECT_FALSE(image->isPlaceholder());
- EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range"));
- EXPECT_EQ(static_cast<int>(WebCachePolicy::BypassingCache),
- static_cast<int>(image->resourceRequest().getCachePolicy()));
- EXPECT_FALSE(client->notifyFinishedCalled());
+ EXPECT_EQ(Resource::Pending, content->getStatus());
+ EXPECT_EQ(nullAtom,
+ reloadingResource->resourceRequest().httpHeaderField("range"));
+ EXPECT_EQ(
+ static_cast<int>(WebCachePolicy::BypassingCache),
+ static_cast<int>(reloadingResource->resourceRequest().getCachePolicy()));
EXPECT_EQ(0, client->imageNotifyFinishedCount());
- image->loader()->didReceiveResponse(WrappedResourceResponse(ResourceResponse(
- testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String())));
- image->loader()->didReceiveData(reinterpret_cast<const char*>(kJpegImage),
- sizeof(kJpegImage));
- image->loader()->didFinishLoading(0.0, sizeof(kJpegImage),
- sizeof(kJpegImage));
+ reloadingResource->loader()->didReceiveResponse(
+ WrappedResourceResponse(ResourceResponse(
+ testURL, "image/jpeg", sizeof(kJpegImage), nullAtom, String())));
+ reloadingResource->loader()->didReceiveData(
+ reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
+ reloadingResource->loader()->didFinishLoading(0.0, sizeof(kJpegImage),
+ sizeof(kJpegImage));
- EXPECT_EQ(Resource::Cached, image->getStatus());
- EXPECT_EQ(sizeof(kJpegImage), image->encodedSize());
- EXPECT_FALSE(image->isPlaceholder());
+ EXPECT_EQ(Resource::Cached, content->getStatus());
+ EXPECT_EQ(sizeof(kJpegImage), reloadingResource->encodedSize());
+ EXPECT_FALSE(reloadingResource->isPlaceholder());
EXPECT_LT(0, client->imageChangedCount());
EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnLastImageChanged());
- EXPECT_TRUE(client->notifyFinishedCalled());
EXPECT_EQ(1, client->imageNotifyFinishedCount());
- EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnNotifyFinished());
EXPECT_EQ(sizeof(kJpegImage), client->encodedSizeOnImageNotifyFinished());
- ASSERT_TRUE(image->getContent()->hasImage());
- EXPECT_EQ(1, image->getContent()->getImage()->width());
- EXPECT_EQ(1, image->getContent()->getImage()->height());
- EXPECT_TRUE(image->getContent()->getImage()->isBitmapImage());
+ ASSERT_TRUE(content->hasImage());
+ EXPECT_EQ(1, content->getImage()->width());
+ EXPECT_EQ(1, content->getImage()->height());
+ EXPECT_TRUE(content->getImage()->isBitmapImage());
}
TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) {
@@ -1062,21 +1171,26 @@ TEST(ImageResourceTest, FetchAllowPlaceholderThenDisallowPlaceholder) {
FetchRequest placeholderRequest(testURL, FetchInitiatorInfo());
placeholderRequest.setAllowImagePlaceholder();
ImageResource* image = ImageResource::fetch(placeholderRequest, fetcher);
+ ImageResourceContent* content = image->getContent();
Persistent<MockImageResourceClient> client =
new MockImageResourceClient(image);
FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo());
ImageResource* secondImage =
ImageResource::fetch(nonPlaceholderRequest, fetcher);
- EXPECT_EQ(image, secondImage);
- EXPECT_EQ(Resource::Pending, image->getStatus());
- EXPECT_FALSE(image->isPlaceholder());
- EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range"));
+ EXPECT_NE(image, secondImage);
+ ASSERT_EQ(secondImage, content->resourceForTest());
+ EXPECT_EQ(secondImage, memoryCache()->resourceForURL(testURL));
+ EXPECT_EQ(content, secondImage->getContent());
+ EXPECT_EQ(Resource::Pending, content->getStatus());
+ EXPECT_FALSE(secondImage->isPlaceholder());
+ EXPECT_EQ(nullAtom, secondImage->resourceRequest().httpHeaderField("range"));
EXPECT_EQ(static_cast<int>(WebCachePolicy::UseProtocolCachePolicy),
- static_cast<int>(image->resourceRequest().getCachePolicy()));
+ static_cast<int>(secondImage->resourceRequest().getCachePolicy()));
EXPECT_FALSE(client->notifyFinishedCalled());
image->loader()->cancel();
+ secondImage->loader()->cancel();
}
TEST(ImageResourceTest,
@@ -1089,6 +1203,7 @@ TEST(ImageResourceTest,
FetchRequest placeholderRequest(testURL, FetchInitiatorInfo());
placeholderRequest.setAllowImagePlaceholder();
ImageResource* image = ImageResource::fetch(placeholderRequest, fetcher);
+ ImageResourceContent* content = image->getContent();
Persistent<MockImageResourceClient> client =
new MockImageResourceClient(image);
@@ -1114,14 +1229,18 @@ TEST(ImageResourceTest,
FetchRequest nonPlaceholderRequest(testURL, FetchInitiatorInfo());
ImageResource* secondImage =
ImageResource::fetch(nonPlaceholderRequest, fetcher);
- EXPECT_EQ(image, secondImage);
- EXPECT_EQ(Resource::Pending, image->getStatus());
- EXPECT_FALSE(image->isPlaceholder());
- EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range"));
+ EXPECT_FALSE(image->getContent());
+ EXPECT_NE(image, secondImage);
+ EXPECT_EQ(secondImage, memoryCache()->resourceForURL(testURL));
+ ASSERT_EQ(secondImage, content->resourceForTest());
+ EXPECT_EQ(content, secondImage->getContent());
+ EXPECT_EQ(Resource::Pending, content->getStatus());
+ EXPECT_FALSE(secondImage->isPlaceholder());
+ EXPECT_EQ(nullAtom, secondImage->resourceRequest().httpHeaderField("range"));
EXPECT_EQ(static_cast<int>(WebCachePolicy::UseProtocolCachePolicy),
- static_cast<int>(image->resourceRequest().getCachePolicy()));
+ static_cast<int>(secondImage->resourceRequest().getCachePolicy()));
- image->loader()->cancel();
+ secondImage->loader()->cancel();
}
TEST(ImageResourceTest, PeriodicFlushTest) {

Powered by Google App Engine
This is Rietveld 408576698