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

Unified Diff: net/http/http_response_headers_unittest.cc

Issue 455623003: stale-while-revalidate experimental implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Support the bandwidth reduction proxy. Created 6 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_response_headers_unittest.cc
diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc
index 409a6bddd8a92d2e47428b604db1d2808591c25e..1528615a4e6a6c125aae42ae1ae0034173414c65 100644
--- a/net/http/http_response_headers_unittest.cc
+++ b/net/http/http_response_headers_unittest.cc
@@ -777,9 +777,17 @@ INSTANTIATE_TEST_CASE_P(HttpResponseHeaders,
ContentTypeTest,
testing::ValuesIn(mimetype_tests));
+typedef net::HttpResponseHeaders::ValidationType ValidationType;
+const ValidationType VALIDATION_NONE =
+ net::HttpResponseHeaders::VALIDATION_NONE;
+const ValidationType VALIDATION_SYNCHRONOUS =
+ net::HttpResponseHeaders::VALIDATION_SYNCHRONOUS;
+const ValidationType VALIDATION_ASYNCHRONOUS =
+ net::HttpResponseHeaders::VALIDATION_ASYNCHRONOUS;
+
struct RequiresValidationTestData {
const char* headers;
- bool requires_validation;
+ ValidationType validation_type;
};
class RequiresValidationTest
@@ -800,41 +808,41 @@ TEST_P(RequiresValidationTest, RequiresValidation) {
scoped_refptr<net::HttpResponseHeaders> parsed(
new net::HttpResponseHeaders(headers));
- bool requires_validation =
+ ValidationType validation_type =
parsed->RequiresValidation(request_time, response_time, current_time);
- EXPECT_EQ(test.requires_validation, requires_validation);
+ EXPECT_EQ(test.validation_type, validation_type);
}
const struct RequiresValidationTestData requires_validation_tests[] = {
// No expiry info: expires immediately.
{ "HTTP/1.1 200 OK\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
// No expiry info: expires immediately.
{ "HTTP/1.1 200 OK\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
// Valid for a little while.
{ "HTTP/1.1 200 OK\n"
"cache-control: max-age=10000\n"
"\n",
- false
+ VALIDATION_NONE
},
// Expires in the future.
{ "HTTP/1.1 200 OK\n"
"date: Wed, 28 Nov 2007 00:40:11 GMT\n"
"expires: Wed, 28 Nov 2007 01:00:00 GMT\n"
"\n",
- false
+ VALIDATION_NONE
},
// Already expired.
{ "HTTP/1.1 200 OK\n"
"date: Wed, 28 Nov 2007 00:40:11 GMT\n"
"expires: Wed, 28 Nov 2007 00:00:00 GMT\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
// Max-age trumps expires.
{ "HTTP/1.1 200 OK\n"
@@ -842,77 +850,77 @@ const struct RequiresValidationTestData requires_validation_tests[] = {
"expires: Wed, 28 Nov 2007 00:00:00 GMT\n"
"cache-control: max-age=10000\n"
"\n",
- false
+ VALIDATION_NONE
},
// Last-modified heuristic: modified a while ago.
{ "HTTP/1.1 200 OK\n"
"date: Wed, 28 Nov 2007 00:40:11 GMT\n"
"last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n"
"\n",
- false
+ VALIDATION_NONE
},
{ "HTTP/1.1 203 Non-Authoritative Information\n"
"date: Wed, 28 Nov 2007 00:40:11 GMT\n"
"last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n"
"\n",
- false
+ VALIDATION_NONE
},
{ "HTTP/1.1 206 Partial Content\n"
"date: Wed, 28 Nov 2007 00:40:11 GMT\n"
"last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n"
"\n",
- false
+ VALIDATION_NONE
},
// Last-modified heuristic: modified recently.
{ "HTTP/1.1 200 OK\n"
"date: Wed, 28 Nov 2007 00:40:11 GMT\n"
"last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
{ "HTTP/1.1 203 Non-Authoritative Information\n"
"date: Wed, 28 Nov 2007 00:40:11 GMT\n"
"last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
{ "HTTP/1.1 206 Partial Content\n"
"date: Wed, 28 Nov 2007 00:40:11 GMT\n"
"last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
// Cached permanent redirect.
{ "HTTP/1.1 301 Moved Permanently\n"
"\n",
- false
+ VALIDATION_NONE
},
// Another cached permanent redirect.
{ "HTTP/1.1 308 Permanent Redirect\n"
"\n",
- false
+ VALIDATION_NONE
},
// Cached redirect: not reusable even though by default it would be.
{ "HTTP/1.1 300 Multiple Choices\n"
"Cache-Control: no-cache\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
// Cached forever by default.
{ "HTTP/1.1 410 Gone\n"
"\n",
- false
+ VALIDATION_NONE
},
// Cached temporary redirect: not reusable.
{ "HTTP/1.1 302 Found\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
// Cached temporary redirect: reusable.
{ "HTTP/1.1 302 Found\n"
"cache-control: max-age=10000\n"
"\n",
- false
+ VALIDATION_NONE
},
// Cache-control: max-age=N overrides expires: date in the past.
{ "HTTP/1.1 200 OK\n"
@@ -920,7 +928,7 @@ const struct RequiresValidationTestData requires_validation_tests[] = {
"expires: Wed, 28 Nov 2007 00:20:11 GMT\n"
"cache-control: max-age=10000\n"
"\n",
- false
+ VALIDATION_NONE
},
// Cache-control: no-store overrides expires: in the future.
{ "HTTP/1.1 200 OK\n"
@@ -928,7 +936,7 @@ const struct RequiresValidationTestData requires_validation_tests[] = {
"expires: Wed, 29 Nov 2007 00:40:11 GMT\n"
"cache-control: no-store,private,no-cache=\"foo\"\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
},
// Pragma: no-cache overrides last-modified heuristic.
{ "HTTP/1.1 200 OK\n"
@@ -936,7 +944,52 @@ const struct RequiresValidationTestData requires_validation_tests[] = {
"last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n"
"pragma: no-cache\n"
"\n",
- true
+ VALIDATION_SYNCHRONOUS
+ },
+ // max-age has expired, needs synchronous revalidation
+ { "HTTP/1.1 200 OK\n"
+ "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
+ "cache-control: max-age=300\n"
+ "\n",
+ VALIDATION_SYNCHRONOUS
+ },
+ // max-age has expired, stale-while-revalidate has not, eligible for
+ // asynchronous revalidation
+ { "HTTP/1.1 200 OK\n"
+ "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
+ "cache-control: max-age=300, stale-while-revalidate=3600\n"
+ "\n",
+ VALIDATION_ASYNCHRONOUS
+ },
+ // max-age and stale-while-revalidate have expired, needs synchronous
+ // revalidation
+ { "HTTP/1.1 200 OK\n"
+ "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
+ "cache-control: max-age=300, stale-while-revalidate=5\n"
+ "\n",
+ VALIDATION_SYNCHRONOUS
+ },
+ // max-age is 0, stale-while-revalidate is large enough to permit
+ // asynchronous revalidation
+ { "HTTP/1.1 200 OK\n"
+ "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
+ "cache-control: max-age=0, stale-while-revalidate=360\n"
+ "\n",
+ VALIDATION_ASYNCHRONOUS
+ },
+ // stale-while-revalidate must not override no-cache or similar directives.
+ { "HTTP/1.1 200 OK\n"
+ "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
+ "cache-control: no-cache, stale-while-revalidate=360\n"
+ "\n",
+ VALIDATION_SYNCHRONOUS
+ },
+ // max-age has not expired, so no revalidation is needed.
+ { "HTTP/1.1 200 OK\n"
+ "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
+ "cache-control: max-age=3600, stale-while-revalidate=3600\n"
+ "\n",
+ VALIDATION_NONE
},
// TODO(darin): Add many many more tests here.

Powered by Google App Engine
This is Rietveld 408576698