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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 | 1678 |
1679 "Content-Length", // Matching name. | 1679 "Content-Length", // Matching name. |
1680 | 1680 |
1681 "999", // Mismatching value. | 1681 "999", // Mismatching value. |
1682 | 1682 |
1683 "HTTP/1.1 200 OK\n" | 1683 "HTTP/1.1 200 OK\n" |
1684 "connection: keep-alive\n" | 1684 "connection: keep-alive\n" |
1685 "Content-Length: 450\n" | 1685 "Content-Length: 450\n" |
1686 "Cache-control: max-age=10000\n" | 1686 "Cache-control: max-age=10000\n" |
1687 }, | 1687 }, |
| 1688 { "HTTP/1.1 200 OK\n" |
| 1689 "connection: keep-alive \n" |
| 1690 "Foo: bar, baz\n" |
| 1691 "Foo: bar\n" |
| 1692 "Cache-control: max-age=10000\n", |
1688 | 1693 |
| 1694 "Foo", |
| 1695 |
| 1696 "bar, baz", // Space in value. |
| 1697 |
| 1698 "HTTP/1.1 200 OK\n" |
| 1699 "connection: keep-alive\n" |
| 1700 "Foo: bar\n" |
| 1701 "Cache-control: max-age=10000\n" |
| 1702 }, |
| 1703 { "HTTP/1.1 200 OK\n" |
| 1704 "connection: keep-alive \n" |
| 1705 "Foo: bar, baz\n" |
| 1706 "Cache-control: max-age=10000\n", |
| 1707 |
| 1708 "Foo", |
| 1709 |
| 1710 "baz", // Only partial match -> ignored. |
| 1711 |
| 1712 "HTTP/1.1 200 OK\n" |
| 1713 "connection: keep-alive\n" |
| 1714 "Foo: bar, baz\n" |
| 1715 "Cache-control: max-age=10000\n" |
| 1716 }, |
1689 }; | 1717 }; |
1690 | 1718 |
1691 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1719 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
1692 std::string orig_headers(tests[i].orig_headers); | 1720 std::string orig_headers(tests[i].orig_headers); |
1693 HeadersToRaw(&orig_headers); | 1721 HeadersToRaw(&orig_headers); |
1694 scoped_refptr<net::HttpResponseHeaders> parsed( | 1722 scoped_refptr<net::HttpResponseHeaders> parsed( |
1695 new net::HttpResponseHeaders(orig_headers)); | 1723 new net::HttpResponseHeaders(orig_headers)); |
1696 | 1724 |
1697 std::string name(tests[i].to_remove_name); | 1725 std::string name(tests[i].to_remove_name); |
1698 std::string value(tests[i].to_remove_value); | 1726 std::string value(tests[i].to_remove_value); |
1699 parsed->RemoveHeaderWithValue(name, value); | 1727 parsed->RemoveHeaderLine(name, value); |
1700 | 1728 |
1701 std::string resulting_headers; | 1729 std::string resulting_headers; |
1702 parsed->GetNormalizedHeaders(&resulting_headers); | 1730 parsed->GetNormalizedHeaders(&resulting_headers); |
1703 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); | 1731 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); |
1704 } | 1732 } |
1705 } | 1733 } |
1706 | 1734 |
1707 TEST(HttpResponseHeadersTest, ReplaceStatus) { | 1735 TEST(HttpResponseHeadersTest, ReplaceStatus) { |
1708 const struct { | 1736 const struct { |
1709 const char* orig_headers; | 1737 const char* orig_headers; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1778 EXPECT_EQ(parsed->response_code(), recreated->response_code()); | 1806 EXPECT_EQ(parsed->response_code(), recreated->response_code()); |
1779 EXPECT_EQ(parsed->GetContentLength(), recreated->GetContentLength()); | 1807 EXPECT_EQ(parsed->GetContentLength(), recreated->GetContentLength()); |
1780 EXPECT_EQ(parsed->IsKeepAlive(), recreated->IsKeepAlive()); | 1808 EXPECT_EQ(parsed->IsKeepAlive(), recreated->IsKeepAlive()); |
1781 | 1809 |
1782 std::string normalized_parsed; | 1810 std::string normalized_parsed; |
1783 parsed->GetNormalizedHeaders(&normalized_parsed); | 1811 parsed->GetNormalizedHeaders(&normalized_parsed); |
1784 std::string normalized_recreated; | 1812 std::string normalized_recreated; |
1785 parsed->GetNormalizedHeaders(&normalized_recreated); | 1813 parsed->GetNormalizedHeaders(&normalized_recreated); |
1786 EXPECT_EQ(normalized_parsed, normalized_recreated); | 1814 EXPECT_EQ(normalized_parsed, normalized_recreated); |
1787 } | 1815 } |
OLD | NEW |