| 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 a9567c6512a4333cda0ff0f86a302b921c39fa58..f47da3877ad27d8766ea29b5d6a755bdfab21824 100644
|
| --- a/net/http/http_response_headers_unittest.cc
|
| +++ b/net/http/http_response_headers_unittest.cc
|
| @@ -765,18 +765,23 @@ INSTANTIATE_TEST_CASE_P(HttpResponseHeaders,
|
| ContentTypeTest,
|
| testing::ValuesIn(mimetype_tests));
|
|
|
| -struct RequiresValidationTestData {
|
| +enum TestValidationType {
|
| + TEST_VALIDATION_NONE,
|
| + TEST_VALIDATION_ASYNCHRONOUS,
|
| + TEST_VALIDATION_SYNCHRONOUS,
|
| +};
|
| +
|
| +struct ExpirationTimesTestData {
|
| const char* headers;
|
| - ValidationType validation_type;
|
| + TestValidationType validation_type;
|
| };
|
|
|
| -class RequiresValidationTest
|
| +class ExpirationTimesTest
|
| : public HttpResponseHeadersTest,
|
| - public ::testing::WithParamInterface<RequiresValidationTestData> {
|
| -};
|
| + public ::testing::WithParamInterface<ExpirationTimesTestData> {};
|
|
|
| -TEST_P(RequiresValidationTest, RequiresValidation) {
|
| - const RequiresValidationTestData test = GetParam();
|
| +TEST_P(ExpirationTimesTest, ExpirationTimes) {
|
| + const ExpirationTimesTestData test = GetParam();
|
|
|
| base::Time request_time, response_time, current_time;
|
| base::Time::FromString("Wed, 28 Nov 2007 00:40:09 GMT", &request_time);
|
| @@ -787,204 +792,185 @@ TEST_P(RequiresValidationTest, RequiresValidation) {
|
| HeadersToRaw(&headers);
|
| scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
|
|
|
| - ValidationType validation_type =
|
| - parsed->RequiresValidation(request_time, response_time, current_time);
|
| + HttpResponseHeaders::ExpirationTimes expiration_times =
|
| + parsed->GetExpirationTimes(request_time, response_time);
|
| + TestValidationType validation_type;
|
| + if (current_time < expiration_times.GetExpirationTime())
|
| + validation_type = TEST_VALIDATION_NONE;
|
| + else if (current_time < expiration_times.GetAsyncExpirationTime())
|
| + validation_type = TEST_VALIDATION_ASYNCHRONOUS;
|
| + else
|
| + validation_type = TEST_VALIDATION_SYNCHRONOUS;
|
| 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",
|
| - VALIDATION_SYNCHRONOUS
|
| - },
|
| - // No expiry info: expires immediately.
|
| - { "HTTP/1.1 200 OK\n"
|
| - "\n",
|
| - VALIDATION_SYNCHRONOUS
|
| - },
|
| - // Valid for a little while.
|
| - { "HTTP/1.1 200 OK\n"
|
| - "cache-control: max-age=10000\n"
|
| - "\n",
|
| - 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",
|
| - 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",
|
| - VALIDATION_SYNCHRONOUS
|
| - },
|
| - // Max-age trumps expires.
|
| - { "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"
|
| - "cache-control: max-age=10000\n"
|
| - "\n",
|
| - 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",
|
| - 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",
|
| - 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",
|
| - 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",
|
| - 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",
|
| - 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",
|
| - VALIDATION_SYNCHRONOUS
|
| - },
|
| - // Cached permanent redirect.
|
| - { "HTTP/1.1 301 Moved Permanently\n"
|
| - "\n",
|
| - VALIDATION_NONE
|
| - },
|
| - // Another cached permanent redirect.
|
| - { "HTTP/1.1 308 Permanent Redirect\n"
|
| - "\n",
|
| - 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",
|
| - VALIDATION_SYNCHRONOUS
|
| - },
|
| - // Cached forever by default.
|
| - { "HTTP/1.1 410 Gone\n"
|
| - "\n",
|
| - VALIDATION_NONE
|
| - },
|
| - // Cached temporary redirect: not reusable.
|
| - { "HTTP/1.1 302 Found\n"
|
| - "\n",
|
| - VALIDATION_SYNCHRONOUS
|
| - },
|
| - // Cached temporary redirect: reusable.
|
| - { "HTTP/1.1 302 Found\n"
|
| - "cache-control: max-age=10000\n"
|
| - "\n",
|
| - VALIDATION_NONE
|
| - },
|
| - // Cache-control: max-age=N overrides expires: date in the past.
|
| - { "HTTP/1.1 200 OK\n"
|
| - "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
|
| - "expires: Wed, 28 Nov 2007 00:20:11 GMT\n"
|
| - "cache-control: max-age=10000\n"
|
| - "\n",
|
| - VALIDATION_NONE
|
| - },
|
| - // Cache-control: no-store overrides expires: in the future.
|
| - { "HTTP/1.1 200 OK\n"
|
| - "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
|
| - "expires: Wed, 29 Nov 2007 00:40:11 GMT\n"
|
| - "cache-control: no-store,private,no-cache=\"foo\"\n"
|
| - "\n",
|
| - VALIDATION_SYNCHRONOUS
|
| - },
|
| - // Pragma: no-cache overrides last-modified heuristic.
|
| - { "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"
|
| - "pragma: no-cache\n"
|
| - "\n",
|
| - 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
|
| - },
|
| - // must-revalidate overrides stale-while-revalidate, so synchronous validation
|
| - // is needed.
|
| - { "HTTP/1.1 200 OK\n"
|
| - "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
|
| - "cache-control: must-revalidate, max-age=300, stale-while-revalidate=3600\n"
|
| - "\n",
|
| - VALIDATION_SYNCHRONOUS
|
| - },
|
| +const struct ExpirationTimesTestData expiration_times_tests[] = {
|
| + // No expiry info: expires immediately.
|
| + {"HTTP/1.1 200 OK\n"
|
| + "\n",
|
| + TEST_VALIDATION_SYNCHRONOUS},
|
| + // No expiry info: expires immediately.
|
| + {"HTTP/1.1 200 OK\n"
|
| + "\n",
|
| + TEST_VALIDATION_SYNCHRONOUS},
|
| + // Valid for a little while.
|
| + {"HTTP/1.1 200 OK\n"
|
| + "cache-control: max-age=10000\n"
|
| + "\n",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_VALIDATION_SYNCHRONOUS},
|
| + // Max-age trumps expires.
|
| + {"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"
|
| + "cache-control: max-age=10000\n"
|
| + "\n",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_VALIDATION_SYNCHRONOUS},
|
| + // Cached permanent redirect.
|
| + {"HTTP/1.1 301 Moved Permanently\n"
|
| + "\n",
|
| + TEST_VALIDATION_NONE},
|
| + // Another cached permanent redirect.
|
| + {"HTTP/1.1 308 Permanent Redirect\n"
|
| + "\n",
|
| + TEST_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",
|
| + TEST_VALIDATION_SYNCHRONOUS},
|
| + // Cached forever by default.
|
| + {"HTTP/1.1 410 Gone\n"
|
| + "\n",
|
| + TEST_VALIDATION_NONE},
|
| + // Cached temporary redirect: not reusable.
|
| + {"HTTP/1.1 302 Found\n"
|
| + "\n",
|
| + TEST_VALIDATION_SYNCHRONOUS},
|
| + // Cached temporary redirect: reusable.
|
| + {"HTTP/1.1 302 Found\n"
|
| + "cache-control: max-age=10000\n"
|
| + "\n",
|
| + TEST_VALIDATION_NONE},
|
| + // Cache-control: max-age=N overrides expires: date in the past.
|
| + {"HTTP/1.1 200 OK\n"
|
| + "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
|
| + "expires: Wed, 28 Nov 2007 00:20:11 GMT\n"
|
| + "cache-control: max-age=10000\n"
|
| + "\n",
|
| + TEST_VALIDATION_NONE},
|
| + // Cache-control: no-store overrides expires: in the future.
|
| + {"HTTP/1.1 200 OK\n"
|
| + "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
|
| + "expires: Wed, 29 Nov 2007 00:40:11 GMT\n"
|
| + "cache-control: no-store,private,no-cache=\"foo\"\n"
|
| + "\n",
|
| + TEST_VALIDATION_SYNCHRONOUS},
|
| + // Pragma: no-cache overrides last-modified heuristic.
|
| + {"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"
|
| + "pragma: no-cache\n"
|
| + "\n",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_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",
|
| + TEST_VALIDATION_NONE},
|
| + // must-revalidate overrides stale-while-revalidate, so synchronous
|
| + // validation
|
| + // is needed.
|
| + {"HTTP/1.1 200 OK\n"
|
| + "date: Wed, 28 Nov 2007 00:40:11 GMT\n"
|
| + "cache-control: must-revalidate, max-age=300, "
|
| + "stale-while-revalidate=3600\n"
|
| + "\n",
|
| + TEST_VALIDATION_SYNCHRONOUS},
|
|
|
| - // TODO(darin): Add many many more tests here.
|
| + // TODO(darin): Add many many more tests here.
|
| };
|
|
|
| INSTANTIATE_TEST_CASE_P(HttpResponseHeaders,
|
| - RequiresValidationTest,
|
| - testing::ValuesIn(requires_validation_tests));
|
| + ExpirationTimesTest,
|
| + testing::ValuesIn(expiration_times_tests));
|
|
|
| struct UpdateTestData {
|
| const char* orig_headers;
|
|
|