OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 17 matching lines...) Expand all Loading... |
28 const bool has_charset; | 28 const bool has_charset; |
29 const std::string all_content_type; | 29 const std::string all_content_type; |
30 }; | 30 }; |
31 | 31 |
32 class HttpResponseHeadersTest : public testing::Test { | 32 class HttpResponseHeadersTest : public testing::Test { |
33 }; | 33 }; |
34 | 34 |
35 // Transform "normal"-looking headers (\n-separated) to the appropriate | 35 // Transform "normal"-looking headers (\n-separated) to the appropriate |
36 // input format for ParseRawHeaders (\0-separated). | 36 // input format for ParseRawHeaders (\0-separated). |
37 void HeadersToRaw(std::string* headers) { | 37 void HeadersToRaw(std::string* headers) { |
38 replace(headers->begin(), headers->end(), '\n', '\0'); | 38 std::replace(headers->begin(), headers->end(), '\n', '\0'); |
39 if (!headers->empty()) | 39 if (!headers->empty()) |
40 *headers += '\0'; | 40 *headers += '\0'; |
41 } | 41 } |
42 | 42 |
43 void TestCommon(const TestData& test) { | 43 void TestCommon(const TestData& test) { |
44 std::string raw_headers(test.raw_headers); | 44 std::string raw_headers(test.raw_headers); |
45 HeadersToRaw(&raw_headers); | 45 HeadersToRaw(&raw_headers); |
46 std::string expected_headers(test.expected_headers); | 46 std::string expected_headers(test.expected_headers); |
47 | 47 |
48 std::string headers; | 48 std::string headers; |
49 scoped_refptr<net::HttpResponseHeaders> parsed( | 49 scoped_refptr<net::HttpResponseHeaders> parsed( |
50 new net::HttpResponseHeaders(raw_headers)); | 50 new net::HttpResponseHeaders(raw_headers)); |
51 parsed->GetNormalizedHeaders(&headers); | 51 parsed->GetNormalizedHeaders(&headers); |
52 | 52 |
53 // Transform to readable output format (so it's easier to see diffs). | 53 // Transform to readable output format (so it's easier to see diffs). |
54 replace(headers.begin(), headers.end(), ' ', '_'); | 54 std::replace(headers.begin(), headers.end(), ' ', '_'); |
55 replace(headers.begin(), headers.end(), '\n', '\\'); | 55 std::replace(headers.begin(), headers.end(), '\n', '\\'); |
56 replace(expected_headers.begin(), expected_headers.end(), ' ', '_'); | 56 std::replace(expected_headers.begin(), expected_headers.end(), ' ', '_'); |
57 replace(expected_headers.begin(), expected_headers.end(), '\n', '\\'); | 57 std::replace(expected_headers.begin(), expected_headers.end(), '\n', '\\'); |
58 | 58 |
59 EXPECT_EQ(expected_headers, headers); | 59 EXPECT_EQ(expected_headers, headers); |
60 | 60 |
61 EXPECT_EQ(test.expected_response_code, parsed->response_code()); | 61 EXPECT_EQ(test.expected_response_code, parsed->response_code()); |
62 | 62 |
63 EXPECT_TRUE(test.expected_parsed_version == parsed->GetParsedHttpVersion()); | 63 EXPECT_TRUE(test.expected_parsed_version == parsed->GetParsedHttpVersion()); |
64 EXPECT_TRUE(test.expected_version == parsed->GetHttpVersion()); | 64 EXPECT_TRUE(test.expected_version == parsed->GetHttpVersion()); |
65 } | 65 } |
66 | 66 |
67 } // end namespace | 67 } // end namespace |
(...skipping 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 new net::HttpResponseHeaders(orig_headers)); | 1671 new net::HttpResponseHeaders(orig_headers)); |
1672 | 1672 |
1673 std::string name(tests[i].new_status); | 1673 std::string name(tests[i].new_status); |
1674 parsed->ReplaceStatusLine(name); | 1674 parsed->ReplaceStatusLine(name); |
1675 | 1675 |
1676 std::string resulting_headers; | 1676 std::string resulting_headers; |
1677 parsed->GetNormalizedHeaders(&resulting_headers); | 1677 parsed->GetNormalizedHeaders(&resulting_headers); |
1678 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); | 1678 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); |
1679 } | 1679 } |
1680 } | 1680 } |
OLD | NEW |