Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Unified Diff: net/base/cookie_monster_unittest.cc

Issue 7598001: Remove the old synchronous CookieMonster API. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/cookie_monster_unittest.cc
===================================================================
--- net/base/cookie_monster_unittest.cc (revision 96178)
+++ net/base/cookie_monster_unittest.cc (working copy)
@@ -499,9 +499,9 @@
std::string GetCookies(CookieMonster* cm, const GURL& url) {
DCHECK(cm);
GetCookieStringCallback callback;
- cm->GetCookiesAsync(
- url, base::Bind(&GetCookieStringCallback::Run,
- base::Unretained(&callback)));
+ cm->GetCookiesWithOptionsAsync(
+ url, CookieOptions(), base::Bind(&GetCookieStringCallback::Run,
+ base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.cookie();
@@ -589,6 +589,13 @@
return callback.result();
}
+ bool SetCookie(CookieMonster* cm,
+ const GURL& url,
+ const std::string& cookie_line) {
+ CookieOptions options;
+ return SetCookieWithOptions(cm, url, cookie_line, options);
+ }
+
bool SetCookieWithDetails(CookieMonster* cm,
const GURL& url,
const std::string& name,
@@ -619,14 +626,23 @@
EXPECT_TRUE(callback.did_run());
}
+ int DeleteAll(CookieMonster*cm) {
+ DCHECK(cm);
+ DeleteCallback callback;
+ cm->DeleteAllAsync(
+ base::Bind(&DeleteCallback::Run, base::Unretained(&callback)));
+ RunFor(kTimeout);
+ EXPECT_TRUE(callback.did_run());
+ return callback.num_deleted();
+ }
+
int DeleteAllCreatedBetween(CookieMonster*cm,
const base::Time& delete_begin,
- const base::Time& delete_end,
- bool sync_to_store) {
+ const base::Time& delete_end) {
DCHECK(cm);
DeleteCallback callback;
cm->DeleteAllCreatedBetweenAsync(
- delete_begin, delete_end, sync_to_store,
+ delete_begin, delete_end,
base::Bind(&DeleteCallback::Run, base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
@@ -675,7 +691,7 @@
GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3);
GURL url_other(kOtherDomain);
- cm->DeleteAll(true);
+ DeleteAll(cm);
// Static population for probe:
// * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a)
@@ -778,7 +794,7 @@
cm->SetExpiryAndKeyScheme(key_scheme);
for (int i = 0; i < more_than_enough_cookies; ++i) {
std::string cookie = base::StringPrintf("a%03d=b", i);
- EXPECT_TRUE(cm->SetCookie(url_google_, cookie));
+ EXPECT_TRUE(SetCookie(cm, url_google_, cookie));
std::string cookies = this->GetCookies(cm, url_google_);
// Make sure we find it in the cookies.
EXPECT_NE(cookies.find(cookie), std::string::npos);
@@ -800,9 +816,9 @@
cm->SetExpiryAndKeyScheme(key_scheme);
for (int i = 0; i < more_than_enough_cookies; ++i) {
std::string cookie_general = base::StringPrintf("a%03d=b", i);
- EXPECT_TRUE(cm->SetCookie(url_google_, cookie_general));
+ EXPECT_TRUE(SetCookie(cm, url_google_, cookie_general));
std::string cookie_specific = base::StringPrintf("c%03d=b", i);
- EXPECT_TRUE(cm->SetCookie(url_google_specific, cookie_specific));
+ EXPECT_TRUE(SetCookie(cm, url_google_specific, cookie_specific));
std::string cookies_general = this->GetCookies(cm, url_google_);
EXPECT_NE(cookies_general.find(cookie_general), std::string::npos);
std::string cookies_specific =
@@ -840,6 +856,16 @@
}
}
+ // Function for creating a CM with a number of cookies in it,
+ // no store (and hence no ability to affect access time).
+ CookieMonster* CreateMonsterForGC(int num_cookies) {
+ CookieMonster* cm(new CookieMonster(NULL, NULL));
+ for (int i = 0; i < num_cookies; i++) {
+ SetCookie(cm, GURL(StringPrintf("http://h%05d.izzle", i)), "a=1");
+ }
+ return cm;
+ }
+
protected:
GURL url_google_;
GURL url_google_secure_;
@@ -855,9 +881,9 @@
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
- EXPECT_TRUE(cm->SetCookie(url_google_, "C=D; domain=.google.izzle"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "C=D; domain=.google.izzle"));
EXPECT_EQ("A=B; C=D", GetCookies(cm, url_google_));
// Verify that A=B was set as a host cookie rather than a domain
@@ -865,18 +891,18 @@
EXPECT_EQ("C=D", GetCookies(cm, GURL("http://foo.www.google.izzle")));
// Test and make sure we find domain cookies on the same domain.
- EXPECT_TRUE(cm->SetCookie(url_google_, "E=F; domain=.www.google.izzle"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "E=F; domain=.www.google.izzle"));
EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_));
// Test setting a domain= that doesn't start w/ a dot, should
// treat it as a domain cookie, as if there was a pre-pended dot.
- EXPECT_TRUE(cm->SetCookie(url_google_, "G=H; domain=www.google.izzle"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "G=H; domain=www.google.izzle"));
EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_));
// Test domain enforcement, should fail on a sub-domain or something too deep.
- EXPECT_FALSE(cm->SetCookie(url_google_, "I=J; domain=.izzle"));
+ EXPECT_FALSE(SetCookie(cm, url_google_, "I=J; domain=.izzle"));
EXPECT_EQ("", GetCookies(cm, GURL("http://a.izzle")));
- EXPECT_FALSE(cm->SetCookie(url_google_, "K=L; domain=.bla.www.google.izzle"));
+ EXPECT_FALSE(SetCookie(cm, url_google_, "K=L; domain=.bla.www.google.izzle"));
EXPECT_EQ("C=D; E=F; G=H",
GetCookies(cm, GURL("http://bla.www.google.izzle")));
EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_));
@@ -891,8 +917,8 @@
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL));
- EXPECT_FALSE(cm->SetCookie(url_google_, "a=1; domain=.www.google.com."));
- EXPECT_FALSE(cm->SetCookie(url_google_, "b=2; domain=.www.google.com.."));
+ EXPECT_FALSE(SetCookie(cm, url_google_, "a=1; domain=.www.google.com."));
+ EXPECT_FALSE(SetCookie(cm, url_google_, "b=2; domain=.www.google.com.."));
EXPECT_EQ("", GetCookies(cm, url_google_));
// Nothing was persisted to the backing store.
@@ -910,10 +936,10 @@
GURL url_cd("http://c.d.com");
GURL url_d("http://d.com");
- EXPECT_TRUE(cm->SetCookie(url_abcd, "a=1; domain=.a.b.c.d.com"));
- EXPECT_TRUE(cm->SetCookie(url_abcd, "b=2; domain=.b.c.d.com"));
- EXPECT_TRUE(cm->SetCookie(url_abcd, "c=3; domain=.c.d.com"));
- EXPECT_TRUE(cm->SetCookie(url_abcd, "d=4; domain=.d.com"));
+ EXPECT_TRUE(SetCookie(cm, url_abcd, "a=1; domain=.a.b.c.d.com"));
+ EXPECT_TRUE(SetCookie(cm, url_abcd, "b=2; domain=.b.c.d.com"));
+ EXPECT_TRUE(SetCookie(cm, url_abcd, "c=3; domain=.c.d.com"));
+ EXPECT_TRUE(SetCookie(cm, url_abcd, "d=4; domain=.d.com"));
EXPECT_EQ("a=1; b=2; c=3; d=4", GetCookies(cm, url_abcd));
EXPECT_EQ("b=2; c=3; d=4", GetCookies(cm, url_bcd));
@@ -921,8 +947,8 @@
EXPECT_EQ("d=4", GetCookies(cm, url_d));
// Check that the same cookie can exist on different sub-domains.
- EXPECT_TRUE(cm->SetCookie(url_bcd, "X=bcd; domain=.b.c.d.com"));
- EXPECT_TRUE(cm->SetCookie(url_bcd, "X=cd; domain=.c.d.com"));
+ EXPECT_TRUE(SetCookie(cm, url_bcd, "X=bcd; domain=.b.c.d.com"));
+ EXPECT_TRUE(SetCookie(cm, url_bcd, "X=cd; domain=.c.d.com"));
EXPECT_EQ("b=2; c=3; d=4; X=bcd; X=cd", GetCookies(cm, url_bcd));
EXPECT_EQ("c=3; d=4; X=cd", GetCookies(cm, url_cd));
@@ -943,31 +969,31 @@
GURL url_foobar("http://foo.bar.com");
// More specific sub-domain than allowed.
- EXPECT_FALSE(cm->SetCookie(url_foobar, "a=1; domain=.yo.foo.bar.com"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "a=1; domain=.yo.foo.bar.com"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "b=2; domain=.foo.com"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "c=3; domain=.bar.foo.com"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "b=2; domain=.foo.com"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "c=3; domain=.bar.foo.com"));
// Different TLD, but the rest is a substring.
- EXPECT_FALSE(cm->SetCookie(url_foobar, "d=4; domain=.foo.bar.com.net"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "d=4; domain=.foo.bar.com.net"));
// A substring that isn't really a parent domain.
- EXPECT_FALSE(cm->SetCookie(url_foobar, "e=5; domain=ar.com"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "e=5; domain=ar.com"));
// Completely invalid domains:
- EXPECT_FALSE(cm->SetCookie(url_foobar, "f=6; domain=."));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "g=7; domain=/"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "h=8; domain=http://foo.bar.com"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "i=9; domain=..foo.bar.com"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "j=10; domain=..bar.com"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "f=6; domain=."));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "g=7; domain=/"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "h=8; domain=http://foo.bar.com"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "i=9; domain=..foo.bar.com"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "j=10; domain=..bar.com"));
// Make sure there isn't something quirky in the domain canonicalization
// that supports full URL semantics.
- EXPECT_FALSE(cm->SetCookie(url_foobar, "k=11; domain=.foo.bar.com?blah"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "l=12; domain=.foo.bar.com/blah"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "m=13; domain=.foo.bar.com:80"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "n=14; domain=.foo.bar.com:"));
- EXPECT_FALSE(cm->SetCookie(url_foobar, "o=15; domain=.foo.bar.com#sup"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "k=11; domain=.foo.bar.com?blah"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "l=12; domain=.foo.bar.com/blah"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "m=13; domain=.foo.bar.com:80"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "n=14; domain=.foo.bar.com:"));
+ EXPECT_FALSE(SetCookie(cm, url_foobar, "o=15; domain=.foo.bar.com#sup"));
EXPECT_EQ("", GetCookies(cm, url_foobar));
@@ -981,7 +1007,7 @@
// hosts below have the same domain + registry.
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url_foocom("http://foo.com.com");
- EXPECT_FALSE(cm->SetCookie(url_foocom, "a=1; domain=.foo.com.com.com"));
+ EXPECT_FALSE(SetCookie(cm, url_foocom, "a=1; domain=.foo.com.com.com"));
EXPECT_EQ("", GetCookies(cm, url_foocom));
}
}
@@ -994,7 +1020,7 @@
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url_hosted("http://manage.hosted.filefront.com");
GURL url_filefront("http://www.filefront.com");
- EXPECT_TRUE(cm->SetCookie(url_hosted, "sawAd=1; domain=filefront.com"));
+ EXPECT_TRUE(SetCookie(cm, url_hosted, "sawAd=1; domain=filefront.com"));
EXPECT_EQ("sawAd=1", GetCookies(cm, url_hosted));
EXPECT_EQ("sawAd=1", GetCookies(cm, url_filefront));
}
@@ -1002,7 +1028,7 @@
{ // Even when the domains match exactly, don't consider it host cookie.
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://www.google.com");
- EXPECT_TRUE(cm->SetCookie(url, "a=1; domain=www.google.com"));
+ EXPECT_TRUE(SetCookie(cm, url, "a=1; domain=www.google.com"));
EXPECT_EQ("a=1", GetCookies(cm, url));
EXPECT_EQ("a=1", GetCookies(cm, GURL("http://sub.www.google.com")));
EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.com")));
@@ -1014,8 +1040,8 @@
TEST_F(CookieMonsterTest, CaseInsensitiveDomainTest) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://www.google.com");
- EXPECT_TRUE(cm->SetCookie(url, "a=1; domain=.GOOGLE.COM"));
- EXPECT_TRUE(cm->SetCookie(url, "b=2; domain=.wWw.gOOgLE.coM"));
+ EXPECT_TRUE(SetCookie(cm, url, "a=1; domain=.GOOGLE.COM"));
+ EXPECT_TRUE(SetCookie(cm, url, "b=2; domain=.wWw.gOOgLE.coM"));
EXPECT_EQ("a=1; b=2", GetCookies(cm, url));
}
@@ -1023,20 +1049,20 @@
GURL url_ip("http://1.2.3.4/weee");
{
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(url_ip, kValidCookieLine));
+ EXPECT_TRUE(SetCookie(cm, url_ip, kValidCookieLine));
EXPECT_EQ("A=B", GetCookies(cm, url_ip));
}
{ // IP addresses should not be able to set domain cookies.
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_FALSE(cm->SetCookie(url_ip, "b=2; domain=.1.2.3.4"));
- EXPECT_FALSE(cm->SetCookie(url_ip, "c=3; domain=.3.4"));
+ EXPECT_FALSE(SetCookie(cm, url_ip, "b=2; domain=.1.2.3.4"));
+ EXPECT_FALSE(SetCookie(cm, url_ip, "c=3; domain=.3.4"));
EXPECT_EQ("", GetCookies(cm, url_ip));
// It should be allowed to set a cookie if domain= matches the IP address
// exactly. This matches IE/Firefox, even though it seems a bit wrong.
- EXPECT_FALSE(cm->SetCookie(url_ip, "b=2; domain=1.2.3.3"));
+ EXPECT_FALSE(SetCookie(cm, url_ip, "b=2; domain=1.2.3.3"));
EXPECT_EQ("", GetCookies(cm, url_ip));
- EXPECT_TRUE(cm->SetCookie(url_ip, "b=2; domain=1.2.3.4"));
+ EXPECT_TRUE(SetCookie(cm, url_ip, "b=2; domain=1.2.3.4"));
EXPECT_EQ("b=2", GetCookies(cm, url_ip));
}
}
@@ -1047,9 +1073,9 @@
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://com/");
// Allow setting on "com", (but only as a host cookie).
- EXPECT_TRUE(cm->SetCookie(url, "a=1"));
- EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.com"));
- EXPECT_FALSE(cm->SetCookie(url, "c=3; domain=com"));
+ EXPECT_TRUE(SetCookie(cm, url, "a=1"));
+ EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.com"));
+ EXPECT_FALSE(SetCookie(cm, url, "c=3; domain=com"));
EXPECT_EQ("a=1", GetCookies(cm, url));
// Make sure it doesn't show up for a normal .com, it should be a host
// not a domain cookie.
@@ -1060,7 +1086,7 @@
{ // http://com. should be treated the same as http://com.
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://com./index.html");
- EXPECT_TRUE(cm->SetCookie(url, "a=1"));
+ EXPECT_TRUE(SetCookie(cm, url, "a=1"));
EXPECT_EQ("a=1", GetCookies(cm, url));
EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com./")));
}
@@ -1068,24 +1094,24 @@
{ // Should not be able to set host cookie from a subdomain.
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://a.b");
- EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.b"));
- EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=b"));
+ EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.b"));
+ EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=b"));
EXPECT_EQ("", GetCookies(cm, url));
}
{ // Same test as above, but explicitly on a known TLD (com).
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://google.com");
- EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.com"));
- EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=com"));
+ EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.com"));
+ EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=com"));
EXPECT_EQ("", GetCookies(cm, url));
}
{ // Make sure can't set cookie on TLD which is dotted.
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://google.co.uk");
- EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.co.uk"));
- EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.uk"));
+ EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.co.uk"));
+ EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.uk"));
EXPECT_EQ("", GetCookies(cm, url));
EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.co.uk")));
EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.uk")));
@@ -1094,9 +1120,9 @@
{ // Intranet URLs should only be able to set host cookies.
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://b");
- EXPECT_TRUE(cm->SetCookie(url, "a=1"));
- EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.b"));
- EXPECT_FALSE(cm->SetCookie(url, "c=3; domain=b"));
+ EXPECT_TRUE(SetCookie(cm, url, "a=1"));
+ EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.b"));
+ EXPECT_FALSE(SetCookie(cm, url, "c=3; domain=b"));
EXPECT_EQ("a=1", GetCookies(cm, url));
}
}
@@ -1107,15 +1133,15 @@
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
GURL url("http://www.google.com");
GURL url_with_dot("http://www.google.com.");
- EXPECT_TRUE(cm->SetCookie(url, "a=1"));
+ EXPECT_TRUE(SetCookie(cm, url, "a=1"));
EXPECT_EQ("a=1", GetCookies(cm, url));
// Do not share cookie space with the dot version of domain.
// Note: this is not what FireFox does, but it _is_ what IE+Safari do.
- EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.www.google.com."));
+ EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.www.google.com."));
EXPECT_EQ("a=1", GetCookies(cm, url));
- EXPECT_TRUE(cm->SetCookie(url_with_dot, "b=2; domain=.google.com."));
+ EXPECT_TRUE(SetCookie(cm, url_with_dot, "b=2; domain=.google.com."));
EXPECT_EQ("b=2", GetCookies(cm, url_with_dot));
// Make sure there weren't any side effects.
@@ -1125,19 +1151,19 @@
TEST_F(CookieMonsterTest, InvalidScheme) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_FALSE(cm->SetCookie(GURL(kUrlFtp), kValidCookieLine));
+ EXPECT_FALSE(SetCookie(cm, GURL(kUrlFtp), kValidCookieLine));
}
TEST_F(CookieMonsterTest, InvalidScheme_Read) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(GURL(kUrlGoogle), kValidDomainCookieLine));
+ EXPECT_TRUE(SetCookie(cm, GURL(kUrlGoogle), kValidDomainCookieLine));
EXPECT_EQ("", GetCookies(cm, GURL(kUrlFtp)));
}
TEST_F(CookieMonsterTest, PathTest) {
std::string url("http://www.google.izzle");
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(GURL(url), "A=B; path=/wee"));
+ EXPECT_TRUE(SetCookie(cm, GURL(url), "A=B; path=/wee"));
EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee")));
EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/")));
EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war")));
@@ -1146,7 +1172,7 @@
EXPECT_EQ("", GetCookies(cm, GURL(url + "/")));
// If we add a 0 length path, it should default to /
- EXPECT_TRUE(cm->SetCookie(GURL(url), "A=C; path="));
+ EXPECT_TRUE(SetCookie(cm, GURL(url), "A=C; path="));
EXPECT_EQ("A=B; A=C", GetCookies(cm, GURL(url + "/wee")));
EXPECT_EQ("A=C", GetCookies(cm, GURL(url + "/")));
}
@@ -1164,14 +1190,14 @@
EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options));
// Check httponly overwrite protection.
- EXPECT_FALSE(cm->SetCookie(url_google_, "A=C"));
+ EXPECT_FALSE(SetCookie(cm, url_google_, "A=C"));
EXPECT_EQ("", GetCookies(cm, url_google_));
EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options));
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=C", options));
EXPECT_EQ("A=C", GetCookies(cm, url_google_));
// Check httponly create protection.
- EXPECT_FALSE(cm->SetCookie(url_google_, "B=A; httponly"));
+ EXPECT_FALSE(SetCookie(cm, url_google_, "B=A; httponly"));
EXPECT_EQ("A=C", GetCookiesWithOptions(cm, url_google_, options));
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "B=A; httponly", options));
EXPECT_EQ("A=C; B=A", GetCookiesWithOptions(cm, url_google_, options));
@@ -1324,24 +1350,24 @@
scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL));
// Create a session cookie.
- EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine));
+ EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine));
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
// Delete it via Max-Age.
- EXPECT_TRUE(cm->SetCookie(url_google_,
+ EXPECT_TRUE(SetCookie(cm, url_google_,
std::string(kValidCookieLine) + "; max-age=0"));
EXPECT_EQ("", GetCookies(cm, url_google_));
// Create a session cookie.
- EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine));
+ EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine));
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
// Delete it via Expires.
- EXPECT_TRUE(cm->SetCookie(url_google_,
+ EXPECT_TRUE(SetCookie(cm, url_google_,
std::string(kValidCookieLine) +
"; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
EXPECT_EQ("", GetCookies(cm, url_google_));
// Create a persistent cookie.
- EXPECT_TRUE(cm->SetCookie(url_google_,
+ EXPECT_TRUE(SetCookie(cm, url_google_,
std::string(kValidCookieLine) +
"; expires=Mon, 18-Apr-22 22:50:13 GMT"));
ASSERT_EQ(1u, store->commands().size());
@@ -1349,38 +1375,38 @@
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
// Delete it via Max-Age.
- EXPECT_TRUE(cm->SetCookie(url_google_,
+ EXPECT_TRUE(SetCookie(cm, url_google_,
std::string(kValidCookieLine) + "; max-age=0"));
ASSERT_EQ(2u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
EXPECT_EQ("", GetCookies(cm, url_google_));
// Create a persistent cookie.
- EXPECT_TRUE(cm->SetCookie(url_google_,
- std::string(kValidCookieLine) +
- "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
+ EXPECT_TRUE(SetCookie(cm, url_google_,
+ std::string(kValidCookieLine) +
+ "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
ASSERT_EQ(3u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
// Delete it via Expires.
- EXPECT_TRUE(cm->SetCookie(url_google_,
- std::string(kValidCookieLine) +
- "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
+ EXPECT_TRUE(SetCookie(cm, url_google_,
+ std::string(kValidCookieLine) +
+ "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
ASSERT_EQ(4u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
EXPECT_EQ("", GetCookies(cm, url_google_));
// Create a persistent cookie.
- EXPECT_TRUE(cm->SetCookie(url_google_,
- std::string(kValidCookieLine) +
- "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
+ EXPECT_TRUE(SetCookie(cm, url_google_,
+ std::string(kValidCookieLine) +
+ "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
ASSERT_EQ(5u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type);
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
// Delete it via Expires, with a unix epoch of 0.
- EXPECT_TRUE(cm->SetCookie(url_google_,
- std::string(kValidCookieLine) +
- "; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
+ EXPECT_TRUE(SetCookie(cm, url_google_,
+ std::string(kValidCookieLine) +
+ "; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
ASSERT_EQ(6u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[5].type);
EXPECT_EQ("", GetCookies(cm, url_google_));
@@ -1393,25 +1419,25 @@
CookieOptions options;
options.set_include_httponly();
- EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine));
+ EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine));
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "C=D; httponly", options));
EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm, url_google_, options));
- EXPECT_EQ(2, cm->DeleteAll(false));
+ EXPECT_EQ(2, DeleteAll(cm));
EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options));
EXPECT_EQ(0u, store->commands().size());
// Create a persistent cookie.
- EXPECT_TRUE(cm->SetCookie(url_google_,
- std::string(kValidCookieLine) +
- "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
+ EXPECT_TRUE(SetCookie(cm, url_google_,
+ std::string(kValidCookieLine) +
+ "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
ASSERT_EQ(1u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
- EXPECT_EQ(1, cm->DeleteAll(true)); // sync_to_store = true.
+ EXPECT_EQ(1, DeleteAll(cm)); // sync_to_store = true.
ASSERT_EQ(2u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
@@ -1424,59 +1450,56 @@
// Nothing has been added so nothing should be deleted.
EXPECT_EQ(0, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99),
- Time(), false));
+ Time()));
// Create 3 cookies with creation date of today, yesterday and the day before.
EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now));
EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday",
- now - TimeDelta::FromDays(1)));
+ now - TimeDelta::FromDays(1)));
EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore",
- now - TimeDelta::FromDays(2)));
+ now - TimeDelta::FromDays(2)));
EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays",
- now - TimeDelta::FromDays(3)));
+ now - TimeDelta::FromDays(3)));
EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek",
- now - TimeDelta::FromDays(7)));
+ now - TimeDelta::FromDays(7)));
// Try to delete threedays and the daybefore.
EXPECT_EQ(2, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(3),
- now - TimeDelta::FromDays(1),
- false));
+ now - TimeDelta::FromDays(1)));
// Try to delete yesterday, also make sure that delete_end is not
// inclusive.
EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(2),
- now,
- false));
+ now));
// Make sure the delete_begin is inclusive.
EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(7),
- now,
- false));
+ now));
// Delete the last (now) item.
- EXPECT_EQ(1, DeleteAllCreatedBetween(cm, Time(), Time(), false));
+ EXPECT_EQ(1, DeleteAllCreatedBetween(cm, Time(), Time()));
// Really make sure everything is gone.
- EXPECT_EQ(0, cm->DeleteAll(false));
+ EXPECT_EQ(0, DeleteAll(cm));
}
TEST_F(CookieMonsterTest, TestSecure) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_));
- EXPECT_TRUE(cm->SetCookie(url_google_secure_, "A=B; secure"));
+ EXPECT_TRUE(SetCookie(cm, url_google_secure_, "A=B; secure"));
// The secure should overwrite the non-secure.
EXPECT_EQ("", GetCookies(cm, url_google_));
EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_));
- EXPECT_TRUE(cm->SetCookie(url_google_secure_, "D=E; secure"));
+ EXPECT_TRUE(SetCookie(cm, url_google_secure_, "D=E; secure"));
EXPECT_EQ("", GetCookies(cm, url_google_));
EXPECT_EQ("A=B; D=E", GetCookies(cm, url_google_secure_));
- EXPECT_TRUE(cm->SetCookie(url_google_secure_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_secure_, "A=B"));
// The non-secure should overwrite the secure.
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
EXPECT_EQ("D=E; A=B", GetCookies(cm, url_google_secure_));
@@ -1488,7 +1511,7 @@
scoped_refptr<CookieMonster> cm(
new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
const Time last_access_date(GetFirstCookieAccessDate(cm));
// Reading the cookie again immediately shouldn't update the access date,
@@ -1517,13 +1540,13 @@
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(test_url, "foo=bar"));
+ EXPECT_TRUE(SetCookie(cm, test_url, "foo=bar"));
std::string value = GetCookies(cm, test_url);
EXPECT_EQ("foo=bar", value);
// test that we can retrieve all cookies:
- EXPECT_TRUE(cm->SetCookie(test_url, "x=1"));
- EXPECT_TRUE(cm->SetCookie(test_url, "y=2"));
+ EXPECT_TRUE(SetCookie(cm, test_url, "x=1"));
+ EXPECT_TRUE(SetCookie(cm, test_url, "y=2"));
std::string result = GetCookies(cm, test_url);
EXPECT_FALSE(result.empty());
@@ -1534,9 +1557,9 @@
TEST_F(CookieMonsterTest, TestDeleteSingleCookie) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "C=D"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "E=F"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "C=D"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "E=F"));
EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_));
EXPECT_TRUE(FindAndDeleteCookie(cm, url_google_.host(), "C"));
@@ -1557,10 +1580,10 @@
GURL foo_url("foo://host/path");
GURL http_url("http://host/path");
- EXPECT_TRUE(cm->SetCookie(http_url, "x=1"));
- EXPECT_FALSE(cm->SetCookie(foo_url, "x=1"));
- EXPECT_TRUE(cm_foo->SetCookie(foo_url, "x=1"));
- EXPECT_FALSE(cm_foo->SetCookie(http_url, "x=1"));
+ EXPECT_TRUE(SetCookie(cm, http_url, "x=1"));
+ EXPECT_FALSE(SetCookie(cm, foo_url, "x=1"));
+ EXPECT_TRUE(SetCookie(cm_foo, foo_url, "x=1"));
+ EXPECT_FALSE(SetCookie(cm_foo, http_url, "x=1"));
}
TEST_F(CookieMonsterTest, GetAllCookiesForURL) {
@@ -1573,11 +1596,11 @@
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B; httponly", options));
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_,
- "C=D; domain=.google.izzle",
- options));
+ "C=D; domain=.google.izzle",
+ options));
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_secure_,
- "E=F; domain=.google.izzle; secure",
- options));
+ "E=F; domain=.google.izzle; secure",
+ options));
const Time last_access_date(GetFirstCookieAccessDate(cm));
@@ -1635,14 +1658,11 @@
CookieOptions options;
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_foo_,
- "A=B; path=/foo;",
- options));
+ "A=B; path=/foo;", options));
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_bar_,
- "C=D; path=/bar;",
- options));
+ "C=D; path=/bar;", options));
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_,
- "E=F;",
- options));
+ "E=F;", options));
CookieList cookies = GetAllCookiesForURL(cm, url_google_foo_);
CookieList::iterator it = cookies.begin();
@@ -1674,12 +1694,12 @@
TEST_F(CookieMonsterTest, DeleteCookieByName) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=A1; path=/"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=A2; path=/foo"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=A3; path=/bar"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "B=B1; path=/"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "B=B2; path=/foo"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "B=B3; path=/bar"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=A1; path=/"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=A2; path=/foo"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=A3; path=/bar"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "B=B1; path=/"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "B=B2; path=/foo"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "B=B3; path=/bar"));
DeleteCookie(cm, GURL(std::string(kUrlGoogle) + "/foo/bar"), "A");
@@ -1698,33 +1718,31 @@
CookieOptions options;
EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_,
- "A1=B; path=/foo;",
- options));
+ "A1=B; path=/foo;", options));
EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_,
- "A2=D; path=/bar;",
- options));
+ "A2=D; path=/bar;", options));
EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_,
- "A3=F;",
- options));
+ "A3=F;", options));
+ CookieList cookies_1 = GetAllCookies(cm_1);
scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL));
- ASSERT_TRUE(cm_2->InitializeFrom(cm_1.get()));
- CookieList cookies = cm_2->GetAllCookies();
+ ASSERT_TRUE(cm_2->InitializeFrom(cookies_1));
+ CookieList cookies_2 = GetAllCookies(cm_2);
size_t expected_size = 3;
- EXPECT_EQ(expected_size, cookies.size());
+ EXPECT_EQ(expected_size, cookies_2.size());
- CookieList::iterator it = cookies.begin();
+ CookieList::iterator it = cookies_2.begin();
- ASSERT_TRUE(it != cookies.end());
+ ASSERT_TRUE(it != cookies_2.end());
EXPECT_EQ("A1", it->Name());
EXPECT_EQ("/foo", it->Path());
- ASSERT_TRUE(++it != cookies.end());
+ ASSERT_TRUE(++it != cookies_2.end());
EXPECT_EQ("A2", it->Name());
EXPECT_EQ("/bar", it->Path());
- ASSERT_TRUE(++it != cookies.end());
+ ASSERT_TRUE(++it != cookies_2.end());
EXPECT_EQ("A3", it->Name());
EXPECT_EQ("/", it->Path());
}
@@ -1741,15 +1759,15 @@
// Insert a cookie "a" for path "/path1"
EXPECT_TRUE(
- cm->SetCookie(url_google, "a=val1; path=/path1; "
- "expires=Mon, 18-Apr-22 22:50:13 GMT"));
+ SetCookie(cm, url_google, "a=val1; path=/path1; "
+ "expires=Mon, 18-Apr-22 22:50:13 GMT"));
ASSERT_EQ(1u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
// Insert a cookie "b" for path "/path1"
EXPECT_TRUE(
- cm->SetCookie(url_google, "b=val1; path=/path1; "
- "expires=Mon, 18-Apr-22 22:50:14 GMT"));
+ SetCookie(cm, url_google, "b=val1; path=/path1; "
+ "expires=Mon, 18-Apr-22 22:50:14 GMT"));
ASSERT_EQ(2u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[1].type);
@@ -1759,35 +1777,35 @@
allow_httponly.set_include_httponly();
EXPECT_TRUE(
SetCookieWithOptions(cm, url_google,
- "b=val2; path=/path1; httponly; "
- "expires=Mon, 18-Apr-22 22:50:14 GMT",
- allow_httponly));
+ "b=val2; path=/path1; httponly; "
+ "expires=Mon, 18-Apr-22 22:50:14 GMT",
+ allow_httponly));
ASSERT_EQ(4u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type);
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[3].type);
// Insert a cookie "a" for path "/path1". This should overwrite.
- EXPECT_TRUE(cm->SetCookie(url_google,
- "a=val33; path=/path1; "
- "expires=Mon, 18-Apr-22 22:50:14 GMT"));
+ EXPECT_TRUE(SetCookie(cm, url_google,
+ "a=val33; path=/path1; "
+ "expires=Mon, 18-Apr-22 22:50:14 GMT"));
ASSERT_EQ(6u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[4].type);
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[5].type);
// Insert a cookie "a" for path "/path2". This should NOT overwrite
// cookie "a", since the path is different.
- EXPECT_TRUE(cm->SetCookie(url_google,
- "a=val9; path=/path2; "
- "expires=Mon, 18-Apr-22 22:50:14 GMT"));
+ EXPECT_TRUE(SetCookie(cm, url_google,
+ "a=val9; path=/path2; "
+ "expires=Mon, 18-Apr-22 22:50:14 GMT"));
ASSERT_EQ(7u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[6].type);
// Insert a cookie "a" for path "/path1", but this time for "chromium.org".
// Although the name and path match, the hostnames do not, so shouldn't
// overwrite.
- EXPECT_TRUE(cm->SetCookie(url_chromium,
- "a=val99; path=/path1; "
- "expires=Mon, 18-Apr-22 22:50:14 GMT"));
+ EXPECT_TRUE(SetCookie(cm, url_chromium,
+ "a=val99; path=/path1; "
+ "expires=Mon, 18-Apr-22 22:50:14 GMT"));
ASSERT_EQ(8u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[7].type);
@@ -1928,9 +1946,9 @@
new MockCookieMonsterDelegate);
scoped_refptr<CookieMonster> cm(new CookieMonster(store, delegate));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "C=D"));
- EXPECT_TRUE(cm->SetCookie(url_google_, "E=F"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "C=D"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "E=F"));
EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_));
ASSERT_EQ(3u, delegate->changes().size());
EXPECT_FALSE(delegate->changes()[0].second);
@@ -1962,7 +1980,7 @@
// Insert a cookie "a" for path "/path1"
EXPECT_TRUE(
- cm->SetCookie(url_google_, "a=val1; path=/path1; "
+ SetCookie(cm, url_google_, "a=val1; path=/path1; "
"expires=Mon, 18-Apr-22 22:50:13 GMT"));
ASSERT_EQ(1u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
@@ -1979,9 +1997,9 @@
allow_httponly.set_include_httponly();
EXPECT_TRUE(
SetCookieWithOptions(cm, url_google_,
- "a=val2; path=/path1; httponly; "
- "expires=Mon, 18-Apr-22 22:50:14 GMT",
- allow_httponly));
+ "a=val2; path=/path1; httponly; "
+ "expires=Mon, 18-Apr-22 22:50:14 GMT",
+ allow_httponly));
ASSERT_EQ(3u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
@@ -2142,40 +2160,22 @@
// are not included as they aren't going to be public for very much
// longer.
- // SetCookie, SetCookies, SetCookiesWithOptions,
- // SetCookieWithOptions, SetCookieWithDetails
+ // SetCookie, SetCookieWithOptions, SetCookieWithDetails
- cm->SetCookie(url_google_, "SetCookie1=A");
- cm->SetCookie(url_google_, "SetCookie2=A");
- cm->SetCookie(url_google_, "SetCookie3=A");
+ SetCookie(cm, url_google_, "SetCookie1=A");
+ SetCookie(cm, url_google_, "SetCookie2=A");
+ SetCookie(cm, url_google_, "SetCookie3=A");
- {
- std::vector<std::string> cookie_lines;
- cookie_lines.push_back("setCookies1=A");
- cookie_lines.push_back("setCookies2=A");
- cookie_lines.push_back("setCookies4=A");
- cm->SetCookies(url_google_, cookie_lines);
- }
-
- {
- std::vector<std::string> cookie_lines;
- cookie_lines.push_back("setCookiesWithOptions1=A");
- cookie_lines.push_back("setCookiesWithOptions2=A");
- cookie_lines.push_back("setCookiesWithOptions3=A");
-
- cm->SetCookiesWithOptions(url_google_, cookie_lines, options);
- }
-
SetCookieWithOptions(cm, url_google_, "setCookieWithOptions1=A", options);
SetCookieWithOptions(cm, url_google_, "setCookieWithOptions2=A", options);
SetCookieWithOptions(cm, url_google_, "setCookieWithOptions3=A", options);
SetCookieWithDetails(cm, url_google_, "setCookieWithDetails1", "A",
- ".google.com", "/", Time(), false, false);
+ ".google.com", "/", Time(), false, false);
SetCookieWithDetails(cm, url_google_, "setCookieWithDetails2", "A",
- ".google.com", "/", Time(), false, false);
+ ".google.com", "/", Time(), false, false);
SetCookieWithDetails(cm, url_google_, "setCookieWithDetails3", "A",
- ".google.com", "/", Time(), false, false);
+ ".google.com", "/", Time(), false, false);
// Now we check
CookieList cookie_list(GetAllCookies(cm));
@@ -2262,9 +2262,9 @@
scoped_refptr<CookieMonster> cmout(new CookieMonster(store, NULL));
for (const CookiesInputInfo* p = input_info;
p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) {
- EXPECT_TRUE(cmout->SetCookieWithDetails(GURL(p->gurl), p->name, p->value,
- p->domain, p->path, p->expires,
- p->secure, p->http_only));
+ EXPECT_TRUE(SetCookieWithDetails(cmout, GURL(p->gurl), p->name, p->value,
+ p->domain, p->path, p->expires,
+ p->secure, p->http_only));
}
DeleteCookie(cmout, GURL(std::string(input_info[INPUT_DELETE].gurl) +
input_info[INPUT_DELETE].path),
@@ -2303,26 +2303,26 @@
// Put a random set of cookies into a monster and make sure
// they're returned in the right order.
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/x.html"),
- "c=1"));
- EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"),
- "d=1; domain=b.a.google.com"));
- EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"),
- "a=4; domain=b.a.google.com"));
- EXPECT_TRUE(cm->SetCookie(GURL("http://c.b.a.google.com/aa/bb/cc/x.html"),
- "e=1; domain=c.b.a.google.com"));
- EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/bb/x.html"),
- "b=1"));
- EXPECT_TRUE(cm->SetCookie(GURL("http://news.bbc.co.uk/midpath/x.html"),
- "g=10"));
+ EXPECT_TRUE(SetCookie(cm, GURL("http://d.c.b.a.google.com/aa/x.html"),
+ "c=1"));
+ EXPECT_TRUE(SetCookie(cm, GURL("http://b.a.google.com/aa/bb/cc/x.html"),
+ "d=1; domain=b.a.google.com"));
+ EXPECT_TRUE(SetCookie(cm, GURL("http://b.a.google.com/aa/bb/cc/x.html"),
+ "a=4; domain=b.a.google.com"));
+ EXPECT_TRUE(SetCookie(cm, GURL("http://c.b.a.google.com/aa/bb/cc/x.html"),
+ "e=1; domain=c.b.a.google.com"));
+ EXPECT_TRUE(SetCookie(cm, GURL("http://d.c.b.a.google.com/aa/bb/x.html"),
+ "b=1"));
+ EXPECT_TRUE(SetCookie(cm, GURL("http://news.bbc.co.uk/midpath/x.html"),
+ "g=10"));
EXPECT_EQ("d=1; a=4; e=1; b=1; c=1",
- GetCookiesWithOptions(cm,
- GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"),
+ GetCookiesWithOptions(
+ cm, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"),
CookieOptions()));
{
unsigned int i = 0;
- CookieList cookies(cm->GetAllCookiesForURL(
- GURL("http://d.c.b.a.google.com/aa/bb/cc/dd")));
+ CookieList cookies(GetAllCookiesForURL(
+ cm, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd")));
ASSERT_EQ(5u, cookies.size());
EXPECT_EQ("d", cookies[i++].Name());
EXPECT_EQ("a", cookies[i++].Name());
@@ -2344,16 +2344,6 @@
}
}
-
-// Function for creating a CM with a number of cookies in it,
-// no store (and hence no ability to affect access time).
-static CookieMonster* CreateMonsterForGC(int num_cookies) {
- CookieMonster* cm(new CookieMonster(NULL, NULL));
- for (int i = 0; i < num_cookies; i++)
- cm->SetCookie(GURL(StringPrintf("http://h%05d.izzle", i)), "a=1");
- return cm;
-}
-
// This test and CookieMonstertest.TestGCTimes (in cookie_monster_perftest.cc)
// are somewhat complementary twins. This test is probing for whether
// garbage collection always happens when it should (i.e. that we actually
@@ -2367,7 +2357,7 @@
scoped_refptr<CookieMonster> cm(
CreateMonsterForGC(CookieMonster::kMaxCookies * 2));
EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm).size());
- cm->SetCookie(GURL("http://newdomain.com"), "b=2");
+ SetCookie(cm, GURL("http://newdomain.com"), "b=2");
EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, GetAllCookies(cm).size());
}
@@ -2432,7 +2422,7 @@
static_cast<int>(GetAllCookies(cm).size()))
<< "For test case " << ci;
// Will trigger GC
- cm->SetCookie(GURL("http://newdomain.com"), "b=2");
+ SetCookie(cm, GURL("http://newdomain.com"), "b=2");
EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme],
static_cast<int>((GetAllCookies(cm).size())))
<< "For test case (" << ci << ", " << recent_scheme << ")";
@@ -2448,7 +2438,8 @@
// Set a persistent cookie, but force it to be a session cookie.
options.set_force_session();
- ASSERT_TRUE(SetCookieWithOptions(cm, url_google_,
+ ASSERT_TRUE(SetCookieWithOptions(
+ cm, url_google_,
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT",
options));
@@ -2458,7 +2449,8 @@
ASSERT_FALSE(cookie_list[0].IsPersistent());
// Use a past expiry date to delete the cookie, but force it to session only.
- ASSERT_TRUE(SetCookieWithOptions(cm, url_google_,
+ ASSERT_TRUE(SetCookieWithOptions(
+ cm, url_google_,
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
options));
@@ -2474,7 +2466,8 @@
CookieOptions options;
// Set a persistent cookie.
- ASSERT_TRUE(SetCookieWithOptions(cm, url_google_,
+ ASSERT_TRUE(SetCookieWithOptions(
+ cm, url_google_,
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT",
options));
@@ -2483,7 +2476,8 @@
ASSERT_EQ(1U, cookie_list.size());
// Use a past expiry date to delete the cookie.
- ASSERT_TRUE(SetCookieWithOptions(cm, url_google_,
+ ASSERT_TRUE(SetCookieWithOptions(
+ cm, url_google_,
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
options));
@@ -2501,7 +2495,9 @@
public:
FlushablePersistentStore() : flush_count_(0) {}
- bool Load(std::vector<CookieMonster::CanonicalCookie*>*) {
+ bool Load(const LoadedCallback& loaded_callback) {
+ std::vector<CookieMonster::CanonicalCookie*> out_cookies;
+ loaded_callback.Run(out_cookies);
return false;
}
@@ -2651,7 +2647,7 @@
histogram_set_2.TotalCount());
// kValidCookieLine creates a session cookie.
- ASSERT_TRUE(cm->SetCookie(url_google_, kValidCookieLine));
+ ASSERT_TRUE(SetCookie(cm, url_google_, kValidCookieLine));
expired_histogram->SnapshotSample(&histogram_set_1);
EXPECT_EQ(histogram_set_2.TotalCount(),
histogram_set_1.TotalCount());
@@ -2669,8 +2665,8 @@
void GetCookiesTask(CookieMonster* cm,
const GURL& url,
GetCookieStringCallback* callback) {
- cm->GetCookiesAsync(
- url,
+ cm->GetCookiesWithOptionsAsync(
+ url, CookieOptions(),
base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback)));
}
@@ -2754,10 +2750,9 @@
void DeleteAllCreatedBetweenTask(CookieMonster* cm,
const base::Time& delete_begin,
const base::Time& delete_end,
- bool sync_to_store,
DeleteCallback* callback) {
cm->DeleteAllCreatedBetweenAsync(
- delete_begin, delete_end, sync_to_store,
+ delete_begin, delete_end,
base::Bind(&DeleteCallback::Run,
base::Unretained(callback)));
}
@@ -2797,7 +2792,7 @@
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookies) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
EXPECT_EQ("A=B", GetCookies(cm, url_google_));
GetCookieStringCallback callback(&other_thread_);
base::Closure task = base::Bind(
@@ -2812,7 +2807,7 @@
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithOptions) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
CookieOptions options;
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options));
GetCookieStringCallback callback(&other_thread_);
base::Closure task = base::Bind(
@@ -2829,7 +2824,7 @@
CookieOptions options;
std::string cookie_line;
std::vector<CookieStore::CookieInfo> cookie_infos;
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
GetCookiesWithInfo(cm, url_google_, options, &cookie_line, &cookie_infos);
EXPECT_EQ("A=B", cookie_line);
EXPECT_EQ(1U, cookie_infos.size());
@@ -2852,7 +2847,7 @@
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
CookieList cookies = GetAllCookies(cm);
CookieList::const_iterator it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
@@ -2875,7 +2870,7 @@
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
CookieList cookies = GetAllCookiesForURL(cm, url_google_);
CookieList::const_iterator it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
@@ -2898,7 +2893,7 @@
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(cm->SetCookie(url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm, url_google_, "A=B"));
CookieOptions options;
CookieList cookies =
GetAllCookiesForURLWithOptions(cm, url_google_, options);
@@ -2972,14 +2967,14 @@
Time now = Time::Now();
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99),
- Time(), false));
+ Time()));
EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
DeleteCallback callback(&other_thread_);
base::Closure task = base::Bind(
&net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask,
base::Unretained(this),
cm, now - TimeDelta::FromDays(99),
- Time(), false, &callback);
+ Time(), &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_EQ(1, callback.num_deleted());

Powered by Google App Engine
This is Rietveld 408576698