summaryrefslogtreecommitdiffstats
path: root/net/base/static_cookie_policy_unittest.cc
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/base/static_cookie_policy_unittest.cc
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/base/static_cookie_policy_unittest.cc')
-rw-r--r--net/base/static_cookie_policy_unittest.cc104
1 files changed, 56 insertions, 48 deletions
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()));
}