Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 6995013: More progress towards removing content settings code from the content layer. We can't use Cookie... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments and sync Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #endif 10 #endif
(...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 1648
1649 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 1649 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
1650 != std::string::npos); 1650 != std::string::npos);
1651 1651
1652 EXPECT_EQ(0, d.blocked_get_cookies_count()); 1652 EXPECT_EQ(0, d.blocked_get_cookies_count());
1653 EXPECT_EQ(0, d.blocked_set_cookie_count()); 1653 EXPECT_EQ(0, d.blocked_set_cookie_count());
1654 } 1654 }
1655 1655
1656 // Verify that the cookie isn't sent. 1656 // Verify that the cookie isn't sent.
1657 { 1657 {
1658 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES);
1659 context->set_cookie_policy(&cookie_policy);
1660
1661 TestDelegate d; 1658 TestDelegate d;
1659 d.set_cookie_options(TestDelegate::NO_GET_COOKIES);
1662 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 1660 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
1663 req.set_context(context); 1661 req.set_context(context);
1664 req.Start(); 1662 req.Start();
1665 MessageLoop::current()->Run(); 1663 MessageLoop::current()->Run();
1666 1664
1667 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 1665 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
1668 == std::string::npos); 1666 == std::string::npos);
1669 1667
1670 context->set_cookie_policy(NULL);
1671
1672 EXPECT_EQ(1, d.blocked_get_cookies_count()); 1668 EXPECT_EQ(1, d.blocked_get_cookies_count());
1673 EXPECT_EQ(0, d.blocked_set_cookie_count()); 1669 EXPECT_EQ(0, d.blocked_set_cookie_count());
1674 } 1670 }
1675 } 1671 }
1676 1672
1677 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 1673 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
1678 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); 1674 TestServer test_server(TestServer::TYPE_HTTP, FilePath());
1679 ASSERT_TRUE(test_server.Start()); 1675 ASSERT_TRUE(test_server.Start());
1680 1676
1681 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); 1677 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext());
1682 1678
1683 // Set up a cookie. 1679 // Set up a cookie.
1684 { 1680 {
1685 TestDelegate d; 1681 TestDelegate d;
1686 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), 1682 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"),
1687 &d); 1683 &d);
1688 req.set_context(context); 1684 req.set_context(context);
1689 req.Start(); 1685 req.Start();
1690 MessageLoop::current()->Run(); 1686 MessageLoop::current()->Run();
1691 1687
1692 EXPECT_EQ(0, d.blocked_get_cookies_count()); 1688 EXPECT_EQ(0, d.blocked_get_cookies_count());
1693 EXPECT_EQ(0, d.blocked_set_cookie_count()); 1689 EXPECT_EQ(0, d.blocked_set_cookie_count());
1694 } 1690 }
1695 1691
1696 // Try to set-up another cookie and update the previous cookie. 1692 // Try to set-up another cookie and update the previous cookie.
1697 { 1693 {
1698 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE);
1699 context->set_cookie_policy(&cookie_policy);
1700
1701 TestDelegate d; 1694 TestDelegate d;
1695 d.set_cookie_options(TestDelegate::NO_SET_COOKIE);
1702 URLRequest req(test_server.GetURL( 1696 URLRequest req(test_server.GetURL(
1703 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 1697 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
1704 req.set_context(context); 1698 req.set_context(context);
1705 req.Start(); 1699 req.Start();
1706 1700
1707 MessageLoop::current()->Run(); 1701 MessageLoop::current()->Run();
1708 1702
1709 context->set_cookie_policy(NULL);
1710
1711 EXPECT_EQ(0, d.blocked_get_cookies_count()); 1703 EXPECT_EQ(0, d.blocked_get_cookies_count());
1712 EXPECT_EQ(2, d.blocked_set_cookie_count()); 1704 EXPECT_EQ(2, d.blocked_set_cookie_count());
1713 } 1705 }
1714 1706
1715 1707
1716 // Verify the cookies weren't saved or updated. 1708 // Verify the cookies weren't saved or updated.
1717 { 1709 {
1718 TestDelegate d; 1710 TestDelegate d;
1719 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 1711 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
1720 req.set_context(context); 1712 req.set_context(context);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 1771
1780 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 1772 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
1781 != std::string::npos); 1773 != std::string::npos);
1782 1774
1783 EXPECT_EQ(0, d.blocked_get_cookies_count()); 1775 EXPECT_EQ(0, d.blocked_get_cookies_count());
1784 EXPECT_EQ(0, d.blocked_set_cookie_count()); 1776 EXPECT_EQ(0, d.blocked_set_cookie_count());
1785 } 1777 }
1786 1778
1787 // Verify that the cookie isn't sent. 1779 // Verify that the cookie isn't sent.
1788 { 1780 {
1789 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES);
1790 context->set_cookie_policy(&cookie_policy);
1791
1792 TestDelegate d; 1781 TestDelegate d;
1782 d.set_cookie_options(TestDelegate::NO_GET_COOKIES);
1793 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 1783 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
1794 req.set_context(context); 1784 req.set_context(context);
1795 req.Start(); 1785 req.Start();
1796 MessageLoop::current()->Run(); 1786 MessageLoop::current()->Run();
1797 1787
1798 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 1788 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
1799 == std::string::npos); 1789 == std::string::npos);
1800 1790
1801 context->set_cookie_policy(NULL);
1802
1803 EXPECT_EQ(1, d.blocked_get_cookies_count()); 1791 EXPECT_EQ(1, d.blocked_get_cookies_count());
1804 EXPECT_EQ(0, d.blocked_set_cookie_count()); 1792 EXPECT_EQ(0, d.blocked_set_cookie_count());
1805 } 1793 }
1806 } 1794 }
1807 1795
1808 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 1796 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
1809 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); 1797 TestServer test_server(TestServer::TYPE_HTTP, FilePath());
1810 ASSERT_TRUE(test_server.Start()); 1798 ASSERT_TRUE(test_server.Start());
1811 1799
1812 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); 1800 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext());
1813 1801
1814 // Set up a cookie. 1802 // Set up a cookie.
1815 { 1803 {
1816 TestDelegate d; 1804 TestDelegate d;
1817 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), 1805 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"),
1818 &d); 1806 &d);
1819 req.set_context(context); 1807 req.set_context(context);
1820 req.Start(); 1808 req.Start();
1821 MessageLoop::current()->Run(); 1809 MessageLoop::current()->Run();
1822 1810
1823 EXPECT_EQ(0, d.blocked_get_cookies_count()); 1811 EXPECT_EQ(0, d.blocked_get_cookies_count());
1824 EXPECT_EQ(0, d.blocked_set_cookie_count()); 1812 EXPECT_EQ(0, d.blocked_set_cookie_count());
1825 } 1813 }
1826 1814
1827 // Try to set-up another cookie and update the previous cookie. 1815 // Try to set-up another cookie and update the previous cookie.
1828 { 1816 {
1829 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE);
1830 context->set_cookie_policy(&cookie_policy);
1831
1832 TestDelegate d; 1817 TestDelegate d;
1818 d.set_cookie_options(TestDelegate::NO_SET_COOKIE);
1833 URLRequest req(test_server.GetURL( 1819 URLRequest req(test_server.GetURL(
1834 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 1820 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
1835 req.set_context(context); 1821 req.set_context(context);
1836 req.Start(); 1822 req.Start();
1837 1823
1838 MessageLoop::current()->Run(); 1824 MessageLoop::current()->Run();
1839 1825
1840 context->set_cookie_policy(NULL);
1841
1842 EXPECT_EQ(0, d.blocked_get_cookies_count()); 1826 EXPECT_EQ(0, d.blocked_get_cookies_count());
1843 EXPECT_EQ(2, d.blocked_set_cookie_count()); 1827 EXPECT_EQ(2, d.blocked_set_cookie_count());
1844 } 1828 }
1845 1829
1846 // Verify the cookies weren't saved or updated. 1830 // Verify the cookies weren't saved or updated.
1847 { 1831 {
1848 TestDelegate d; 1832 TestDelegate d;
1849 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 1833 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
1850 req.set_context(context); 1834 req.set_context(context);
1851 req.Start(); 1835 req.Start();
1852 MessageLoop::current()->Run(); 1836 MessageLoop::current()->Run();
1853 1837
1854 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 1838 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
1855 == std::string::npos); 1839 == std::string::npos);
1856 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 1840 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
1857 != std::string::npos); 1841 != std::string::npos);
1858 1842
1859 EXPECT_EQ(0, d.blocked_get_cookies_count()); 1843 EXPECT_EQ(0, d.blocked_get_cookies_count());
1860 EXPECT_EQ(0, d.blocked_set_cookie_count()); 1844 EXPECT_EQ(0, d.blocked_set_cookie_count());
1861 } 1845 }
1862 } 1846 }
1863 1847
1864 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { 1848 TEST_F(URLRequestTest, CookiePolicy_ForceSession) {
1865 TestServer test_server(TestServer::TYPE_HTTP, FilePath()); 1849 TestServer test_server(TestServer::TYPE_HTTP, FilePath());
1866 ASSERT_TRUE(test_server.Start()); 1850 ASSERT_TRUE(test_server.Start());
1867 1851
1868 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); 1852 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext());
1869 1853
1870 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION);
1871 context->set_cookie_policy(&cookie_policy);
1872
1873 // Set up a cookie. 1854 // Set up a cookie.
1874 { 1855 {
1875 TestDelegate d; 1856 TestDelegate d;
1857 d.set_cookie_options(TestDelegate::FORCE_SESSION);
1876 URLRequest req(test_server.GetURL( 1858 URLRequest req(test_server.GetURL(
1877 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); 1859 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d);
1878 req.set_context(context); 1860 req.set_context(context);
1879 req.Start(); // Triggers an asynchronous cookie policy check. 1861 req.Start(); // Triggers an asynchronous cookie policy check.
1880 1862
1881 MessageLoop::current()->Run(); 1863 MessageLoop::current()->Run();
1882 1864
1883 EXPECT_EQ(0, d.blocked_get_cookies_count()); 1865 EXPECT_EQ(0, d.blocked_get_cookies_count());
1884 EXPECT_EQ(0, d.blocked_set_cookie_count()); 1866 EXPECT_EQ(0, d.blocked_set_cookie_count());
1885 } 1867 }
1886 1868
1887 // Now, check the cookie store. 1869 // Now, check the cookie store.
1888 CookieList cookies = 1870 CookieList cookies =
1889 context->cookie_store()->GetCookieMonster()->GetAllCookies(); 1871 context->cookie_store()->GetCookieMonster()->GetAllCookies();
1890 EXPECT_EQ(1U, cookies.size()); 1872 EXPECT_EQ(1U, cookies.size());
1891 EXPECT_FALSE(cookies[0].IsPersistent()); 1873 EXPECT_FALSE(cookies[0].IsPersistent());
1892
1893 context->set_cookie_policy(NULL);
1894 } 1874 }
1895 1875
1896 // In this test, we do a POST which the server will 302 redirect. 1876 // In this test, we do a POST which the server will 302 redirect.
1897 // The subsequent transaction should use GET, and should not send the 1877 // The subsequent transaction should use GET, and should not send the
1898 // Content-Type header. 1878 // Content-Type header.
1899 // http://code.google.com/p/chromium/issues/detail?id=843 1879 // http://code.google.com/p/chromium/issues/detail?id=843
1900 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { 1880 TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
1901 ASSERT_TRUE(test_server_.Start()); 1881 ASSERT_TRUE(test_server_.Start());
1902 1882
1903 const char kData[] = "hello world"; 1883 const char kData[] = "hello world";
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 req.SetExtraRequestHeaders(headers); 2872 req.SetExtraRequestHeaders(headers);
2893 req.Start(); 2873 req.Start();
2894 MessageLoop::current()->Run(); 2874 MessageLoop::current()->Run();
2895 // If the net tests are being run with ChromeFrame then we need to allow for 2875 // If the net tests are being run with ChromeFrame then we need to allow for
2896 // the 'chromeframe' suffix which is added to the user agent before the 2876 // the 'chromeframe' suffix which is added to the user agent before the
2897 // closing parentheses. 2877 // closing parentheses.
2898 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 2878 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
2899 } 2879 }
2900 2880
2901 } // namespace net 2881 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698