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 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1635 std::string resulting_headers; | 1635 std::string resulting_headers; |
1636 parsed->GetNormalizedHeaders(&resulting_headers); | 1636 parsed->GetNormalizedHeaders(&resulting_headers); |
1637 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); | 1637 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); |
1638 } | 1638 } |
1639 } | 1639 } |
1640 | 1640 |
1641 TEST(HttpResponseHeadersTest, RemoveIndividualHeader) { | 1641 TEST(HttpResponseHeadersTest, RemoveIndividualHeader) { |
1642 const struct { | 1642 const struct { |
1643 const char* orig_headers; | 1643 const char* orig_headers; |
1644 const char* to_remove_name; | 1644 const char* to_remove_name; |
1645 const char* to_remove_value; | 1645 const char* to_remove_values; |
rvargas (doing something else)
2012/07/19 19:11:02
nit: I would still use singular here.
battre
2012/07/23 13:31:11
Done.
| |
1646 const char* expected_headers; | 1646 const char* expected_headers; |
1647 } tests[] = { | 1647 } tests[] = { |
1648 { "HTTP/1.1 200 OK\n" | 1648 { "HTTP/1.1 200 OK\n" |
1649 "connection: keep-alive\n" | 1649 "connection: keep-alive\n" |
1650 "Cache-control: max-age=10000\n" | 1650 "Cache-control: max-age=10000\n" |
1651 "Content-Length: 450\n", | 1651 "Content-Length: 450\n", |
1652 | 1652 |
1653 "Content-Length", | 1653 "Content-Length", |
1654 | 1654 |
1655 "450", | 1655 "450", |
(...skipping 22 matching lines...) Expand all 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" | |
rvargas (doing something else)
2012/07/19 19:11:02
How about adding another "Foo: bar\n" line here (t
battre
2012/07/23 13:31:11
Done.
| |
1691 "Cache-control: max-age=10000\n", | |
1688 | 1692 |
1693 "Foo", | |
1694 | |
1695 "bar, baz", // Space in value. | |
1696 | |
1697 "HTTP/1.1 200 OK\n" | |
1698 "connection: keep-alive\n" | |
1699 "Cache-control: max-age=10000\n" | |
1700 }, | |
1701 { "HTTP/1.1 200 OK\n" | |
1702 "connection: keep-alive \n" | |
1703 "Foo: bar, baz\n" | |
1704 "Cache-control: max-age=10000\n", | |
1705 | |
1706 "Foo", | |
1707 | |
1708 "baz", // Only partial match -> ignored. | |
1709 | |
1710 "HTTP/1.1 200 OK\n" | |
1711 "connection: keep-alive\n" | |
1712 "Foo: bar, baz\n" | |
1713 "Cache-control: max-age=10000\n" | |
1714 }, | |
1689 }; | 1715 }; |
1690 | 1716 |
1691 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1717 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
1692 std::string orig_headers(tests[i].orig_headers); | 1718 std::string orig_headers(tests[i].orig_headers); |
1693 HeadersToRaw(&orig_headers); | 1719 HeadersToRaw(&orig_headers); |
1694 scoped_refptr<net::HttpResponseHeaders> parsed( | 1720 scoped_refptr<net::HttpResponseHeaders> parsed( |
1695 new net::HttpResponseHeaders(orig_headers)); | 1721 new net::HttpResponseHeaders(orig_headers)); |
1696 | 1722 |
1697 std::string name(tests[i].to_remove_name); | 1723 std::string name(tests[i].to_remove_name); |
1698 std::string value(tests[i].to_remove_value); | 1724 std::string values(tests[i].to_remove_values); |
1699 parsed->RemoveHeaderWithValue(name, value); | 1725 parsed->RemoveHeaderLine(name, values); |
1700 | 1726 |
1701 std::string resulting_headers; | 1727 std::string resulting_headers; |
1702 parsed->GetNormalizedHeaders(&resulting_headers); | 1728 parsed->GetNormalizedHeaders(&resulting_headers); |
1703 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); | 1729 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); |
1704 } | 1730 } |
1705 } | 1731 } |
1706 | 1732 |
1707 TEST(HttpResponseHeadersTest, ReplaceStatus) { | 1733 TEST(HttpResponseHeadersTest, ReplaceStatus) { |
1708 const struct { | 1734 const struct { |
1709 const char* orig_headers; | 1735 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()); | 1804 EXPECT_EQ(parsed->response_code(), recreated->response_code()); |
1779 EXPECT_EQ(parsed->GetContentLength(), recreated->GetContentLength()); | 1805 EXPECT_EQ(parsed->GetContentLength(), recreated->GetContentLength()); |
1780 EXPECT_EQ(parsed->IsKeepAlive(), recreated->IsKeepAlive()); | 1806 EXPECT_EQ(parsed->IsKeepAlive(), recreated->IsKeepAlive()); |
1781 | 1807 |
1782 std::string normalized_parsed; | 1808 std::string normalized_parsed; |
1783 parsed->GetNormalizedHeaders(&normalized_parsed); | 1809 parsed->GetNormalizedHeaders(&normalized_parsed); |
1784 std::string normalized_recreated; | 1810 std::string normalized_recreated; |
1785 parsed->GetNormalizedHeaders(&normalized_recreated); | 1811 parsed->GetNormalizedHeaders(&normalized_recreated); |
1786 EXPECT_EQ(normalized_parsed, normalized_recreated); | 1812 EXPECT_EQ(normalized_parsed, normalized_recreated); |
1787 } | 1813 } |
OLD | NEW |