summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorcmumford <cmumford@chromium.org>2015-10-15 11:08:06 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-15 18:09:18 +0000
commit8688a8f8c4f3e2010d5a6ecf7cc928121f7a4340 (patch)
tree222ab6196b17a6509a63eb7045a4b63e2a38c3b7 /net
parent11f0177394eedc116c54e786d65b8c5dc7d72440 (diff)
downloadchromium_src-8688a8f8c4f3e2010d5a6ecf7cc928121f7a4340.zip
chromium_src-8688a8f8c4f3e2010d5a6ecf7cc928121f7a4340.tar.gz
chromium_src-8688a8f8c4f3e2010d5a6ecf7cc928121f7a4340.tar.bz2
Decouple CookieMonsterTest from CookieStoreTest.
Prior implementation had CookieMonsterTest hard-coded to be aware of specific parts (domain, etc.) of CookieStoreTest's test URL's. This change switches CookieStoreTest's URL's from GURL to a new URLHelper which has methods for these tests so that the desired parts of the URL's from CookieStoreTest can be extracted, or new variants can be created. Review URL: https://codereview.chromium.org/1378273003 Cr-Commit-Position: refs/heads/master@{#354304}
Diffstat (limited to 'net')
-rw-r--r--net/cookies/cookie_monster_unittest.cc613
-rw-r--r--net/cookies/cookie_store_test_helpers.cc41
-rw-r--r--net/cookies/cookie_store_test_helpers.h21
-rw-r--r--net/cookies/cookie_store_unittest.h385
4 files changed, 611 insertions, 449 deletions
diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc
index 203dd10..839add8 100644
--- a/net/cookies/cookie_monster_unittest.cc
+++ b/net/cookies/cookie_monster_unittest.cc
@@ -70,7 +70,6 @@ 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 kOtherDomain[] = "http://www.mit.edu";
-const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle";
class GetCookieListCallback : public CookieCallback {
public:
@@ -359,8 +358,9 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
for (int i = 0; i < more_than_enough_cookies; ++i) {
std::string cookie = base::StringPrintf("a%03d=b", i);
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, cookie));
- std::string cookies = this->GetCookies(cm.get(), url_google_);
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), cookie));
+ std::string cookies =
+ this->GetCookies(cm.get(), http_www_google_.url());
// Make sure we find it in the cookies.
EXPECT_NE(cookies.find(cookie), std::string::npos);
// Count the number of cookies.
@@ -371,15 +371,17 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
// Add a bunch of cookies on multiple hosts within a single eTLD.
// Should keep at least kDomainMaxCookies - kDomainPurgeCookies
// between them. We shouldn't go above kDomainMaxCookies for both together.
- GURL url_google_specific(kUrlGoogleSpecific);
+ GURL url_google_specific(http_www_google_.Format("http://www.gmail.%D"));
{
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
for (int i = 0; i < more_than_enough_cookies; ++i) {
std::string cookie_general = base::StringPrintf("a%03d=b", i);
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, cookie_general));
+ EXPECT_TRUE(
+ SetCookie(cm.get(), http_www_google_.url(), cookie_general));
std::string cookie_specific = base::StringPrintf("c%03d=b", i);
EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific));
- std::string cookies_general = this->GetCookies(cm.get(), url_google_);
+ std::string cookies_general =
+ this->GetCookies(cm.get(), http_www_google_.url());
EXPECT_NE(cookies_general.find(cookie_general), std::string::npos);
std::string cookies_specific =
this->GetCookies(cm.get(), url_google_specific);
@@ -390,7 +392,8 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
}
// After all this, there should be at least
// kDomainMaxCookies - kDomainPurgeCookies for both URLs.
- std::string cookies_general = this->GetCookies(cm.get(), url_google_);
+ std::string cookies_general =
+ this->GetCookies(cm.get(), http_www_google_.url());
std::string cookies_specific =
this->GetCookies(cm.get(), url_google_specific);
int total_cookies = (CountInString(cookies_general, '=') +
@@ -413,8 +416,8 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
return COOKIE_PRIORITY_DEFAULT;
}
- // Instantiates a CookieMonster, adds multiple cookies (to url_google_) with
- // priorities specified by |coded_priority_str|, and tests priority-aware
+ // Instantiates a CookieMonster, adds multiple cookies (to http_www_google_)
+ // with priorities specified by |coded_priority_str|, and tests priority-aware
// domain cookie eviction.
// |coded_priority_str| specifies a run-length-encoded string of priorities.
// Example: "2M 3L M 4H" means "MMLLLMHHHH", and speicifies sequential (i.e.,
@@ -453,7 +456,7 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
for (; rep > 0; --rep, ++next_cookie_id) {
std::string cookie = base::StringPrintf(
"a%d=b;priority=%s", next_cookie_id, priority_str.c_str());
- EXPECT_TRUE(SetCookie(cm, url_google_, cookie));
+ EXPECT_TRUE(SetCookie(cm, http_www_google_.url(), cookie));
priority_list.push_back(priority);
id_list[priority].push_back(next_cookie_id);
}
@@ -463,7 +466,7 @@ class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> {
std::vector<int> surviving_id_list[3]; // Indexed by CookiePriority.
// Parse the list of cookies
- std::string cookie_str = this->GetCookies(cm, url_google_);
+ std::string cookie_str = this->GetCookies(cm, http_www_google_.url());
for (const std::string& token : base::SplitString(
cookie_str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
// Assuming *it is "a#=b", so extract and parse "#" portion.
@@ -816,20 +819,21 @@ class DeferredCookieTaskTest : public CookieMonsterTest {
};
TEST_F(DeferredCookieTaskTest, DeferredGetCookies) {
- DeclareLoadedCookie("www.google.izzle",
+ DeclareLoadedCookie(http_www_google_.host(),
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
MockGetCookiesCallback get_cookies_callback;
BeginWithForDomainKey(
- "google.izzle",
- GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback));
+ http_www_google_.domain(),
+ GetCookiesAction(&cookie_monster(), http_www_google_.url(),
+ &get_cookies_callback));
WaitForLoadCall();
EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
- .WillOnce(GetCookiesAction(&cookie_monster(), url_google_,
+ .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(),
&get_cookies_callback));
EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
.WillOnce(QuitCurrentMessageLoop());
@@ -840,15 +844,16 @@ 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(
+ http_www_google_.domain(),
+ SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B",
+ &set_cookies_callback));
WaitForLoadCall();
EXPECT_CALL(set_cookies_callback, Invoke(true))
- .WillOnce(SetCookieAction(&cookie_monster(), url_google_, "X=Y",
- &set_cookies_callback));
+ .WillOnce(SetCookieAction(&cookie_monster(), http_www_google_.url(),
+ "X=Y", &set_cookies_callback));
EXPECT_CALL(set_cookies_callback, Invoke(true))
.WillOnce(QuitCurrentMessageLoop());
@@ -858,10 +863,12 @@ TEST_F(DeferredCookieTaskTest, DeferredSetCookie) {
TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) {
MockSetCookiesCallback set_cookies_callback;
CookieList list;
- list.push_back(CanonicalCookie(url_google_, "A", "B", "google.izzle", "/",
+ list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B",
+ http_www_google_.domain(), "/",
base::Time::Now(), base::Time(), base::Time(),
false, true, false, COOKIE_PRIORITY_DEFAULT));
- list.push_back(CanonicalCookie(url_google_, "C", "D", "google.izzle", "/",
+ list.push_back(CanonicalCookie(http_www_google_.url(), "C", "D",
+ http_www_google_.domain(), "/",
base::Time::Now(), base::Time(), base::Time(),
false, true, false, COOKIE_PRIORITY_DEFAULT));
@@ -882,15 +889,16 @@ TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) {
TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) {
MockClosure delete_cookie_callback;
- BeginWithForDomainKey("google.izzle",
- DeleteCookieAction(&cookie_monster(), url_google_, "A",
- &delete_cookie_callback));
+ BeginWithForDomainKey(
+ http_www_google_.domain(),
+ DeleteCookieAction(&cookie_monster(), http_www_google_.url(), "A",
+ &delete_cookie_callback));
WaitForLoadCall();
EXPECT_CALL(delete_cookie_callback, Invoke())
- .WillOnce(DeleteCookieAction(&cookie_monster(), url_google_, "X",
- &delete_cookie_callback));
+ .WillOnce(DeleteCookieAction(&cookie_monster(), http_www_google_.url(),
+ "X", &delete_cookie_callback));
EXPECT_CALL(delete_cookie_callback, Invoke())
.WillOnce(QuitCurrentMessageLoop());
@@ -900,7 +908,7 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) {
TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) {
MockSetCookiesCallback set_cookies_callback;
- CookiesInputInfo cookie_info = {url_google_foo_,
+ CookiesInputInfo cookie_info = {www_google_foo_.url(),
"A",
"B",
std::string(),
@@ -911,12 +919,13 @@ TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) {
false,
COOKIE_PRIORITY_DEFAULT};
BeginWithForDomainKey(
- "google.izzle", SetCookieWithDetailsAction(&cookie_monster(), cookie_info,
- &set_cookies_callback));
+ http_www_google_.domain(),
+ SetCookieWithDetailsAction(&cookie_monster(), cookie_info,
+ &set_cookies_callback));
WaitForLoadCall();
- CookiesInputInfo cookie_info_exp = {url_google_foo_,
+ CookiesInputInfo cookie_info_exp = {www_google_foo_.url(),
"A",
"B",
std::string(),
@@ -936,7 +945,7 @@ TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) {
}
TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) {
- DeclareLoadedCookie("www.google.izzle",
+ DeclareLoadedCookie(http_www_google_.host(),
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
@@ -956,20 +965,22 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) {
}
TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) {
- DeclareLoadedCookie("www.google.izzle",
+ DeclareLoadedCookie(http_www_google_.host(),
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
MockGetCookieListCallback get_cookie_list_callback;
BeginWithForDomainKey(
- "google.izzle", GetAllCookiesForUrlAction(&cookie_monster(), url_google_,
- &get_cookie_list_callback));
+ http_www_google_.domain(),
+ GetAllCookiesForUrlAction(&cookie_monster(), http_www_google_.url(),
+ &get_cookie_list_callback));
WaitForLoadCall();
EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
- .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(), url_google_,
+ .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(),
+ http_www_google_.url(),
&get_cookie_list_callback));
EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
.WillOnce(QuitCurrentMessageLoop());
@@ -978,21 +989,23 @@ TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) {
}
TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) {
- DeclareLoadedCookie("www.google.izzle",
+ DeclareLoadedCookie(http_www_google_.host(),
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
MockGetCookieListCallback get_cookie_list_callback;
- BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlWithOptionsAction(
- &cookie_monster(), url_google_,
- &get_cookie_list_callback));
+ BeginWithForDomainKey(http_www_google_.domain(),
+ GetAllCookiesForUrlWithOptionsAction(
+ &cookie_monster(), http_www_google_.url(),
+ &get_cookie_list_callback));
WaitForLoadCall();
EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
.WillOnce(GetAllCookiesForUrlWithOptionsAction(
- &cookie_monster(), url_google_, &get_cookie_list_callback));
+ &cookie_monster(), http_www_google_.url(),
+ &get_cookie_list_callback));
EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_))
.WillOnce(QuitCurrentMessageLoop());
@@ -1036,14 +1049,15 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) {
MockDeleteCallback delete_callback;
BeginWithForDomainKey(
- "google.izzle",
- DeleteAllForHostAction(&cookie_monster(), url_google_, &delete_callback));
+ http_www_google_.domain(),
+ DeleteAllForHostAction(&cookie_monster(), http_www_google_.url(),
+ &delete_callback));
WaitForLoadCall();
EXPECT_CALL(delete_callback, Invoke(false))
- .WillOnce(DeleteAllForHostAction(&cookie_monster(), url_google_,
- &delete_callback));
+ .WillOnce(DeleteAllForHostAction(
+ &cookie_monster(), http_www_google_.url(), &delete_callback));
EXPECT_CALL(delete_callback, Invoke(false))
.WillOnce(QuitCurrentMessageLoop());
@@ -1052,8 +1066,8 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) {
TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
std::vector<CanonicalCookie*> cookies;
- CanonicalCookie cookie =
- BuildCanonicalCookie("www.google.com", "X=1; path=/", base::Time::Now());
+ CanonicalCookie cookie = BuildCanonicalCookie(
+ http_www_google_.host(), "X=1; path=/", base::Time::Now());
MockDeleteCookieCallback delete_cookie_callback;
@@ -1091,7 +1105,7 @@ TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) {
// the backing store and that new tasks received while the queued tasks are
// being dispatched go to the end of the queue.
TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) {
- DeclareLoadedCookie("www.google.izzle",
+ DeclareLoadedCookie(http_www_google_.host(),
"X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
Time::Now() + TimeDelta::FromDays(3));
@@ -1100,17 +1114,18 @@ TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) {
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)));
+ .WillOnce(testing::DoAll(
+ GetCookiesAction(&cookie_monster(), http_www_google_.url(),
+ &get_cookies_callback),
+ SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B",
+ &set_cookies_callback)));
ExpectLoadCall();
- ExpectLoadForKeyCall("google.izzle", false);
+ ExpectLoadForKeyCall(http_www_google_.domain(), false);
Begin();
WaitForLoadCall();
EXPECT_CALL(get_cookies_callback, Invoke("X=1"))
- .WillOnce(GetCookiesAction(&cookie_monster(), url_google_,
+ .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(),
&get_cookies_callback_deferred));
EXPECT_CALL(set_cookies_callback, Invoke(true));
EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1"))
@@ -1125,20 +1140,22 @@ TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
CookieOptions options;
options.set_include_httponly();
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine));
- EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine));
+ EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
- EXPECT_TRUE(
- SetCookieWithOptions(cm.get(), url_google_, "C=D; httponly", options));
- EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm.get(), url_google_, options));
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
+ "C=D; httponly", options));
+ EXPECT_EQ("A=B; C=D",
+ GetCookiesWithOptions(cm.get(), http_www_google_.url(), options));
EXPECT_EQ(2, DeleteAll(cm.get()));
- EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options));
+ EXPECT_EQ("",
+ GetCookiesWithOptions(cm.get(), http_www_google_.url(), options));
EXPECT_EQ(0u, store->commands().size());
// Create a persistent cookie.
EXPECT_TRUE(SetCookie(
- cm.get(), url_google_,
+ cm.get(), http_www_google_.url(),
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);
@@ -1147,7 +1164,8 @@ TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
ASSERT_EQ(2u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
- EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options));
+ EXPECT_EQ("",
+ GetCookiesWithOptions(cm.get(), http_www_google_.url(), options));
}
TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
@@ -1159,15 +1177,16 @@ TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
Time()));
// Create 3 cookies with creation date of today, yesterday and the day before.
- EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now));
- EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday",
- now - TimeDelta::FromDays(1)));
- EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore",
- now - TimeDelta::FromDays(2)));
- EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays",
- now - TimeDelta::FromDays(3)));
- EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek",
- now - TimeDelta::FromDays(7)));
+ EXPECT_TRUE(
+ cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now));
+ EXPECT_TRUE(cm->SetCookieWithCreationTime(
+ http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1)));
+ EXPECT_TRUE(cm->SetCookieWithCreationTime(
+ http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2)));
+ EXPECT_TRUE(cm->SetCookieWithCreationTime(
+ http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3)));
+ EXPECT_TRUE(cm->SetCookieWithCreationTime(
+ http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7)));
// Try to delete threedays and the daybefore.
EXPECT_EQ(2, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3),
@@ -1195,18 +1214,18 @@ TEST_F(CookieMonsterTest, TestLastAccess) {
scoped_refptr<CookieMonster> cm(
new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
const Time last_access_date(GetFirstCookieAccessDate(cm.get()));
// Reading the cookie again immediately shouldn't update the access date,
// since we're inside the threshold.
- EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_));
+ EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get()));
// Reading after a short wait should update the access date.
base::PlatformThread::Sleep(
base::TimeDelta::FromMilliseconds(kAccessDelayMs));
- EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_));
+ EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm.get()));
}
@@ -1221,16 +1240,17 @@ TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) {
TEST_F(CookieMonsterTest, TestDeleteSingleCookie) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F"));
- EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F"));
+ EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url()));
- EXPECT_TRUE(FindAndDeleteCookie(cm.get(), url_google_.host(), "C"));
- EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(
+ FindAndDeleteCookie(cm.get(), http_www_google_.url().host(), "C"));
+ EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E"));
- EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_));
+ EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
}
TEST_F(CookieMonsterTest, SetCookieableSchemes) {
@@ -1258,13 +1278,14 @@ TEST_F(CookieMonsterTest, GetAllCookiesForURL) {
CookieOptions options;
options.set_include_httponly();
- 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_,
- "E=F; domain=.google.izzle; secure",
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
+ "A=B; httponly", options));
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
+ http_www_google_.Format("C=D; domain=.%D"),
options));
+ EXPECT_TRUE(SetCookieWithOptions(
+ cm.get(), https_www_google_.url(),
+ http_www_google_.Format("E=F; domain=.%D; secure"), options));
const Time last_access_date(GetFirstCookieAccessDate(cm.get()));
@@ -1272,44 +1293,44 @@ TEST_F(CookieMonsterTest, GetAllCookiesForURL) {
base::TimeDelta::FromMilliseconds(kAccessDelayMs));
// Check cookies for url.
- CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_);
+ CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url());
CookieList::iterator it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.host(), it->Domain());
EXPECT_EQ("A", it->Name());
ASSERT_TRUE(++it != cookies.end());
- EXPECT_EQ(".google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain());
EXPECT_EQ("C", it->Name());
ASSERT_TRUE(++it == cookies.end());
// Check cookies for url excluding http-only cookies.
- cookies =
- GetAllCookiesForURLWithOptions(cm.get(), url_google_, CookieOptions());
+ cookies = GetAllCookiesForURLWithOptions(cm.get(), http_www_google_.url(),
+ CookieOptions());
it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
- EXPECT_EQ(".google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain());
EXPECT_EQ("C", it->Name());
ASSERT_TRUE(++it == cookies.end());
// Test secure cookies.
- cookies = GetAllCookiesForURL(cm.get(), url_google_secure_);
+ cookies = GetAllCookiesForURL(cm.get(), https_www_google_.url());
it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.host(), it->Domain());
EXPECT_EQ("A", it->Name());
ASSERT_TRUE(++it != cookies.end());
- EXPECT_EQ(".google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain());
EXPECT_EQ("C", it->Name());
ASSERT_TRUE(++it != cookies.end());
- EXPECT_EQ(".google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain());
EXPECT_EQ("E", it->Name());
ASSERT_TRUE(++it == cookies.end());
@@ -1322,13 +1343,14 @@ 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_, "E=F;", options));
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(),
+ "A=B; path=/foo;", options));
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(),
+ "C=D; path=/bar;", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options));
- CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_);
+ CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url());
CookieList::iterator it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
@@ -1341,7 +1363,7 @@ TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
ASSERT_TRUE(++it == cookies.end());
- cookies = GetAllCookiesForURL(cm.get(), url_google_bar_);
+ cookies = GetAllCookiesForURL(cm.get(), www_google_bar_.url());
it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
@@ -1358,15 +1380,18 @@ TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
TEST_F(CookieMonsterTest, CookieSorting) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/foo/bar"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A1; path=/"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A2; path=/foo"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/foo/bar"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo"));
+ EXPECT_TRUE(
+ SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo"));
+ EXPECT_TRUE(
+ SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar"));
// Re-set cookie which should not change sort order.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/foo/bar"));
+ EXPECT_TRUE(
+ SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar"));
CookieList cookies = GetAllCookies(cm.get());
ASSERT_EQ(6u, cookies.size());
@@ -1385,14 +1410,14 @@ TEST_F(CookieMonsterTest, CookieSorting) {
TEST_F(CookieMonsterTest, DeleteCookieByName) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A1; path=/"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A2; path=/foo"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/bar"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/bar"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/bar"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/bar"));
- DeleteCookie(cm.get(), GURL(std::string(kUrlGoogle) + "/foo/bar"), "A");
+ DeleteCookie(cm.get(), http_www_google_.AppendPath("foo/bar"), "A");
CookieList cookies = GetAllCookies(cm.get());
size_t expected_size = 4;
@@ -1407,11 +1432,12 @@ TEST_F(CookieMonsterTest, ImportCookiesFromCookieMonster) {
scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL));
CookieOptions options;
- EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_,
+ EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), www_google_foo_.url(),
"A1=B; path=/foo;", options));
- EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_,
+ EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), www_google_bar_.url(),
"A2=D; path=/bar;", options));
- EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, "A3=F;", options));
+ EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), http_www_google_.url(), "A3=F;",
+ options));
CookieList cookies_1 = GetAllCookies(cm_1.get());
scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL));
@@ -1559,47 +1585,53 @@ TEST_F(CookieMonsterTest, CookieMonsterDelegate) {
scoped_refptr<CookieMonster> cm(
new CookieMonster(store.get(), delegate.get()));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F"));
- EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F"));
+ EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url()));
ASSERT_EQ(3u, delegate->changes().size());
EXPECT_FALSE(delegate->changes()[0].second);
- EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain());
+ EXPECT_EQ(http_www_google_.url().host(),
+ delegate->changes()[0].first.Domain());
EXPECT_EQ("A", delegate->changes()[0].first.Name());
EXPECT_EQ("B", delegate->changes()[0].first.Value());
- EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain());
+ EXPECT_EQ(http_www_google_.url().host(),
+ delegate->changes()[1].first.Domain());
EXPECT_FALSE(delegate->changes()[1].second);
EXPECT_EQ("C", delegate->changes()[1].first.Name());
EXPECT_EQ("D", delegate->changes()[1].first.Value());
- EXPECT_EQ(url_google_.host(), delegate->changes()[2].first.Domain());
+ EXPECT_EQ(http_www_google_.url().host(),
+ delegate->changes()[2].first.Domain());
EXPECT_FALSE(delegate->changes()[2].second);
EXPECT_EQ("E", delegate->changes()[2].first.Name());
EXPECT_EQ("F", delegate->changes()[2].first.Value());
delegate->reset();
- EXPECT_TRUE(FindAndDeleteCookie(cm.get(), url_google_.host(), "C"));
- EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(
+ FindAndDeleteCookie(cm.get(), http_www_google_.url().host(), "C"));
+ EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
ASSERT_EQ(1u, delegate->changes().size());
- EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain());
+ EXPECT_EQ(http_www_google_.url().host(),
+ delegate->changes()[0].first.Domain());
EXPECT_TRUE(delegate->changes()[0].second);
EXPECT_EQ("C", delegate->changes()[0].first.Name());
EXPECT_EQ("D", delegate->changes()[0].first.Value());
delegate->reset();
EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E"));
- EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_));
+ EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url()));
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(), http_www_google_.url(),
"a=val1; path=/path1; "
"expires=Mon, 18-Apr-22 22:50:13 GMT"));
ASSERT_EQ(1u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
ASSERT_EQ(1u, delegate->changes().size());
EXPECT_FALSE(delegate->changes()[0].second);
- EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain());
+ EXPECT_EQ(http_www_google_.url().host(),
+ delegate->changes()[0].first.Domain());
EXPECT_EQ("a", delegate->changes()[0].first.Name());
EXPECT_EQ("val1", delegate->changes()[0].first.Value());
delegate->reset();
@@ -1608,7 +1640,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(), http_www_google_.url(),
"a=val2; path=/path1; httponly; "
"expires=Mon, 18-Apr-22 22:50:14 GMT",
allow_httponly));
@@ -1616,11 +1648,13 @@ TEST_F(CookieMonsterTest, CookieMonsterDelegate) {
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
ASSERT_EQ(2u, delegate->changes().size());
- EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain());
+ EXPECT_EQ(http_www_google_.url().host(),
+ delegate->changes()[0].first.Domain());
EXPECT_TRUE(delegate->changes()[0].second);
EXPECT_EQ("a", delegate->changes()[0].first.Name());
EXPECT_EQ("val1", delegate->changes()[0].first.Value());
- EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain());
+ EXPECT_EQ(http_www_google_.url().host(),
+ delegate->changes()[1].first.Domain());
EXPECT_FALSE(delegate->changes()[1].second);
EXPECT_EQ("a", delegate->changes()[1].first.Name());
EXPECT_EQ("val2", delegate->changes()[1].first.Value());
@@ -1630,40 +1664,40 @@ 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",
+ EXPECT_TRUE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A", "B",
std::string(), "/foo", base::Time(), false,
false, false, COOKIE_PRIORITY_DEFAULT));
- EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_bar_, "C", "D",
- "google.izzle", "/bar", base::Time(), false,
- true, false, COOKIE_PRIORITY_DEFAULT));
EXPECT_TRUE(SetCookieWithDetails(
- cm.get(), url_google_, "E", "F", std::string(), std::string(),
+ cm.get(), www_google_bar_.url(), "C", "D", www_google_bar_.domain(),
+ "/bar", base::Time(), false, true, false, COOKIE_PRIORITY_DEFAULT));
+ EXPECT_TRUE(SetCookieWithDetails(
+ cm.get(), http_www_google_.url(), "E", "F", std::string(), std::string(),
base::Time(), true, false, false, COOKIE_PRIORITY_DEFAULT));
// Test that malformed attributes fail to set the cookie.
- EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, " A", "B",
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), " A", "B",
std::string(), "/foo", base::Time(), false,
false, false, COOKIE_PRIORITY_DEFAULT));
- EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A;", "B",
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A;", "B",
std::string(), "/foo", base::Time(), false,
false, false, COOKIE_PRIORITY_DEFAULT));
- EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B",
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A=", "B",
std::string(), "/foo", base::Time(), false,
false, false, COOKIE_PRIORITY_DEFAULT));
EXPECT_FALSE(SetCookieWithDetails(
- cm.get(), url_google_foo_, "A", "B", "google.ozzzzzzle", "foo",
+ cm.get(), www_google_foo_.url(), "A", "B", "google.ozzzzzzle", "foo",
base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
- EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B",
+ EXPECT_FALSE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A=", "B",
std::string(), "foo", base::Time(), false,
false, false, COOKIE_PRIORITY_DEFAULT));
- CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_);
+ CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url());
CookieList::iterator it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
EXPECT_EQ("A", it->Name());
EXPECT_EQ("B", it->Value());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(www_google_foo_.host(), it->Domain());
EXPECT_EQ("/foo", it->Path());
EXPECT_FALSE(it->IsPersistent());
EXPECT_FALSE(it->IsSecure());
@@ -1671,27 +1705,27 @@ TEST_F(CookieMonsterTest, SetCookieWithDetails) {
ASSERT_TRUE(++it == cookies.end());
- cookies = GetAllCookiesForURL(cm.get(), url_google_bar_);
+ cookies = GetAllCookiesForURL(cm.get(), www_google_bar_.url());
it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
EXPECT_EQ("C", it->Name());
EXPECT_EQ("D", it->Value());
- EXPECT_EQ(".google.izzle", it->Domain());
+ EXPECT_EQ(www_google_bar_.Format(".%D"), it->Domain());
EXPECT_EQ("/bar", it->Path());
EXPECT_FALSE(it->IsSecure());
EXPECT_TRUE(it->IsHttpOnly());
ASSERT_TRUE(++it == cookies.end());
- cookies = GetAllCookiesForURL(cm.get(), url_google_secure_);
+ cookies = GetAllCookiesForURL(cm.get(), https_www_google_.url());
it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
EXPECT_EQ("E", it->Name());
EXPECT_EQ("F", it->Value());
EXPECT_EQ("/", it->Path());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(https_www_google_.host(), it->Domain());
EXPECT_TRUE(it->IsSecure());
EXPECT_FALSE(it->IsHttpOnly());
@@ -1779,26 +1813,29 @@ TEST_F(CookieMonsterTest, UniqueCreationTime) {
// SetCookie, SetCookieWithOptions, SetCookieWithDetails
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie1=A"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie2=A"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie3=A"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie1=A"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie2=A"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie3=A"));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_,
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
"setCookieWithOptions1=A", options));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_,
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
"setCookieWithOptions2=A", options));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_,
+ EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(),
"setCookieWithOptions3=A", options));
EXPECT_TRUE(SetCookieWithDetails(
- cm.get(), url_google_, "setCookieWithDetails1", "A", ".google.izzle", "/",
- Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
+ cm.get(), http_www_google_.url(), "setCookieWithDetails1", "A",
+ http_www_google_.Format(".%D"), "/", Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT));
EXPECT_TRUE(SetCookieWithDetails(
- cm.get(), url_google_, "setCookieWithDetails2", "A", ".google.izzle", "/",
- Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
+ cm.get(), http_www_google_.url(), "setCookieWithDetails2", "A",
+ http_www_google_.Format(".%D"), "/", Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT));
EXPECT_TRUE(SetCookieWithDetails(
- cm.get(), url_google_, "setCookieWithDetails3", "A", ".google.izzle", "/",
- Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
+ cm.get(), http_www_google_.url(), "setCookieWithDetails3", "A",
+ http_www_google_.Format(".%D"), "/", Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT));
// Now we check
CookieList cookie_list(GetAllCookies(cm.get()));
@@ -2059,7 +2096,7 @@ TEST_F(CookieMonsterTest, KeepExpiredCookies) {
// Set a persistent cookie.
ASSERT_TRUE(SetCookieWithOptions(
- cm.get(), url_google_,
+ cm.get(), http_www_google_.url(),
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT",
options));
@@ -2069,7 +2106,7 @@ TEST_F(CookieMonsterTest, KeepExpiredCookies) {
// Use a past expiry date to delete the cookie.
ASSERT_TRUE(SetCookieWithOptions(
- cm.get(), url_google_,
+ cm.get(), http_www_google_.url(),
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
options));
@@ -2194,19 +2231,21 @@ TEST_F(CookieMonsterTest, SetAllCookies) {
scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
cm->SetPersistSessionCookies(true);
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "U=V; path=/"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "W=X; path=/foo"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "Y=Z; path=/"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/"));
CookieList list;
- list.push_back(CanonicalCookie(url_google_, "A", "B", url_google_.host(), "/",
+ list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B",
+ http_www_google_.url().host(), "/",
base::Time::Now(), base::Time(), base::Time(),
false, false, false, COOKIE_PRIORITY_DEFAULT));
- list.push_back(CanonicalCookie(url_google_, "W", "X", url_google_.host(),
- "/bar", base::Time::Now(), base::Time(),
- base::Time(), false, false, false,
- COOKIE_PRIORITY_DEFAULT));
- list.push_back(CanonicalCookie(url_google_, "Y", "Z", url_google_.host(), "/",
+ list.push_back(CanonicalCookie(http_www_google_.url(), "W", "X",
+ http_www_google_.url().host(), "/bar",
+ base::Time::Now(), base::Time(), base::Time(),
+ false, false, false, COOKIE_PRIORITY_DEFAULT));
+ list.push_back(CanonicalCookie(http_www_google_.url(), "Y", "Z",
+ http_www_google_.url().host(), "/",
base::Time::Now(), base::Time(), base::Time(),
false, false, false, COOKIE_PRIORITY_DEFAULT));
@@ -2240,39 +2279,49 @@ TEST_F(CookieMonsterTest, ComputeCookieDiff) {
base::Time now = base::Time::Now();
base::Time creation_time = now - base::TimeDelta::FromSeconds(1);
- CanonicalCookie cookie1(url_google_, "A", "B", url_google_.host(), "/",
- creation_time, base::Time(), base::Time(), false,
- false, false, COOKIE_PRIORITY_DEFAULT);
- CanonicalCookie cookie2(url_google_, "C", "D", url_google_.host(), "/",
- creation_time, base::Time(), base::Time(), false,
- false, false, COOKIE_PRIORITY_DEFAULT);
- CanonicalCookie cookie3(url_google_, "E", "F", url_google_.host(), "/",
- creation_time, base::Time(), base::Time(), false,
- false, false, COOKIE_PRIORITY_DEFAULT);
- CanonicalCookie cookie4(url_google_, "G", "H", url_google_.host(), "/",
- creation_time, base::Time(), base::Time(), false,
- false, false, COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie1(http_www_google_.url(), "A", "B",
+ http_www_google_.url().host(), "/", creation_time,
+ base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie2(http_www_google_.url(), "C", "D",
+ http_www_google_.url().host(), "/", creation_time,
+ base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie3(http_www_google_.url(), "E", "F",
+ http_www_google_.url().host(), "/", creation_time,
+ base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie4(http_www_google_.url(), "G", "H",
+ http_www_google_.url().host(), "/", creation_time,
+ base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
CanonicalCookie cookie4_with_new_value(
- url_google_, "G", "iamnew", url_google_.host(), "/", creation_time,
- base::Time(), base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT);
- CanonicalCookie cookie5(url_google_, "I", "J", url_google_.host(), "/",
- creation_time, base::Time(), base::Time(), false,
- false, false, COOKIE_PRIORITY_DEFAULT);
+ http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), "/",
+ creation_time, base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie5(http_www_google_.url(), "I", "J",
+ http_www_google_.url().host(), "/", creation_time,
+ base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
CanonicalCookie cookie5_with_new_creation_time(
- url_google_, "I", "J", url_google_.host(), "/", now, base::Time(),
- base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT);
- CanonicalCookie cookie6(url_google_, "K", "L", url_google_.host(), "/foo",
- creation_time, base::Time(), base::Time(), false,
- false, false, COOKIE_PRIORITY_DEFAULT);
- CanonicalCookie cookie6_with_new_path(
- url_google_, "K", "L", url_google_.host(), "/bar", creation_time,
+ http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", now,
base::Time(), base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT);
- CanonicalCookie cookie7(url_google_, "M", "N", url_google_.host(), "/foo",
- creation_time, base::Time(), base::Time(), false,
- false, false, COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie6(http_www_google_.url(), "K", "L",
+ http_www_google_.url().host(), "/foo", creation_time,
+ base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie6_with_new_path(
+ http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/bar",
+ creation_time, base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
+ CanonicalCookie cookie7(http_www_google_.url(), "M", "N",
+ http_www_google_.url().host(), "/foo", creation_time,
+ base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
CanonicalCookie cookie7_with_new_path(
- url_google_, "M", "N", url_google_.host(), "/bar", creation_time,
- base::Time(), base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT);
+ http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/bar",
+ creation_time, base::Time(), base::Time(), false, false, false,
+ COOKIE_PRIORITY_DEFAULT);
CookieList old_cookies;
old_cookies.push_back(cookie1);
@@ -2345,7 +2394,7 @@ TEST_F(CookieMonsterTest, DeleteAll) {
scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
cm->SetPersistSessionCookies(true);
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "X=Y; path=/"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/"));
ASSERT_EQ(0, store->flush_count());
EXPECT_EQ(1, DeleteAll(cm.get()));
@@ -2373,7 +2422,7 @@ TEST_F(CookieMonsterTest, HistogramCheck) {
EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount());
// kValidCookieLine creates a session cookie.
- ASSERT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine));
+ ASSERT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine));
scoped_ptr<base::HistogramSamples> samples3(
expired_histogram->SnapshotSamples());
@@ -2484,11 +2533,11 @@ class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
CookieList cookies = GetAllCookies(cm.get());
CookieList::const_iterator it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.host(), it->Domain());
EXPECT_EQ("A", it->Name());
ASSERT_TRUE(++it == cookies.end());
GetCookieListCallback callback(&other_thread_);
@@ -2499,66 +2548,66 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) {
EXPECT_TRUE(callback.did_run());
it = callback.cookies().begin();
ASSERT_TRUE(it != callback.cookies().end());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.host(), it->Domain());
EXPECT_EQ("A", it->Name());
ASSERT_TRUE(++it == callback.cookies().end());
}
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
- CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_);
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
+ CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url());
CookieList::const_iterator it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.host(), it->Domain());
EXPECT_EQ("A", it->Name());
ASSERT_TRUE(++it == cookies.end());
GetCookieListCallback callback(&other_thread_);
base::Closure task =
base::Bind(&MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask,
- base::Unretained(this), cm, url_google_, &callback);
+ base::Unretained(this), cm, http_www_google_.url(), &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
it = callback.cookies().begin();
ASSERT_TRUE(it != callback.cookies().end());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.host(), it->Domain());
EXPECT_EQ("A", it->Name());
ASSERT_TRUE(++it == callback.cookies().end());
}
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
CookieOptions options;
CookieList cookies =
- GetAllCookiesForURLWithOptions(cm.get(), url_google_, options);
+ GetAllCookiesForURLWithOptions(cm.get(), http_www_google_.url(), options);
CookieList::const_iterator it = cookies.begin();
ASSERT_TRUE(it != cookies.end());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.host(), it->Domain());
EXPECT_EQ("A", it->Name());
ASSERT_TRUE(++it == cookies.end());
GetCookieListCallback callback(&other_thread_);
base::Closure task = base::Bind(
&MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask,
- base::Unretained(this), cm, url_google_, options, &callback);
+ base::Unretained(this), cm, http_www_google_.url(), options, &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
it = callback.cookies().begin();
ASSERT_TRUE(it != callback.cookies().end());
- EXPECT_EQ("www.google.izzle", it->Domain());
+ EXPECT_EQ(http_www_google_.host(), it->Domain());
EXPECT_EQ("A", it->Name());
ASSERT_TRUE(++it == callback.cookies().end());
}
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
- EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B",
+ EXPECT_TRUE(SetCookieWithDetails(cm.get(), www_google_foo_.url(), "A", "B",
std::string(), "/foo", base::Time(), false,
false, false, COOKIE_PRIORITY_DEFAULT));
ResultSavingCookieCallback<bool> callback(&other_thread_);
base::Closure task =
base::Bind(&MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask,
- base::Unretained(this), cm, url_google_foo_, &callback);
+ base::Unretained(this), cm, www_google_foo_.url(), &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_TRUE(callback.result());
@@ -2568,10 +2617,12 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
CookieOptions options;
Time now = Time::Now();
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99),
Time()));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
ResultSavingCookieCallback<int> callback(&other_thread_);
base::Closure task =
base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask,
@@ -2585,13 +2636,15 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) {
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
CookieOptions options;
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
- EXPECT_EQ(1, DeleteAllForHost(cm.get(), url_google_));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
+ EXPECT_EQ(1, DeleteAllForHost(cm.get(), http_www_google_.url()));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
ResultSavingCookieCallback<int> callback(&other_thread_);
base::Closure task =
base::Bind(&MultiThreadedCookieMonsterTest::DeleteAllForHostTask,
- base::Unretained(this), cm, url_google_, &callback);
+ base::Unretained(this), cm, http_www_google_.url(), &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_EQ(1, callback.result());
@@ -2610,29 +2663,35 @@ TEST_F(MultiThreadedCookieMonsterTest,
Time ago3 = now - TimeDelta::FromDays(99);
// These 3 cookies match the first deletion.
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "C=D", options));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "Y=Z", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "C=D", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "Y=Z", options));
// This cookie does not match host.
EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_not_google, "E=F", options));
// This cookie does not match time range: [ago3, inf], for first deletion, but
// matches for the second deletion.
- EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "G=H", ago2));
+ EXPECT_TRUE(
+ cm->SetCookieWithCreationTime(http_www_google_.url(), "G=H", ago2));
// 1. First set of deletions.
- EXPECT_EQ(
- 3, // Deletes A=B, C=D, Y=Z
- DeleteAllCreatedBetweenForHost(cm.get(), ago3, Time::Max(), url_google_));
+ EXPECT_EQ(3, // Deletes A=B, C=D, Y=Z
+ DeleteAllCreatedBetweenForHost(cm.get(), ago3, Time::Max(),
+ http_www_google_.url()));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
ResultSavingCookieCallback<int> callback(&other_thread_);
// 2. Second set of deletions.
base::Closure task = base::Bind(
&MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask,
- base::Unretained(this), cm, ago1, Time(), url_google_, &callback);
+ base::Unretained(this), cm, ago1, Time(), http_www_google_.url(),
+ &callback);
RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H.
@@ -2641,12 +2700,14 @@ TEST_F(MultiThreadedCookieMonsterTest,
TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) {
scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
CookieOptions options;
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
CookieList cookies = GetAllCookies(cm.get());
CookieList::iterator it = cookies.begin();
EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it));
- EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
+ EXPECT_TRUE(
+ SetCookieWithOptions(cm.get(), http_www_google_.url(), "A=B", options));
ResultSavingCookieCallback<bool> callback(&other_thread_);
cookies = GetAllCookies(cm.get());
it = cookies.begin();
@@ -2665,8 +2726,8 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) {
TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
std::vector<CanonicalCookie*> cookies;
// This cookie will be freed by the CookieMonster.
- cookies.push_back(CanonicalCookie::Create(url_google_, kValidCookieLine,
- Time::Now(), CookieOptions()));
+ cookies.push_back(CanonicalCookie::Create(
+ http_www_google_.url(), kValidCookieLine, Time::Now(), CookieOptions()));
CanonicalCookie cookie = *cookies[0];
scoped_refptr<NewMockPersistentCookieStore> store(
new NewMockPersistentCookieStore);
@@ -2674,8 +2735,8 @@ TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback;
::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint;
- const std::string key =
- cookie_util::GetEffectiveDomain(url_google_.scheme(), url_google_.host());
+ const std::string key = cookie_util::GetEffectiveDomain(
+ http_www_google_.url().scheme(), http_www_google_.url().host());
::testing::InSequence s;
EXPECT_CALL(checkpoint, Call(0));
@@ -2690,7 +2751,7 @@ TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
GetCookieListCallback callback;
checkpoint.Call(0);
- GetAllCookiesForURLTask(cm.get(), url_google_, &callback);
+ GetAllCookiesForURLTask(cm.get(), http_www_google_.url(), &callback);
checkpoint.Call(1);
ASSERT_FALSE(callback.did_run());
// Pass the cookies to the CookieMonster.
@@ -2703,10 +2764,8 @@ TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
// All urls in |urls| should share the same cookie domain.
const GURL kUrls[] = {
- url_google_,
- url_google_secure_,
- GURL(kUrlGoogleWebSocket),
- GURL(kUrlGoogleWebSocketSecure),
+ http_www_google_.url(), https_www_google_.url(), ws_www_google_.url(),
+ wss_www_google_.url(),
};
for (const GURL& url : kUrls) {
// Call the function with |url| and verify it is done synchronously without
@@ -2723,7 +2782,7 @@ 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()));
+ http_www_google_.url(), cookie_line, Time::Now(), CookieOptions()));
ASSERT_FALSE(cookie->IsPersistent());
}
@@ -2735,8 +2794,8 @@ TEST_F(CookieMonsterTest, PersistSessionCookies) {
cm->SetPersistSessionCookies(true);
// All cookies set with SetCookie are session cookies.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
- EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B"));
+ EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
// The cookie was written to the backing store.
EXPECT_EQ(1u, store->commands().size());
@@ -2745,8 +2804,8 @@ TEST_F(CookieMonsterTest, PersistSessionCookies) {
EXPECT_EQ("B", store->commands()[0].cookie.Value());
// Modify the cookie.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=C"));
- EXPECT_EQ("A=C", GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=C"));
+ EXPECT_EQ("A=C", GetCookies(cm.get(), http_www_google_.url()));
EXPECT_EQ(3u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
EXPECT_EQ("A", store->commands()[1].cookie.Name());
@@ -2756,8 +2815,8 @@ TEST_F(CookieMonsterTest, PersistSessionCookies) {
EXPECT_EQ("C", store->commands()[2].cookie.Value());
// Delete the cookie.
- DeleteCookie(cm.get(), url_google_, "A");
- EXPECT_EQ("", GetCookies(cm.get(), url_google_));
+ DeleteCookie(cm.get(), http_www_google_.url(), "A");
+ EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url()));
EXPECT_EQ(4u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
EXPECT_EQ("A", store->commands()[3].cookie.Name());
@@ -2770,35 +2829,37 @@ TEST_F(CookieMonsterTest, PersisentCookieStorageTest) {
scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
// Add a cookie.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_,
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
"A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
- this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_));
+ this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url()));
ASSERT_EQ(1u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
// Remove it.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; max-age=0"));
- this->MatchCookieLines(std::string(), GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0"));
+ this->MatchCookieLines(std::string(),
+ GetCookies(cm.get(), http_www_google_.url()));
ASSERT_EQ(2u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
// Add a cookie.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_,
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
"A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
- this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_));
+ this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url()));
ASSERT_EQ(3u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
// Overwrite it.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_,
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
"A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT"));
- this->MatchCookieLines("A=Foo", GetCookies(cm.get(), url_google_));
+ this->MatchCookieLines("A=Foo", GetCookies(cm.get(), http_www_google_.url()));
ASSERT_EQ(5u, store->commands().size());
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type);
// Create some non-persistent cookies and check that they don't go to the
// persistent storage.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=Bar"));
- this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm.get(), url_google_));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=Bar"));
+ this->MatchCookieLines("A=Foo; B=Bar",
+ GetCookies(cm.get(), http_www_google_.url()));
EXPECT_EQ(5u, store->commands().size());
}
@@ -2850,21 +2911,23 @@ TEST_F(CookieMonsterTest, CookieSourceHistogram) {
histograms.ExpectTotalCount(cookie_source_histogram, 0);
// Set a Secure cookie on a cryptographic scheme.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "A=B; path=/; Secure"));
+ EXPECT_TRUE(
+ SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure"));
histograms.ExpectTotalCount(cookie_source_histogram, 1);
histograms.ExpectBucketCount(
cookie_source_histogram,
CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1);
// Set a non-Secure cookie on a cryptographic scheme.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "C=D; path=/;"));
+ EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "C=D; path=/;"));
histograms.ExpectTotalCount(cookie_source_histogram, 2);
histograms.ExpectBucketCount(
cookie_source_histogram,
CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1);
// Set a Secure cookie on a non-cryptographic scheme.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "D=E; path=/; Secure"));
+ EXPECT_TRUE(
+ SetCookie(cm.get(), http_www_google_.url(), "D=E; path=/; Secure"));
histograms.ExpectTotalCount(cookie_source_histogram, 3);
histograms.ExpectBucketCount(
cookie_source_histogram,
@@ -2872,7 +2935,8 @@ TEST_F(CookieMonsterTest, CookieSourceHistogram) {
// Overwrite a Secure cookie (set by a cryptographic scheme) on a
// non-cryptographic scheme.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; path=/; Secure"));
+ EXPECT_TRUE(
+ SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/; Secure"));
histograms.ExpectTotalCount(cookie_source_histogram, 4);
histograms.ExpectBucketCount(
cookie_source_histogram,
@@ -2883,18 +2947,19 @@ TEST_F(CookieMonsterTest, CookieSourceHistogram) {
// Test that clearing a Secure cookie on a http:// URL does not get
// counted.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "F=G; path=/; Secure"));
+ EXPECT_TRUE(
+ SetCookie(cm.get(), https_www_google_.url(), "F=G; path=/; Secure"));
histograms.ExpectTotalCount(cookie_source_histogram, 5);
- std::string cookies1 = GetCookies(cm.get(), url_google_secure_);
+ std::string cookies1 = GetCookies(cm.get(), https_www_google_.url());
EXPECT_NE(std::string::npos, cookies1.find("F=G"));
- EXPECT_TRUE(SetCookie(cm.get(), url_google_,
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(),
"F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT"));
- std::string cookies2 = GetCookies(cm.get(), url_google_secure_);
+ std::string cookies2 = GetCookies(cm.get(), https_www_google_.url());
EXPECT_EQ(std::string::npos, cookies2.find("F=G"));
histograms.ExpectTotalCount(cookie_source_histogram, 5);
// Set a non-Secure cookie on a non-cryptographic scheme.
- EXPECT_TRUE(SetCookie(cm.get(), url_google_, "H=I; path=/"));
+ EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/"));
histograms.ExpectTotalCount(cookie_source_histogram, 6);
histograms.ExpectBucketCount(
cookie_source_histogram,
diff --git a/net/cookies/cookie_store_test_helpers.cc b/net/cookies/cookie_store_test_helpers.cc
index 49f9d9a..e75039c 100644
--- a/net/cookies/cookie_store_test_helpers.cc
+++ b/net/cookies/cookie_store_test_helpers.cc
@@ -7,7 +7,27 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
+#include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h"
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
+
+using net::registry_controlled_domains::GetDomainAndRegistry;
+using net::registry_controlled_domains::GetRegistryLength;
+using net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES;
+using net::registry_controlled_domains::INCLUDE_UNKNOWN_REGISTRIES;
+
+namespace {
+
+std::string GetRegistry(const GURL& url) {
+ size_t registry_length = GetRegistryLength(url, INCLUDE_UNKNOWN_REGISTRIES,
+ INCLUDE_PRIVATE_REGISTRIES);
+ if (registry_length == 0)
+ return std::string();
+ return std::string(url.host(), url.host().length() - registry_length,
+ registry_length);
+}
+
+} // namespace
namespace net {
@@ -143,4 +163,25 @@ DelayedCookieMonster::AddCallbackForCookie(
return scoped_ptr<CookieStore::CookieChangedSubscription>();
}
+//
+// CookieURLHelper
+//
+CookieURLHelper::CookieURLHelper(const std::string& url_string)
+ : url_(url_string),
+ registry_(GetRegistry(url_)),
+ domain_and_registry_(
+ GetDomainAndRegistry(url_, INCLUDE_PRIVATE_REGISTRIES)) {}
+
+const GURL CookieURLHelper::AppendPath(const std::string& path) const {
+ return GURL(url_.spec() + path);
+}
+
+std::string CookieURLHelper::Format(const std::string& format_string) const {
+ std::string new_string = format_string;
+ base::ReplaceSubstringsAfterOffset(&new_string, 0, "%D",
+ domain_and_registry_);
+ base::ReplaceSubstringsAfterOffset(&new_string, 0, "%R", registry_);
+ return new_string;
+}
+
} // namespace net
diff --git a/net/cookies/cookie_store_test_helpers.h b/net/cookies/cookie_store_test_helpers.h
index 760b847..1750c7f 100644
--- a/net/cookies/cookie_store_test_helpers.h
+++ b/net/cookies/cookie_store_test_helpers.h
@@ -70,7 +70,6 @@ class DelayedCookieMonster : public CookieStore {
const CookieChangedCallback& callback) override;
private:
-
// Be called immediately from CookieMonster.
void SetCookiesInternalCallback(bool result);
@@ -96,6 +95,26 @@ class DelayedCookieMonster : public CookieStore {
std::string cookie_line_;
};
+class CookieURLHelper {
+ public:
+ explicit CookieURLHelper(const std::string& url_string);
+
+ const std::string& domain() const { return domain_and_registry_; }
+ std::string host() const { return url_.host(); }
+ const GURL& url() const { return url_; }
+ const GURL AppendPath(const std::string& path) const;
+
+ // Return a new string with the following substitutions:
+ // 1. "%R" -> Domain registry (i.e. "com")
+ // 2. "%D" -> Domain + registry (i.e. "google.com")
+ std::string Format(const std::string& format_string) const;
+
+ private:
+ const GURL url_;
+ const std::string registry_;
+ const std::string domain_and_registry_;
+};
+
} // namespace net
#endif // NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_
diff --git a/net/cookies/cookie_store_unittest.h b/net/cookies/cookie_store_unittest.h
index 9892fae..b380fbc 100644
--- a/net/cookies/cookie_store_unittest.h
+++ b/net/cookies/cookie_store_unittest.h
@@ -5,6 +5,10 @@
#ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_
#define NET_COOKIES_COOKIE_STORE_UNITTEST_H_
+#include <set>
+#include <string>
+#include <vector>
+
#include "base/bind.h"
#include "base/location.h"
#include "base/message_loop/message_loop.h"
@@ -15,6 +19,7 @@
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_store_test_callbacks.h"
+#include "net/cookies/cookie_store_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
@@ -32,15 +37,7 @@ using base::Thread;
const int kTimeout = 1000;
-const char kUrlFtp[] = "ftp://ftp.google.izzle/";
-const char kUrlGoogle[] = "http://www.google.izzle";
-const char kUrlGoogleFoo[] = "http://www.google.izzle/foo";
-const char kUrlGoogleBar[] = "http://www.google.izzle/bar";
-const char kUrlGoogleSecure[] = "https://www.google.izzle";
-const char kUrlGoogleWebSocket[] = "ws://www.google.izzle";
-const char kUrlGoogleWebSocketSecure[] = "wss://www.google.izzle";
const char kValidCookieLine[] = "A=B; path=/";
-const char kValidDomainCookieLine[] = "A=B; path=/; domain=google.izzle";
// The CookieStoreTestTraits must have the following members:
// struct CookieStoreTestTraits {
@@ -78,10 +75,13 @@ template <class CookieStoreTestTraits>
class CookieStoreTest : public testing::Test {
protected:
CookieStoreTest()
- : url_google_(kUrlGoogle),
- url_google_secure_(kUrlGoogleSecure),
- url_google_foo_(kUrlGoogleFoo),
- url_google_bar_(kUrlGoogleBar) {
+ : http_www_google_("http://www.google.izzle"),
+ https_www_google_("https://www.google.izzle"),
+ ftp_google_("ftp://ftp.google.izzle/"),
+ ws_www_google_("ws://www.google.izzle"),
+ wss_www_google_("wss://www.google.izzle"),
+ www_google_foo_("http://www.google.izzle/foo"),
+ www_google_bar_("http://www.google.izzle/bar") {
// This test may be used outside of the net test suite, and thus may not
// have a message loop.
if (!base::MessageLoop::current())
@@ -252,10 +252,13 @@ class CookieStoreTest : public testing::Test {
<< "\" does not match \"" << line << "\"";
}
- GURL url_google_;
- GURL url_google_secure_;
- GURL url_google_foo_;
- GURL url_google_bar_;
+ const CookieURLHelper http_www_google_;
+ const CookieURLHelper https_www_google_;
+ const CookieURLHelper ftp_google_;
+ const CookieURLHelper ws_www_google_;
+ const CookieURLHelper wss_www_google_;
+ const CookieURLHelper www_google_foo_;
+ const CookieURLHelper www_google_bar_;
scoped_ptr<base::WeakPtrFactory<base::MessageLoop> > weak_factory_;
scoped_ptr<base::MessageLoop> message_loop_;
@@ -282,55 +285,69 @@ TYPED_TEST_P(CookieStoreTest, TypeTest) {
TYPED_TEST_P(CookieStoreTest, DomainTest) {
scoped_refptr<CookieStore> cs(this->GetCookieStore());
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
- EXPECT_TRUE(this->SetCookie(
- cs.get(), this->url_google_, "C=D; domain=.google.izzle"));
- this->MatchCookieLines("A=B; C=D",
- this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
+ EXPECT_TRUE(
+ this->SetCookie(cs.get(), this->http_www_google_.url(),
+ this->http_www_google_.Format("C=D; domain=.%D")));
+ this->MatchCookieLines(
+ "A=B; C=D", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Verify that A=B was set as a host cookie rather than a domain
// cookie -- should not be accessible from a sub sub-domain.
this->MatchCookieLines(
- "C=D", this->GetCookies(cs.get(), GURL("http://foo.www.google.izzle")));
+ "C=D",
+ this->GetCookies(
+ cs.get(), GURL(this->http_www_google_.Format("http://foo.www.%D"))));
// Test and make sure we find domain cookies on the same domain.
- EXPECT_TRUE(this->SetCookie(
- cs.get(), this->url_google_, "E=F; domain=.www.google.izzle"));
- this->MatchCookieLines("A=B; C=D; E=F",
- this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_TRUE(
+ this->SetCookie(cs.get(), this->http_www_google_.url(),
+ this->http_www_google_.Format("E=F; domain=.www.%D")));
+ this->MatchCookieLines(
+ "A=B; C=D; E=F",
+ this->GetCookies(cs.get(), this->http_www_google_.url()));
// Test setting a domain= that doesn't start w/ a dot, should
// treat it as a domain cookie, as if there was a pre-pended dot.
- EXPECT_TRUE(this->SetCookie(
- cs.get(), this->url_google_, "G=H; domain=www.google.izzle"));
- this->MatchCookieLines("A=B; C=D; E=F; G=H",
- this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_TRUE(
+ this->SetCookie(cs.get(), this->http_www_google_.url(),
+ this->http_www_google_.Format("G=H; domain=www.%D")));
+ this->MatchCookieLines(
+ "A=B; C=D; E=F; G=H",
+ this->GetCookies(cs.get(), this->http_www_google_.url()));
// Test domain enforcement, should fail on a sub-domain or something too deep.
EXPECT_FALSE(
- this->SetCookie(cs.get(), this->url_google_, "I=J; domain=.izzle"));
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), GURL("http://a.izzle")));
+ this->SetCookie(cs.get(), this->http_www_google_.url(),
+ this->http_www_google_.Format("I=J; domain=.%R")));
+ this->MatchCookieLines(
+ std::string(),
+ this->GetCookies(cs.get(),
+ GURL(this->http_www_google_.Format("http://a.%R"))));
EXPECT_FALSE(this->SetCookie(
- cs.get(), this->url_google_, "K=L; domain=.bla.www.google.izzle"));
+ cs.get(), this->http_www_google_.url(),
+ this->http_www_google_.Format("K=L; domain=.bla.www.%D")));
this->MatchCookieLines(
"C=D; E=F; G=H",
- this->GetCookies(cs.get(), GURL("http://bla.www.google.izzle")));
- this->MatchCookieLines("A=B; C=D; E=F; G=H",
- this->GetCookies(cs.get(), this->url_google_));
+ this->GetCookies(
+ cs.get(), GURL(this->http_www_google_.Format("http://bla.www.%D"))));
+ this->MatchCookieLines(
+ "A=B; C=D; E=F; G=H",
+ this->GetCookies(cs.get(), this->http_www_google_.url()));
}
// FireFox recognizes domains containing trailing periods as valid.
// IE and Safari do not. Assert the expected policy here.
TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) {
scoped_refptr<CookieStore> cs(this->GetCookieStore());
- EXPECT_FALSE(this->SetCookie(
- cs.get(), this->url_google_, "a=1; domain=.www.google.com."));
- EXPECT_FALSE(this->SetCookie(
- cs.get(), this->url_google_, "b=2; domain=.www.google.com.."));
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(),
+ "a=1; domain=.www.google.com."));
+ EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(),
+ "b=2; domain=.www.google.com.."));
+ this->MatchCookieLines(
+ std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
}
// Test that cookies can bet set on higher level domains.
@@ -599,18 +616,22 @@ TYPED_TEST_P(CookieStoreTest, InvalidScheme) {
return;
scoped_refptr<CookieStore> cs(this->GetCookieStore());
- EXPECT_FALSE(this->SetCookie(cs.get(), GURL(kUrlFtp), kValidCookieLine));
+ EXPECT_FALSE(
+ this->SetCookie(cs.get(), this->ftp_google_.url(), kValidCookieLine));
}
TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) {
if (!TypeParam::filters_schemes)
return;
+ const std::string kValidDomainCookieLine =
+ this->http_www_google_.Format("A=B; path=/; domain=%D");
+
scoped_refptr<CookieStore> cs(this->GetCookieStore());
- EXPECT_TRUE(
- this->SetCookie(cs.get(), GURL(kUrlGoogle), kValidDomainCookieLine));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
+ kValidDomainCookieLine));
this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), GURL(kUrlFtp)));
+ this->GetCookies(cs.get(), this->ftp_google_.url()));
}
TYPED_TEST_P(CookieStoreTest, PathTest) {
@@ -671,117 +692,124 @@ TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) {
options.set_include_httponly();
// Create a httponly cookie.
- EXPECT_TRUE(this->SetCookieWithOptions(
- cs.get(), this->url_google_, "A=B; httponly", options));
+ EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
+ "A=B; httponly", options));
// Check httponly read protection.
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
this->MatchCookieLines(
- "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
+ std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
+ this->MatchCookieLines(
+ "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
+ options));
// Check httponly overwrite protection.
- EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "A=C"));
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_FALSE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=C"));
this->MatchCookieLines(
- "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
- EXPECT_TRUE(
- this->SetCookieWithOptions(cs.get(), this->url_google_, "A=C", options));
- this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_));
+ std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
+ this->MatchCookieLines(
+ "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
+ options));
+ EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
+ "A=C", options));
+ this->MatchCookieLines(
+ "A=C", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Check httponly create protection.
- EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "B=A; httponly"));
+ EXPECT_FALSE(
+ this->SetCookie(cs.get(), this->http_www_google_.url(), "B=A; httponly"));
this->MatchCookieLines(
- "A=C", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
- EXPECT_TRUE(this->SetCookieWithOptions(
- cs.get(), this->url_google_, "B=A; httponly", options));
+ "A=C", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
+ options));
+ EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
+ "B=A; httponly", options));
+ this->MatchCookieLines("A=C; B=A",
+ this->GetCookiesWithOptions(
+ cs.get(), this->http_www_google_.url(), options));
this->MatchCookieLines(
- "A=C; B=A",
- this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
- this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_));
+ "A=C", this->GetCookies(cs.get(), this->http_www_google_.url()));
}
TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) {
scoped_refptr<CookieStore> cs(this->GetCookieStore());
// Create a session cookie.
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
+ kValidCookieLine));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Delete it via Max-Age.
- EXPECT_TRUE(this->SetCookie(cs.get(),
- this->url_google_,
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) + "; max-age=0"));
- this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string());
+ this->MatchCookieLineWithTimeout(cs.get(), this->http_www_google_.url(),
+ std::string());
// Create a session cookie.
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
+ kValidCookieLine));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Delete it via Expires.
- EXPECT_TRUE(this->SetCookie(cs.get(),
- this->url_google_,
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) +
"; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
// Create a persistent cookie.
EXPECT_TRUE(this->SetCookie(
- cs.get(),
- this->url_google_,
+ cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Delete it via Max-Age.
- EXPECT_TRUE(this->SetCookie(cs.get(),
- this->url_google_,
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) + "; max-age=0"));
- this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string());
+ this->MatchCookieLineWithTimeout(cs.get(), this->http_www_google_.url(),
+ std::string());
// Create a persistent cookie.
EXPECT_TRUE(this->SetCookie(
- cs.get(),
- this->url_google_,
+ cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Delete it via Expires.
- EXPECT_TRUE(this->SetCookie(cs.get(),
- this->url_google_,
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) +
"; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
// Create a persistent cookie.
EXPECT_TRUE(this->SetCookie(
- cs.get(),
- this->url_google_,
+ cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Check that it is not deleted with significant enough clock skew.
base::Time server_time;
EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT",
&server_time));
EXPECT_TRUE(this->SetCookieWithServerTime(
- cs.get(),
- this->url_google_,
+ cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
server_time));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Create a persistent cookie.
EXPECT_TRUE(this->SetCookie(
- cs.get(),
- this->url_google_,
+ cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Delete it via Expires, with a unix epoch of 0.
- EXPECT_TRUE(this->SetCookie(cs.get(),
- this->url_google_,
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
std::string(kValidCookieLine) +
"; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
}
TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
@@ -796,32 +824,35 @@ TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
base::TimeDelta::FromDays(30);
// Add a cookie.
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
// Check that the cookie is in the store.
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Remove cookies in empty intervals.
EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute));
EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month));
// Check that the cookie is still there.
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Remove the cookie with an interval defined by two dates.
EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, next_minute));
// Check that the cookie disappeared.
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
// Add another cookie.
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D"));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "C=D"));
// Check that the cookie is in the store.
- this->MatchCookieLines("C=D", this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ "C=D", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Remove the cookie with a null ending time.
EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, base::Time()));
// Check that the cookie disappeared.
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
+ this->MatchCookieLines(
+ std::string(), this->GetCookies(cs.get(), this->http_www_google_.url()));
}
TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) {
@@ -830,9 +861,9 @@ TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) {
base::Time now = base::Time::Now();
// These 3 cookies match the time range and host.
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D"));
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "Y=Z"));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "C=D"));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "Y=Z"));
// This cookie does not match host.
EXPECT_TRUE(this->SetCookie(cs.get(), url_not_google, "E=F"));
@@ -840,39 +871,43 @@ TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetweenForHost) {
// Delete cookies.
EXPECT_EQ(
3, // Deletes A=B, C=D, Y=Z
- this->DeleteAllCreatedBetweenForHost(
- cs.get(), now, base::Time::Max(), this->url_google_));
+ this->DeleteAllCreatedBetweenForHost(cs.get(), now, base::Time::Max(),
+ this->http_www_google_.url()));
}
TYPED_TEST_P(CookieStoreTest, TestSecure) {
scoped_refptr<CookieStore> cs(this->GetCookieStore());
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
- this->MatchCookieLines("A=B",
- this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
this->MatchCookieLines(
- "A=B", this->GetCookies(cs.get(), this->url_google_secure_));
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->https_www_google_.url()));
- EXPECT_TRUE(
- this->SetCookie(cs.get(), this->url_google_secure_, "A=B; secure"));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->https_www_google_.url(),
+ "A=B; secure"));
// The secure should overwrite the non-secure.
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
- this->MatchCookieLines("A=B",
- this->GetCookies(cs.get(), this->url_google_secure_));
+ this->MatchCookieLines(
+ std::string(),
+ this->GetCookies(cs.get(), this->http_www_google_.url()));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->https_www_google_.url()));
- EXPECT_TRUE(
- this->SetCookie(cs.get(), this->url_google_secure_, "D=E; secure"));
- this->MatchCookieLines(std::string(),
- this->GetCookies(cs.get(), this->url_google_));
- this->MatchCookieLines("A=B; D=E",
- this->GetCookies(cs.get(), this->url_google_secure_));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->https_www_google_.url(),
+ "D=E; secure"));
+ this->MatchCookieLines(
+ std::string(),
+ this->GetCookies(cs.get(), this->http_www_google_.url()));
+ this->MatchCookieLines(
+ "A=B; D=E", this->GetCookies(cs.get(), this->https_www_google_.url()));
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_secure_, "A=B"));
+ EXPECT_TRUE(
+ this->SetCookie(cs.get(), this->https_www_google_.url(), "A=B"));
// The non-secure should overwrite the secure.
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
- this->MatchCookieLines("D=E; A=B",
- this->GetCookies(cs.get(), this->url_google_secure_));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
+ this->MatchCookieLines(
+ "D=E; A=B", this->GetCookies(cs.get(), this->https_www_google_.url()));
}
static const int kLastAccessThresholdMilliseconds = 200;
@@ -993,18 +1028,18 @@ TYPED_TEST_P(CookieStoreTest, CookieOrdering) {
TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) {
scoped_refptr<CookieStore> cs(this->GetCookieStore());
// Create a session cookie and a persistent cookie.
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(),
+ std::string(kValidCookieLine)));
EXPECT_TRUE(this->SetCookie(
- cs.get(), this->url_google_, std::string(kValidCookieLine)));
- EXPECT_TRUE(this->SetCookie(cs.get(),
- this->url_google_,
- "C=D; path=/; domain=google.izzle;"
- "expires=Mon, 18-Apr-22 22:50:13 GMT"));
- this->MatchCookieLines("A=B; C=D",
- this->GetCookies(cs.get(), this->url_google_));
+ cs.get(), this->http_www_google_.url(),
+ this->http_www_google_.Format("C=D; path=/; domain=%D;"
+ "expires=Mon, 18-Apr-22 22:50:13 GMT")));
+ this->MatchCookieLines(
+ "A=B; C=D", this->GetCookies(cs.get(), this->http_www_google_.url()));
// Delete the session cookie.
this->DeleteSessionCookies(cs.get());
// Check that the session cookie has been deleted but not the persistent one.
- EXPECT_EQ("C=D", this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_EQ("C=D", this->GetCookies(cs.get(), this->http_www_google_.url()));
}
REGISTER_TYPED_TEST_CASE_P(CookieStoreTest,
@@ -1110,12 +1145,13 @@ TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest);
// thread).
TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) {
scoped_refptr<CookieStore> cs(this->GetCookieStore());
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
- this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
+ this->MatchCookieLines(
+ "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
StringResultCookieCallback callback(&this->other_thread_);
- base::Closure task =
- base::Bind(&MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask,
- base::Unretained(this), cs, this->url_google_, &callback);
+ base::Closure task = base::Bind(
+ &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask,
+ base::Unretained(this), cs, this->http_www_google_.url(), &callback);
this->RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_EQ("A=B", callback.result());
@@ -1126,13 +1162,15 @@ TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) {
CookieOptions options;
if (!TypeParam::supports_http_only)
options.set_include_httponly();
- EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
+ EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
this->MatchCookieLines(
- "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
+ "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
+ options));
StringResultCookieCallback callback(&this->other_thread_);
base::Closure task = base::Bind(
&MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask,
- base::Unretained(this), cs, this->url_google_, options, &callback);
+ base::Unretained(this), cs, this->http_www_google_.url(), options,
+ &callback);
this->RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_EQ("A=B", callback.result());
@@ -1143,12 +1181,13 @@ TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) {
CookieOptions options;
if (!TypeParam::supports_http_only)
options.set_include_httponly();
- EXPECT_TRUE(
- this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
+ EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
+ "A=B", options));
ResultSavingCookieCallback<bool> callback(&this->other_thread_);
base::Closure task = base::Bind(
&MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask,
- base::Unretained(this), cs, this->url_google_, "A=B", options, &callback);
+ base::Unretained(this), cs, this->http_www_google_.url(), "A=B", options,
+ &callback);
this->RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
EXPECT_TRUE(callback.result());
@@ -1159,15 +1198,15 @@ TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) {
CookieOptions options;
if (!TypeParam::supports_http_only)
options.set_include_httponly();
- EXPECT_TRUE(
- this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
- this->DeleteCookie(cs.get(), this->url_google_, "A");
- EXPECT_TRUE(
- this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
+ EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
+ "A=B", options));
+ this->DeleteCookie(cs.get(), this->http_www_google_.url(), "A");
+ EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
+ "A=B", options));
NoResultCookieCallback callback(&this->other_thread_);
- base::Closure task =
- base::Bind(&MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask,
- base::Unretained(this), cs, this->url_google_, "A", &callback);
+ base::Closure task = base::Bind(
+ &MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask,
+ base::Unretained(this), cs, this->http_www_google_.url(), "A", &callback);
this->RunOnOtherThread(task);
EXPECT_TRUE(callback.did_run());
}
@@ -1177,17 +1216,15 @@ TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) {
CookieOptions options;
if (!TypeParam::supports_http_only)
options.set_include_httponly();
- EXPECT_TRUE(
- this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
- EXPECT_TRUE(
- this->SetCookieWithOptions(cs.get(),
- this->url_google_,
- "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT",
- options));
+ EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
+ "A=B", options));
+ EXPECT_TRUE(this->SetCookieWithOptions(
+ cs.get(), this->http_www_google_.url(),
+ "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT", options));
EXPECT_EQ(1, this->DeleteSessionCookies(cs.get()));
EXPECT_EQ(0, this->DeleteSessionCookies(cs.get()));
- EXPECT_TRUE(
- this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
+ EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
+ "A=B", options));
ResultSavingCookieCallback<int> callback(&this->other_thread_);
base::Closure task = base::Bind(
&MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask,