| 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, GetAgeValue10) { |
| 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, GetAgeValue0) { |
| 548 std::string headers = |
| 549 "HTTP/1.1 200 OK\n" |
| 550 "Age: 0\n"; |
| 551 HeadersToRaw(&headers); |
| 552 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 553 base::TimeDelta age; |
| 554 ASSERT_TRUE(parsed->GetAgeValue(&age)); |
| 555 EXPECT_EQ(0, age.InSeconds()); |
| 556 } |
| 557 |
| 558 TEST(HttpResponseHeadersTest, GetAgeValueBogus) { |
| 559 std::string headers = |
| 560 "HTTP/1.1 200 OK\n" |
| 561 "Age: donkey\n"; |
| 562 HeadersToRaw(&headers); |
| 563 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 564 base::TimeDelta age; |
| 565 ASSERT_FALSE(parsed->GetAgeValue(&age)); |
| 566 } |
| 567 |
| 568 TEST(HttpResponseHeadersTest, GetAgeValueNegative) { |
| 569 std::string headers = |
| 570 "HTTP/1.1 200 OK\n" |
| 571 "Age: -10\n"; |
| 572 HeadersToRaw(&headers); |
| 573 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 574 base::TimeDelta age; |
| 575 ASSERT_FALSE(parsed->GetAgeValue(&age)); |
| 576 } |
| 577 |
| 578 TEST(HttpResponseHeadersTest, GetAgeValueLeadingPlus) { |
| 579 std::string headers = |
| 580 "HTTP/1.1 200 OK\n" |
| 581 "Age: +10\n"; |
| 582 HeadersToRaw(&headers); |
| 583 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 584 base::TimeDelta age; |
| 585 ASSERT_FALSE(parsed->GetAgeValue(&age)); |
| 586 } |
| 587 |
| 588 TEST(HttpResponseHeadersTest, GetAgeValueOverflow) { |
| 589 std::string headers = |
| 590 "HTTP/1.1 200 OK\n" |
| 591 "Age: 999999999999999999999999999999999999999999\n"; |
| 592 HeadersToRaw(&headers); |
| 593 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 594 base::TimeDelta age; |
| 595 ASSERT_TRUE(parsed->GetAgeValue(&age)); |
| 596 |
| 597 // Should have saturated to 2^32 - 1. |
| 598 EXPECT_EQ(static_cast<int64_t>(0xFFFFFFFFL), age.InSeconds()); |
| 599 } |
| 600 |
| 536 struct ContentTypeTestData { | 601 struct ContentTypeTestData { |
| 537 const std::string raw_headers; | 602 const std::string raw_headers; |
| 538 const std::string mime_type; | 603 const std::string mime_type; |
| 539 const bool has_mimetype; | 604 const bool has_mimetype; |
| 540 const std::string charset; | 605 const std::string charset; |
| 541 const bool has_charset; | 606 const bool has_charset; |
| 542 const std::string all_content_type; | 607 const std::string all_content_type; |
| 543 }; | 608 }; |
| 544 | 609 |
| 545 class ContentTypeTest | 610 class ContentTypeTest |
| (...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 TEST_F(HttpResponseHeadersCacheControlTest, | 2213 TEST_F(HttpResponseHeadersCacheControlTest, |
| 2149 FirstStaleWhileRevalidateValueUsed) { | 2214 FirstStaleWhileRevalidateValueUsed) { |
| 2150 InitializeHeadersWithCacheControl( | 2215 InitializeHeadersWithCacheControl( |
| 2151 "stale-while-revalidate=1,stale-while-revalidate=7200"); | 2216 "stale-while-revalidate=1,stale-while-revalidate=7200"); |
| 2152 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); | 2217 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); |
| 2153 } | 2218 } |
| 2154 | 2219 |
| 2155 } // namespace | 2220 } // namespace |
| 2156 | 2221 |
| 2157 } // namespace net | 2222 } // namespace net |
| OLD | NEW |