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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1735 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 1735 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
1736 == std::string::npos); | 1736 == std::string::npos); |
1737 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1737 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
1738 != std::string::npos); | 1738 != std::string::npos); |
1739 | 1739 |
1740 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1740 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1741 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1741 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1742 } | 1742 } |
1743 } | 1743 } |
1744 | 1744 |
1745 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header | |
1746 // value for the |fixed_date| argument given to the constructor. | |
1747 class FixedDateNetworkDelegate : public TestNetworkDelegate { | |
1748 public: | |
1749 FixedDateNetworkDelegate(std::string fixed_date); | |
szym
2012/10/30 19:52:53
nit: make explicit, use const &
| |
1750 virtual ~FixedDateNetworkDelegate(); | |
szym
2012/10/30 19:52:53
I'd make all methods inline here.
| |
1751 | |
1752 // net::NetworkDelegate implementation | |
1753 virtual int OnHeadersReceived( | |
1754 net::URLRequest* request, | |
1755 const net::CompletionCallback& callback, | |
1756 const net::HttpResponseHeaders* original_response_headers, | |
1757 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) | |
1758 OVERRIDE; | |
1759 | |
1760 private: | |
1761 std::string fixed_date_; | |
1762 | |
1763 DISALLOW_COPY_AND_ASSIGN(FixedDateNetworkDelegate); | |
1764 }; | |
1765 | |
1766 FixedDateNetworkDelegate::FixedDateNetworkDelegate(std::string fixed_date) | |
1767 : fixed_date_(fixed_date) {} | |
1768 | |
1769 FixedDateNetworkDelegate::~FixedDateNetworkDelegate() {} | |
1770 | |
1771 int FixedDateNetworkDelegate::OnHeadersReceived( | |
1772 net::URLRequest* request, | |
1773 const net::CompletionCallback& callback, | |
1774 const net::HttpResponseHeaders* original_response_headers, | |
1775 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { | |
1776 net::HttpResponseHeaders* new_response_headers = | |
1777 new net::HttpResponseHeaders(original_response_headers->raw_headers()); | |
1778 | |
1779 new_response_headers->RemoveHeader("Date"); | |
1780 new_response_headers->AddHeader("Date: " + fixed_date_); | |
1781 | |
1782 *override_response_headers = new_response_headers; | |
1783 return TestNetworkDelegate::OnHeadersReceived(request, | |
1784 callback, | |
1785 original_response_headers, | |
1786 override_response_headers); | |
1787 } | |
1788 | |
1789 // Test that cookie expiration times are adjusted for server/client clock | |
1790 // skew and that we handle incorrect timezone specifier "UTC" in HTTP Date | |
1791 // headers by defaulting to GMT. (crbug.com/135131) | |
1792 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { | |
1793 LocalHttpTestServer test_server; | |
1794 ASSERT_TRUE(test_server.Start()); | |
1795 | |
1796 // Set up an expired cookie. | |
1797 { | |
1798 TestNetworkDelegate network_delegate; | |
1799 default_context_.set_network_delegate(&network_delegate); | |
1800 TestDelegate d; | |
1801 URLRequest req(test_server.GetURL( | |
1802 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | |
1803 &d, | |
1804 &default_context_); | |
1805 req.Start(); | |
1806 MessageLoop::current()->Run(); | |
1807 } | |
1808 // Verify that the cookie is not set. | |
1809 { | |
1810 TestNetworkDelegate network_delegate; | |
1811 default_context_.set_network_delegate(&network_delegate); | |
1812 TestDelegate d; | |
1813 URLRequest req( | |
1814 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | |
1815 req.Start(); | |
1816 MessageLoop::current()->Run(); | |
1817 | |
1818 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); | |
1819 } | |
1820 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. | |
1821 { | |
1822 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); | |
1823 default_context_.set_network_delegate(&network_delegate); | |
1824 TestDelegate d; | |
1825 URLRequest req(test_server.GetURL( | |
1826 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | |
1827 &d, | |
1828 &default_context_); | |
1829 req.Start(); | |
1830 MessageLoop::current()->Run(); | |
1831 } | |
1832 // Verify that the cookie is set. | |
1833 { | |
1834 TestNetworkDelegate network_delegate; | |
1835 default_context_.set_network_delegate(&network_delegate); | |
1836 TestDelegate d; | |
1837 URLRequest req( | |
1838 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | |
1839 req.Start(); | |
1840 MessageLoop::current()->Run(); | |
1841 | |
1842 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); | |
1843 } | |
1844 } | |
1845 | |
1846 | |
1745 // Check that it is impossible to change the referrer in the extra headers of | 1847 // Check that it is impossible to change the referrer in the extra headers of |
1746 // an URLRequest. | 1848 // an URLRequest. |
1747 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 1849 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
1748 LocalHttpTestServer test_server; | 1850 LocalHttpTestServer test_server; |
1749 ASSERT_TRUE(test_server.Start()); | 1851 ASSERT_TRUE(test_server.Start()); |
1750 | 1852 |
1751 // If extra headers contain referer and the request contains a referer, | 1853 // If extra headers contain referer and the request contains a referer, |
1752 // only the latter shall be respected. | 1854 // only the latter shall be respected. |
1753 { | 1855 { |
1754 TestDelegate d; | 1856 TestDelegate d; |
(...skipping 3078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4833 | 4935 |
4834 EXPECT_FALSE(r.is_pending()); | 4936 EXPECT_FALSE(r.is_pending()); |
4835 EXPECT_EQ(1, d->response_started_count()); | 4937 EXPECT_EQ(1, d->response_started_count()); |
4836 EXPECT_FALSE(d->received_data_before_response()); | 4938 EXPECT_FALSE(d->received_data_before_response()); |
4837 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4939 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
4838 } | 4940 } |
4839 } | 4941 } |
4840 #endif // !defined(DISABLE_FTP_SUPPORT) | 4942 #endif // !defined(DISABLE_FTP_SUPPORT) |
4841 | 4943 |
4842 } // namespace net | 4944 } // namespace net |
OLD | NEW |