| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
| 6 | 6 |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Correct because fetching cookies will get a sorted cookie list. | 87 // Correct because fetching cookies will get a sorted cookie list. |
| 88 ASSERT_TRUE(it != cookies.end()); | 88 ASSERT_TRUE(it != cookies.end()); |
| 89 EXPECT_EQ("www.google.com", it->Domain()); | 89 EXPECT_EQ("www.google.com", it->Domain()); |
| 90 EXPECT_EQ("A", it->Name()); | 90 EXPECT_EQ("A", it->Name()); |
| 91 | 91 |
| 92 ASSERT_TRUE(++it != cookies.end()); | 92 ASSERT_TRUE(++it != cookies.end()); |
| 93 EXPECT_EQ("www.gmail.google.com", it->Domain()); | 93 EXPECT_EQ("www.gmail.google.com", it->Domain()); |
| 94 EXPECT_EQ("B", it->Name()); | 94 EXPECT_EQ("B", it->Name()); |
| 95 | 95 |
| 96 ASSERT_TRUE(++it == cookies.end()); | 96 ASSERT_TRUE(++it == cookies.end()); |
| 97 MessageLoop::current()->Quit(); | 97 base::MessageLoop::current()->Quit(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void DomainCookieCallback(const net::CookieList& cookies) { | 100 void DomainCookieCallback(const net::CookieList& cookies) { |
| 101 ASSERT_EQ(2UL, cookies.size()); | 101 ASSERT_EQ(2UL, cookies.size()); |
| 102 cookie_list_ = cookies; | 102 cookie_list_ = cookies; |
| 103 net::CookieList::const_iterator it = cookies.begin(); | 103 net::CookieList::const_iterator it = cookies.begin(); |
| 104 | 104 |
| 105 // Correct because fetching cookies will get a sorted cookie list. | 105 // Correct because fetching cookies will get a sorted cookie list. |
| 106 ASSERT_TRUE(it != cookies.end()); | 106 ASSERT_TRUE(it != cookies.end()); |
| 107 EXPECT_EQ("www.google.com", it->Domain()); | 107 EXPECT_EQ("www.google.com", it->Domain()); |
| 108 EXPECT_EQ("A", it->Name()); | 108 EXPECT_EQ("A", it->Name()); |
| 109 EXPECT_EQ("1", it->Value()); | 109 EXPECT_EQ("1", it->Value()); |
| 110 | 110 |
| 111 ASSERT_TRUE(++it != cookies.end()); | 111 ASSERT_TRUE(++it != cookies.end()); |
| 112 EXPECT_EQ(".www.google.com", it->Domain()); | 112 EXPECT_EQ(".www.google.com", it->Domain()); |
| 113 EXPECT_EQ("A", it->Name()); | 113 EXPECT_EQ("A", it->Name()); |
| 114 EXPECT_EQ("2", it->Value()); | 114 EXPECT_EQ("2", it->Value()); |
| 115 | 115 |
| 116 ASSERT_TRUE(++it == cookies.end()); | 116 ASSERT_TRUE(++it == cookies.end()); |
| 117 MessageLoop::current()->Quit(); | 117 base::MessageLoop::current()->Quit(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void DeleteCallback(const net::CookieList& cookies) { | 120 void DeleteCallback(const net::CookieList& cookies) { |
| 121 ASSERT_EQ(1UL, cookies.size()); | 121 ASSERT_EQ(1UL, cookies.size()); |
| 122 net::CookieList::const_iterator it = cookies.begin(); | 122 net::CookieList::const_iterator it = cookies.begin(); |
| 123 | 123 |
| 124 ASSERT_TRUE(it != cookies.end()); | 124 ASSERT_TRUE(it != cookies.end()); |
| 125 EXPECT_EQ("www.gmail.google.com", it->Domain()); | 125 EXPECT_EQ("www.gmail.google.com", it->Domain()); |
| 126 EXPECT_EQ("B", it->Name()); | 126 EXPECT_EQ("B", it->Name()); |
| 127 | 127 |
| 128 ASSERT_TRUE(++it == cookies.end()); | 128 ASSERT_TRUE(++it == cookies.end()); |
| 129 MessageLoop::current()->Quit(); | 129 base::MessageLoop::current()->Quit(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void CannedUniqueCallback(const net::CookieList& cookies) { | 132 void CannedUniqueCallback(const net::CookieList& cookies) { |
| 133 EXPECT_EQ(1UL, cookies.size()); | 133 EXPECT_EQ(1UL, cookies.size()); |
| 134 cookie_list_ = cookies; | 134 cookie_list_ = cookies; |
| 135 net::CookieList::const_iterator it = cookies.begin(); | 135 net::CookieList::const_iterator it = cookies.begin(); |
| 136 | 136 |
| 137 ASSERT_TRUE(it != cookies.end()); | 137 ASSERT_TRUE(it != cookies.end()); |
| 138 EXPECT_EQ("http://www.google.com/", it->Source()); | 138 EXPECT_EQ("http://www.google.com/", it->Source()); |
| 139 EXPECT_EQ("www.google.com", it->Domain()); | 139 EXPECT_EQ("www.google.com", it->Domain()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 EXPECT_EQ(".www.google.com", it->Domain()); | 202 EXPECT_EQ(".www.google.com", it->Domain()); |
| 203 | 203 |
| 204 ASSERT_TRUE(++it == cookies.end()); | 204 ASSERT_TRUE(++it == cookies.end()); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void CannedDifferentFramesCallback(const net::CookieList& cookie_list) { | 207 void CannedDifferentFramesCallback(const net::CookieList& cookie_list) { |
| 208 ASSERT_EQ(3U, cookie_list.size()); | 208 ASSERT_EQ(3U, cookie_list.size()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 protected: | 211 protected: |
| 212 MessageLoop message_loop_; | 212 base::MessageLoop message_loop_; |
| 213 scoped_ptr<content::TestBrowserThread> ui_thread_; | 213 scoped_ptr<content::TestBrowserThread> ui_thread_; |
| 214 scoped_ptr<content::TestBrowserThread> io_thread_; | 214 scoped_ptr<content::TestBrowserThread> io_thread_; |
| 215 scoped_ptr<TestingProfile> testing_profile_; | 215 scoped_ptr<TestingProfile> testing_profile_; |
| 216 | 216 |
| 217 net::CookieList cookie_list_; | 217 net::CookieList cookie_list_; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 TEST_F(BrowsingDataCookieHelperTest, FetchData) { | 220 TEST_F(BrowsingDataCookieHelperTest, FetchData) { |
| 221 CreateCookiesForTest(); | 221 CreateCookiesForTest(); |
| 222 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( | 222 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( |
| 223 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); | 223 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); |
| 224 | 224 |
| 225 cookie_helper->StartFetching( | 225 cookie_helper->StartFetching( |
| 226 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, | 226 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, |
| 227 base::Unretained(this))); | 227 base::Unretained(this))); |
| 228 | 228 |
| 229 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. | 229 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. |
| 230 MessageLoop::current()->Run(); | 230 base::MessageLoop::current()->Run(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 TEST_F(BrowsingDataCookieHelperTest, DomainCookie) { | 233 TEST_F(BrowsingDataCookieHelperTest, DomainCookie) { |
| 234 CreateCookiesForDomainCookieTest(); | 234 CreateCookiesForDomainCookieTest(); |
| 235 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( | 235 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( |
| 236 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); | 236 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); |
| 237 | 237 |
| 238 cookie_helper->StartFetching( | 238 cookie_helper->StartFetching( |
| 239 base::Bind(&BrowsingDataCookieHelperTest::DomainCookieCallback, | 239 base::Bind(&BrowsingDataCookieHelperTest::DomainCookieCallback, |
| 240 base::Unretained(this))); | 240 base::Unretained(this))); |
| 241 | 241 |
| 242 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. | 242 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. |
| 243 MessageLoop::current()->Run(); | 243 base::MessageLoop::current()->Run(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) { | 246 TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) { |
| 247 CreateCookiesForTest(); | 247 CreateCookiesForTest(); |
| 248 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( | 248 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( |
| 249 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); | 249 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); |
| 250 | 250 |
| 251 cookie_helper->StartFetching( | 251 cookie_helper->StartFetching( |
| 252 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, | 252 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, |
| 253 base::Unretained(this))); | 253 base::Unretained(this))); |
| 254 | 254 |
| 255 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. | 255 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. |
| 256 MessageLoop::current()->Run(); | 256 base::MessageLoop::current()->Run(); |
| 257 | 257 |
| 258 net::CanonicalCookie cookie = cookie_list_[0]; | 258 net::CanonicalCookie cookie = cookie_list_[0]; |
| 259 cookie_helper->DeleteCookie(cookie); | 259 cookie_helper->DeleteCookie(cookie); |
| 260 | 260 |
| 261 cookie_helper->StartFetching( | 261 cookie_helper->StartFetching( |
| 262 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, | 262 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, |
| 263 base::Unretained(this))); | 263 base::Unretained(this))); |
| 264 MessageLoop::current()->Run(); | 264 base::MessageLoop::current()->Run(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST_F(BrowsingDataCookieHelperTest, CannedDomainCookie) { | 267 TEST_F(BrowsingDataCookieHelperTest, CannedDomainCookie) { |
| 268 const GURL origin("http://www.google.com"); | 268 const GURL origin("http://www.google.com"); |
| 269 net::CookieList cookie; | 269 net::CookieList cookie; |
| 270 | 270 |
| 271 scoped_refptr<CannedBrowsingDataCookieHelper> helper( | 271 scoped_refptr<CannedBrowsingDataCookieHelper> helper( |
| 272 new CannedBrowsingDataCookieHelper( | 272 new CannedBrowsingDataCookieHelper( |
| 273 testing_profile_->GetRequestContext())); | 273 testing_profile_->GetRequestContext())); |
| 274 | 274 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 // "A=1; | 481 // "A=1; |
| 482 // "A=3; Domain=www.google.com" | 482 // "A=3; Domain=www.google.com" |
| 483 // Add a domain cookie and check if it increases the cookie count. | 483 // Add a domain cookie and check if it increases the cookie count. |
| 484 helper->AddChangedCookie(frame2_url, frame1_url, | 484 helper->AddChangedCookie(frame2_url, frame1_url, |
| 485 cookie_pair4 + "; Domain=" + cookie_domain, | 485 cookie_pair4 + "; Domain=" + cookie_domain, |
| 486 net::CookieOptions()); | 486 net::CookieOptions()); |
| 487 EXPECT_EQ(5U, helper->GetCookieCount()); | 487 EXPECT_EQ(5U, helper->GetCookieCount()); |
| 488 } | 488 } |
| 489 | 489 |
| 490 } // namespace | 490 } // namespace |
| OLD | NEW |