Chromium Code Reviews| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iostream> | 8 #include <iostream> |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 // If GMT is missing but an RFC822-conforming one is present, use that. | 526 // If GMT is missing but an RFC822-conforming one is present, use that. |
| 527 EXPECT_TRUE(parsed->GetLastModifiedValue(&value)); | 527 EXPECT_TRUE(parsed->GetLastModifiedValue(&value)); |
| 528 EXPECT_EQ(expected_value, value); | 528 EXPECT_EQ(expected_value, value); |
| 529 // If an unknown timezone is present, treat like a missing timezone and | 529 // If an unknown timezone is present, treat like a missing timezone and |
| 530 // default to GMT. The only example of a web server not specifying "GMT" | 530 // default to GMT. The only example of a web server not specifying "GMT" |
| 531 // used "UTC" which is equivalent to GMT. | 531 // used "UTC" which is equivalent to GMT. |
| 532 if (parsed->GetExpiresValue(&value)) | 532 if (parsed->GetExpiresValue(&value)) |
| 533 EXPECT_EQ(expected_value, value); | 533 EXPECT_EQ(expected_value, value); |
| 534 } | 534 } |
| 535 | 535 |
| 536 TEST(HttpResponseHeadersTest, GetAgeValue) { | |
| 537 std::string headers = | |
| 538 "HTTP/1.1 200 OK\n" | |
| 539 "Age: 10\n"; | |
| 540 HeadersToRaw(&headers); | |
| 541 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); | |
| 542 base::TimeDelta age; | |
| 543 ASSERT_TRUE(parsed->GetAgeValue(&age)); | |
| 544 EXPECT_EQ(10, age.InSeconds()); | |
| 545 } | |
| 546 | |
| 547 TEST(HttpResponseHeadersTest, GetAgeValueBogus) { | |
| 548 std::string headers = | |
| 549 "HTTP/1.1 200 OK\n" | |
| 550 "Age: donkey\n"; | |
| 551 HeadersToRaw(&headers); | |
| 552 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); | |
| 553 base::TimeDelta age; | |
| 554 ASSERT_FALSE(parsed->GetAgeValue(&age)); | |
| 555 } | |
| 556 | |
| 557 TEST(HttpResponseHeadersTest, GetAgeValueNegative) { | |
| 558 std::string headers = | |
| 559 "HTTP/1.1 200 OK\n" | |
| 560 "Age: -10\n"; | |
|
mmenke
2016/04/11 16:59:07
Should we have a "0" test?
eroman
2016/04/11 17:39:25
Done.
| |
| 561 HeadersToRaw(&headers); | |
| 562 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); | |
| 563 base::TimeDelta age; | |
| 564 ASSERT_FALSE(parsed->GetAgeValue(&age)); | |
| 565 } | |
| 566 | |
| 567 TEST(HttpResponseHeadersTest, GetAgeValueLeadingPlus) { | |
| 568 std::string headers = | |
| 569 "HTTP/1.1 200 OK\n" | |
| 570 "Age: +10\n"; | |
| 571 HeadersToRaw(&headers); | |
| 572 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); | |
| 573 base::TimeDelta age; | |
| 574 ASSERT_FALSE(parsed->GetAgeValue(&age)); | |
| 575 } | |
| 576 | |
| 577 TEST(HttpResponseHeadersTest, GetAgeValueOverflow) { | |
| 578 std::string headers = | |
| 579 "HTTP/1.1 200 OK\n" | |
| 580 "Age: 999999999999999999999999999999999999999999\n"; | |
| 581 HeadersToRaw(&headers); | |
| 582 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); | |
| 583 base::TimeDelta age; | |
| 584 ASSERT_TRUE(parsed->GetAgeValue(&age)); | |
| 585 | |
| 586 // Should have saturated to 2^32 | |
|
mmenke
2016/04/11 16:59:07
nit: +period, -1.
eroman
2016/04/11 17:39:25
Done.
| |
| 587 EXPECT_EQ(static_cast<int64_t>(0xFFFFFFFFL), age.InSeconds()); | |
| 588 } | |
| 589 | |
| 536 struct ContentTypeTestData { | 590 struct ContentTypeTestData { |
| 537 const std::string raw_headers; | 591 const std::string raw_headers; |
| 538 const std::string mime_type; | 592 const std::string mime_type; |
| 539 const bool has_mimetype; | 593 const bool has_mimetype; |
| 540 const std::string charset; | 594 const std::string charset; |
| 541 const bool has_charset; | 595 const bool has_charset; |
| 542 const std::string all_content_type; | 596 const std::string all_content_type; |
| 543 }; | 597 }; |
| 544 | 598 |
| 545 class ContentTypeTest | 599 class ContentTypeTest |
| (...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2148 TEST_F(HttpResponseHeadersCacheControlTest, | 2202 TEST_F(HttpResponseHeadersCacheControlTest, |
| 2149 FirstStaleWhileRevalidateValueUsed) { | 2203 FirstStaleWhileRevalidateValueUsed) { |
| 2150 InitializeHeadersWithCacheControl( | 2204 InitializeHeadersWithCacheControl( |
| 2151 "stale-while-revalidate=1,stale-while-revalidate=7200"); | 2205 "stale-while-revalidate=1,stale-while-revalidate=7200"); |
| 2152 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); | 2206 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); |
| 2153 } | 2207 } |
| 2154 | 2208 |
| 2155 } // namespace | 2209 } // namespace |
| 2156 | 2210 |
| 2157 } // namespace net | 2211 } // namespace net |
| OLD | NEW |