summaryrefslogtreecommitdiffstats
path: root/net/base/cookie_monster_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/base/cookie_monster_unittest.cc')
-rw-r--r--net/base/cookie_monster_unittest.cc184
1 files changed, 146 insertions, 38 deletions
diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc
index 4c7dd4b..c2a5cae 100644
--- a/net/base/cookie_monster_unittest.cc
+++ b/net/base/cookie_monster_unittest.cc
@@ -100,6 +100,36 @@ class MockPersistentCookieStore
DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore);
};
+// Mock for CookieMonster::Delegate
+class MockCookieMonsterDelegate : public net::CookieMonster::Delegate {
+ public:
+ typedef std::pair<net::CookieMonster::CookieListPair, bool>
+ CookieNotification;
+
+ MockCookieMonsterDelegate() {}
+
+ virtual void OnCookieChanged(
+ const std::string& domain_key,
+ const net::CookieMonster::CanonicalCookie& cookie,
+ bool removed) {
+ CookieNotification notification(
+ net::CookieMonster::CookieListPair(domain_key, cookie),
+ removed);
+ changes_.push_back(notification);
+ }
+
+ const std::vector<CookieNotification>& changes() const { return changes_; }
+
+ void reset() { changes_.clear(); }
+
+ private:
+ virtual ~MockCookieMonsterDelegate() {}
+
+ std::vector<CookieNotification> changes_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockCookieMonsterDelegate);
+};
+
// Helper to build a list of KeyedCanonicalCookies.
void AddKeyedCookieToList(
const std::string& key,
@@ -360,7 +390,7 @@ TEST(CookieMonsterTest, DomainTest) {
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
EXPECT_TRUE(cm->SetCookie(url_google, "A=B"));
EXPECT_EQ("A=B", cm->GetCookies(url_google));
EXPECT_TRUE(cm->SetCookie(url_google, "C=D; domain=.google.izzle"));
@@ -396,7 +426,7 @@ TEST(CookieMonsterTest, DomainTest) {
TEST(CookieMonsterTest, DomainWithTrailingDotTest) {
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
GURL url_google("http://www.google.com");
EXPECT_FALSE(cm->SetCookie(url_google, "a=1; domain=.www.google.com."));
@@ -412,7 +442,7 @@ TEST(CookieMonsterTest, DomainWithTrailingDotTest) {
TEST(CookieMonsterTest, ValidSubdomainTest) {
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
GURL url_abcd("http://a.b.c.d.com");
GURL url_bcd("http://b.c.d.com");
GURL url_cd("http://c.d.com");
@@ -447,7 +477,7 @@ TEST(CookieMonsterTest, InvalidDomainTest) {
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
GURL url_foobar("http://foo.bar.com");
// More specific sub-domain than allowed.
@@ -487,7 +517,7 @@ TEST(CookieMonsterTest, InvalidDomainTest) {
// Make sure the cookie code hasn't gotten its subdomain string handling
// reversed, missed a suffix check, etc. It's important here that the two
// hosts below have the same domain + registry.
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url_foocom("http://foo.com.com");
EXPECT_FALSE(cm->SetCookie(url_foocom, "a=1; domain=.foo.com.com.com"));
EXPECT_EQ("", cm->GetCookies(url_foocom));
@@ -499,7 +529,7 @@ TEST(CookieMonsterTest, InvalidDomainTest) {
// http://b/issue?id=889898
TEST(CookieMonsterTest, DomainWithoutLeadingDotTest) {
{ // The omission of dot results in setting a domain cookie.
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url_hosted("http://manage.hosted.filefront.com");
GURL url_filefront("http://www.filefront.com");
EXPECT_TRUE(cm->SetCookie(url_hosted, "sawAd=1; domain=filefront.com"));
@@ -508,7 +538,7 @@ TEST(CookieMonsterTest, DomainWithoutLeadingDotTest) {
}
{ // Even when the domains match exactly, don't consider it host cookie.
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url("http://www.google.com");
EXPECT_TRUE(cm->SetCookie(url, "a=1; domain=www.google.com"));
EXPECT_EQ("a=1", cm->GetCookies(url));
@@ -520,7 +550,7 @@ TEST(CookieMonsterTest, DomainWithoutLeadingDotTest) {
// Test that the domain specified in cookie string is treated case-insensitive
// http://b/issue?id=896475.
TEST(CookieMonsterTest, CaseInsensitiveDomainTest) {
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url_google("http://www.google.com");
EXPECT_TRUE(cm->SetCookie(url_google, "a=1; domain=.GOOGLE.COM"));
EXPECT_TRUE(cm->SetCookie(url_google, "b=2; domain=.wWw.gOOgLE.coM"));
@@ -530,13 +560,13 @@ TEST(CookieMonsterTest, CaseInsensitiveDomainTest) {
TEST(CookieMonsterTest, TestIpAddress) {
GURL url_ip("http://1.2.3.4/weee");
{
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
EXPECT_TRUE(cm->SetCookie(url_ip, kValidCookieLine));
EXPECT_EQ("A=B", cm->GetCookies(url_ip));
}
{ // IP addresses should not be able to set domain cookies.
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
EXPECT_FALSE(cm->SetCookie(url_ip, "b=2; domain=.1.2.3.4"));
EXPECT_FALSE(cm->SetCookie(url_ip, "c=3; domain=.3.4"));
EXPECT_EQ("", cm->GetCookies(url_ip));
@@ -552,7 +582,7 @@ TEST(CookieMonsterTest, TestIpAddress) {
// Test host cookies, and setting of cookies on TLD.
TEST(CookieMonsterTest, TestNonDottedAndTLD) {
{
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url("http://com/");
// Allow setting on "com", (but only as a host cookie).
EXPECT_TRUE(cm->SetCookie(url, "a=1"));
@@ -566,7 +596,7 @@ TEST(CookieMonsterTest, TestNonDottedAndTLD) {
}
{ // http://com. should be treated the same as http://com.
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url("http://com./index.html");
EXPECT_TRUE(cm->SetCookie(url, "a=1"));
EXPECT_EQ("a=1", cm->GetCookies(url));
@@ -574,7 +604,7 @@ TEST(CookieMonsterTest, TestNonDottedAndTLD) {
}
{ // Should not be able to set host cookie from a subdomain.
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url("http://a.b");
EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.b"));
EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=b"));
@@ -582,7 +612,7 @@ TEST(CookieMonsterTest, TestNonDottedAndTLD) {
}
{ // Same test as above, but explicitly on a known TLD (com).
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url("http://google.com");
EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.com"));
EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=com"));
@@ -590,7 +620,7 @@ TEST(CookieMonsterTest, TestNonDottedAndTLD) {
}
{ // Make sure can't set cookie on TLD which is dotted.
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url("http://google.co.uk");
EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.co.uk"));
EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.uk"));
@@ -600,7 +630,7 @@ TEST(CookieMonsterTest, TestNonDottedAndTLD) {
}
{ // Intranet URLs should only be able to set host cookies.
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url("http://b");
EXPECT_TRUE(cm->SetCookie(url, "a=1"));
EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.b"));
@@ -612,7 +642,7 @@ TEST(CookieMonsterTest, TestNonDottedAndTLD) {
// Test reading/writing cookies when the domain ends with a period,
// as in "www.google.com."
TEST(CookieMonsterTest, TestHostEndsWithDot) {
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url("http://www.google.com");
GURL url_with_dot("http://www.google.com.");
EXPECT_TRUE(cm->SetCookie(url, "a=1"));
@@ -632,19 +662,19 @@ TEST(CookieMonsterTest, TestHostEndsWithDot) {
}
TEST(CookieMonsterTest, InvalidScheme) {
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
EXPECT_FALSE(cm->SetCookie(GURL(kUrlFtp), kValidCookieLine));
}
TEST(CookieMonsterTest, InvalidScheme_Read) {
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
EXPECT_TRUE(cm->SetCookie(GURL(kUrlGoogle), kValidDomainCookieLine));
EXPECT_EQ("", cm->GetCookies(GURL(kUrlFtp)));
}
TEST(CookieMonsterTest, PathTest) {
std::string url("http://www.google.izzle");
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
EXPECT_TRUE(cm->SetCookie(GURL(url), "A=B; path=/wee"));
EXPECT_EQ("A=B", cm->GetCookies(GURL(url + "/wee")));
EXPECT_EQ("A=B", cm->GetCookies(GURL(url + "/wee/")));
@@ -661,7 +691,7 @@ TEST(CookieMonsterTest, PathTest) {
TEST(CookieMonsterTest, HttpOnlyTest) {
GURL url_google(kUrlGoogle);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
net::CookieOptions options;
options.set_include_httponly();
@@ -785,7 +815,7 @@ TEST(CookieMonsterTest, TestCookieDeletion) {
GURL url_google(kUrlGoogle);
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
// Create a session cookie.
EXPECT_TRUE(cm->SetCookie(url_google, kValidCookieLine));
@@ -854,7 +884,7 @@ TEST(CookieMonsterTest, TestCookieDeleteAll) {
GURL url_google(kUrlGoogle);
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
net::CookieOptions options;
options.set_include_httponly();
@@ -885,7 +915,7 @@ TEST(CookieMonsterTest, TestCookieDeleteAll) {
TEST(CookieMonsterTest, TestCookieDeleteAllCreatedAfterTimestamp) {
GURL url_google(kUrlGoogle);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
Time now = Time::Now();
// Nothing has been added so nothing should be deleted.
@@ -913,7 +943,7 @@ TEST(CookieMonsterTest, TestCookieDeleteAllCreatedAfterTimestamp) {
TEST(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
GURL url_google(kUrlGoogle);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
Time now = Time::Now();
// Nothing has been added so nothing should be deleted.
@@ -956,7 +986,7 @@ TEST(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
TEST(CookieMonsterTest, TestSecure) {
GURL url_google(kUrlGoogle);
GURL url_google_secure(kUrlGoogleSecure);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
EXPECT_TRUE(cm->SetCookie(url_google, "A=B"));
EXPECT_EQ("A=B", cm->GetCookies(url_google));
@@ -987,7 +1017,7 @@ static const int kLastAccessThresholdMilliseconds = 200;
TEST(CookieMonsterTest, TestLastAccess) {
GURL url_google(kUrlGoogle);
scoped_refptr<net::CookieMonster> cm(
- new net::CookieMonster(NULL, kLastAccessThresholdMilliseconds));
+ new net::CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
EXPECT_TRUE(cm->SetCookie(url_google, "A=B"));
const Time last_access_date(GetFirstCookieAccessDate(cm));
@@ -1015,7 +1045,7 @@ static int CountInString(const std::string& str, char c) {
TEST(CookieMonsterTest, TestHostGarbageCollection) {
GURL url_google(kUrlGoogle);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
// Add a bunch of cookies on a single host, should purge them.
for (int i = 0; i < 101; i++) {
std::string cookie = StringPrintf("a%03d=b", i);
@@ -1030,7 +1060,7 @@ TEST(CookieMonsterTest, TestHostGarbageCollection) {
TEST(CookieMonsterTest, TestTotalGarbageCollection) {
scoped_refptr<net::CookieMonster> cm(
- new net::CookieMonster(NULL, kLastAccessThresholdMilliseconds));
+ new net::CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
// Add a bunch of cookies on a bunch of host, some should get purged.
const GURL sticky_cookie("http://a0000.izzle");
@@ -1065,7 +1095,7 @@ TEST(CookieMonsterTest, TestTotalGarbageCollection) {
TEST(CookieMonsterTest, NetUtilCookieTest) {
const GURL test_url("http://mojo.jojo.google.izzle/");
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
EXPECT_TRUE(cm->SetCookie(test_url, "foo=bar"));
std::string value = cm->GetCookies(test_url);
@@ -1095,7 +1125,7 @@ static bool FindAndDeleteCookie(net::CookieMonster* cm,
TEST(CookieMonsterTest, TestDeleteSingleCookie) {
GURL url_google(kUrlGoogle);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
EXPECT_TRUE(cm->SetCookie(url_google, "A=B"));
EXPECT_TRUE(cm->SetCookie(url_google, "C=D"));
@@ -1110,8 +1140,8 @@ TEST(CookieMonsterTest, TestDeleteSingleCookie) {
}
TEST(CookieMonsterTest, SetCookieableSchemes) {
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
- scoped_refptr<net::CookieMonster> cm_foo(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
+ scoped_refptr<net::CookieMonster> cm_foo(new net::CookieMonster(NULL, NULL));
// Only cm_foo should allow foo:// cookies.
const char* kSchemes[] = {"foo"};
@@ -1132,7 +1162,7 @@ TEST(CookieMonsterTest, GetAllCookiesForURL) {
GURL url_google_secure(kUrlGoogleSecure);
scoped_refptr<net::CookieMonster> cm(
- new net::CookieMonster(NULL, kLastAccessThresholdMilliseconds));
+ new net::CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
// Create an httponly cookie.
net::CookieOptions options;
@@ -1192,7 +1222,7 @@ TEST(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
GURL url_google_foo("http://www.google.izzle/foo");
GURL url_google_bar("http://www.google.izzle/bar");
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
net::CookieOptions options;
EXPECT_TRUE(cm->SetCookieWithOptions(url_google_foo,
@@ -1235,7 +1265,7 @@ TEST(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
}
TEST(CookieMonsterTest, DeleteCookieByName) {
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
GURL url_google(kUrlGoogle);
EXPECT_TRUE(cm->SetCookie(url_google, "A=A1; path=/"));
@@ -1264,7 +1294,7 @@ TEST(CookieMonsterTest, OverwritePersistentCookie) {
GURL url_chromium("http://chromium.org");
scoped_refptr<MockPersistentCookieStore> store(
new MockPersistentCookieStore);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
// Insert a cookie "a" for path "/path1"
EXPECT_TRUE(
@@ -1386,7 +1416,7 @@ TEST(CookieMonsterTest, DontImportDuplicateCookies) {
// Inject our initial cookies into the mock PersistentCookieStore.
store->SetLoadExpectation(true, initial_cookies);
- scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store));
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, NULL));
// Verify that duplicates were not imported for path "/".
// (If this had failed, GetCookies() would have also returned X=1, X=2, X=4).
@@ -1404,3 +1434,81 @@ TEST(CookieMonsterTest, DontImportDuplicateCookies) {
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type);
EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
}
+
+TEST(CookieMonsterTest, Delegate) {
+ GURL url_google(kUrlGoogle);
+
+ scoped_refptr<MockPersistentCookieStore> store(
+ new MockPersistentCookieStore);
+ scoped_refptr<MockCookieMonsterDelegate> delegate(
+ new MockCookieMonsterDelegate);
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(store, delegate));
+
+ EXPECT_TRUE(cm->SetCookie(url_google, "A=B"));
+ EXPECT_TRUE(cm->SetCookie(url_google, "C=D"));
+ EXPECT_TRUE(cm->SetCookie(url_google, "E=F"));
+ EXPECT_EQ("A=B; C=D; E=F", cm->GetCookies(url_google));
+ ASSERT_EQ(3u, delegate->changes().size());
+ EXPECT_EQ(false, delegate->changes()[0].second);
+ EXPECT_EQ(url_google.host(), delegate->changes()[0].first.first);
+ EXPECT_EQ("A", delegate->changes()[0].first.second.Name());
+ EXPECT_EQ("B", delegate->changes()[0].first.second.Value());
+ EXPECT_EQ(url_google.host(), delegate->changes()[1].first.first);
+ EXPECT_EQ(false, delegate->changes()[1].second);
+ EXPECT_EQ("C", delegate->changes()[1].first.second.Name());
+ EXPECT_EQ("D", delegate->changes()[1].first.second.Value());
+ EXPECT_EQ(url_google.host(), delegate->changes()[2].first.first);
+ EXPECT_EQ(false, delegate->changes()[2].second);
+ EXPECT_EQ("E", delegate->changes()[2].first.second.Name());
+ EXPECT_EQ("F", delegate->changes()[2].first.second.Value());
+ delegate->reset();
+
+ EXPECT_TRUE(FindAndDeleteCookie(cm, url_google.host(), "C"));
+ EXPECT_EQ("A=B; E=F", cm->GetCookies(url_google));
+ ASSERT_EQ(1u, delegate->changes().size());
+ EXPECT_EQ(url_google.host(), delegate->changes()[0].first.first);
+ EXPECT_EQ(true, delegate->changes()[0].second);
+ EXPECT_EQ("C", delegate->changes()[0].first.second.Name());
+ EXPECT_EQ("D", delegate->changes()[0].first.second.Value());
+ delegate->reset();
+
+ EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E"));
+ EXPECT_EQ("A=B; E=F", cm->GetCookies(url_google));
+ EXPECT_EQ(0u, delegate->changes().size());
+
+ // Insert a cookie "a" for path "/path1"
+ EXPECT_TRUE(
+ cm->SetCookie(url_google, "a=val1; path=/path1; "
+ "expires=Mon, 18-Apr-22 22:50:13 GMT"));
+ ASSERT_EQ(1u, store->commands().size());
+ EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
+ ASSERT_EQ(1u, delegate->changes().size());
+ EXPECT_EQ(false, delegate->changes()[0].second);
+ EXPECT_EQ(url_google.host(), delegate->changes()[0].first.first);
+ EXPECT_EQ("a", delegate->changes()[0].first.second.Name());
+ EXPECT_EQ("val1", delegate->changes()[0].first.second.Value());
+ delegate->reset();
+
+ // Insert a cookie "a" for path "/path1", that is httponly. This should
+ // overwrite the non-http-only version.
+ net::CookieOptions allow_httponly;
+ allow_httponly.set_include_httponly();
+ EXPECT_TRUE(
+ cm->SetCookieWithOptions(url_google,
+ "a=val2; path=/path1; httponly; "
+ "expires=Mon, 18-Apr-22 22:50:14 GMT",
+ allow_httponly));
+ ASSERT_EQ(3u, store->commands().size());
+ EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
+ EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
+ ASSERT_EQ(2u, delegate->changes().size());
+ EXPECT_EQ(url_google.host(), delegate->changes()[0].first.first);
+ EXPECT_EQ(true, delegate->changes()[0].second);
+ EXPECT_EQ("a", delegate->changes()[0].first.second.Name());
+ EXPECT_EQ("val1", delegate->changes()[0].first.second.Value());
+ EXPECT_EQ(url_google.host(), delegate->changes()[1].first.first);
+ EXPECT_EQ(false, delegate->changes()[1].second);
+ EXPECT_EQ("a", delegate->changes()[1].first.second.Name());
+ EXPECT_EQ("val2", delegate->changes()[1].first.second.Value());
+ delegate->reset();
+}