Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2932)

Unified Diff: chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc

Issue 11341011: Make the BrowsingDataCookieHelper create canonical cookies with the correct cookie-domain attribute. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_cookie_helper.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
diff --git a/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
index d5fc256b567362ee9e744a2beb48854b50d00ebd..2b6d63ad9f504a74aac9e6f6f173110e78501f21 100644
--- a/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
@@ -68,6 +68,17 @@ class BrowsingDataCookieHelperTest : public testing::Test {
net::CookieMonster::SetCookiesCallback());
}
+ void CreateCookiesForDomainCookieTest() {
+ scoped_refptr<net::CookieMonster> cookie_monster =
+ testing_profile_->GetCookieMonster();
+ cookie_monster->SetCookieWithOptionsAsync(
+ GURL("http://www.google.com"), "A=1", net::CookieOptions(),
+ net::CookieMonster::SetCookiesCallback());
+ cookie_monster->SetCookieWithOptionsAsync(
+ GURL("http://www.google.com"), "A=2; Domain=.www.google.com ",
+ net::CookieOptions(), net::CookieMonster::SetCookiesCallback());
+ }
+
void FetchCallback(const net::CookieList& cookies) {
ASSERT_EQ(2UL, cookies.size());
cookie_list_ = cookies;
@@ -86,6 +97,26 @@ class BrowsingDataCookieHelperTest : public testing::Test {
MessageLoop::current()->Quit();
}
+ void DomainCookieCallback(const net::CookieList& cookies) {
+ ASSERT_EQ(2UL, cookies.size());
+ cookie_list_ = cookies;
+ net::CookieList::const_iterator it = cookies.begin();
+
+ // Correct because fetching cookies will get a sorted cookie list.
+ ASSERT_TRUE(it != cookies.end());
+ EXPECT_EQ("www.google.com", it->Domain());
+ EXPECT_EQ("A", it->Name());
+ EXPECT_EQ("1", it->Value());
+
+ ASSERT_TRUE(++it != cookies.end());
+ EXPECT_EQ(".www.google.com", it->Domain());
+ EXPECT_EQ("A", it->Name());
+ EXPECT_EQ("2", it->Value());
+
+ ASSERT_TRUE(++it == cookies.end());
+ MessageLoop::current()->Quit();
+ }
+
void DeleteCallback(const net::CookieList& cookies) {
ASSERT_EQ(1UL, cookies.size());
net::CookieList::const_iterator it = cookies.begin();
@@ -110,6 +141,24 @@ class BrowsingDataCookieHelperTest : public testing::Test {
ASSERT_TRUE(++it == cookies.end());
}
+ void CannedDomainCookieCallback(const net::CookieList& cookies) {
+ ASSERT_EQ(2UL, cookies.size());
+ cookie_list_ = cookies;
+ net::CookieList::const_iterator it = cookies.begin();
+
+ ASSERT_TRUE(it != cookies.end());
+ EXPECT_EQ("http://www.google.com/", it->Source());
+ EXPECT_EQ("A", it->Name());
+ EXPECT_EQ("www.google.com", it->Domain());
+
+ ASSERT_TRUE(++it != cookies.end());
+ EXPECT_EQ("http://www.google.com/", it->Source());
+ EXPECT_EQ("A", it->Name());
+ EXPECT_EQ(".www.google.com", it->Domain());
+
+ ASSERT_TRUE(++it == cookies.end());
+ }
+
void CannedDifferentFramesCallback(const net::CookieList& cookie_list) {
ASSERT_EQ(3U, cookie_list.size());
}
@@ -136,6 +185,19 @@ TEST_F(BrowsingDataCookieHelperTest, FetchData) {
MessageLoop::current()->Run();
}
+TEST_F(BrowsingDataCookieHelperTest, DomainCookie) {
+ CreateCookiesForDomainCookieTest();
+ scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
+ new BrowsingDataCookieHelper(testing_profile_->GetRequestContext()));
+
+ cookie_helper->StartFetching(
+ base::Bind(&BrowsingDataCookieHelperTest::DomainCookieCallback,
+ base::Unretained(this)));
+
+ // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
+ MessageLoop::current()->Run();
+}
+
TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
CreateCookiesForTest();
scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
@@ -157,6 +219,33 @@ TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
MessageLoop::current()->Run();
}
+TEST_F(BrowsingDataCookieHelperTest, CannedDomainCookie) {
+ const GURL origin("http://www.google.com");
+ net::CookieList cookie;
+
+ scoped_refptr<CannedBrowsingDataCookieHelper> helper(
+ new CannedBrowsingDataCookieHelper(
+ testing_profile_->GetRequestContext()));
+
+ ASSERT_TRUE(helper->empty());
+ helper->AddChangedCookie(origin, origin, "A=1", net::CookieOptions());
+ helper->AddChangedCookie(origin, origin, "A=1; Domain=.www.google.com",
+ net::CookieOptions());
+
+ helper->StartFetching(
+ base::Bind(&BrowsingDataCookieHelperTest::CannedDomainCookieCallback,
+ base::Unretained(this)));
+ cookie = cookie_list_;
+
+ helper->Reset();
+ ASSERT_TRUE(helper->empty());
+
+ helper->AddReadCookies(origin, origin, cookie);
+ helper->StartFetching(
+ base::Bind(&BrowsingDataCookieHelperTest::CannedDomainCookieCallback,
+ base::Unretained(this)));
+}
+
TEST_F(BrowsingDataCookieHelperTest, CannedUnique) {
const GURL origin("http://www.google.com");
net::CookieList cookie;
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_cookie_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698