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

Unified Diff: components/image_fetcher/image_data_fetcher_unittest.cc

Issue 2749283002: components/image_fetcher: Add a from_http_cache flag to RequestMetadata (Closed)
Patch Set: test 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 | « components/image_fetcher/image_data_fetcher.cc ('k') | components/image_fetcher/request_metadata.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/image_fetcher/image_data_fetcher_unittest.cc
diff --git a/components/image_fetcher/image_data_fetcher_unittest.cc b/components/image_fetcher/image_data_fetcher_unittest.cc
index 15039781fb4a9f2fd8f002491c44e16e8e28c2a8..e8d240f3e3273b856c8bf70ab5c0730d96248814 100644
--- a/components/image_fetcher/image_data_fetcher_unittest.cc
+++ b/components/image_fetcher/image_data_fetcher_unittest.cc
@@ -65,7 +65,7 @@ TEST_F(ImageDataFetcherTest, FetchImageData) {
RequestMetadata expected_metadata;
expected_metadata.mime_type = std::string("image/png");
- expected_metadata.response_code = net::HTTP_OK;
+ expected_metadata.http_response_code = net::HTTP_OK;
EXPECT_CALL(*this, OnImageDataFetched(std::string(kURLResponseData),
expected_metadata));
@@ -90,6 +90,40 @@ TEST_F(ImageDataFetcherTest, FetchImageData) {
test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher);
}
+TEST_F(ImageDataFetcherTest, FetchImageData_FromCache) {
+ image_data_fetcher_.FetchImageData(
+ GURL(kImageURL), base::Bind(&ImageDataFetcherTest::OnImageDataFetched,
+ base::Unretained(this)));
+
+ RequestMetadata expected_metadata;
+ expected_metadata.mime_type = std::string("image/png");
+ expected_metadata.http_response_code = net::HTTP_OK;
+ expected_metadata.from_http_cache = true;
+ EXPECT_CALL(*this, OnImageDataFetched(std::string(kURLResponseData),
+ expected_metadata));
+
+ // Get and configure the TestURLFetcher.
+ net::TestURLFetcher* test_url_fetcher = fetcher_factory_.GetFetcherByID(0);
+ ASSERT_NE(nullptr, test_url_fetcher);
+ test_url_fetcher->set_status(
+ net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
+ test_url_fetcher->SetResponseString(kURLResponseData);
+ test_url_fetcher->set_response_code(net::HTTP_OK);
+ test_url_fetcher->set_was_cached(true);
+
+ std::string raw_header =
+ "HTTP/1.1 200 OK\n"
+ "Content-type: image/png\n\n";
+ std::replace(raw_header.begin(), raw_header.end(), '\n', '\0');
+ scoped_refptr<net::HttpResponseHeaders> headers(
+ new net::HttpResponseHeaders(raw_header));
+
+ test_url_fetcher->set_response_headers(headers);
+
+ // Call the URLFetcher delegate to continue the test.
+ test_url_fetcher->delegate()->OnURLFetchComplete(test_url_fetcher);
+}
+
TEST_F(ImageDataFetcherTest, FetchImageData_NotFound) {
image_data_fetcher_.FetchImageData(
GURL(kImageURL), base::Bind(&ImageDataFetcherTest::OnImageDataFetched,
@@ -97,7 +131,7 @@ TEST_F(ImageDataFetcherTest, FetchImageData_NotFound) {
RequestMetadata expected_metadata;
expected_metadata.mime_type = std::string("image/png");
- expected_metadata.response_code = net::HTTP_NOT_FOUND;
+ expected_metadata.http_response_code = net::HTTP_NOT_FOUND;
// For 404, expect an empty result even though correct image data is sent.
EXPECT_CALL(*this, OnImageDataFetched(std::string(), expected_metadata));
@@ -128,7 +162,7 @@ TEST_F(ImageDataFetcherTest, FetchImageData_FailedRequest) {
base::Unretained(this)));
RequestMetadata expected_metadata;
- expected_metadata.response_code = net::URLFetcher::RESPONSE_CODE_INVALID;
+ expected_metadata.http_response_code = net::URLFetcher::RESPONSE_CODE_INVALID;
EXPECT_CALL(
*this, OnImageDataFetchedFailedRequest(std::string(), expected_metadata));
« no previous file with comments | « components/image_fetcher/image_data_fetcher.cc ('k') | components/image_fetcher/request_metadata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698