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

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

Issue 2800473002: Treat responses with legacy LoFi headers as LoFi images. (Closed)
Patch Set: Added comment describing CPCT header format Created 3 years, 8 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
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 7107dcad2f4269c3e0619d93e0870eae2f42b11e..d8c8ff9294e1efb737d63d426873f0c53557b12f 100644
--- a/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
+++ b/third_party/WebKit/Source/core/loader/resource/ImageResourceTest.cpp
@@ -547,6 +547,49 @@ TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinished) {
WebCachePolicy::BypassingCache);
}
+TEST(ImageResourceTest, ReloadIfLoFiOrPlaceholderAfterFinishedWithOldHeaders) {
+ KURL testURL(ParsedURLString, kTestURL);
+ ScopedMockedURLLoad scopedMockedURLLoad(testURL, GetTestFilePath());
+ ResourceRequest request = ResourceRequest(testURL);
+ 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.
+ ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage),
+ nullAtom);
+ resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low");
+
+ imageResource->responseReceived(resourceResponse, 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);
+
+ EXPECT_EQ(3, observer->imageChangedCount());
+ testThatReloadIsStartedThenServeReload(
+ testURL, imageResource, imageResource->getContent(), observer.get(),
+ WebCachePolicy::BypassingCache);
+}
+
TEST(ImageResourceTest,
ReloadIfLoFiOrPlaceholderAfterFinishedWithoutLoFiHeaders) {
KURL testURL(ParsedURLString, kTestURL);

Powered by Google App Engine
This is Rietveld 408576698