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 base::Time::FromString(test.request_time, &request_time); | |
jkarlin
2017/01/23 14:09:41
You'll need to check the return values of FromStri
billyjay
2017/01/24 06:38:31
Done.
| |
2240 base::Time::FromString(test.response_time, &response_time); | |
2241 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. | |
jkarlin
2017/01/23 14:09:41
Please also add a case where date_value > response
billyjay
2017/01/24 06:38:31
Done.
| |
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 // apparent_age > corrected_age_value | |
2270 {"HTTP/1.1 200 OK\n" | |
2271 "Date: Fri, 20 Jan 2011 10:40:07 GMT\n" | |
2272 "Age: 0\n", | |
2273 "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT", | |
2274 "Fri, 20 Jan 2011 10:40:14 GMT", 7}}; | |
2275 | |
2276 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | |
2277 GetCurrentAgeTest, | |
2278 testing::ValuesIn(get_current_age_tests)); | |
2279 | |
2222 } // namespace | 2280 } // namespace |
2223 | 2281 |
2224 } // namespace net | 2282 } // namespace net |
OLD | NEW |