| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 EXPECT_EQ(test.expected_response_code, parsed->response_code()); | 62 EXPECT_EQ(test.expected_response_code, parsed->response_code()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 } // end namespace | 65 } // end namespace |
| 66 | 66 |
| 67 // Check that we normalize headers properly. | 67 // Check that we normalize headers properly. |
| 68 TEST(HttpResponseHeadersTest, NormalizeHeadersWhitespace) { | 68 TEST(HttpResponseHeadersTest, NormalizeHeadersWhitespace) { |
| 69 TestData test = { | 69 TestData test = { |
| 70 "HTTP/1.1 202 Accepted \n" | 70 "HTTP/1.1 202 Accepted \n" |
| 71 " Content-TYPE : text/html; charset=utf-8 \n" | 71 "Content-TYPE : text/html; charset=utf-8 \n" |
| 72 "Set-Cookie: a \n" | 72 "Set-Cookie: a \n" |
| 73 "Set-Cookie: b \n", | 73 "Set-Cookie: b \n", |
| 74 | 74 |
| 75 "HTTP/1.1 202 Accepted\n" | 75 "HTTP/1.1 202 Accepted\n" |
| 76 "Content-TYPE: text/html; charset=utf-8\n" | 76 "Content-TYPE: text/html; charset=utf-8\n" |
| 77 "Set-Cookie: a, b\n", | 77 "Set-Cookie: a, b\n", |
| 78 | 78 |
| 79 202 | 79 202 |
| 80 }; | 80 }; |
| 81 TestCommon(test); | 81 TestCommon(test); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Check that we normalize headers properly (header name is invalid if starts |
| 85 // with LWS). |
| 86 TEST(HttpResponseHeadersTest, NormalizeHeadersLeadingWhitespace) { |
| 87 TestData test = { |
| 88 "HTTP/1.1 202 Accepted \n" |
| 89 // Starts with space -- will be skipped as invalid. |
| 90 " Content-TYPE : text/html; charset=utf-8 \n" |
| 91 "Set-Cookie: a \n" |
| 92 "Set-Cookie: b \n", |
| 93 |
| 94 "HTTP/1.1 202 Accepted\n" |
| 95 "Set-Cookie: a, b\n", |
| 96 |
| 97 202 |
| 98 }; |
| 99 TestCommon(test); |
| 100 } |
| 101 |
| 84 TEST(HttpResponseHeadersTest, BlankHeaders) { | 102 TEST(HttpResponseHeadersTest, BlankHeaders) { |
| 85 TestData test = { | 103 TestData test = { |
| 86 "HTTP/1.1 200 OK\n" | 104 "HTTP/1.1 200 OK\n" |
| 87 "Header1 : \n" | 105 "Header1 : \n" |
| 88 "Header2: \n" | 106 "Header2: \n" |
| 89 "Header3:\n" | 107 "Header3:\n" |
| 90 "Header4\n" | 108 "Header4\n" |
| 91 "Header5 :\n", | 109 "Header5 :\n", |
| 92 | 110 |
| 93 "HTTP/1.1 200 OK\n" | 111 "HTTP/1.1 200 OK\n" |
| (...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 990 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 973 string headers(tests[i].headers); | 991 string headers(tests[i].headers); |
| 974 HeadersToRaw(&headers); | 992 HeadersToRaw(&headers); |
| 975 scoped_refptr<HttpResponseHeaders> parsed = | 993 scoped_refptr<HttpResponseHeaders> parsed = |
| 976 new HttpResponseHeaders(headers); | 994 new HttpResponseHeaders(headers); |
| 977 | 995 |
| 978 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); | 996 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); |
| 979 } | 997 } |
| 980 } | 998 } |
| 981 | 999 |
| OLD | NEW |