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 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
11 #include "content/public/test/test_browser_thread_bundle.h" | 11 #include "content/public/test/test_browser_thread_bundle.h" |
12 #include "net/cookies/canonical_cookie.h" | 12 #include "net/cookies/canonical_cookie.h" |
13 #include "net/cookies/cookie_options.h" | 13 #include "net/cookies/cookie_options.h" |
14 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Test expectations for a given cookie. | 19 // Test expectations for a given cookie. |
20 class CookieExpectation { | 20 class CookieExpectation { |
21 public: | 21 public: |
22 CookieExpectation() {} | 22 CookieExpectation() {} |
23 | 23 |
24 bool MatchesCookie(const net::CanonicalCookie& cookie) const { | 24 bool MatchesCookie(const net::CanonicalCookie& cookie) const { |
25 if (!source_.is_empty() && source_ != cookie.Source()) | |
26 return false; | |
27 if (!domain_.empty() && domain_ != cookie.Domain()) | 25 if (!domain_.empty() && domain_ != cookie.Domain()) |
28 return false; | 26 return false; |
29 if (!path_.empty() && path_ != cookie.Path()) | 27 if (!path_.empty() && path_ != cookie.Path()) |
30 return false; | 28 return false; |
31 if (!name_.empty() && name_ != cookie.Name()) | 29 if (!name_.empty() && name_ != cookie.Name()) |
32 return false; | 30 return false; |
33 if (!value_.empty() && value_ != cookie.Value()) | 31 if (!value_.empty() && value_ != cookie.Value()) |
34 return false; | 32 return false; |
35 return true; | 33 return true; |
36 } | 34 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 "A", nullptr); | 180 "A", nullptr); |
183 AddCookieExpectation("http://www.google.com/", ".www.google.com", nullptr, | 181 AddCookieExpectation("http://www.google.com/", ".www.google.com", nullptr, |
184 "A", nullptr); | 182 "A", nullptr); |
185 CheckCookieExpectations(); | 183 CheckCookieExpectations(); |
186 } | 184 } |
187 | 185 |
188 void CannedDifferentFramesCallback(const net::CookieList& cookie_list) { | 186 void CannedDifferentFramesCallback(const net::CookieList& cookie_list) { |
189 ASSERT_EQ(3U, cookie_list.size()); | 187 ASSERT_EQ(3U, cookie_list.size()); |
190 } | 188 } |
191 | 189 |
192 void DeleteCookie(BrowsingDataCookieHelper* helper, const GURL origin) { | 190 void DeleteCookie(BrowsingDataCookieHelper* helper, |
| 191 const std::string& domain) { |
193 for (const auto& cookie : cookie_list_) { | 192 for (const auto& cookie : cookie_list_) { |
194 if (cookie.Source() == origin) | 193 if (cookie.Domain() == domain) |
195 helper->DeleteCookie(cookie); | 194 helper->DeleteCookie(cookie); |
196 } | 195 } |
197 } | 196 } |
198 | 197 |
199 protected: | 198 protected: |
200 content::TestBrowserThreadBundle thread_bundle_; | 199 content::TestBrowserThreadBundle thread_bundle_; |
201 std::unique_ptr<TestingProfile> testing_profile_; | 200 std::unique_ptr<TestingProfile> testing_profile_; |
202 | 201 |
203 std::vector<CookieExpectation> cookie_expectations_; | 202 std::vector<CookieExpectation> cookie_expectations_; |
204 net::CookieList cookie_list_; | 203 net::CookieList cookie_list_; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 helper->AddChangedCookie(origin1, origin1, "A=1", net::CookieOptions()); | 257 helper->AddChangedCookie(origin1, origin1, "A=1", net::CookieOptions()); |
259 helper->AddChangedCookie(origin2, origin2, "B=1", net::CookieOptions()); | 258 helper->AddChangedCookie(origin2, origin2, "B=1", net::CookieOptions()); |
260 | 259 |
261 helper->StartFetching( | 260 helper->StartFetching( |
262 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, | 261 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, |
263 base::Unretained(this))); | 262 base::Unretained(this))); |
264 base::RunLoop().RunUntilIdle(); | 263 base::RunLoop().RunUntilIdle(); |
265 | 264 |
266 EXPECT_EQ(2u, helper->GetCookieCount()); | 265 EXPECT_EQ(2u, helper->GetCookieCount()); |
267 | 266 |
268 DeleteCookie(helper.get(), origin1); | 267 DeleteCookie(helper.get(), origin1.host()); |
269 | 268 |
270 EXPECT_EQ(1u, helper->GetCookieCount()); | 269 EXPECT_EQ(1u, helper->GetCookieCount()); |
271 helper->StartFetching( | 270 helper->StartFetching( |
272 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, | 271 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, |
273 base::Unretained(this))); | 272 base::Unretained(this))); |
274 base::RunLoop().RunUntilIdle(); | 273 base::RunLoop().RunUntilIdle(); |
275 } | 274 } |
276 | 275 |
277 TEST_F(BrowsingDataCookieHelperTest, CannedDomainCookie) { | 276 TEST_F(BrowsingDataCookieHelperTest, CannedDomainCookie) { |
278 const GURL origin("http://www.google.com"); | 277 const GURL origin("http://www.google.com"); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // "A=1; | 489 // "A=1; |
491 // "A=3; Domain=www.google.com" | 490 // "A=3; Domain=www.google.com" |
492 // Add a domain cookie and check if it increases the cookie count. | 491 // Add a domain cookie and check if it increases the cookie count. |
493 helper->AddChangedCookie(frame2_url, frame1_url, | 492 helper->AddChangedCookie(frame2_url, frame1_url, |
494 cookie_pair4 + "; Domain=" + cookie_domain, | 493 cookie_pair4 + "; Domain=" + cookie_domain, |
495 net::CookieOptions()); | 494 net::CookieOptions()); |
496 EXPECT_EQ(5U, helper->GetCookieCount()); | 495 EXPECT_EQ(5U, helper->GetCookieCount()); |
497 } | 496 } |
498 | 497 |
499 } // namespace | 498 } // namespace |
OLD | NEW |