summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_unittest.h
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 22:14:15 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 22:14:15 +0000
commit3460228438564690022243511825894c9c600608 (patch)
treebada6636f1a8656ffb8ac481cad1c1d29bddf9f5 /net/url_request/url_request_unittest.h
parente56e96f80ce491b23454a039ae5eba1a1c6ee3f9 (diff)
downloadchromium_src-3460228438564690022243511825894c9c600608.zip
chromium_src-3460228438564690022243511825894c9c600608.tar.gz
chromium_src-3460228438564690022243511825894c9c600608.tar.bz2
Revert 38001 and 38002.
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. 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/564045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38028 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request/url_request_unittest.h')
-rw-r--r--net/url_request/url_request_unittest.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index abd94aa..e912ab9 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -22,6 +22,7 @@
#include "base/time.h"
#include "base/waitable_event.h"
#include "net/base/cookie_monster.h"
+#include "net/base/cookie_policy.h"
#include "net/base/host_resolver.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -45,6 +46,83 @@ const std::string kDefaultHostName("localhost");
using base::TimeDelta;
+//-----------------------------------------------------------------------------
+
+class TestCookiePolicy : public net::CookiePolicy {
+ public:
+ enum Options {
+ NO_GET_COOKIES = 1 << 0,
+ NO_SET_COOKIE = 1 << 1,
+ ASYNC = 1 << 2
+ };
+
+ explicit TestCookiePolicy(int options_bit_mask)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
+ options_(options_bit_mask),
+ callback_(NULL) {
+ }
+
+ virtual int CanGetCookies(const GURL& url, const GURL& first_party,
+ net::CompletionCallback* callback) {
+ if ((options_ & ASYNC) && callback) {
+ callback_ = callback;
+ MessageLoop::current()->PostTask(FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &TestCookiePolicy::DoGetCookiesPolicy, url, first_party));
+ return net::ERR_IO_PENDING;
+ }
+
+ if (options_ & NO_GET_COOKIES)
+ return net::ERR_ACCESS_DENIED;
+
+ return net::OK;
+ }
+
+ virtual int CanSetCookie(const GURL& url, const GURL& first_party,
+ const std::string& cookie_line,
+ net::CompletionCallback* callback) {
+ if ((options_ & ASYNC) && callback) {
+ callback_ = callback;
+ MessageLoop::current()->PostTask(FROM_HERE,
+ method_factory_.NewRunnableMethod(
+ &TestCookiePolicy::DoSetCookiePolicy, url, first_party,
+ cookie_line));
+ return net::ERR_IO_PENDING;
+ }
+
+ if (options_ & NO_SET_COOKIE)
+ return net::ERR_ACCESS_DENIED;
+
+ return net::OK;
+ }
+
+ private:
+ void DoGetCookiesPolicy(const GURL& url, const GURL& first_party) {
+ int policy = CanGetCookies(url, first_party, NULL);
+
+ DCHECK(callback_);
+ net::CompletionCallback* callback = callback_;
+ callback_ = NULL;
+ callback->Run(policy);
+ }
+
+ void DoSetCookiePolicy(const GURL& url, const GURL& first_party,
+ const std::string& cookie_line) {
+ int policy = CanSetCookie(url, first_party, cookie_line, NULL);
+
+ DCHECK(callback_);
+ net::CompletionCallback* callback = callback_;
+ callback_ = NULL;
+ callback->Run(policy);
+ }
+
+ ScopedRunnableMethodFactory<TestCookiePolicy> method_factory_;
+ int options_;
+ net::CompletionCallback* callback_;
+};
+
+//-----------------------------------------------------------------------------
+
class TestURLRequestContext : public URLRequestContext {
public:
TestURLRequestContext() {
@@ -61,6 +139,10 @@ class TestURLRequestContext : public URLRequestContext {
Init();
}
+ void set_cookie_policy(net::CookiePolicy* policy) {
+ cookie_policy_ = policy;
+ }
+
protected:
virtual ~TestURLRequestContext() {
delete ftp_transaction_factory_;
@@ -86,6 +168,8 @@ class TestURLRequestContext : public URLRequestContext {
// TODO(phajdan.jr): Migrate callers to the new name and remove the typedef.
typedef TestURLRequestContext URLRequestTestContext;
+//-----------------------------------------------------------------------------
+
class TestURLRequest : public URLRequest {
public:
TestURLRequest(const GURL& url, Delegate* delegate)
@@ -94,6 +178,8 @@ class TestURLRequest : public URLRequest {
}
};
+//-----------------------------------------------------------------------------
+
class TestDelegate : public URLRequest::Delegate {
public:
TestDelegate()
@@ -261,6 +347,8 @@ class TestDelegate : public URLRequest::Delegate {
scoped_refptr<net::IOBuffer> buf_;
};
+//-----------------------------------------------------------------------------
+
// This object bounds the lifetime of an external python-based HTTP/FTP server
// that can provide various responses useful for testing.
class BaseTestServer : public base::RefCounted<BaseTestServer> {
@@ -372,6 +460,7 @@ class BaseTestServer : public base::RefCounted<BaseTestServer> {
std::string port_str_;
};
+//-----------------------------------------------------------------------------
// HTTP
class HTTPTestServer : public BaseTestServer {
@@ -522,6 +611,8 @@ class HTTPTestServer : public BaseTestServer {
MessageLoop* loop_;
};
+//-----------------------------------------------------------------------------
+
class HTTPSTestServer : public HTTPTestServer {
protected:
explicit HTTPSTestServer() {
@@ -598,6 +689,7 @@ class HTTPSTestServer : public HTTPTestServer {
virtual ~HTTPSTestServer() {}
};
+//-----------------------------------------------------------------------------
class FTPTestServer : public BaseTestServer {
public: