diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 22:14:15 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 22:14:15 +0000 |
commit | 3460228438564690022243511825894c9c600608 (patch) | |
tree | bada6636f1a8656ffb8ac481cad1c1d29bddf9f5 /net/base | |
parent | e56e96f80ce491b23454a039ae5eba1a1c6ee3f9 (diff) | |
download | chromium_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/base')
-rw-r--r-- | net/base/cookie_monster.cc | 77 | ||||
-rw-r--r-- | net/base/cookie_monster.h | 33 | ||||
-rw-r--r-- | net/base/cookie_monster_unittest.cc | 7 | ||||
-rw-r--r-- | net/base/cookie_policy.h | 27 | ||||
-rw-r--r-- | net/base/cookie_store.h | 58 | ||||
-rw-r--r-- | net/base/static_cookie_policy.cc | 32 | ||||
-rw-r--r-- | net/base/static_cookie_policy.h | 40 | ||||
-rw-r--r-- | net/base/static_cookie_policy_unittest.cc | 104 |
8 files changed, 186 insertions, 192 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index 992191c..805bfc1 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -404,44 +404,11 @@ void CookieMonster::SetCookieableSchemes( schemes, schemes + num_schemes); } -bool CookieMonster::SetCookie(const GURL& url, - const std::string& cookie_line) { - CookieOptions options; - return SetCookieWithOptions(url, cookie_line, options); -} - -bool CookieMonster::SetCookieWithOptions(const GURL& url, - const std::string& cookie_line, - const CookieOptions& options) { - Time creation_date; - { - AutoLock autolock(lock_); - creation_date = CurrentTime(); - last_time_seen_ = creation_date; - } - return SetCookieWithCreationTimeWithOptions(url, - cookie_line, - creation_date, - options); -} - -bool CookieMonster::SetCookieWithCreationTime(const GURL& url, - const std::string& cookie_line, - const Time& creation_time) { - CookieOptions options; - return SetCookieWithCreationTimeWithOptions(url, - cookie_line, - creation_time, - options); -} - -bool CookieMonster::SetCookieWithCreationTimeWithOptions( - const GURL& url, - const std::string& cookie_line, - const Time& creation_time, - const CookieOptions& options) { - DCHECK(!creation_time.is_null()); - +bool CookieMonster::SetCookieWithCreationTimeAndOptions( + const GURL& url, + const std::string& cookie_line, + const Time& creation_time_or_null, + const CookieOptions& options) { if (!HasCookieableScheme(url)) { return false; } @@ -451,6 +418,12 @@ bool CookieMonster::SetCookieWithCreationTimeWithOptions( COOKIE_DLOG(INFO) << "SetCookie() line: " << cookie_line; + Time creation_time = creation_time_or_null; + if (creation_time.is_null()) { + creation_time = CurrentTime(); + last_time_seen_ = creation_time; + } + // Parse the cookie. ParsedCookie pc(cookie_line); @@ -508,21 +481,6 @@ bool CookieMonster::SetCookieWithCreationTimeWithOptions( return true; } -void CookieMonster::SetCookies(const GURL& url, - const std::vector<std::string>& cookies) { - CookieOptions options; - SetCookiesWithOptions(url, cookies, options); -} - -void CookieMonster::SetCookiesWithOptions( - const GURL& url, - const std::vector<std::string>& cookies, - const CookieOptions& options) { - for (std::vector<std::string>::const_iterator iter = cookies.begin(); - iter != cookies.end(); ++iter) - SetCookieWithOptions(url, *iter, options); -} - void CookieMonster::InternalInsertCookie(const std::string& key, CanonicalCookie* cc, bool sync_to_store) { @@ -736,6 +694,12 @@ static bool CookieSorter(CookieMonster::CanonicalCookie* cc1, return cc1->Path().length() > cc2->Path().length(); } +bool CookieMonster::SetCookieWithOptions(const GURL& url, + const std::string& cookie_line, + const CookieOptions& options) { + return SetCookieWithCreationTimeAndOptions(url, cookie_line, Time(), options); +} + // Currently our cookie datastructure is based on Mozilla's approach. We have a // hash keyed on the cookie's domain, and for any query we walk down the domain // components and probe for cookies until we reach the TLD, where we stop. @@ -748,11 +712,6 @@ static bool CookieSorter(CookieMonster::CanonicalCookie* cc1, // search/prefix trie, where we reverse the hostname and query for all // keys that are a prefix of our hostname. I think the hash probing // should be fast and simple enough for now. -std::string CookieMonster::GetCookies(const GURL& url) { - CookieOptions options; - return GetCookiesWithOptions(url, options); -} - std::string CookieMonster::GetCookiesWithOptions(const GURL& url, const CookieOptions& options) { if (!HasCookieableScheme(url)) { @@ -834,7 +793,7 @@ CookieMonster::CookieList CookieMonster::GetAllCookies() { return cookie_list; } -CookieMonster::CookieList CookieMonster::GetRawCookies(const GURL& url) { +CookieMonster::CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { AutoLock autolock(lock_); InitIfNecessary(); diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index 6976f7f..7578c46 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -73,30 +73,25 @@ class CookieMonster : public CookieStore { static base::Time ParseCookieTime(const std::string& time_string); // CookieStore implementation. - virtual bool SetCookie(const GURL& url, const std::string& cookie_line); virtual bool SetCookieWithOptions(const GURL& url, const std::string& cookie_line, const CookieOptions& options); - virtual bool SetCookieWithCreationTime(const GURL& url, - const std::string& cookie_line, - const base::Time& creation_time); - virtual bool SetCookieWithCreationTimeWithOptions( - const GURL& url, - const std::string& cookie_line, - const base::Time& creation_time, - const CookieOptions& options); - virtual void SetCookies(const GURL& url, - const std::vector<std::string>& cookies); - virtual void SetCookiesWithOptions(const GURL& url, - const std::vector<std::string>& cookies, - const CookieOptions& options); - virtual std::string GetCookies(const GURL& url); virtual std::string GetCookiesWithOptions(const GURL& url, const CookieOptions& options); virtual void DeleteCookie(const GURL& url, const std::string& cookie_name); - - virtual CookieMonster* GetCookieMonster() { - return this; + virtual CookieMonster* GetCookieMonster() { return this; } + + + // Exposed for unit testing. + bool SetCookieWithCreationTimeAndOptions(const GURL& url, + const std::string& cookie_line, + const base::Time& creation_time, + const CookieOptions& options); + bool SetCookieWithCreationTime(const GURL& url, + const std::string& cookie_line, + const base::Time& creation_time) { + return SetCookieWithCreationTimeAndOptions(url, cookie_line, creation_time, + CookieOptions()); } // Returns all the cookies, for use in management UI, etc. This does not mark @@ -106,7 +101,7 @@ class CookieMonster : public CookieStore { // Returns all the cookies, for use in management UI, etc. Filters results // using given url scheme and host / domain. This does not mark the cookies // as having been accessed. - CookieList GetRawCookies(const GURL& url); + CookieList GetAllCookiesForURL(const GURL& url); // Delete all of the cookies. int DeleteAll(bool sync_to_store); diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc index ba645ee..cdbf869 100644 --- a/net/base/cookie_monster_unittest.cc +++ b/net/base/cookie_monster_unittest.cc @@ -961,7 +961,7 @@ TEST(CookieMonsterTest, SetCookieableSchemes) { EXPECT_FALSE(cm_foo->SetCookie(http_url, "x=1")); } -TEST(CookieMonsterTest, GetRawCookies) { +TEST(CookieMonsterTest, GetAllCookiesForURL) { GURL url_google(kUrlGoogle); GURL url_google_secure(kUrlGoogleSecure); @@ -985,7 +985,8 @@ TEST(CookieMonsterTest, GetRawCookies) { PlatformThread::Sleep(kLastAccessThresholdMilliseconds + 20); // Check raw cookies. - net::CookieMonster::CookieList raw_cookies = cm->GetRawCookies(url_google); + net::CookieMonster::CookieList raw_cookies = + cm->GetAllCookiesForURL(url_google); net::CookieMonster::CookieList::iterator it = raw_cookies.begin(); ASSERT_TRUE(it != raw_cookies.end()); @@ -999,7 +1000,7 @@ TEST(CookieMonsterTest, GetRawCookies) { ASSERT_TRUE(++it == raw_cookies.end()); // Test secure cookies. - raw_cookies = cm->GetRawCookies(url_google_secure); + raw_cookies = cm->GetAllCookiesForURL(url_google_secure); it = raw_cookies.begin(); ASSERT_TRUE(it != raw_cookies.end()); diff --git a/net/base/cookie_policy.h b/net/base/cookie_policy.h index 91bbfb9..d2df2f5 100644 --- a/net/base/cookie_policy.h +++ b/net/base/cookie_policy.h @@ -5,19 +5,32 @@ #ifndef NET_BASE_COOKIE_POLICY_H_ #define NET_BASE_COOKIE_POLICY_H_ +#include "net/base/completion_callback.h" + class GURL; namespace net { class CookiePolicy { public: - // Determine if the URL's cookies may be read. - virtual bool CanGetCookies(const GURL& url, - const GURL& first_party_for_cookies) = 0; - - // Determine if the URL's cookies may be written. - virtual bool CanSetCookie(const GURL& url, - const GURL& first_party_for_cookies) = 0; + // Determines if the URL's cookies may be read. Returns OK if allowed to + // read cookies for the given URL. Returns ERR_IO_PENDING to indicate that + // the completion callback will be notified (asynchronously and on the + // current thread) of the final result. Note: The completion callback must + // remain valid until notified. + virtual int CanGetCookies(const GURL& url, + const GURL& first_party_for_cookies, + CompletionCallback* callback) = 0; + + // Determines if the URL's cookies may be written. Returns OK if allowed to + // write a cookie for the given URL. Returns ERR_IO_PENDING to indicate that + // the completion callback will be notified (asynchronously and on the + // current thread) of the final result. Note: The completion callback must + // remain valid until notified. + virtual int CanSetCookie(const GURL& url, + const GURL& first_party_for_cookies, + const std::string& cookie_line, + CompletionCallback* callback) = 0; protected: virtual ~CookiePolicy() {} diff --git a/net/base/cookie_store.h b/net/base/cookie_store.h index 1ea3fa2..2fbe1d8 100644 --- a/net/base/cookie_store.h +++ b/net/base/cookie_store.h @@ -24,45 +24,51 @@ class CookieMonster; // be thread safe as its methods can be accessed from IO as well as UI threads. class CookieStore : public base::RefCountedThreadSafe<CookieStore> { public: - // Set a single cookie. Expects a cookie line, like "a=1; domain=b.com". - virtual bool SetCookie(const GURL& url, const std::string& cookie_line) = 0; + // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com". virtual bool SetCookieWithOptions(const GURL& url, const std::string& cookie_line, const CookieOptions& options) = 0; - // Sets a single cookie with a specific creation date. To set a cookie with - // a creation date of Now() use SetCookie() instead (it calls this function - // internally). - virtual bool SetCookieWithCreationTime(const GURL& url, - const std::string& cookie_line, - const base::Time& creation_time) = 0; - virtual bool SetCookieWithCreationTimeWithOptions( - const GURL& url, - const std::string& cookie_line, - const base::Time& creation_time, - const CookieOptions& options) = 0; - // Set a vector of response cookie values for the same URL. - virtual void SetCookies(const GURL& url, - const std::vector<std::string>& cookies) = 0; - virtual void SetCookiesWithOptions(const GURL& url, - const std::vector<std::string>& cookies, - const CookieOptions& options) = 0; // TODO what if the total size of all the cookies >4k, can we have a header // that big or do we need multiple Cookie: headers? - // Simple interface, get a cookie string "a=b; c=d" for the given URL. - // It will _not_ return httponly cookies, see CookieOptions. - virtual std::string GetCookies(const GURL& url) = 0; + // Simple interface, gets a cookie string "a=b; c=d" for the given URL. + // Use options to access httponly cookies. virtual std::string GetCookiesWithOptions(const GURL& url, const CookieOptions& options) = 0; - virtual CookieMonster* GetCookieMonster() { - return NULL; - }; - // Deletes the passed in cookie for the specified URL. virtual void DeleteCookie(const GURL& url, const std::string& cookie_name) = 0; + // Returns the underlying CookieMonster. + virtual CookieMonster* GetCookieMonster() = 0; + + + // -------------------------------------------------------------------------- + // Helpers to make the above interface simpler for some cases. + + // Sets a cookie for the given URL using default options. + bool SetCookie(const GURL& url, const std::string& cookie_line) { + return SetCookieWithOptions(url, cookie_line, CookieOptions()); + } + + // Gets cookies for the given URL using default options. + std::string GetCookies(const GURL& url) { + return GetCookiesWithOptions(url, CookieOptions()); + } + + // Sets a vector of response cookie values for the same URL. + void SetCookiesWithOptions(const GURL& url, + const std::vector<std::string>& cookie_lines, + const CookieOptions& options) { + for (size_t i = 0; i < cookie_lines.size(); ++i) + SetCookieWithOptions(url, cookie_lines[i], options); + } + void SetCookies(const GURL& url, + const std::vector<std::string>& cookie_lines) { + SetCookiesWithOptions(url, cookie_lines, CookieOptions()); + } + protected: friend class base::RefCountedThreadSafe<CookieStore>; virtual ~CookieStore() {} diff --git a/net/base/static_cookie_policy.cc b/net/base/static_cookie_policy.cc index 25d58bc..0ff6ead 100644 --- a/net/base/static_cookie_policy.cc +++ b/net/base/static_cookie_policy.cc @@ -6,40 +6,44 @@ #include "base/logging.h" #include "googleurl/src/gurl.h" +#include "net/base/net_errors.h" #include "net/base/registry_controlled_domain.h" namespace net { -bool StaticCookiePolicy::CanGetCookies(const GURL& url, - const GURL& first_party_for_cookies) { +int StaticCookiePolicy::CanGetCookies(const GURL& url, + const GURL& first_party_for_cookies, + CompletionCallback* callback) { switch (type_) { case StaticCookiePolicy::ALLOW_ALL_COOKIES: - return true; + return OK; case StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES: - return true; + return OK; case StaticCookiePolicy::BLOCK_ALL_COOKIES: - return false; + return ERR_ACCESS_DENIED; default: NOTREACHED(); - return false; + return ERR_ACCESS_DENIED; } } -bool StaticCookiePolicy::CanSetCookie(const GURL& url, - const GURL& first_party_for_cookies) { +int StaticCookiePolicy::CanSetCookie(const GURL& url, + const GURL& first_party_for_cookies, + const std::string& cookie_line, + CompletionCallback* callback) { switch (type_) { case StaticCookiePolicy::ALLOW_ALL_COOKIES: - return true; + return OK; case StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES: if (first_party_for_cookies.is_empty()) - return true; // Empty first-party URL indicates a first-party request. - return net::RegistryControlledDomainService::SameDomainOrHost( - url, first_party_for_cookies); + return OK; // Empty first-party URL indicates a first-party request. + return RegistryControlledDomainService::SameDomainOrHost( + url, first_party_for_cookies) ? OK : ERR_ACCESS_DENIED; case StaticCookiePolicy::BLOCK_ALL_COOKIES: - return false; + return ERR_ACCESS_DENIED; default: NOTREACHED(); - return false; + return ERR_ACCESS_DENIED; } } diff --git a/net/base/static_cookie_policy.h b/net/base/static_cookie_policy.h index a16fd0c..4734d33 100644 --- a/net/base/static_cookie_policy.h +++ b/net/base/static_cookie_policy.h @@ -14,30 +14,18 @@ namespace net { // The StaticCookiePolicy class implements a static cookie policy that supports // three modes: allow all, deny all, or block third-party cookies. +// +// NOTE: This CookiePolicy implementation always completes synchronously. The +// callback parameter will be ignored if specified. Just pass NULL. +// class StaticCookiePolicy : public CookiePolicy { public: - // Consult the user's third-party cookie blocking preferences to determine - // whether the URL's cookies can be read. - bool CanGetCookies(const GURL& url, const GURL& first_party_for_cookies); - - // Consult the user's third-party cookie blocking preferences to determine - // whether the URL's cookies can be set. - bool CanSetCookie(const GURL& url, const GURL& first_party_for_cookies); - enum Type { ALLOW_ALL_COOKIES = 0, // Do not perform any cookie blocking. BLOCK_THIRD_PARTY_COOKIES, // Prevent third-party cookies from being set. BLOCK_ALL_COOKIES // Disable cookies. }; - // Sets the current policy to enforce. This should be called when the user's - // preferences change. - void set_type(Type type) { type_ = type; } - - Type type() const { - return type_; - } - StaticCookiePolicy() : type_(StaticCookiePolicy::ALLOW_ALL_COOKIES) { } @@ -46,6 +34,26 @@ class StaticCookiePolicy : public CookiePolicy { : type_(type) { } + // Sets the current policy to enforce. This should be called when the user's + // preferences change. + void set_type(Type type) { type_ = type; } + Type type() const { return type_; } + + // CookiePolicy methods: + + // Consults the user's third-party cookie blocking preferences to determine + // whether the URL's cookies can be read. + virtual int CanGetCookies(const GURL& url, + const GURL& first_party_for_cookies, + CompletionCallback* callback); + + // Consults the user's third-party cookie blocking preferences to determine + // whether the URL's cookies can be set. + virtual int CanSetCookie(const GURL& url, + const GURL& first_party_for_cookies, + const std::string& cookie_line, + CompletionCallback* callback); + private: Type type_; diff --git a/net/base/static_cookie_policy_unittest.cc b/net/base/static_cookie_policy_unittest.cc index 35af0fc..35c1a82 100644 --- a/net/base/static_cookie_policy_unittest.cc +++ b/net/base/static_cookie_policy_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "net/base/net_errors.h" #include "net/base/static_cookie_policy.h" #include "testing/gtest/include/gtest/gtest.h" #include "googleurl/src/gurl.h" @@ -12,8 +13,19 @@ class StaticCookiePolicyTest : public testing::Test { : url_google_("http://www.google.izzle"), url_google_secure_("https://www.google.izzle"), url_google_mail_("http://mail.google.izzle"), - url_google_analytics_("http://www.googleanalytics.izzle") { } + url_google_analytics_("http://www.googleanalytics.izzle") { + } + void SetPolicyType(net::StaticCookiePolicy::Type type) { + policy_.set_type(type); + } + int CanGetCookies(const GURL& url, const GURL& first_party) { + return policy_.CanGetCookies(url, first_party, NULL); + } + int CanSetCookie(const GURL& url, const GURL& first_party) { + return policy_.CanSetCookie(url, first_party, std::string(), NULL); + } protected: + net::StaticCookiePolicy policy_; GURL url_google_; GURL url_google_secure_; GURL url_google_mail_; @@ -21,67 +33,63 @@ class StaticCookiePolicyTest : public testing::Test { }; TEST_F(StaticCookiePolicyTest, DefaultPolicyTest) { - net::StaticCookiePolicy cp; - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_secure_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_mail_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_analytics_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, GURL())); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_secure_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_mail_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_analytics_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, GURL())); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_secure_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_mail_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_analytics_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, GURL())); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_secure_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_mail_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_analytics_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, GURL())); } TEST_F(StaticCookiePolicyTest, AllowAllCookiesTest) { - net::StaticCookiePolicy cp; - cp.set_type(net::StaticCookiePolicy::ALLOW_ALL_COOKIES); + SetPolicyType(net::StaticCookiePolicy::ALLOW_ALL_COOKIES); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_secure_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_mail_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_analytics_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, GURL())); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_secure_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_mail_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_analytics_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, GURL())); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_secure_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_mail_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_analytics_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, GURL())); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_secure_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_mail_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_analytics_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, GURL())); } TEST_F(StaticCookiePolicyTest, BlockThirdPartyCookiesTest) { - net::StaticCookiePolicy cp; - cp.set_type(net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES); + SetPolicyType(net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_secure_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_mail_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, url_google_analytics_)); - EXPECT_TRUE(cp.CanGetCookies(url_google_, GURL())); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_secure_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_mail_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, url_google_analytics_)); + EXPECT_EQ(net::OK, CanGetCookies(url_google_, GURL())); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_secure_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, url_google_mail_)); - EXPECT_FALSE(cp.CanSetCookie(url_google_, url_google_analytics_)); - EXPECT_TRUE(cp.CanSetCookie(url_google_, GURL())); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_secure_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, url_google_mail_)); + EXPECT_NE(net::OK, CanSetCookie(url_google_, url_google_analytics_)); + EXPECT_EQ(net::OK, CanSetCookie(url_google_, GURL())); } TEST_F(StaticCookiePolicyTest, BlockAllCookiesTest) { - net::StaticCookiePolicy cp; - cp.set_type(net::StaticCookiePolicy::BLOCK_ALL_COOKIES); + SetPolicyType(net::StaticCookiePolicy::BLOCK_ALL_COOKIES); - EXPECT_FALSE(cp.CanGetCookies(url_google_, url_google_)); - EXPECT_FALSE(cp.CanGetCookies(url_google_, url_google_secure_)); - EXPECT_FALSE(cp.CanGetCookies(url_google_, url_google_mail_)); - EXPECT_FALSE(cp.CanGetCookies(url_google_, url_google_analytics_)); - EXPECT_FALSE(cp.CanGetCookies(url_google_, GURL())); + EXPECT_NE(net::OK, CanGetCookies(url_google_, url_google_)); + EXPECT_NE(net::OK, CanGetCookies(url_google_, url_google_secure_)); + EXPECT_NE(net::OK, CanGetCookies(url_google_, url_google_mail_)); + EXPECT_NE(net::OK, CanGetCookies(url_google_, url_google_analytics_)); + EXPECT_NE(net::OK, CanGetCookies(url_google_, GURL())); - EXPECT_FALSE(cp.CanSetCookie(url_google_, url_google_)); - EXPECT_FALSE(cp.CanSetCookie(url_google_, url_google_secure_)); - EXPECT_FALSE(cp.CanSetCookie(url_google_, url_google_mail_)); - EXPECT_FALSE(cp.CanSetCookie(url_google_, url_google_analytics_)); - EXPECT_FALSE(cp.CanSetCookie(url_google_, GURL())); + EXPECT_NE(net::OK, CanSetCookie(url_google_, url_google_)); + EXPECT_NE(net::OK, CanSetCookie(url_google_, url_google_secure_)); + EXPECT_NE(net::OK, CanSetCookie(url_google_, url_google_mail_)); + EXPECT_NE(net::OK, CanSetCookie(url_google_, url_google_analytics_)); + EXPECT_NE(net::OK, CanSetCookie(url_google_, GURL())); } |