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

Unified Diff: net/http/http_cache_unittest.cc

Issue 1039263002: //net changes for stale-while-revalidate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s-w-r-remove-old-impl
Patch Set: Rebase. Created 5 years, 4 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: net/http/http_cache_unittest.cc
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 8d62ee0b4d59c7d2d03d6b36a555c1a580c1883a..a24271417a049772e9d6df4727d7fda11a431e79 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -7377,6 +7377,149 @@ TEST(HttpCache, ResourceFreshnessHeaderNotSent) {
EXPECT_EQ(2, cache.network_layer()->transaction_count());
}
+TEST(HttpCache, StaleContentNotUsedWhenLoadFlagNotSet) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction stale_while_revalidate_transaction(
+ kSimpleGET_Transaction);
+
+ stale_while_revalidate_transaction.response_headers =
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
+ "Age: 10801\n"
+ "Cache-Control: max-age=0,stale-while-revalidate=86400\n";
+
+ // Write to the cache.
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+
+ // Send the request again and check that it is sent to the network again.
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
rvargas (doing something else) 2015/08/20 22:26:29 We should check the response flag instead of writi
Adam Rice 2015/08/21 15:01:46 Done.
+
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+}
+
+TEST(HttpCache, StaleContentUsedWhenLoadFlagSetAndUsable) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction stale_while_revalidate_transaction(
+ kSimpleGET_Transaction);
+ stale_while_revalidate_transaction.load_flags |=
+ LOAD_SUPPORT_ASYNC_REVALIDATION;
+ stale_while_revalidate_transaction.response_headers =
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
+ "Age: 10801\n"
+ "Cache-Control: max-age=0,stale-while-revalidate=86400\n";
+
+ // Write to the cache.
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+
+ // Send the request again and check that it is not sent to the network again.
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+}
+
+TEST(HttpCache, StaleContentNotUsedWhenUnusable) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction stale_while_revalidate_transaction(
+ kSimpleGET_Transaction);
+ stale_while_revalidate_transaction.load_flags |=
+ LOAD_SUPPORT_ASYNC_REVALIDATION;
+ stale_while_revalidate_transaction.response_headers =
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
+ "Age: 10801\n"
+ "Cache-Control: max-age=0,stale-while-revalidate=1800\n";
+
+ // Write to the cache.
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+
+ // Send the request again and check that it is sent to the network again.
+ RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
+
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+}
+
+TEST(HttpCache, AsyncRevalidationRequiredWhenLoadFlagSetAndUsable) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction stale_while_revalidate_transaction(
+ kSimpleGET_Transaction);
+ stale_while_revalidate_transaction.load_flags |=
+ LOAD_SUPPORT_ASYNC_REVALIDATION;
+ stale_while_revalidate_transaction.response_headers =
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
+ "Age: 10801\n"
+ "Cache-Control: max-age=0,stale-while-revalidate=86400\n";
+
+ // Write to the cache.
+ HttpResponseInfo response_info;
+ RunTransactionTestWithResponseInfo(
+ cache.http_cache(), stale_while_revalidate_transaction, &response_info);
+
+ EXPECT_FALSE(response_info.async_revalidation_required);
+
+ // Send the request again and check that the async_revalidation_required flag
+ // is set.
+ RunTransactionTestWithResponseInfo(
+ cache.http_cache(), stale_while_revalidate_transaction, &response_info);
+
+ EXPECT_TRUE(response_info.async_revalidation_required);
+}
+
+TEST(HttpCache, AsyncRevalidationNotRequiredWhenLoadFlagNotSet) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction stale_while_revalidate_transaction(
+ kSimpleGET_Transaction);
+ stale_while_revalidate_transaction.response_headers =
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
+ "Age: 10801\n"
+ "Cache-Control: max-age=0,stale-while-revalidate=86400\n";
+
+ // Write to the cache.
+ HttpResponseInfo response_info;
+ RunTransactionTestWithResponseInfo(
+ cache.http_cache(), stale_while_revalidate_transaction, &response_info);
+
+ // Send the request again and check that the async_revalidation_required flag
+ // is not set.
+ RunTransactionTestWithResponseInfo(
+ cache.http_cache(), stale_while_revalidate_transaction, &response_info);
+
+ EXPECT_FALSE(response_info.async_revalidation_required);
+}
+
+TEST(HttpCache, AsyncRevalidationNotRequiredWhenNotUsable) {
+ MockHttpCache cache;
+
+ ScopedMockTransaction stale_while_revalidate_transaction(
+ kSimpleGET_Transaction);
+ stale_while_revalidate_transaction.load_flags |=
+ LOAD_SUPPORT_ASYNC_REVALIDATION;
+ stale_while_revalidate_transaction.response_headers =
+ "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
+ "Age: 10801\n"
+ "Cache-Control: max-age=0,stale-while-revalidate=1800\n";
+
+ // Write to the cache.
+ HttpResponseInfo response_info;
+ RunTransactionTestWithResponseInfo(
+ cache.http_cache(), stale_while_revalidate_transaction, &response_info);
+
+ // Send the request again and check that the async_revalidation_required flag
+ // is not set.
+ RunTransactionTestWithResponseInfo(
+ cache.http_cache(), stale_while_revalidate_transaction, &response_info);
+
+ EXPECT_FALSE(response_info.async_revalidation_required);
+}
+
// Tests that we allow multiple simultaneous, non-overlapping transactions to
// take place on a sparse entry.
TEST(HttpCache, RangeGET_MultipleRequests) {

Powered by Google App Engine
This is Rietveld 408576698