summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkwst <mkwst@chromium.org>2015-02-20 00:52:45 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-20 08:53:20 +0000
commitbe84af3196d7b6ce5c49c02b2fa47685f8d417c9 (patch)
tree7b56bf3149a692e664659c794a1b9615a3361282
parent4d3fd65dae4f4ea1f6463e3d18b850e114fa5be0 (diff)
downloadchromium_src-be84af3196d7b6ce5c49c02b2fa47685f8d417c9.zip
chromium_src-be84af3196d7b6ce5c49c02b2fa47685f8d417c9.tar.gz
chromium_src-be84af3196d7b6ce5c49c02b2fa47685f8d417c9.tar.bz2
clang-formatting files in //net/cookies to clear up a diff.
The change in https://codereview.chromium.org/876973003 is vaguely incomprehensible because of all the clang-format changes. This patch formats all the files that patch touches in the hopes of clearing up the diff. BUG=459154 Review URL: https://codereview.chromium.org/929303003 Cr-Commit-Position: refs/heads/master@{#317274}
-rw-r--r--net/cookies/canonical_cookie_unittest.cc190
-rw-r--r--net/cookies/cookie_monster.cc518
-rw-r--r--net/cookies/cookie_monster.h21
-rw-r--r--net/cookies/cookie_monster_perftest.cc108
-rw-r--r--net/cookies/cookie_monster_store_test.cc82
-rw-r--r--net/cookies/cookie_monster_store_test.h38
-rw-r--r--net/cookies/cookie_monster_unittest.cc1148
-rw-r--r--net/cookies/cookie_options.h6
-rw-r--r--net/cookies/parsed_cookie.cc45
-rw-r--r--net/cookies/parsed_cookie.h4
-rw-r--r--net/cookies/parsed_cookie_unittest.cc168
11 files changed, 1022 insertions, 1306 deletions
diff --git a/net/cookies/canonical_cookie_unittest.cc b/net/cookies/canonical_cookie_unittest.cc
index 26e4e12..46d730b 100644
--- a/net/cookies/canonical_cookie_unittest.cc
+++ b/net/cookies/canonical_cookie_unittest.cc
@@ -13,33 +13,24 @@
namespace net {
TEST(CanonicalCookieTest, GetCookieSourceFromURL) {
- EXPECT_EQ("http://example.com/",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("http://example.com")));
- EXPECT_EQ("http://example.com/",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("http://example.com/")));
- EXPECT_EQ("http://example.com/",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("http://example.com/test")));
- EXPECT_EQ("file:///tmp/test.html",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("file:///tmp/test.html")));
- EXPECT_EQ("http://example.com/",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("http://example.com:1234/")));
- EXPECT_EQ("http://example.com/",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("https://example.com/")));
- EXPECT_EQ("http://example.com/",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("http://user:pwd@example.com/")));
- EXPECT_EQ("http://example.com/",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("http://example.com/test?foo")));
- EXPECT_EQ("http://example.com/",
- CanonicalCookie::GetCookieSourceFromURL(
- GURL("http://example.com/test#foo")));
+ EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("http://example.com")));
+ EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("http://example.com/")));
+ EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("http://example.com/test")));
+ EXPECT_EQ("file:///tmp/test.html", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("file:///tmp/test.html")));
+ EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("http://example.com:1234/")));
+ EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("https://example.com/")));
+ EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("http://user:pwd@example.com/")));
+ EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("http://example.com/test?foo")));
+ EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL(
+ GURL("http://example.com/test#foo")));
}
TEST(CanonicalCookieTest, Constructor) {
@@ -56,24 +47,15 @@ TEST(CanonicalCookieTest, Constructor) {
EXPECT_EQ("/test", cookie.Path());
EXPECT_FALSE(cookie.IsSecure());
- CanonicalCookie cookie2(url,
- "A",
- "2",
- std::string(),
- std::string(),
- current_time,
- base::Time(),
- current_time,
- false,
- false,
- COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie2(url, "A", "2", std::string(), std::string(),
+ current_time, base::Time(), current_time, false,
+ false, COOKIE_PRIORITY_DEFAULT);
EXPECT_EQ(url.GetOrigin().spec(), cookie.Source());
EXPECT_EQ("A", cookie2.Name());
EXPECT_EQ("2", cookie2.Value());
EXPECT_EQ("", cookie2.Domain());
EXPECT_EQ("", cookie2.Path());
EXPECT_FALSE(cookie2.IsSecure());
-
}
TEST(CanonicalCookieTest, Create) {
@@ -83,7 +65,7 @@ TEST(CanonicalCookieTest, Create) {
CookieOptions options;
scoped_ptr<CanonicalCookie> cookie(
- CanonicalCookie::Create(url, "A=2", creation_time, options));
+ CanonicalCookie::Create(url, "A=2", creation_time, options));
EXPECT_EQ(url.GetOrigin().spec(), cookie->Source());
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
@@ -113,16 +95,15 @@ TEST(CanonicalCookieTest, Create) {
EXPECT_FALSE(cookie.get());
CookieOptions httponly_options;
httponly_options.set_include_httponly();
- cookie.reset(
- CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time,
- httponly_options));
+ cookie.reset(CanonicalCookie::Create(url, "A=2; HttpOnly", creation_time,
+ httponly_options));
EXPECT_TRUE(cookie->IsHttpOnly());
// Test the creating cookies using specific parameter instead of a cookie
// string.
- cookie.reset(CanonicalCookie::Create(
- url, "A", "2", "www.example.com", "/test", creation_time, base::Time(),
- false, false, COOKIE_PRIORITY_DEFAULT));
+ cookie.reset(CanonicalCookie::Create(url, "A", "2", "www.example.com",
+ "/test", creation_time, base::Time(),
+ false, false, COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ(url.GetOrigin().spec(), cookie->Source());
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
@@ -130,9 +111,9 @@ TEST(CanonicalCookieTest, Create) {
EXPECT_EQ("/test", cookie->Path());
EXPECT_FALSE(cookie->IsSecure());
- cookie.reset(CanonicalCookie::Create(
- url, "A", "2", ".www.example.com", "/test", creation_time, base::Time(),
- false, false, COOKIE_PRIORITY_DEFAULT));
+ cookie.reset(CanonicalCookie::Create(url, "A", "2", ".www.example.com",
+ "/test", creation_time, base::Time(),
+ false, false, COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ(url.GetOrigin().spec(), cookie->Source());
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
@@ -148,8 +129,8 @@ TEST(CanonicalCookieTest, EmptyExpiry) {
std::string cookie_line =
"ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires=";
- scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
- url, cookie_line, creation_time, options));
+ scoped_ptr<CanonicalCookie> cookie(
+ CanonicalCookie::Create(url, cookie_line, creation_time, options));
EXPECT_TRUE(cookie.get());
EXPECT_FALSE(cookie->IsPersistent());
EXPECT_FALSE(cookie->IsExpired(creation_time));
@@ -157,8 +138,8 @@ TEST(CanonicalCookieTest, EmptyExpiry) {
// With a stale server time
options.set_server_time(creation_time - base::TimeDelta::FromHours(1));
- cookie.reset(CanonicalCookie::Create(
- url, cookie_line, creation_time, options));
+ cookie.reset(
+ CanonicalCookie::Create(url, cookie_line, creation_time, options));
EXPECT_TRUE(cookie.get());
EXPECT_FALSE(cookie->IsPersistent());
EXPECT_FALSE(cookie->IsExpired(creation_time));
@@ -166,8 +147,8 @@ TEST(CanonicalCookieTest, EmptyExpiry) {
// With a future server time
options.set_server_time(creation_time + base::TimeDelta::FromHours(1));
- cookie.reset(CanonicalCookie::Create(
- url, cookie_line, creation_time, options));
+ cookie.reset(
+ CanonicalCookie::Create(url, cookie_line, creation_time, options));
EXPECT_TRUE(cookie.get());
EXPECT_FALSE(cookie->IsPersistent());
EXPECT_FALSE(cookie->IsExpired(creation_time));
@@ -187,76 +168,66 @@ TEST(CanonicalCookieTest, IsEquivalent) {
bool httponly(false);
// Test that a cookie is equivalent to itself.
- scoped_ptr<CanonicalCookie> cookie(
- new CanonicalCookie(url, cookie_name, cookie_value, cookie_domain,
- cookie_path, creation_time, expiration_time,
- last_access_time, secure, httponly,
- COOKIE_PRIORITY_MEDIUM));
+ scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(
+ url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time,
+ expiration_time, last_access_time, secure, httponly,
+ COOKIE_PRIORITY_MEDIUM));
EXPECT_TRUE(cookie->IsEquivalent(*cookie));
// Test that two identical cookies are equivalent.
- scoped_ptr<CanonicalCookie> other_cookie(
- new CanonicalCookie(url, cookie_name, cookie_value, cookie_domain,
- cookie_path, creation_time, expiration_time,
- last_access_time, secure, httponly,
- COOKIE_PRIORITY_MEDIUM));
+ scoped_ptr<CanonicalCookie> other_cookie(new CanonicalCookie(
+ url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time,
+ expiration_time, last_access_time, secure, httponly,
+ COOKIE_PRIORITY_MEDIUM));
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
// Tests that use different variations of attribute values that
// DON'T affect cookie equivalence.
- other_cookie.reset(new CanonicalCookie(url, cookie_name, "2", cookie_domain,
- cookie_path, creation_time,
- expiration_time, last_access_time,
- secure, httponly,
- COOKIE_PRIORITY_HIGH));
+ other_cookie.reset(
+ new CanonicalCookie(url, cookie_name, "2", cookie_domain, cookie_path,
+ creation_time, expiration_time, last_access_time,
+ secure, httponly, COOKIE_PRIORITY_HIGH));
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
base::Time other_creation_time =
creation_time + base::TimeDelta::FromMinutes(2);
- other_cookie.reset(new CanonicalCookie(url, cookie_name, "2", cookie_domain,
- cookie_path, other_creation_time,
- expiration_time, last_access_time,
- secure, httponly,
- COOKIE_PRIORITY_MEDIUM));
+ other_cookie.reset(new CanonicalCookie(
+ url, cookie_name, "2", cookie_domain, cookie_path, other_creation_time,
+ expiration_time, last_access_time, secure, httponly,
+ COOKIE_PRIORITY_MEDIUM));
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
- other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_name,
- cookie_domain, cookie_path,
- creation_time, expiration_time,
- last_access_time, true, httponly,
- COOKIE_PRIORITY_LOW));
+ other_cookie.reset(new CanonicalCookie(
+ url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
+ expiration_time, last_access_time, true, httponly, COOKIE_PRIORITY_LOW));
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
// Tests that use different variations of attribute values that
// DO affect cookie equivalence.
- other_cookie.reset(new CanonicalCookie(url, "B", cookie_value, cookie_domain,
- cookie_path, creation_time,
- expiration_time, last_access_time,
- secure, httponly,
- COOKIE_PRIORITY_MEDIUM));
+ other_cookie.reset(
+ new CanonicalCookie(url, "B", cookie_value, cookie_domain, cookie_path,
+ creation_time, expiration_time, last_access_time,
+ secure, httponly, COOKIE_PRIORITY_MEDIUM));
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
- other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value,
- "www.example.com", cookie_path,
- creation_time, expiration_time,
- last_access_time, secure, httponly,
- COOKIE_PRIORITY_MEDIUM));
+ other_cookie.reset(new CanonicalCookie(
+ url, cookie_name, cookie_value, "www.example.com", cookie_path,
+ creation_time, expiration_time, last_access_time, secure, httponly,
+ COOKIE_PRIORITY_MEDIUM));
EXPECT_TRUE(cookie->IsDomainCookie());
EXPECT_FALSE(other_cookie->IsDomainCookie());
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
- other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value,
- ".example.com", cookie_path,
- creation_time, expiration_time,
- last_access_time, secure, httponly,
- COOKIE_PRIORITY_MEDIUM));
+ other_cookie.reset(new CanonicalCookie(
+ url, cookie_name, cookie_value, ".example.com", cookie_path,
+ creation_time, expiration_time, last_access_time, secure, httponly,
+ COOKIE_PRIORITY_MEDIUM));
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
- other_cookie.reset(new CanonicalCookie(url, cookie_name, cookie_value,
- cookie_domain, "/test/0",
- creation_time, expiration_time,
- last_access_time, secure, httponly,
- COOKIE_PRIORITY_MEDIUM));
+ other_cookie.reset(new CanonicalCookie(
+ url, cookie_name, cookie_value, cookie_domain, "/test/0", creation_time,
+ expiration_time, last_access_time, secure, httponly,
+ COOKIE_PRIORITY_MEDIUM));
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
}
@@ -274,9 +245,8 @@ TEST(CanonicalCookieTest, IsDomainMatch) {
EXPECT_FALSE(cookie->IsDomainMatch("www0.example.com"));
EXPECT_FALSE(cookie->IsDomainMatch("example.com"));
- cookie.reset(
- CanonicalCookie::Create(url, "A=2; Domain=www.example.com", creation_time,
- options));
+ cookie.reset(CanonicalCookie::Create(url, "A=2; Domain=www.example.com",
+ creation_time, options));
EXPECT_TRUE(cookie->IsDomainCookie());
EXPECT_TRUE(cookie->IsDomainMatch("www.example.com"));
EXPECT_TRUE(cookie->IsDomainMatch("www.example.com"));
@@ -284,9 +254,8 @@ TEST(CanonicalCookieTest, IsDomainMatch) {
EXPECT_FALSE(cookie->IsDomainMatch("www0.example.com"));
EXPECT_FALSE(cookie->IsDomainMatch("example.com"));
- cookie.reset(
- CanonicalCookie::Create(url, "A=2; Domain=.www.example.com",
- creation_time, options));
+ cookie.reset(CanonicalCookie::Create(url, "A=2; Domain=.www.example.com",
+ creation_time, options));
EXPECT_TRUE(cookie->IsDomainMatch("www.example.com"));
EXPECT_TRUE(cookie->IsDomainMatch("www.example.com"));
EXPECT_TRUE(cookie->IsDomainMatch("foo.www.example.com"));
@@ -298,9 +267,8 @@ TEST(CanonicalCookieTest, IsOnPath) {
base::Time creation_time = base::Time::Now();
CookieOptions options;
- scoped_ptr<CanonicalCookie> cookie(
- CanonicalCookie::Create(GURL("http://www.example.com"),
- "A=2", creation_time, options));
+ scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
+ GURL("http://www.example.com"), "A=2", creation_time, options));
EXPECT_TRUE(cookie->IsOnPath("/"));
EXPECT_TRUE(cookie->IsOnPath("/test"));
EXPECT_TRUE(cookie->IsOnPath("/test/bar.html"));
@@ -329,8 +297,8 @@ TEST(CanonicalCookieTest, IncludeForRequestURL) {
GURL("http://www.example.com/foo/bar"), options));
EXPECT_TRUE(cookie->IncludeForRequestURL(
GURL("https://www.example.com/foo/bar"), options));
- EXPECT_FALSE(cookie->IncludeForRequestURL(GURL("https://sub.example.com"),
- options));
+ EXPECT_FALSE(
+ cookie->IncludeForRequestURL(GURL("https://sub.example.com"), options));
EXPECT_FALSE(cookie->IncludeForRequestURL(GURL("https://sub.www.example.com"),
options));
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc
index 452ce68..7c2a14c 100644
--- a/net/cookies/cookie_monster.cc
+++ b/net/cookies/cookie_monster.cc
@@ -97,18 +97,18 @@ namespace net {
// See comments at declaration of these variables in cookie_monster.h
// for details.
-const size_t CookieMonster::kDomainMaxCookies = 180;
-const size_t CookieMonster::kDomainPurgeCookies = 30;
-const size_t CookieMonster::kMaxCookies = 3300;
-const size_t CookieMonster::kPurgeCookies = 300;
+const size_t CookieMonster::kDomainMaxCookies = 180;
+const size_t CookieMonster::kDomainPurgeCookies = 30;
+const size_t CookieMonster::kMaxCookies = 3300;
+const size_t CookieMonster::kPurgeCookies = 300;
-const size_t CookieMonster::kDomainCookiesQuotaLow = 30;
+const size_t CookieMonster::kDomainCookiesQuotaLow = 30;
const size_t CookieMonster::kDomainCookiesQuotaMedium = 50;
-const size_t CookieMonster::kDomainCookiesQuotaHigh =
- kDomainMaxCookies - kDomainPurgeCookies
- - kDomainCookiesQuotaLow - kDomainCookiesQuotaMedium;
+const size_t CookieMonster::kDomainCookiesQuotaHigh =
+ kDomainMaxCookies - kDomainPurgeCookies - kDomainCookiesQuotaLow -
+ kDomainCookiesQuotaMedium;
-const int CookieMonster::kSafeFromGlobalPurgeDays = 30;
+const int CookieMonster::kSafeFromGlobalPurgeDays = 30;
namespace {
@@ -177,8 +177,7 @@ struct CookieSignature {
CookieSignature(const std::string& name,
const std::string& domain,
const std::string& path)
- : name(name), domain(domain), path(path) {
- }
+ : name(name), domain(domain), path(path) {}
// To be a key for a map this class needs to be assignable, copyable,
// and have an operator<. The default assignment operator
@@ -206,10 +205,9 @@ struct CookieSignature {
// sorts the first |num_sort| + 1 elements by LastAccessDate().
// The + 1 element exists so for any interval of length <= |num_sort| starting
// from |cookies_its_begin|, a LastAccessDate() bound can be found.
-void SortLeastRecentlyAccessed(
- CookieMonster::CookieItVector::iterator it_begin,
- CookieMonster::CookieItVector::iterator it_end,
- size_t num_sort) {
+void SortLeastRecentlyAccessed(CookieMonster::CookieItVector::iterator it_begin,
+ CookieMonster::CookieItVector::iterator it_end,
+ size_t num_sort) {
DCHECK_LT(static_cast<int>(num_sort), it_end - it_begin);
std::partial_sort(it_begin, it_begin + num_sort + 1, it_end, LRACookieSorter);
}
@@ -218,7 +216,7 @@ void SortLeastRecentlyAccessed(
struct CookiePriorityEqualsTo
: std::unary_function<const CookieMonster::CookieMap::iterator, bool> {
explicit CookiePriorityEqualsTo(CookiePriority priority)
- : priority_(priority) {}
+ : priority_(priority) {}
bool operator()(const CookieMonster::CookieMap::iterator it) const {
return it->second->Priority() == priority_;
@@ -238,8 +236,8 @@ CookieMonster::CookieItVector::iterator PartitionCookieByPriority(
return std::partition(it_begin, it_end, CookiePriorityEqualsTo(priority));
}
-bool LowerBoundAccessDateComparator(
- const CookieMonster::CookieMap::iterator it, const Time& access_date) {
+bool LowerBoundAccessDateComparator(const CookieMonster::CookieMap::iterator it,
+ const Time& access_date) {
return it->second->LastAccessDate() < access_date;
}
@@ -263,33 +261,32 @@ typedef struct ChangeCausePair_struct {
bool notify;
} ChangeCausePair;
ChangeCausePair ChangeCauseMapping[] = {
- // DELETE_COOKIE_EXPLICIT
- { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true },
- // DELETE_COOKIE_OVERWRITE
- { CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true },
- // DELETE_COOKIE_EXPIRED
- { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true },
- // DELETE_COOKIE_EVICTED
- { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
- // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE
- { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false },
- // DELETE_COOKIE_DONT_RECORD
- { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false },
- // DELETE_COOKIE_EVICTED_DOMAIN
- { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
- // DELETE_COOKIE_EVICTED_GLOBAL
- { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
- // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE
- { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
- // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE
- { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
- // DELETE_COOKIE_EXPIRED_OVERWRITE
- { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true },
- // DELETE_COOKIE_CONTROL_CHAR
- { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
- // DELETE_COOKIE_LAST_ENTRY
- { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }
-};
+ // DELETE_COOKIE_EXPLICIT
+ {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true},
+ // DELETE_COOKIE_OVERWRITE
+ {CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true},
+ // DELETE_COOKIE_EXPIRED
+ {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true},
+ // DELETE_COOKIE_EVICTED
+ {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
+ // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE
+ {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false},
+ // DELETE_COOKIE_DONT_RECORD
+ {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false},
+ // DELETE_COOKIE_EVICTED_DOMAIN
+ {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
+ // DELETE_COOKIE_EVICTED_GLOBAL
+ {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
+ // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE
+ {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
+ // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE
+ {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
+ // DELETE_COOKIE_EXPIRED_OVERWRITE
+ {CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true},
+ // DELETE_COOKIE_CONTROL_CHAR
+ {CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true},
+ // DELETE_COOKIE_LAST_ENTRY
+ {CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false}};
std::string BuildCookieLine(const CanonicalCookieVector& cookies) {
std::string cookie_line;
@@ -347,7 +344,6 @@ CookieMonster::CookieMonster(PersistentCookieStore* store,
SetDefaultCookieableSchemes();
}
-
// Task classes for queueing the coming request.
class CookieMonster::CookieMonsterTask
@@ -367,9 +363,7 @@ class CookieMonster::CookieMonsterTask
// instance until the callback completes.
void InvokeCallback(base::Closure callback);
- CookieMonster* cookie_monster() {
- return cookie_monster_;
- }
+ CookieMonster* cookie_monster() { return cookie_monster_; }
private:
friend class base::RefCountedThreadSafe<CookieMonsterTask>;
@@ -386,7 +380,8 @@ CookieMonster::CookieMonsterTask::CookieMonsterTask(
thread_(base::MessageLoopProxy::current()) {
}
-CookieMonster::CookieMonsterTask::~CookieMonsterTask() {}
+CookieMonster::CookieMonsterTask::~CookieMonsterTask() {
+}
// Unfortunately, one cannot re-bind a Callback with parameters into a closure.
// Therefore, the closure passed to InvokeCallback is a clumsy binding of
@@ -402,8 +397,8 @@ void CookieMonster::CookieMonsterTask::InvokeCallback(base::Closure callback) {
if (thread_->BelongsToCurrentThread()) {
callback.Run();
} else {
- thread_->PostTask(FROM_HERE, base::Bind(
- &CookieMonsterTask::InvokeCallback, this, callback));
+ thread_->PostTask(FROM_HERE, base::Bind(&CookieMonsterTask::InvokeCallback,
+ this, callback));
}
}
@@ -431,8 +426,7 @@ class CookieMonster::SetCookieWithDetailsTask : public CookieMonsterTask {
secure_(secure),
http_only_(http_only),
priority_(priority),
- callback_(callback) {
- }
+ callback_(callback) {}
// CookieMonsterTask:
void Run() override;
@@ -456,9 +450,9 @@ class CookieMonster::SetCookieWithDetailsTask : public CookieMonsterTask {
};
void CookieMonster::SetCookieWithDetailsTask::Run() {
- bool success = this->cookie_monster()->
- SetCookieWithDetails(url_, name_, value_, domain_, path_,
- expiration_time_, secure_, http_only_, priority_);
+ bool success = this->cookie_monster()->SetCookieWithDetails(
+ url_, name_, value_, domain_, path_, expiration_time_, secure_,
+ http_only_, priority_);
if (!callback_.is_null()) {
this->InvokeCallback(base::Bind(&SetCookiesCallback::Run,
base::Unretained(&callback_), success));
@@ -470,9 +464,7 @@ class CookieMonster::GetAllCookiesTask : public CookieMonsterTask {
public:
GetAllCookiesTask(CookieMonster* cookie_monster,
const GetCookieListCallback& callback)
- : CookieMonsterTask(cookie_monster),
- callback_(callback) {
- }
+ : CookieMonsterTask(cookie_monster), callback_(callback) {}
// CookieMonsterTask
void Run() override;
@@ -491,23 +483,21 @@ void CookieMonster::GetAllCookiesTask::Run() {
CookieList cookies = this->cookie_monster()->GetAllCookies();
this->InvokeCallback(base::Bind(&GetCookieListCallback::Run,
base::Unretained(&callback_), cookies));
- }
+ }
}
// Task class for GetAllCookiesForURLWithOptions call.
class CookieMonster::GetAllCookiesForURLWithOptionsTask
: public CookieMonsterTask {
public:
- GetAllCookiesForURLWithOptionsTask(
- CookieMonster* cookie_monster,
- const GURL& url,
- const CookieOptions& options,
- const GetCookieListCallback& callback)
+ GetAllCookiesForURLWithOptionsTask(CookieMonster* cookie_monster,
+ const GURL& url,
+ const CookieOptions& options,
+ const GetCookieListCallback& callback)
: CookieMonsterTask(cookie_monster),
url_(url),
options_(options),
- callback_(callback) {
- }
+ callback_(callback) {}
// CookieMonsterTask:
void Run() override;
@@ -525,18 +515,20 @@ class CookieMonster::GetAllCookiesForURLWithOptionsTask
void CookieMonster::GetAllCookiesForURLWithOptionsTask::Run() {
if (!callback_.is_null()) {
- CookieList cookies = this->cookie_monster()->
- GetAllCookiesForURLWithOptions(url_, options_);
+ CookieList cookies =
+ this->cookie_monster()->GetAllCookiesForURLWithOptions(url_, options_);
this->InvokeCallback(base::Bind(&GetCookieListCallback::Run,
base::Unretained(&callback_), cookies));
}
}
-template <typename Result> struct CallbackType {
+template <typename Result>
+struct CallbackType {
typedef base::Callback<void(Result)> Type;
};
-template <> struct CallbackType<void> {
+template <>
+struct CallbackType<void> {
typedef base::Closure Type;
};
@@ -546,9 +538,7 @@ class CookieMonster::DeleteTask : public CookieMonsterTask {
public:
DeleteTask(CookieMonster* cookie_monster,
const typename CallbackType<Result>::Type& callback)
- : CookieMonsterTask(cookie_monster),
- callback_(callback) {
- }
+ : CookieMonsterTask(cookie_monster), callback_(callback) {}
// CookieMonsterTask:
virtual void Run() override;
@@ -588,9 +578,8 @@ base::Closure CookieMonster::DeleteTask<void>::RunDeleteTaskAndBindCallback() {
template <typename Result>
void CookieMonster::DeleteTask<Result>::Run() {
- this->cookie_monster()->FlushStore(
- base::Bind(&DeleteTask<Result>::FlushDone, this,
- RunDeleteTaskAndBindCallback()));
+ this->cookie_monster()->FlushStore(base::Bind(
+ &DeleteTask<Result>::FlushDone, this, RunDeleteTaskAndBindCallback()));
}
template <typename Result>
@@ -604,10 +593,8 @@ void CookieMonster::DeleteTask<Result>::FlushDone(
// Task class for DeleteAll call.
class CookieMonster::DeleteAllTask : public DeleteTask<int> {
public:
- DeleteAllTask(CookieMonster* cookie_monster,
- const DeleteCallback& callback)
- : DeleteTask<int>(cookie_monster, callback) {
- }
+ DeleteAllTask(CookieMonster* cookie_monster, const DeleteCallback& callback)
+ : DeleteTask<int>(cookie_monster, callback) {}
// DeleteTask:
int RunDeleteTask() override;
@@ -632,8 +619,7 @@ class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> {
const DeleteCallback& callback)
: DeleteTask<int>(cookie_monster, callback),
delete_begin_(delete_begin),
- delete_end_(delete_end) {
- }
+ delete_end_(delete_end) {}
// DeleteTask:
int RunDeleteTask() override;
@@ -649,8 +635,8 @@ class CookieMonster::DeleteAllCreatedBetweenTask : public DeleteTask<int> {
};
int CookieMonster::DeleteAllCreatedBetweenTask::RunDeleteTask() {
- return this->cookie_monster()->
- DeleteAllCreatedBetween(delete_begin_, delete_end_);
+ return this->cookie_monster()->DeleteAllCreatedBetween(delete_begin_,
+ delete_end_);
}
// Task class for DeleteAllForHost call.
@@ -659,9 +645,7 @@ class CookieMonster::DeleteAllForHostTask : public DeleteTask<int> {
DeleteAllForHostTask(CookieMonster* cookie_monster,
const GURL& url,
const DeleteCallback& callback)
- : DeleteTask<int>(cookie_monster, callback),
- url_(url) {
- }
+ : DeleteTask<int>(cookie_monster, callback), url_(url) {}
// DeleteTask:
int RunDeleteTask() override;
@@ -683,17 +667,15 @@ int CookieMonster::DeleteAllForHostTask::RunDeleteTask() {
class CookieMonster::DeleteAllCreatedBetweenForHostTask
: public DeleteTask<int> {
public:
- DeleteAllCreatedBetweenForHostTask(
- CookieMonster* cookie_monster,
- Time delete_begin,
- Time delete_end,
- const GURL& url,
- const DeleteCallback& callback)
+ DeleteAllCreatedBetweenForHostTask(CookieMonster* cookie_monster,
+ Time delete_begin,
+ Time delete_end,
+ const GURL& url,
+ const DeleteCallback& callback)
: DeleteTask<int>(cookie_monster, callback),
delete_begin_(delete_begin),
delete_end_(delete_end),
- url_(url) {
- }
+ url_(url) {}
// DeleteTask:
int RunDeleteTask() override;
@@ -720,9 +702,7 @@ class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<bool> {
DeleteCanonicalCookieTask(CookieMonster* cookie_monster,
const CanonicalCookie& cookie,
const DeleteCookieCallback& callback)
- : DeleteTask<bool>(cookie_monster, callback),
- cookie_(cookie) {
- }
+ : DeleteTask<bool>(cookie_monster, callback), cookie_(cookie) {}
// DeleteTask:
bool RunDeleteTask() override;
@@ -752,8 +732,7 @@ class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask {
url_(url),
cookie_line_(cookie_line),
options_(options),
- callback_(callback) {
- }
+ callback_(callback) {}
// CookieMonsterTask:
void Run() override;
@@ -771,8 +750,8 @@ class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask {
};
void CookieMonster::SetCookieWithOptionsTask::Run() {
- bool result = this->cookie_monster()->
- SetCookieWithOptions(url_, cookie_line_, options_);
+ bool result = this->cookie_monster()->SetCookieWithOptions(url_, cookie_line_,
+ options_);
if (!callback_.is_null()) {
this->InvokeCallback(base::Bind(&SetCookiesCallback::Run,
base::Unretained(&callback_), result));
@@ -789,8 +768,7 @@ class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask {
: CookieMonsterTask(cookie_monster),
url_(url),
options_(options),
- callback_(callback) {
- }
+ callback_(callback) {}
// CookieMonsterTask:
void Run() override;
@@ -807,8 +785,8 @@ class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask {
};
void CookieMonster::GetCookiesWithOptionsTask::Run() {
- std::string cookie = this->cookie_monster()->
- GetCookiesWithOptions(url_, options_);
+ std::string cookie =
+ this->cookie_monster()->GetCookiesWithOptions(url_, options_);
if (!callback_.is_null()) {
this->InvokeCallback(base::Bind(&GetCookiesCallback::Run,
base::Unretained(&callback_), cookie));
@@ -824,8 +802,7 @@ class CookieMonster::DeleteCookieTask : public DeleteTask<void> {
const base::Closure& callback)
: DeleteTask<void>(cookie_monster, callback),
url_(url),
- cookie_name_(cookie_name) {
- }
+ cookie_name_(cookie_name) {}
// DeleteTask:
void RunDeleteTask() override;
@@ -849,8 +826,7 @@ class CookieMonster::DeleteSessionCookiesTask : public DeleteTask<int> {
public:
DeleteSessionCookiesTask(CookieMonster* cookie_monster,
const DeleteCallback& callback)
- : DeleteTask<int>(cookie_monster, callback) {
- }
+ : DeleteTask<int>(cookie_monster, callback) {}
// DeleteTask:
int RunDeleteTask() override;
@@ -869,14 +845,12 @@ int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() {
// Task class for HasCookiesForETLDP1Task call.
class CookieMonster::HasCookiesForETLDP1Task : public CookieMonsterTask {
public:
- HasCookiesForETLDP1Task(
- CookieMonster* cookie_monster,
- const std::string& etldp1,
- const HasCookiesForETLDP1Callback& callback)
+ HasCookiesForETLDP1Task(CookieMonster* cookie_monster,
+ const std::string& etldp1,
+ const HasCookiesForETLDP1Callback& callback)
: CookieMonsterTask(cookie_monster),
etldp1_(etldp1),
- callback_(callback) {
- }
+ callback_(callback) {}
// CookieMonsterTask:
void Run() override;
@@ -894,9 +868,8 @@ class CookieMonster::HasCookiesForETLDP1Task : public CookieMonsterTask {
void CookieMonster::HasCookiesForETLDP1Task::Run() {
bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_);
if (!callback_.is_null()) {
- this->InvokeCallback(
- base::Bind(&HasCookiesForETLDP1Callback::Run,
- base::Unretained(&callback_), result));
+ this->InvokeCallback(base::Bind(&HasCookiesForETLDP1Callback::Run,
+ base::Unretained(&callback_), result));
}
}
@@ -913,21 +886,18 @@ void CookieMonster::SetCookieWithDetailsAsync(
bool http_only,
CookiePriority priority,
const SetCookiesCallback& callback) {
- scoped_refptr<SetCookieWithDetailsTask> task =
- new SetCookieWithDetailsTask(this, url, name, value, domain, path,
- expiration_time, secure, http_only, priority,
- callback);
+ scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask(
+ this, url, name, value, domain, path, expiration_time, secure, http_only,
+ priority, callback);
DoCookieTaskForURL(task, url);
}
void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) {
- scoped_refptr<GetAllCookiesTask> task =
- new GetAllCookiesTask(this, callback);
+ scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback);
DoCookieTask(task);
}
-
void CookieMonster::GetAllCookiesForURLWithOptionsAsync(
const GURL& url,
const CookieOptions& options,
@@ -939,7 +909,8 @@ void CookieMonster::GetAllCookiesForURLWithOptionsAsync(
}
void CookieMonster::GetAllCookiesForURLAsync(
- const GURL& url, const GetCookieListCallback& callback) {
+ const GURL& url,
+ const GetCookieListCallback& callback) {
CookieOptions options;
options.set_include_httponly();
scoped_refptr<GetAllCookiesForURLWithOptionsTask> task =
@@ -958,18 +929,17 @@ void CookieMonster::HasCookiesForETLDP1Async(
}
void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) {
- scoped_refptr<DeleteAllTask> task =
- new DeleteAllTask(this, callback);
+ scoped_refptr<DeleteAllTask> task = new DeleteAllTask(this, callback);
DoCookieTask(task);
}
void CookieMonster::DeleteAllCreatedBetweenAsync(
- const Time& delete_begin, const Time& delete_end,
+ const Time& delete_begin,
+ const Time& delete_end,
const DeleteCallback& callback) {
scoped_refptr<DeleteAllCreatedBetweenTask> task =
- new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end,
- callback);
+ new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback);
DoCookieTask(task);
}
@@ -980,14 +950,14 @@ void CookieMonster::DeleteAllCreatedBetweenForHostAsync(
const GURL& url,
const DeleteCallback& callback) {
scoped_refptr<DeleteAllCreatedBetweenForHostTask> task =
- new DeleteAllCreatedBetweenForHostTask(
- this, delete_begin, delete_end, url, callback);
+ new DeleteAllCreatedBetweenForHostTask(this, delete_begin, delete_end,
+ url, callback);
DoCookieTaskForURL(task, url);
}
-void CookieMonster::DeleteAllForHostAsync(
- const GURL& url, const DeleteCallback& callback) {
+void CookieMonster::DeleteAllForHostAsync(const GURL& url,
+ const DeleteCallback& callback) {
scoped_refptr<DeleteAllForHostTask> task =
new DeleteAllForHostTask(this, url, callback);
@@ -1065,16 +1035,19 @@ void CookieMonster::DoCookieTaskForURL(
// then run the task, otherwise load from DB.
if (!loaded_) {
// Checks if the domain key has been loaded.
- std::string key(cookie_util::GetEffectiveDomain(url.scheme(),
- url.host()));
+ std::string key(
+ cookie_util::GetEffectiveDomain(url.scheme(), url.host()));
if (keys_loaded_.find(key) == keys_loaded_.end()) {
- std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > >
- ::iterator it = tasks_pending_for_key_.find(key);
+ std::map<std::string,
+ std::deque<scoped_refptr<CookieMonsterTask>>>::iterator it =
+ tasks_pending_for_key_.find(key);
if (it == tasks_pending_for_key_.end()) {
- store_->LoadCookiesForKey(key,
- base::Bind(&CookieMonster::OnKeyLoaded, this, key));
- it = tasks_pending_for_key_.insert(std::make_pair(key,
- std::deque<scoped_refptr<CookieMonsterTask> >())).first;
+ store_->LoadCookiesForKey(
+ key, base::Bind(&CookieMonster::OnKeyLoaded, this, key));
+ it = tasks_pending_for_key_
+ .insert(std::make_pair(
+ key, std::deque<scoped_refptr<CookieMonsterTask>>()))
+ .first;
}
it->second.push_back(task_item);
return;
@@ -1103,8 +1076,8 @@ bool CookieMonster::SetCookieWithDetails(const GURL& url,
scoped_ptr<CanonicalCookie> cc;
cc.reset(CanonicalCookie::Create(url, name, value, domain, path,
- creation_time, expiration_time,
- secure, http_only, priority));
+ creation_time, expiration_time, secure,
+ http_only, priority));
if (!cc.get())
return false;
@@ -1117,8 +1090,8 @@ bool CookieMonster::SetCookieWithDetails(const GURL& url,
bool CookieMonster::ImportCookies(const CookieList& list) {
base::AutoLock autolock(lock_);
InitIfNecessary();
- for (net::CookieList::const_iterator iter = list.begin();
- iter != list.end(); ++iter) {
+ for (net::CookieList::const_iterator iter = list.begin(); iter != list.end();
+ ++iter) {
scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter));
net::CookieOptions options;
options.set_include_httponly();
@@ -1139,9 +1112,8 @@ CookieList CookieMonster::GetAllCookies() {
//
// Note that this does not prune cookies to be below our limits (if we've
// exceeded them) the way that calling GarbageCollect() would.
- GarbageCollectExpired(Time::Now(),
- CookieMapItPair(cookies_.begin(), cookies_.end()),
- NULL);
+ GarbageCollectExpired(
+ Time::Now(), CookieMapItPair(cookies_.begin(), cookies_.end()), NULL);
// Copy the CanonicalCookie pointers from the map so that we can use the same
// sorter as elsewhere, then copy the result out.
@@ -1193,8 +1165,9 @@ int CookieMonster::DeleteAll(bool sync_to_store) {
CookieMap::iterator curit = it;
++it;
InternalDeleteCookie(curit, sync_to_store,
- sync_to_store ? DELETE_COOKIE_EXPLICIT :
- DELETE_COOKIE_DONT_RECORD /* Destruction. */);
+ sync_to_store
+ ? DELETE_COOKIE_EXPLICIT
+ : DELETE_COOKIE_DONT_RECORD /* Destruction. */);
++num_deleted;
}
@@ -1213,8 +1186,7 @@ int CookieMonster::DeleteAllCreatedBetween(const Time& delete_begin,
if (cc->CreationDate() >= delete_begin &&
(delete_end.is_null() || cc->CreationDate() < delete_end)) {
- InternalDeleteCookie(curit,
- true, /*sync_to_store*/
+ InternalDeleteCookie(curit, true, /*sync_to_store*/
DELETE_COOKIE_EXPLICIT);
++num_deleted;
}
@@ -1262,7 +1234,6 @@ int CookieMonster::DeleteAllForHost(const GURL& url) {
return DeleteAllCreatedBetweenForHost(Time(), Time::Max(), url);
}
-
bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) {
base::AutoLock autolock(lock_);
@@ -1285,15 +1256,15 @@ void CookieMonster::SetCookieableSchemes(const char* const schemes[],
DCHECK(!initialized_);
cookieable_schemes_.clear();
- cookieable_schemes_.insert(cookieable_schemes_.end(),
- schemes, schemes + num_schemes);
+ cookieable_schemes_.insert(cookieable_schemes_.end(), schemes,
+ schemes + num_schemes);
}
void CookieMonster::SetEnableFileScheme(bool accept) {
// This assumes "file" is always at the end of the array. See the comment
// above kDefaultCookieableSchemes.
- int num_schemes = accept ? kDefaultCookieableSchemesCount :
- kDefaultCookieableSchemesCount - 1;
+ int num_schemes = accept ? kDefaultCookieableSchemesCount
+ : kDefaultCookieableSchemesCount - 1;
SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes);
}
@@ -1381,8 +1352,7 @@ int CookieMonster::DeleteSessionCookies() {
++it;
if (!cc->IsPersistent()) {
- InternalDeleteCookie(curit,
- true, /*sync_to_store*/
+ InternalDeleteCookie(curit, true, /*sync_to_store*/
DELETE_COOKIE_EXPIRED);
++num_deleted;
}
@@ -1467,7 +1437,7 @@ void CookieMonster::OnKeyLoaded(const std::string& key,
// This function does its own separate locking.
StoreLoadedCookies(cookies);
- std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key;
+ std::deque<scoped_refptr<CookieMonsterTask>> tasks_pending_for_key;
// We need to do this repeatedly until no more tasks were added to the queue
// during the period where we release the lock.
@@ -1478,8 +1448,9 @@ void CookieMonster::OnKeyLoaded(const std::string& key,
FROM_HERE_WITH_EXPLICIT_FUNCTION("456373 CookieMonster::OnKeyLoaded1"));
{
base::AutoLock autolock(lock_);
- std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > >
- ::iterator it = tasks_pending_for_key_.find(key);
+ std::map<std::string,
+ std::deque<scoped_refptr<CookieMonsterTask>>>::iterator it =
+ tasks_pending_for_key_.find(key);
if (it == tasks_pending_for_key_.end()) {
keys_loaded_.insert(key);
return;
@@ -1531,15 +1502,15 @@ void CookieMonster::StoreLoadedCookies(
if (ContainsControlCharacter((*it)->Name()) ||
ContainsControlCharacter((*it)->Value())) {
- cookies_with_control_chars.push_back(inserted);
+ cookies_with_control_chars.push_back(inserted);
}
} else {
- LOG(ERROR) << base::StringPrintf("Found cookies with duplicate creation "
- "times in backing store: "
- "{name='%s', domain='%s', path='%s'}",
- (*it)->Name().c_str(),
- (*it)->Domain().c_str(),
- (*it)->Path().c_str());
+ LOG(ERROR) << base::StringPrintf(
+ "Found cookies with duplicate creation "
+ "times in backing store: "
+ "{name='%s', domain='%s', path='%s'}",
+ (*it)->Name().c_str(), (*it)->Domain().c_str(),
+ (*it)->Path().c_str());
// We've been given ownership of the cookie and are throwing it
// away; reclaim the space.
delete (*it);
@@ -1610,10 +1581,9 @@ void CookieMonster::EnsureCookiesMapIsValid() {
histogram_cookie_deletion_cause_->Add(num_duplicates_trimmed);
}
-int CookieMonster::TrimDuplicateCookiesForKey(
- const std::string& key,
- CookieMap::iterator begin,
- CookieMap::iterator end) {
+int CookieMonster::TrimDuplicateCookiesForKey(const std::string& key,
+ CookieMap::iterator begin,
+ CookieMap::iterator end) {
lock_.AssertAcquired();
// Set of cookies ordered by creation time.
@@ -1632,8 +1602,7 @@ int CookieMonster::TrimDuplicateCookiesForKey(
DCHECK_EQ(key, it->first);
CanonicalCookie* cookie = it->second;
- CookieSignature signature(cookie->Name(), cookie->Domain(),
- cookie->Path());
+ CookieSignature signature(cookie->Name(), cookie->Domain(), cookie->Path());
CookieSet& set = equivalent_cookies[signature];
// We found a duplicate!
@@ -1643,8 +1612,8 @@ int CookieMonster::TrimDuplicateCookiesForKey(
// We save the iterator into |cookies_| rather than the actual cookie
// pointer, since we may need to delete it later.
bool insert_success = set.insert(it).second;
- DCHECK(insert_success) <<
- "Duplicate creation times found in duplicate cookie name scan.";
+ DCHECK(insert_success)
+ << "Duplicate creation times found in duplicate cookie name scan.";
}
// If there were no duplicates, we are done!
@@ -1657,8 +1626,7 @@ int CookieMonster::TrimDuplicateCookiesForKey(
// Otherwise, delete all the duplicate cookies, both from our in-memory store
// and from the backing store.
for (EquivalenceMap::iterator it = equivalent_cookies.begin();
- it != equivalent_cookies.end();
- ++it) {
+ it != equivalent_cookies.end(); ++it) {
const CookieSignature& signature = it->first;
CookieSet& dupes = it->second;
@@ -1673,17 +1641,13 @@ int CookieMonster::TrimDuplicateCookiesForKey(
LOG(ERROR) << base::StringPrintf(
"Found %d duplicate cookies for host='%s', "
"with {name='%s', domain='%s', path='%s'}",
- static_cast<int>(dupes.size()),
- key.c_str(),
- signature.name.c_str(),
- signature.domain.c_str(),
- signature.path.c_str());
+ static_cast<int>(dupes.size()), key.c_str(), signature.name.c_str(),
+ signature.domain.c_str(), signature.path.c_str());
// Remove all the cookies identified by |dupes|. It is valid to delete our
// list of iterators one at a time, since |cookies_| is a multimap (they
// don't invalidate existing iterators following deletion).
- for (CookieSet::iterator dupes_it = dupes.begin();
- dupes_it != dupes.end();
+ for (CookieSet::iterator dupes_it = dupes.begin(); dupes_it != dupes.end();
++dupes_it) {
InternalDeleteCookie(*dupes_it, true,
DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE);
@@ -1695,8 +1659,11 @@ int CookieMonster::TrimDuplicateCookiesForKey(
}
// Note: file must be the last scheme.
-const char* const CookieMonster::kDefaultCookieableSchemes[] =
- { "http", "https", "ws", "wss", "file" };
+const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http",
+ "https",
+ "ws",
+ "wss",
+ "file"};
const int CookieMonster::kDefaultCookieableSchemesCount =
arraysize(kDefaultCookieableSchemes);
@@ -1722,8 +1689,8 @@ void CookieMonster::FindCookiesForHostAndDomain(
// Can just dispatch to FindCookiesForKey
const std::string key(GetKey(url.host()));
- FindCookiesForKey(key, url, options, current_time,
- update_access_time, cookies);
+ FindCookiesForKey(key, url, options, current_time, update_access_time,
+ cookies);
}
void CookieMonster::FindCookiesForKey(const std::string& key,
@@ -1735,7 +1702,7 @@ void CookieMonster::FindCookiesForKey(const std::string& key,
lock_.AssertAcquired();
for (CookieMapItPair its = cookies_.equal_range(key);
- its.first != its.second; ) {
+ its.first != its.second;) {
CookieMap::iterator curit = its.first;
CanonicalCookie* cc = curit->second;
++its.first;
@@ -1770,7 +1737,7 @@ bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key,
bool found_equivalent_cookie = false;
bool skipped_httponly = false;
for (CookieMapItPair its = cookies_.equal_range(key);
- its.first != its.second; ) {
+ its.first != its.second;) {
CookieMap::iterator curit = its.first;
CanonicalCookie* cc = curit->second;
++its.first;
@@ -1778,13 +1745,14 @@ bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key,
if (ecc.IsEquivalent(*cc)) {
// We should never have more than one equivalent cookie, since they should
// overwrite each other.
- CHECK(!found_equivalent_cookie) <<
- "Duplicate equivalent cookies found, cookie store is corrupted.";
+ CHECK(!found_equivalent_cookie)
+ << "Duplicate equivalent cookies found, cookie store is corrupted.";
if (skip_httponly && cc->IsHttpOnly()) {
skipped_httponly = true;
} else {
- InternalDeleteCookie(curit, true, already_expired ?
- DELETE_COOKIE_EXPIRED_OVERWRITE : DELETE_COOKIE_OVERWRITE);
+ InternalDeleteCookie(curit, true, already_expired
+ ? DELETE_COOKIE_EXPIRED_OVERWRITE
+ : DELETE_COOKIE_OVERWRITE);
}
found_equivalent_cookie = true;
}
@@ -1804,8 +1772,8 @@ CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie(
CookieMap::iterator inserted =
cookies_.insert(CookieMap::value_type(key, cc));
if (delegate_.get()) {
- delegate_->OnCookieChanged(
- *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT);
+ delegate_->OnCookieChanged(*cc, false,
+ CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT);
}
RunCallbacks(*cc, false);
@@ -1849,8 +1817,8 @@ bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc,
return false;
}
- VLOG(kVlogSetCookies) << "SetCookie() key: " << key << " cc: "
- << (*cc)->DebugString();
+ VLOG(kVlogSetCookies) << "SetCookie() key: " << key
+ << " cc: " << (*cc)->DebugString();
// Realize that we might be setting an expired cookie, and the only point
// was to delete the cookie which we've already done.
@@ -1935,21 +1903,19 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it,
// Domain expiry behavior is unchanged by key/expiry scheme (the
// meaning of the key is different, but that's not visible to this routine).
-int CookieMonster::GarbageCollect(const Time& current,
- const std::string& key) {
+int CookieMonster::GarbageCollect(const Time& current, const std::string& key) {
lock_.AssertAcquired();
int num_deleted = 0;
- Time safe_date(
- Time::Now() - TimeDelta::FromDays(kSafeFromGlobalPurgeDays));
+ Time safe_date(Time::Now() - TimeDelta::FromDays(kSafeFromGlobalPurgeDays));
// Collect garbage for this key, minding cookie priorities.
if (cookies_.count(key) > kDomainMaxCookies) {
VLOG(kVlogGarbageCollection) << "GarbageCollect() key: " << key;
CookieItVector cookie_its;
- num_deleted += GarbageCollectExpired(
- current, cookies_.equal_range(key), &cookie_its);
+ num_deleted +=
+ GarbageCollectExpired(current, cookies_.equal_range(key), &cookie_its);
if (cookie_its.size() > kDomainMaxCookies) {
VLOG(kVlogGarbageCollection) << "Deep Garbage Collect domain.";
size_t purge_goal =
@@ -1962,15 +1928,13 @@ int CookieMonster::GarbageCollect(const Time& current,
// Schematic: [MLLHMHHLMM] => [LLL|MMMM|HHH], with 4 boundaries.
it_bdd[0] = cookie_its.begin();
it_bdd[3] = cookie_its.end();
- it_bdd[1] = PartitionCookieByPriority(it_bdd[0], it_bdd[3],
- COOKIE_PRIORITY_LOW);
+ it_bdd[1] =
+ PartitionCookieByPriority(it_bdd[0], it_bdd[3], COOKIE_PRIORITY_LOW);
it_bdd[2] = PartitionCookieByPriority(it_bdd[1], it_bdd[3],
COOKIE_PRIORITY_MEDIUM);
- size_t quota[3] = {
- kDomainCookiesQuotaLow,
- kDomainCookiesQuotaMedium,
- kDomainCookiesQuotaHigh
- };
+ size_t quota[3] = {kDomainCookiesQuotaLow,
+ kDomainCookiesQuotaMedium,
+ kDomainCookiesQuotaHigh};
// Purge domain cookies in 3 rounds.
// Round 1: consider low-priority cookies only: evict least-recently
@@ -2000,15 +1964,11 @@ int CookieMonster::GarbageCollect(const Time& current,
LowerBoundAccessDate(it_purge_begin, it_purge_end, safe_date);
// Delete cookies accessed before |safe_date|.
num_deleted += GarbageCollectDeleteRange(
- current,
- DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE,
- it_purge_begin,
+ current, DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE, it_purge_begin,
it_purge_middle);
// Delete cookies accessed on or after |safe_date|.
num_deleted += GarbageCollectDeleteRange(
- current,
- DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE,
- it_purge_middle,
+ current, DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE, it_purge_middle,
it_purge_end);
it_purge_begin = it_purge_end;
}
@@ -2018,8 +1978,7 @@ int CookieMonster::GarbageCollect(const Time& current,
// Collect garbage for everything. With firefox style we want to preserve
// cookies accessed in kSafeFromGlobalPurgeDays, otherwise evict.
- if (cookies_.size() > kMaxCookies &&
- earliest_access_time_ < safe_date) {
+ if (cookies_.size() > kMaxCookies && earliest_access_time_ < safe_date) {
VLOG(kVlogGarbageCollection) << "GarbageCollect() everything";
CookieItVector cookie_its;
num_deleted += GarbageCollectExpired(
@@ -2035,16 +1994,12 @@ int CookieMonster::GarbageCollect(const Time& current,
SortLeastRecentlyAccessed(cookie_its.begin(), cookie_its.end(),
purge_goal);
// Find boundary to cookies older than safe_date.
- CookieItVector::iterator global_purge_it =
- LowerBoundAccessDate(cookie_its.begin(),
- cookie_its.begin() + purge_goal,
- safe_date);
+ CookieItVector::iterator global_purge_it = LowerBoundAccessDate(
+ cookie_its.begin(), cookie_its.begin() + purge_goal, safe_date);
// Only delete the old cookies.
- num_deleted += GarbageCollectDeleteRange(
- current,
- DELETE_COOKIE_EVICTED_GLOBAL,
- cookie_its.begin(),
- global_purge_it);
+ num_deleted +=
+ GarbageCollectDeleteRange(current, DELETE_COOKIE_EVICTED_GLOBAL,
+ cookie_its.begin(), global_purge_it);
// Set access day to the oldest cookie that wasn't deleted.
earliest_access_time_ = (*global_purge_it)->second->LastAccessDate();
}
@@ -2053,10 +2008,9 @@ int CookieMonster::GarbageCollect(const Time& current,
return num_deleted;
}
-int CookieMonster::GarbageCollectExpired(
- const Time& current,
- const CookieMapItPair& itpair,
- CookieItVector* cookie_its) {
+int CookieMonster::GarbageCollectExpired(const Time& current,
+ const CookieMapItPair& itpair,
+ CookieItVector* cookie_its) {
if (keep_expired_cookies_)
return 0;
@@ -2078,11 +2032,10 @@ int CookieMonster::GarbageCollectExpired(
return num_deleted;
}
-int CookieMonster::GarbageCollectDeleteRange(
- const Time& current,
- DeletionCause cause,
- CookieItVector::iterator it_begin,
- CookieItVector::iterator it_end) {
+int CookieMonster::GarbageCollectDeleteRange(const Time& current,
+ DeletionCause cause,
+ CookieItVector::iterator it_begin,
+ CookieItVector::iterator it_end) {
for (CookieItVector::iterator it = it_begin; it != it_end; it++) {
histogram_evicted_last_access_minutes_->Add(
(current - (*it)->second->LastAccessDate()).InMinutes());
@@ -2146,8 +2099,8 @@ bool CookieMonster::HasCookieableScheme(const GURL& url) {
}
// The scheme didn't match any in our whitelist.
- VLOG(kVlogPerCookieMonster) << "WARNING: Unsupported cookie scheme: "
- << url.scheme();
+ VLOG(kVlogPerCookieMonster)
+ << "WARNING: Unsupported cookie scheme: " << url.scheme();
return false;
}
@@ -2176,7 +2129,7 @@ void CookieMonster::RecordPeriodicStats(const base::Time& current_time) {
TimeTicks beginning_of_time(TimeTicks::Now());
for (CookieMap::const_iterator it_key = cookies_.begin();
- it_key != cookies_.end(); ) {
+ it_key != cookies_.end();) {
const std::string& key(it_key->first);
int key_count = 0;
@@ -2199,9 +2152,9 @@ void CookieMonster::RecordPeriodicStats(const base::Time& current_time) {
it_key = its_cookies.second;
}
- VLOG(kVlogPeriodic)
- << "Time for recording cookie stats (us): "
- << (TimeTicks::Now() - beginning_of_time).InMicroseconds();
+ VLOG(kVlogPeriodic) << "Time for recording cookie stats (us): "
+ << (TimeTicks::Now() - beginning_of_time)
+ .InMicroseconds();
last_statistic_record_time_ = current_time;
}
@@ -2232,55 +2185,49 @@ void CookieMonster::RecordPeriodicStats(const base::Time& current_time) {
void CookieMonster::InitializeHistograms() {
// From UMA_HISTOGRAM_CUSTOM_COUNTS
histogram_expiration_duration_minutes_ = base::Histogram::FactoryGet(
- "Cookie.ExpirationDurationMinutes",
- 1, kMinutesInTenYears, 50,
+ "Cookie.ExpirationDurationMinutes", 1, kMinutesInTenYears, 50,
base::Histogram::kUmaTargetedHistogramFlag);
histogram_between_access_interval_minutes_ = base::Histogram::FactoryGet(
- "Cookie.BetweenAccessIntervalMinutes",
- 1, kMinutesInTenYears, 50,
+ "Cookie.BetweenAccessIntervalMinutes", 1, kMinutesInTenYears, 50,
base::Histogram::kUmaTargetedHistogramFlag);
histogram_evicted_last_access_minutes_ = base::Histogram::FactoryGet(
- "Cookie.EvictedLastAccessMinutes",
- 1, kMinutesInTenYears, 50,
+ "Cookie.EvictedLastAccessMinutes", 1, kMinutesInTenYears, 50,
base::Histogram::kUmaTargetedHistogramFlag);
histogram_count_ = base::Histogram::FactoryGet(
- "Cookie.Count", 1, 4000, 50,
- base::Histogram::kUmaTargetedHistogramFlag);
- histogram_domain_count_ = base::Histogram::FactoryGet(
- "Cookie.DomainCount", 1, 4000, 50,
- base::Histogram::kUmaTargetedHistogramFlag);
- histogram_etldp1_count_ = base::Histogram::FactoryGet(
- "Cookie.Etldp1Count", 1, 4000, 50,
- base::Histogram::kUmaTargetedHistogramFlag);
- histogram_domain_per_etldp1_count_ = base::Histogram::FactoryGet(
- "Cookie.DomainPerEtldp1Count", 1, 4000, 50,
- base::Histogram::kUmaTargetedHistogramFlag);
+ "Cookie.Count", 1, 4000, 50, base::Histogram::kUmaTargetedHistogramFlag);
+ histogram_domain_count_ =
+ base::Histogram::FactoryGet("Cookie.DomainCount", 1, 4000, 50,
+ base::Histogram::kUmaTargetedHistogramFlag);
+ histogram_etldp1_count_ =
+ base::Histogram::FactoryGet("Cookie.Etldp1Count", 1, 4000, 50,
+ base::Histogram::kUmaTargetedHistogramFlag);
+ histogram_domain_per_etldp1_count_ =
+ base::Histogram::FactoryGet("Cookie.DomainPerEtldp1Count", 1, 4000, 50,
+ base::Histogram::kUmaTargetedHistogramFlag);
// From UMA_HISTOGRAM_COUNTS_10000 & UMA_HISTOGRAM_CUSTOM_COUNTS
- histogram_number_duplicate_db_cookies_ = base::Histogram::FactoryGet(
- "Net.NumDuplicateCookiesInDb", 1, 10000, 50,
- base::Histogram::kUmaTargetedHistogramFlag);
+ histogram_number_duplicate_db_cookies_ =
+ base::Histogram::FactoryGet("Net.NumDuplicateCookiesInDb", 1, 10000, 50,
+ base::Histogram::kUmaTargetedHistogramFlag);
// From UMA_HISTOGRAM_ENUMERATION
histogram_cookie_deletion_cause_ = base::LinearHistogram::FactoryGet(
- "Cookie.DeletionCause", 1,
- DELETE_COOKIE_LAST_ENTRY - 1, DELETE_COOKIE_LAST_ENTRY,
- base::Histogram::kUmaTargetedHistogramFlag);
+ "Cookie.DeletionCause", 1, DELETE_COOKIE_LAST_ENTRY - 1,
+ DELETE_COOKIE_LAST_ENTRY, base::Histogram::kUmaTargetedHistogramFlag);
// From UMA_HISTOGRAM_{CUSTOM_,}TIMES
histogram_time_blocked_on_load_ = base::Histogram::FactoryTimeGet(
- "Cookie.TimeBlockedOnLoad",
- base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(1),
- 50, base::Histogram::kUmaTargetedHistogramFlag);
+ "Cookie.TimeBlockedOnLoad", base::TimeDelta::FromMilliseconds(1),
+ base::TimeDelta::FromMinutes(1), 50,
+ base::Histogram::kUmaTargetedHistogramFlag);
}
-
// The system resolution is not high enough, so we can have multiple
// set cookies that result in the same system time. When this happens, we
// increment by one Time unit. Let's hope computers don't get too fast.
Time CookieMonster::CurrentTime() {
- return std::max(Time::Now(),
- Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1));
+ return std::max(Time::Now(), Time::FromInternalValue(
+ last_time_seen_.ToInternalValue() + 1));
}
bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster(
@@ -2295,8 +2242,7 @@ bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster(
return false;
for (CookieMapItPair its = cookies_.equal_range(key);
- its.first != its.second;
- ++its.first) {
+ its.first != its.second; ++its.first) {
CookieMap::iterator curit = its.first;
CanonicalCookie* cc = curit->second;
@@ -2317,8 +2263,7 @@ bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster(
// Store the copied cookies in |other|.
for (ScopedVector<CanonicalCookie>::const_iterator it =
duplicated_cookies.begin();
- it != duplicated_cookies.end();
- ++it) {
+ it != duplicated_cookies.end(); ++it) {
other->InternalInsertCookie(key, *it, true);
}
@@ -2335,10 +2280,9 @@ bool CookieMonster::loaded() {
}
scoped_ptr<CookieStore::CookieChangedSubscription>
-CookieMonster::AddCallbackForCookie(
- const GURL& gurl,
- const std::string& name,
- const CookieChangedCallback& callback) {
+CookieMonster::AddCallbackForCookie(const GURL& gurl,
+ const std::string& name,
+ const CookieChangedCallback& callback) {
base::AutoLock autolock(lock_);
std::pair<GURL, std::string> key(gurl, name);
if (hook_map_.count(key) == 0)
diff --git a/net/cookies/cookie_monster.h b/net/cookies/cookie_monster.h
index 0f00490..75c6397 100644
--- a/net/cookies/cookie_monster.h
+++ b/net/cookies/cookie_monster.h
@@ -171,7 +171,6 @@ class NET_EXPORT CookieMonster : public CookieStore {
CookiePriority priority,
const SetCookiesCallback& callback);
-
// Returns all the cookies, for use in management UI, etc. This does not mark
// the cookies as having been accessed.
// The returned cookies are ordered by longest path, then by earliest
@@ -195,8 +194,7 @@ class NET_EXPORT CookieMonster : public CookieStore {
// regardless of path. This includes all http_only and secure cookies,
// but does not include any domain cookies that may apply to this host.
// Returns the number of cookies deleted.
- void DeleteAllForHostAsync(const GURL& url,
- const DeleteCallback& callback);
+ void DeleteAllForHostAsync(const GURL& url, const DeleteCallback& callback);
// Deletes one specific cookie.
void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
@@ -325,7 +323,8 @@ class NET_EXPORT CookieMonster : public CookieStore {
private:
// For queueing the cookie monster calls.
class CookieMonsterTask;
- template <typename Result> class DeleteTask;
+ template <typename Result>
+ class DeleteTask;
class DeleteAllCreatedBetweenTask;
class DeleteAllCreatedBetweenForHostTask;
class DeleteAllForHostTask;
@@ -495,9 +494,8 @@ class NET_EXPORT CookieMonster : public CookieStore {
// (eTLD+1). Called when all cookies for the domain key(eTLD+1) have been
// loaded from DB. See PersistentCookieStore::Load for details on the contents
// of cookies.
- void OnKeyLoaded(
- const std::string& key,
- const std::vector<CanonicalCookie*>& cookies);
+ void OnKeyLoaded(const std::string& key,
+ const std::vector<CanonicalCookie*>& cookies);
// Stores the loaded cookies.
void StoreLoadedCookies(const std::vector<CanonicalCookie*>& cookies);
@@ -568,7 +566,8 @@ class NET_EXPORT CookieMonster : public CookieStore {
// the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged
// notifications. Guarantee: All iterators to cookies_ except to the
// deleted entry remain vaild.
- void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store,
+ void InternalDeleteCookie(CookieMap::iterator it,
+ bool sync_to_store,
DeletionCause deletion_cause);
// If the number of cookies for CookieMap key |key|, or globally, are
@@ -618,7 +617,7 @@ class NET_EXPORT CookieMonster : public CookieStore {
// Runs the task if, or defers the task until, the cookies for the given URL
// are loaded.
void DoCookieTaskForURL(const scoped_refptr<CookieMonsterTask>& task_item,
- const GURL& url);
+ const GURL& url);
// Run all cookie changed callbacks that are monitoring |cookie|.
// |removed| is true if the cookie was deleted.
@@ -654,12 +653,12 @@ class NET_EXPORT CookieMonster : public CookieStore {
// Map of domain keys to their associated task queues. These tasks are blocked
// until all cookies for the associated domain key eTLD+1 are loaded from the
// backend store.
- std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask> > >
+ std::map<std::string, std::deque<scoped_refptr<CookieMonsterTask>>>
tasks_pending_for_key_;
// Queues tasks that are blocked until all cookies are loaded from the backend
// store.
- std::queue<scoped_refptr<CookieMonsterTask> > tasks_pending_;
+ std::queue<scoped_refptr<CookieMonsterTask>> tasks_pending_;
scoped_refptr<PersistentCookieStore> store_;
diff --git a/net/cookies/cookie_monster_perftest.cc b/net/cookies/cookie_monster_perftest.cc
index 40dc946..95ccbad 100644
--- a/net/cookies/cookie_monster_perftest.cc
+++ b/net/cookies/cookie_monster_perftest.cc
@@ -52,21 +52,22 @@ class BaseCallback {
has_run_ = false;
}
- void Run() {
- has_run_ = true;
- }
+ void Run() { has_run_ = true; }
bool has_run_;
};
-class SetCookieCallback : public BaseCallback {
+class SetCookieCallback : public BaseCallback {
public:
- void SetCookie(
- CookieMonster* cm, const GURL& gurl, const std::string& cookie) {
- cm->SetCookieWithOptionsAsync(gurl, cookie, options_, base::Bind(
- &SetCookieCallback::Run, base::Unretained(this)));
+ void SetCookie(CookieMonster* cm,
+ const GURL& gurl,
+ const std::string& cookie) {
+ cm->SetCookieWithOptionsAsync(
+ gurl, cookie, options_,
+ base::Bind(&SetCookieCallback::Run, base::Unretained(this)));
WaitForCallback();
}
+
private:
void Run(bool success) {
EXPECT_TRUE(success);
@@ -78,8 +79,9 @@ class SetCookieCallback : public BaseCallback {
class GetCookiesCallback : public BaseCallback {
public:
const std::string& GetCookies(CookieMonster* cm, const GURL& gurl) {
- cm->GetCookiesWithOptionsAsync(gurl, options_, base::Bind(
- &GetCookiesCallback::Run, base::Unretained(this)));
+ cm->GetCookiesWithOptionsAsync(
+ gurl, options_,
+ base::Bind(&GetCookiesCallback::Run, base::Unretained(this)));
WaitForCallback();
return cookies_;
}
@@ -161,8 +163,8 @@ TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) {
// Add a cookie on a bunch of host
base::PerfTimeLogger timer("Cookie_monster_add_many_hosts");
- for (std::vector<GURL>::const_iterator it = gurls.begin();
- it != gurls.end(); ++it) {
+ for (std::vector<GURL>::const_iterator it = gurls.begin(); it != gurls.end();
+ ++it) {
setCookieCallback.SetCookie(cm.get(), *it, cookie);
}
timer.Done();
@@ -170,8 +172,8 @@ TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) {
GetCookiesCallback getCookiesCallback;
base::PerfTimeLogger timer2("Cookie_monster_query_many_hosts");
- for (std::vector<GURL>::const_iterator it = gurls.begin();
- it != gurls.end(); ++it) {
+ for (std::vector<GURL>::const_iterator it = gurls.begin(); it != gurls.end();
+ ++it) {
getCookiesCallback.GetCookies(cm.get(), *it);
}
timer2.Done();
@@ -214,13 +216,12 @@ TEST_F(CookieMonsterTest, TestDomainTree) {
}
}
-
EXPECT_EQ(31u, domain_list.size());
for (std::vector<std::string>::const_iterator it = domain_list.begin();
it != domain_list.end(); it++) {
GURL gurl("https://" + *it + "/");
- const std::string cookie = base::StringPrintf(domain_cookie_format_tree,
- it->c_str());
+ const std::string cookie =
+ base::StringPrintf(domain_cookie_format_tree, it->c_str());
setCookieCallback.SetCookie(cm.get(), gurl, cookie);
}
EXPECT_EQ(31u, cm->GetAllCookies().size());
@@ -261,8 +262,8 @@ TEST_F(CookieMonsterTest, TestDomainLine) {
for (std::vector<std::string>::const_iterator it = domain_list.begin();
it != domain_list.end(); it++) {
GURL gurl("https://" + *it + "/");
- const std::string cookie = base::StringPrintf(domain_cookie_format_line,
- i, it->c_str());
+ const std::string cookie =
+ base::StringPrintf(domain_cookie_format_line, i, it->c_str());
setCookieCallback.SetCookie(cm.get(), gurl, cookie);
}
}
@@ -289,8 +290,8 @@ TEST_F(CookieMonsterTest, TestImport) {
std::string domain_name(base::StringPrintf(".Domain_%d.com", domain_num));
std::string gurl("www" + domain_name);
for (int cookie_num = 0; cookie_num < 50; cookie_num++) {
- std::string cookie_line(base::StringPrintf("Cookie_%d=1; Path=/",
- cookie_num));
+ std::string cookie_line(
+ base::StringPrintf("Cookie_%d=1; Path=/", cookie_num));
AddCookieToList(gurl, cookie_line,
base::Time::FromInternalValue(time_tick++),
&initial_cookies);
@@ -335,40 +336,43 @@ TEST_F(CookieMonsterTest, TestGCTimes) {
size_t num_cookies;
size_t num_old_cookies;
} test_cases[] = {
- {
- // A whole lot of recent cookies; gc shouldn't happen.
- "all_recent",
- CookieMonster::kMaxCookies * 2,
- 0,
- }, {
- // Some old cookies, but still overflowing max.
- "mostly_recent",
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies / 2,
- }, {
- // Old cookies enough to bring us right down to our purge line.
- "balanced",
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1,
- }, {
- "mostly_old",
- // Old cookies enough to bring below our purge line (which we
- // shouldn't do).
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies * 3 / 4,
- }, {
- "less_than_gc_thresh",
- // Few enough cookies that gc shouldn't happen at all.
- CookieMonster::kMaxCookies - 5,
- 0,
- },
+ {
+ // A whole lot of recent cookies; gc shouldn't happen.
+ "all_recent",
+ CookieMonster::kMaxCookies * 2,
+ 0,
+ },
+ {
+ // Some old cookies, but still overflowing max.
+ "mostly_recent",
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies / 2,
+ },
+ {
+ // Old cookies enough to bring us right down to our purge line.
+ "balanced",
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1,
+ },
+ {
+ "mostly_old",
+ // Old cookies enough to bring below our purge line (which we
+ // shouldn't do).
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies * 3 / 4,
+ },
+ {
+ "less_than_gc_thresh",
+ // Few enough cookies that gc shouldn't happen at all.
+ CookieMonster::kMaxCookies - 5,
+ 0,
+ },
};
for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) {
const TestCase& test_case(test_cases[ci]);
- scoped_refptr<CookieMonster> cm(
- CreateMonsterFromStoreForGC(
- test_case.num_cookies, test_case.num_old_cookies,
- CookieMonster::kSafeFromGlobalPurgeDays * 2));
+ scoped_refptr<CookieMonster> cm(CreateMonsterFromStoreForGC(
+ test_case.num_cookies, test_case.num_old_cookies,
+ CookieMonster::kSafeFromGlobalPurgeDays * 2));
GURL gurl("http://google.com");
std::string cookie_line("z=3");
diff --git a/net/cookies/cookie_monster_store_test.cc b/net/cookies/cookie_monster_store_test.cc
index 226242a..dc371ed 100644
--- a/net/cookies/cookie_monster_store_test.cc
+++ b/net/cookies/cookie_monster_store_test.cc
@@ -17,15 +17,14 @@
namespace net {
LoadedCallbackTask::LoadedCallbackTask(LoadedCallback loaded_callback,
std::vector<CanonicalCookie*> cookies)
- : loaded_callback_(loaded_callback),
- cookies_(cookies) {
+ : loaded_callback_(loaded_callback), cookies_(cookies) {
}
-LoadedCallbackTask::~LoadedCallbackTask() {}
+LoadedCallbackTask::~LoadedCallbackTask() {
+}
MockPersistentCookieStore::MockPersistentCookieStore()
- : load_return_value_(true),
- loaded_(false) {
+ : load_return_value_(true), loaded_(false) {
}
void MockPersistentCookieStore::SetLoadExpectation(
@@ -62,19 +61,17 @@ void MockPersistentCookieStore::LoadCookiesForKey(
}
void MockPersistentCookieStore::AddCookie(const CanonicalCookie& cookie) {
- commands_.push_back(
- CookieStoreCommand(CookieStoreCommand::ADD, cookie));
+ commands_.push_back(CookieStoreCommand(CookieStoreCommand::ADD, cookie));
}
void MockPersistentCookieStore::UpdateCookieAccessTime(
const CanonicalCookie& cookie) {
- commands_.push_back(CookieStoreCommand(
- CookieStoreCommand::UPDATE_ACCESS_TIME, cookie));
+ commands_.push_back(
+ CookieStoreCommand(CookieStoreCommand::UPDATE_ACCESS_TIME, cookie));
}
void MockPersistentCookieStore::DeleteCookie(const CanonicalCookie& cookie) {
- commands_.push_back(
- CookieStoreCommand(CookieStoreCommand::REMOVE, cookie));
+ commands_.push_back(CookieStoreCommand(CookieStoreCommand::REMOVE, cookie));
}
void MockPersistentCookieStore::Flush(const base::Closure& callback) {
@@ -85,9 +82,11 @@ void MockPersistentCookieStore::Flush(const base::Closure& callback) {
void MockPersistentCookieStore::SetForceKeepSessionState() {
}
-MockPersistentCookieStore::~MockPersistentCookieStore() {}
+MockPersistentCookieStore::~MockPersistentCookieStore() {
+}
-MockCookieMonsterDelegate::MockCookieMonsterDelegate() {}
+MockCookieMonsterDelegate::MockCookieMonsterDelegate() {
+}
void MockCookieMonsterDelegate::OnCookieChanged(
const CanonicalCookie& cookie,
@@ -97,14 +96,15 @@ void MockCookieMonsterDelegate::OnCookieChanged(
changes_.push_back(notification);
}
-void MockCookieMonsterDelegate::OnLoaded() {}
+void MockCookieMonsterDelegate::OnLoaded() {
+}
-MockCookieMonsterDelegate::~MockCookieMonsterDelegate() {}
+MockCookieMonsterDelegate::~MockCookieMonsterDelegate() {
+}
CanonicalCookie BuildCanonicalCookie(const std::string& key,
const std::string& cookie_line,
const base::Time& creation_time) {
-
// Parse the cookie line.
ParsedCookie pc(cookie_line);
EXPECT_TRUE(pc.IsValid());
@@ -114,24 +114,22 @@ CanonicalCookie BuildCanonicalCookie(const std::string& key,
// functions. Would be nice to export them, and re-use here.
EXPECT_FALSE(pc.HasMaxAge());
EXPECT_TRUE(pc.HasPath());
- base::Time cookie_expires = pc.HasExpires() ?
- cookie_util::ParseCookieTime(pc.Expires()) : base::Time();
+ base::Time cookie_expires = pc.HasExpires()
+ ? cookie_util::ParseCookieTime(pc.Expires())
+ : base::Time();
std::string cookie_path = pc.Path();
- return CanonicalCookie(
- GURL(), pc.Name(), pc.Value(), key, cookie_path,
- creation_time, cookie_expires, creation_time,
- pc.IsSecure(), pc.IsHttpOnly(), pc.Priority());
+ return CanonicalCookie(GURL(), pc.Name(), pc.Value(), key, cookie_path,
+ creation_time, cookie_expires, creation_time,
+ pc.IsSecure(), pc.IsHttpOnly(), pc.Priority());
}
-void AddCookieToList(
- const std::string& key,
- const std::string& cookie_line,
- const base::Time& creation_time,
- std::vector<CanonicalCookie*>* out_list) {
- scoped_ptr<CanonicalCookie> cookie(
- new CanonicalCookie(
- BuildCanonicalCookie(key, cookie_line, creation_time)));
+void AddCookieToList(const std::string& key,
+ const std::string& cookie_line,
+ const base::Time& creation_time,
+ std::vector<CanonicalCookie*>* out_list) {
+ scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(
+ BuildCanonicalCookie(key, cookie_line, creation_time)));
out_list->push_back(cookie.release());
}
@@ -155,7 +153,8 @@ void MockSimplePersistentCookieStore::Load(
loaded_ = true;
}
-void MockSimplePersistentCookieStore::LoadCookiesForKey(const std::string& key,
+void MockSimplePersistentCookieStore::LoadCookiesForKey(
+ const std::string& key,
const LoadedCallback& loaded_callback) {
if (!loaded_) {
Load(loaded_callback);
@@ -197,10 +196,9 @@ void MockSimplePersistentCookieStore::Flush(const base::Closure& callback) {
void MockSimplePersistentCookieStore::SetForceKeepSessionState() {
}
-CookieMonster* CreateMonsterFromStoreForGC(
- int num_cookies,
- int num_old_cookies,
- int days_old) {
+CookieMonster* CreateMonsterFromStoreForGC(int num_cookies,
+ int num_old_cookies,
+ int days_old) {
base::Time current(base::Time::Now());
base::Time past_creation(base::Time::Now() - base::TimeDelta::FromDays(1000));
scoped_refptr<MockSimplePersistentCookieStore> store(
@@ -211,19 +209,19 @@ CookieMonster* CreateMonsterFromStoreForGC(
past_creation + base::TimeDelta::FromMicroseconds(i);
base::Time expiration_time = current + base::TimeDelta::FromDays(30);
base::Time last_access_time =
- (i < num_old_cookies) ? current - base::TimeDelta::FromDays(days_old) :
- current;
+ (i < num_old_cookies) ? current - base::TimeDelta::FromDays(days_old)
+ : current;
- CanonicalCookie cc(
- GURL(), "a", "1", base::StringPrintf("h%05d.izzle", i), "/path",
- creation_time, expiration_time, last_access_time, false, false,
- COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cc(GURL(), "a", "1", base::StringPrintf("h%05d.izzle", i),
+ "/path", creation_time, expiration_time,
+ last_access_time, false, false, COOKIE_PRIORITY_DEFAULT);
store->AddCookie(cc);
}
return new CookieMonster(store.get(), NULL);
}
-MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {}
+MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {
+}
} // namespace net
diff --git a/net/cookies/cookie_monster_store_test.h b/net/cookies/cookie_monster_store_test.h
index 4a3f9a9..4c4d9df 100644
--- a/net/cookies/cookie_monster_store_test.h
+++ b/net/cookies/cookie_monster_store_test.h
@@ -34,9 +34,7 @@ class LoadedCallbackTask
LoadedCallbackTask(LoadedCallback loaded_callback,
std::vector<CanonicalCookie*> cookies);
- void Run() {
- loaded_callback_.Run(cookies_);
- }
+ void Run() { loaded_callback_.Run(cookies_); }
private:
friend class base::RefCountedThreadSafe<LoadedCallbackTask>;
@@ -57,8 +55,7 @@ struct CookieStoreCommand {
};
CookieStoreCommand(Type type, const CanonicalCookie& cookie)
- : type(type),
- cookie(cookie) {}
+ : type(type), cookie(cookie) {}
Type type;
CanonicalCookie cookie;
@@ -67,20 +64,16 @@ struct CookieStoreCommand {
// Implementation of PersistentCookieStore that captures the
// received commands and saves them to a list.
// The result of calls to Load() can be configured using SetLoadExpectation().
-class MockPersistentCookieStore
- : public CookieMonster::PersistentCookieStore {
+class MockPersistentCookieStore : public CookieMonster::PersistentCookieStore {
public:
typedef std::vector<CookieStoreCommand> CommandList;
MockPersistentCookieStore();
- void SetLoadExpectation(
- bool return_value,
- const std::vector<CanonicalCookie*>& result);
+ void SetLoadExpectation(bool return_value,
+ const std::vector<CanonicalCookie*>& result);
- const CommandList& commands() const {
- return commands_;
- }
+ const CommandList& commands() const { return commands_; }
void Load(const LoadedCallback& loaded_callback) override;
@@ -116,8 +109,7 @@ class MockPersistentCookieStore
// Mock for CookieMonsterDelegate
class MockCookieMonsterDelegate : public CookieMonsterDelegate {
public:
- typedef std::pair<CanonicalCookie, bool>
- CookieNotification;
+ typedef std::pair<CanonicalCookie, bool> CookieNotification;
MockCookieMonsterDelegate();
@@ -145,11 +137,10 @@ CanonicalCookie BuildCanonicalCookie(const std::string& key,
const base::Time& creation_time);
// Helper to build a list of CanonicalCookie*s.
-void AddCookieToList(
- const std::string& key,
- const std::string& cookie_line,
- const base::Time& creation_time,
- std::vector<CanonicalCookie*>* out_list);
+void AddCookieToList(const std::string& key,
+ const std::string& cookie_line,
+ const base::Time& creation_time,
+ std::vector<CanonicalCookie*>* out_list);
// Just act like a backing database. Keep cookie information from
// Add/Update/Delete and regurgitate it when Load is called.
@@ -194,10 +185,9 @@ class MockSimplePersistentCookieStore
// Do two SetCookies(). Return whether each of the two SetCookies() took
// longer than |gc_perf_micros| to complete, and how many cookie were
// left in the store afterwards.
-CookieMonster* CreateMonsterFromStoreForGC(
- int num_cookies,
- int num_old_cookies,
- int days_old);
+CookieMonster* CreateMonsterFromStoreForGC(int num_cookies,
+ int num_old_cookies,
+ int days_old);
} // namespace net
diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc
index 224efec..51724a9 100644
--- a/net/cookies/cookie_monster_unittest.cc
+++ b/net/cookies/cookie_monster_unittest.cc
@@ -46,8 +46,9 @@ class NewMockPersistentCookieStore
: public CookieMonster::PersistentCookieStore {
public:
MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback));
- MOCK_METHOD2(LoadCookiesForKey, void(const std::string& key,
- const LoadedCallback& loaded_callback));
+ MOCK_METHOD2(LoadCookiesForKey,
+ void(const std::string& key,
+ const LoadedCallback& loaded_callback));
MOCK_METHOD1(AddCookie, void(const CanonicalCookie& cc));
MOCK_METHOD1(UpdateCookieAccessTime, void(const CanonicalCookie& cc));
MOCK_METHOD1(DeleteCookie, void(const CanonicalCookie& cc));
@@ -64,8 +65,7 @@ class NewMockPersistentCookieStore
const char kTopLevelDomainPlus1[] = "http://www.harvard.edu";
const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu";
const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu";
-const char kTopLevelDomainPlus3[] =
- "http://www.bourbaki.math.harvard.edu";
+const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu";
const char kOtherDomain[] = "http://www.mit.edu";
const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle";
@@ -91,12 +91,12 @@ struct CookieMonsterTestTraits {
return new CookieMonster(NULL, NULL);
}
- static const bool is_cookie_monster = true;
- static const bool supports_http_only = true;
- static const bool supports_non_dotted_domains = true;
- static const bool supports_trailing_dots = true;
- static const bool filters_schemes = true;
- static const bool has_path_prefix_bug = false;
+ static const bool is_cookie_monster = true;
+ static const bool supports_http_only = true;
+ static const bool supports_non_dotted_domains = true;
+ static const bool supports_trailing_dots = true;
+ static const bool filters_schemes = true;
+ static const bool has_path_prefix_bug = false;
static const int creation_time_granularity_in_ms = 0;
};
@@ -110,25 +110,21 @@ INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster,
class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
protected:
-
CookieList GetAllCookies(CookieMonster* cm) {
DCHECK(cm);
GetCookieListCallback callback;
cm->GetAllCookiesAsync(
- base::Bind(&GetCookieListCallback::Run,
- base::Unretained(&callback)));
+ base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.cookies();
}
- CookieList GetAllCookiesForURL(CookieMonster* cm,
- const GURL& url) {
+ CookieList GetAllCookiesForURL(CookieMonster* cm, const GURL& url) {
DCHECK(cm);
GetCookieListCallback callback;
- cm->GetAllCookiesForURLAsync(
- url, base::Bind(&GetCookieListCallback::Run,
- base::Unretained(&callback)));
+ cm->GetAllCookiesForURLAsync(url, base::Bind(&GetCookieListCallback::Run,
+ base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.cookies();
@@ -140,8 +136,8 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
DCHECK(cm);
GetCookieListCallback callback;
cm->GetAllCookiesForURLWithOptionsAsync(
- url, options, base::Bind(&GetCookieListCallback::Run,
- base::Unretained(&callback)));
+ url, options,
+ base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.cookies();
@@ -161,37 +157,32 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
ResultSavingCookieCallback<bool> callback;
cm->SetCookieWithDetailsAsync(
url, name, value, domain, path, expiration_time, secure, http_only,
- priority,
- base::Bind(
- &ResultSavingCookieCallback<bool>::Run,
- base::Unretained(&callback)));
+ priority, base::Bind(&ResultSavingCookieCallback<bool>::Run,
+ base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.result();
}
- int DeleteAll(CookieMonster*cm) {
+ int DeleteAll(CookieMonster* cm) {
DCHECK(cm);
ResultSavingCookieCallback<int> callback;
- cm->DeleteAllAsync(
- base::Bind(
- &ResultSavingCookieCallback<int>::Run,
- base::Unretained(&callback)));
+ cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.result();
}
- int DeleteAllCreatedBetween(CookieMonster*cm,
+ int DeleteAllCreatedBetween(CookieMonster* cm,
const base::Time& delete_begin,
const base::Time& delete_end) {
DCHECK(cm);
ResultSavingCookieCallback<int> callback;
cm->DeleteAllCreatedBetweenAsync(
delete_begin, delete_end,
- base::Bind(
- &ResultSavingCookieCallback<int>::Run,
- base::Unretained(&callback)));
+ base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.result();
@@ -205,21 +196,19 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
ResultSavingCookieCallback<int> callback;
cm->DeleteAllCreatedBetweenForHostAsync(
delete_begin, delete_end, url,
- base::Bind(
- &ResultSavingCookieCallback<int>::Run,
- base::Unretained(&callback)));
+ base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.result();
}
- int DeleteAllForHost(CookieMonster* cm,
- const GURL& url) {
+ int DeleteAllForHost(CookieMonster* cm, const GURL& url) {
DCHECK(cm);
ResultSavingCookieCallback<int> callback;
- cm->DeleteAllForHostAsync(
- url, base::Bind(&ResultSavingCookieCallback<int>::Run,
- base::Unretained(&callback)));
+ cm->DeleteAllForHostAsync(url,
+ base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.result();
@@ -229,9 +218,8 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
DCHECK(cm);
ResultSavingCookieCallback<bool> callback;
cm->DeleteCanonicalCookieAsync(
- cookie,
- base::Bind(&ResultSavingCookieCallback<bool>::Run,
- base::Unretained(&callback)));
+ cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run,
+ base::Unretained(&callback)));
RunFor(kTimeout);
EXPECT_TRUE(callback.did_run());
return callback.result();
@@ -257,146 +245,64 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
// * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2)
// Domain cookies
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_1,
- "dom_1",
- "X",
- ".harvard.edu",
- "/",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2,
- "dom_2",
- "X",
- ".math.harvard.edu",
- "/",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_3,
- "dom_3",
- "X",
- ".bourbaki.math.harvard.edu",
- "/",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu",
+ "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2, "dom_2", "X",
+ ".math.harvard.edu", "/", base::Time(), false, false,
+ COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_3, "dom_3", "X",
+ ".bourbaki.math.harvard.edu", "/", base::Time(), false, false,
+ COOKIE_PRIORITY_DEFAULT));
// Host cookies
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_1,
- "host_1",
- "X",
- std::string(),
- "/",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2,
- "host_2",
- "X",
- std::string(),
- "/",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_3,
- "host_3",
- "X",
- std::string(),
- "/",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_1, "host_1", "X", std::string(),
+ "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2, "host_2", "X", std::string(),
+ "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(),
+ "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT));
// Http_only cookie
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2,
- "httpo_check",
- "X",
- std::string(),
- "/",
- base::Time(),
- false,
- true,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2, "httpo_check", "X",
+ std::string(), "/", base::Time(), false, true,
+ COOKIE_PRIORITY_DEFAULT));
// Secure cookies
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2_secure,
- "sec_dom",
- "X",
- ".math.harvard.edu",
- "/",
- base::Time(),
- true,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2_secure,
- "sec_host",
- "X",
- std::string(),
- "/",
- base::Time(),
- true,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X",
+ ".math.harvard.edu", "/", base::Time(), true, false,
+ COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X",
+ std::string(), "/", base::Time(), true, false,
+ COOKIE_PRIORITY_DEFAULT));
// Domain path cookies
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2,
- "dom_path_1",
- "X",
- ".math.harvard.edu",
- "/dir1",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2,
- "dom_path_2",
- "X",
- ".math.harvard.edu",
- "/dir1/dir2",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2, "dom_path_1", "X",
+ ".math.harvard.edu", "/dir1", base::Time(), false, false,
+ COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2, "dom_path_2", "X",
+ ".math.harvard.edu", "/dir1/dir2", base::Time(), false, false,
+ COOKIE_PRIORITY_DEFAULT));
// Host path cookies
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2,
- "host_path_1",
- "X",
- std::string(),
- "/dir1",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
- url_top_level_domain_plus_2,
- "host_path_2",
- "X",
- std::string(),
- "/dir1/dir2",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2, "host_path_1", "X",
+ std::string(), "/dir1", base::Time(), false, false,
+ COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(this->SetCookieWithDetails(
+ cm.get(), url_top_level_domain_plus_2, "host_path_2", "X",
+ std::string(), "/dir1/dir2", base::Time(), false, false,
+ COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ(13U, this->GetAllCookies(cm.get()).size());
}
@@ -410,8 +316,7 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
const std::string& domain,
const std::string& name) {
CookieList cookies = this->GetAllCookies(cm);
- for (CookieList::iterator it = cookies.begin();
- it != cookies.end(); ++it)
+ for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it)
if (it->Domain() == domain && it->Name() == name)
return this->DeleteCanonicalCookie(cm, *it);
return false;
@@ -554,8 +459,7 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
// Validate each priority.
size_t expected_count[3] = {
- expected_low_count, expected_medium_count, expected_high_count
- };
+ expected_low_count, expected_medium_count, expected_high_count};
for (int i = 0; i < 3; ++i) {
DCHECK_LE(surviving_id_list[i].size(), id_list[i].size());
EXPECT_EQ(expected_count[i], surviving_id_list[i].size());
@@ -574,7 +478,7 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
// Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint.
DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies);
DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
- CookieMonster::kDomainPurgeCookies);
+ CookieMonster::kDomainPurgeCookies);
DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow);
DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium);
DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh);
@@ -610,8 +514,8 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
// Round 1 => 10L; round 2 => 10M; round 3 => 11H.
TestPriorityCookieCase(cm.get(), "21H 60M 40L 60H", 30U, 50U, 70U);
// Round 1 => 10L; round 2 => 11M, 10L; round 3 => none.
- TestPriorityCookieCase(
- cm.get(), "11H 10M 20L 110M 20L 10H", 20U, 109U, 21U);
+ TestPriorityCookieCase(cm.get(), "11H 10M 20L 110M 20L 10H", 20U, 109U,
+ 21U);
// Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H.
TestPriorityCookieCase(cm.get(), "11L 10M 140H 10M 10L", 10U, 10U, 130U);
// Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H.
@@ -633,7 +537,8 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
// TODO(erikwright): Replace the other callbacks and synchronous helper methods
// in this test suite with these Mocks.
-template<typename T, typename C> class MockCookieCallback {
+template <typename T, typename C>
+class MockCookieCallback {
public:
C AsCallback() {
return base::Bind(&T::Invoke, base::Unretained(static_cast<T*>(this)));
@@ -641,42 +546,41 @@ template<typename T, typename C> class MockCookieCallback {
};
class MockGetCookiesCallback
- : public MockCookieCallback<MockGetCookiesCallback,
- CookieStore::GetCookiesCallback> {
+ : public MockCookieCallback<MockGetCookiesCallback,
+ CookieStore::GetCookiesCallback> {
public:
MOCK_METHOD1(Invoke, void(const std::string& cookies));
};
class MockSetCookiesCallback
- : public MockCookieCallback<MockSetCookiesCallback,
- CookieStore::SetCookiesCallback> {
+ : public MockCookieCallback<MockSetCookiesCallback,
+ CookieStore::SetCookiesCallback> {
public:
MOCK_METHOD1(Invoke, void(bool success));
};
-class MockClosure
- : public MockCookieCallback<MockClosure, base::Closure> {
+class MockClosure : public MockCookieCallback<MockClosure, base::Closure> {
public:
MOCK_METHOD0(Invoke, void(void));
};
class MockGetCookieListCallback
- : public MockCookieCallback<MockGetCookieListCallback,
- CookieMonster::GetCookieListCallback> {
+ : public MockCookieCallback<MockGetCookieListCallback,
+ CookieMonster::GetCookieListCallback> {
public:
MOCK_METHOD1(Invoke, void(const CookieList& cookies));
};
class MockDeleteCallback
- : public MockCookieCallback<MockDeleteCallback,
- CookieMonster::DeleteCallback> {
+ : public MockCookieCallback<MockDeleteCallback,
+ CookieMonster::DeleteCallback> {
public:
MOCK_METHOD1(Invoke, void(int num_deleted));
};
class MockDeleteCookieCallback
- : public MockCookieCallback<MockDeleteCookieCallback,
- CookieMonster::DeleteCookieCallback> {
+ : public MockCookieCallback<MockDeleteCookieCallback,
+ CookieMonster::DeleteCookieCallback> {
public:
MOCK_METHOD1(Invoke, void(bool success));
};
@@ -704,23 +608,25 @@ ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) {
cookie_monster->DeleteCookieAsync(url, name, callback->AsCallback());
}
ACTION_P3(GetCookiesAction, cookie_monster, url, callback) {
- cookie_monster->GetCookiesWithOptionsAsync(
- url, CookieOptions(), callback->AsCallback());
+ cookie_monster->GetCookiesWithOptionsAsync(url, CookieOptions(),
+ callback->AsCallback());
}
ACTION_P4(SetCookieAction, cookie_monster, url, cookie_line, callback) {
- cookie_monster->SetCookieWithOptionsAsync(
- url, cookie_line, CookieOptions(), callback->AsCallback());
+ cookie_monster->SetCookieWithOptionsAsync(url, cookie_line, CookieOptions(),
+ callback->AsCallback());
}
ACTION_P4(DeleteAllCreatedBetweenAction,
- cookie_monster, delete_begin, delete_end, callback) {
- cookie_monster->DeleteAllCreatedBetweenAsync(
- delete_begin, delete_end, callback->AsCallback());
+ cookie_monster,
+ delete_begin,
+ delete_end,
+ callback) {
+ cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
+ callback->AsCallback());
}
ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) {
cookie_monster->SetCookieWithDetailsAsync(
cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time,
- cc.secure, cc.http_only, cc.priority,
- callback->AsCallback());
+ cc.secure, cc.http_only, cc.priority, callback->AsCallback());
}
ACTION_P2(GetAllCookiesAction, cookie_monster, callback) {
@@ -740,8 +646,8 @@ ACTION_P2(DeleteAllAction, cookie_monster, callback) {
}
ACTION_P3(GetAllCookiesForUrlWithOptionsAction, cookie_monster, url, callback) {
- cookie_monster->GetAllCookiesForURLWithOptionsAsync(
- url, CookieOptions(), callback->AsCallback());
+ cookie_monster->GetAllCookiesForURLWithOptionsAsync(url, CookieOptions(),
+ callback->AsCallback());
}
ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) {
@@ -834,8 +740,8 @@ class DeferredCookieTaskTest : public CookieMonsterTest {
if (quit_queue)
EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_))
.WillOnce(
- testing::DoAll(PushCallbackAction(&loaded_for_key_callbacks_),
- QuitCurrentMessageLoop()));
+ testing::DoAll(PushCallbackAction(&loaded_for_key_callbacks_),
+ QuitCurrentMessageLoop()));
else
EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_))
.WillOnce(PushCallbackAction(&loaded_for_key_callbacks_));
@@ -859,7 +765,7 @@ class DeferredCookieTaskTest : public CookieMonsterTest {
// Stores the callback passed from the CookieMonster to the
// PersistentCookieStore::LoadCookiesForKey
std::queue<CookieMonster::PersistentCookieStore::LoadedCallback>
- loaded_for_key_callbacks_;
+ loaded_for_key_callbacks_;
// Stores the CookieMonster under test.
scoped_refptr<CookieMonster> cookie_monster_;
@@ -874,15 +780,17 @@ TEST_F(DeferredCookieTaskTest, DeferredGetCookies) {
MockGetCookiesCallback get_cookies_callback;
- BeginWithForDomainKey("google.izzle", GetCookiesAction(
- &cookie_monster(), url_google_, &get_cookies_callback));
+ BeginWithForDomainKey(
+ "google.izzle",
+ GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback));
WaitForLoadCall();
- EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce(
- GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback));
- EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
+ .WillOnce(GetCookiesAction(&cookie_monster(), url_google_,
+ &get_cookies_callback));
+ EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -890,16 +798,17 @@ TEST_F(DeferredCookieTaskTest, DeferredGetCookies) {
TEST_F(DeferredCookieTaskTest, DeferredSetCookie) {
MockSetCookiesCallback set_cookies_callback;
- BeginWithForDomainKey("google.izzle", SetCookieAction(
- &cookie_monster(), url_google_, "A=B", &set_cookies_callback));
+ BeginWithForDomainKey("google.izzle",
+ SetCookieAction(&cookie_monster(), url_google_, "A=B",
+ &set_cookies_callback));
WaitForLoadCall();
- EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(
- SetCookieAction(
- &cookie_monster(), url_google_, "X=Y", &set_cookies_callback));
- EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(set_cookies_callback, Invoke(true))
+ .WillOnce(SetCookieAction(&cookie_monster(), url_google_, "X=Y",
+ &set_cookies_callback));
+ EXPECT_CALL(set_cookies_callback, Invoke(true))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -907,16 +816,17 @@ TEST_F(DeferredCookieTaskTest, DeferredSetCookie) {
TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) {
MockClosure delete_cookie_callback;
- BeginWithForDomainKey("google.izzle", DeleteCookieAction(
- &cookie_monster(), url_google_, "A", &delete_cookie_callback));
+ BeginWithForDomainKey("google.izzle",
+ DeleteCookieAction(&cookie_monster(), url_google_, "A",
+ &delete_cookie_callback));
WaitForLoadCall();
- EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce(
- DeleteCookieAction(
- &cookie_monster(), url_google_, "X", &delete_cookie_callback));
- EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(delete_cookie_callback, Invoke())
+ .WillOnce(DeleteCookieAction(&cookie_monster(), url_google_, "X",
+ &delete_cookie_callback));
+ EXPECT_CALL(delete_cookie_callback, Invoke())
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -924,24 +834,35 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) {
TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) {
MockSetCookiesCallback set_cookies_callback;
- CookiesInputInfo cookie_info = {
- url_google_foo_, "A", "B", std::string(), "/foo",
- base::Time(), false, false, COOKIE_PRIORITY_DEFAULT
- };
- BeginWithForDomainKey("google.izzle", SetCookieWithDetailsAction(
- &cookie_monster(), cookie_info, &set_cookies_callback));
+ CookiesInputInfo cookie_info = {url_google_foo_,
+ "A",
+ "B",
+ std::string(),
+ "/foo",
+ base::Time(),
+ false,
+ false,
+ COOKIE_PRIORITY_DEFAULT};
+ BeginWithForDomainKey(
+ "google.izzle", SetCookieWithDetailsAction(&cookie_monster(), cookie_info,
+ &set_cookies_callback));
WaitForLoadCall();
- CookiesInputInfo cookie_info_exp = {
- url_google_foo_, "A", "B", std::string(), "/foo",
- base::Time(), false, false, COOKIE_PRIORITY_DEFAULT
- };
- EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(
- SetCookieWithDetailsAction(
- &cookie_monster(), cookie_info_exp, &set_cookies_callback));
- EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(
- QuitCurrentMessageLoop());
+ CookiesInputInfo cookie_info_exp = {url_google_foo_,
+ "A",
+ "B",
+ std::string(),
+ "/foo",
+ base::Time(),
+ false,
+ false,
+ COOKIE_PRIORITY_DEFAULT};
+ EXPECT_CALL(set_cookies_callback, Invoke(true))
+ .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp,
+ &set_cookies_callback));
+ EXPECT_CALL(set_cookies_callback, Invoke(true))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -953,15 +874,15 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) {
MockGetCookieListCallback get_cookie_list_callback;
- BeginWith(GetAllCookiesAction(
- &cookie_monster(), &get_cookie_list_callback));
+ BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
WaitForLoadCall();
- EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce(
- GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
- EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
+ .WillOnce(
+ GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback));
+ EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -973,16 +894,17 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) {
MockGetCookieListCallback get_cookie_list_callback;
- BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlAction(
- &cookie_monster(), url_google_, &get_cookie_list_callback));
+ BeginWithForDomainKey(
+ "google.izzle", GetAllCookiesForUrlAction(&cookie_monster(), url_google_,
+ &get_cookie_list_callback));
WaitForLoadCall();
- EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce(
- GetAllCookiesForUrlAction(
- &cookie_monster(), url_google_, &get_cookie_list_callback));
- EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
+ .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(), url_google_,
+ &get_cookie_list_callback));
+ EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -995,15 +917,16 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) {
MockGetCookieListCallback get_cookie_list_callback;
BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlWithOptionsAction(
- &cookie_monster(), url_google_, &get_cookie_list_callback));
+ &cookie_monster(), url_google_,
+ &get_cookie_list_callback));
WaitForLoadCall();
- EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce(
- GetAllCookiesForUrlWithOptionsAction(
+ EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
+ .WillOnce(GetAllCookiesForUrlWithOptionsAction(
&cookie_monster(), url_google_, &get_cookie_list_callback));
- EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -1011,15 +934,14 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) {
TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) {
MockDeleteCallback delete_callback;
- BeginWith(DeleteAllAction(
- &cookie_monster(), &delete_callback));
+ BeginWith(DeleteAllAction(&cookie_monster(), &delete_callback));
WaitForLoadCall();
- EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
- DeleteAllAction(&cookie_monster(), &delete_callback));
- EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(delete_callback, Invoke(false))
+ .WillOnce(DeleteAllAction(&cookie_monster(), &delete_callback));
+ EXPECT_CALL(delete_callback, Invoke(false))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -1027,17 +949,17 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) {
TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) {
MockDeleteCallback delete_callback;
- BeginWith(DeleteAllCreatedBetweenAction(
- &cookie_monster(), base::Time(), base::Time::Now(), &delete_callback));
+ BeginWith(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(),
+ base::Time::Now(), &delete_callback));
WaitForLoadCall();
- EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
- DeleteAllCreatedBetweenAction(
- &cookie_monster(), base::Time(), base::Time::Now(),
- &delete_callback));
- EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(delete_callback, Invoke(false))
+ .WillOnce(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(),
+ base::Time::Now(),
+ &delete_callback));
+ EXPECT_CALL(delete_callback, Invoke(false))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -1045,37 +967,38 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) {
TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) {
MockDeleteCallback delete_callback;
- BeginWithForDomainKey("google.izzle", DeleteAllForHostAction(
- &cookie_monster(), url_google_, &delete_callback));
+ BeginWithForDomainKey(
+ "google.izzle",
+ DeleteAllForHostAction(&cookie_monster(), url_google_, &delete_callback));
WaitForLoadCall();
- EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
- DeleteAllForHostAction(
- &cookie_monster(), url_google_, &delete_callback));
- EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(delete_callback, Invoke(false))
+ .WillOnce(DeleteAllForHostAction(&cookie_monster(), url_google_,
+ &delete_callback));
+ EXPECT_CALL(delete_callback, Invoke(false))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
std::vector<CanonicalCookie*> cookies;
- CanonicalCookie cookie = BuildCanonicalCookie(
- "www.google.com", "X=1; path=/", base::Time::Now());
+ CanonicalCookie cookie =
+ BuildCanonicalCookie("www.google.com", "X=1; path=/", base::Time::Now());
MockDeleteCookieCallback delete_cookie_callback;
- BeginWith(DeleteCanonicalCookieAction(
- &cookie_monster(), cookie, &delete_cookie_callback));
+ BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), cookie,
+ &delete_cookie_callback));
WaitForLoadCall();
- EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce(
- DeleteCanonicalCookieAction(
- &cookie_monster(), cookie, &delete_cookie_callback));
- EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(delete_cookie_callback, Invoke(false))
+ .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), cookie,
+ &delete_cookie_callback));
+ EXPECT_CALL(delete_cookie_callback, Invoke(false))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -1083,15 +1006,15 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) {
MockDeleteCallback delete_callback;
- BeginWith(DeleteSessionCookiesAction(
- &cookie_monster(), &delete_callback));
+ BeginWith(DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
WaitForLoadCall();
- EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
- DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
- EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(delete_callback, Invoke(false))
+ .WillOnce(
+ DeleteSessionCookiesAction(&cookie_monster(), &delete_callback));
+ EXPECT_CALL(delete_callback, Invoke(false))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
@@ -1108,29 +1031,28 @@ TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) {
MockSetCookiesCallback set_cookies_callback;
MockGetCookiesCallback get_cookies_callback_deferred;
- EXPECT_CALL(*this, Begin()).WillOnce(testing::DoAll(
- GetCookiesAction(
- &cookie_monster(), url_google_, &get_cookies_callback),
- SetCookieAction(
- &cookie_monster(), url_google_, "A=B", &set_cookies_callback)));
+ EXPECT_CALL(*this, Begin())
+ .WillOnce(testing::DoAll(GetCookiesAction(&cookie_monster(), url_google_,
+ &get_cookies_callback),
+ SetCookieAction(&cookie_monster(), url_google_,
+ "A=B", &set_cookies_callback)));
ExpectLoadCall();
ExpectLoadForKeyCall("google.izzle", false);
Begin();
WaitForLoadCall();
- EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce(
- GetCookiesAction(
- &cookie_monster(), url_google_, &get_cookies_callback_deferred));
+ EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
+ .WillOnce(GetCookiesAction(&cookie_monster(), url_google_,
+ &get_cookies_callback_deferred));
EXPECT_CALL(set_cookies_callback, Invoke(true));
- EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")).WillOnce(
- QuitCurrentMessageLoop());
+ EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1"))
+ .WillOnce(QuitCurrentMessageLoop());
CompleteLoadingAndWait();
}
TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
- scoped_refptr<MockPersistentCookieStore> store(
- new MockPersistentCookieStore);
+ scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
CookieOptions options;
options.set_include_httponly();
@@ -1148,8 +1070,7 @@ TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
// Create a persistent cookie.
EXPECT_TRUE(SetCookie(
- cm.get(),
- url_google_,
+ cm.get(), 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);
@@ -1166,9 +1087,8 @@ TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
Time now = Time::Now();
// Nothing has been added so nothing should be deleted.
- EXPECT_EQ(
- 0,
- DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time()));
+ EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99),
+ Time()));
// Create 3 cookies with creation date of today, yesterday and the day before.
EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now));
@@ -1182,10 +1102,8 @@ TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
now - TimeDelta::FromDays(7)));
// Try to delete threedays and the daybefore.
- EXPECT_EQ(2,
- DeleteAllCreatedBetween(cm.get(),
- now - TimeDelta::FromDays(3),
- now - TimeDelta::FromDays(1)));
+ EXPECT_EQ(2, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3),
+ now - TimeDelta::FromDays(1)));
// Try to delete yesterday, also make sure that delete_end is not
// inclusive.
@@ -1274,10 +1192,9 @@ TEST_F(CookieMonsterTest, GetAllCookiesForURL) {
EXPECT_TRUE(
SetCookieWithOptions(cm.get(), url_google_, "A=B; httponly", options));
- EXPECT_TRUE(SetCookieWithOptions(
- cm.get(), url_google_, "C=D; domain=.google.izzle", options));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(),
- url_google_secure_,
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_,
+ "C=D; domain=.google.izzle", options));
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_secure_,
"E=F; domain=.google.izzle; secure",
options));
@@ -1337,10 +1254,10 @@ TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
CookieOptions options;
- EXPECT_TRUE(SetCookieWithOptions(
- cm.get(), url_google_foo_, "A=B; path=/foo;", options));
- EXPECT_TRUE(SetCookieWithOptions(
- cm.get(), url_google_bar_, "C=D; path=/bar;", options));
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_foo_, "A=B; path=/foo;",
+ options));
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_bar_, "C=D; path=/bar;",
+ options));
EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "E=F;", options));
CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_);
@@ -1385,8 +1302,7 @@ TEST_F(CookieMonsterTest, DeleteCookieByName) {
CookieList cookies = GetAllCookies(cm.get());
size_t expected_size = 4;
EXPECT_EQ(expected_size, cookies.size());
- for (CookieList::iterator it = cookies.begin();
- it != cookies.end(); ++it) {
+ for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) {
EXPECT_NE("A1", it->Value());
EXPECT_NE("A2", it->Value());
}
@@ -1397,14 +1313,10 @@ TEST_F(CookieMonsterTest, ImportCookiesFromCookieMonster) {
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));
- EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_,
- "A3=F;",
- options));
+ "A2=D; path=/bar;", options));
+ EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, "A3=F;", options));
CookieList cookies_1 = GetAllCookies(cm_1.get());
scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL));
@@ -1435,8 +1347,7 @@ TEST_F(CookieMonsterTest, ImportCookiesFromCookieMonster) {
//
// This is a regression test for: http://crbug.com/17855.
TEST_F(CookieMonsterTest, DontImportDuplicateCookies) {
- scoped_refptr<MockPersistentCookieStore> store(
- new MockPersistentCookieStore);
+ scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
// We will fill some initial cookies into the PersistentCookieStore,
// to simulate a database with 4 duplicates. Note that we need to
@@ -1451,24 +1362,20 @@ TEST_F(CookieMonsterTest, DontImportDuplicateCookies) {
AddCookieToList("www.google.com",
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
- Time::Now() + TimeDelta::FromDays(3),
- &initial_cookies);
+ Time::Now() + TimeDelta::FromDays(3), &initial_cookies);
AddCookieToList("www.google.com",
"X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
- Time::Now() + TimeDelta::FromDays(1),
- &initial_cookies);
+ Time::Now() + TimeDelta::FromDays(1), &initial_cookies);
// ===> This one is the WINNER (biggest creation time). <====
AddCookieToList("www.google.com",
"X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
- Time::Now() + TimeDelta::FromDays(4),
- &initial_cookies);
+ Time::Now() + TimeDelta::FromDays(4), &initial_cookies);
AddCookieToList("www.google.com",
"X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
- Time::Now(),
- &initial_cookies);
+ Time::Now(), &initial_cookies);
// Insert 2 cookies with name "X" on path "/2", with varying creation
// dates. We expect only the most recent one to be preserved the import.
@@ -1476,19 +1383,16 @@ TEST_F(CookieMonsterTest, DontImportDuplicateCookies) {
// ===> This one is the WINNER (biggest creation time). <====
AddCookieToList("www.google.com",
"X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT",
- Time::Now() + TimeDelta::FromDays(9),
- &initial_cookies);
+ Time::Now() + TimeDelta::FromDays(9), &initial_cookies);
AddCookieToList("www.google.com",
"X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT",
- Time::Now() + TimeDelta::FromDays(2),
- &initial_cookies);
+ Time::Now() + TimeDelta::FromDays(2), &initial_cookies);
// Insert 1 cookie with name "Y" on path "/".
AddCookieToList("www.google.com",
"Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
- Time::Now() + TimeDelta::FromDays(10),
- &initial_cookies);
+ Time::Now() + TimeDelta::FromDays(10), &initial_cookies);
// Inject our initial cookies into the mock PersistentCookieStore.
store->SetLoadExpectation(true, initial_cookies);
@@ -1518,8 +1422,7 @@ TEST_F(CookieMonsterTest, DontImportDuplicateCookies) {
//
// This is a regression test for: http://crbug.com/43188.
TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) {
- scoped_refptr<MockPersistentCookieStore> store(
- new MockPersistentCookieStore);
+ scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
Time now(Time::Now());
Time earlier(now - TimeDelta::FromDays(1));
@@ -1555,8 +1458,7 @@ TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) {
}
TEST_F(CookieMonsterTest, CookieMonsterDelegate) {
- scoped_refptr<MockPersistentCookieStore> store(
- new MockPersistentCookieStore);
+ scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
scoped_refptr<MockCookieMonsterDelegate> delegate(
new MockCookieMonsterDelegate);
scoped_refptr<CookieMonster> cm(
@@ -1595,8 +1497,7 @@ TEST_F(CookieMonsterTest, CookieMonsterDelegate) {
EXPECT_EQ(0u, delegate->changes().size());
// Insert a cookie "a" for path "/path1"
- EXPECT_TRUE(SetCookie(cm.get(),
- url_google_,
+ EXPECT_TRUE(SetCookie(cm.get(), url_google_,
"a=val1; path=/path1; "
"expires=Mon, 18-Apr-22 22:50:13 GMT"));
ASSERT_EQ(1u, store->commands().size());
@@ -1612,8 +1513,7 @@ TEST_F(CookieMonsterTest, CookieMonsterDelegate) {
// overwrite the non-http-only version.
CookieOptions allow_httponly;
allow_httponly.set_include_httponly();
- EXPECT_TRUE(SetCookieWithOptions(cm.get(),
- url_google_,
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_,
"a=val2; path=/path1; httponly; "
"expires=Mon, 18-Apr-22 22:50:14 GMT",
allow_httponly));
@@ -1635,88 +1535,32 @@ TEST_F(CookieMonsterTest, CookieMonsterDelegate) {
TEST_F(CookieMonsterTest, SetCookieWithDetails) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookieWithDetails(cm.get(),
- url_google_foo_,
- "A",
- "B",
- std::string(),
- "/foo",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(SetCookieWithDetails(cm.get(),
- url_google_bar_,
- "C",
- "D",
- "google.izzle",
- "/bar",
- base::Time(),
- false,
- true,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(SetCookieWithDetails(cm.get(),
- url_google_,
- "E",
- "F",
- std::string(),
- std::string(),
- base::Time(),
- true,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B",
+ std::string(), "/foo", base::Time(), false,
+ false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_bar_, "C", "D",
+ "google.izzle", "/bar", base::Time(), false,
+ true, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_, "E", "F",
+ std::string(), std::string(), base::Time(),
+ true, false, COOKIE_PRIORITY_DEFAULT));
// Test that malformed attributes fail to set the cookie.
- EXPECT_FALSE(SetCookieWithDetails(cm.get(),
- url_google_foo_,
- " A",
- "B",
- std::string(),
- "/foo",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_FALSE(SetCookieWithDetails(cm.get(),
- url_google_foo_,
- "A;",
- "B",
- std::string(),
- "/foo",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_FALSE(SetCookieWithDetails(cm.get(),
- url_google_foo_,
- "A=",
- "B",
- std::string(),
- "/foo",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_FALSE(SetCookieWithDetails(cm.get(),
- url_google_foo_,
- "A",
- "B",
- "google.ozzzzzzle",
- "foo",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
- EXPECT_FALSE(SetCookieWithDetails(cm.get(),
- url_google_foo_,
- "A=",
- "B",
- std::string(),
- "foo",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, " A", "B",
+ std::string(), "/foo", base::Time(), false,
+ false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A;", "B",
+ std::string(), "/foo", base::Time(), false,
+ false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B",
+ std::string(), "/foo", base::Time(), false,
+ false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B",
+ "google.ozzzzzzle", "foo", base::Time(),
+ false, false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B",
+ std::string(), "foo", base::Time(), false,
+ false, COOKIE_PRIORITY_DEFAULT));
CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_);
CookieList::iterator it = cookies.begin();
@@ -1777,11 +1621,11 @@ TEST_F(CookieMonsterTest, DeleteAllForHost) {
GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
EXPECT_EQ("dom_1=X; host_1=X",
GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
- EXPECT_EQ("dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; "
- "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X",
- GetCookies(cm.get(),
- GURL(kTopLevelDomainPlus2Secure +
- std::string("/dir1/dir2/xxx"))));
+ EXPECT_EQ(
+ "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; "
+ "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X",
+ GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure +
+ std::string("/dir1/dir2/xxx"))));
EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2)));
EXPECT_EQ(8U, GetAllCookies(cm.get()).size());
@@ -1793,9 +1637,8 @@ TEST_F(CookieMonsterTest, DeleteAllForHost) {
EXPECT_EQ("dom_1=X; host_1=X",
GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
- GetCookies(cm.get(),
- GURL(kTopLevelDomainPlus2Secure +
- std::string("/dir1/dir2/xxx"))));
+ GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure +
+ std::string("/dir1/dir2/xxx"))));
PopulateCmForDeleteAllForHost(cm);
EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
@@ -1808,15 +1651,12 @@ TEST_F(CookieMonsterTest, DeleteAllForHost) {
EXPECT_EQ("dom_1=X; host_1=X",
GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
- GetCookies(cm.get(),
- GURL(kTopLevelDomainPlus2Secure +
- std::string("/dir1/dir2/xxx"))));
+ GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure +
+ std::string("/dir1/dir2/xxx"))));
PopulateCmForDeleteAllForHost(cm);
- EXPECT_EQ(5,
- DeleteAllForHost(
- cm.get(),
- GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/xxx"))));
+ EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure +
+ std::string("/dir1/xxx"))));
EXPECT_EQ(8U, GetAllCookies(cm.get()).size());
EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
@@ -1826,9 +1666,8 @@ TEST_F(CookieMonsterTest, DeleteAllForHost) {
EXPECT_EQ("dom_1=X; host_1=X",
GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
- GetCookies(cm.get(),
- GURL(kTopLevelDomainPlus2Secure +
- std::string("/dir1/dir2/xxx"))));
+ GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure +
+ std::string("/dir1/dir2/xxx"))));
}
TEST_F(CookieMonsterTest, UniqueCreationTime) {
@@ -1849,42 +1688,21 @@ TEST_F(CookieMonsterTest, UniqueCreationTime) {
SetCookie(cm.get(), url_google_, "SetCookie2=A");
SetCookie(cm.get(), url_google_, "SetCookie3=A");
- SetCookieWithOptions(
- cm.get(), url_google_, "setCookieWithOptions1=A", options);
- SetCookieWithOptions(
- cm.get(), url_google_, "setCookieWithOptions2=A", options);
- SetCookieWithOptions(
- cm.get(), url_google_, "setCookieWithOptions3=A", options);
-
- SetCookieWithDetails(cm.get(),
- url_google_,
- "setCookieWithDetails1",
- "A",
- ".google.com",
- "/",
- Time(),
- false,
- false,
+ SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions1=A",
+ options);
+ SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions2=A",
+ options);
+ SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions3=A",
+ options);
+
+ SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails1", "A",
+ ".google.com", "/", Time(), false, false,
COOKIE_PRIORITY_DEFAULT);
- SetCookieWithDetails(cm.get(),
- url_google_,
- "setCookieWithDetails2",
- "A",
- ".google.com",
- "/",
- Time(),
- false,
- false,
+ SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails2", "A",
+ ".google.com", "/", Time(), false, false,
COOKIE_PRIORITY_DEFAULT);
- SetCookieWithDetails(cm.get(),
- url_google_,
- "setCookieWithDetails3",
- "A",
- ".google.com",
- "/",
- Time(),
- false,
- false,
+ SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails3", "A",
+ ".google.com", "/", Time(), false, false,
COOKIE_PRIORITY_DEFAULT);
// Now we check
@@ -1894,8 +1712,8 @@ TEST_F(CookieMonsterTest, UniqueCreationTime) {
for (CookieList::const_iterator it = cookie_list.begin();
it != cookie_list.end(); it++) {
const int64 creation_date = it->CreationDate().ToInternalValue();
- TimeCookieMap::const_iterator
- existing_cookie_it(check_map.find(creation_date));
+ TimeCookieMap::const_iterator existing_cookie_it(
+ check_map.find(creation_date));
EXPECT_TRUE(existing_cookie_it == check_map.end())
<< "Cookie " << it->Name() << " has same creation date ("
<< it->CreationDate().ToInternalValue()
@@ -1903,8 +1721,8 @@ TEST_F(CookieMonsterTest, UniqueCreationTime) {
<< existing_cookie_it->second.Name();
if (existing_cookie_it == check_map.end()) {
- check_map.insert(TimeCookieMap::value_type(
- it->CreationDate().ToInternalValue(), *it));
+ check_map.insert(
+ TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it));
}
}
}
@@ -1944,36 +1762,47 @@ TEST_F(CookieMonsterTest, BackingStoreCommunication) {
base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100));
const CookiesInputInfo input_info[] = {
- {GURL("http://a.b.google.com"), "a", "1", "", "/path/to/cookie", expires,
- false, false, COOKIE_PRIORITY_DEFAULT},
- {GURL("https://www.google.com"), "b", "2", ".google.com",
- "/path/from/cookie", expires + TimeDelta::FromSeconds(10),
- true, true, COOKIE_PRIORITY_DEFAULT},
- {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie",
- base::Time::Now() + base::TimeDelta::FromSeconds(100),
- true, false, COOKIE_PRIORITY_DEFAULT}
- };
+ {GURL("http://a.b.google.com"),
+ "a",
+ "1",
+ "",
+ "/path/to/cookie",
+ expires,
+ false,
+ false,
+ COOKIE_PRIORITY_DEFAULT},
+ {GURL("https://www.google.com"),
+ "b",
+ "2",
+ ".google.com",
+ "/path/from/cookie",
+ expires + TimeDelta::FromSeconds(10),
+ true,
+ true,
+ COOKIE_PRIORITY_DEFAULT},
+ {GURL("https://google.com"),
+ "c",
+ "3",
+ "",
+ "/another/path/to/cookie",
+ base::Time::Now() + base::TimeDelta::FromSeconds(100),
+ true,
+ false,
+ COOKIE_PRIORITY_DEFAULT}};
const int INPUT_DELETE = 1;
// Create new cookies and flush them to the store.
{
scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL));
for (const CookiesInputInfo* p = input_info;
- p < &input_info[arraysize(input_info)];
- p++) {
- EXPECT_TRUE(SetCookieWithDetails(cmout.get(),
- p->url,
- p->name,
- p->value,
- p->domain,
- p->path,
- p->expiration_time,
- p->secure,
- p->http_only,
- p->priority));
+ p < &input_info[arraysize(input_info)]; p++) {
+ EXPECT_TRUE(SetCookieWithDetails(cmout.get(), p->url, p->name, p->value,
+ p->domain, p->path, p->expiration_time,
+ p->secure, p->http_only, p->priority));
}
- GURL del_url(input_info[INPUT_DELETE].url.Resolve(
- input_info[INPUT_DELETE].path).spec());
+ GURL del_url(input_info[INPUT_DELETE]
+ .url.Resolve(input_info[INPUT_DELETE].path)
+ .spec());
DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name);
}
@@ -2011,19 +1840,17 @@ TEST_F(CookieMonsterTest, CookieListOrdering) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
EXPECT_TRUE(
SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1"));
- EXPECT_TRUE(SetCookie(cm.get(),
- GURL("http://b.a.google.com/aa/bb/cc/x.html"),
+ EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"),
"d=1; domain=b.a.google.com"));
- EXPECT_TRUE(SetCookie(cm.get(),
- GURL("http://b.a.google.com/aa/bb/cc/x.html"),
+ EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"),
"a=4; domain=b.a.google.com"));
EXPECT_TRUE(SetCookie(cm.get(),
GURL("http://c.b.a.google.com/aa/bb/cc/x.html"),
"e=1; domain=c.b.a.google.com"));
- EXPECT_TRUE(SetCookie(
- cm.get(), GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1"));
- EXPECT_TRUE(SetCookie(
- cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10"));
+ EXPECT_TRUE(SetCookie(cm.get(),
+ GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1"));
+ EXPECT_TRUE(SetCookie(cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"),
+ "g=10"));
{
unsigned int i = 0;
CookieList cookies(GetAllCookiesForURL(
@@ -2085,46 +1912,41 @@ TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) {
// Indexed by ExpiryAndKeyScheme
size_t expected_cookies_after_set;
} test_cases[] = {
- {
- // A whole lot of recent cookies; gc shouldn't happen.
- CookieMonster::kMaxCookies * 2,
- 0,
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies * 2 + 1
- }, {
- // Some old cookies, but still overflowing max.
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies / 2,
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies * 2 - CookieMonster::kMaxCookies / 2 + 1
- }, {
- // Old cookies enough to bring us right down to our purge line.
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1,
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies
- }, {
- // Old cookies enough to bring below our purge line (which we
- // shouldn't do).
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies * 3 / 2,
- CookieMonster::kMaxCookies * 2,
- CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies
- }
- };
+ {// A whole lot of recent cookies; gc shouldn't happen.
+ CookieMonster::kMaxCookies * 2,
+ 0,
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies * 2 + 1},
+ {// Some old cookies, but still overflowing max.
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies / 2,
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies * 2 - CookieMonster::kMaxCookies / 2 + 1},
+ {// Old cookies enough to bring us right down to our purge line.
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1,
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies},
+ {// Old cookies enough to bring below our purge line (which we
+ // shouldn't do).
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies * 3 / 2,
+ CookieMonster::kMaxCookies * 2,
+ CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}};
for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) {
- const TestCase *test_case = &test_cases[ci];
- scoped_refptr<CookieMonster> cm(
- CreateMonsterFromStoreForGC(
- test_case->num_cookies, test_case->num_old_cookies,
- CookieMonster::kSafeFromGlobalPurgeDays * 2));
+ const TestCase* test_case = &test_cases[ci];
+ scoped_refptr<CookieMonster> cm(CreateMonsterFromStoreForGC(
+ test_case->num_cookies, test_case->num_old_cookies,
+ CookieMonster::kSafeFromGlobalPurgeDays * 2));
EXPECT_EQ(test_case->expected_initial_cookies,
- GetAllCookies(cm.get()).size()) << "For test case " << ci;
+ GetAllCookies(cm.get()).size())
+ << "For test case " << ci;
// Will trigger GC
SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2");
EXPECT_EQ(test_case->expected_cookies_after_set,
- GetAllCookies(cm.get()).size()) << "For test case " << ci;
+ GetAllCookies(cm.get()).size())
+ << "For test case " << ci;
}
}
@@ -2136,8 +1958,7 @@ TEST_F(CookieMonsterTest, KeepExpiredCookies) {
// Set a persistent cookie.
ASSERT_TRUE(SetCookieWithOptions(
- cm.get(),
- url_google_,
+ cm.get(), url_google_,
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT",
options));
@@ -2147,8 +1968,7 @@ TEST_F(CookieMonsterTest, KeepExpiredCookies) {
// Use a past expiry date to delete the cookie.
ASSERT_TRUE(SetCookieWithOptions(
- cm.get(),
- url_google_,
+ cm.get(), url_google_,
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
options));
@@ -2190,9 +2010,7 @@ class FlushablePersistentStore : public CookieMonster::PersistentCookieStore {
callback.Run();
}
- int flush_count() {
- return flush_count_;
- }
+ int flush_count() { return flush_count_; }
private:
~FlushablePersistentStore() override {}
@@ -2205,13 +2023,9 @@ class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> {
public:
CallbackCounter() : callback_count_(0) {}
- void Callback() {
- ++callback_count_;
- }
+ void Callback() { ++callback_count_; }
- int callback_count() {
- return callback_count_;
- }
+ int callback_count() { return callback_count_; }
private:
friend class base::RefCountedThreadSafe<CallbackCounter>;
@@ -2279,24 +2093,16 @@ TEST_F(CookieMonsterTest, HistogramCheck) {
// Should match call in InitializeHistograms, but doesn't really matter
// since the histogram should have been initialized by the CM construction
// above.
- base::HistogramBase* expired_histogram =
- base::Histogram::FactoryGet(
- "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50,
- base::Histogram::kUmaTargetedHistogramFlag);
+ base::HistogramBase* expired_histogram = base::Histogram::FactoryGet(
+ "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50,
+ base::Histogram::kUmaTargetedHistogramFlag);
scoped_ptr<base::HistogramSamples> samples1(
expired_histogram->SnapshotSamples());
- ASSERT_TRUE(
- SetCookieWithDetails(cm.get(),
- GURL("http://fake.a.url"),
- "a",
- "b",
- "a.url",
- "/",
- base::Time::Now() + base::TimeDelta::FromMinutes(59),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ ASSERT_TRUE(SetCookieWithDetails(
+ cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/",
+ base::Time::Now() + base::TimeDelta::FromMinutes(59), false, false,
+ COOKIE_PRIORITY_DEFAULT));
scoped_ptr<base::HistogramSamples> samples2(
expired_histogram->SnapshotSamples());
@@ -2319,8 +2125,7 @@ class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
// Helper methods for calling the asynchronous CookieMonster methods
// from a different thread.
- void GetAllCookiesTask(CookieMonster* cm,
- GetCookieListCallback* callback) {
+ void GetAllCookiesTask(CookieMonster* cm, GetCookieListCallback* callback) {
cm->GetAllCookiesAsync(
base::Bind(&GetCookieListCallback::Run, base::Unretained(callback)));
}
@@ -2328,9 +2133,8 @@ class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
void GetAllCookiesForURLTask(CookieMonster* cm,
const GURL& url,
GetCookieListCallback* callback) {
- cm->GetAllCookiesForURLAsync(
- url,
- base::Bind(&GetCookieListCallback::Run, base::Unretained(callback)));
+ cm->GetAllCookiesForURLAsync(url, base::Bind(&GetCookieListCallback::Run,
+ base::Unretained(callback)));
}
void GetAllCookiesForURLWithOptionsTask(CookieMonster* cm,
@@ -2342,7 +2146,8 @@ class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
base::Bind(&GetCookieListCallback::Run, base::Unretained(callback)));
}
- void SetCookieWithDetailsTask(CookieMonster* cm, const GURL& url,
+ void SetCookieWithDetailsTask(CookieMonster* cm,
+ const GURL& url,
ResultSavingCookieCallback<bool>* callback) {
// Define the parameters here instead of in the calling fucntion.
// The maximum number of parameters for Bind function is 6.
@@ -2356,10 +2161,8 @@ class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
CookiePriority priority = COOKIE_PRIORITY_DEFAULT;
cm->SetCookieWithDetailsAsync(
url, name, value, domain, path, expiration_time, secure, http_only,
- priority,
- base::Bind(
- &ResultSavingCookieCallback<bool>::Run,
- base::Unretained(callback)));
+ priority, base::Bind(&ResultSavingCookieCallback<bool>::Run,
+ base::Unretained(callback)));
}
void DeleteAllCreatedBetweenTask(CookieMonster* cm,
@@ -2368,17 +2171,16 @@ class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
ResultSavingCookieCallback<int>* callback) {
cm->DeleteAllCreatedBetweenAsync(
delete_begin, delete_end,
- base::Bind(
- &ResultSavingCookieCallback<int>::Run, base::Unretained(callback)));
+ base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(callback)));
}
void DeleteAllForHostTask(CookieMonster* cm,
const GURL& url,
ResultSavingCookieCallback<int>* callback) {
- cm->DeleteAllForHostAsync(
- url,
- base::Bind(
- &ResultSavingCookieCallback<int>::Run, base::Unretained(callback)));
+ cm->DeleteAllForHostAsync(url,
+ base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(callback)));
}
void DeleteAllCreatedBetweenForHostTask(
@@ -2389,19 +2191,16 @@ class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
ResultSavingCookieCallback<int>* callback) {
cm->DeleteAllCreatedBetweenForHostAsync(
delete_begin, delete_end, url,
- base::Bind(
- &ResultSavingCookieCallback<int>::Run,
- base::Unretained(callback)));
+ base::Bind(&ResultSavingCookieCallback<int>::Run,
+ base::Unretained(callback)));
}
void DeleteCanonicalCookieTask(CookieMonster* cm,
const CanonicalCookie& cookie,
ResultSavingCookieCallback<bool>* callback) {
cm->DeleteCanonicalCookieAsync(
- cookie,
- base::Bind(
- &ResultSavingCookieCallback<bool>::Run,
- base::Unretained(callback)));
+ cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run,
+ base::Unretained(callback)));
}
protected:
@@ -2429,8 +2228,7 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) {
GetCookieListCallback callback(&other_thread_);
base::Closure task =
base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask,
- base::Unretained(this),
- cm, &callback);
+ base::Unretained(this), cm, &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
it = callback.cookies().begin();
@@ -2452,8 +2250,7 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) {
GetCookieListCallback callback(&other_thread_);
base::Closure task =
base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask,
- base::Unretained(this),
- cm, url_google_, &callback);
+ base::Unretained(this), cm, url_google_, &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
it = callback.cookies().begin();
@@ -2477,8 +2274,7 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) {
GetCookieListCallback callback(&other_thread_);
base::Closure task = base::Bind(
&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask,
- base::Unretained(this),
- cm, url_google_, options, &callback);
+ base::Unretained(this), cm, url_google_, options, &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
it = callback.cookies().begin();
@@ -2490,21 +2286,13 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) {
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookieWithDetails(cm.get(),
- url_google_foo_,
- "A",
- "B",
- std::string(),
- "/foo",
- base::Time(),
- false,
- false,
- COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B",
+ std::string(), "/foo", base::Time(), false,
+ false, COOKIE_PRIORITY_DEFAULT));
ResultSavingCookieCallback<bool> callback(&other_thread_);
- base::Closure task = base::Bind(
- &net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask,
- base::Unretained(this),
- cm, url_google_foo_, &callback);
+ base::Closure task =
+ base::Bind(&net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask,
+ base::Unretained(this), cm, url_google_foo_, &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_TRUE(callback.result());
@@ -2515,16 +2303,14 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) {
CookieOptions options;
Time now = Time::Now();
EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
- EXPECT_EQ(
- 1,
- DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time()));
+ EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99),
+ Time()));
EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
ResultSavingCookieCallback<int> callback(&other_thread_);
base::Closure task = base::Bind(
&net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask,
- base::Unretained(this),
- cm, now - TimeDelta::FromDays(99),
- Time(), &callback);
+ base::Unretained(this), cm, now - TimeDelta::FromDays(99), Time(),
+ &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_EQ(1, callback.result());
@@ -2537,10 +2323,9 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) {
EXPECT_EQ(1, DeleteAllForHost(cm.get(), url_google_));
EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
ResultSavingCookieCallback<int> callback(&other_thread_);
- base::Closure task = base::Bind(
- &net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask,
- base::Unretained(this),
- cm, url_google_, &callback);
+ base::Closure task =
+ base::Bind(&net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask,
+ base::Unretained(this), cm, url_google_, &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_EQ(1, callback.result());
@@ -2573,8 +2358,7 @@ TEST_F(MultiThreadedCookieMonsterTest,
// 1. First set of deletions.
EXPECT_EQ(
3, // Deletes A=B, C=D, Y=Z
- DeleteAllCreatedBetweenForHost(
- cm.get(), ago3, Time::Max(), url_google_));
+ DeleteAllCreatedBetweenForHost(cm.get(), ago3, Time::Max(), url_google_));
EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
ResultSavingCookieCallback<int> callback(&other_thread_);
@@ -2582,9 +2366,7 @@ TEST_F(MultiThreadedCookieMonsterTest,
// 2. Second set of deletions.
base::Closure task = base::Bind(
&net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask,
- base::Unretained(this),
- cm, ago1, Time(), url_google_,
- &callback);
+ base::Unretained(this), cm, ago1, Time(), url_google_, &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H.
@@ -2604,8 +2386,7 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) {
it = cookies.begin();
base::Closure task = base::Bind(
&net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask,
- base::Unretained(this),
- cm, *it, &callback);
+ base::Unretained(this), cm, *it, &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_TRUE(callback.result());
@@ -2675,17 +2456,15 @@ TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
TEST_F(CookieMonsterTest, InvalidExpiryTime) {
std::string cookie_line =
std::string(kValidCookieLine) + "; expires=Blarg arg arg";
- scoped_ptr<CanonicalCookie> cookie(
- CanonicalCookie::Create(url_google_, cookie_line, Time::Now(),
- CookieOptions()));
+ scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
+ url_google_, cookie_line, Time::Now(), CookieOptions()));
ASSERT_FALSE(cookie->IsPersistent());
}
// Test that CookieMonster writes session cookies into the underlying
// CookieStore if the "persist session cookies" option is on.
TEST_F(CookieMonsterTest, PersistSessionCookies) {
- scoped_refptr<MockPersistentCookieStore> store(
- new MockPersistentCookieStore);
+ scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
cm->SetPersistSessionCookies(true);
@@ -2721,13 +2500,12 @@ TEST_F(CookieMonsterTest, PersistSessionCookies) {
// Test the commands sent to the persistent cookie store.
TEST_F(CookieMonsterTest, PersisentCookieStorageTest) {
- scoped_refptr<MockPersistentCookieStore> store(
- new MockPersistentCookieStore);
+ scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
// Add a cookie.
- EXPECT_TRUE(SetCookie(
- cm.get(), url_google_, "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
+ EXPECT_TRUE(SetCookie(cm.get(), url_google_,
+ "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_));
ASSERT_EQ(1u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
@@ -2738,14 +2516,14 @@ TEST_F(CookieMonsterTest, PersisentCookieStorageTest) {
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
// Add a cookie.
- EXPECT_TRUE(SetCookie(
- cm.get(), url_google_, "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
+ EXPECT_TRUE(SetCookie(cm.get(), url_google_,
+ "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_));
ASSERT_EQ(3u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
// Overwrite it.
- EXPECT_TRUE(SetCookie(
- cm.get(), url_google_, "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT"));
+ EXPECT_TRUE(SetCookie(cm.get(), url_google_,
+ "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT"));
this->MatchCookieLines("A=Foo", GetCookies(cm.get(), url_google_));
ASSERT_EQ(5u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
@@ -2769,27 +2547,22 @@ TEST_F(CookieMonsterTest, ControlCharacterPurge) {
const std::string domain("host");
const std::string path("/path");
- scoped_refptr<MockPersistentCookieStore> store(
- new MockPersistentCookieStore);
+ scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
std::vector<CanonicalCookie*> initial_cookies;
- AddCookieToList(domain,
- "foo=bar; path=" + path,
- now1,
- &initial_cookies);
+ AddCookieToList(domain, "foo=bar; path=" + path, now1, &initial_cookies);
// We have to manually build this cookie because it contains a control
// character, and our cookie line parser rejects control characters.
- CanonicalCookie *cc = new CanonicalCookie(url, "baz", "\x05" "boo", domain,
- path, now2, later, now2, false,
- false, COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie* cc = new CanonicalCookie(
+ url, "baz",
+ "\x05"
+ "boo",
+ domain, path, now2, later, now2, false, false, COOKIE_PRIORITY_DEFAULT);
initial_cookies.push_back(cc);
- AddCookieToList(domain,
- "hello=world; path=" + path,
- now3,
- &initial_cookies);
+ AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies);
// Inject our initial cookies into the mock PersistentCookieStore.
store->SetLoadExpectation(true, initial_cookies);
@@ -2831,7 +2604,8 @@ void RecordCookieChanges(std::vector<net::CanonicalCookie>* out_cookies,
TEST_F(CookieMonsterNotificationTest, NoNotifyWithNoCookie) {
std::vector<net::CanonicalCookie> cookies;
scoped_ptr<CookieStore::CookieChangedSubscription> sub(
- monster()->AddCallbackForCookie(test_url_, "abc",
+ monster()->AddCallbackForCookie(
+ test_url_, "abc",
base::Bind(&RecordCookieChanges, &cookies, nullptr)));
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(0U, cookies.size());
@@ -2842,7 +2616,8 @@ TEST_F(CookieMonsterNotificationTest, NoNotifyWithInitialCookie) {
SetCookie(monster(), test_url_, "abc=def");
base::MessageLoop::current()->RunUntilIdle();
scoped_ptr<CookieStore::CookieChangedSubscription> sub(
- monster()->AddCallbackForCookie(test_url_, "abc",
+ monster()->AddCallbackForCookie(
+ test_url_, "abc",
base::Bind(&RecordCookieChanges, &cookies, nullptr)));
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(0U, cookies.size());
@@ -2852,7 +2627,8 @@ TEST_F(CookieMonsterNotificationTest, NotifyOnSet) {
std::vector<net::CanonicalCookie> cookies;
std::vector<bool> removes;
scoped_ptr<CookieStore::CookieChangedSubscription> sub(
- monster()->AddCallbackForCookie(test_url_, "abc",
+ monster()->AddCallbackForCookie(
+ test_url_, "abc",
base::Bind(&RecordCookieChanges, &cookies, &removes)));
SetCookie(monster(), test_url_, "abc=def");
base::MessageLoop::current()->RunUntilIdle();
@@ -2868,7 +2644,8 @@ TEST_F(CookieMonsterNotificationTest, NotifyOnDelete) {
std::vector<net::CanonicalCookie> cookies;
std::vector<bool> removes;
scoped_ptr<CookieStore::CookieChangedSubscription> sub(
- monster()->AddCallbackForCookie(test_url_, "abc",
+ monster()->AddCallbackForCookie(
+ test_url_, "abc",
base::Bind(&RecordCookieChanges, &cookies, &removes)));
SetCookie(monster(), test_url_, "abc=def");
base::MessageLoop::current()->RunUntilIdle();
@@ -2889,7 +2666,8 @@ TEST_F(CookieMonsterNotificationTest, NotifyOnUpdate) {
std::vector<net::CanonicalCookie> cookies;
std::vector<bool> removes;
scoped_ptr<CookieStore::CookieChangedSubscription> sub(
- monster()->AddCallbackForCookie(test_url_, "abc",
+ monster()->AddCallbackForCookie(
+ test_url_, "abc",
base::Bind(&RecordCookieChanges, &cookies, &removes)));
SetCookie(monster(), test_url_, "abc=def");
base::MessageLoop::current()->RunUntilIdle();
@@ -2916,10 +2694,12 @@ TEST_F(CookieMonsterNotificationTest, MultipleNotifies) {
std::vector<net::CanonicalCookie> cookies0;
std::vector<net::CanonicalCookie> cookies1;
scoped_ptr<CookieStore::CookieChangedSubscription> sub0(
- monster()->AddCallbackForCookie(test_url_, "abc",
+ monster()->AddCallbackForCookie(
+ test_url_, "abc",
base::Bind(&RecordCookieChanges, &cookies0, nullptr)));
scoped_ptr<CookieStore::CookieChangedSubscription> sub1(
- monster()->AddCallbackForCookie(test_url_, "def",
+ monster()->AddCallbackForCookie(
+ test_url_, "def",
base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
SetCookie(monster(), test_url_, "abc=def");
base::MessageLoop::current()->RunUntilIdle();
@@ -2935,10 +2715,12 @@ TEST_F(CookieMonsterNotificationTest, MultipleSameNotifies) {
std::vector<net::CanonicalCookie> cookies0;
std::vector<net::CanonicalCookie> cookies1;
scoped_ptr<CookieStore::CookieChangedSubscription> sub0(
- monster()->AddCallbackForCookie(test_url_, "abc",
+ monster()->AddCallbackForCookie(
+ test_url_, "abc",
base::Bind(&RecordCookieChanges, &cookies0, nullptr)));
scoped_ptr<CookieStore::CookieChangedSubscription> sub1(
- monster()->AddCallbackForCookie(test_url_, "abc",
+ monster()->AddCallbackForCookie(
+ test_url_, "abc",
base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
SetCookie(monster(), test_url_, "abc=def");
base::MessageLoop::current()->RunUntilIdle();
diff --git a/net/cookies/cookie_options.h b/net/cookies/cookie_options.h
index ed5e2ef..975b8c8 100644
--- a/net/cookies/cookie_options.h
+++ b/net/cookies/cookie_options.h
@@ -14,10 +14,7 @@ class CookieOptions {
// Default is to exclude httponly, which means:
// - reading operations will not return httponly cookies.
// - writing operations will not write httponly cookies.
- CookieOptions()
- : exclude_httponly_(true),
- server_time_() {
- }
+ CookieOptions() : exclude_httponly_(true), server_time_() {}
void set_exclude_httponly() { exclude_httponly_ = true; }
void set_include_httponly() { exclude_httponly_ = false; }
@@ -39,4 +36,3 @@ class CookieOptions {
} // namespace net
#endif // NET_COOKIES_COOKIE_OPTIONS_H_
-
diff --git a/net/cookies/parsed_cookie.cc b/net/cookies/parsed_cookie.cc
index 2c72c3b..8cbca5c 100644
--- a/net/cookies/parsed_cookie.cc
+++ b/net/cookies/parsed_cookie.cc
@@ -73,7 +73,8 @@ inline bool CharIsA(const char c, const char* chars) {
inline bool SeekTo(std::string::const_iterator* it,
const std::string::const_iterator& end,
const char* chars) {
- for (; *it != end && !CharIsA(**it, chars); ++(*it)) {}
+ for (; *it != end && !CharIsA(**it, chars); ++(*it)) {
+ }
return *it == end;
}
// Seek the iterator to the first occurrence of a character not in |chars|.
@@ -81,13 +82,15 @@ inline bool SeekTo(std::string::const_iterator* it,
inline bool SeekPast(std::string::const_iterator* it,
const std::string::const_iterator& end,
const char* chars) {
- for (; *it != end && CharIsA(**it, chars); ++(*it)) {}
+ for (; *it != end && CharIsA(**it, chars); ++(*it)) {
+ }
return *it == end;
}
inline bool SeekBackPast(std::string::const_iterator* it,
const std::string::const_iterator& end,
const char* chars) {
- for (; *it != end && CharIsA(**it, chars); --(*it)) {}
+ for (; *it != end && CharIsA(**it, chars); --(*it)) {
+ }
return *it == end;
}
@@ -120,15 +123,13 @@ bool IsValidToken(const std::string& value) {
bool IsValidCookieValue(const std::string& value) {
// Number of characters to skip in validation at beginning and end of string.
size_t skip = 0;
- if (value.size() >= 2 && *value.begin() == '"' && *(value.end()-1) == '"')
+ if (value.size() >= 2 && *value.begin() == '"' && *(value.end() - 1) == '"')
skip = 1;
for (std::string::const_iterator i = value.begin() + skip;
i != value.end() - skip; ++i) {
bool valid_octet =
- (*i == 0x21 ||
- (*i >= 0x23 && *i <= 0x2B) ||
- (*i >= 0x2D && *i <= 0x3A) ||
- (*i >= 0x3C && *i <= 0x5B) ||
+ (*i == 0x21 || (*i >= 0x23 && *i <= 0x2B) ||
+ (*i >= 0x2D && *i <= 0x3A) || (*i >= 0x3C && *i <= 0x5B) ||
(*i >= 0x5D && *i <= 0x7E));
if (!valid_octet)
return false;
@@ -162,7 +163,6 @@ ParsedCookie::ParsedCookie(const std::string& cookie_line)
secure_index_(0),
httponly_index_(0),
priority_index_(0) {
-
if (cookie_line.size() > kMaxCookieSize) {
VLOG(1) << "Not parsing cookie, too large: " << cookie_line.size();
return;
@@ -181,8 +181,9 @@ bool ParsedCookie::IsValid() const {
}
CookiePriority ParsedCookie::Priority() const {
- return (priority_index_ == 0) ? COOKIE_PRIORITY_DEFAULT :
- StringToCookiePriority(pairs_[priority_index_].second);
+ return (priority_index_ == 0)
+ ? COOKIE_PRIORITY_DEFAULT
+ : StringToCookiePriority(pairs_[priority_index_].second);
}
bool ParsedCookie::SetName(const std::string& name) {
@@ -233,8 +234,7 @@ bool ParsedCookie::SetPriority(const std::string& priority) {
std::string ParsedCookie::ToCookieLine() const {
std::string out;
- for (PairList::const_iterator it = pairs_.begin();
- it != pairs_.end(); ++it) {
+ for (PairList::const_iterator it = pairs_.begin(); it != pairs_.end(); ++it) {
if (!out.empty())
out.append("; ");
out.append(it->first);
@@ -249,8 +249,7 @@ std::string ParsedCookie::ToCookieLine() const {
std::string::const_iterator ParsedCookie::FindFirstTerminator(
const std::string& s) {
std::string::const_iterator end = s.end();
- size_t term_pos =
- s.find_first_of(std::string(kTerminator, kTerminatorLen));
+ size_t term_pos = s.find_first_of(std::string(kTerminator, kTerminatorLen));
if (term_pos != std::string::npos) {
// We found a character we should treat as an end of string.
end = s.begin() + term_pos;
@@ -281,7 +280,7 @@ bool ParsedCookie::ParseToken(std::string::const_iterator* it,
// token_end should point after the last interesting token character,
// pointing at either whitespace, or at '=' (and equal to token_real_end).
if (*it != *token_start) { // We could have an empty token name.
- --(*it); // Go back before the token separator.
+ --(*it); // Go back before the token separator.
// Skip over any whitespace to the first non-whitespace character.
SeekBackPast(it, *token_start, kWhitespace);
// Point after it.
@@ -449,9 +448,7 @@ bool ParsedCookie::SetString(size_t* index,
}
}
-bool ParsedCookie::SetBool(size_t* index,
- const std::string& key,
- bool value) {
+bool ParsedCookie::SetBool(size_t* index, const std::string& key, bool value) {
if (!value) {
ClearAttributePair(*index);
return true;
@@ -483,9 +480,13 @@ void ParsedCookie::ClearAttributePair(size_t index) {
if (index == 0)
return;
- size_t* indexes[] = { &path_index_, &domain_index_, &expires_index_,
- &maxage_index_, &secure_index_, &httponly_index_,
- &priority_index_ };
+ size_t* indexes[] = {&path_index_,
+ &domain_index_,
+ &expires_index_,
+ &maxage_index_,
+ &secure_index_,
+ &httponly_index_,
+ &priority_index_};
for (size_t i = 0; i < arraysize(indexes); ++i) {
if (*indexes[i] == index)
*indexes[i] = 0;
diff --git a/net/cookies/parsed_cookie.h b/net/cookies/parsed_cookie.h
index 115ca1f..971cf37 100644
--- a/net/cookies/parsed_cookie.h
+++ b/net/cookies/parsed_cookie.h
@@ -113,9 +113,7 @@ class NET_EXPORT ParsedCookie {
bool SetString(size_t* index,
const std::string& key,
const std::string& value);
- bool SetBool(size_t* index,
- const std::string& key,
- bool value);
+ bool SetBool(size_t* index, const std::string& key, bool value);
// Helper function for SetString and SetBool handling the case that the
// key/value pair shall not be removed.
diff --git a/net/cookies/parsed_cookie_unittest.cc b/net/cookies/parsed_cookie_unittest.cc
index 30d41eb..9f231e8 100644
--- a/net/cookies/parsed_cookie_unittest.cc
+++ b/net/cookies/parsed_cookie_unittest.cc
@@ -39,22 +39,26 @@ TEST(ParsedCookieTest, TestQuoted) {
// Firefox 3, and Safari Windows 3.2.1. We originally tried to match
// Firefox closely, however we now match Internet Explorer and Safari.
const char* const values[] = {
- // Trailing whitespace after a quoted value. The whitespace after
- // the quote is stripped in all browsers.
- "\"zzz \" ", "\"zzz \"",
- // Handling a quoted value with a ';', like FOO="zz;pp" ;
- // IE and Safari: "zz;
- // Firefox and Opera: "zz;pp"
- "\"zz;pp\" ;", "\"zz",
- // Handling a value with multiple quoted parts, like FOO="zzz " "ppp" ;
- // IE and Safari: "zzz " "ppp";
- // Firefox: "zzz ";
- // Opera: <rejects cookie>
- "\"zzz \" \"ppp\" ", "\"zzz \" \"ppp\"",
- // A quote in a value that didn't start quoted. like FOO=A"B ;
- // IE, Safari, and Firefox: A"B;
- // Opera: <rejects cookie>
- "A\"B", "A\"B",
+ // Trailing whitespace after a quoted value. The whitespace after
+ // the quote is stripped in all browsers.
+ "\"zzz \" ",
+ "\"zzz \"",
+ // Handling a quoted value with a ';', like FOO="zz;pp" ;
+ // IE and Safari: "zz;
+ // Firefox and Opera: "zz;pp"
+ "\"zz;pp\" ;",
+ "\"zz",
+ // Handling a value with multiple quoted parts, like FOO="zzz " "ppp" ;
+ // IE and Safari: "zzz " "ppp";
+ // Firefox: "zzz ";
+ // Opera: <rejects cookie>
+ "\"zzz \" \"ppp\" ",
+ "\"zzz \" \"ppp\"",
+ // A quote in a value that didn't start quoted. like FOO=A"B ;
+ // IE, Safari, and Firefox: A"B;
+ // Opera: <rejects cookie>
+ "A\"B",
+ "A\"B",
};
for (size_t i = 0; i < arraysize(values); i += 2) {
@@ -169,9 +173,10 @@ TEST(ParsedCookieTest, MultipleEquals) {
}
TEST(ParsedCookieTest, QuotedTrailingWhitespace) {
- ParsedCookie pc("ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; "
- "expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
- "path=/ ; ");
+ ParsedCookie pc(
+ "ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; "
+ "expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
+ "path=/ ; ");
EXPECT_TRUE(pc.IsValid());
EXPECT_EQ("ANCUUID", pc.Name());
// Stripping whitespace after the quotes matches all other major browsers.
@@ -184,9 +189,10 @@ TEST(ParsedCookieTest, QuotedTrailingWhitespace) {
}
TEST(ParsedCookieTest, TrailingWhitespace) {
- ParsedCookie pc("ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; "
- "expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
- "path=/ ; ");
+ ParsedCookie pc(
+ "ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; "
+ "expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
+ "path=/ ; ");
EXPECT_TRUE(pc.IsValid());
EXPECT_EQ("ANCUUID", pc.Name());
EXPECT_EQ("zohNumRKgI0oxyhSsV3Z7D", pc.Value());
@@ -248,36 +254,31 @@ TEST(ParsedCookieTest, EmbeddedTerminator) {
}
TEST(ParsedCookieTest, ParseTokensAndValues) {
- EXPECT_EQ("hello",
- ParsedCookie::ParseTokenString("hello\nworld"));
- EXPECT_EQ("fs!!@",
- ParsedCookie::ParseTokenString("fs!!@;helloworld"));
+ EXPECT_EQ("hello", ParsedCookie::ParseTokenString("hello\nworld"));
+ EXPECT_EQ("fs!!@", ParsedCookie::ParseTokenString("fs!!@;helloworld"));
EXPECT_EQ("hello world\tgood",
ParsedCookie::ParseTokenString("hello world\tgood\rbye"));
- EXPECT_EQ("A",
- ParsedCookie::ParseTokenString("A=B=C;D=E"));
- EXPECT_EQ("hello",
- ParsedCookie::ParseValueString("hello\nworld"));
- EXPECT_EQ("fs!!@",
- ParsedCookie::ParseValueString("fs!!@;helloworld"));
+ EXPECT_EQ("A", ParsedCookie::ParseTokenString("A=B=C;D=E"));
+ EXPECT_EQ("hello", ParsedCookie::ParseValueString("hello\nworld"));
+ EXPECT_EQ("fs!!@", ParsedCookie::ParseValueString("fs!!@;helloworld"));
EXPECT_EQ("hello world\tgood",
ParsedCookie::ParseValueString("hello world\tgood\rbye"));
- EXPECT_EQ("A=B=C",
- ParsedCookie::ParseValueString("A=B=C;D=E"));
+ EXPECT_EQ("A=B=C", ParsedCookie::ParseValueString("A=B=C;D=E"));
}
TEST(ParsedCookieTest, SerializeCookieLine) {
- const char input[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; "
- "expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
- "path=/ ; priority=low ; ";
- const char output[] = "ANCUUID=zohNumRKgI0oxyhSsV3Z7D; "
- "expires=Sun, 18-Apr-2027 21:06:29 GMT; "
- "path=/; priority=low";
+ const char input[] =
+ "ANCUUID=zohNumRKgI0oxyhSsV3Z7D ; "
+ "expires=Sun, 18-Apr-2027 21:06:29 GMT ; "
+ "path=/ ; priority=low ; ";
+ const char output[] =
+ "ANCUUID=zohNumRKgI0oxyhSsV3Z7D; "
+ "expires=Sun, 18-Apr-2027 21:06:29 GMT; "
+ "path=/; priority=low";
ParsedCookie pc(input);
EXPECT_EQ(output, pc.ToCookieLine());
}
-
TEST(ParsedCookieTest, SetNameAndValue) {
ParsedCookie empty((std::string()));
EXPECT_FALSE(empty.IsValid());
@@ -353,10 +354,11 @@ TEST(ParsedCookieTest, SetAttributes) {
EXPECT_TRUE(pc.SetIsHttpOnly(true));
EXPECT_TRUE(pc.SetIsHttpOnly(true));
EXPECT_TRUE(pc.SetPriority("HIGH"));
- EXPECT_EQ("name=value; domain=domain.com; path=/; "
- "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
- "httponly; priority=HIGH",
- pc.ToCookieLine());
+ EXPECT_EQ(
+ "name=value; domain=domain.com; path=/; "
+ "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
+ "httponly; priority=HIGH",
+ pc.ToCookieLine());
EXPECT_TRUE(pc.HasDomain());
EXPECT_TRUE(pc.HasPath());
EXPECT_TRUE(pc.HasExpires());
@@ -372,17 +374,19 @@ TEST(ParsedCookieTest, SetAttributes) {
EXPECT_TRUE(pc.HasExpires());
EXPECT_TRUE(pc.IsSecure());
EXPECT_TRUE(pc.IsHttpOnly());
- EXPECT_EQ("name=value; domain=domain.com; path=/foo; "
- "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
- "httponly; priority=HIGH",
- pc.ToCookieLine());
+ EXPECT_EQ(
+ "name=value; domain=domain.com; path=/foo; "
+ "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
+ "httponly; priority=HIGH",
+ pc.ToCookieLine());
// Set priority to medium.
EXPECT_TRUE(pc.SetPriority("medium"));
- EXPECT_EQ("name=value; domain=domain.com; path=/foo; "
- "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
- "httponly; priority=medium",
- pc.ToCookieLine());
+ EXPECT_EQ(
+ "name=value; domain=domain.com; path=/foo; "
+ "expires=Sun, 18-Apr-2027 21:06:29 GMT; max-age=12345; secure; "
+ "httponly; priority=medium",
+ pc.ToCookieLine());
// Clear the rest and change the name and value.
EXPECT_TRUE(pc.SetDomain(std::string()));
@@ -439,20 +443,53 @@ TEST(ParsedCookieTest, SetPriority) {
TEST(ParsedCookieTest, InvalidNonAlphanumericChars) {
ParsedCookie pc1("name=\x05");
- ParsedCookie pc2("name=foo" "\x1c" "bar");
- ParsedCookie pc3("name=foobar" "\x11");
- ParsedCookie pc4("name=\x02" "foobar");
+ ParsedCookie pc2(
+ "name=foo"
+ "\x1c"
+ "bar");
+ ParsedCookie pc3(
+ "name=foobar"
+ "\x11");
+ ParsedCookie pc4(
+ "name=\x02"
+ "foobar");
ParsedCookie pc5("\x05=value");
- ParsedCookie pc6("foo" "\x05" "bar=value");
- ParsedCookie pc7("foobar" "\x05" "=value");
- ParsedCookie pc8("\x05" "foobar" "=value");
-
- ParsedCookie pc9("foo" "\x05" "bar" "=foo" "\x05" "bar");
-
- ParsedCookie pc10("foo=bar;ba" "\x05" "z=boo");
- ParsedCookie pc11("foo=bar;baz=bo" "\x05" "o");
- ParsedCookie pc12("foo=bar;ba" "\05" "z=bo" "\x05" "o");
+ ParsedCookie pc6(
+ "foo"
+ "\x05"
+ "bar=value");
+ ParsedCookie pc7(
+ "foobar"
+ "\x05"
+ "=value");
+ ParsedCookie pc8(
+ "\x05"
+ "foobar"
+ "=value");
+
+ ParsedCookie pc9(
+ "foo"
+ "\x05"
+ "bar"
+ "=foo"
+ "\x05"
+ "bar");
+
+ ParsedCookie pc10(
+ "foo=bar;ba"
+ "\x05"
+ "z=boo");
+ ParsedCookie pc11(
+ "foo=bar;baz=bo"
+ "\x05"
+ "o");
+ ParsedCookie pc12(
+ "foo=bar;ba"
+ "\05"
+ "z=bo"
+ "\x05"
+ "o");
EXPECT_FALSE(pc1.IsValid());
EXPECT_FALSE(pc2.IsValid());
@@ -505,5 +542,4 @@ TEST(ParsedCookieTest, ValidNonAlphanumericChars) {
EXPECT_TRUE(pc8.IsValid());
EXPECT_EQ(pc8_literal, pc8.ToCookieLine());
}
-
}