Index: net/http/http_cache_unittest.cc |
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc |
index 83241ab301e441665f6acf3f1b794fa7e5f9f183..e530b716c93d4ceffd39d1ea99696daa562c6f4a 100644 |
--- a/net/http/http_cache_unittest.cc |
+++ b/net/http/http_cache_unittest.cc |
@@ -6443,3 +6443,85 @@ TEST(HttpCache, ReceivedBytesRange) { |
RemoveMockTransaction(&kRangeGET_TransactionOK); |
} |
+ |
+static void CheckChromeFreshnessHeader(const net::HttpRequestInfo* request, |
+ std::string* response_status, |
+ std::string* response_headers, |
+ std::string* response_data) { |
+ std::string value; |
+ EXPECT_TRUE(request->extra_headers.GetHeader("Chrome-Freshness", &value)); |
+ EXPECT_EQ("max-age=3600,stale-while-revalidate=7200,age=228658821", value); |
tyoshino (SeeGerritForStatus)
2014/07/22 06:31:55
could you please write a comment explaining why th
Adam Rice
2014/07/22 07:27:42
I wrote a comment explaining that I don't know why
|
+} |
+ |
+// Verify that the Chrome-Freshness header is sent on a revalidation if the |
+// stale-while-revalidate directive was on the response. |
+TEST(HttpCache, StaleWhileRevalidateHeader) { |
+ MockHttpCache cache; |
+ |
+ const MockTransaction kStaleWhileRevalidateTransaction = { |
+ "http://www.example.com/stale-while-revalidate", |
+ "GET", |
+ base::Time(), |
+ "", |
+ net::LOAD_NORMAL, |
+ "HTTP/1.1 200 OK", |
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
+ "Cache-Control: max-age=3600,stale-while-revalidate=7200\n", |
+ base::Time(), |
+ "<title>Testing stale-while-revalidate</title>", |
+ TEST_MODE_SYNC_NET_START, |
+ NULL, |
+ 0, |
+ net::OK}; |
+ |
+ ScopedMockTransaction stale_while_revalidate_transaction( |
+ kStaleWhileRevalidateTransaction); |
+ |
+ // write to the cache |
tyoshino (SeeGerritForStatus)
2014/07/22 06:29:34
Use a capital letter at the head of a sentence in
Adam Rice
2014/07/22 07:27:42
Done.
|
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); |
+ |
+ // send the request again and check that Chrome-Freshness header is added. |
+ stale_while_revalidate_transaction.handler = CheckChromeFreshnessHeader; |
+ |
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); |
+} |
+ |
+static void CheckChromeFreshnessAbsent(const net::HttpRequestInfo* request, |
+ std::string* response_status, |
+ std::string* response_headers, |
+ std::string* response_data) { |
+ EXPECT_FALSE(request->extra_headers.HasHeader("Chrome-Freshness")); |
+} |
+ |
+// Verify that the Chrome-Freshness header is not sent when cookies are |
+// disabled. |
+TEST(HttpCache, StaleWhileRevalidateHeaderNotSent) { |
tyoshino (SeeGerritForStatus)
2014/07/22 06:29:34
ChromeFreshnessHeaderNotSent?
Adam Rice
2014/07/22 07:27:42
Done.
|
+ MockHttpCache cache; |
+ |
+ const MockTransaction kStaleWhileRevalidateTransaction = { |
+ "http://www.example.com/stale-while-revalidate", |
+ "GET", |
+ base::Time(), |
+ "", |
+ net::LOAD_DO_NOT_SEND_COOKIES, |
+ "HTTP/1.1 200 OK", |
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
+ "Cache-Control: max-age=3600,stale-while-revalidate=7200\n", |
+ base::Time(), |
+ "<title>Testing stale-while-revalidate</title>", |
+ TEST_MODE_SYNC_NET_START, |
+ NULL, |
+ 0, |
+ net::OK}; |
+ |
+ ScopedMockTransaction stale_while_revalidate_transaction( |
+ kStaleWhileRevalidateTransaction); |
+ |
+ // write to the cache |
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); |
+ |
+ // send the request again and check that Chrome-Freshness header is absent. |
+ stale_while_revalidate_transaction.handler = CheckChromeFreshnessAbsent; |
+ |
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); |
+} |