| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #elif defined(USE_NSS) | 10 #elif defined(USE_NSS) |
| (...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 | 1656 |
| 1657 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 1657 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 1658 != std::string::npos); | 1658 != std::string::npos); |
| 1659 | 1659 |
| 1660 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1660 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1661 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1661 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1662 } | 1662 } |
| 1663 | 1663 |
| 1664 // Verify that the cookie isn't sent. | 1664 // Verify that the cookie isn't sent. |
| 1665 { | 1665 { |
| 1666 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES | | 1666 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); |
| 1667 TestCookiePolicy::ASYNC); | |
| 1668 context->set_cookie_policy(&cookie_policy); | 1667 context->set_cookie_policy(&cookie_policy); |
| 1669 | 1668 |
| 1670 TestDelegate d; | 1669 TestDelegate d; |
| 1671 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 1670 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 1672 req.set_context(context); | 1671 req.set_context(context); |
| 1673 req.Start(); | 1672 req.Start(); |
| 1674 MessageLoop::current()->Run(); | 1673 MessageLoop::current()->Run(); |
| 1675 | 1674 |
| 1676 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 1675 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 1677 == std::string::npos); | 1676 == std::string::npos); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1697 req.set_context(context); | 1696 req.set_context(context); |
| 1698 req.Start(); | 1697 req.Start(); |
| 1699 MessageLoop::current()->Run(); | 1698 MessageLoop::current()->Run(); |
| 1700 | 1699 |
| 1701 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1700 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1702 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1701 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1703 } | 1702 } |
| 1704 | 1703 |
| 1705 // Try to set-up another cookie and update the previous cookie. | 1704 // Try to set-up another cookie and update the previous cookie. |
| 1706 { | 1705 { |
| 1707 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE | | 1706 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
| 1708 TestCookiePolicy::ASYNC); | |
| 1709 context->set_cookie_policy(&cookie_policy); | 1707 context->set_cookie_policy(&cookie_policy); |
| 1710 | 1708 |
| 1711 TestDelegate d; | 1709 TestDelegate d; |
| 1712 URLRequest req(test_server.GetURL( | 1710 URLRequest req(test_server.GetURL( |
| 1713 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 1711 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
| 1714 req.set_context(context); | 1712 req.set_context(context); |
| 1715 req.Start(); | 1713 req.Start(); |
| 1716 | 1714 |
| 1717 MessageLoop::current()->Run(); | 1715 MessageLoop::current()->Run(); |
| 1718 | 1716 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1733 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 1731 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 1734 == std::string::npos); | 1732 == std::string::npos); |
| 1735 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1733 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 1736 != std::string::npos); | 1734 != std::string::npos); |
| 1737 | 1735 |
| 1738 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1736 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
| 1739 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1737 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1740 } | 1738 } |
| 1741 } | 1739 } |
| 1742 | 1740 |
| 1743 TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { | |
| 1744 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); | |
| 1745 ASSERT_TRUE(test_server.Start()); | |
| 1746 | |
| 1747 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | |
| 1748 | |
| 1749 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); | |
| 1750 context->set_cookie_policy(&cookie_policy); | |
| 1751 | |
| 1752 // Set up a cookie. | |
| 1753 { | |
| 1754 TestDelegate d; | |
| 1755 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | |
| 1756 &d); | |
| 1757 req.set_context(context); | |
| 1758 req.Start(); // Triggers an asynchronous cookie policy check. | |
| 1759 | |
| 1760 // But, now we cancel the request by letting it go out of scope. This | |
| 1761 // should not cause a crash. | |
| 1762 | |
| 1763 EXPECT_EQ(0, d.blocked_get_cookies_count()); | |
| 1764 EXPECT_EQ(0, d.blocked_set_cookie_count()); | |
| 1765 } | |
| 1766 | |
| 1767 context->set_cookie_policy(NULL); | |
| 1768 | |
| 1769 // Let the cookie policy complete. Make sure it handles the destruction of | |
| 1770 // the URLRequest properly. | |
| 1771 MessageLoop::current()->RunAllPending(); | |
| 1772 } | |
| 1773 | |
| 1774 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { | |
| 1775 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); | |
| 1776 ASSERT_TRUE(test_server.Start()); | |
| 1777 | |
| 1778 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | |
| 1779 | |
| 1780 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); | |
| 1781 context->set_cookie_policy(&cookie_policy); | |
| 1782 | |
| 1783 // Set up a cookie. | |
| 1784 { | |
| 1785 TestDelegate d; | |
| 1786 d.set_cancel_in_get_cookies_blocked(true); | |
| 1787 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | |
| 1788 &d); | |
| 1789 req.set_context(context); | |
| 1790 req.Start(); // Triggers an asynchronous cookie policy check. | |
| 1791 | |
| 1792 MessageLoop::current()->Run(); | |
| 1793 | |
| 1794 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | |
| 1795 | |
| 1796 EXPECT_EQ(1, d.blocked_get_cookies_count()); | |
| 1797 EXPECT_EQ(0, d.blocked_set_cookie_count()); | |
| 1798 } | |
| 1799 | |
| 1800 context->set_cookie_policy(NULL); | |
| 1801 } | |
| 1802 | |
| 1803 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { | |
| 1804 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); | |
| 1805 ASSERT_TRUE(test_server.Start()); | |
| 1806 | |
| 1807 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | |
| 1808 | |
| 1809 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | |
| 1810 context->set_cookie_policy(&cookie_policy); | |
| 1811 | |
| 1812 // Set up a cookie. | |
| 1813 { | |
| 1814 TestDelegate d; | |
| 1815 d.set_cancel_in_set_cookie_blocked(true); | |
| 1816 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | |
| 1817 &d); | |
| 1818 req.set_context(context); | |
| 1819 req.Start(); // Triggers an asynchronous cookie policy check. | |
| 1820 | |
| 1821 MessageLoop::current()->Run(); | |
| 1822 | |
| 1823 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | |
| 1824 | |
| 1825 // Even though the response will contain 3 set-cookie headers, we expect | |
| 1826 // only one to be blocked as that first one will cause OnSetCookie to be | |
| 1827 // called, which will cancel the request. Once canceled, it should not | |
| 1828 // attempt to set further cookies. | |
| 1829 | |
| 1830 EXPECT_EQ(0, d.blocked_get_cookies_count()); | |
| 1831 EXPECT_EQ(1, d.blocked_set_cookie_count()); | |
| 1832 } | |
| 1833 | |
| 1834 context->set_cookie_policy(NULL); | |
| 1835 } | |
| 1836 | |
| 1837 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 1741 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
| 1838 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); | 1742 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); |
| 1839 ASSERT_TRUE(test_server.Start()); | 1743 ASSERT_TRUE(test_server.Start()); |
| 1840 | 1744 |
| 1841 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 1745 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
| 1842 | 1746 |
| 1843 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); | 1747 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); |
| 1844 context->set_cookie_policy(&cookie_policy); | 1748 context->set_cookie_policy(&cookie_policy); |
| 1845 | 1749 |
| 1846 // Set up a cookie. | 1750 // Set up a cookie. |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2865 req.SetExtraRequestHeaders(headers); | 2769 req.SetExtraRequestHeaders(headers); |
| 2866 req.Start(); | 2770 req.Start(); |
| 2867 MessageLoop::current()->Run(); | 2771 MessageLoop::current()->Run(); |
| 2868 // If the net tests are being run with ChromeFrame then we need to allow for | 2772 // If the net tests are being run with ChromeFrame then we need to allow for |
| 2869 // the 'chromeframe' suffix which is added to the user agent before the | 2773 // the 'chromeframe' suffix which is added to the user agent before the |
| 2870 // closing parentheses. | 2774 // closing parentheses. |
| 2871 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 2775 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 2872 } | 2776 } |
| 2873 | 2777 |
| 2874 } // namespace net | 2778 } // namespace net |
| OLD | NEW |