| 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 "net/cookies/cookie_monster.h" | 5 #include "net/cookies/cookie_monster.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 115 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
| 116 CookieStoreTest, | 116 CookieStoreTest, |
| 117 CookieMonsterTestTraits); | 117 CookieMonsterTestTraits); |
| 118 | 118 |
| 119 template <typename T> | 119 template <typename T> |
| 120 class CookieMonsterTestBase : public CookieStoreTest<T> { | 120 class CookieMonsterTestBase : public CookieStoreTest<T> { |
| 121 public: | 121 public: |
| 122 using CookieStoreTest<T>::SetCookie; | 122 using CookieStoreTest<T>::SetCookie; |
| 123 | 123 |
| 124 protected: | 124 protected: |
| 125 using CookieStoreTest<T>::http_www_google_; | 125 using CookieStoreTest<T>::http_www_foo_; |
| 126 using CookieStoreTest<T>::https_www_google_; | 126 using CookieStoreTest<T>::https_www_foo_; |
| 127 | 127 |
| 128 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, | 128 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, |
| 129 const GURL& url, | 129 const GURL& url, |
| 130 const CookieOptions& options) { | 130 const CookieOptions& options) { |
| 131 DCHECK(cm); | 131 DCHECK(cm); |
| 132 GetCookieListCallback callback; | 132 GetCookieListCallback callback; |
| 133 cm->GetCookieListWithOptionsAsync( | 133 cm->GetCookieListWithOptionsAsync( |
| 134 url, options, | 134 url, options, |
| 135 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback))); | 135 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback))); |
| 136 callback.WaitUntilDone(); | 136 callback.WaitUntilDone(); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 void TestHostGarbageCollectHelper() { | 290 void TestHostGarbageCollectHelper() { |
| 291 int domain_max_cookies = CookieMonster::kDomainMaxCookies; | 291 int domain_max_cookies = CookieMonster::kDomainMaxCookies; |
| 292 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies; | 292 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies; |
| 293 const int more_than_enough_cookies = | 293 const int more_than_enough_cookies = |
| 294 (domain_max_cookies + domain_purge_cookies) * 2; | 294 (domain_max_cookies + domain_purge_cookies) * 2; |
| 295 // Add a bunch of cookies on a single host, should purge them. | 295 // Add a bunch of cookies on a single host, should purge them. |
| 296 { | 296 { |
| 297 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 297 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 298 for (int i = 0; i < more_than_enough_cookies; ++i) { | 298 for (int i = 0; i < more_than_enough_cookies; ++i) { |
| 299 std::string cookie = base::StringPrintf("a%03d=b", i); | 299 std::string cookie = base::StringPrintf("a%03d=b", i); |
| 300 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), cookie)); | 300 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), cookie)); |
| 301 std::string cookies = | 301 std::string cookies = this->GetCookies(cm.get(), http_www_foo_.url()); |
| 302 this->GetCookies(cm.get(), http_www_google_.url()); | |
| 303 // Make sure we find it in the cookies. | 302 // Make sure we find it in the cookies. |
| 304 EXPECT_NE(cookies.find(cookie), std::string::npos); | 303 EXPECT_NE(cookies.find(cookie), std::string::npos); |
| 305 // Count the number of cookies. | 304 // Count the number of cookies. |
| 306 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); | 305 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); |
| 307 } | 306 } |
| 308 } | 307 } |
| 309 | 308 |
| 310 // Add a bunch of cookies on multiple hosts within a single eTLD. | 309 // Add a bunch of cookies on multiple hosts within a single eTLD. |
| 311 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies | 310 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies |
| 312 // between them. We shouldn't go above kDomainMaxCookies for both together. | 311 // between them. We shouldn't go above kDomainMaxCookies for both together. |
| 313 GURL url_google_specific(http_www_google_.Format("http://www.gmail.%D")); | 312 GURL url_google_specific(http_www_foo_.Format("http://www.gmail.%D")); |
| 314 { | 313 { |
| 315 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 314 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 316 for (int i = 0; i < more_than_enough_cookies; ++i) { | 315 for (int i = 0; i < more_than_enough_cookies; ++i) { |
| 317 std::string cookie_general = base::StringPrintf("a%03d=b", i); | 316 std::string cookie_general = base::StringPrintf("a%03d=b", i); |
| 318 EXPECT_TRUE( | 317 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), cookie_general)); |
| 319 SetCookie(cm.get(), http_www_google_.url(), cookie_general)); | |
| 320 std::string cookie_specific = base::StringPrintf("c%03d=b", i); | 318 std::string cookie_specific = base::StringPrintf("c%03d=b", i); |
| 321 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific)); | 319 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific)); |
| 322 std::string cookies_general = | 320 std::string cookies_general = |
| 323 this->GetCookies(cm.get(), http_www_google_.url()); | 321 this->GetCookies(cm.get(), http_www_foo_.url()); |
| 324 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); | 322 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); |
| 325 std::string cookies_specific = | 323 std::string cookies_specific = |
| 326 this->GetCookies(cm.get(), url_google_specific); | 324 this->GetCookies(cm.get(), url_google_specific); |
| 327 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos); | 325 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos); |
| 328 EXPECT_LE((CountInString(cookies_general, '=') + | 326 EXPECT_LE((CountInString(cookies_general, '=') + |
| 329 CountInString(cookies_specific, '=')), | 327 CountInString(cookies_specific, '=')), |
| 330 domain_max_cookies); | 328 domain_max_cookies); |
| 331 } | 329 } |
| 332 // After all this, there should be at least | 330 // After all this, there should be at least |
| 333 // kDomainMaxCookies - kDomainPurgeCookies for both URLs. | 331 // kDomainMaxCookies - kDomainPurgeCookies for both URLs. |
| 334 std::string cookies_general = | 332 std::string cookies_general = |
| 335 this->GetCookies(cm.get(), http_www_google_.url()); | 333 this->GetCookies(cm.get(), http_www_foo_.url()); |
| 336 std::string cookies_specific = | 334 std::string cookies_specific = |
| 337 this->GetCookies(cm.get(), url_google_specific); | 335 this->GetCookies(cm.get(), url_google_specific); |
| 338 int total_cookies = (CountInString(cookies_general, '=') + | 336 int total_cookies = (CountInString(cookies_general, '=') + |
| 339 CountInString(cookies_specific, '=')); | 337 CountInString(cookies_specific, '=')); |
| 340 EXPECT_GE(total_cookies, domain_max_cookies - domain_purge_cookies); | 338 EXPECT_GE(total_cookies, domain_max_cookies - domain_purge_cookies); |
| 341 EXPECT_LE(total_cookies, domain_max_cookies); | 339 EXPECT_LE(total_cookies, domain_max_cookies); |
| 342 } | 340 } |
| 343 } | 341 } |
| 344 | 342 |
| 345 CookiePriority CharToPriority(char ch) { | 343 CookiePriority CharToPriority(char ch) { |
| 346 switch (ch) { | 344 switch (ch) { |
| 347 case 'L': | 345 case 'L': |
| 348 return COOKIE_PRIORITY_LOW; | 346 return COOKIE_PRIORITY_LOW; |
| 349 case 'M': | 347 case 'M': |
| 350 return COOKIE_PRIORITY_MEDIUM; | 348 return COOKIE_PRIORITY_MEDIUM; |
| 351 case 'H': | 349 case 'H': |
| 352 return COOKIE_PRIORITY_HIGH; | 350 return COOKIE_PRIORITY_HIGH; |
| 353 } | 351 } |
| 354 NOTREACHED(); | 352 NOTREACHED(); |
| 355 return COOKIE_PRIORITY_DEFAULT; | 353 return COOKIE_PRIORITY_DEFAULT; |
| 356 } | 354 } |
| 357 | 355 |
| 358 // Instantiates a CookieMonster, adds multiple cookies (to http_www_google_) | 356 // Instantiates a CookieMonster, adds multiple cookies (to http_www_foo_) |
| 359 // with priorities specified by |coded_priority_str|, and tests priority-aware | 357 // with priorities specified by |coded_priority_str|, and tests priority-aware |
| 360 // domain cookie eviction. | 358 // domain cookie eviction. |
| 361 // | 359 // |
| 362 // Example: |coded_priority_string| of "2MN 3LS MN 4HN" specifies sequential | 360 // Example: |coded_priority_string| of "2MN 3LS MN 4HN" specifies sequential |
| 363 // (i.e., from least- to most-recently accessed) insertion of 2 | 361 // (i.e., from least- to most-recently accessed) insertion of 2 |
| 364 // medium-priority non-secure cookies, 3 low-priority secure cookies, 1 | 362 // medium-priority non-secure cookies, 3 low-priority secure cookies, 1 |
| 365 // medium-priority non-secure cookie, and 4 high-priority non-secure cookies. | 363 // medium-priority non-secure cookie, and 4 high-priority non-secure cookies. |
| 366 // | 364 // |
| 367 // Within each priority, only the least-accessed cookies should be evicted. | 365 // Within each priority, only the least-accessed cookies should be evicted. |
| 368 // Thus, to describe expected suriving cookies, it suffices to specify the | 366 // Thus, to describe expected suriving cookies, it suffices to specify the |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 if (!token.empty()) { | 398 if (!token.empty()) { |
| 401 bool result = base::StringToInt( | 399 bool result = base::StringToInt( |
| 402 base::StringPiece(token.begin(), token.end() - 2), &rep); | 400 base::StringPiece(token.begin(), token.end() - 2), &rep); |
| 403 DCHECK(result); | 401 DCHECK(result); |
| 404 } | 402 } |
| 405 for (; rep > 0; --rep, ++next_cookie_id) { | 403 for (; rep > 0; --rep, ++next_cookie_id) { |
| 406 std::string cookie = | 404 std::string cookie = |
| 407 base::StringPrintf("a%d=b;priority=%s;%s", next_cookie_id, | 405 base::StringPrintf("a%d=b;priority=%s;%s", next_cookie_id, |
| 408 CookiePriorityToString(priority).c_str(), | 406 CookiePriorityToString(priority).c_str(), |
| 409 is_secure ? "secure" : ""); | 407 is_secure ? "secure" : ""); |
| 410 EXPECT_TRUE(SetCookie(cm, https_www_google_.url(), cookie)); | 408 EXPECT_TRUE(SetCookie(cm, https_www_foo_.url(), cookie)); |
| 411 cookie_data.push_back(std::make_pair(is_secure, priority)); | 409 cookie_data.push_back(std::make_pair(is_secure, priority)); |
| 412 id_list[is_secure][priority].push_back(next_cookie_id); | 410 id_list[is_secure][priority].push_back(next_cookie_id); |
| 413 } | 411 } |
| 414 } | 412 } |
| 415 | 413 |
| 416 int num_cookies = static_cast<int>(cookie_data.size()); | 414 int num_cookies = static_cast<int>(cookie_data.size()); |
| 417 // A list of cookie IDs, indexed by secure status, then by priority. | 415 // A list of cookie IDs, indexed by secure status, then by priority. |
| 418 std::vector<int> surviving_id_list[2][3]; | 416 std::vector<int> surviving_id_list[2][3]; |
| 419 | 417 |
| 420 // Parse the list of cookies | 418 // Parse the list of cookies |
| 421 std::string cookie_str = this->GetCookies(cm, https_www_google_.url()); | 419 std::string cookie_str = this->GetCookies(cm, https_www_foo_.url()); |
| 422 size_t num_nonsecure = 0; | 420 size_t num_nonsecure = 0; |
| 423 size_t num_secure = 0; | 421 size_t num_secure = 0; |
| 424 for (const std::string& token : base::SplitString( | 422 for (const std::string& token : base::SplitString( |
| 425 cookie_str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 423 cookie_str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 426 // Assuming *it is "a#=b", so extract and parse "#" portion. | 424 // Assuming *it is "a#=b", so extract and parse "#" portion. |
| 427 int id = -1; | 425 int id = -1; |
| 428 bool result = base::StringToInt( | 426 bool result = base::StringToInt( |
| 429 base::StringPiece(token.begin() + 1, token.end() - 2), &id); | 427 base::StringPiece(token.begin() + 1, token.end() - 2), &id); |
| 430 DCHECK(result); | 428 DCHECK(result); |
| 431 DCHECK_GE(id, 0); | 429 DCHECK_GE(id, 0); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 } | 500 } |
| 503 | 501 |
| 504 int next_cookie_id = 0; | 502 int next_cookie_id = 0; |
| 505 for (size_t i = 0; i < num_cookie_entries; i++) { | 503 for (size_t i = 0; i < num_cookie_entries; i++) { |
| 506 for (size_t j = 0; j < cookie_entries[i].num_cookies; j++) { | 504 for (size_t j = 0; j < cookie_entries[i].num_cookies; j++) { |
| 507 std::string cookie; | 505 std::string cookie; |
| 508 if (cookie_entries[i].is_secure) | 506 if (cookie_entries[i].is_secure) |
| 509 cookie = base::StringPrintf("a%d=b; Secure", next_cookie_id); | 507 cookie = base::StringPrintf("a%d=b; Secure", next_cookie_id); |
| 510 else | 508 else |
| 511 cookie = base::StringPrintf("a%d=b", next_cookie_id); | 509 cookie = base::StringPrintf("a%d=b", next_cookie_id); |
| 512 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), cookie)); | 510 EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), cookie)); |
| 513 ++next_cookie_id; | 511 ++next_cookie_id; |
| 514 } | 512 } |
| 515 } | 513 } |
| 516 | 514 |
| 517 CookieList cookies = this->GetAllCookies(cm.get()); | 515 CookieList cookies = this->GetAllCookies(cm.get()); |
| 518 EXPECT_EQ(expected_secure_cookies + expected_non_secure_cookies, | 516 EXPECT_EQ(expected_secure_cookies + expected_non_secure_cookies, |
| 519 cookies.size()); | 517 cookies.size()); |
| 520 size_t total_secure_cookies = 0; | 518 size_t total_secure_cookies = 0; |
| 521 size_t total_non_secure_cookies = 0; | 519 size_t total_non_secure_cookies = 0; |
| 522 for (const auto& cookie : cookies) { | 520 for (const auto& cookie : cookies) { |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 base::RunLoop load_run_loop_; | 986 base::RunLoop load_run_loop_; |
| 989 // Indicates whether ExpectLoadCall() has been called. | 987 // Indicates whether ExpectLoadCall() has been called. |
| 990 bool expect_load_called_; | 988 bool expect_load_called_; |
| 991 // Stores the CookieMonster under test. | 989 // Stores the CookieMonster under test. |
| 992 std::unique_ptr<CookieMonster> cookie_monster_; | 990 std::unique_ptr<CookieMonster> cookie_monster_; |
| 993 // Stores the mock PersistentCookieStore. | 991 // Stores the mock PersistentCookieStore. |
| 994 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; | 992 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; |
| 995 }; | 993 }; |
| 996 | 994 |
| 997 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { | 995 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { |
| 998 DeclareLoadedCookie(http_www_google_.url(), | 996 DeclareLoadedCookie(http_www_foo_.url(), |
| 999 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 997 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1000 Time::Now() + TimeDelta::FromDays(3)); | 998 Time::Now() + TimeDelta::FromDays(3)); |
| 1001 | 999 |
| 1002 MockGetCookiesCallback get_cookies_callback; | 1000 MockGetCookiesCallback get_cookies_callback; |
| 1003 | 1001 |
| 1004 BeginWithForDomainKey( | 1002 BeginWithForDomainKey(http_www_foo_.domain(), |
| 1005 http_www_google_.domain(), | 1003 GetCookiesAction(&cookie_monster(), http_www_foo_.url(), |
| 1006 GetCookiesAction(&cookie_monster(), http_www_google_.url(), | 1004 &get_cookies_callback)); |
| 1007 &get_cookies_callback)); | |
| 1008 | 1005 |
| 1009 WaitForLoadCall(); | 1006 WaitForLoadCall(); |
| 1010 | 1007 |
| 1011 EXPECT_CALL(get_cookies_callback, Run("X=1")) | 1008 EXPECT_CALL(get_cookies_callback, Run("X=1")) |
| 1012 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(), | 1009 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_foo_.url(), |
| 1013 &get_cookies_callback)); | 1010 &get_cookies_callback)); |
| 1014 base::RunLoop loop; | 1011 base::RunLoop loop; |
| 1015 EXPECT_CALL(get_cookies_callback, Run("X=1")).WillOnce(QuitRunLoop(&loop)); | 1012 EXPECT_CALL(get_cookies_callback, Run("X=1")).WillOnce(QuitRunLoop(&loop)); |
| 1016 | 1013 |
| 1017 CompleteLoading(); | 1014 CompleteLoading(); |
| 1018 loop.Run(); | 1015 loop.Run(); |
| 1019 } | 1016 } |
| 1020 | 1017 |
| 1021 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { | 1018 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { |
| 1022 MockSetCookiesCallback set_cookies_callback; | 1019 MockSetCookiesCallback set_cookies_callback; |
| 1023 | 1020 |
| 1024 BeginWithForDomainKey( | 1021 BeginWithForDomainKey(http_www_foo_.domain(), |
| 1025 http_www_google_.domain(), | 1022 SetCookieAction(&cookie_monster(), http_www_foo_.url(), |
| 1026 SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B", | 1023 "A=B", &set_cookies_callback)); |
| 1027 &set_cookies_callback)); | |
| 1028 | 1024 |
| 1029 WaitForLoadCall(); | 1025 WaitForLoadCall(); |
| 1030 | 1026 |
| 1031 EXPECT_CALL(set_cookies_callback, Run(true)) | 1027 EXPECT_CALL(set_cookies_callback, Run(true)) |
| 1032 .WillOnce(SetCookieAction(&cookie_monster(), http_www_google_.url(), | 1028 .WillOnce(SetCookieAction(&cookie_monster(), http_www_foo_.url(), "X=Y", |
| 1033 "X=Y", &set_cookies_callback)); | 1029 &set_cookies_callback)); |
| 1034 base::RunLoop loop; | 1030 base::RunLoop loop; |
| 1035 EXPECT_CALL(set_cookies_callback, Run(true)).WillOnce(QuitRunLoop(&loop)); | 1031 EXPECT_CALL(set_cookies_callback, Run(true)).WillOnce(QuitRunLoop(&loop)); |
| 1036 | 1032 |
| 1037 CompleteLoading(); | 1033 CompleteLoading(); |
| 1038 loop.Run(); | 1034 loop.Run(); |
| 1039 } | 1035 } |
| 1040 | 1036 |
| 1041 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { | 1037 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { |
| 1042 MockSetCookiesCallback set_cookies_callback; | 1038 MockSetCookiesCallback set_cookies_callback; |
| 1043 CookieList list; | 1039 CookieList list; |
| 1044 list.push_back(CanonicalCookie("A", "B", "." + http_www_google_.domain(), "/", | 1040 list.push_back(CanonicalCookie("A", "B", "." + http_www_foo_.domain(), "/", |
| 1045 base::Time::Now(), base::Time(), base::Time(), | 1041 base::Time::Now(), base::Time(), base::Time(), |
| 1046 false, true, CookieSameSite::DEFAULT_MODE, | 1042 false, true, CookieSameSite::DEFAULT_MODE, |
| 1047 COOKIE_PRIORITY_DEFAULT)); | 1043 COOKIE_PRIORITY_DEFAULT)); |
| 1048 list.push_back(CanonicalCookie("C", "D", "." + http_www_google_.domain(), "/", | 1044 list.push_back(CanonicalCookie("C", "D", "." + http_www_foo_.domain(), "/", |
| 1049 base::Time::Now(), base::Time(), base::Time(), | 1045 base::Time::Now(), base::Time(), base::Time(), |
| 1050 false, true, CookieSameSite::DEFAULT_MODE, | 1046 false, true, CookieSameSite::DEFAULT_MODE, |
| 1051 COOKIE_PRIORITY_DEFAULT)); | 1047 COOKIE_PRIORITY_DEFAULT)); |
| 1052 | 1048 |
| 1053 BeginWith( | 1049 BeginWith( |
| 1054 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 1050 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
| 1055 | 1051 |
| 1056 WaitForLoadCall(); | 1052 WaitForLoadCall(); |
| 1057 | 1053 |
| 1058 EXPECT_CALL(set_cookies_callback, Run(true)) | 1054 EXPECT_CALL(set_cookies_callback, Run(true)) |
| 1059 .WillOnce( | 1055 .WillOnce( |
| 1060 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 1056 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
| 1061 base::RunLoop loop; | 1057 base::RunLoop loop; |
| 1062 EXPECT_CALL(set_cookies_callback, Run(true)).WillOnce(QuitRunLoop(&loop)); | 1058 EXPECT_CALL(set_cookies_callback, Run(true)).WillOnce(QuitRunLoop(&loop)); |
| 1063 | 1059 |
| 1064 CompleteLoading(); | 1060 CompleteLoading(); |
| 1065 loop.Run(); | 1061 loop.Run(); |
| 1066 } | 1062 } |
| 1067 | 1063 |
| 1068 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { | 1064 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { |
| 1069 MockClosure delete_cookie_callback; | 1065 MockClosure delete_cookie_callback; |
| 1070 | 1066 |
| 1071 BeginWithForDomainKey( | 1067 BeginWithForDomainKey( |
| 1072 http_www_google_.domain(), | 1068 http_www_foo_.domain(), |
| 1073 DeleteCookieAction(&cookie_monster(), http_www_google_.url(), "A", | 1069 DeleteCookieAction(&cookie_monster(), http_www_foo_.url(), "A", |
| 1074 &delete_cookie_callback)); | 1070 &delete_cookie_callback)); |
| 1075 | 1071 |
| 1076 WaitForLoadCall(); | 1072 WaitForLoadCall(); |
| 1077 | 1073 |
| 1078 EXPECT_CALL(delete_cookie_callback, Run()) | 1074 EXPECT_CALL(delete_cookie_callback, Run()) |
| 1079 .WillOnce(DeleteCookieAction(&cookie_monster(), http_www_google_.url(), | 1075 .WillOnce(DeleteCookieAction(&cookie_monster(), http_www_foo_.url(), "X", |
| 1080 "X", &delete_cookie_callback)); | 1076 &delete_cookie_callback)); |
| 1081 base::RunLoop loop; | 1077 base::RunLoop loop; |
| 1082 EXPECT_CALL(delete_cookie_callback, Run()).WillOnce(QuitRunLoop(&loop)); | 1078 EXPECT_CALL(delete_cookie_callback, Run()).WillOnce(QuitRunLoop(&loop)); |
| 1083 | 1079 |
| 1084 CompleteLoading(); | 1080 CompleteLoading(); |
| 1085 loop.Run(); | 1081 loop.Run(); |
| 1086 } | 1082 } |
| 1087 | 1083 |
| 1088 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { | 1084 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { |
| 1089 MockSetCookiesCallback set_cookies_callback; | 1085 MockSetCookiesCallback set_cookies_callback; |
| 1090 | 1086 |
| 1091 CookiesInputInfo cookie_info = {www_google_foo_.url(), | 1087 CookiesInputInfo cookie_info = {www_foo_foo_.url(), |
| 1092 "A", | 1088 "A", |
| 1093 "B", | 1089 "B", |
| 1094 std::string(), | 1090 std::string(), |
| 1095 "/foo", | 1091 "/foo", |
| 1096 base::Time(), | 1092 base::Time(), |
| 1097 false, | 1093 false, |
| 1098 false, | 1094 false, |
| 1099 CookieSameSite::DEFAULT_MODE, | 1095 CookieSameSite::DEFAULT_MODE, |
| 1100 COOKIE_PRIORITY_DEFAULT}; | 1096 COOKIE_PRIORITY_DEFAULT}; |
| 1101 BeginWithForDomainKey( | 1097 BeginWithForDomainKey( |
| 1102 http_www_google_.domain(), | 1098 http_www_foo_.domain(), |
| 1103 SetCookieWithDetailsAction(&cookie_monster(), cookie_info, | 1099 SetCookieWithDetailsAction(&cookie_monster(), cookie_info, |
| 1104 &set_cookies_callback)); | 1100 &set_cookies_callback)); |
| 1105 | 1101 |
| 1106 WaitForLoadCall(); | 1102 WaitForLoadCall(); |
| 1107 | 1103 |
| 1108 CookiesInputInfo cookie_info_exp = {www_google_foo_.url(), | 1104 CookiesInputInfo cookie_info_exp = {www_foo_foo_.url(), |
| 1109 "A", | 1105 "A", |
| 1110 "B", | 1106 "B", |
| 1111 std::string(), | 1107 std::string(), |
| 1112 "/foo", | 1108 "/foo", |
| 1113 base::Time(), | 1109 base::Time(), |
| 1114 false, | 1110 false, |
| 1115 false, | 1111 false, |
| 1116 CookieSameSite::DEFAULT_MODE, | 1112 CookieSameSite::DEFAULT_MODE, |
| 1117 COOKIE_PRIORITY_DEFAULT}; | 1113 COOKIE_PRIORITY_DEFAULT}; |
| 1118 EXPECT_CALL(set_cookies_callback, Run(true)) | 1114 EXPECT_CALL(set_cookies_callback, Run(true)) |
| 1119 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, | 1115 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, |
| 1120 &set_cookies_callback)); | 1116 &set_cookies_callback)); |
| 1121 base::RunLoop loop; | 1117 base::RunLoop loop; |
| 1122 EXPECT_CALL(set_cookies_callback, Run(true)).WillOnce(QuitRunLoop(&loop)); | 1118 EXPECT_CALL(set_cookies_callback, Run(true)).WillOnce(QuitRunLoop(&loop)); |
| 1123 | 1119 |
| 1124 CompleteLoading(); | 1120 CompleteLoading(); |
| 1125 loop.Run(); | 1121 loop.Run(); |
| 1126 } | 1122 } |
| 1127 | 1123 |
| 1128 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { | 1124 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { |
| 1129 DeclareLoadedCookie(http_www_google_.url(), | 1125 DeclareLoadedCookie(http_www_foo_.url(), |
| 1130 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1126 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1131 Time::Now() + TimeDelta::FromDays(3)); | 1127 Time::Now() + TimeDelta::FromDays(3)); |
| 1132 | 1128 |
| 1133 MockGetCookieListCallback get_cookie_list_callback; | 1129 MockGetCookieListCallback get_cookie_list_callback; |
| 1134 | 1130 |
| 1135 BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); | 1131 BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); |
| 1136 | 1132 |
| 1137 WaitForLoadCall(); | 1133 WaitForLoadCall(); |
| 1138 | 1134 |
| 1139 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) | 1135 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) |
| 1140 .WillOnce( | 1136 .WillOnce( |
| 1141 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); | 1137 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); |
| 1142 base::RunLoop loop; | 1138 base::RunLoop loop; |
| 1143 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) | 1139 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) |
| 1144 .WillOnce(QuitRunLoop(&loop)); | 1140 .WillOnce(QuitRunLoop(&loop)); |
| 1145 | 1141 |
| 1146 CompleteLoading(); | 1142 CompleteLoading(); |
| 1147 loop.Run(); | 1143 loop.Run(); |
| 1148 } | 1144 } |
| 1149 | 1145 |
| 1150 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { | 1146 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { |
| 1151 DeclareLoadedCookie(http_www_google_.url(), | 1147 DeclareLoadedCookie(http_www_foo_.url(), |
| 1152 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1148 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1153 Time::Now() + TimeDelta::FromDays(3)); | 1149 Time::Now() + TimeDelta::FromDays(3)); |
| 1154 | 1150 |
| 1155 MockGetCookieListCallback get_cookie_list_callback; | 1151 MockGetCookieListCallback get_cookie_list_callback; |
| 1156 | 1152 |
| 1157 BeginWithForDomainKey( | 1153 BeginWithForDomainKey( |
| 1158 http_www_google_.domain(), | 1154 http_www_foo_.domain(), |
| 1159 GetAllCookiesForUrlAction(&cookie_monster(), http_www_google_.url(), | 1155 GetAllCookiesForUrlAction(&cookie_monster(), http_www_foo_.url(), |
| 1160 &get_cookie_list_callback)); | 1156 &get_cookie_list_callback)); |
| 1161 | 1157 |
| 1162 WaitForLoadCall(); | 1158 WaitForLoadCall(); |
| 1163 | 1159 |
| 1164 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) | 1160 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) |
| 1165 .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(), | 1161 .WillOnce(GetAllCookiesForUrlAction( |
| 1166 http_www_google_.url(), | 1162 &cookie_monster(), http_www_foo_.url(), &get_cookie_list_callback)); |
| 1167 &get_cookie_list_callback)); | |
| 1168 base::RunLoop loop; | 1163 base::RunLoop loop; |
| 1169 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) | 1164 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) |
| 1170 .WillOnce(QuitRunLoop(&loop)); | 1165 .WillOnce(QuitRunLoop(&loop)); |
| 1171 | 1166 |
| 1172 CompleteLoading(); | 1167 CompleteLoading(); |
| 1173 loop.Run(); | 1168 loop.Run(); |
| 1174 } | 1169 } |
| 1175 | 1170 |
| 1176 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { | 1171 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { |
| 1177 DeclareLoadedCookie(http_www_google_.url(), | 1172 DeclareLoadedCookie(http_www_foo_.url(), |
| 1178 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1173 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1179 Time::Now() + TimeDelta::FromDays(3)); | 1174 Time::Now() + TimeDelta::FromDays(3)); |
| 1180 | 1175 |
| 1181 MockGetCookieListCallback get_cookie_list_callback; | 1176 MockGetCookieListCallback get_cookie_list_callback; |
| 1182 | 1177 |
| 1183 BeginWithForDomainKey(http_www_google_.domain(), | 1178 BeginWithForDomainKey( |
| 1184 GetCookieListForUrlWithOptionsAction( | 1179 http_www_foo_.domain(), |
| 1185 &cookie_monster(), http_www_google_.url(), | 1180 GetCookieListForUrlWithOptionsAction( |
| 1186 &get_cookie_list_callback)); | 1181 &cookie_monster(), http_www_foo_.url(), &get_cookie_list_callback)); |
| 1187 | 1182 |
| 1188 WaitForLoadCall(); | 1183 WaitForLoadCall(); |
| 1189 | 1184 |
| 1190 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) | 1185 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) |
| 1191 .WillOnce(GetCookieListForUrlWithOptionsAction( | 1186 .WillOnce(GetCookieListForUrlWithOptionsAction( |
| 1192 &cookie_monster(), http_www_google_.url(), | 1187 &cookie_monster(), http_www_foo_.url(), &get_cookie_list_callback)); |
| 1193 &get_cookie_list_callback)); | |
| 1194 base::RunLoop loop; | 1188 base::RunLoop loop; |
| 1195 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) | 1189 EXPECT_CALL(get_cookie_list_callback, Run(testing::_)) |
| 1196 .WillOnce(QuitRunLoop(&loop)); | 1190 .WillOnce(QuitRunLoop(&loop)); |
| 1197 | 1191 |
| 1198 CompleteLoading(); | 1192 CompleteLoading(); |
| 1199 loop.Run(); | 1193 loop.Run(); |
| 1200 } | 1194 } |
| 1201 | 1195 |
| 1202 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { | 1196 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { |
| 1203 MockDeleteCallback delete_callback; | 1197 MockDeleteCallback delete_callback; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 base::RunLoop loop; | 1248 base::RunLoop loop; |
| 1255 EXPECT_CALL(delete_callback, Run(false)).WillOnce(QuitRunLoop(&loop)); | 1249 EXPECT_CALL(delete_callback, Run(false)).WillOnce(QuitRunLoop(&loop)); |
| 1256 | 1250 |
| 1257 CompleteLoading(); | 1251 CompleteLoading(); |
| 1258 loop.Run(); | 1252 loop.Run(); |
| 1259 } | 1253 } |
| 1260 | 1254 |
| 1261 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { | 1255 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { |
| 1262 std::vector<std::unique_ptr<CanonicalCookie>> cookies; | 1256 std::vector<std::unique_ptr<CanonicalCookie>> cookies; |
| 1263 std::unique_ptr<CanonicalCookie> cookie = BuildCanonicalCookie( | 1257 std::unique_ptr<CanonicalCookie> cookie = BuildCanonicalCookie( |
| 1264 http_www_google_.url(), "X=1; path=/", base::Time::Now()); | 1258 http_www_foo_.url(), "X=1; path=/", base::Time::Now()); |
| 1265 | 1259 |
| 1266 MockDeleteCallback delete_cookie_callback; | 1260 MockDeleteCallback delete_cookie_callback; |
| 1267 | 1261 |
| 1268 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), *cookie, | 1262 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), *cookie, |
| 1269 &delete_cookie_callback)); | 1263 &delete_cookie_callback)); |
| 1270 | 1264 |
| 1271 WaitForLoadCall(); | 1265 WaitForLoadCall(); |
| 1272 | 1266 |
| 1273 EXPECT_CALL(delete_cookie_callback, Run(0)) | 1267 EXPECT_CALL(delete_cookie_callback, Run(0)) |
| 1274 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), *cookie, | 1268 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), *cookie, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1294 EXPECT_CALL(delete_callback, Run(false)).WillOnce(QuitRunLoop(&loop)); | 1288 EXPECT_CALL(delete_callback, Run(false)).WillOnce(QuitRunLoop(&loop)); |
| 1295 | 1289 |
| 1296 CompleteLoading(); | 1290 CompleteLoading(); |
| 1297 loop.Run(); | 1291 loop.Run(); |
| 1298 } | 1292 } |
| 1299 | 1293 |
| 1300 // Verify that a series of queued tasks are executed in order upon loading of | 1294 // Verify that a series of queued tasks are executed in order upon loading of |
| 1301 // the backing store and that new tasks received while the queued tasks are | 1295 // the backing store and that new tasks received while the queued tasks are |
| 1302 // being dispatched go to the end of the queue. | 1296 // being dispatched go to the end of the queue. |
| 1303 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { | 1297 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { |
| 1304 DeclareLoadedCookie(http_www_google_.url(), | 1298 DeclareLoadedCookie(http_www_foo_.url(), |
| 1305 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1299 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1306 Time::Now() + TimeDelta::FromDays(3)); | 1300 Time::Now() + TimeDelta::FromDays(3)); |
| 1307 | 1301 |
| 1308 MockGetCookiesCallback get_cookies_callback; | 1302 MockGetCookiesCallback get_cookies_callback; |
| 1309 MockSetCookiesCallback set_cookies_callback; | 1303 MockSetCookiesCallback set_cookies_callback; |
| 1310 MockGetCookiesCallback get_cookies_callback_deferred; | 1304 MockGetCookiesCallback get_cookies_callback_deferred; |
| 1311 | 1305 |
| 1312 EXPECT_CALL(*this, Begin()) | 1306 EXPECT_CALL(*this, Begin()) |
| 1313 .WillOnce(testing::DoAll( | 1307 .WillOnce(testing::DoAll( |
| 1314 GetCookiesAction(&cookie_monster(), http_www_google_.url(), | 1308 GetCookiesAction(&cookie_monster(), http_www_foo_.url(), |
| 1315 &get_cookies_callback), | 1309 &get_cookies_callback), |
| 1316 SetCookieAction(&cookie_monster(), http_www_google_.url(), "A=B", | 1310 SetCookieAction(&cookie_monster(), http_www_foo_.url(), "A=B", |
| 1317 &set_cookies_callback))); | 1311 &set_cookies_callback))); |
| 1318 ExpectLoadCall(); | 1312 ExpectLoadCall(); |
| 1319 ExpectLoadForKeyCall(http_www_google_.domain()); | 1313 ExpectLoadForKeyCall(http_www_foo_.domain()); |
| 1320 Begin(); | 1314 Begin(); |
| 1321 | 1315 |
| 1322 WaitForLoadCall(); | 1316 WaitForLoadCall(); |
| 1323 EXPECT_CALL(get_cookies_callback, Run("X=1")) | 1317 EXPECT_CALL(get_cookies_callback, Run("X=1")) |
| 1324 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_google_.url(), | 1318 .WillOnce(GetCookiesAction(&cookie_monster(), http_www_foo_.url(), |
| 1325 &get_cookies_callback_deferred)); | 1319 &get_cookies_callback_deferred)); |
| 1326 EXPECT_CALL(set_cookies_callback, Run(true)); | 1320 EXPECT_CALL(set_cookies_callback, Run(true)); |
| 1327 base::RunLoop loop; | 1321 base::RunLoop loop; |
| 1328 EXPECT_CALL(get_cookies_callback_deferred, Run("A=B; X=1")) | 1322 EXPECT_CALL(get_cookies_callback_deferred, Run("A=B; X=1")) |
| 1329 .WillOnce(QuitRunLoop(&loop)); | 1323 .WillOnce(QuitRunLoop(&loop)); |
| 1330 | 1324 |
| 1331 CompleteLoading(); | 1325 CompleteLoading(); |
| 1332 loop.Run(); | 1326 loop.Run(); |
| 1333 } | 1327 } |
| 1334 | 1328 |
| 1335 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { | 1329 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { |
| 1336 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1330 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1337 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 1331 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1338 CookieOptions options; | 1332 CookieOptions options; |
| 1339 options.set_include_httponly(); | 1333 options.set_include_httponly(); |
| 1340 | 1334 |
| 1341 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); | 1335 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), kValidCookieLine)); |
| 1342 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1336 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_foo_.url())); |
| 1343 | 1337 |
| 1344 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1338 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), |
| 1345 "C=D; httponly", options)); | 1339 "C=D; httponly", options)); |
| 1346 EXPECT_EQ("A=B; C=D", | 1340 EXPECT_EQ("A=B; C=D", |
| 1347 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1341 GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); |
| 1348 | 1342 |
| 1349 EXPECT_EQ(2, DeleteAll(cm.get())); | 1343 EXPECT_EQ(2, DeleteAll(cm.get())); |
| 1350 EXPECT_EQ("", | 1344 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); |
| 1351 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | |
| 1352 EXPECT_EQ(0u, store->commands().size()); | 1345 EXPECT_EQ(0u, store->commands().size()); |
| 1353 | 1346 |
| 1354 // Create a persistent cookie. | 1347 // Create a persistent cookie. |
| 1355 EXPECT_TRUE(SetCookie( | 1348 EXPECT_TRUE(SetCookie( |
| 1356 cm.get(), http_www_google_.url(), | 1349 cm.get(), http_www_foo_.url(), |
| 1357 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1350 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1358 ASSERT_EQ(1u, store->commands().size()); | 1351 ASSERT_EQ(1u, store->commands().size()); |
| 1359 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1352 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1360 | 1353 |
| 1361 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. | 1354 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. |
| 1362 ASSERT_EQ(2u, store->commands().size()); | 1355 ASSERT_EQ(2u, store->commands().size()); |
| 1363 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1356 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1364 | 1357 |
| 1365 EXPECT_EQ("", | 1358 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); |
| 1366 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | |
| 1367 } | 1359 } |
| 1368 | 1360 |
| 1369 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1361 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 1370 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1362 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1371 Time now = Time::Now(); | 1363 Time now = Time::Now(); |
| 1372 | 1364 |
| 1373 // Nothing has been added so nothing should be deleted. | 1365 // Nothing has been added so nothing should be deleted. |
| 1374 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), | 1366 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
| 1375 Time())); | 1367 Time())); |
| 1376 | 1368 |
| 1377 // Create 5 cookies with different creation dates. | 1369 // Create 5 cookies with different creation dates. |
| 1378 EXPECT_TRUE( | 1370 EXPECT_TRUE( |
| 1379 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); | 1371 cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-0=Now", now)); |
| 1380 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1372 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1381 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); | 1373 http_www_foo_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); |
| 1382 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1374 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1383 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); | 1375 http_www_foo_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); |
| 1384 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1376 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1385 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); | 1377 http_www_foo_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); |
| 1386 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1378 EXPECT_TRUE(cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-7=LastWeek", |
| 1387 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7))); | 1379 now - TimeDelta::FromDays(7))); |
| 1388 | 1380 |
| 1389 // Try to delete threedays and the daybefore. | 1381 // Try to delete threedays and the daybefore. |
| 1390 EXPECT_EQ(2, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3), | 1382 EXPECT_EQ(2, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3), |
| 1391 now - TimeDelta::FromDays(1))); | 1383 now - TimeDelta::FromDays(1))); |
| 1392 | 1384 |
| 1393 // Try to delete yesterday, also make sure that delete_end is not | 1385 // Try to delete yesterday, also make sure that delete_end is not |
| 1394 // inclusive. | 1386 // inclusive. |
| 1395 EXPECT_EQ( | 1387 EXPECT_EQ( |
| 1396 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); | 1388 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); |
| 1397 | 1389 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1418 CookiePredicate false_predicate = | 1410 CookiePredicate false_predicate = |
| 1419 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); | 1411 base::Bind(&AlwaysFalseCookiePredicate, &test_cookie); |
| 1420 | 1412 |
| 1421 // Nothing has been added so nothing should be deleted. | 1413 // Nothing has been added so nothing should be deleted. |
| 1422 EXPECT_EQ( | 1414 EXPECT_EQ( |
| 1423 0, DeleteAllCreatedBetweenWithPredicate( | 1415 0, DeleteAllCreatedBetweenWithPredicate( |
| 1424 cm.get(), now - TimeDelta::FromDays(99), Time(), true_predicate)); | 1416 cm.get(), now - TimeDelta::FromDays(99), Time(), true_predicate)); |
| 1425 | 1417 |
| 1426 // Create 5 cookies with different creation dates. | 1418 // Create 5 cookies with different creation dates. |
| 1427 EXPECT_TRUE( | 1419 EXPECT_TRUE( |
| 1428 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); | 1420 cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-0=Now", now)); |
| 1429 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1421 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1430 http_www_google_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); | 1422 http_www_foo_.url(), "T-1=Yesterday", now - TimeDelta::FromDays(1))); |
| 1431 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1423 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1432 http_www_google_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); | 1424 http_www_foo_.url(), "T-2=DayBefore", now - TimeDelta::FromDays(2))); |
| 1433 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1425 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| 1434 http_www_google_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); | 1426 http_www_foo_.url(), "T-3=ThreeDays", now - TimeDelta::FromDays(3))); |
| 1435 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1427 EXPECT_TRUE(cm->SetCookieWithCreationTime(http_www_foo_.url(), "T-7=LastWeek", |
| 1436 http_www_google_.url(), "T-7=LastWeek", now - TimeDelta::FromDays(7))); | 1428 now - TimeDelta::FromDays(7))); |
| 1437 | 1429 |
| 1438 // Try to delete threedays and the daybefore, but we should do nothing due | 1430 // Try to delete threedays and the daybefore, but we should do nothing due |
| 1439 // to the predicate. | 1431 // to the predicate. |
| 1440 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate( | 1432 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate( |
| 1441 cm.get(), now - TimeDelta::FromDays(3), | 1433 cm.get(), now - TimeDelta::FromDays(3), |
| 1442 now - TimeDelta::FromDays(1), false_predicate)); | 1434 now - TimeDelta::FromDays(1), false_predicate)); |
| 1443 // Same as above with a null predicate, so it shouldn't delete anything. | 1435 // Same as above with a null predicate, so it shouldn't delete anything. |
| 1444 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate( | 1436 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate( |
| 1445 cm.get(), now - TimeDelta::FromDays(3), | 1437 cm.get(), now - TimeDelta::FromDays(3), |
| 1446 now - TimeDelta::FromDays(1), CookiePredicate())); | 1438 now - TimeDelta::FromDays(1), CookiePredicate())); |
| 1447 // Same as above, but we use the true_predicate, so it works. | 1439 // Same as above, but we use the true_predicate, so it works. |
| 1448 EXPECT_EQ(2, DeleteAllCreatedBetweenWithPredicate( | 1440 EXPECT_EQ(2, DeleteAllCreatedBetweenWithPredicate( |
| 1449 cm.get(), now - TimeDelta::FromDays(3), | 1441 cm.get(), now - TimeDelta::FromDays(3), |
| 1450 now - TimeDelta::FromDays(1), true_predicate)); | 1442 now - TimeDelta::FromDays(1), true_predicate)); |
| 1451 | 1443 |
| 1452 // Try to delete yesterday, also make sure that delete_end is not | 1444 // Try to delete yesterday, also make sure that delete_end is not |
| 1453 // inclusive. | 1445 // inclusive. |
| 1454 EXPECT_EQ(0, | 1446 EXPECT_EQ(0, |
| 1455 DeleteAllCreatedBetweenWithPredicate( | 1447 DeleteAllCreatedBetweenWithPredicate( |
| 1456 cm.get(), now - TimeDelta::FromDays(2), now, false_predicate)); | 1448 cm.get(), now - TimeDelta::FromDays(2), now, false_predicate)); |
| 1457 EXPECT_EQ(1, | 1449 EXPECT_EQ(1, |
| 1458 DeleteAllCreatedBetweenWithPredicate( | 1450 DeleteAllCreatedBetweenWithPredicate( |
| 1459 cm.get(), now - TimeDelta::FromDays(2), now, true_predicate)); | 1451 cm.get(), now - TimeDelta::FromDays(2), now, true_predicate)); |
| 1460 // Check our cookie values. | 1452 // Check our cookie values. |
| 1461 std::unique_ptr<CanonicalCookie> expected_cookie = | 1453 std::unique_ptr<CanonicalCookie> expected_cookie = |
| 1462 CanonicalCookie::Create(http_www_google_.url(), "T-1=Yesterday", | 1454 CanonicalCookie::Create(http_www_foo_.url(), "T-1=Yesterday", |
| 1463 now - TimeDelta::FromDays(1), CookieOptions()); | 1455 now - TimeDelta::FromDays(1), CookieOptions()); |
| 1464 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) | 1456 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) |
| 1465 << "Actual:\n" | 1457 << "Actual:\n" |
| 1466 << test_cookie.DebugString() << "\nExpected:\n" | 1458 << test_cookie.DebugString() << "\nExpected:\n" |
| 1467 << expected_cookie->DebugString(); | 1459 << expected_cookie->DebugString(); |
| 1468 | 1460 |
| 1469 // Make sure the delete_begin is inclusive. | 1461 // Make sure the delete_begin is inclusive. |
| 1470 EXPECT_EQ(0, | 1462 EXPECT_EQ(0, |
| 1471 DeleteAllCreatedBetweenWithPredicate( | 1463 DeleteAllCreatedBetweenWithPredicate( |
| 1472 cm.get(), now - TimeDelta::FromDays(7), now, false_predicate)); | 1464 cm.get(), now - TimeDelta::FromDays(7), now, false_predicate)); |
| 1473 EXPECT_EQ(1, | 1465 EXPECT_EQ(1, |
| 1474 DeleteAllCreatedBetweenWithPredicate( | 1466 DeleteAllCreatedBetweenWithPredicate( |
| 1475 cm.get(), now - TimeDelta::FromDays(7), now, true_predicate)); | 1467 cm.get(), now - TimeDelta::FromDays(7), now, true_predicate)); |
| 1476 | 1468 |
| 1477 // Delete the last (now) item. | 1469 // Delete the last (now) item. |
| 1478 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), | 1470 EXPECT_EQ(0, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), |
| 1479 false_predicate)); | 1471 false_predicate)); |
| 1480 EXPECT_EQ(1, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), | 1472 EXPECT_EQ(1, DeleteAllCreatedBetweenWithPredicate(cm.get(), Time(), Time(), |
| 1481 true_predicate)); | 1473 true_predicate)); |
| 1482 expected_cookie = CanonicalCookie::Create(http_www_google_.url(), "T-0=Now", | 1474 expected_cookie = CanonicalCookie::Create(http_www_foo_.url(), "T-0=Now", now, |
| 1483 now, CookieOptions()); | 1475 CookieOptions()); |
| 1484 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) | 1476 EXPECT_THAT(test_cookie, CookieEquals(*expected_cookie)) |
| 1485 << "Actual:\n" | 1477 << "Actual:\n" |
| 1486 << test_cookie.DebugString() << "\nExpected:\n" | 1478 << test_cookie.DebugString() << "\nExpected:\n" |
| 1487 << expected_cookie->DebugString(); | 1479 << expected_cookie->DebugString(); |
| 1488 | 1480 |
| 1489 // Really make sure everything is gone. | 1481 // Really make sure everything is gone. |
| 1490 EXPECT_EQ(0, DeleteAll(cm.get())); | 1482 EXPECT_EQ(0, DeleteAll(cm.get())); |
| 1491 } | 1483 } |
| 1492 | 1484 |
| 1493 static const base::TimeDelta kLastAccessThreshold = | 1485 static const base::TimeDelta kLastAccessThreshold = |
| 1494 base::TimeDelta::FromMilliseconds(200); | 1486 base::TimeDelta::FromMilliseconds(200); |
| 1495 static const base::TimeDelta kAccessDelay = | 1487 static const base::TimeDelta kAccessDelay = |
| 1496 kLastAccessThreshold + base::TimeDelta::FromMilliseconds(20); | 1488 kLastAccessThreshold + base::TimeDelta::FromMilliseconds(20); |
| 1497 | 1489 |
| 1498 TEST_F(CookieMonsterTest, TestLastAccess) { | 1490 TEST_F(CookieMonsterTest, TestLastAccess) { |
| 1499 std::unique_ptr<CookieMonster> cm( | 1491 std::unique_ptr<CookieMonster> cm( |
| 1500 new CookieMonster(nullptr, nullptr, kLastAccessThreshold)); | 1492 new CookieMonster(nullptr, nullptr, kLastAccessThreshold)); |
| 1501 | 1493 |
| 1502 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1494 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=B")); |
| 1503 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1495 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
| 1504 | 1496 |
| 1505 // Reading the cookie again immediately shouldn't update the access date, | 1497 // Reading the cookie again immediately shouldn't update the access date, |
| 1506 // since we're inside the threshold. | 1498 // since we're inside the threshold. |
| 1507 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1499 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_foo_.url())); |
| 1508 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1500 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1509 | 1501 |
| 1510 // Reading after a short wait will update the access date, if the cookie | 1502 // Reading after a short wait will update the access date, if the cookie |
| 1511 // is requested with options that would update the access date. First, test | 1503 // is requested with options that would update the access date. First, test |
| 1512 // that the flag's behavior is respected. | 1504 // that the flag's behavior is respected. |
| 1513 base::PlatformThread::Sleep(kAccessDelay); | 1505 base::PlatformThread::Sleep(kAccessDelay); |
| 1514 CookieOptions options; | 1506 CookieOptions options; |
| 1515 options.set_do_not_update_access_time(); | 1507 options.set_do_not_update_access_time(); |
| 1516 EXPECT_EQ("A=B", | 1508 EXPECT_EQ("A=B", |
| 1517 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1509 GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); |
| 1518 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1510 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1519 | 1511 |
| 1520 // Getting all cookies for a URL doesn't update the accessed time either. | 1512 // Getting all cookies for a URL doesn't update the accessed time either. |
| 1521 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url()); | 1513 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_foo_.url()); |
| 1522 CookieList::iterator it = cookies.begin(); | 1514 CookieList::iterator it = cookies.begin(); |
| 1523 ASSERT_TRUE(it != cookies.end()); | 1515 ASSERT_TRUE(it != cookies.end()); |
| 1524 EXPECT_EQ(http_www_google_.host(), it->Domain()); | 1516 EXPECT_EQ(http_www_foo_.host(), it->Domain()); |
| 1525 EXPECT_EQ("A", it->Name()); | 1517 EXPECT_EQ("A", it->Name()); |
| 1526 EXPECT_EQ("B", it->Value()); | 1518 EXPECT_EQ("B", it->Value()); |
| 1527 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1519 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1528 EXPECT_TRUE(++it == cookies.end()); | 1520 EXPECT_TRUE(++it == cookies.end()); |
| 1529 | 1521 |
| 1530 // If the flag isn't set, the last accessed time should be updated. | 1522 // If the flag isn't set, the last accessed time should be updated. |
| 1531 options = CookieOptions(); | 1523 options = CookieOptions(); |
| 1532 EXPECT_EQ("A=B", | 1524 EXPECT_EQ("A=B", |
| 1533 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1525 GetCookiesWithOptions(cm.get(), http_www_foo_.url(), options)); |
| 1534 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm.get())); | 1526 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm.get())); |
| 1535 } | 1527 } |
| 1536 | 1528 |
| 1537 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { | 1529 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { |
| 1538 TestHostGarbageCollectHelper(); | 1530 TestHostGarbageCollectHelper(); |
| 1539 } | 1531 } |
| 1540 | 1532 |
| 1541 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionNonSecure) { | 1533 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionNonSecure) { |
| 1542 TestPriorityAwareGarbageCollectHelperNonSecure(); | 1534 TestPriorityAwareGarbageCollectHelperNonSecure(); |
| 1543 } | 1535 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1569 } | 1561 } |
| 1570 | 1562 |
| 1571 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { | 1563 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { |
| 1572 std::unique_ptr<CookieMonster> cm( | 1564 std::unique_ptr<CookieMonster> cm( |
| 1573 new CookieMonster(nullptr, nullptr, kLastAccessThreshold)); | 1565 new CookieMonster(nullptr, nullptr, kLastAccessThreshold)); |
| 1574 | 1566 |
| 1575 // Create an httponly cookie. | 1567 // Create an httponly cookie. |
| 1576 CookieOptions options; | 1568 CookieOptions options; |
| 1577 options.set_include_httponly(); | 1569 options.set_include_httponly(); |
| 1578 | 1570 |
| 1579 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1571 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), |
| 1580 "A=B; httponly", options)); | 1572 "A=B; httponly", options)); |
| 1581 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1573 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), |
| 1582 http_www_google_.Format("C=D; domain=.%D"), | 1574 http_www_foo_.Format("C=D; domain=.%D"), |
| 1583 options)); | 1575 options)); |
| 1584 EXPECT_TRUE(SetCookieWithOptions( | 1576 EXPECT_TRUE(SetCookieWithOptions( |
| 1585 cm.get(), https_www_google_.url(), | 1577 cm.get(), https_www_foo_.url(), |
| 1586 http_www_google_.Format("E=F; domain=.%D; secure"), options)); | 1578 http_www_foo_.Format("E=F; domain=.%D; secure"), options)); |
| 1587 | 1579 |
| 1588 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1580 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
| 1589 | 1581 |
| 1590 base::PlatformThread::Sleep(kAccessDelay); | 1582 base::PlatformThread::Sleep(kAccessDelay); |
| 1591 | 1583 |
| 1592 // Check cookies for url. | 1584 // Check cookies for url. |
| 1593 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_google_.url()); | 1585 CookieList cookies = GetAllCookiesForURL(cm.get(), http_www_foo_.url()); |
| 1594 CookieList::iterator it = cookies.begin(); | 1586 CookieList::iterator it = cookies.begin(); |
| 1595 | 1587 |
| 1596 ASSERT_TRUE(it != cookies.end()); | 1588 ASSERT_TRUE(it != cookies.end()); |
| 1597 EXPECT_EQ(http_www_google_.host(), it->Domain()); | 1589 EXPECT_EQ(http_www_foo_.host(), it->Domain()); |
| 1598 EXPECT_EQ("A", it->Name()); | 1590 EXPECT_EQ("A", it->Name()); |
| 1599 | 1591 |
| 1600 ASSERT_TRUE(++it != cookies.end()); | 1592 ASSERT_TRUE(++it != cookies.end()); |
| 1601 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); | 1593 EXPECT_EQ(http_www_foo_.Format(".%D"), it->Domain()); |
| 1602 EXPECT_EQ("C", it->Name()); | 1594 EXPECT_EQ("C", it->Name()); |
| 1603 | 1595 |
| 1604 ASSERT_TRUE(++it == cookies.end()); | 1596 ASSERT_TRUE(++it == cookies.end()); |
| 1605 | 1597 |
| 1606 // Check cookies for url excluding http-only cookies. | 1598 // Check cookies for url excluding http-only cookies. |
| 1607 cookies = GetAllCookiesForURLWithOptions(cm.get(), http_www_google_.url(), | 1599 cookies = GetAllCookiesForURLWithOptions(cm.get(), http_www_foo_.url(), |
| 1608 CookieOptions()); | 1600 CookieOptions()); |
| 1609 it = cookies.begin(); | 1601 it = cookies.begin(); |
| 1610 | 1602 |
| 1611 ASSERT_TRUE(it != cookies.end()); | 1603 ASSERT_TRUE(it != cookies.end()); |
| 1612 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); | 1604 EXPECT_EQ(http_www_foo_.Format(".%D"), it->Domain()); |
| 1613 EXPECT_EQ("C", it->Name()); | 1605 EXPECT_EQ("C", it->Name()); |
| 1614 | 1606 |
| 1615 ASSERT_TRUE(++it == cookies.end()); | 1607 ASSERT_TRUE(++it == cookies.end()); |
| 1616 | 1608 |
| 1617 // Test secure cookies. | 1609 // Test secure cookies. |
| 1618 cookies = GetAllCookiesForURL(cm.get(), https_www_google_.url()); | 1610 cookies = GetAllCookiesForURL(cm.get(), https_www_foo_.url()); |
| 1619 it = cookies.begin(); | 1611 it = cookies.begin(); |
| 1620 | 1612 |
| 1621 ASSERT_TRUE(it != cookies.end()); | 1613 ASSERT_TRUE(it != cookies.end()); |
| 1622 EXPECT_EQ(http_www_google_.host(), it->Domain()); | 1614 EXPECT_EQ(http_www_foo_.host(), it->Domain()); |
| 1623 EXPECT_EQ("A", it->Name()); | 1615 EXPECT_EQ("A", it->Name()); |
| 1624 | 1616 |
| 1625 ASSERT_TRUE(++it != cookies.end()); | 1617 ASSERT_TRUE(++it != cookies.end()); |
| 1626 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); | 1618 EXPECT_EQ(http_www_foo_.Format(".%D"), it->Domain()); |
| 1627 EXPECT_EQ("C", it->Name()); | 1619 EXPECT_EQ("C", it->Name()); |
| 1628 | 1620 |
| 1629 ASSERT_TRUE(++it != cookies.end()); | 1621 ASSERT_TRUE(++it != cookies.end()); |
| 1630 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); | 1622 EXPECT_EQ(http_www_foo_.Format(".%D"), it->Domain()); |
| 1631 EXPECT_EQ("E", it->Name()); | 1623 EXPECT_EQ("E", it->Name()); |
| 1632 | 1624 |
| 1633 ASSERT_TRUE(++it == cookies.end()); | 1625 ASSERT_TRUE(++it == cookies.end()); |
| 1634 | 1626 |
| 1635 // Reading after a short wait should not update the access date. | 1627 // Reading after a short wait should not update the access date. |
| 1636 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1628 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1637 } | 1629 } |
| 1638 | 1630 |
| 1639 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { | 1631 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { |
| 1640 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1632 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1641 CookieOptions options; | 1633 CookieOptions options; |
| 1642 | 1634 |
| 1643 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(), | 1635 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_foo_foo_.url(), |
| 1644 "A=B; path=/foo;", options)); | 1636 "A=B; path=/foo;", options)); |
| 1645 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(), | 1637 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_foo_bar_.url(), |
| 1646 "C=D; path=/bar;", options)); | 1638 "C=D; path=/bar;", options)); |
| 1647 EXPECT_TRUE( | 1639 EXPECT_TRUE( |
| 1648 SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options)); | 1640 SetCookieWithOptions(cm.get(), http_www_foo_.url(), "E=F;", options)); |
| 1649 | 1641 |
| 1650 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url()); | 1642 CookieList cookies = GetAllCookiesForURL(cm.get(), www_foo_foo_.url()); |
| 1651 CookieList::iterator it = cookies.begin(); | 1643 CookieList::iterator it = cookies.begin(); |
| 1652 | 1644 |
| 1653 ASSERT_TRUE(it != cookies.end()); | 1645 ASSERT_TRUE(it != cookies.end()); |
| 1654 EXPECT_EQ("A", it->Name()); | 1646 EXPECT_EQ("A", it->Name()); |
| 1655 EXPECT_EQ("/foo", it->Path()); | 1647 EXPECT_EQ("/foo", it->Path()); |
| 1656 | 1648 |
| 1657 ASSERT_TRUE(++it != cookies.end()); | 1649 ASSERT_TRUE(++it != cookies.end()); |
| 1658 EXPECT_EQ("E", it->Name()); | 1650 EXPECT_EQ("E", it->Name()); |
| 1659 EXPECT_EQ("/", it->Path()); | 1651 EXPECT_EQ("/", it->Path()); |
| 1660 | 1652 |
| 1661 ASSERT_TRUE(++it == cookies.end()); | 1653 ASSERT_TRUE(++it == cookies.end()); |
| 1662 | 1654 |
| 1663 cookies = GetAllCookiesForURL(cm.get(), www_google_bar_.url()); | 1655 cookies = GetAllCookiesForURL(cm.get(), www_foo_bar_.url()); |
| 1664 it = cookies.begin(); | 1656 it = cookies.begin(); |
| 1665 | 1657 |
| 1666 ASSERT_TRUE(it != cookies.end()); | 1658 ASSERT_TRUE(it != cookies.end()); |
| 1667 EXPECT_EQ("C", it->Name()); | 1659 EXPECT_EQ("C", it->Name()); |
| 1668 EXPECT_EQ("/bar", it->Path()); | 1660 EXPECT_EQ("/bar", it->Path()); |
| 1669 | 1661 |
| 1670 ASSERT_TRUE(++it != cookies.end()); | 1662 ASSERT_TRUE(++it != cookies.end()); |
| 1671 EXPECT_EQ("E", it->Name()); | 1663 EXPECT_EQ("E", it->Name()); |
| 1672 EXPECT_EQ("/", it->Path()); | 1664 EXPECT_EQ("/", it->Path()); |
| 1673 | 1665 |
| 1674 ASSERT_TRUE(++it == cookies.end()); | 1666 ASSERT_TRUE(++it == cookies.end()); |
| 1675 } | 1667 } |
| 1676 | 1668 |
| 1677 TEST_F(CookieMonsterTest, CookieSorting) { | 1669 TEST_F(CookieMonsterTest, CookieSorting) { |
| 1678 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1670 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1679 | 1671 |
| 1680 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); | 1672 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B1; path=/")); |
| 1681 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); | 1673 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B2; path=/foo")); |
| 1682 EXPECT_TRUE( | 1674 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B3; path=/foo/bar")); |
| 1683 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); | 1675 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A1; path=/")); |
| 1684 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); | 1676 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A2; path=/foo")); |
| 1685 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); | 1677 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A3; path=/foo/bar")); |
| 1686 EXPECT_TRUE( | |
| 1687 SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar")); | |
| 1688 | 1678 |
| 1689 // Re-set cookie which should not change sort order. | 1679 // Re-set cookie which should not change sort order. |
| 1690 EXPECT_TRUE( | 1680 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B3; path=/foo/bar")); |
| 1691 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); | |
| 1692 | 1681 |
| 1693 CookieList cookies = GetAllCookies(cm.get()); | 1682 CookieList cookies = GetAllCookies(cm.get()); |
| 1694 ASSERT_EQ(6u, cookies.size()); | 1683 ASSERT_EQ(6u, cookies.size()); |
| 1695 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the | 1684 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the |
| 1696 // initial creation-time from above, and the sort order should not change. | 1685 // initial creation-time from above, and the sort order should not change. |
| 1697 // Chrome's current implementation deviates from the spec so capturing this to | 1686 // Chrome's current implementation deviates from the spec so capturing this to |
| 1698 // avoid any inadvertent changes to this behavior. | 1687 // avoid any inadvertent changes to this behavior. |
| 1699 EXPECT_EQ("A3", cookies[0].Value()); | 1688 EXPECT_EQ("A3", cookies[0].Value()); |
| 1700 EXPECT_EQ("B3", cookies[1].Value()); | 1689 EXPECT_EQ("B3", cookies[1].Value()); |
| 1701 EXPECT_EQ("B2", cookies[2].Value()); | 1690 EXPECT_EQ("B2", cookies[2].Value()); |
| 1702 EXPECT_EQ("A2", cookies[3].Value()); | 1691 EXPECT_EQ("A2", cookies[3].Value()); |
| 1703 EXPECT_EQ("B1", cookies[4].Value()); | 1692 EXPECT_EQ("B1", cookies[4].Value()); |
| 1704 EXPECT_EQ("A1", cookies[5].Value()); | 1693 EXPECT_EQ("A1", cookies[5].Value()); |
| 1705 } | 1694 } |
| 1706 | 1695 |
| 1707 TEST_F(CookieMonsterTest, DeleteCookieByName) { | 1696 TEST_F(CookieMonsterTest, DeleteCookieByName) { |
| 1708 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1697 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1709 | 1698 |
| 1710 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); | 1699 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A1; path=/")); |
| 1711 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); | 1700 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A2; path=/foo")); |
| 1712 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/bar")); | 1701 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A3; path=/bar")); |
| 1713 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); | 1702 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B1; path=/")); |
| 1714 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); | 1703 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B2; path=/foo")); |
| 1715 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/bar")); | 1704 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B3; path=/bar")); |
| 1716 | 1705 |
| 1717 DeleteCookie(cm.get(), http_www_google_.AppendPath("foo/bar"), "A"); | 1706 DeleteCookie(cm.get(), http_www_foo_.AppendPath("foo/bar"), "A"); |
| 1718 | 1707 |
| 1719 CookieList cookies = GetAllCookies(cm.get()); | 1708 CookieList cookies = GetAllCookies(cm.get()); |
| 1720 size_t expected_size = 4; | 1709 size_t expected_size = 4; |
| 1721 EXPECT_EQ(expected_size, cookies.size()); | 1710 EXPECT_EQ(expected_size, cookies.size()); |
| 1722 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) { | 1711 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) { |
| 1723 EXPECT_NE("A1", it->Value()); | 1712 EXPECT_NE("A1", it->Value()); |
| 1724 EXPECT_NE("A2", it->Value()); | 1713 EXPECT_NE("A2", it->Value()); |
| 1725 } | 1714 } |
| 1726 } | 1715 } |
| 1727 | 1716 |
| 1728 // Tests importing from a persistent cookie store that contains duplicate | 1717 // Tests importing from a persistent cookie store that contains duplicate |
| 1729 // equivalent cookies. This situation should be handled by removing the | 1718 // equivalent cookies. This situation should be handled by removing the |
| 1730 // duplicate cookie (both from the in-memory cache, and from the backing store). | 1719 // duplicate cookie (both from the in-memory cache, and from the backing store). |
| 1731 // | 1720 // |
| 1732 // This is a regression test for: http://crbug.com/17855. | 1721 // This is a regression test for: http://crbug.com/17855. |
| 1733 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { | 1722 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { |
| 1734 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1723 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1735 | 1724 |
| 1736 // We will fill some initial cookies into the PersistentCookieStore, | 1725 // We will fill some initial cookies into the PersistentCookieStore, |
| 1737 // to simulate a database with 4 duplicates. Note that we need to | 1726 // to simulate a database with 4 duplicates. Note that we need to |
| 1738 // be careful not to have any duplicate creation times at all (as it's a | 1727 // be careful not to have any duplicate creation times at all (as it's a |
| 1739 // violation of a CookieMonster invariant) even if Time::Now() doesn't | 1728 // violation of a CookieMonster invariant) even if Time::Now() doesn't |
| 1740 // move between calls. | 1729 // move between calls. |
| 1741 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; | 1730 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; |
| 1742 | 1731 |
| 1743 // Insert 4 cookies with name "X" on path "/", with varying creation | 1732 // Insert 4 cookies with name "X" on path "/", with varying creation |
| 1744 // dates. We expect only the most recent one to be preserved following | 1733 // dates. We expect only the most recent one to be preserved following |
| 1745 // the import. | 1734 // the import. |
| 1746 | 1735 |
| 1747 AddCookieToList(GURL("http://www.google.com"), | 1736 AddCookieToList(GURL("http://www.foo.com"), |
| 1748 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1737 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1749 Time::Now() + TimeDelta::FromDays(3), &initial_cookies); | 1738 Time::Now() + TimeDelta::FromDays(3), &initial_cookies); |
| 1750 | 1739 |
| 1751 AddCookieToList(GURL("http://www.google.com"), | 1740 AddCookieToList(GURL("http://www.foo.com"), |
| 1752 "X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1741 "X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1753 Time::Now() + TimeDelta::FromDays(1), &initial_cookies); | 1742 Time::Now() + TimeDelta::FromDays(1), &initial_cookies); |
| 1754 | 1743 |
| 1755 // ===> This one is the WINNER (biggest creation time). <==== | 1744 // ===> This one is the WINNER (biggest creation time). <==== |
| 1756 AddCookieToList(GURL("http://www.google.com"), | 1745 AddCookieToList(GURL("http://www.foo.com"), |
| 1757 "X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1746 "X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1758 Time::Now() + TimeDelta::FromDays(4), &initial_cookies); | 1747 Time::Now() + TimeDelta::FromDays(4), &initial_cookies); |
| 1759 | 1748 |
| 1760 AddCookieToList(GURL("http://www.google.com"), | 1749 AddCookieToList(GURL("http://www.foo.com"), |
| 1761 "X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1750 "X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1762 Time::Now(), &initial_cookies); | 1751 Time::Now(), &initial_cookies); |
| 1763 | 1752 |
| 1764 // Insert 2 cookies with name "X" on path "/2", with varying creation | 1753 // Insert 2 cookies with name "X" on path "/2", with varying creation |
| 1765 // dates. We expect only the most recent one to be preserved the import. | 1754 // dates. We expect only the most recent one to be preserved the import. |
| 1766 | 1755 |
| 1767 // ===> This one is the WINNER (biggest creation time). <==== | 1756 // ===> This one is the WINNER (biggest creation time). <==== |
| 1768 AddCookieToList(GURL("http://www.google.com"), | 1757 AddCookieToList(GURL("http://www.foo.com"), |
| 1769 "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1758 "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1770 Time::Now() + TimeDelta::FromDays(9), &initial_cookies); | 1759 Time::Now() + TimeDelta::FromDays(9), &initial_cookies); |
| 1771 | 1760 |
| 1772 AddCookieToList(GURL("http://www.google.com"), | 1761 AddCookieToList(GURL("http://www.foo.com"), |
| 1773 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1762 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1774 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); | 1763 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); |
| 1775 | 1764 |
| 1776 // Insert 1 cookie with name "Y" on path "/". | 1765 // Insert 1 cookie with name "Y" on path "/". |
| 1777 AddCookieToList(GURL("http://www.google.com"), | 1766 AddCookieToList(GURL("http://www.foo.com"), |
| 1778 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1767 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1779 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); | 1768 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); |
| 1780 | 1769 |
| 1781 // Inject our initial cookies into the mock PersistentCookieStore. | 1770 // Inject our initial cookies into the mock PersistentCookieStore. |
| 1782 store->SetLoadExpectation(true, std::move(initial_cookies)); | 1771 store->SetLoadExpectation(true, std::move(initial_cookies)); |
| 1783 | 1772 |
| 1784 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 1773 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1785 | 1774 |
| 1786 // Verify that duplicates were not imported for path "/". | 1775 // Verify that duplicates were not imported for path "/". |
| 1787 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). | 1776 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). |
| 1788 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); | 1777 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.foo.com/"))); |
| 1789 | 1778 |
| 1790 // Verify that same-named cookie on a different path ("/x2") didn't get | 1779 // Verify that same-named cookie on a different path ("/x2") didn't get |
| 1791 // messed up. | 1780 // messed up. |
| 1792 EXPECT_EQ("X=a1; X=3; Y=a", | 1781 EXPECT_EQ("X=a1; X=3; Y=a", |
| 1793 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); | 1782 GetCookies(cm.get(), GURL("http://www.foo.com/2/x"))); |
| 1794 | 1783 |
| 1795 // Verify that the PersistentCookieStore was told to kill its 4 duplicates. | 1784 // Verify that the PersistentCookieStore was told to kill its 4 duplicates. |
| 1796 ASSERT_EQ(4u, store->commands().size()); | 1785 ASSERT_EQ(4u, store->commands().size()); |
| 1797 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type); | 1786 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type); |
| 1798 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1787 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1799 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); | 1788 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); |
| 1800 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 1789 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 1801 } | 1790 } |
| 1802 | 1791 |
| 1803 // Tests importing from a persistent cookie store that contains cookies | 1792 // Tests importing from a persistent cookie store that contains cookies |
| 1804 // with duplicate creation times. This situation should be handled by | 1793 // with duplicate creation times. This situation should be handled by |
| 1805 // dropping the cookies before insertion/visibility to user. | 1794 // dropping the cookies before insertion/visibility to user. |
| 1806 // | 1795 // |
| 1807 // This is a regression test for: http://crbug.com/43188. | 1796 // This is a regression test for: http://crbug.com/43188. |
| 1808 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { | 1797 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { |
| 1809 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1798 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1810 | 1799 |
| 1811 Time now(Time::Now()); | 1800 Time now(Time::Now()); |
| 1812 Time earlier(now - TimeDelta::FromDays(1)); | 1801 Time earlier(now - TimeDelta::FromDays(1)); |
| 1813 | 1802 |
| 1814 // Insert 8 cookies, four with the current time as creation times, and | 1803 // Insert 8 cookies, four with the current time as creation times, and |
| 1815 // four with the earlier time as creation times. We should only get | 1804 // four with the earlier time as creation times. We should only get |
| 1816 // two cookies remaining, but which two (other than that there should | 1805 // two cookies remaining, but which two (other than that there should |
| 1817 // be one from each set) will be random. | 1806 // be one from each set) will be random. |
| 1818 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; | 1807 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; |
| 1819 AddCookieToList(GURL("http://www.google.com"), "X=1; path=/", now, | 1808 AddCookieToList(GURL("http://www.foo.com"), "X=1; path=/", now, |
| 1820 &initial_cookies); | 1809 &initial_cookies); |
| 1821 AddCookieToList(GURL("http://www.google.com"), "X=2; path=/", now, | 1810 AddCookieToList(GURL("http://www.foo.com"), "X=2; path=/", now, |
| 1822 &initial_cookies); | 1811 &initial_cookies); |
| 1823 AddCookieToList(GURL("http://www.google.com"), "X=3; path=/", now, | 1812 AddCookieToList(GURL("http://www.foo.com"), "X=3; path=/", now, |
| 1824 &initial_cookies); | 1813 &initial_cookies); |
| 1825 AddCookieToList(GURL("http://www.google.com"), "X=4; path=/", now, | 1814 AddCookieToList(GURL("http://www.foo.com"), "X=4; path=/", now, |
| 1826 &initial_cookies); | 1815 &initial_cookies); |
| 1827 | 1816 |
| 1828 AddCookieToList(GURL("http://www.google.com"), "Y=1; path=/", earlier, | 1817 AddCookieToList(GURL("http://www.foo.com"), "Y=1; path=/", earlier, |
| 1829 &initial_cookies); | 1818 &initial_cookies); |
| 1830 AddCookieToList(GURL("http://www.google.com"), "Y=2; path=/", earlier, | 1819 AddCookieToList(GURL("http://www.foo.com"), "Y=2; path=/", earlier, |
| 1831 &initial_cookies); | 1820 &initial_cookies); |
| 1832 AddCookieToList(GURL("http://www.google.com"), "Y=3; path=/", earlier, | 1821 AddCookieToList(GURL("http://www.foo.com"), "Y=3; path=/", earlier, |
| 1833 &initial_cookies); | 1822 &initial_cookies); |
| 1834 AddCookieToList(GURL("http://www.google.com"), "Y=4; path=/", earlier, | 1823 AddCookieToList(GURL("http://www.foo.com"), "Y=4; path=/", earlier, |
| 1835 &initial_cookies); | 1824 &initial_cookies); |
| 1836 | 1825 |
| 1837 // Inject our initial cookies into the mock PersistentCookieStore. | 1826 // Inject our initial cookies into the mock PersistentCookieStore. |
| 1838 store->SetLoadExpectation(true, std::move(initial_cookies)); | 1827 store->SetLoadExpectation(true, std::move(initial_cookies)); |
| 1839 | 1828 |
| 1840 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 1829 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1841 | 1830 |
| 1842 CookieList list(GetAllCookies(cm.get())); | 1831 CookieList list(GetAllCookies(cm.get())); |
| 1843 EXPECT_EQ(2U, list.size()); | 1832 EXPECT_EQ(2U, list.size()); |
| 1844 // Confirm that we have one of each. | 1833 // Confirm that we have one of each. |
| 1845 std::string name1(list[0].Name()); | 1834 std::string name1(list[0].Name()); |
| 1846 std::string name2(list[1].Name()); | 1835 std::string name2(list[1].Name()); |
| 1847 EXPECT_TRUE(name1 == "X" || name2 == "X"); | 1836 EXPECT_TRUE(name1 == "X" || name2 == "X"); |
| 1848 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); | 1837 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); |
| 1849 EXPECT_NE(name1, name2); | 1838 EXPECT_NE(name1, name2); |
| 1850 } | 1839 } |
| 1851 | 1840 |
| 1852 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { | 1841 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { |
| 1853 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1842 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1854 scoped_refptr<MockCookieMonsterDelegate> delegate( | 1843 scoped_refptr<MockCookieMonsterDelegate> delegate( |
| 1855 new MockCookieMonsterDelegate); | 1844 new MockCookieMonsterDelegate); |
| 1856 std::unique_ptr<CookieMonster> cm( | 1845 std::unique_ptr<CookieMonster> cm( |
| 1857 new CookieMonster(store.get(), delegate.get())); | 1846 new CookieMonster(store.get(), delegate.get())); |
| 1858 | 1847 |
| 1859 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1848 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=B")); |
| 1860 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D")); | 1849 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "C=D")); |
| 1861 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F")); | 1850 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "E=F")); |
| 1862 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url())); | 1851 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_foo_.url())); |
| 1863 ASSERT_EQ(3u, delegate->changes().size()); | 1852 ASSERT_EQ(3u, delegate->changes().size()); |
| 1864 EXPECT_FALSE(delegate->changes()[0].second); | 1853 EXPECT_FALSE(delegate->changes()[0].second); |
| 1865 EXPECT_EQ(http_www_google_.url().host(), | 1854 EXPECT_EQ(http_www_foo_.url().host(), delegate->changes()[0].first.Domain()); |
| 1866 delegate->changes()[0].first.Domain()); | |
| 1867 EXPECT_EQ("A", delegate->changes()[0].first.Name()); | 1855 EXPECT_EQ("A", delegate->changes()[0].first.Name()); |
| 1868 EXPECT_EQ("B", delegate->changes()[0].first.Value()); | 1856 EXPECT_EQ("B", delegate->changes()[0].first.Value()); |
| 1869 EXPECT_EQ(http_www_google_.url().host(), | 1857 EXPECT_EQ(http_www_foo_.url().host(), delegate->changes()[1].first.Domain()); |
| 1870 delegate->changes()[1].first.Domain()); | |
| 1871 EXPECT_FALSE(delegate->changes()[1].second); | 1858 EXPECT_FALSE(delegate->changes()[1].second); |
| 1872 EXPECT_EQ("C", delegate->changes()[1].first.Name()); | 1859 EXPECT_EQ("C", delegate->changes()[1].first.Name()); |
| 1873 EXPECT_EQ("D", delegate->changes()[1].first.Value()); | 1860 EXPECT_EQ("D", delegate->changes()[1].first.Value()); |
| 1874 EXPECT_EQ(http_www_google_.url().host(), | 1861 EXPECT_EQ(http_www_foo_.url().host(), delegate->changes()[2].first.Domain()); |
| 1875 delegate->changes()[2].first.Domain()); | |
| 1876 EXPECT_FALSE(delegate->changes()[2].second); | 1862 EXPECT_FALSE(delegate->changes()[2].second); |
| 1877 EXPECT_EQ("E", delegate->changes()[2].first.Name()); | 1863 EXPECT_EQ("E", delegate->changes()[2].first.Name()); |
| 1878 EXPECT_EQ("F", delegate->changes()[2].first.Value()); | 1864 EXPECT_EQ("F", delegate->changes()[2].first.Value()); |
| 1879 delegate->reset(); | 1865 delegate->reset(); |
| 1880 | 1866 |
| 1881 EXPECT_TRUE( | 1867 EXPECT_TRUE(FindAndDeleteCookie(cm.get(), http_www_foo_.url().host(), "C")); |
| 1882 FindAndDeleteCookie(cm.get(), http_www_google_.url().host(), "C")); | 1868 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_foo_.url())); |
| 1883 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url())); | |
| 1884 ASSERT_EQ(1u, delegate->changes().size()); | 1869 ASSERT_EQ(1u, delegate->changes().size()); |
| 1885 EXPECT_EQ(http_www_google_.url().host(), | 1870 EXPECT_EQ(http_www_foo_.url().host(), delegate->changes()[0].first.Domain()); |
| 1886 delegate->changes()[0].first.Domain()); | |
| 1887 EXPECT_TRUE(delegate->changes()[0].second); | 1871 EXPECT_TRUE(delegate->changes()[0].second); |
| 1888 EXPECT_EQ("C", delegate->changes()[0].first.Name()); | 1872 EXPECT_EQ("C", delegate->changes()[0].first.Name()); |
| 1889 EXPECT_EQ("D", delegate->changes()[0].first.Value()); | 1873 EXPECT_EQ("D", delegate->changes()[0].first.Value()); |
| 1890 delegate->reset(); | 1874 delegate->reset(); |
| 1891 | 1875 |
| 1892 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E")); | 1876 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E")); |
| 1893 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_google_.url())); | 1877 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), http_www_foo_.url())); |
| 1894 EXPECT_EQ(0u, delegate->changes().size()); | 1878 EXPECT_EQ(0u, delegate->changes().size()); |
| 1895 | 1879 |
| 1896 // Insert a cookie "a" for path "/path1" | 1880 // Insert a cookie "a" for path "/path1" |
| 1897 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 1881 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), |
| 1898 "a=val1; path=/path1; " | 1882 "a=val1; path=/path1; " |
| 1899 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1883 "expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1900 ASSERT_EQ(1u, store->commands().size()); | 1884 ASSERT_EQ(1u, store->commands().size()); |
| 1901 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1885 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1902 ASSERT_EQ(1u, delegate->changes().size()); | 1886 ASSERT_EQ(1u, delegate->changes().size()); |
| 1903 EXPECT_FALSE(delegate->changes()[0].second); | 1887 EXPECT_FALSE(delegate->changes()[0].second); |
| 1904 EXPECT_EQ(http_www_google_.url().host(), | 1888 EXPECT_EQ(http_www_foo_.url().host(), delegate->changes()[0].first.Domain()); |
| 1905 delegate->changes()[0].first.Domain()); | |
| 1906 EXPECT_EQ("a", delegate->changes()[0].first.Name()); | 1889 EXPECT_EQ("a", delegate->changes()[0].first.Name()); |
| 1907 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 1890 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1908 delegate->reset(); | 1891 delegate->reset(); |
| 1909 | 1892 |
| 1910 // Insert a cookie "a" for path "/path1", that is httponly. This should | 1893 // Insert a cookie "a" for path "/path1", that is httponly. This should |
| 1911 // overwrite the non-http-only version. | 1894 // overwrite the non-http-only version. |
| 1912 CookieOptions allow_httponly; | 1895 CookieOptions allow_httponly; |
| 1913 allow_httponly.set_include_httponly(); | 1896 allow_httponly.set_include_httponly(); |
| 1914 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1897 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), |
| 1915 "a=val2; path=/path1; httponly; " | 1898 "a=val2; path=/path1; httponly; " |
| 1916 "expires=Mon, 18-Apr-22 22:50:14 GMT", | 1899 "expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1917 allow_httponly)); | 1900 allow_httponly)); |
| 1918 ASSERT_EQ(3u, store->commands().size()); | 1901 ASSERT_EQ(3u, store->commands().size()); |
| 1919 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1902 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1920 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 1903 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 1921 ASSERT_EQ(2u, delegate->changes().size()); | 1904 ASSERT_EQ(2u, delegate->changes().size()); |
| 1922 EXPECT_EQ(http_www_google_.url().host(), | 1905 EXPECT_EQ(http_www_foo_.url().host(), delegate->changes()[0].first.Domain()); |
| 1923 delegate->changes()[0].first.Domain()); | |
| 1924 EXPECT_TRUE(delegate->changes()[0].second); | 1906 EXPECT_TRUE(delegate->changes()[0].second); |
| 1925 EXPECT_EQ("a", delegate->changes()[0].first.Name()); | 1907 EXPECT_EQ("a", delegate->changes()[0].first.Name()); |
| 1926 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 1908 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1927 EXPECT_EQ(http_www_google_.url().host(), | 1909 EXPECT_EQ(http_www_foo_.url().host(), delegate->changes()[1].first.Domain()); |
| 1928 delegate->changes()[1].first.Domain()); | |
| 1929 EXPECT_FALSE(delegate->changes()[1].second); | 1910 EXPECT_FALSE(delegate->changes()[1].second); |
| 1930 EXPECT_EQ("a", delegate->changes()[1].first.Name()); | 1911 EXPECT_EQ("a", delegate->changes()[1].first.Name()); |
| 1931 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); | 1912 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); |
| 1932 delegate->reset(); | 1913 delegate->reset(); |
| 1933 } | 1914 } |
| 1934 | 1915 |
| 1935 TEST_F(CookieMonsterTest, PredicateSeesAllCookies) { | 1916 TEST_F(CookieMonsterTest, PredicateSeesAllCookies) { |
| 1936 const std::string kTrueValue = "A"; | 1917 const std::string kTrueValue = "A"; |
| 1937 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1918 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1938 // We test that we can see all cookies with our predicated. This includes | 1919 // We test that we can see all cookies with our predicated. This includes |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1960 // Add in three cookies through every public interface to the | 1941 // Add in three cookies through every public interface to the |
| 1961 // CookieMonster and confirm that none of them have duplicate | 1942 // CookieMonster and confirm that none of them have duplicate |
| 1962 // creation times. | 1943 // creation times. |
| 1963 | 1944 |
| 1964 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions | 1945 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions |
| 1965 // are not included as they aren't going to be public for very much | 1946 // are not included as they aren't going to be public for very much |
| 1966 // longer. | 1947 // longer. |
| 1967 | 1948 |
| 1968 // SetCookie, SetCookieWithOptions, SetCookieWithDetails | 1949 // SetCookie, SetCookieWithOptions, SetCookieWithDetails |
| 1969 | 1950 |
| 1970 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie1=A")); | 1951 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "SetCookie1=A")); |
| 1971 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie2=A")); | 1952 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "SetCookie2=A")); |
| 1972 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "SetCookie3=A")); | 1953 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "SetCookie3=A")); |
| 1973 | 1954 |
| 1974 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1955 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), |
| 1975 "setCookieWithOptions1=A", options)); | 1956 "setCookieWithOptions1=A", options)); |
| 1976 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1957 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), |
| 1977 "setCookieWithOptions2=A", options)); | 1958 "setCookieWithOptions2=A", options)); |
| 1978 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1959 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_foo_.url(), |
| 1979 "setCookieWithOptions3=A", options)); | 1960 "setCookieWithOptions3=A", options)); |
| 1980 | 1961 |
| 1981 EXPECT_TRUE(SetCookieWithDetails( | 1962 EXPECT_TRUE(SetCookieWithDetails( |
| 1982 cm.get(), http_www_google_.url(), "setCookieWithDetails1", "A", | 1963 cm.get(), http_www_foo_.url(), "setCookieWithDetails1", "A", |
| 1983 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, | 1964 http_www_foo_.Format(".%D"), "/", Time(), Time(), Time(), false, false, |
| 1984 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 1965 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 1985 EXPECT_TRUE(SetCookieWithDetails( | 1966 EXPECT_TRUE(SetCookieWithDetails( |
| 1986 cm.get(), http_www_google_.url(), "setCookieWithDetails2", "A", | 1967 cm.get(), http_www_foo_.url(), "setCookieWithDetails2", "A", |
| 1987 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, | 1968 http_www_foo_.Format(".%D"), "/", Time(), Time(), Time(), false, false, |
| 1988 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 1969 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 1989 EXPECT_TRUE(SetCookieWithDetails( | 1970 EXPECT_TRUE(SetCookieWithDetails( |
| 1990 cm.get(), http_www_google_.url(), "setCookieWithDetails3", "A", | 1971 cm.get(), http_www_foo_.url(), "setCookieWithDetails3", "A", |
| 1991 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, | 1972 http_www_foo_.Format(".%D"), "/", Time(), Time(), Time(), false, false, |
| 1992 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 1973 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 1993 | 1974 |
| 1994 // Now we check | 1975 // Now we check |
| 1995 CookieList cookie_list(GetAllCookies(cm.get())); | 1976 CookieList cookie_list(GetAllCookies(cm.get())); |
| 1996 EXPECT_EQ(9u, cookie_list.size()); | 1977 EXPECT_EQ(9u, cookie_list.size()); |
| 1997 typedef std::map<int64_t, CanonicalCookie> TimeCookieMap; | 1978 typedef std::map<int64_t, CanonicalCookie> TimeCookieMap; |
| 1998 TimeCookieMap check_map; | 1979 TimeCookieMap check_map; |
| 1999 for (CookieList::const_iterator it = cookie_list.begin(); | 1980 for (CookieList::const_iterator it = cookie_list.begin(); |
| 2000 it != cookie_list.end(); it++) { | 1981 it != cookie_list.end(); it++) { |
| 2001 const int64_t creation_date = it->CreationDate().ToInternalValue(); | 1982 const int64_t creation_date = it->CreationDate().ToInternalValue(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2013 } | 1994 } |
| 2014 } | 1995 } |
| 2015 } | 1996 } |
| 2016 | 1997 |
| 2017 // Mainly a test of GetEffectiveDomain, or more specifically, of the | 1998 // Mainly a test of GetEffectiveDomain, or more specifically, of the |
| 2018 // expected behavior of GetEffectiveDomain within the CookieMonster. | 1999 // expected behavior of GetEffectiveDomain within the CookieMonster. |
| 2019 TEST_F(CookieMonsterTest, GetKey) { | 2000 TEST_F(CookieMonsterTest, GetKey) { |
| 2020 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2001 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2021 | 2002 |
| 2022 // This test is really only interesting if GetKey() actually does something. | 2003 // This test is really only interesting if GetKey() actually does something. |
| 2023 EXPECT_EQ("google.com", cm->GetKey("www.google.com")); | 2004 EXPECT_EQ("foo.com", cm->GetKey("www.foo.com")); |
| 2024 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); | 2005 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); |
| 2025 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); | 2006 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); |
| 2026 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); | 2007 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); |
| 2027 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); | 2008 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); |
| 2028 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); | 2009 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); |
| 2029 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); | 2010 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); |
| 2030 | 2011 |
| 2031 // Cases where the effective domain is null, so we use the host | 2012 // Cases where the effective domain is null, so we use the host |
| 2032 // as the key. | 2013 // as the key. |
| 2033 EXPECT_EQ("co.uk", cm->GetKey("co.uk")); | 2014 EXPECT_EQ("co.uk", cm->GetKey("co.uk")); |
| 2034 const std::string extension_name("iehocdgbbocmkdidlbnnfbmbinnahbae"); | 2015 const std::string extension_name("iehocdgbbocmkdidlbnnfbmbinnahbae"); |
| 2035 EXPECT_EQ(extension_name, cm->GetKey(extension_name)); | 2016 EXPECT_EQ(extension_name, cm->GetKey(extension_name)); |
| 2036 EXPECT_EQ("com", cm->GetKey("com")); | 2017 EXPECT_EQ("com", cm->GetKey("com")); |
| 2037 EXPECT_EQ("hostalias", cm->GetKey("hostalias")); | 2018 EXPECT_EQ("hostalias", cm->GetKey("hostalias")); |
| 2038 EXPECT_EQ("localhost", cm->GetKey("localhost")); | 2019 EXPECT_EQ("localhost", cm->GetKey("localhost")); |
| 2039 } | 2020 } |
| 2040 | 2021 |
| 2041 // Test that cookies transfer from/to the backing store correctly. | 2022 // Test that cookies transfer from/to the backing store correctly. |
| 2042 TEST_F(CookieMonsterTest, BackingStoreCommunication) { | 2023 TEST_F(CookieMonsterTest, BackingStoreCommunication) { |
| 2043 // Store details for cookies transforming through the backing store interface. | 2024 // Store details for cookies transforming through the backing store interface. |
| 2044 | 2025 |
| 2045 base::Time current(base::Time::Now()); | 2026 base::Time current(base::Time::Now()); |
| 2046 scoped_refptr<MockSimplePersistentCookieStore> store( | 2027 scoped_refptr<MockSimplePersistentCookieStore> store( |
| 2047 new MockSimplePersistentCookieStore); | 2028 new MockSimplePersistentCookieStore); |
| 2048 base::Time new_access_time; | 2029 base::Time new_access_time; |
| 2049 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); | 2030 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); |
| 2050 | 2031 |
| 2051 const CookiesInputInfo input_info[] = { | 2032 const CookiesInputInfo input_info[] = { |
| 2052 {GURL("http://a.b.google.com"), "a", "1", "", "/path/to/cookie", expires, | 2033 {GURL("http://a.b.foo.com"), "a", "1", "", "/path/to/cookie", expires, |
| 2053 false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, | 2034 false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, |
| 2054 {GURL("https://www.google.com"), "b", "2", ".google.com", | 2035 {GURL("https://www.foo.com"), "b", "2", ".foo.com", "/path/from/cookie", |
| 2055 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), true, true, | 2036 expires + TimeDelta::FromSeconds(10), true, true, |
| 2056 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, | 2037 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, |
| 2057 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", | 2038 {GURL("https://foo.com"), "c", "3", "", "/another/path/to/cookie", |
| 2058 base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false, | 2039 base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false, |
| 2059 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT}}; | 2040 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT}}; |
| 2060 const int INPUT_DELETE = 1; | 2041 const int INPUT_DELETE = 1; |
| 2061 | 2042 |
| 2062 // Create new cookies and flush them to the store. | 2043 // Create new cookies and flush them to the store. |
| 2063 { | 2044 { |
| 2064 std::unique_ptr<CookieMonster> cmout( | 2045 std::unique_ptr<CookieMonster> cmout( |
| 2065 new CookieMonster(store.get(), nullptr)); | 2046 new CookieMonster(store.get(), nullptr)); |
| 2066 for (const CookiesInputInfo* p = input_info; | 2047 for (const CookiesInputInfo* p = input_info; |
| 2067 p < &input_info[arraysize(input_info)]; p++) { | 2048 p < &input_info[arraysize(input_info)]; p++) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2104 output->ExpiryDate().ToInternalValue()); | 2085 output->ExpiryDate().ToInternalValue()); |
| 2105 } | 2086 } |
| 2106 } | 2087 } |
| 2107 } | 2088 } |
| 2108 | 2089 |
| 2109 TEST_F(CookieMonsterTest, CookieListOrdering) { | 2090 TEST_F(CookieMonsterTest, CookieListOrdering) { |
| 2110 // Put a random set of cookies into a monster and make sure | 2091 // Put a random set of cookies into a monster and make sure |
| 2111 // they're returned in the right order. | 2092 // they're returned in the right order. |
| 2112 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2093 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2113 EXPECT_TRUE( | 2094 EXPECT_TRUE( |
| 2114 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); | 2095 SetCookie(cm.get(), GURL("http://d.c.b.a.foo.com/aa/x.html"), "c=1")); |
| 2115 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 2096 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.foo.com/aa/bb/cc/x.html"), |
| 2116 "d=1; domain=b.a.google.com")); | 2097 "d=1; domain=b.a.foo.com")); |
| 2117 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 2098 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.foo.com/aa/bb/cc/x.html"), |
| 2118 "a=4; domain=b.a.google.com")); | 2099 "a=4; domain=b.a.foo.com")); |
| 2119 EXPECT_TRUE(SetCookie(cm.get(), | 2100 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://c.b.a.foo.com/aa/bb/cc/x.html"), |
| 2120 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 2101 "e=1; domain=c.b.a.foo.com")); |
| 2121 "e=1; domain=c.b.a.google.com")); | 2102 EXPECT_TRUE( |
| 2122 EXPECT_TRUE(SetCookie(cm.get(), | 2103 SetCookie(cm.get(), GURL("http://d.c.b.a.foo.com/aa/bb/x.html"), "b=1")); |
| 2123 GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1")); | |
| 2124 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), | 2104 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), |
| 2125 "g=10")); | 2105 "g=10")); |
| 2126 { | 2106 { |
| 2127 unsigned int i = 0; | 2107 unsigned int i = 0; |
| 2128 CookieList cookies(GetAllCookiesForURL( | 2108 CookieList cookies(GetAllCookiesForURL( |
| 2129 cm.get(), GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); | 2109 cm.get(), GURL("http://d.c.b.a.foo.com/aa/bb/cc/dd"))); |
| 2130 ASSERT_EQ(5u, cookies.size()); | 2110 ASSERT_EQ(5u, cookies.size()); |
| 2131 EXPECT_EQ("d", cookies[i++].Name()); | 2111 EXPECT_EQ("d", cookies[i++].Name()); |
| 2132 EXPECT_EQ("a", cookies[i++].Name()); | 2112 EXPECT_EQ("a", cookies[i++].Name()); |
| 2133 EXPECT_EQ("e", cookies[i++].Name()); | 2113 EXPECT_EQ("e", cookies[i++].Name()); |
| 2134 EXPECT_EQ("b", cookies[i++].Name()); | 2114 EXPECT_EQ("b", cookies[i++].Name()); |
| 2135 EXPECT_EQ("c", cookies[i++].Name()); | 2115 EXPECT_EQ("c", cookies[i++].Name()); |
| 2136 } | 2116 } |
| 2137 | 2117 |
| 2138 { | 2118 { |
| 2139 unsigned int i = 0; | 2119 unsigned int i = 0; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2571 base::RunLoop().RunUntilIdle(); | 2551 base::RunLoop().RunUntilIdle(); |
| 2572 | 2552 |
| 2573 EXPECT_EQ(1, channel_id_store->flush_count()); | 2553 EXPECT_EQ(1, channel_id_store->flush_count()); |
| 2574 } | 2554 } |
| 2575 | 2555 |
| 2576 TEST_F(CookieMonsterTest, SetAllCookies) { | 2556 TEST_F(CookieMonsterTest, SetAllCookies) { |
| 2577 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2557 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2578 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2558 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2579 cm->SetPersistSessionCookies(true); | 2559 cm->SetPersistSessionCookies(true); |
| 2580 | 2560 |
| 2581 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2561 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "U=V; path=/")); |
| 2582 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2562 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "W=X; path=/foo")); |
| 2583 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2563 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "Y=Z; path=/")); |
| 2584 | 2564 |
| 2585 CookieList list; | 2565 CookieList list; |
| 2586 list.push_back(CanonicalCookie( | 2566 list.push_back(CanonicalCookie( |
| 2587 "A", "B", "." + http_www_google_.url().host(), "/", base::Time::Now(), | 2567 "A", "B", "." + http_www_foo_.url().host(), "/", base::Time::Now(), |
| 2588 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2568 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2589 COOKIE_PRIORITY_DEFAULT)); | 2569 COOKIE_PRIORITY_DEFAULT)); |
| 2590 list.push_back(CanonicalCookie( | 2570 list.push_back(CanonicalCookie( |
| 2591 "W", "X", "." + http_www_google_.url().host(), "/bar", base::Time::Now(), | 2571 "W", "X", "." + http_www_foo_.url().host(), "/bar", base::Time::Now(), |
| 2592 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2572 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2593 COOKIE_PRIORITY_DEFAULT)); | 2573 COOKIE_PRIORITY_DEFAULT)); |
| 2594 list.push_back(CanonicalCookie( | 2574 list.push_back(CanonicalCookie( |
| 2595 "Y", "Z", "." + http_www_google_.url().host(), "/", base::Time::Now(), | 2575 "Y", "Z", "." + http_www_foo_.url().host(), "/", base::Time::Now(), |
| 2596 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2576 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2597 COOKIE_PRIORITY_DEFAULT)); | 2577 COOKIE_PRIORITY_DEFAULT)); |
| 2598 | 2578 |
| 2599 // SetAllCookies must not flush. | 2579 // SetAllCookies must not flush. |
| 2600 ASSERT_EQ(0, store->flush_count()); | 2580 ASSERT_EQ(0, store->flush_count()); |
| 2601 EXPECT_TRUE(SetAllCookies(cm.get(), list)); | 2581 EXPECT_TRUE(SetAllCookies(cm.get(), list)); |
| 2602 EXPECT_EQ(0, store->flush_count()); | 2582 EXPECT_EQ(0, store->flush_count()); |
| 2603 | 2583 |
| 2604 CookieList cookies = GetAllCookies(cm.get()); | 2584 CookieList cookies = GetAllCookies(cm.get()); |
| 2605 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. | 2585 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2620 EXPECT_EQ("Z", it->Value()); | 2600 EXPECT_EQ("Z", it->Value()); |
| 2621 } | 2601 } |
| 2622 | 2602 |
| 2623 TEST_F(CookieMonsterTest, ComputeCookieDiff) { | 2603 TEST_F(CookieMonsterTest, ComputeCookieDiff) { |
| 2624 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2604 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2625 | 2605 |
| 2626 base::Time now = base::Time::Now(); | 2606 base::Time now = base::Time::Now(); |
| 2627 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); | 2607 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); |
| 2628 | 2608 |
| 2629 std::unique_ptr<CanonicalCookie> cookie1(base::MakeUnique<CanonicalCookie>( | 2609 std::unique_ptr<CanonicalCookie> cookie1(base::MakeUnique<CanonicalCookie>( |
| 2630 "A", "B", "." + http_www_google_.url().host(), "/", creation_time, | 2610 "A", "B", "." + http_www_foo_.url().host(), "/", creation_time, |
| 2631 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2611 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2632 COOKIE_PRIORITY_DEFAULT)); | 2612 COOKIE_PRIORITY_DEFAULT)); |
| 2633 std::unique_ptr<CanonicalCookie> cookie2(base::MakeUnique<CanonicalCookie>( | 2613 std::unique_ptr<CanonicalCookie> cookie2(base::MakeUnique<CanonicalCookie>( |
| 2634 "C", "D", "." + http_www_google_.url().host(), "/", creation_time, | 2614 "C", "D", "." + http_www_foo_.url().host(), "/", creation_time, |
| 2635 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2615 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2636 COOKIE_PRIORITY_DEFAULT)); | 2616 COOKIE_PRIORITY_DEFAULT)); |
| 2637 std::unique_ptr<CanonicalCookie> cookie3(base::MakeUnique<CanonicalCookie>( | 2617 std::unique_ptr<CanonicalCookie> cookie3(base::MakeUnique<CanonicalCookie>( |
| 2638 "E", "F", "." + http_www_google_.url().host(), "/", creation_time, | 2618 "E", "F", "." + http_www_foo_.url().host(), "/", creation_time, |
| 2639 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2619 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2640 COOKIE_PRIORITY_DEFAULT)); | 2620 COOKIE_PRIORITY_DEFAULT)); |
| 2641 std::unique_ptr<CanonicalCookie> cookie4(base::MakeUnique<CanonicalCookie>( | 2621 std::unique_ptr<CanonicalCookie> cookie4(base::MakeUnique<CanonicalCookie>( |
| 2642 "G", "H", "." + http_www_google_.url().host(), "/", creation_time, | 2622 "G", "H", "." + http_www_foo_.url().host(), "/", creation_time, |
| 2643 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2623 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2644 COOKIE_PRIORITY_DEFAULT)); | 2624 COOKIE_PRIORITY_DEFAULT)); |
| 2645 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( | 2625 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( |
| 2646 base::MakeUnique<CanonicalCookie>( | 2626 base::MakeUnique<CanonicalCookie>( |
| 2647 "G", "iamnew", "." + http_www_google_.url().host(), "/", | 2627 "G", "iamnew", "." + http_www_foo_.url().host(), "/", creation_time, |
| 2648 creation_time, base::Time(), base::Time(), false, false, | 2628 base::Time(), base::Time(), false, false, |
| 2649 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2629 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2650 std::unique_ptr<CanonicalCookie> cookie5(base::MakeUnique<CanonicalCookie>( | 2630 std::unique_ptr<CanonicalCookie> cookie5(base::MakeUnique<CanonicalCookie>( |
| 2651 "I", "J", "." + http_www_google_.url().host(), "/", creation_time, | 2631 "I", "J", "." + http_www_foo_.url().host(), "/", creation_time, |
| 2652 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2632 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2653 COOKIE_PRIORITY_DEFAULT)); | 2633 COOKIE_PRIORITY_DEFAULT)); |
| 2654 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( | 2634 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( |
| 2655 base::MakeUnique<CanonicalCookie>( | 2635 base::MakeUnique<CanonicalCookie>( |
| 2656 "I", "J", "." + http_www_google_.url().host(), "/", now, base::Time(), | 2636 "I", "J", "." + http_www_foo_.url().host(), "/", now, base::Time(), |
| 2657 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2637 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2658 COOKIE_PRIORITY_DEFAULT)); | 2638 COOKIE_PRIORITY_DEFAULT)); |
| 2659 std::unique_ptr<CanonicalCookie> cookie6(base::MakeUnique<CanonicalCookie>( | 2639 std::unique_ptr<CanonicalCookie> cookie6(base::MakeUnique<CanonicalCookie>( |
| 2660 "K", "L", "." + http_www_google_.url().host(), "/foo", creation_time, | 2640 "K", "L", "." + http_www_foo_.url().host(), "/foo", creation_time, |
| 2661 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2641 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2662 COOKIE_PRIORITY_DEFAULT)); | 2642 COOKIE_PRIORITY_DEFAULT)); |
| 2663 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( | 2643 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( |
| 2664 base::MakeUnique<CanonicalCookie>( | 2644 base::MakeUnique<CanonicalCookie>( |
| 2665 "K", "L", "." + http_www_google_.url().host(), "/bar", creation_time, | 2645 "K", "L", "." + http_www_foo_.url().host(), "/bar", creation_time, |
| 2666 base::Time(), base::Time(), false, false, | 2646 base::Time(), base::Time(), false, false, |
| 2667 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2647 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2668 std::unique_ptr<CanonicalCookie> cookie7(base::MakeUnique<CanonicalCookie>( | 2648 std::unique_ptr<CanonicalCookie> cookie7(base::MakeUnique<CanonicalCookie>( |
| 2669 "M", "N", "." + http_www_google_.url().host(), "/foo", creation_time, | 2649 "M", "N", "." + http_www_foo_.url().host(), "/foo", creation_time, |
| 2670 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2650 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2671 COOKIE_PRIORITY_DEFAULT)); | 2651 COOKIE_PRIORITY_DEFAULT)); |
| 2672 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( | 2652 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( |
| 2673 base::MakeUnique<CanonicalCookie>( | 2653 base::MakeUnique<CanonicalCookie>( |
| 2674 "M", "N", "." + http_www_google_.url().host(), "/bar", creation_time, | 2654 "M", "N", "." + http_www_foo_.url().host(), "/bar", creation_time, |
| 2675 base::Time(), base::Time(), false, false, | 2655 base::Time(), base::Time(), false, false, |
| 2676 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2656 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2677 | 2657 |
| 2678 CookieList old_cookies; | 2658 CookieList old_cookies; |
| 2679 old_cookies.push_back(*cookie1); | 2659 old_cookies.push_back(*cookie1); |
| 2680 old_cookies.push_back(*cookie2); | 2660 old_cookies.push_back(*cookie2); |
| 2681 old_cookies.push_back(*cookie4); | 2661 old_cookies.push_back(*cookie4); |
| 2682 old_cookies.push_back(*cookie5); | 2662 old_cookies.push_back(*cookie5); |
| 2683 old_cookies.push_back(*cookie6); | 2663 old_cookies.push_back(*cookie6); |
| 2684 old_cookies.push_back(*cookie7); | 2664 old_cookies.push_back(*cookie7); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2739 EXPECT_FALSE(IsCookieInList(*cookie7_with_new_path, cookies_to_delete)); | 2719 EXPECT_FALSE(IsCookieInList(*cookie7_with_new_path, cookies_to_delete)); |
| 2740 } | 2720 } |
| 2741 | 2721 |
| 2742 // Check that DeleteAll does flush (as a sanity check that flush_count() | 2722 // Check that DeleteAll does flush (as a sanity check that flush_count() |
| 2743 // works). | 2723 // works). |
| 2744 TEST_F(CookieMonsterTest, DeleteAll) { | 2724 TEST_F(CookieMonsterTest, DeleteAll) { |
| 2745 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2725 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2746 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2726 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2747 cm->SetPersistSessionCookies(true); | 2727 cm->SetPersistSessionCookies(true); |
| 2748 | 2728 |
| 2749 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/")); | 2729 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "X=Y; path=/")); |
| 2750 | 2730 |
| 2751 ASSERT_EQ(0, store->flush_count()); | 2731 ASSERT_EQ(0, store->flush_count()); |
| 2752 EXPECT_EQ(1, DeleteAll(cm.get())); | 2732 EXPECT_EQ(1, DeleteAll(cm.get())); |
| 2753 EXPECT_EQ(1, store->flush_count()); | 2733 EXPECT_EQ(1, store->flush_count()); |
| 2754 } | 2734 } |
| 2755 | 2735 |
| 2756 TEST_F(CookieMonsterTest, HistogramCheck) { | 2736 TEST_F(CookieMonsterTest, HistogramCheck) { |
| 2757 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2737 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2758 // Should match call in InitializeHistograms, but doesn't really matter | 2738 // Should match call in InitializeHistograms, but doesn't really matter |
| 2759 // since the histogram should have been initialized by the CM construction | 2739 // since the histogram should have been initialized by the CM construction |
| 2760 // above. | 2740 // above. |
| 2761 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( | 2741 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( |
| 2762 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2742 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
| 2763 base::Histogram::kUmaTargetedHistogramFlag); | 2743 base::Histogram::kUmaTargetedHistogramFlag); |
| 2764 | 2744 |
| 2765 std::unique_ptr<base::HistogramSamples> samples1( | 2745 std::unique_ptr<base::HistogramSamples> samples1( |
| 2766 expired_histogram->SnapshotSamples()); | 2746 expired_histogram->SnapshotSamples()); |
| 2767 ASSERT_TRUE(SetCookieWithDetails( | 2747 ASSERT_TRUE(SetCookieWithDetails( |
| 2768 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", base::Time(), | 2748 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", base::Time(), |
| 2769 base::Time::Now() + base::TimeDelta::FromMinutes(59), base::Time(), false, | 2749 base::Time::Now() + base::TimeDelta::FromMinutes(59), base::Time(), false, |
| 2770 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2750 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2771 | 2751 |
| 2772 std::unique_ptr<base::HistogramSamples> samples2( | 2752 std::unique_ptr<base::HistogramSamples> samples2( |
| 2773 expired_histogram->SnapshotSamples()); | 2753 expired_histogram->SnapshotSamples()); |
| 2774 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); | 2754 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); |
| 2775 | 2755 |
| 2776 // kValidCookieLine creates a session cookie. | 2756 // kValidCookieLine creates a session cookie. |
| 2777 ASSERT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); | 2757 ASSERT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), kValidCookieLine)); |
| 2778 | 2758 |
| 2779 std::unique_ptr<base::HistogramSamples> samples3( | 2759 std::unique_ptr<base::HistogramSamples> samples3( |
| 2780 expired_histogram->SnapshotSamples()); | 2760 expired_histogram->SnapshotSamples()); |
| 2781 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); | 2761 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); |
| 2782 } | 2762 } |
| 2783 | 2763 |
| 2784 TEST_F(CookieMonsterTest, InvalidExpiryTime) { | 2764 TEST_F(CookieMonsterTest, InvalidExpiryTime) { |
| 2785 std::string cookie_line = | 2765 std::string cookie_line = |
| 2786 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; | 2766 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |
| 2787 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 2767 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
| 2788 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); | 2768 http_www_foo_.url(), cookie_line, Time::Now(), CookieOptions())); |
| 2789 ASSERT_FALSE(cookie->IsPersistent()); | 2769 ASSERT_FALSE(cookie->IsPersistent()); |
| 2790 } | 2770 } |
| 2791 | 2771 |
| 2792 // Test that CookieMonster writes session cookies into the underlying | 2772 // Test that CookieMonster writes session cookies into the underlying |
| 2793 // CookieStore if the "persist session cookies" option is on. | 2773 // CookieStore if the "persist session cookies" option is on. |
| 2794 TEST_F(CookieMonsterTest, PersistSessionCookies) { | 2774 TEST_F(CookieMonsterTest, PersistSessionCookies) { |
| 2795 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2775 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2796 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2776 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2797 cm->SetPersistSessionCookies(true); | 2777 cm->SetPersistSessionCookies(true); |
| 2798 | 2778 |
| 2799 // All cookies set with SetCookie are session cookies. | 2779 // All cookies set with SetCookie are session cookies. |
| 2800 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 2780 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=B")); |
| 2801 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2781 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_foo_.url())); |
| 2802 | 2782 |
| 2803 // The cookie was written to the backing store. | 2783 // The cookie was written to the backing store. |
| 2804 EXPECT_EQ(1u, store->commands().size()); | 2784 EXPECT_EQ(1u, store->commands().size()); |
| 2805 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2785 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 2806 EXPECT_EQ("A", store->commands()[0].cookie.Name()); | 2786 EXPECT_EQ("A", store->commands()[0].cookie.Name()); |
| 2807 EXPECT_EQ("B", store->commands()[0].cookie.Value()); | 2787 EXPECT_EQ("B", store->commands()[0].cookie.Value()); |
| 2808 | 2788 |
| 2809 // Modify the cookie. | 2789 // Modify the cookie. |
| 2810 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=C")); | 2790 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=C")); |
| 2811 EXPECT_EQ("A=C", GetCookies(cm.get(), http_www_google_.url())); | 2791 EXPECT_EQ("A=C", GetCookies(cm.get(), http_www_foo_.url())); |
| 2812 EXPECT_EQ(3u, store->commands().size()); | 2792 EXPECT_EQ(3u, store->commands().size()); |
| 2813 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 2793 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 2814 EXPECT_EQ("A", store->commands()[1].cookie.Name()); | 2794 EXPECT_EQ("A", store->commands()[1].cookie.Name()); |
| 2815 EXPECT_EQ("B", store->commands()[1].cookie.Value()); | 2795 EXPECT_EQ("B", store->commands()[1].cookie.Value()); |
| 2816 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 2796 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 2817 EXPECT_EQ("A", store->commands()[2].cookie.Name()); | 2797 EXPECT_EQ("A", store->commands()[2].cookie.Name()); |
| 2818 EXPECT_EQ("C", store->commands()[2].cookie.Value()); | 2798 EXPECT_EQ("C", store->commands()[2].cookie.Value()); |
| 2819 | 2799 |
| 2820 // Delete the cookie. | 2800 // Delete the cookie. |
| 2821 DeleteCookie(cm.get(), http_www_google_.url(), "A"); | 2801 DeleteCookie(cm.get(), http_www_foo_.url(), "A"); |
| 2822 EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url())); | 2802 EXPECT_EQ("", GetCookies(cm.get(), http_www_foo_.url())); |
| 2823 EXPECT_EQ(4u, store->commands().size()); | 2803 EXPECT_EQ(4u, store->commands().size()); |
| 2824 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2804 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 2825 EXPECT_EQ("A", store->commands()[3].cookie.Name()); | 2805 EXPECT_EQ("A", store->commands()[3].cookie.Name()); |
| 2826 EXPECT_EQ("C", store->commands()[3].cookie.Value()); | 2806 EXPECT_EQ("C", store->commands()[3].cookie.Value()); |
| 2827 } | 2807 } |
| 2828 | 2808 |
| 2829 // Test the commands sent to the persistent cookie store. | 2809 // Test the commands sent to the persistent cookie store. |
| 2830 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { | 2810 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { |
| 2831 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2811 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2832 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2812 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2833 | 2813 |
| 2834 // Add a cookie. | 2814 // Add a cookie. |
| 2835 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 2815 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), |
| 2836 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2816 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 2837 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2817 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_foo_.url())); |
| 2838 ASSERT_EQ(1u, store->commands().size()); | 2818 ASSERT_EQ(1u, store->commands().size()); |
| 2839 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2819 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 2840 // Remove it. | 2820 // Remove it. |
| 2841 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0")); | 2821 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=B; max-age=0")); |
| 2842 this->MatchCookieLines(std::string(), | 2822 this->MatchCookieLines(std::string(), |
| 2843 GetCookies(cm.get(), http_www_google_.url())); | 2823 GetCookies(cm.get(), http_www_foo_.url())); |
| 2844 ASSERT_EQ(2u, store->commands().size()); | 2824 ASSERT_EQ(2u, store->commands().size()); |
| 2845 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 2825 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 2846 | 2826 |
| 2847 // Add a cookie. | 2827 // Add a cookie. |
| 2848 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 2828 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), |
| 2849 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2829 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 2850 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2830 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_foo_.url())); |
| 2851 ASSERT_EQ(3u, store->commands().size()); | 2831 ASSERT_EQ(3u, store->commands().size()); |
| 2852 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 2832 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 2853 // Overwrite it. | 2833 // Overwrite it. |
| 2854 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 2834 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), |
| 2855 "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT")); | 2835 "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 2856 this->MatchCookieLines("A=Foo", GetCookies(cm.get(), http_www_google_.url())); | 2836 this->MatchCookieLines("A=Foo", GetCookies(cm.get(), http_www_foo_.url())); |
| 2857 ASSERT_EQ(5u, store->commands().size()); | 2837 ASSERT_EQ(5u, store->commands().size()); |
| 2858 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2838 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 2859 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); | 2839 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
| 2860 | 2840 |
| 2861 // Create some non-persistent cookies and check that they don't go to the | 2841 // Create some non-persistent cookies and check that they don't go to the |
| 2862 // persistent storage. | 2842 // persistent storage. |
| 2863 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=Bar")); | 2843 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=Bar")); |
| 2864 this->MatchCookieLines("A=Foo; B=Bar", | 2844 this->MatchCookieLines("A=Foo; B=Bar", |
| 2865 GetCookies(cm.get(), http_www_google_.url())); | 2845 GetCookies(cm.get(), http_www_foo_.url())); |
| 2866 EXPECT_EQ(5u, store->commands().size()); | 2846 EXPECT_EQ(5u, store->commands().size()); |
| 2867 } | 2847 } |
| 2868 | 2848 |
| 2869 // Test to assure that cookies with control characters are purged appropriately. | 2849 // Test to assure that cookies with control characters are purged appropriately. |
| 2870 // See http://crbug.com/238041 for background. | 2850 // See http://crbug.com/238041 for background. |
| 2871 TEST_F(CookieMonsterTest, ControlCharacterPurge) { | 2851 TEST_F(CookieMonsterTest, ControlCharacterPurge) { |
| 2872 const Time now1(Time::Now()); | 2852 const Time now1(Time::Now()); |
| 2873 const Time now2(Time::Now() + TimeDelta::FromSeconds(1)); | 2853 const Time now2(Time::Now() + TimeDelta::FromSeconds(1)); |
| 2874 const Time now3(Time::Now() + TimeDelta::FromSeconds(2)); | 2854 const Time now3(Time::Now() + TimeDelta::FromSeconds(2)); |
| 2875 const Time later(now1 + TimeDelta::FromDays(1)); | 2855 const Time later(now1 + TimeDelta::FromDays(1)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2907 TEST_F(CookieMonsterTest, CookieSourceHistogram) { | 2887 TEST_F(CookieMonsterTest, CookieSourceHistogram) { |
| 2908 base::HistogramTester histograms; | 2888 base::HistogramTester histograms; |
| 2909 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; | 2889 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; |
| 2910 | 2890 |
| 2911 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2891 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2912 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2892 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2913 | 2893 |
| 2914 histograms.ExpectTotalCount(cookie_source_histogram, 0); | 2894 histograms.ExpectTotalCount(cookie_source_histogram, 0); |
| 2915 | 2895 |
| 2916 // Set a secure cookie on a cryptographic scheme. | 2896 // Set a secure cookie on a cryptographic scheme. |
| 2917 EXPECT_TRUE( | 2897 EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), "A=B; path=/; Secure")); |
| 2918 SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure")); | |
| 2919 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2898 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2920 histograms.ExpectBucketCount( | 2899 histograms.ExpectBucketCount( |
| 2921 cookie_source_histogram, | 2900 cookie_source_histogram, |
| 2922 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2901 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
| 2923 | 2902 |
| 2924 // Set a non-secure cookie on a cryptographic scheme. | 2903 // Set a non-secure cookie on a cryptographic scheme. |
| 2925 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "C=D; path=/;")); | 2904 EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), "C=D; path=/;")); |
| 2926 histograms.ExpectTotalCount(cookie_source_histogram, 2); | 2905 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
| 2927 histograms.ExpectBucketCount( | 2906 histograms.ExpectBucketCount( |
| 2928 cookie_source_histogram, | 2907 cookie_source_histogram, |
| 2929 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2908 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
| 2930 | 2909 |
| 2931 // Set a secure cookie on a non-cryptographic scheme. | 2910 // Set a secure cookie on a non-cryptographic scheme. |
| 2932 EXPECT_FALSE( | 2911 EXPECT_FALSE(SetCookie(cm.get(), http_www_foo_.url(), "D=E; path=/; Secure")); |
| 2933 SetCookie(cm.get(), http_www_google_.url(), "D=E; path=/; Secure")); | |
| 2934 histograms.ExpectTotalCount(cookie_source_histogram, 2); | 2912 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
| 2935 histograms.ExpectBucketCount( | 2913 histograms.ExpectBucketCount( |
| 2936 cookie_source_histogram, | 2914 cookie_source_histogram, |
| 2937 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 0); | 2915 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 0); |
| 2938 | 2916 |
| 2939 // Overwrite a secure cookie (set by a cryptographic scheme) on a | 2917 // Overwrite a secure cookie (set by a cryptographic scheme) on a |
| 2940 // non-cryptographic scheme. | 2918 // non-cryptographic scheme. |
| 2941 EXPECT_FALSE( | 2919 EXPECT_FALSE(SetCookie(cm.get(), http_www_foo_.url(), "A=B; path=/; Secure")); |
| 2942 SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/; Secure")); | |
| 2943 histograms.ExpectTotalCount(cookie_source_histogram, 2); | 2920 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
| 2944 histograms.ExpectBucketCount( | 2921 histograms.ExpectBucketCount( |
| 2945 cookie_source_histogram, | 2922 cookie_source_histogram, |
| 2946 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2923 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
| 2947 histograms.ExpectBucketCount( | 2924 histograms.ExpectBucketCount( |
| 2948 cookie_source_histogram, | 2925 cookie_source_histogram, |
| 2949 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 0); | 2926 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 0); |
| 2950 | 2927 |
| 2951 // Test that attempting to clear a secure cookie on a http:// URL does | 2928 // Test that attempting to clear a secure cookie on a http:// URL does |
| 2952 // nothing. | 2929 // nothing. |
| 2953 EXPECT_TRUE( | 2930 EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), "F=G; path=/; Secure")); |
| 2954 SetCookie(cm.get(), https_www_google_.url(), "F=G; path=/; Secure")); | |
| 2955 histograms.ExpectTotalCount(cookie_source_histogram, 3); | 2931 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
| 2956 std::string cookies1 = GetCookies(cm.get(), https_www_google_.url()); | 2932 std::string cookies1 = GetCookies(cm.get(), https_www_foo_.url()); |
| 2957 EXPECT_NE(std::string::npos, cookies1.find("F=G")); | 2933 EXPECT_NE(std::string::npos, cookies1.find("F=G")); |
| 2958 EXPECT_FALSE(SetCookie(cm.get(), http_www_google_.url(), | 2934 EXPECT_FALSE(SetCookie(cm.get(), http_www_foo_.url(), |
| 2959 "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT")); | 2935 "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT")); |
| 2960 std::string cookies2 = GetCookies(cm.get(), https_www_google_.url()); | 2936 std::string cookies2 = GetCookies(cm.get(), https_www_foo_.url()); |
| 2961 EXPECT_NE(std::string::npos, cookies2.find("F=G")); | 2937 EXPECT_NE(std::string::npos, cookies2.find("F=G")); |
| 2962 histograms.ExpectTotalCount(cookie_source_histogram, 3); | 2938 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
| 2963 | 2939 |
| 2964 // Set a non-secure cookie on a non-cryptographic scheme. | 2940 // Set a non-secure cookie on a non-cryptographic scheme. |
| 2965 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/")); | 2941 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "H=I; path=/")); |
| 2966 histograms.ExpectTotalCount(cookie_source_histogram, 4); | 2942 histograms.ExpectTotalCount(cookie_source_histogram, 4); |
| 2967 histograms.ExpectBucketCount( | 2943 histograms.ExpectBucketCount( |
| 2968 cookie_source_histogram, | 2944 cookie_source_histogram, |
| 2969 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2945 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); |
| 2970 } | 2946 } |
| 2971 | 2947 |
| 2972 // Test that cookie delete equivalent histograms are recorded correctly. | 2948 // Test that cookie delete equivalent histograms are recorded correctly. |
| 2973 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { | 2949 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { |
| 2974 base::HistogramTester histograms; | 2950 base::HistogramTester histograms; |
| 2975 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 2951 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
| 2976 | 2952 |
| 2977 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2953 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2978 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2954 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2979 | 2955 |
| 2980 // Set a secure cookie from a secure origin | 2956 // Set a secure cookie from a secure origin |
| 2981 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 2957 EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), "A=B; Secure")); |
| 2982 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2958 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2983 histograms.ExpectBucketCount(cookie_source_histogram, | 2959 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2984 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2960 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2985 1); | 2961 1); |
| 2986 | 2962 |
| 2987 // Set a new cookie with a different name from a variety of origins (including | 2963 // Set a new cookie with a different name from a variety of origins (including |
| 2988 // the same one). | 2964 // the same one). |
| 2989 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "B=A;")); | 2965 EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), "B=A;")); |
| 2990 histograms.ExpectTotalCount(cookie_source_histogram, 2); | 2966 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
| 2991 histograms.ExpectBucketCount(cookie_source_histogram, | 2967 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2992 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2968 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2993 2); | 2969 2); |
| 2994 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=A;")); | 2970 EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "C=A;")); |
| 2995 histograms.ExpectTotalCount(cookie_source_histogram, 3); | 2971 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
| 2996 histograms.ExpectBucketCount(cookie_source_histogram, | 2972 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2997 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2973 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2998 3); | 2974 3); |
| 2999 | 2975 |
| 3000 // Set a non-secure cookie from an insecure origin that matches the name of an | 2976 // Set a non-secure cookie from an insecure origin that matches the name of an |
| 3001 // already existing cookie and additionally is equivalent to the existing | 2977 // already existing cookie and additionally is equivalent to the existing |
| 3002 // cookie. This should fail since it's trying to overwrite a secure cookie. | 2978 // cookie. This should fail since it's trying to overwrite a secure cookie. |
| 3003 EXPECT_FALSE(SetCookie(cm.get(), http_www_google_.url(), "A=B;")); | 2979 EXPECT_FALSE(SetCookie(cm.get(), http_www_foo_.url(), "A=B;")); |
| 3004 histograms.ExpectTotalCount(cookie_source_histogram, 6); | 2980 histograms.ExpectTotalCount(cookie_source_histogram, 6); |
| 3005 histograms.ExpectBucketCount(cookie_source_histogram, | 2981 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3006 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2982 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3007 4); | 2983 4); |
| 3008 histograms.ExpectBucketCount(cookie_source_histogram, | 2984 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3009 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, | 2985 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, |
| 3010 0); | 2986 0); |
| 3011 histograms.ExpectBucketCount( | 2987 histograms.ExpectBucketCount( |
| 3012 cookie_source_histogram, | 2988 cookie_source_histogram, |
| 3013 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 1); | 2989 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 1); |
| 3014 histograms.ExpectBucketCount( | 2990 histograms.ExpectBucketCount( |
| 3015 cookie_source_histogram, | 2991 cookie_source_histogram, |
| 3016 CookieMonster::COOKIE_DELETE_EQUIVALENT_WOULD_HAVE_DELETED, 1); | 2992 CookieMonster::COOKIE_DELETE_EQUIVALENT_WOULD_HAVE_DELETED, 1); |
| 3017 | 2993 |
| 3018 // Set a non-secure cookie from an insecure origin that matches the name of an | 2994 // Set a non-secure cookie from an insecure origin that matches the name of an |
| 3019 // already existing cookie but is not equivalent. This should fail since it's | 2995 // already existing cookie but is not equivalent. This should fail since it's |
| 3020 // trying to shadow a secure cookie. | 2996 // trying to shadow a secure cookie. |
| 3021 EXPECT_FALSE( | 2997 EXPECT_FALSE( |
| 3022 SetCookie(cm.get(), http_www_google_.url(), "A=C; path=/some/path")); | 2998 SetCookie(cm.get(), http_www_foo_.url(), "A=C; path=/some/path")); |
| 3023 histograms.ExpectTotalCount(cookie_source_histogram, 8); | 2999 histograms.ExpectTotalCount(cookie_source_histogram, 8); |
| 3024 histograms.ExpectBucketCount(cookie_source_histogram, | 3000 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3025 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3001 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3026 5); | 3002 5); |
| 3027 histograms.ExpectBucketCount( | 3003 histograms.ExpectBucketCount( |
| 3028 cookie_source_histogram, | 3004 cookie_source_histogram, |
| 3029 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 2); | 3005 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 2); |
| 3030 | 3006 |
| 3031 // Set a secure cookie from a secure origin that matches the name of an | 3007 // Set a secure cookie from a secure origin that matches the name of an |
| 3032 // already existing cookies and is equivalent. | 3008 // already existing cookies and is equivalent. |
| 3033 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=D; secure")); | 3009 EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), "A=D; secure")); |
| 3034 histograms.ExpectTotalCount(cookie_source_histogram, 10); | 3010 histograms.ExpectTotalCount(cookie_source_histogram, 10); |
| 3035 histograms.ExpectBucketCount(cookie_source_histogram, | 3011 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3036 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3012 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3037 6); | 3013 6); |
| 3038 histograms.ExpectBucketCount(cookie_source_histogram, | 3014 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3039 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, | 3015 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, |
| 3040 1); | 3016 1); |
| 3041 | 3017 |
| 3042 // Set a secure cookie from a secure origin that matches the name of an | 3018 // Set a secure cookie from a secure origin that matches the name of an |
| 3043 // already existing cookie and is not equivalent. | 3019 // already existing cookie and is not equivalent. |
| 3044 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | 3020 EXPECT_TRUE(SetCookie(cm.get(), https_www_foo_.url(), |
| 3045 "A=E; secure; path=/some/other/path")); | 3021 "A=E; secure; path=/some/other/path")); |
| 3046 histograms.ExpectTotalCount(cookie_source_histogram, 11); | 3022 histograms.ExpectTotalCount(cookie_source_histogram, 11); |
| 3047 histograms.ExpectBucketCount(cookie_source_histogram, | 3023 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3048 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3024 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3049 7); | 3025 7); |
| 3050 } | 3026 } |
| 3051 | 3027 |
| 3052 TEST_F(CookieMonsterTest, SetSecureCookies) { | 3028 TEST_F(CookieMonsterTest, SetSecureCookies) { |
| 3053 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3029 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 3054 GURL http_url("http://www.google.com"); | 3030 GURL http_url("http://www.foo.com"); |
| 3055 GURL http_superdomain_url("http://google.com"); | 3031 GURL http_superdomain_url("http://foo.com"); |
| 3056 GURL https_url("https://www.google.com"); | 3032 GURL https_url("https://www.foo.com"); |
| 3057 | 3033 |
| 3058 // A non-secure cookie can be created from either a URL with a secure or | 3034 // A non-secure cookie can be created from either a URL with a secure or |
| 3059 // insecure scheme. | 3035 // insecure scheme. |
| 3060 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); | 3036 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); |
| 3061 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); | 3037 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); |
| 3062 | 3038 |
| 3063 // A secure cookie cannot be created from a URL with an insecure scheme. | 3039 // A secure cookie cannot be created from a URL with an insecure scheme. |
| 3064 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=B; Secure")); | 3040 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=B; Secure")); |
| 3065 | 3041 |
| 3066 // A secure cookie can be created from a URL with a secure scheme. | 3042 // A secure cookie can be created from a URL with a secure scheme. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3094 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C")); | 3070 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C")); |
| 3095 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/")); | 3071 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/")); |
| 3096 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/your/path")); | 3072 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/your/path")); |
| 3097 EXPECT_FALSE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/my/path")); | 3073 EXPECT_FALSE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/my/path")); |
| 3098 EXPECT_FALSE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/my/path/sub")); | 3074 EXPECT_FALSE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/my/path/sub")); |
| 3099 | 3075 |
| 3100 // If a non-secure cookie is created from a URL with an insecure scheme, and | 3076 // If a non-secure cookie is created from a URL with an insecure scheme, and |
| 3101 // a secure cookie with the same name already exists, if the domain strings | 3077 // a secure cookie with the same name already exists, if the domain strings |
| 3102 // domain-match, do not update the cookie. | 3078 // domain-match, do not update the cookie. |
| 3103 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3079 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 3104 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=C; domain=google.com")); | 3080 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=C; domain=foo.com")); |
| 3105 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=C; domain=www.google.com")); | 3081 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=C; domain=www.foo.com")); |
| 3106 | 3082 |
| 3107 // Since A=B was set above with no domain string, set a different cookie here | 3083 // Since A=B was set above with no domain string, set a different cookie here |
| 3108 // so the insecure examples aren't trying to overwrite the one above. | 3084 // so the insecure examples aren't trying to overwrite the one above. |
| 3109 EXPECT_TRUE(SetCookie(cm.get(), https_url, "B=C; Secure; domain=google.com")); | 3085 EXPECT_TRUE(SetCookie(cm.get(), https_url, "B=C; Secure; domain=foo.com")); |
| 3110 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D; domain=google.com")); | 3086 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D; domain=foo.com")); |
| 3111 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D")); | 3087 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D")); |
| 3112 EXPECT_FALSE(SetCookie(cm.get(), http_superdomain_url, "B=D")); | 3088 EXPECT_FALSE(SetCookie(cm.get(), http_superdomain_url, "B=D")); |
| 3113 | 3089 |
| 3114 // Verify that if an httponly version of the cookie exists, adding a Secure | 3090 // Verify that if an httponly version of the cookie exists, adding a Secure |
| 3115 // version of the cookie still does not overwrite it. | 3091 // version of the cookie still does not overwrite it. |
| 3116 CookieOptions include_httponly; | 3092 CookieOptions include_httponly; |
| 3117 include_httponly.set_include_httponly(); | 3093 include_httponly.set_include_httponly(); |
| 3118 EXPECT_TRUE(SetCookieWithOptions(cm.get(), https_url, "C=D; httponly", | 3094 EXPECT_TRUE(SetCookieWithOptions(cm.get(), https_url, "C=D; httponly", |
| 3119 include_httponly)); | 3095 include_httponly)); |
| 3120 // Note that the lack of an explicit options object below uses the default, | 3096 // Note that the lack of an explicit options object below uses the default, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3247 const CookiesEntry test14[] = {{1U, true}}; | 3223 const CookiesEntry test14[] = {{1U, true}}; |
| 3248 const AltHosts test14_alt_hosts(1500, 1800); | 3224 const AltHosts test14_alt_hosts(1500, 1800); |
| 3249 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, | 3225 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, |
| 3250 &test14_alt_hosts); | 3226 &test14_alt_hosts); |
| 3251 } | 3227 } |
| 3252 | 3228 |
| 3253 // Tests that strict secure cookies doesn't trip equivalent cookie checks | 3229 // Tests that strict secure cookies doesn't trip equivalent cookie checks |
| 3254 // accidentally. Regression test for https://crbug.com/569943. | 3230 // accidentally. Regression test for https://crbug.com/569943. |
| 3255 TEST_F(CookieMonsterTest, EquivalentCookies) { | 3231 TEST_F(CookieMonsterTest, EquivalentCookies) { |
| 3256 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3232 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 3257 GURL http_url("http://www.google.com"); | 3233 GURL http_url("http://www.foo.com"); |
| 3258 GURL http_superdomain_url("http://google.com"); | 3234 GURL http_superdomain_url("http://foo.com"); |
| 3259 GURL https_url("https://www.google.com"); | 3235 GURL https_url("https://www.foo.com"); |
| 3260 | 3236 |
| 3261 // Tests that non-equivalent cookies because of the path attribute can be set | 3237 // Tests that non-equivalent cookies because of the path attribute can be set |
| 3262 // successfully. | 3238 // successfully. |
| 3263 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3239 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 3264 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); | 3240 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); |
| 3265 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); | 3241 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); |
| 3266 | 3242 |
| 3267 // Tests that non-equivalent cookies because of the domain attribute can be | 3243 // Tests that non-equivalent cookies because of the domain attribute can be |
| 3268 // set successfully. | 3244 // set successfully. |
| 3269 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3245 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 3270 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); | 3246 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=foo.com")); |
| 3271 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); | 3247 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=foo.com")); |
| 3272 } | 3248 } |
| 3273 | 3249 |
| 3274 class CookieMonsterNotificationTest : public CookieMonsterTest { | 3250 class CookieMonsterNotificationTest : public CookieMonsterTest { |
| 3275 public: | 3251 public: |
| 3276 CookieMonsterNotificationTest() | 3252 CookieMonsterNotificationTest() |
| 3277 : test_url_("http://www.google.com/foo"), | 3253 : test_url_("http://www.foo.com/foo"), |
| 3278 store_(new MockPersistentCookieStore), | 3254 store_(new MockPersistentCookieStore), |
| 3279 monster_(new CookieMonster(store_.get(), nullptr)) {} | 3255 monster_(new CookieMonster(store_.get(), nullptr)) {} |
| 3280 | 3256 |
| 3281 ~CookieMonsterNotificationTest() override {} | 3257 ~CookieMonsterNotificationTest() override {} |
| 3282 | 3258 |
| 3283 CookieMonster* monster() { return monster_.get(); } | 3259 CookieMonster* monster() { return monster_.get(); } |
| 3284 | 3260 |
| 3285 protected: | 3261 protected: |
| 3286 const GURL test_url_; | 3262 const GURL test_url_; |
| 3287 | 3263 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3421 monster()->AddCallbackForCookie( | 3397 monster()->AddCallbackForCookie( |
| 3422 test_url_, "abc", | 3398 test_url_, "abc", |
| 3423 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3399 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 3424 SetCookie(monster(), test_url_, "abc=def"); | 3400 SetCookie(monster(), test_url_, "abc=def"); |
| 3425 base::RunLoop().RunUntilIdle(); | 3401 base::RunLoop().RunUntilIdle(); |
| 3426 EXPECT_EQ(1U, cookies0.size()); | 3402 EXPECT_EQ(1U, cookies0.size()); |
| 3427 EXPECT_EQ(1U, cookies0.size()); | 3403 EXPECT_EQ(1U, cookies0.size()); |
| 3428 } | 3404 } |
| 3429 | 3405 |
| 3430 } // namespace net | 3406 } // namespace net |
| OLD | NEW |