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

Unified Diff: net/http/http_response_headers_unittest.cc

Issue 2644063003: HTTP Cache Age calculation mechanism changed with RFC 7234 (Closed)
Patch Set: HTTP Cache Age calculation mechanism changed with RFC 7234 Created 3 years, 11 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
« no previous file with comments | « net/http/http_response_headers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 041972b76df1edda20c64a541f6dbaa6a926c12b..5302b60796faa72a4ea7f6041ebed6dc7088f6a2 100644
--- a/net/http/http_response_headers_unittest.cc
+++ b/net/http/http_response_headers_unittest.cc
@@ -2219,6 +2219,69 @@ TEST_F(HttpResponseHeadersCacheControlTest,
EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue());
}
+struct GetCurrentAgeTestData {
+ const char* headers;
+ const char* request_time;
+ const char* response_time;
+ const char* current_time;
+ const int expected_age;
+};
+
+class GetCurrentAgeTest
+ : public HttpResponseHeadersTest,
+ public ::testing::WithParamInterface<GetCurrentAgeTestData> {
+};
+
+TEST_P(GetCurrentAgeTest, GetCurrentAge) {
+ const GetCurrentAgeTestData test = GetParam();
+
+ base::Time request_time, response_time, current_time;
+ ASSERT_TRUE(base::Time::FromString(test.request_time, &request_time));
+ ASSERT_TRUE(base::Time::FromString(test.response_time, &response_time));
+ ASSERT_TRUE(base::Time::FromString(test.current_time, &current_time));
+
+ std::string headers(test.headers);
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
+
+ base::TimeDelta age =
+ parsed->GetCurrentAge(request_time, response_time, current_time);
+ EXPECT_EQ(test.expected_age, age.InSeconds());
+}
+
+const struct GetCurrentAgeTestData get_current_age_tests[] = {
+ // Without Date header.
+ {"HTTP/1.1 200 OK\n"
+ "Age: 2",
+ "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT",
+ "Fri, 20 Jan 2011 10:40:14 GMT", 8},
+ // Without Age header.
+ {"HTTP/1.1 200 OK\n"
+ "Date: Fri, 20 Jan 2011 10:40:10 GMT\n",
+ "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT",
+ "Fri, 20 Jan 2011 10:40:14 GMT", 6},
+ // date_value > response_time with Age header.
+ {"HTTP/1.1 200 OK\n"
+ "Date: Fri, 20 Jan 2011 10:40:14 GMT\n"
+ "Age: 2\n",
+ "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT",
+ "Fri, 20 Jan 2011 10:40:14 GMT", 8},
+ // date_value > response_time without Age header.
+ {"HTTP/1.1 200 OK\n"
+ "Date: Fri, 20 Jan 2011 10:40:14 GMT\n",
+ "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT",
+ "Fri, 20 Jan 2011 10:40:14 GMT", 6},
+ // apparent_age > corrected_age_value
+ {"HTTP/1.1 200 OK\n"
+ "Date: Fri, 20 Jan 2011 10:40:07 GMT\n"
+ "Age: 0\n",
+ "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT",
+ "Fri, 20 Jan 2011 10:40:14 GMT", 7}};
+
+INSTANTIATE_TEST_CASE_P(HttpResponseHeaders,
+ GetCurrentAgeTest,
+ testing::ValuesIn(get_current_age_tests));
+
} // namespace
} // namespace net
« no previous file with comments | « net/http/http_response_headers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698