diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 02:33:46 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 02:33:46 +0000 |
commit | 861fcd5d715f0590e75eddfb1bacb0ac356c8026 (patch) | |
tree | d16ca24619a70210141952fe0c50859418b5ef45 /net/url_request | |
parent | 9fa24879b1b211336e6da511a8931f62ad6845d7 (diff) | |
download | chromium_src-861fcd5d715f0590e75eddfb1bacb0ac356c8026.zip chromium_src-861fcd5d715f0590e75eddfb1bacb0ac356c8026.tar.gz chromium_src-861fcd5d715f0590e75eddfb1bacb0ac356c8026.tar.bz2 |
Add the ability to not send cookies or send user name/password.
Added unit tests for the above functionality plus the do not save cookies functionality.
BUG=http://crbug.com/10961
TEST=Added unit tests for this. Also, this isn't yet called from the rest of the code.
Review URL: http://codereview.chromium.org/173206
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r-- | net/url_request/url_request_http_job.cc | 3 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 85 |
2 files changed, 88 insertions, 0 deletions
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index b019c48..b0438fa 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -661,6 +661,9 @@ void URLRequestHttpJob::AddExtraHeaders() { } std::string URLRequestHttpJob::AssembleRequestCookies() { + if (request_info_.load_flags & net::LOAD_DO_NOT_SEND_COOKIES) + return std::string(); + URLRequestContext* context = request_->context(); if (context) { // Add in the cookie header. TODO might we need more than one header? diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index afa2c6c..b224c2e 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -1307,6 +1307,91 @@ TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { } } +TEST_F(URLRequestTest, DoNotSendCookies) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(L"", NULL); + ASSERT_TRUE(NULL != server.get()); + scoped_refptr<URLRequestContext> context = new URLRequestTestContext(); + + // Set up a cookie. + { + TestDelegate d; + URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); + req.set_context(context); + req.Start(); + MessageLoop::current()->Run(); + } + + // Verify that the cookie is set. + { + TestDelegate d; + TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + req.set_context(context); + req.Start(); + MessageLoop::current()->Run(); + + EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") + != std::string::npos); + } + + // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. + { + TestDelegate d; + TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + req.set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); + req.set_context(context); + req.Start(); + MessageLoop::current()->Run(); + + EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") + == std::string::npos); + } +} + +TEST_F(URLRequestTest, DoNotSaveCookies) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(L"", NULL); + ASSERT_TRUE(NULL != server.get()); + scoped_refptr<URLRequestContext> context = new URLRequestTestContext(); + + // Set up a cookie. + { + TestDelegate d; + URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), + &d); + req.set_context(context); + req.Start(); + MessageLoop::current()->Run(); + } + + // Try to set-up another cookie and update the previous cookie. + { + scoped_refptr<URLRequestContext> context = new URLRequestTestContext(); + TestDelegate d; + URLRequest req(server->TestServerPage( + "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); + req.set_load_flags(net::LOAD_DO_NOT_SAVE_COOKIES); + req.set_context(context); + req.Start(); + + MessageLoop::current()->Run(); + } + + // Verify the cookies weren't saved or updated. + { + TestDelegate d; + TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); + req.set_context(context); + req.Start(); + MessageLoop::current()->Run(); + + EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") + == std::string::npos); + EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") + != std::string::npos); + } +} + // In this test, we do a POST which the server will 302 redirect. // The subsequent transaction should use GET, and should not send the // Content-Type header. |