diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-04 17:38:20 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-04 17:38:20 +0000 |
commit | bfcaed4a2f6a8ec579f26ea0f072b0dcc909ffda (patch) | |
tree | 9a5d15a664b9e28427a9a6ff1c4edac96714ff3b /net/base | |
parent | 6015b89218a24dba57f0c3f20aff861da0af083e (diff) | |
download | chromium_src-bfcaed4a2f6a8ec579f26ea0f072b0dcc909ffda.zip chromium_src-bfcaed4a2f6a8ec579f26ea0f072b0dcc909ffda.tar.gz chromium_src-bfcaed4a2f6a8ec579f26ea0f072b0dcc909ffda.tar.bz2 |
Add path filtering into the GetAllCookiesForURL.
Review URL: http://codereview.chromium.org/573011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/cookie_monster.cc | 12 | ||||
-rw-r--r-- | net/base/cookie_monster.h | 5 | ||||
-rw-r--r-- | net/base/cookie_monster_unittest.cc | 72 |
3 files changed, 71 insertions, 18 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index 805bfc1..6cda7e5 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -810,7 +810,7 @@ CookieMonster::CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { // Query for the full host, For example: 'a.c.blah.com'. std::string key(url.host()); - FindRawCookies(key, secure, &cookie_list); + FindRawCookies(key, secure, url.path(), &cookie_list); // See if we can search for domain cookies, i.e. if the host has a TLD + 1. const std::string domain(GetEffectiveDomain(url.scheme(), key)); @@ -822,7 +822,7 @@ CookieMonster::CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { DCHECK_EQ(0, key.compare(key.length() - domain.length(), domain.length(), domain)); for (key = "." + key; key.length() > domain.length(); ) { - FindRawCookies(key, secure, &cookie_list); + FindRawCookies(key, secure, url.path(), &cookie_list); const size_t next_dot = key.find('.', 1); // Skip over leading dot. key.erase(0, next_dot); } @@ -902,12 +902,16 @@ void CookieMonster::FindCookiesForKey( void CookieMonster::FindRawCookies(const std::string& key, bool include_secure, + const std::string& path, CookieList* list) { for (CookieMapItPair its = cookies_.equal_range(key); its.first != its.second; ++its.first) { CanonicalCookie* cc = its.first->second; - if (include_secure || !cc->IsSecure()) - list->push_back(CookieListPair(key, *cc)); + if (!include_secure && cc->IsSecure()) + continue; + if (!cc->IsOnPath(path)) + continue; + list->push_back(CookieListPair(key, *cc)); } } diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index 7578c46..f73698d 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -99,8 +99,8 @@ class CookieMonster : public CookieStore { CookieList GetAllCookies(); // Returns all the cookies, for use in management UI, etc. Filters results - // using given url scheme and host / domain. This does not mark the cookies - // as having been accessed. + // using given url scheme, host / domain and path. This does not mark the + // cookies as having been accessed. CookieList GetAllCookiesForURL(const GURL& url); // Delete all of the cookies. @@ -164,6 +164,7 @@ class CookieMonster : public CookieStore { void FindRawCookies(const std::string& key, bool include_secure, + const std::string& path, CookieList* list); // Delete any cookies that are equivalent to |ecc| (same path, key, etc). diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc index cdbf869..735c182 100644 --- a/net/base/cookie_monster_unittest.cc +++ b/net/base/cookie_monster_unittest.cc @@ -980,47 +980,95 @@ TEST(CookieMonsterTest, GetAllCookiesForURL) { EXPECT_TRUE(cm->SetCookieWithOptions(url_google_secure, "E=F; domain=.google.izzle; secure", options)); + const Time last_access_date(GetFirstCookieAccessDate(cm)); PlatformThread::Sleep(kLastAccessThresholdMilliseconds + 20); - // Check raw cookies. - net::CookieMonster::CookieList raw_cookies = + // Check cookies for url. + net::CookieMonster::CookieList cookies = cm->GetAllCookiesForURL(url_google); - net::CookieMonster::CookieList::iterator it = raw_cookies.begin(); + net::CookieMonster::CookieList::iterator it = cookies.begin(); - ASSERT_TRUE(it != raw_cookies.end()); + ASSERT_TRUE(it != cookies.end()); EXPECT_EQ("www.google.izzle", it->first); EXPECT_EQ("A", it->second.Name()); - ASSERT_TRUE(++it != raw_cookies.end()); + ASSERT_TRUE(++it != cookies.end()); EXPECT_EQ(".google.izzle", it->first); EXPECT_EQ("C", it->second.Name()); - ASSERT_TRUE(++it == raw_cookies.end()); + ASSERT_TRUE(++it == cookies.end()); // Test secure cookies. - raw_cookies = cm->GetAllCookiesForURL(url_google_secure); - it = raw_cookies.begin(); + cookies = cm->GetAllCookiesForURL(url_google_secure); + it = cookies.begin(); - ASSERT_TRUE(it != raw_cookies.end()); + ASSERT_TRUE(it != cookies.end()); EXPECT_EQ("www.google.izzle", it->first); EXPECT_EQ("A", it->second.Name()); - ASSERT_TRUE(++it != raw_cookies.end()); + ASSERT_TRUE(++it != cookies.end()); EXPECT_EQ(".google.izzle", it->first); EXPECT_EQ("C", it->second.Name()); - ASSERT_TRUE(++it != raw_cookies.end()); + ASSERT_TRUE(++it != cookies.end()); EXPECT_EQ(".google.izzle", it->first); EXPECT_EQ("E", it->second.Name()); - ASSERT_TRUE(++it == raw_cookies.end()); + ASSERT_TRUE(++it == cookies.end()); // Reading after a short wait should not update the access date. EXPECT_TRUE (last_access_date == GetFirstCookieAccessDate(cm)); } +TEST(CookieMonsterTest, GetAllCookiesForURLPathMatching) { + GURL url_google(kUrlGoogle); + 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()); + net::CookieOptions options; + + EXPECT_TRUE(cm->SetCookieWithOptions(url_google_foo, + "A=B; path=/foo;", + options)); + EXPECT_TRUE(cm->SetCookieWithOptions(url_google_bar, + "C=D; path=/bar;", + options)); + EXPECT_TRUE(cm->SetCookieWithOptions(url_google, + "E=F;", + options)); + + net::CookieMonster::CookieList cookies = + cm->GetAllCookiesForURL(url_google_foo); + net::CookieMonster::CookieList::iterator it = cookies.begin(); + + ASSERT_TRUE(it != cookies.end()); + EXPECT_EQ("A", it->second.Name()); + EXPECT_EQ("/foo", it->second.Path()); + + ASSERT_TRUE(++it != cookies.end()); + EXPECT_EQ("E", it->second.Name()); + EXPECT_EQ("/", it->second.Path()); + + ASSERT_TRUE(++it == cookies.end()); + + cookies = cm->GetAllCookiesForURL(url_google_bar); + it = cookies.begin(); + + ASSERT_TRUE(it != cookies.end()); + EXPECT_EQ("C", it->second.Name()); + EXPECT_EQ("/bar", it->second.Path()); + + ASSERT_TRUE(++it != cookies.end()); + EXPECT_EQ("E", it->second.Name()); + EXPECT_EQ("/", it->second.Path()); + + ASSERT_TRUE(++it == cookies.end()); + +} + TEST(CookieMonsterTest, DeleteCookieByName) { scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); GURL url_google(kUrlGoogle); |