Chromium Code Reviews| 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..0e7981af1063eecf6314dcc83b9aa3da85340e55 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,25 @@ 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()); |
|
battre
2012/10/29 18:11:04
please test EXPECT_EQ("1", it->Value());
markusheintz_
2012/10/29 18:13:00
Done.
|
| + |
| + 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 +140,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 +184,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 +218,35 @@ 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))); |
| +} |
| + |
| + |
| + |
|
battre
2012/10/29 18:11:04
nit: -2 new lines
markusheintz_
2012/10/29 18:13:00
Done.
|
| TEST_F(BrowsingDataCookieHelperTest, CannedUnique) { |
| const GURL origin("http://www.google.com"); |
| net::CookieList cookie; |