OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_response_headers.h" | 5 #include "net/http/http_response_headers.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iostream> | 10 #include <iostream> |
(...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2212 EXPECT_EQ(TimeDelta::FromSeconds(7200), GetStaleWhileRevalidateValue()); | 2212 EXPECT_EQ(TimeDelta::FromSeconds(7200), GetStaleWhileRevalidateValue()); |
2213 } | 2213 } |
2214 | 2214 |
2215 TEST_F(HttpResponseHeadersCacheControlTest, | 2215 TEST_F(HttpResponseHeadersCacheControlTest, |
2216 FirstStaleWhileRevalidateValueUsed) { | 2216 FirstStaleWhileRevalidateValueUsed) { |
2217 InitializeHeadersWithCacheControl( | 2217 InitializeHeadersWithCacheControl( |
2218 "stale-while-revalidate=1,stale-while-revalidate=7200"); | 2218 "stale-while-revalidate=1,stale-while-revalidate=7200"); |
2219 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); | 2219 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); |
2220 } | 2220 } |
2221 | 2221 |
| 2222 struct GetCurrentAgeTestData { |
| 2223 const char* headers; |
| 2224 const char* request_time; |
| 2225 const char* response_time; |
| 2226 const char* current_time; |
| 2227 const int expected_age; |
| 2228 }; |
| 2229 |
| 2230 class GetCurrentAgeTest |
| 2231 : public HttpResponseHeadersTest, |
| 2232 public ::testing::WithParamInterface<GetCurrentAgeTestData> { |
| 2233 }; |
| 2234 |
| 2235 TEST_P(GetCurrentAgeTest, GetCurrentAge) { |
| 2236 const GetCurrentAgeTestData test = GetParam(); |
| 2237 |
| 2238 base::Time request_time, response_time, current_time; |
| 2239 ASSERT_TRUE(base::Time::FromString(test.request_time, &request_time)); |
| 2240 ASSERT_TRUE(base::Time::FromString(test.response_time, &response_time)); |
| 2241 ASSERT_TRUE(base::Time::FromString(test.current_time, ¤t_time)); |
| 2242 |
| 2243 std::string headers(test.headers); |
| 2244 HeadersToRaw(&headers); |
| 2245 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 2246 |
| 2247 base::TimeDelta age = |
| 2248 parsed->GetCurrentAge(request_time, response_time, current_time); |
| 2249 EXPECT_EQ(test.expected_age, age.InSeconds()); |
| 2250 } |
| 2251 |
| 2252 const struct GetCurrentAgeTestData get_current_age_tests[] = { |
| 2253 // Without Date header. |
| 2254 {"HTTP/1.1 200 OK\n" |
| 2255 "Age: 2", |
| 2256 "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT", |
| 2257 "Fri, 20 Jan 2011 10:40:14 GMT", 8}, |
| 2258 // Without Age header. |
| 2259 {"HTTP/1.1 200 OK\n" |
| 2260 "Date: Fri, 20 Jan 2011 10:40:10 GMT\n", |
| 2261 "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT", |
| 2262 "Fri, 20 Jan 2011 10:40:14 GMT", 6}, |
| 2263 // date_value > response_time with Age header. |
| 2264 {"HTTP/1.1 200 OK\n" |
| 2265 "Date: Fri, 20 Jan 2011 10:40:14 GMT\n" |
| 2266 "Age: 2\n", |
| 2267 "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT", |
| 2268 "Fri, 20 Jan 2011 10:40:14 GMT", 8}, |
| 2269 // date_value > response_time without Age header. |
| 2270 {"HTTP/1.1 200 OK\n" |
| 2271 "Date: Fri, 20 Jan 2011 10:40:14 GMT\n", |
| 2272 "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT", |
| 2273 "Fri, 20 Jan 2011 10:40:14 GMT", 6}, |
| 2274 // apparent_age > corrected_age_value |
| 2275 {"HTTP/1.1 200 OK\n" |
| 2276 "Date: Fri, 20 Jan 2011 10:40:07 GMT\n" |
| 2277 "Age: 0\n", |
| 2278 "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT", |
| 2279 "Fri, 20 Jan 2011 10:40:14 GMT", 7}}; |
| 2280 |
| 2281 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
| 2282 GetCurrentAgeTest, |
| 2283 testing::ValuesIn(get_current_age_tests)); |
| 2284 |
2222 } // namespace | 2285 } // namespace |
2223 | 2286 |
2224 } // namespace net | 2287 } // namespace net |
OLD | NEW |