OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 { "HTTP/1.1 200 OK\n" | 629 { "HTTP/1.1 200 OK\n" |
630 "Content-type: */*\n", | 630 "Content-type: */*\n", |
631 "", false, | 631 "", false, |
632 "", false, | 632 "", false, |
633 "*/*" }, | 633 "*/*" }, |
634 }; | 634 }; |
635 | 635 |
636 for (size_t i = 0; i < arraysize(tests); ++i) { | 636 for (size_t i = 0; i < arraysize(tests); ++i) { |
637 string headers(tests[i].raw_headers); | 637 string headers(tests[i].raw_headers); |
638 HeadersToRaw(&headers); | 638 HeadersToRaw(&headers); |
639 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers)
; | 639 scoped_refptr<HttpResponseHeaders> parsed = |
| 640 new HttpResponseHeaders(headers); |
640 | 641 |
641 std::string value; | 642 std::string value; |
642 EXPECT_EQ(tests[i].has_mimetype, parsed->GetMimeType(&value)); | 643 EXPECT_EQ(tests[i].has_mimetype, parsed->GetMimeType(&value)); |
643 EXPECT_EQ(tests[i].mime_type, value); | 644 EXPECT_EQ(tests[i].mime_type, value); |
644 value.clear(); | 645 value.clear(); |
645 EXPECT_EQ(tests[i].has_charset, parsed->GetCharset(&value)); | 646 EXPECT_EQ(tests[i].has_charset, parsed->GetCharset(&value)); |
646 EXPECT_EQ(tests[i].charset, value); | 647 EXPECT_EQ(tests[i].charset, value); |
647 EXPECT_TRUE(parsed->GetNormalizedHeader("content-type", &value)); | 648 EXPECT_TRUE(parsed->GetNormalizedHeader("content-type", &value)); |
648 EXPECT_EQ(tests[i].all_content_type, value); | 649 EXPECT_EQ(tests[i].all_content_type, value); |
649 } | 650 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 // TODO(darin): add many many more tests here | 756 // TODO(darin): add many many more tests here |
756 }; | 757 }; |
757 Time request_time, response_time, current_time; | 758 Time request_time, response_time, current_time; |
758 Time::FromString(L"Wed, 28 Nov 2007 00:40:09 GMT", &request_time); | 759 Time::FromString(L"Wed, 28 Nov 2007 00:40:09 GMT", &request_time); |
759 Time::FromString(L"Wed, 28 Nov 2007 00:40:12 GMT", &response_time); | 760 Time::FromString(L"Wed, 28 Nov 2007 00:40:12 GMT", &response_time); |
760 Time::FromString(L"Wed, 28 Nov 2007 00:45:20 GMT", ¤t_time); | 761 Time::FromString(L"Wed, 28 Nov 2007 00:45:20 GMT", ¤t_time); |
761 | 762 |
762 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 763 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
763 string headers(tests[i].headers); | 764 string headers(tests[i].headers); |
764 HeadersToRaw(&headers); | 765 HeadersToRaw(&headers); |
765 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers)
; | 766 scoped_refptr<HttpResponseHeaders> parsed = |
| 767 new HttpResponseHeaders(headers); |
766 | 768 |
767 bool requires_validation = | 769 bool requires_validation = |
768 parsed->RequiresValidation(request_time, response_time, current_time); | 770 parsed->RequiresValidation(request_time, response_time, current_time); |
769 EXPECT_EQ(tests[i].requires_validation, requires_validation); | 771 EXPECT_EQ(tests[i].requires_validation, requires_validation); |
770 } | 772 } |
771 } | 773 } |
772 | 774 |
773 TEST(HttpResponseHeadersTest, Update) { | 775 TEST(HttpResponseHeadersTest, Update) { |
774 const struct { | 776 const struct { |
775 const char* orig_headers; | 777 const char* orig_headers; |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 } | 1135 } |
1134 | 1136 |
1135 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { | 1137 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { |
1136 std::string headers("Foo bar."); | 1138 std::string headers("Foo bar."); |
1137 HeadersToRaw(&headers); | 1139 HeadersToRaw(&headers); |
1138 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 1140 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); |
1139 // The bad status line would have gotten rewritten as | 1141 // The bad status line would have gotten rewritten as |
1140 // HTTP/1.0 200 OK. | 1142 // HTTP/1.0 200 OK. |
1141 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); | 1143 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); |
1142 } | 1144 } |
OLD | NEW |