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

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

Issue 2795073003: Treat responses with LoFi headers as being LoFi images. (Closed)
Patch Set: addressed comments Created 3 years, 9 months 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
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResource.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 962a51741d3c46f07a10a764fc513fce9bb5ec95..7107dcad2f4269c3e0619d93e0870eae2f42b11e 100644
--- a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
@@ -507,7 +507,6 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
KURL testURL(ParsedURLString, kTestURL);
ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
ResourceRequest request = ResourceRequest(testURL);
- request.setPreviewsState(WebURLRequest::ServerLoFiOn);
ImageResource* imageResource = ImageResource::create(request);
imageResource->setStatus(ResourceStatus::Pending);
@@ -548,6 +547,49 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
WebCachePolicy::BypassingCache);
}
+TEST(ImageResourceTest,
+ ReloadIfLoFiOrPlaceholderAfterFinishedWithoutLoFiHeaders) {
+ KURL testURL(ParsedURLString, kTestURL);
+ ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
+ ResourceRequest request = ResourceRequest(testURL);
+ request.setPreviewsState(WebURLRequest::ServerLoFiOn);
+ ImageResource* imageResource = ImageResource::create(request);
+ imageResource->setStatus(ResourceStatus::Pending);
+
+ std::unique_ptr<MockImageResourceObserver> observer =
+ MockImageResourceObserver::create(imageResource->getContent());
+ ResourceFetcher* fetcher = createFetcher();
+
+ // Send the image response, without any LoFi image response headers.
+ imageResource->responseReceived(
+ ResourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage), nullAtom),
+ nullptr);
+ imageResource->appendData(reinterpret_cast<const char*>(kJpegImage),
+ sizeof(kJpegImage));
+ imageResource->finish();
+ EXPECT_FALSE(imageResource->errorOccurred());
+ ASSERT_TRUE(imageResource->getContent()->hasImage());
+ EXPECT_FALSE(imageResource->getContent()->getImage()->isNull());
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnLastImageChanged());
+ // The observer should have been notified that the image load completed.
+ EXPECT_TRUE(observer->imageNotifyFinishedCalled());
+ EXPECT_EQ(kJpegImageWidth, observer->imageWidthOnImageNotifyFinished());
+ EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage());
+ EXPECT_EQ(kJpegImageWidth, imageResource->getContent()->getImage()->width());
+ EXPECT_EQ(kJpegImageHeight,
+ imageResource->getContent()->getImage()->height());
+
+ // Call reloadIfLoFiOrPlaceholderImage() after the image has finished loading.
+ imageResource->reloadIfLoFiOrPlaceholderImage(fetcher,
+ Resource::kReloadAlways);
+
+ // The image should not have been reloaded, since it didn't have the LoFi
+ // image response headers.
+ EXPECT_EQ(2, observer->imageChangedCount());
+ EXPECT_TRUE(imageResource->isLoaded());
+}
+
TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderViaResourceFetcher) {
ResourceFetcher* fetcher = createFetcher();
@@ -604,12 +646,8 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderDuringFetch) {
MockImageResourceObserver::create(imageResource->getContent());
// Send the image response.
- ResourceResponse initialResourceResponse(testURL, "image/jpeg",
- sizeof(kJpegImage), nullAtom);
- initialResourceResponse.addHTTPHeaderField("chrome-proxy", "q=low");
-
- imageResource->loader()->didReceiveResponse(
- WrappedResourceResponse(initialResourceResponse));
+ imageResource->loader()->didReceiveResponse(WrappedResourceResponse(
+ ResourceResponse(testURL, "image/jpeg", sizeof(kJpegImage), nullAtom)));
imageResource->loader()->didReceiveData(
reinterpret_cast<const char*>(kJpegImage), sizeof(kJpegImage));
« no previous file with comments | « third_party/WebKit/Source/core/loader/resource/ImageResource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698