Chromium Code Reviews| 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 70a5d09562a4a13d31f0c7bfebb92e64513ec74b..b96a8949935b303aaac0ed37d68ea7bca02d1970 100644 |
| --- a/net/http/http_response_headers_unittest.cc |
| +++ b/net/http/http_response_headers_unittest.cc |
| @@ -533,6 +533,60 @@ TEST(HttpResponseHeadersTest, DefaultDateToGMT) { |
| EXPECT_EQ(expected_value, value); |
| } |
| +TEST(HttpResponseHeadersTest, GetAgeValue) { |
| + std::string headers = |
| + "HTTP/1.1 200 OK\n" |
| + "Age: 10\n"; |
| + HeadersToRaw(&headers); |
| + scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| + base::TimeDelta age; |
| + ASSERT_TRUE(parsed->GetAgeValue(&age)); |
| + EXPECT_EQ(10, age.InSeconds()); |
| +} |
| + |
| +TEST(HttpResponseHeadersTest, GetAgeValueBogus) { |
| + std::string headers = |
| + "HTTP/1.1 200 OK\n" |
| + "Age: donkey\n"; |
| + HeadersToRaw(&headers); |
| + scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| + base::TimeDelta age; |
| + ASSERT_FALSE(parsed->GetAgeValue(&age)); |
| +} |
| + |
| +TEST(HttpResponseHeadersTest, GetAgeValueNegative) { |
| + std::string headers = |
| + "HTTP/1.1 200 OK\n" |
| + "Age: -10\n"; |
|
mmenke
2016/04/11 16:59:07
Should we have a "0" test?
eroman
2016/04/11 17:39:25
Done.
|
| + HeadersToRaw(&headers); |
| + scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| + base::TimeDelta age; |
| + ASSERT_FALSE(parsed->GetAgeValue(&age)); |
| +} |
| + |
| +TEST(HttpResponseHeadersTest, GetAgeValueLeadingPlus) { |
| + std::string headers = |
| + "HTTP/1.1 200 OK\n" |
| + "Age: +10\n"; |
| + HeadersToRaw(&headers); |
| + scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| + base::TimeDelta age; |
| + ASSERT_FALSE(parsed->GetAgeValue(&age)); |
| +} |
| + |
| +TEST(HttpResponseHeadersTest, GetAgeValueOverflow) { |
| + std::string headers = |
| + "HTTP/1.1 200 OK\n" |
| + "Age: 999999999999999999999999999999999999999999\n"; |
| + HeadersToRaw(&headers); |
| + scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| + base::TimeDelta age; |
| + ASSERT_TRUE(parsed->GetAgeValue(&age)); |
| + |
| + // Should have saturated to 2^32 |
|
mmenke
2016/04/11 16:59:07
nit: +period, -1.
eroman
2016/04/11 17:39:25
Done.
|
| + EXPECT_EQ(static_cast<int64_t>(0xFFFFFFFFL), age.InSeconds()); |
| +} |
| + |
| struct ContentTypeTestData { |
| const std::string raw_headers; |
| const std::string mime_type; |