@@ -1438,15 +1438,55 @@ TEST_F(CacheUrlAsyncFetcherTest, FetchFailedIgnore) {
14381438 EXPECT_EQ (0 , http_cache_->cache_inserts ()->Get ());
14391439}
14401440
1441+ TEST_F (CacheUrlAsyncFetcherTest, NoCacheEmpty) {
1442+ const char url[] = " http://www.example.com/empty.html" ;
1443+ ResponseHeaders response_headers;
1444+ SetDefaultHeaders (kContentTypeHtml , &response_headers);
1445+ int ttl_ms = 5 * Timer::kMinuteMs ;
1446+ response_headers.SetDateAndCaching (timer_.NowMs (), ttl_ms);
1447+
1448+ GoogleString empty_contents = " " ;
1449+ mock_fetcher_.SetResponse (url, response_headers, empty_contents);
1450+ FetchAndValidate (url, empty_request_headers_, true , HttpStatus::kOK ,
1451+ empty_contents, kBackendFetch , false );
1452+
1453+ GoogleString non_empty_contents = " foobar" ;
1454+ mock_fetcher_.SetResponse (url, response_headers, non_empty_contents);
1455+ // cache_url_fetcher did not remember the empty contents.
1456+ FetchAndValidate (url, empty_request_headers_, true , HttpStatus::kOK ,
1457+ non_empty_contents, kBackendFetch , true );
1458+ }
1459+
1460+ TEST_F (CacheUrlAsyncFetcherTest, CacheNonEmpty) {
1461+ // Companion test to NoCacheEmpty to make sure we are caching non-empty
1462+ // through the same flow.
1463+ const char url[] = " http://www.example.com/non_empty.html" ;
1464+ ResponseHeaders response_headers;
1465+ SetDefaultHeaders (kContentTypeHtml , &response_headers);
1466+ int ttl_ms = 5 * Timer::kMinuteMs ;
1467+ response_headers.SetDateAndCaching (timer_.NowMs (), ttl_ms);
1468+
1469+ GoogleString original_contents = " foo" ;
1470+ mock_fetcher_.SetResponse (url, response_headers, original_contents);
1471+ FetchAndValidate (url, empty_request_headers_, true , HttpStatus::kOK ,
1472+ original_contents, kBackendFetch , true );
1473+
1474+ GoogleString new_contents = " foobar" ;
1475+ mock_fetcher_.SetResponse (url, response_headers, new_contents);
1476+ // cache_url_fetcher did remember the original content.
1477+ FetchAndValidate (url, empty_request_headers_, true , HttpStatus::kOK ,
1478+ original_contents, kBackendFetch , true );
1479+ }
1480+
14411481TEST_F (CacheUrlAsyncFetcherTest, NoCacheHtmlOnEmptyHeader) {
14421482 ResponseHeaders response_headers;
14431483 SetDefaultHeaders (kContentTypeHtml , &response_headers);
14441484 response_headers.SetDate (timer_.NowMs ());
14451485 response_headers.RemoveAll (HttpAttributes::kCacheControl );
14461486 const char url[] = " http://www.example.com/foo.html" ;
1447- mock_fetcher_.SetResponse (url, response_headers, " " );
1487+ mock_fetcher_.SetResponse (url, response_headers, " foo " );
14481488
1449- ExpectNoCache (url, " " );
1489+ ExpectNoCache (url, " foo " );
14501490}
14511491
14521492TEST_F (CacheUrlAsyncFetcherTest, DoCacheHtmlOnEmptyHeader) {
@@ -1458,9 +1498,9 @@ TEST_F(CacheUrlAsyncFetcherTest, DoCacheHtmlOnEmptyHeader) {
14581498 response_headers.SetDate (timer_.NowMs ());
14591499 response_headers.RemoveAll (HttpAttributes::kCacheControl );
14601500 const char url[] = " http://www.example.com/foo.html" ;
1461- mock_fetcher_.SetResponse (url, response_headers, " " );
1501+ mock_fetcher_.SetResponse (url, response_headers, " foo " );
14621502
1463- ExpectCache (url, " " );
1503+ ExpectCache (url, " foo " );
14641504}
14651505
14661506// Even when set_default_cache_html(true), we still don't cache responses
@@ -1474,9 +1514,9 @@ TEST_F(CacheUrlAsyncFetcherTest, NoCacheSetCookie) {
14741514 response_headers.RemoveAll (HttpAttributes::kCacheControl );
14751515 response_headers.Add (HttpAttributes::kSetCookie , " foo=bar" );
14761516 const char url[] = " http://www.example.com/foo.html" ;
1477- mock_fetcher_.SetResponse (url, response_headers, " " );
1517+ mock_fetcher_.SetResponse (url, response_headers, " foo " );
14781518
1479- ExpectNoCache (url, " " );
1519+ ExpectNoCache (url, " foo " );
14801520}
14811521
14821522TEST_F (CacheUrlAsyncFetcherTest, CachePublicSansTtl) {
@@ -1488,9 +1528,9 @@ TEST_F(CacheUrlAsyncFetcherTest, CachePublicSansTtl) {
14881528 response_headers.SetDate (timer_.NowMs ());
14891529 response_headers.Replace (HttpAttributes::kCacheControl , " public" );
14901530 const char url[] = " http://www.example.com/foo.html" ;
1491- mock_fetcher_.SetResponse (url, response_headers, " " );
1531+ mock_fetcher_.SetResponse (url, response_headers, " foo " );
14921532
1493- ExpectCache (url, " " );
1533+ ExpectCache (url, " foo " );
14941534}
14951535
14961536TEST_F (CacheUrlAsyncFetcherTest, CacheVaryForNonHtml) {
0 commit comments