@@ -1438,15 +1438,55 @@ TEST_F(CacheUrlAsyncFetcherTest, FetchFailedIgnore) {
1438
1438
EXPECT_EQ (0 , http_cache_->cache_inserts ()->Get ());
1439
1439
}
1440
1440
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
+
1441
1481
TEST_F (CacheUrlAsyncFetcherTest, NoCacheHtmlOnEmptyHeader) {
1442
1482
ResponseHeaders response_headers;
1443
1483
SetDefaultHeaders (kContentTypeHtml , &response_headers);
1444
1484
response_headers.SetDate (timer_.NowMs ());
1445
1485
response_headers.RemoveAll (HttpAttributes::kCacheControl );
1446
1486
const char url[] = " http://www.example.com/foo.html" ;
1447
- mock_fetcher_.SetResponse (url, response_headers, " " );
1487
+ mock_fetcher_.SetResponse (url, response_headers, " foo " );
1448
1488
1449
- ExpectNoCache (url, " " );
1489
+ ExpectNoCache (url, " foo " );
1450
1490
}
1451
1491
1452
1492
TEST_F (CacheUrlAsyncFetcherTest, DoCacheHtmlOnEmptyHeader) {
@@ -1458,9 +1498,9 @@ TEST_F(CacheUrlAsyncFetcherTest, DoCacheHtmlOnEmptyHeader) {
1458
1498
response_headers.SetDate (timer_.NowMs ());
1459
1499
response_headers.RemoveAll (HttpAttributes::kCacheControl );
1460
1500
const char url[] = " http://www.example.com/foo.html" ;
1461
- mock_fetcher_.SetResponse (url, response_headers, " " );
1501
+ mock_fetcher_.SetResponse (url, response_headers, " foo " );
1462
1502
1463
- ExpectCache (url, " " );
1503
+ ExpectCache (url, " foo " );
1464
1504
}
1465
1505
1466
1506
// Even when set_default_cache_html(true), we still don't cache responses
@@ -1474,9 +1514,9 @@ TEST_F(CacheUrlAsyncFetcherTest, NoCacheSetCookie) {
1474
1514
response_headers.RemoveAll (HttpAttributes::kCacheControl );
1475
1515
response_headers.Add (HttpAttributes::kSetCookie , " foo=bar" );
1476
1516
const char url[] = " http://www.example.com/foo.html" ;
1477
- mock_fetcher_.SetResponse (url, response_headers, " " );
1517
+ mock_fetcher_.SetResponse (url, response_headers, " foo " );
1478
1518
1479
- ExpectNoCache (url, " " );
1519
+ ExpectNoCache (url, " foo " );
1480
1520
}
1481
1521
1482
1522
TEST_F (CacheUrlAsyncFetcherTest, CachePublicSansTtl) {
@@ -1488,9 +1528,9 @@ TEST_F(CacheUrlAsyncFetcherTest, CachePublicSansTtl) {
1488
1528
response_headers.SetDate (timer_.NowMs ());
1489
1529
response_headers.Replace (HttpAttributes::kCacheControl , " public" );
1490
1530
const char url[] = " http://www.example.com/foo.html" ;
1491
- mock_fetcher_.SetResponse (url, response_headers, " " );
1531
+ mock_fetcher_.SetResponse (url, response_headers, " foo " );
1492
1532
1493
- ExpectCache (url, " " );
1533
+ ExpectCache (url, " foo " );
1494
1534
}
1495
1535
1496
1536
TEST_F (CacheUrlAsyncFetcherTest, CacheVaryForNonHtml) {
0 commit comments