summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_unittest.cc
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 19:58:57 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 19:58:57 +0000
commita0b0d63b60bbc0675115317a0b08ee4183436787 (patch)
treebe1e255eac2d1e176af658d492bfcf2b28d30ae3 /net/url_request/url_request_unittest.cc
parentb24586704bd0ab21ea365bd75eb6ab0ffc1e00ec (diff)
downloadchromium_src-a0b0d63b60bbc0675115317a0b08ee4183436787.zip
chromium_src-a0b0d63b60bbc0675115317a0b08ee4183436787.tar.gz
chromium_src-a0b0d63b60bbc0675115317a0b08ee4183436787.tar.bz2
Back out trunk r37998.
Modify CookiePolicy to work asynchronously This change will enable us to prompt the user before setting a cookie. While we only need to prompt before setting, we actually need to make both CanSetCookie and CanGetCookies asynchronous. This is necessary in order to preserve FIFO ordering since the value returned by GetCookies depends on the changes made to the cookie DB by SetCookie. This change also includes some simplification of CookieStore. Instead of N virtual functions, I distilled it down to only 4. The remaining functions are instead expressed in terms of those. While studying all the places where we currently use CookiePolicy, I found that some of them were not appropriate. After discussing with Amit, I decided to remove the policy checks in URLRequestAutomationJob. See the comments in the code regarding this. I changed the signature of CookieMonster::GetRawCookies to GetAllCookiesForURL to better match GetAllCookies. I also filed a bug about making it even closer in functionality. Related to this change webkit/glue/webcookie.h grows a constructor that takes a CanonicalCookie to help clean up some code. On the Chrome side, ChromeURLRequestContext now has a ChromeCookiePolicy object. That object is threadsafe ref counted because it is passed between the UI and IO threads. It is responsible for implementing the queuing logic described above. It will also in the future trigger the Chrome UI code to actually show the setcookie prompt. Please review the state machinery changes in URLRequestHttpJob carefully. R=eroman BUG=34331 TEST=no tests yet for prompting. Review URL: http://codereview.chromium.org/567015 TBR=darin@chromium.org Review URL: http://codereview.chromium.org/562037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request/url_request_unittest.cc')
-rw-r--r--net/url_request/url_request_unittest.cc212
1 files changed, 1 insertions, 211 deletions
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 56901fc..48cfd35 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -24,7 +24,6 @@
#include "base/string_piece.h"
#include "base/string_util.h"
#include "net/base/cookie_monster.h"
-#include "net/base/cookie_policy.h"
#include "net/base/load_flags.h"
#include "net/base/load_log.h"
#include "net/base/load_log_unittest.h"
@@ -1287,6 +1286,7 @@ TEST_F(URLRequestTest, DoNotSaveCookies) {
// 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);
@@ -1312,216 +1312,6 @@ TEST_F(URLRequestTest, DoNotSaveCookies) {
}
}
-TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
- scoped_refptr<HTTPTestServer> server =
- HTTPTestServer::CreateServer(L"", NULL);
- ASSERT_TRUE(NULL != server.get());
- scoped_refptr<URLRequestTestContext> 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.
- {
- TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES);
- context->set_cookie_policy(&cookie_policy);
-
- TestDelegate d;
- TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d);
- req.set_context(context);
- req.Start();
- MessageLoop::current()->Run();
-
- EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
- == std::string::npos);
-
- context->set_cookie_policy(NULL);
- }
-}
-
-TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
- scoped_refptr<HTTPTestServer> server =
- HTTPTestServer::CreateServer(L"", NULL);
- ASSERT_TRUE(NULL != server.get());
- scoped_refptr<URLRequestTestContext> 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.
- {
- TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE);
- context->set_cookie_policy(&cookie_policy);
-
- TestDelegate d;
- URLRequest req(server->TestServerPage(
- "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
- req.set_context(context);
- req.Start();
-
- MessageLoop::current()->Run();
-
- context->set_cookie_policy(NULL);
- }
-
-
- // 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);
- }
-}
-
-TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
- scoped_refptr<HTTPTestServer> server =
- HTTPTestServer::CreateServer(L"", NULL);
- ASSERT_TRUE(NULL != server.get());
- scoped_refptr<URLRequestTestContext> 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.
- {
- TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES |
- TestCookiePolicy::ASYNC);
- context->set_cookie_policy(&cookie_policy);
-
- TestDelegate d;
- TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d);
- req.set_context(context);
- req.Start();
- MessageLoop::current()->Run();
-
- EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
- == std::string::npos);
-
- context->set_cookie_policy(NULL);
- }
-}
-
-TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
- scoped_refptr<HTTPTestServer> server =
- HTTPTestServer::CreateServer(L"", NULL);
- ASSERT_TRUE(NULL != server.get());
- scoped_refptr<URLRequestTestContext> 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.
- {
- TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE |
- TestCookiePolicy::ASYNC);
- context->set_cookie_policy(&cookie_policy);
-
- TestDelegate d;
- URLRequest req(server->TestServerPage(
- "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
- req.set_context(context);
- req.Start();
-
- MessageLoop::current()->Run();
-
- context->set_cookie_policy(NULL);
- }
-
- // 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);
- }
-}
-
-TEST_F(URLRequestTest, CancelTest_DuringCookiePolicy) {
- scoped_refptr<HTTPTestServer> server =
- HTTPTestServer::CreateServer(L"", NULL);
- ASSERT_TRUE(NULL != server.get());
- scoped_refptr<URLRequestTestContext> context = new URLRequestTestContext();
-
- TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC);
- context->set_cookie_policy(&cookie_policy);
-
- // Set up a cookie.
- {
- TestDelegate d;
- URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"),
- &d);
- req.set_context(context);
- req.Start(); // Triggers an asynchronous cookie policy check.
-
- // But, now we cancel the request. This should not cause a crash.
- }
-
- context->set_cookie_policy(NULL);
-}
-
// 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.