summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-30 14:48:15 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-30 14:48:15 +0000
commit6e2efc0462d72267c5a524411e4771e67da206e1 (patch)
tree4a04584732416447adae2132ec391c6ea5b8bde1 /net
parent08c0f98e3c63880dd0975afa9cd6a10c1f10c94e (diff)
downloadchromium_src-6e2efc0462d72267c5a524411e4771e67da206e1.zip
chromium_src-6e2efc0462d72267c5a524411e4771e67da206e1.tar.gz
chromium_src-6e2efc0462d72267c5a524411e4771e67da206e1.tar.bz2
DevTools: Allow deleting cookies.
Review URL: http://codereview.chromium.org/350001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30578 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/cookie_monster.cc27
-rw-r--r--net/base/cookie_monster_unittest.cc40
2 files changed, 61 insertions, 6 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc
index 2c2f21d..01b68a1 100644
--- a/net/base/cookie_monster.cc
+++ b/net/base/cookie_monster.cc
@@ -792,12 +792,27 @@ void CookieMonster::DeleteCookie(const GURL& url,
if (!HasCookieableScheme(url))
return;
- for (CookieMapItPair its = cookies_.equal_range(url.host());
- its.first != its.second; ++its.first) {
- if (its.first->second->Name() == cookie_name) {
- InternalDeleteCookie(its.first, true);
- return;
- }
+ CookieOptions options;
+ options.set_include_httponly();
+ // Get the cookies for this host and its domain(s).
+ std::vector<CanonicalCookie*> cookies;
+ FindCookiesForHostAndDomain(url, options, &cookies);
+ std::set<CanonicalCookie*> matching_cookies;
+
+ for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin();
+ it != cookies.end(); ++it) {
+ if ((*it)->Name() != cookie_name)
+ continue;
+ if (url.path().find((*it)->Path()))
+ continue;
+ matching_cookies.insert(*it);
+ }
+
+ for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
+ CookieMap::iterator curit = it;
+ ++it;
+ if (matching_cookies.find(curit->second) != matching_cookies.end())
+ InternalDeleteCookie(curit, true);
}
}
diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc
index 8fda8db..bb45b68 100644
--- a/net/base/cookie_monster_unittest.cc
+++ b/net/base/cookie_monster_unittest.cc
@@ -961,4 +961,44 @@ TEST(CookieMonsterTest, SetCookieableSchemes) {
EXPECT_FALSE(cm_foo->SetCookie(http_url, "x=1"));
}
+TEST(CookieMonsterTest, GetRawCookies) {
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster);
+ GURL url_google(kUrlGoogle);
+
+ net::CookieOptions options;
+ options.set_include_httponly();
+
+ // Create a httponly cookie.
+ EXPECT_TRUE(cm->SetCookieWithOptions(url_google, "A=B; httponly", options));
+
+ // Get raw cookies.
+ std::vector<net::CookieMonster::CanonicalCookie> raw_cookies;
+ cm->GetRawCookies(url_google, &raw_cookies);
+ EXPECT_TRUE(raw_cookies.begin() != raw_cookies.end());
+ net::CookieMonster::CanonicalCookie cookie = *raw_cookies.begin();
+ EXPECT_EQ("A", cookie.Name());
+}
+
+TEST(CookieMonsterTest, DeleteCookieByName) {
+ scoped_refptr<net::CookieMonster> cm(new net::CookieMonster);
+ GURL url_google(kUrlGoogle);
+
+ EXPECT_TRUE(cm->SetCookie(url_google, "A=A1; path=/"));
+ EXPECT_TRUE(cm->SetCookie(url_google, "A=A2; path=/foo"));
+ EXPECT_TRUE(cm->SetCookie(url_google, "A=A3; path=/bar"));
+ EXPECT_TRUE(cm->SetCookie(url_google, "B=B1; path=/"));
+ EXPECT_TRUE(cm->SetCookie(url_google, "B=B2; path=/foo"));
+ EXPECT_TRUE(cm->SetCookie(url_google, "B=B3; path=/bar"));
+
+ cm->DeleteCookie(GURL(std::string(kUrlGoogle) + "/foo/bar"), "A");
+
+ net::CookieMonster::CookieList cookies = cm->GetAllCookies();
+ EXPECT_EQ(4, cookies.size());
+ for (net::CookieMonster::CookieList::iterator it = cookies.begin();
+ it != cookies.end(); ++it) {
+ EXPECT_NE("A1", it->second.Value());
+ EXPECT_NE("A2", it->second.Value());
+ }
+}
+
// TODO test overwrite cookie