| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <time.h> | 5 #include <time.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/cookie_monster.h" | 22 #include "net/base/cookie_monster.h" |
| 23 #include "net/base/cookie_monster_store_test.h" // For CookieStore Mock | 23 #include "net/base/cookie_monster_store_test.h" // For CookieStore mock |
| 24 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 namespace net { | 27 namespace net { |
| 27 | 28 |
| 28 using base::Time; | 29 using base::Time; |
| 29 using base::TimeDelta; | 30 using base::TimeDelta; |
| 30 using base::Thread; | 31 using base::Thread; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 35 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and |
| 36 // brethren) with this one, and remove the 'New' prefix. |
| 37 class NewMockPersistentCookieStore |
| 38 : public CookieMonster::PersistentCookieStore { |
| 39 public: |
| 40 MOCK_METHOD1(Load, bool(const LoadedCallback& loaded_callback)); |
| 41 MOCK_METHOD1(AddCookie, void(const CookieMonster::CanonicalCookie& cc)); |
| 42 MOCK_METHOD1(UpdateCookieAccessTime, |
| 43 void(const CookieMonster::CanonicalCookie& cc)); |
| 44 MOCK_METHOD1(DeleteCookie, void(const CookieMonster::CanonicalCookie& cc)); |
| 45 MOCK_METHOD1(SetClearLocalStateOnExit, void(bool clear_local_state)); |
| 46 MOCK_METHOD1(Flush, void(Task* completion_task)); |
| 47 }; |
| 48 |
| 34 const int kTimeout = 1000; | 49 const int kTimeout = 1000; |
| 35 | 50 |
| 36 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu"; | 51 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu"; |
| 37 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu"; | 52 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu"; |
| 38 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu"; | 53 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu"; |
| 39 const char* kTopLevelDomainPlus3 = | 54 const char* kTopLevelDomainPlus3 = |
| 40 "http://www.bourbaki.math.harvard.edu"; | 55 "http://www.bourbaki.math.harvard.edu"; |
| 41 const char* kOtherDomain = "http://www.mit.edu"; | 56 const char* kOtherDomain = "http://www.mit.edu"; |
| 42 | 57 |
| 43 const char kUrlGoogle[] = "http://www.google.izzle"; | 58 const char kUrlGoogle[] = "http://www.google.izzle"; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 std::string cookie_; | 153 std::string cookie_; |
| 139 }; | 154 }; |
| 140 | 155 |
| 141 class GetCookiesWithInfoCallback : public CookieCallback { | 156 class GetCookiesWithInfoCallback : public CookieCallback { |
| 142 public: | 157 public: |
| 143 GetCookiesWithInfoCallback() {} | 158 GetCookiesWithInfoCallback() {} |
| 144 explicit GetCookiesWithInfoCallback(Thread* run_in_thread) | 159 explicit GetCookiesWithInfoCallback(Thread* run_in_thread) |
| 145 : CookieCallback(run_in_thread) {} | 160 : CookieCallback(run_in_thread) {} |
| 146 | 161 |
| 147 void Run( | 162 void Run( |
| 148 std::string* cookie_line, | 163 const std::string& cookie_line, |
| 149 std::vector<CookieStore::CookieInfo>* cookie_info) { | 164 const std::vector<CookieStore::CookieInfo>& cookie_info) { |
| 150 cookie_line_ = *cookie_line; | 165 cookie_line_ = cookie_line; |
| 151 cookie_info_ = *cookie_info; | 166 cookie_info_ = cookie_info; |
| 152 CallbackEpilogue(); | 167 CallbackEpilogue(); |
| 153 } | 168 } |
| 154 | 169 |
| 155 const std::string& cookie_line() { return cookie_line_; } | 170 const std::string& cookie_line() { return cookie_line_; } |
| 156 const std::vector<CookieStore::CookieInfo>& cookie_info() { | 171 const std::vector<CookieStore::CookieInfo>& cookie_info() { |
| 157 return cookie_info_; | 172 return cookie_info_; |
| 158 } | 173 } |
| 159 | 174 |
| 160 private: | 175 private: |
| 161 std::string cookie_line_; | 176 std::string cookie_line_; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 425 |
| 411 CookieMonster::ParsedCookie pc1(blankpairs + "secure"); | 426 CookieMonster::ParsedCookie pc1(blankpairs + "secure"); |
| 412 EXPECT_TRUE(pc1.IsValid()); | 427 EXPECT_TRUE(pc1.IsValid()); |
| 413 EXPECT_TRUE(pc1.IsSecure()); | 428 EXPECT_TRUE(pc1.IsSecure()); |
| 414 | 429 |
| 415 CookieMonster::ParsedCookie pc2(blankpairs + ";secure"); | 430 CookieMonster::ParsedCookie pc2(blankpairs + ";secure"); |
| 416 EXPECT_TRUE(pc2.IsValid()); | 431 EXPECT_TRUE(pc2.IsValid()); |
| 417 EXPECT_FALSE(pc2.IsSecure()); | 432 EXPECT_FALSE(pc2.IsSecure()); |
| 418 } | 433 } |
| 419 | 434 |
| 420 // TODO some better test cases for invalid cookies. | 435 // TODO(erikwright): some better test cases for invalid cookies. |
| 421 TEST(ParsedCookieTest, InvalidWhitespace) { | 436 TEST(ParsedCookieTest, InvalidWhitespace) { |
| 422 CookieMonster::ParsedCookie pc(" "); | 437 CookieMonster::ParsedCookie pc(" "); |
| 423 EXPECT_FALSE(pc.IsValid()); | 438 EXPECT_FALSE(pc.IsValid()); |
| 424 } | 439 } |
| 425 | 440 |
| 426 TEST(ParsedCookieTest, InvalidTooLong) { | 441 TEST(ParsedCookieTest, InvalidTooLong) { |
| 427 std::string maxstr; | 442 std::string maxstr; |
| 428 maxstr.resize(CookieMonster::ParsedCookie::kMaxCookieSize, 'a'); | 443 maxstr.resize(CookieMonster::ParsedCookie::kMaxCookieSize, 'a'); |
| 429 | 444 |
| 430 CookieMonster::ParsedCookie pc1(maxstr); | 445 CookieMonster::ParsedCookie pc1(maxstr); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 url_google_bar_(kUrlGoogleBar), | 507 url_google_bar_(kUrlGoogleBar), |
| 493 message_loop_factory_(MessageLoop::current()) {} | 508 message_loop_factory_(MessageLoop::current()) {} |
| 494 | 509 |
| 495 // Helper methods for the asynchronous Cookie Store API that call the | 510 // Helper methods for the asynchronous Cookie Store API that call the |
| 496 // asynchronous method and then pump the loop until the callback is invoked, | 511 // asynchronous method and then pump the loop until the callback is invoked, |
| 497 // finally returning the value. | 512 // finally returning the value. |
| 498 | 513 |
| 499 std::string GetCookies(CookieMonster* cm, const GURL& url) { | 514 std::string GetCookies(CookieMonster* cm, const GURL& url) { |
| 500 DCHECK(cm); | 515 DCHECK(cm); |
| 501 GetCookieStringCallback callback; | 516 GetCookieStringCallback callback; |
| 502 cm->GetCookiesAsync( | 517 cm->GetCookiesWithOptionsAsync( |
| 503 url, base::Bind(&GetCookieStringCallback::Run, | 518 url, CookieOptions(), base::Bind(&GetCookieStringCallback::Run, |
| 504 base::Unretained(&callback))); | 519 base::Unretained(&callback))); |
| 505 RunFor(kTimeout); | 520 RunFor(kTimeout); |
| 506 EXPECT_TRUE(callback.did_run()); | 521 EXPECT_TRUE(callback.did_run()); |
| 507 return callback.cookie(); | 522 return callback.cookie(); |
| 508 } | 523 } |
| 509 | 524 |
| 510 std::string GetCookiesWithOptions(CookieMonster* cm, | 525 std::string GetCookiesWithOptions(CookieMonster* cm, |
| 511 const GURL& url, | 526 const GURL& url, |
| 512 const CookieOptions& options) { | 527 const CookieOptions& options) { |
| 513 DCHECK(cm); | 528 DCHECK(cm); |
| 514 GetCookieStringCallback callback; | 529 GetCookieStringCallback callback; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 DCHECK(cm); | 597 DCHECK(cm); |
| 583 SetCookieCallback callback; | 598 SetCookieCallback callback; |
| 584 cm->SetCookieWithOptionsAsync( | 599 cm->SetCookieWithOptionsAsync( |
| 585 url, cookie_line, options, | 600 url, cookie_line, options, |
| 586 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); | 601 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); |
| 587 RunFor(kTimeout); | 602 RunFor(kTimeout); |
| 588 EXPECT_TRUE(callback.did_run()); | 603 EXPECT_TRUE(callback.did_run()); |
| 589 return callback.result(); | 604 return callback.result(); |
| 590 } | 605 } |
| 591 | 606 |
| 607 bool SetCookie(CookieMonster* cm, |
| 608 const GURL& url, |
| 609 const std::string& cookie_line) { |
| 610 CookieOptions options; |
| 611 return SetCookieWithOptions(cm, url, cookie_line, options); |
| 612 } |
| 613 |
| 592 bool SetCookieWithDetails(CookieMonster* cm, | 614 bool SetCookieWithDetails(CookieMonster* cm, |
| 593 const GURL& url, | 615 const GURL& url, |
| 594 const std::string& name, | 616 const std::string& name, |
| 595 const std::string& value, | 617 const std::string& value, |
| 596 const std::string& domain, | 618 const std::string& domain, |
| 597 const std::string& path, | 619 const std::string& path, |
| 598 const base::Time& expiration_time, | 620 const base::Time& expiration_time, |
| 599 bool secure, bool http_only) { | 621 bool secure, bool http_only) { |
| 600 DCHECK(cm); | 622 DCHECK(cm); |
| 601 SetCookieCallback callback; | 623 SetCookieCallback callback; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 612 const std::string& cookie_name) { | 634 const std::string& cookie_name) { |
| 613 DCHECK(cm); | 635 DCHECK(cm); |
| 614 DeleteCookieCallback callback; | 636 DeleteCookieCallback callback; |
| 615 cm->DeleteCookieAsync(url, cookie_name, | 637 cm->DeleteCookieAsync(url, cookie_name, |
| 616 base::Bind(&DeleteCookieCallback::Run, | 638 base::Bind(&DeleteCookieCallback::Run, |
| 617 base::Unretained(&callback))); | 639 base::Unretained(&callback))); |
| 618 RunFor(kTimeout); | 640 RunFor(kTimeout); |
| 619 EXPECT_TRUE(callback.did_run()); | 641 EXPECT_TRUE(callback.did_run()); |
| 620 } | 642 } |
| 621 | 643 |
| 644 int DeleteAll(CookieMonster*cm) { |
| 645 DCHECK(cm); |
| 646 DeleteCallback callback; |
| 647 cm->DeleteAllAsync( |
| 648 base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); |
| 649 RunFor(kTimeout); |
| 650 EXPECT_TRUE(callback.did_run()); |
| 651 return callback.num_deleted(); |
| 652 } |
| 653 |
| 622 int DeleteAllCreatedBetween(CookieMonster*cm, | 654 int DeleteAllCreatedBetween(CookieMonster*cm, |
| 623 const base::Time& delete_begin, | 655 const base::Time& delete_begin, |
| 624 const base::Time& delete_end, | 656 const base::Time& delete_end) { |
| 625 bool sync_to_store) { | |
| 626 DCHECK(cm); | 657 DCHECK(cm); |
| 627 DeleteCallback callback; | 658 DeleteCallback callback; |
| 628 cm->DeleteAllCreatedBetweenAsync( | 659 cm->DeleteAllCreatedBetweenAsync( |
| 629 delete_begin, delete_end, sync_to_store, | 660 delete_begin, delete_end, |
| 630 base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); | 661 base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); |
| 631 RunFor(kTimeout); | 662 RunFor(kTimeout); |
| 632 EXPECT_TRUE(callback.did_run()); | 663 EXPECT_TRUE(callback.did_run()); |
| 633 return callback.num_deleted(); | 664 return callback.num_deleted(); |
| 634 } | 665 } |
| 635 | 666 |
| 636 int DeleteAllForHost(CookieMonster*cm, | 667 int DeleteAllForHost(CookieMonster*cm, |
| 637 const GURL& url) { | 668 const GURL& url) { |
| 638 DCHECK(cm); | 669 DCHECK(cm); |
| 639 DeleteCallback callback; | 670 DeleteCallback callback; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 668 | 699 |
| 669 // Helper for DeleteAllForHost test; repopulates CM with same layout | 700 // Helper for DeleteAllForHost test; repopulates CM with same layout |
| 670 // each time. | 701 // each time. |
| 671 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { | 702 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { |
| 672 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); | 703 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); |
| 673 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); | 704 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); |
| 674 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); | 705 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); |
| 675 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); | 706 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); |
| 676 GURL url_other(kOtherDomain); | 707 GURL url_other(kOtherDomain); |
| 677 | 708 |
| 678 cm->DeleteAll(true); | 709 DeleteAll(cm); |
| 679 | 710 |
| 680 // Static population for probe: | 711 // Static population for probe: |
| 681 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) | 712 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) |
| 682 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) | 713 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) |
| 683 // * http_only cookie (w.c.b.a) | 714 // * http_only cookie (w.c.b.a) |
| 684 // * Two secure cookies (.c.b.a, w.c.b.a) | 715 // * Two secure cookies (.c.b.a, w.c.b.a) |
| 685 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) | 716 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) |
| 686 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) | 717 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) |
| 687 | 718 |
| 688 // Domain cookies | 719 // Domain cookies |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 int domain_purge_cookies, | 802 int domain_purge_cookies, |
| 772 CookieMonster::ExpiryAndKeyScheme key_scheme) { | 803 CookieMonster::ExpiryAndKeyScheme key_scheme) { |
| 773 const int more_than_enough_cookies = | 804 const int more_than_enough_cookies = |
| 774 (domain_max_cookies + domain_purge_cookies) * 2; | 805 (domain_max_cookies + domain_purge_cookies) * 2; |
| 775 // Add a bunch of cookies on a single host, should purge them. | 806 // Add a bunch of cookies on a single host, should purge them. |
| 776 { | 807 { |
| 777 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 808 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 778 cm->SetExpiryAndKeyScheme(key_scheme); | 809 cm->SetExpiryAndKeyScheme(key_scheme); |
| 779 for (int i = 0; i < more_than_enough_cookies; ++i) { | 810 for (int i = 0; i < more_than_enough_cookies; ++i) { |
| 780 std::string cookie = base::StringPrintf("a%03d=b", i); | 811 std::string cookie = base::StringPrintf("a%03d=b", i); |
| 781 EXPECT_TRUE(cm->SetCookie(url_google_, cookie)); | 812 EXPECT_TRUE(SetCookie(cm, url_google_, cookie)); |
| 782 std::string cookies = this->GetCookies(cm, url_google_); | 813 std::string cookies = this->GetCookies(cm, url_google_); |
| 783 // Make sure we find it in the cookies. | 814 // Make sure we find it in the cookies. |
| 784 EXPECT_NE(cookies.find(cookie), std::string::npos); | 815 EXPECT_NE(cookies.find(cookie), std::string::npos); |
| 785 // Count the number of cookies. | 816 // Count the number of cookies. |
| 786 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); | 817 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); |
| 787 } | 818 } |
| 788 } | 819 } |
| 789 | 820 |
| 790 // Add a bunch of cookies on multiple hosts within a single eTLD. | 821 // Add a bunch of cookies on multiple hosts within a single eTLD. |
| 791 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies | 822 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies |
| 792 // between them. If we are using the effective domain keying system | 823 // between them. If we are using the effective domain keying system |
| 793 // (EKS_KEEP_RECENT_AND_PURGE_ETLDP1) we shouldn't go above | 824 // (EKS_KEEP_RECENT_AND_PURGE_ETLDP1) we shouldn't go above |
| 794 // kDomainMaxCookies for both together. If we're using the domain | 825 // kDomainMaxCookies for both together. If we're using the domain |
| 795 // keying system (EKS_DISCARD_RECENT_AND_PURGE_DOMAIN), each | 826 // keying system (EKS_DISCARD_RECENT_AND_PURGE_DOMAIN), each |
| 796 // individual domain shouldn't go above kDomainMaxCookies. | 827 // individual domain shouldn't go above kDomainMaxCookies. |
| 797 GURL url_google_specific(kUrlGoogleSpecific); | 828 GURL url_google_specific(kUrlGoogleSpecific); |
| 798 { | 829 { |
| 799 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 830 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 800 cm->SetExpiryAndKeyScheme(key_scheme); | 831 cm->SetExpiryAndKeyScheme(key_scheme); |
| 801 for (int i = 0; i < more_than_enough_cookies; ++i) { | 832 for (int i = 0; i < more_than_enough_cookies; ++i) { |
| 802 std::string cookie_general = base::StringPrintf("a%03d=b", i); | 833 std::string cookie_general = base::StringPrintf("a%03d=b", i); |
| 803 EXPECT_TRUE(cm->SetCookie(url_google_, cookie_general)); | 834 EXPECT_TRUE(SetCookie(cm, url_google_, cookie_general)); |
| 804 std::string cookie_specific = base::StringPrintf("c%03d=b", i); | 835 std::string cookie_specific = base::StringPrintf("c%03d=b", i); |
| 805 EXPECT_TRUE(cm->SetCookie(url_google_specific, cookie_specific)); | 836 EXPECT_TRUE(SetCookie(cm, url_google_specific, cookie_specific)); |
| 806 std::string cookies_general = this->GetCookies(cm, url_google_); | 837 std::string cookies_general = this->GetCookies(cm, url_google_); |
| 807 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); | 838 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); |
| 808 std::string cookies_specific = | 839 std::string cookies_specific = |
| 809 this->GetCookies(cm, url_google_specific); | 840 this->GetCookies(cm, url_google_specific); |
| 810 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos); | 841 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos); |
| 811 if (key_scheme == CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1) { | 842 if (key_scheme == CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1) { |
| 812 EXPECT_LE((CountInString(cookies_general, '=') + | 843 EXPECT_LE((CountInString(cookies_general, '=') + |
| 813 CountInString(cookies_specific, '=')), | 844 CountInString(cookies_specific, '=')), |
| 814 domain_max_cookies); | 845 domain_max_cookies); |
| 815 } else { | 846 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 833 EXPECT_GE(general_cookies, | 864 EXPECT_GE(general_cookies, |
| 834 domain_max_cookies - domain_purge_cookies); | 865 domain_max_cookies - domain_purge_cookies); |
| 835 EXPECT_LE(general_cookies, domain_max_cookies); | 866 EXPECT_LE(general_cookies, domain_max_cookies); |
| 836 EXPECT_GE(specific_cookies, | 867 EXPECT_GE(specific_cookies, |
| 837 domain_max_cookies - domain_purge_cookies); | 868 domain_max_cookies - domain_purge_cookies); |
| 838 EXPECT_LE(specific_cookies, domain_max_cookies); | 869 EXPECT_LE(specific_cookies, domain_max_cookies); |
| 839 } | 870 } |
| 840 } | 871 } |
| 841 } | 872 } |
| 842 | 873 |
| 874 // Function for creating a CM with a number of cookies in it, |
| 875 // no store (and hence no ability to affect access time). |
| 876 CookieMonster* CreateMonsterForGC(int num_cookies) { |
| 877 CookieMonster* cm(new CookieMonster(NULL, NULL)); |
| 878 for (int i = 0; i < num_cookies; i++) { |
| 879 SetCookie(cm, GURL(StringPrintf("http://h%05d.izzle", i)), "a=1"); |
| 880 } |
| 881 return cm; |
| 882 } |
| 883 |
| 843 protected: | 884 protected: |
| 844 GURL url_google_; | 885 GURL url_google_; |
| 845 GURL url_google_secure_; | 886 GURL url_google_secure_; |
| 846 GURL url_google_foo_; | 887 GURL url_google_foo_; |
| 847 GURL url_google_bar_; | 888 GURL url_google_bar_; |
| 848 | 889 |
| 849 ScopedRunnableMethodFactory<MessageLoop> message_loop_factory_; | 890 ScopedRunnableMethodFactory<MessageLoop> message_loop_factory_; |
| 850 }; | 891 }; |
| 851 | 892 |
| 893 // TODO(erikwright): Replace the other callbacks and synchronous helper methods |
| 894 // in this test suite with these Mocks. |
| 895 template<typename T, typename C> class MockCookieCallback { |
| 896 public: |
| 897 C AsCallback() { |
| 898 return base::Bind(&T::Invoke, base::Unretained(static_cast<T*>(this))); |
| 899 } |
| 900 }; |
| 901 |
| 902 class MockGetCookiesCallback |
| 903 : public MockCookieCallback<MockGetCookiesCallback, |
| 904 CookieStore::GetCookiesCallback> { |
| 905 public: |
| 906 MOCK_METHOD1(Invoke, void(const std::string& cookies)); |
| 907 }; |
| 908 |
| 909 class MockGetCookieInfoCallback |
| 910 : public MockCookieCallback<MockGetCookieInfoCallback, |
| 911 CookieStore::GetCookieInfoCallback> { |
| 912 public: |
| 913 MOCK_METHOD2(Invoke, |
| 914 void(const std::string& cookies, |
| 915 const std::vector<CookieStore::CookieInfo>& cookie_infos)); |
| 916 }; |
| 917 |
| 918 class MockSetCookiesCallback |
| 919 : public MockCookieCallback<MockSetCookiesCallback, |
| 920 CookieStore::SetCookiesCallback> { |
| 921 public: |
| 922 MOCK_METHOD1(Invoke, void(bool success)); |
| 923 }; |
| 924 |
| 925 class MockClosure |
| 926 : public MockCookieCallback<MockClosure, base::Closure> { |
| 927 public: |
| 928 MOCK_METHOD0(Invoke, void(void)); |
| 929 }; |
| 930 |
| 931 class MockGetCookieListCallback |
| 932 : public MockCookieCallback<MockGetCookieListCallback, |
| 933 CookieMonster::GetCookieListCallback> { |
| 934 public: |
| 935 MOCK_METHOD1(Invoke, void(const CookieList& cookies)); |
| 936 }; |
| 937 |
| 938 class MockDeleteCallback |
| 939 : public MockCookieCallback<MockDeleteCallback, |
| 940 CookieMonster::DeleteCallback> { |
| 941 public: |
| 942 MOCK_METHOD1(Invoke, void(int num_deleted)); |
| 943 }; |
| 944 |
| 945 class MockDeleteCookieCallback |
| 946 : public MockCookieCallback<MockDeleteCookieCallback, |
| 947 CookieMonster::DeleteCookieCallback> { |
| 948 public: |
| 949 MOCK_METHOD1(Invoke, void(bool success)); |
| 950 }; |
| 951 |
| 952 ACTION(QuitCurrentMessageLoop) { |
| 953 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 954 } |
| 955 |
| 956 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, |
| 957 // rename these, removing the 'Action' suffix. |
| 958 ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) { |
| 959 cookie_monster->DeleteCookieAsync(url, name, callback->AsCallback()); |
| 960 } |
| 961 ACTION_P3(GetCookiesAction, cookie_monster, url, callback) { |
| 962 cookie_monster->GetCookiesWithOptionsAsync( |
| 963 url, CookieOptions(), callback->AsCallback()); |
| 964 } |
| 965 ACTION_P3(GetCookiesWithInfoAction, cookie_monster, url, callback) { |
| 966 cookie_monster->GetCookiesWithInfoAsync( |
| 967 url, CookieOptions(), callback->AsCallback()); |
| 968 } |
| 969 ACTION_P4(SetCookieAction, cookie_monster, url, cookie_line, callback) { |
| 970 cookie_monster->SetCookieWithOptionsAsync( |
| 971 url, cookie_line, CookieOptions(), callback->AsCallback()); |
| 972 } |
| 973 ACTION_P4(DeleteAllCreatedBetweenAction, |
| 974 cookie_monster, delete_begin, delete_end, callback) { |
| 975 cookie_monster->DeleteAllCreatedBetweenAsync( |
| 976 delete_begin, delete_end, callback->AsCallback()); |
| 977 } |
| 978 ACTION_P10(SetCookieWithDetailsAction, |
| 979 cookie_monster, url, name, value, domain, path, expiration_time, |
| 980 secure, http_only, callback) { |
| 981 cookie_monster->SetCookieWithDetailsAsync( |
| 982 url, name, value, domain, path, expiration_time, secure, http_only, |
| 983 callback->AsCallback()); |
| 984 } |
| 985 |
| 986 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { |
| 987 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); |
| 988 } |
| 989 |
| 990 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { |
| 991 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); |
| 992 } |
| 993 |
| 994 ACTION_P3(DeleteCanonicalCookieAction, cookie_monster, cookie, callback) { |
| 995 cookie_monster->DeleteCanonicalCookieAsync(cookie, callback->AsCallback()); |
| 996 } |
| 997 |
| 998 ACTION_P2(DeleteAllAction, cookie_monster, callback) { |
| 999 cookie_monster->DeleteAllAsync(callback->AsCallback()); |
| 1000 } |
| 1001 |
| 1002 ACTION_P3(GetAllCookiesForUrlWithOptionsAction, cookie_monster, url, callback) { |
| 1003 cookie_monster->GetAllCookiesForURLWithOptionsAsync( |
| 1004 url, CookieOptions(), callback->AsCallback()); |
| 1005 } |
| 1006 |
| 1007 ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) { |
| 1008 cookie_monster->GetAllCookiesForURLAsync(url, callback->AsCallback()); |
| 1009 } |
| 1010 |
| 852 } // namespace | 1011 } // namespace |
| 853 | 1012 |
| 1013 // This test suite verifies the task deferral behaviour of the CookieMonster. |
| 1014 // Specifically, for each asynchronous method, verify that: |
| 1015 // 1. invoking it on an uninitialized cookie store causes the store to begin |
| 1016 // loading its backing data. |
| 1017 // 2. The initial invocation does not complete until the loading completes. |
| 1018 // 3. Invocations after the loading has completed complete immediately. |
| 1019 class DeferredCookieTaskTest : public CookieMonsterTest { |
| 1020 protected: |
| 1021 DeferredCookieTaskTest() { |
| 1022 persistent_store_ = new NewMockPersistentCookieStore(); |
| 1023 cookie_monster_ = new CookieMonster(persistent_store_.get(), NULL); |
| 1024 } |
| 1025 |
| 1026 // Defines a cookie to be returned from PersistentCookieStore::Load |
| 1027 void DeclareLoadedCookie(const std::string& key, |
| 1028 const std::string& cookie_line, |
| 1029 const base::Time& creation_time) { |
| 1030 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_); |
| 1031 } |
| 1032 |
| 1033 // Runs the message loop, waiting until PersistentCookieStore::Load is called. |
| 1034 // Call CompleteLoadingAndWait to cause the load to complete. |
| 1035 void WaitForLoadCall() { |
| 1036 RunFor(kTimeout); |
| 1037 |
| 1038 // Verify that PeristentStore::Load was called. |
| 1039 testing::Mock::VerifyAndClear(persistent_store_.get()); |
| 1040 } |
| 1041 |
| 1042 // Invokes the PersistentCookieStore::Load completion callback and waits |
| 1043 // until the message loop is quit. |
| 1044 void CompleteLoadingAndWait() { |
| 1045 loaded_callback_.Run(loaded_cookies_); |
| 1046 RunFor(kTimeout); |
| 1047 } |
| 1048 |
| 1049 // Performs the provided action, expecting it to cause a call to |
| 1050 // PersistentCookieStore::Load. Call WaitForLoadCall to verify the load call |
| 1051 // is received. |
| 1052 void BeginWith(testing::Action<void(void)> action) { |
| 1053 EXPECT_CALL(*this, Begin()).WillOnce(action); |
| 1054 ExpectLoadCall(); |
| 1055 Begin(); |
| 1056 } |
| 1057 |
| 1058 // Declares an expectation that PersistentCookieStore::Load will be called, |
| 1059 // saving the provided callback and sending a quit to the message loop. |
| 1060 void ExpectLoadCall() { |
| 1061 EXPECT_CALL(*persistent_store_, Load(testing::_)).WillOnce(testing::DoAll( |
| 1062 testing::SaveArg<0>(&loaded_callback_), |
| 1063 QuitCurrentMessageLoop(), |
| 1064 testing::Return(true))); |
| 1065 } |
| 1066 |
| 1067 // Invokes the initial action. |
| 1068 MOCK_METHOD0(Begin, void(void)); |
| 1069 |
| 1070 // Returns the CookieMonster instance under test. |
| 1071 CookieMonster& cookie_monster() { return *cookie_monster_; } |
| 1072 |
| 1073 private: |
| 1074 // Declares that mock expectations in this test suite are strictly ordered. |
| 1075 testing::InSequence in_sequence_; |
| 1076 // Holds cookies to be returned from PersistentCookieStore::Load. |
| 1077 std::vector<CookieMonster::CanonicalCookie*> loaded_cookies_; |
| 1078 // Stores the callback passed from the CookieMonster to the |
| 1079 // PersistentCookieStore |
| 1080 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; |
| 1081 // Stores the CookieMonster under test. |
| 1082 scoped_refptr<CookieMonster> cookie_monster_; |
| 1083 // Stores the mock PersistentCookieStore. |
| 1084 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; |
| 1085 }; |
| 1086 |
| 1087 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { |
| 1088 DeclareLoadedCookie("www.google.izzle", |
| 1089 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1090 Time::Now() + TimeDelta::FromDays(3)); |
| 1091 |
| 1092 MockGetCookiesCallback get_cookies_callback; |
| 1093 |
| 1094 BeginWith(GetCookiesAction( |
| 1095 &cookie_monster(), url_google_, &get_cookies_callback)); |
| 1096 |
| 1097 WaitForLoadCall(); |
| 1098 |
| 1099 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( |
| 1100 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); |
| 1101 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( |
| 1102 QuitCurrentMessageLoop()); |
| 1103 |
| 1104 CompleteLoadingAndWait(); |
| 1105 } |
| 1106 |
| 1107 TEST_F(DeferredCookieTaskTest, DeferredGetCookiesWithInfo) { |
| 1108 DeclareLoadedCookie("www.google.izzle", |
| 1109 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1110 Time::Now() + TimeDelta::FromDays(3)); |
| 1111 |
| 1112 MockGetCookieInfoCallback get_cookie_info_callback; |
| 1113 |
| 1114 BeginWith(GetCookiesWithInfoAction( |
| 1115 &cookie_monster(), url_google_, &get_cookie_info_callback)); |
| 1116 |
| 1117 WaitForLoadCall(); |
| 1118 |
| 1119 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( |
| 1120 GetCookiesWithInfoAction( |
| 1121 &cookie_monster(), url_google_, &get_cookie_info_callback)); |
| 1122 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( |
| 1123 QuitCurrentMessageLoop()); |
| 1124 |
| 1125 CompleteLoadingAndWait(); |
| 1126 } |
| 1127 |
| 1128 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { |
| 1129 MockSetCookiesCallback set_cookies_callback; |
| 1130 |
| 1131 BeginWith(SetCookieAction( |
| 1132 &cookie_monster(), url_google_, "A=B", &set_cookies_callback)); |
| 1133 |
| 1134 WaitForLoadCall(); |
| 1135 |
| 1136 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( |
| 1137 SetCookieAction( |
| 1138 &cookie_monster(), url_google_, "X=Y", &set_cookies_callback)); |
| 1139 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( |
| 1140 QuitCurrentMessageLoop()); |
| 1141 |
| 1142 CompleteLoadingAndWait(); |
| 1143 } |
| 1144 |
| 1145 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { |
| 1146 MockClosure delete_cookie_callback; |
| 1147 |
| 1148 BeginWith(DeleteCookieAction( |
| 1149 &cookie_monster(), url_google_, "A", &delete_cookie_callback)); |
| 1150 |
| 1151 WaitForLoadCall(); |
| 1152 |
| 1153 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( |
| 1154 DeleteCookieAction( |
| 1155 &cookie_monster(), url_google_, "X", &delete_cookie_callback)); |
| 1156 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( |
| 1157 QuitCurrentMessageLoop()); |
| 1158 |
| 1159 CompleteLoadingAndWait(); |
| 1160 } |
| 1161 |
| 1162 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { |
| 1163 MockSetCookiesCallback set_cookies_callback; |
| 1164 |
| 1165 BeginWith(SetCookieWithDetailsAction( |
| 1166 &cookie_monster(), url_google_foo_, "A", "B", std::string(), "/foo", |
| 1167 base::Time(), false, false, &set_cookies_callback)); |
| 1168 |
| 1169 WaitForLoadCall(); |
| 1170 |
| 1171 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( |
| 1172 SetCookieWithDetailsAction( |
| 1173 &cookie_monster(), url_google_foo_, "A", "B", std::string(), "/foo", |
| 1174 base::Time(), false, false, &set_cookies_callback)); |
| 1175 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( |
| 1176 QuitCurrentMessageLoop()); |
| 1177 |
| 1178 CompleteLoadingAndWait(); |
| 1179 } |
| 1180 |
| 1181 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { |
| 1182 DeclareLoadedCookie("www.google.izzle", |
| 1183 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1184 Time::Now() + TimeDelta::FromDays(3)); |
| 1185 |
| 1186 MockGetCookieListCallback get_cookie_list_callback; |
| 1187 |
| 1188 BeginWith(GetAllCookiesAction( |
| 1189 &cookie_monster(), &get_cookie_list_callback)); |
| 1190 |
| 1191 WaitForLoadCall(); |
| 1192 |
| 1193 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
| 1194 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); |
| 1195 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
| 1196 QuitCurrentMessageLoop()); |
| 1197 |
| 1198 CompleteLoadingAndWait(); |
| 1199 } |
| 1200 |
| 1201 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { |
| 1202 DeclareLoadedCookie("www.google.izzle", |
| 1203 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1204 Time::Now() + TimeDelta::FromDays(3)); |
| 1205 |
| 1206 MockGetCookieListCallback get_cookie_list_callback; |
| 1207 |
| 1208 BeginWith(GetAllCookiesForUrlAction( |
| 1209 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
| 1210 |
| 1211 WaitForLoadCall(); |
| 1212 |
| 1213 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
| 1214 GetAllCookiesForUrlAction( |
| 1215 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
| 1216 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
| 1217 QuitCurrentMessageLoop()); |
| 1218 |
| 1219 CompleteLoadingAndWait(); |
| 1220 } |
| 1221 |
| 1222 |
| 1223 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { |
| 1224 DeclareLoadedCookie("www.google.izzle", |
| 1225 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1226 Time::Now() + TimeDelta::FromDays(3)); |
| 1227 |
| 1228 MockGetCookieListCallback get_cookie_list_callback; |
| 1229 |
| 1230 BeginWith(GetAllCookiesForUrlWithOptionsAction( |
| 1231 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
| 1232 |
| 1233 WaitForLoadCall(); |
| 1234 |
| 1235 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
| 1236 GetAllCookiesForUrlWithOptionsAction( |
| 1237 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
| 1238 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
| 1239 QuitCurrentMessageLoop()); |
| 1240 |
| 1241 CompleteLoadingAndWait(); |
| 1242 } |
| 1243 |
| 1244 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { |
| 1245 MockDeleteCallback delete_callback; |
| 1246 |
| 1247 BeginWith(DeleteAllAction( |
| 1248 &cookie_monster(), &delete_callback)); |
| 1249 |
| 1250 WaitForLoadCall(); |
| 1251 |
| 1252 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
| 1253 DeleteAllAction(&cookie_monster(), &delete_callback)); |
| 1254 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
| 1255 QuitCurrentMessageLoop()); |
| 1256 |
| 1257 CompleteLoadingAndWait(); |
| 1258 } |
| 1259 |
| 1260 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) { |
| 1261 MockDeleteCallback delete_callback; |
| 1262 |
| 1263 BeginWith(DeleteAllCreatedBetweenAction( |
| 1264 &cookie_monster(), base::Time(), base::Time::Now(), &delete_callback)); |
| 1265 |
| 1266 WaitForLoadCall(); |
| 1267 |
| 1268 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
| 1269 DeleteAllCreatedBetweenAction( |
| 1270 &cookie_monster(), base::Time(), base::Time::Now(), |
| 1271 &delete_callback)); |
| 1272 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
| 1273 QuitCurrentMessageLoop()); |
| 1274 |
| 1275 CompleteLoadingAndWait(); |
| 1276 } |
| 1277 |
| 1278 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { |
| 1279 MockDeleteCallback delete_callback; |
| 1280 |
| 1281 BeginWith(DeleteAllForHostAction( |
| 1282 &cookie_monster(), url_google_, &delete_callback)); |
| 1283 |
| 1284 WaitForLoadCall(); |
| 1285 |
| 1286 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
| 1287 DeleteAllForHostAction( |
| 1288 &cookie_monster(), url_google_, &delete_callback)); |
| 1289 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
| 1290 QuitCurrentMessageLoop()); |
| 1291 |
| 1292 CompleteLoadingAndWait(); |
| 1293 } |
| 1294 |
| 1295 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { |
| 1296 std::vector<CookieMonster::CanonicalCookie*> cookies; |
| 1297 CookieMonster::CanonicalCookie cookie = BuildCanonicalCookie( |
| 1298 "www.google.com", "X=1; path=/", base::Time::Now()); |
| 1299 |
| 1300 MockDeleteCookieCallback delete_cookie_callback; |
| 1301 |
| 1302 BeginWith(DeleteCanonicalCookieAction( |
| 1303 &cookie_monster(), cookie, &delete_cookie_callback)); |
| 1304 |
| 1305 WaitForLoadCall(); |
| 1306 |
| 1307 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce( |
| 1308 DeleteCanonicalCookieAction( |
| 1309 &cookie_monster(), cookie, &delete_cookie_callback)); |
| 1310 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce( |
| 1311 QuitCurrentMessageLoop()); |
| 1312 |
| 1313 CompleteLoadingAndWait(); |
| 1314 } |
| 1315 |
| 1316 // Verify that a series of queued tasks are executed in order upon loading of |
| 1317 // the backing store and that new tasks received while the queued tasks are |
| 1318 // being dispatched go to the end of the queue. |
| 1319 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { |
| 1320 DeclareLoadedCookie("www.google.izzle", |
| 1321 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1322 Time::Now() + TimeDelta::FromDays(3)); |
| 1323 |
| 1324 MockGetCookiesCallback get_cookies_callback; |
| 1325 MockSetCookiesCallback set_cookies_callback; |
| 1326 MockClosure delete_cookie_callback; |
| 1327 MockGetCookieInfoCallback get_cookie_info_callback; |
| 1328 |
| 1329 EXPECT_CALL(*this, Begin()).WillOnce(testing::DoAll( |
| 1330 GetCookiesAction( |
| 1331 &cookie_monster(), url_google_, &get_cookies_callback), |
| 1332 SetCookieAction( |
| 1333 &cookie_monster(), url_google_, "A=B", &set_cookies_callback), |
| 1334 DeleteCookieAction( |
| 1335 &cookie_monster(), url_google_, "A", &delete_cookie_callback))); |
| 1336 ExpectLoadCall(); |
| 1337 Begin(); |
| 1338 |
| 1339 WaitForLoadCall(); |
| 1340 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( |
| 1341 GetCookiesWithInfoAction( |
| 1342 &cookie_monster(), url_google_, &get_cookie_info_callback)); |
| 1343 |
| 1344 EXPECT_CALL(set_cookies_callback, Invoke(true)); |
| 1345 EXPECT_CALL(delete_cookie_callback, Invoke()); |
| 1346 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( |
| 1347 QuitCurrentMessageLoop()); |
| 1348 |
| 1349 CompleteLoadingAndWait(); |
| 1350 } |
| 1351 |
| 854 TEST_F(CookieMonsterTest, DomainTest) { | 1352 TEST_F(CookieMonsterTest, DomainTest) { |
| 855 scoped_refptr<MockPersistentCookieStore> store( | 1353 scoped_refptr<MockPersistentCookieStore> store( |
| 856 new MockPersistentCookieStore); | 1354 new MockPersistentCookieStore); |
| 857 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1355 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 858 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 1356 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 859 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1357 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 860 EXPECT_TRUE(cm->SetCookie(url_google_, "C=D; domain=.google.izzle")); | 1358 EXPECT_TRUE(SetCookie(cm, url_google_, "C=D; domain=.google.izzle")); |
| 861 EXPECT_EQ("A=B; C=D", GetCookies(cm, url_google_)); | 1359 EXPECT_EQ("A=B; C=D", GetCookies(cm, url_google_)); |
| 862 | 1360 |
| 863 // Verify that A=B was set as a host cookie rather than a domain | 1361 // Verify that A=B was set as a host cookie rather than a domain |
| 864 // cookie -- should not be accessible from a sub sub-domain. | 1362 // cookie -- should not be accessible from a sub sub-domain. |
| 865 EXPECT_EQ("C=D", GetCookies(cm, GURL("http://foo.www.google.izzle"))); | 1363 EXPECT_EQ("C=D", GetCookies(cm, GURL("http://foo.www.google.izzle"))); |
| 866 | 1364 |
| 867 // Test and make sure we find domain cookies on the same domain. | 1365 // Test and make sure we find domain cookies on the same domain. |
| 868 EXPECT_TRUE(cm->SetCookie(url_google_, "E=F; domain=.www.google.izzle")); | 1366 EXPECT_TRUE(SetCookie(cm, url_google_, "E=F; domain=.www.google.izzle")); |
| 869 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); | 1367 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); |
| 870 | 1368 |
| 871 // Test setting a domain= that doesn't start w/ a dot, should | 1369 // Test setting a domain= that doesn't start w/ a dot, should |
| 872 // treat it as a domain cookie, as if there was a pre-pended dot. | 1370 // treat it as a domain cookie, as if there was a pre-pended dot. |
| 873 EXPECT_TRUE(cm->SetCookie(url_google_, "G=H; domain=www.google.izzle")); | 1371 EXPECT_TRUE(SetCookie(cm, url_google_, "G=H; domain=www.google.izzle")); |
| 874 EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_)); | 1372 EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_)); |
| 875 | 1373 |
| 876 // Test domain enforcement, should fail on a sub-domain or something too deep. | 1374 // Test domain enforcement, should fail on a sub-domain or something too deep. |
| 877 EXPECT_FALSE(cm->SetCookie(url_google_, "I=J; domain=.izzle")); | 1375 EXPECT_FALSE(SetCookie(cm, url_google_, "I=J; domain=.izzle")); |
| 878 EXPECT_EQ("", GetCookies(cm, GURL("http://a.izzle"))); | 1376 EXPECT_EQ("", GetCookies(cm, GURL("http://a.izzle"))); |
| 879 EXPECT_FALSE(cm->SetCookie(url_google_, "K=L; domain=.bla.www.google.izzle")); | 1377 EXPECT_FALSE(SetCookie(cm, url_google_, "K=L; domain=.bla.www.google.izzle")); |
| 880 EXPECT_EQ("C=D; E=F; G=H", | 1378 EXPECT_EQ("C=D; E=F; G=H", |
| 881 GetCookies(cm, GURL("http://bla.www.google.izzle"))); | 1379 GetCookies(cm, GURL("http://bla.www.google.izzle"))); |
| 882 EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_)); | 1380 EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_)); |
| 883 | 1381 |
| 884 // Nothing was persisted to the backing store. | 1382 // Nothing was persisted to the backing store. |
| 885 EXPECT_EQ(0u, store->commands().size()); | 1383 EXPECT_EQ(0u, store->commands().size()); |
| 886 } | 1384 } |
| 887 | 1385 |
| 888 // FireFox recognizes domains containing trailing periods as valid. | 1386 // FireFox recognizes domains containing trailing periods as valid. |
| 889 // IE and Safari do not. Assert the expected policy here. | 1387 // IE and Safari do not. Assert the expected policy here. |
| 890 TEST_F(CookieMonsterTest, DomainWithTrailingDotTest) { | 1388 TEST_F(CookieMonsterTest, DomainWithTrailingDotTest) { |
| 891 scoped_refptr<MockPersistentCookieStore> store( | 1389 scoped_refptr<MockPersistentCookieStore> store( |
| 892 new MockPersistentCookieStore); | 1390 new MockPersistentCookieStore); |
| 893 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1391 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 894 EXPECT_FALSE(cm->SetCookie(url_google_, "a=1; domain=.www.google.com.")); | 1392 EXPECT_FALSE(SetCookie(cm, url_google_, "a=1; domain=.www.google.com.")); |
| 895 EXPECT_FALSE(cm->SetCookie(url_google_, "b=2; domain=.www.google.com..")); | 1393 EXPECT_FALSE(SetCookie(cm, url_google_, "b=2; domain=.www.google.com..")); |
| 896 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1394 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 897 | 1395 |
| 898 // Nothing was persisted to the backing store. | 1396 // Nothing was persisted to the backing store. |
| 899 EXPECT_EQ(0u, store->commands().size()); | 1397 EXPECT_EQ(0u, store->commands().size()); |
| 900 } | 1398 } |
| 901 | 1399 |
| 902 // Test that cookies can bet set on higher level domains. | 1400 // Test that cookies can bet set on higher level domains. |
| 903 // http://b/issue?id=896491 | 1401 // http://b/issue?id=896491 |
| 904 TEST_F(CookieMonsterTest, ValidSubdomainTest) { | 1402 TEST_F(CookieMonsterTest, ValidSubdomainTest) { |
| 905 scoped_refptr<MockPersistentCookieStore> store( | 1403 scoped_refptr<MockPersistentCookieStore> store( |
| 906 new MockPersistentCookieStore); | 1404 new MockPersistentCookieStore); |
| 907 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1405 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 908 GURL url_abcd("http://a.b.c.d.com"); | 1406 GURL url_abcd("http://a.b.c.d.com"); |
| 909 GURL url_bcd("http://b.c.d.com"); | 1407 GURL url_bcd("http://b.c.d.com"); |
| 910 GURL url_cd("http://c.d.com"); | 1408 GURL url_cd("http://c.d.com"); |
| 911 GURL url_d("http://d.com"); | 1409 GURL url_d("http://d.com"); |
| 912 | 1410 |
| 913 EXPECT_TRUE(cm->SetCookie(url_abcd, "a=1; domain=.a.b.c.d.com")); | 1411 EXPECT_TRUE(SetCookie(cm, url_abcd, "a=1; domain=.a.b.c.d.com")); |
| 914 EXPECT_TRUE(cm->SetCookie(url_abcd, "b=2; domain=.b.c.d.com")); | 1412 EXPECT_TRUE(SetCookie(cm, url_abcd, "b=2; domain=.b.c.d.com")); |
| 915 EXPECT_TRUE(cm->SetCookie(url_abcd, "c=3; domain=.c.d.com")); | 1413 EXPECT_TRUE(SetCookie(cm, url_abcd, "c=3; domain=.c.d.com")); |
| 916 EXPECT_TRUE(cm->SetCookie(url_abcd, "d=4; domain=.d.com")); | 1414 EXPECT_TRUE(SetCookie(cm, url_abcd, "d=4; domain=.d.com")); |
| 917 | 1415 |
| 918 EXPECT_EQ("a=1; b=2; c=3; d=4", GetCookies(cm, url_abcd)); | 1416 EXPECT_EQ("a=1; b=2; c=3; d=4", GetCookies(cm, url_abcd)); |
| 919 EXPECT_EQ("b=2; c=3; d=4", GetCookies(cm, url_bcd)); | 1417 EXPECT_EQ("b=2; c=3; d=4", GetCookies(cm, url_bcd)); |
| 920 EXPECT_EQ("c=3; d=4", GetCookies(cm, url_cd)); | 1418 EXPECT_EQ("c=3; d=4", GetCookies(cm, url_cd)); |
| 921 EXPECT_EQ("d=4", GetCookies(cm, url_d)); | 1419 EXPECT_EQ("d=4", GetCookies(cm, url_d)); |
| 922 | 1420 |
| 923 // Check that the same cookie can exist on different sub-domains. | 1421 // Check that the same cookie can exist on different sub-domains. |
| 924 EXPECT_TRUE(cm->SetCookie(url_bcd, "X=bcd; domain=.b.c.d.com")); | 1422 EXPECT_TRUE(SetCookie(cm, url_bcd, "X=bcd; domain=.b.c.d.com")); |
| 925 EXPECT_TRUE(cm->SetCookie(url_bcd, "X=cd; domain=.c.d.com")); | 1423 EXPECT_TRUE(SetCookie(cm, url_bcd, "X=cd; domain=.c.d.com")); |
| 926 EXPECT_EQ("b=2; c=3; d=4; X=bcd; X=cd", GetCookies(cm, url_bcd)); | 1424 EXPECT_EQ("b=2; c=3; d=4; X=bcd; X=cd", GetCookies(cm, url_bcd)); |
| 927 EXPECT_EQ("c=3; d=4; X=cd", GetCookies(cm, url_cd)); | 1425 EXPECT_EQ("c=3; d=4; X=cd", GetCookies(cm, url_cd)); |
| 928 | 1426 |
| 929 // Nothing was persisted to the backing store. | 1427 // Nothing was persisted to the backing store. |
| 930 EXPECT_EQ(0u, store->commands().size()); | 1428 EXPECT_EQ(0u, store->commands().size()); |
| 931 } | 1429 } |
| 932 | 1430 |
| 933 // Test that setting a cookie which specifies an invalid domain has | 1431 // Test that setting a cookie which specifies an invalid domain has |
| 934 // no side-effect. An invalid domain in this context is one which does | 1432 // no side-effect. An invalid domain in this context is one which does |
| 935 // not match the originating domain. | 1433 // not match the originating domain. |
| 936 // http://b/issue?id=896472 | 1434 // http://b/issue?id=896472 |
| 937 TEST_F(CookieMonsterTest, InvalidDomainTest) { | 1435 TEST_F(CookieMonsterTest, InvalidDomainTest) { |
| 938 { | 1436 { |
| 939 scoped_refptr<MockPersistentCookieStore> store( | 1437 scoped_refptr<MockPersistentCookieStore> store( |
| 940 new MockPersistentCookieStore); | 1438 new MockPersistentCookieStore); |
| 941 | 1439 |
| 942 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1440 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 943 GURL url_foobar("http://foo.bar.com"); | 1441 GURL url_foobar("http://foo.bar.com"); |
| 944 | 1442 |
| 945 // More specific sub-domain than allowed. | 1443 // More specific sub-domain than allowed. |
| 946 EXPECT_FALSE(cm->SetCookie(url_foobar, "a=1; domain=.yo.foo.bar.com")); | 1444 EXPECT_FALSE(SetCookie(cm, url_foobar, "a=1; domain=.yo.foo.bar.com")); |
| 947 | 1445 |
| 948 EXPECT_FALSE(cm->SetCookie(url_foobar, "b=2; domain=.foo.com")); | 1446 EXPECT_FALSE(SetCookie(cm, url_foobar, "b=2; domain=.foo.com")); |
| 949 EXPECT_FALSE(cm->SetCookie(url_foobar, "c=3; domain=.bar.foo.com")); | 1447 EXPECT_FALSE(SetCookie(cm, url_foobar, "c=3; domain=.bar.foo.com")); |
| 950 | 1448 |
| 951 // Different TLD, but the rest is a substring. | 1449 // Different TLD, but the rest is a substring. |
| 952 EXPECT_FALSE(cm->SetCookie(url_foobar, "d=4; domain=.foo.bar.com.net")); | 1450 EXPECT_FALSE(SetCookie(cm, url_foobar, "d=4; domain=.foo.bar.com.net")); |
| 953 | 1451 |
| 954 // A substring that isn't really a parent domain. | 1452 // A substring that isn't really a parent domain. |
| 955 EXPECT_FALSE(cm->SetCookie(url_foobar, "e=5; domain=ar.com")); | 1453 EXPECT_FALSE(SetCookie(cm, url_foobar, "e=5; domain=ar.com")); |
| 956 | 1454 |
| 957 // Completely invalid domains: | 1455 // Completely invalid domains: |
| 958 EXPECT_FALSE(cm->SetCookie(url_foobar, "f=6; domain=.")); | 1456 EXPECT_FALSE(SetCookie(cm, url_foobar, "f=6; domain=.")); |
| 959 EXPECT_FALSE(cm->SetCookie(url_foobar, "g=7; domain=/")); | 1457 EXPECT_FALSE(SetCookie(cm, url_foobar, "g=7; domain=/")); |
| 960 EXPECT_FALSE(cm->SetCookie(url_foobar, "h=8; domain=http://foo.bar.com")); | 1458 EXPECT_FALSE(SetCookie(cm, url_foobar, "h=8; domain=http://foo.bar.com")); |
| 961 EXPECT_FALSE(cm->SetCookie(url_foobar, "i=9; domain=..foo.bar.com")); | 1459 EXPECT_FALSE(SetCookie(cm, url_foobar, "i=9; domain=..foo.bar.com")); |
| 962 EXPECT_FALSE(cm->SetCookie(url_foobar, "j=10; domain=..bar.com")); | 1460 EXPECT_FALSE(SetCookie(cm, url_foobar, "j=10; domain=..bar.com")); |
| 963 | 1461 |
| 964 // Make sure there isn't something quirky in the domain canonicalization | 1462 // Make sure there isn't something quirky in the domain canonicalization |
| 965 // that supports full URL semantics. | 1463 // that supports full URL semantics. |
| 966 EXPECT_FALSE(cm->SetCookie(url_foobar, "k=11; domain=.foo.bar.com?blah")); | 1464 EXPECT_FALSE(SetCookie(cm, url_foobar, "k=11; domain=.foo.bar.com?blah")); |
| 967 EXPECT_FALSE(cm->SetCookie(url_foobar, "l=12; domain=.foo.bar.com/blah")); | 1465 EXPECT_FALSE(SetCookie(cm, url_foobar, "l=12; domain=.foo.bar.com/blah")); |
| 968 EXPECT_FALSE(cm->SetCookie(url_foobar, "m=13; domain=.foo.bar.com:80")); | 1466 EXPECT_FALSE(SetCookie(cm, url_foobar, "m=13; domain=.foo.bar.com:80")); |
| 969 EXPECT_FALSE(cm->SetCookie(url_foobar, "n=14; domain=.foo.bar.com:")); | 1467 EXPECT_FALSE(SetCookie(cm, url_foobar, "n=14; domain=.foo.bar.com:")); |
| 970 EXPECT_FALSE(cm->SetCookie(url_foobar, "o=15; domain=.foo.bar.com#sup")); | 1468 EXPECT_FALSE(SetCookie(cm, url_foobar, "o=15; domain=.foo.bar.com#sup")); |
| 971 | 1469 |
| 972 EXPECT_EQ("", GetCookies(cm, url_foobar)); | 1470 EXPECT_EQ("", GetCookies(cm, url_foobar)); |
| 973 | 1471 |
| 974 // Nothing was persisted to the backing store. | 1472 // Nothing was persisted to the backing store. |
| 975 EXPECT_EQ(0u, store->commands().size()); | 1473 EXPECT_EQ(0u, store->commands().size()); |
| 976 } | 1474 } |
| 977 | 1475 |
| 978 { | 1476 { |
| 979 // Make sure the cookie code hasn't gotten its subdomain string handling | 1477 // Make sure the cookie code hasn't gotten its subdomain string handling |
| 980 // reversed, missed a suffix check, etc. It's important here that the two | 1478 // reversed, missed a suffix check, etc. It's important here that the two |
| 981 // hosts below have the same domain + registry. | 1479 // hosts below have the same domain + registry. |
| 982 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1480 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 983 GURL url_foocom("http://foo.com.com"); | 1481 GURL url_foocom("http://foo.com.com"); |
| 984 EXPECT_FALSE(cm->SetCookie(url_foocom, "a=1; domain=.foo.com.com.com")); | 1482 EXPECT_FALSE(SetCookie(cm, url_foocom, "a=1; domain=.foo.com.com.com")); |
| 985 EXPECT_EQ("", GetCookies(cm, url_foocom)); | 1483 EXPECT_EQ("", GetCookies(cm, url_foocom)); |
| 986 } | 1484 } |
| 987 } | 1485 } |
| 988 | 1486 |
| 989 // Test the behavior of omitting dot prefix from domain, should | 1487 // Test the behavior of omitting dot prefix from domain, should |
| 990 // function the same as FireFox. | 1488 // function the same as FireFox. |
| 991 // http://b/issue?id=889898 | 1489 // http://b/issue?id=889898 |
| 992 TEST_F(CookieMonsterTest, DomainWithoutLeadingDotTest) { | 1490 TEST_F(CookieMonsterTest, DomainWithoutLeadingDotTest) { |
| 993 { // The omission of dot results in setting a domain cookie. | 1491 { // The omission of dot results in setting a domain cookie. |
| 994 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1492 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 995 GURL url_hosted("http://manage.hosted.filefront.com"); | 1493 GURL url_hosted("http://manage.hosted.filefront.com"); |
| 996 GURL url_filefront("http://www.filefront.com"); | 1494 GURL url_filefront("http://www.filefront.com"); |
| 997 EXPECT_TRUE(cm->SetCookie(url_hosted, "sawAd=1; domain=filefront.com")); | 1495 EXPECT_TRUE(SetCookie(cm, url_hosted, "sawAd=1; domain=filefront.com")); |
| 998 EXPECT_EQ("sawAd=1", GetCookies(cm, url_hosted)); | 1496 EXPECT_EQ("sawAd=1", GetCookies(cm, url_hosted)); |
| 999 EXPECT_EQ("sawAd=1", GetCookies(cm, url_filefront)); | 1497 EXPECT_EQ("sawAd=1", GetCookies(cm, url_filefront)); |
| 1000 } | 1498 } |
| 1001 | 1499 |
| 1002 { // Even when the domains match exactly, don't consider it host cookie. | 1500 { // Even when the domains match exactly, don't consider it host cookie. |
| 1003 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1501 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1004 GURL url("http://www.google.com"); | 1502 GURL url("http://www.google.com"); |
| 1005 EXPECT_TRUE(cm->SetCookie(url, "a=1; domain=www.google.com")); | 1503 EXPECT_TRUE(SetCookie(cm, url, "a=1; domain=www.google.com")); |
| 1006 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1504 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1007 EXPECT_EQ("a=1", GetCookies(cm, GURL("http://sub.www.google.com"))); | 1505 EXPECT_EQ("a=1", GetCookies(cm, GURL("http://sub.www.google.com"))); |
| 1008 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.com"))); | 1506 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.com"))); |
| 1009 } | 1507 } |
| 1010 } | 1508 } |
| 1011 | 1509 |
| 1012 // Test that the domain specified in cookie string is treated case-insensitive | 1510 // Test that the domain specified in cookie string is treated case-insensitive |
| 1013 // http://b/issue?id=896475. | 1511 // http://b/issue?id=896475. |
| 1014 TEST_F(CookieMonsterTest, CaseInsensitiveDomainTest) { | 1512 TEST_F(CookieMonsterTest, CaseInsensitiveDomainTest) { |
| 1015 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1513 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1016 GURL url("http://www.google.com"); | 1514 GURL url("http://www.google.com"); |
| 1017 EXPECT_TRUE(cm->SetCookie(url, "a=1; domain=.GOOGLE.COM")); | 1515 EXPECT_TRUE(SetCookie(cm, url, "a=1; domain=.GOOGLE.COM")); |
| 1018 EXPECT_TRUE(cm->SetCookie(url, "b=2; domain=.wWw.gOOgLE.coM")); | 1516 EXPECT_TRUE(SetCookie(cm, url, "b=2; domain=.wWw.gOOgLE.coM")); |
| 1019 EXPECT_EQ("a=1; b=2", GetCookies(cm, url)); | 1517 EXPECT_EQ("a=1; b=2", GetCookies(cm, url)); |
| 1020 } | 1518 } |
| 1021 | 1519 |
| 1022 TEST_F(CookieMonsterTest, TestIpAddress) { | 1520 TEST_F(CookieMonsterTest, TestIpAddress) { |
| 1023 GURL url_ip("http://1.2.3.4/weee"); | 1521 GURL url_ip("http://1.2.3.4/weee"); |
| 1024 { | 1522 { |
| 1025 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1523 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1026 EXPECT_TRUE(cm->SetCookie(url_ip, kValidCookieLine)); | 1524 EXPECT_TRUE(SetCookie(cm, url_ip, kValidCookieLine)); |
| 1027 EXPECT_EQ("A=B", GetCookies(cm, url_ip)); | 1525 EXPECT_EQ("A=B", GetCookies(cm, url_ip)); |
| 1028 } | 1526 } |
| 1029 | 1527 |
| 1030 { // IP addresses should not be able to set domain cookies. | 1528 { // IP addresses should not be able to set domain cookies. |
| 1031 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1529 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1032 EXPECT_FALSE(cm->SetCookie(url_ip, "b=2; domain=.1.2.3.4")); | 1530 EXPECT_FALSE(SetCookie(cm, url_ip, "b=2; domain=.1.2.3.4")); |
| 1033 EXPECT_FALSE(cm->SetCookie(url_ip, "c=3; domain=.3.4")); | 1531 EXPECT_FALSE(SetCookie(cm, url_ip, "c=3; domain=.3.4")); |
| 1034 EXPECT_EQ("", GetCookies(cm, url_ip)); | 1532 EXPECT_EQ("", GetCookies(cm, url_ip)); |
| 1035 // It should be allowed to set a cookie if domain= matches the IP address | 1533 // It should be allowed to set a cookie if domain= matches the IP address |
| 1036 // exactly. This matches IE/Firefox, even though it seems a bit wrong. | 1534 // exactly. This matches IE/Firefox, even though it seems a bit wrong. |
| 1037 EXPECT_FALSE(cm->SetCookie(url_ip, "b=2; domain=1.2.3.3")); | 1535 EXPECT_FALSE(SetCookie(cm, url_ip, "b=2; domain=1.2.3.3")); |
| 1038 EXPECT_EQ("", GetCookies(cm, url_ip)); | 1536 EXPECT_EQ("", GetCookies(cm, url_ip)); |
| 1039 EXPECT_TRUE(cm->SetCookie(url_ip, "b=2; domain=1.2.3.4")); | 1537 EXPECT_TRUE(SetCookie(cm, url_ip, "b=2; domain=1.2.3.4")); |
| 1040 EXPECT_EQ("b=2", GetCookies(cm, url_ip)); | 1538 EXPECT_EQ("b=2", GetCookies(cm, url_ip)); |
| 1041 } | 1539 } |
| 1042 } | 1540 } |
| 1043 | 1541 |
| 1044 // Test host cookies, and setting of cookies on TLD. | 1542 // Test host cookies, and setting of cookies on TLD. |
| 1045 TEST_F(CookieMonsterTest, TestNonDottedAndTLD) { | 1543 TEST_F(CookieMonsterTest, TestNonDottedAndTLD) { |
| 1046 { | 1544 { |
| 1047 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1545 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1048 GURL url("http://com/"); | 1546 GURL url("http://com/"); |
| 1049 // Allow setting on "com", (but only as a host cookie). | 1547 // Allow setting on "com", (but only as a host cookie). |
| 1050 EXPECT_TRUE(cm->SetCookie(url, "a=1")); | 1548 EXPECT_TRUE(SetCookie(cm, url, "a=1")); |
| 1051 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.com")); | 1549 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.com")); |
| 1052 EXPECT_FALSE(cm->SetCookie(url, "c=3; domain=com")); | 1550 EXPECT_FALSE(SetCookie(cm, url, "c=3; domain=com")); |
| 1053 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1551 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1054 // Make sure it doesn't show up for a normal .com, it should be a host | 1552 // Make sure it doesn't show up for a normal .com, it should be a host |
| 1055 // not a domain cookie. | 1553 // not a domain cookie. |
| 1056 EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com/"))); | 1554 EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com/"))); |
| 1057 EXPECT_EQ("", GetCookies(cm, GURL("http://.com/"))); | 1555 EXPECT_EQ("", GetCookies(cm, GURL("http://.com/"))); |
| 1058 } | 1556 } |
| 1059 | 1557 |
| 1060 { // http://com. should be treated the same as http://com. | 1558 { // http://com. should be treated the same as http://com. |
| 1061 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1559 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1062 GURL url("http://com./index.html"); | 1560 GURL url("http://com./index.html"); |
| 1063 EXPECT_TRUE(cm->SetCookie(url, "a=1")); | 1561 EXPECT_TRUE(SetCookie(cm, url, "a=1")); |
| 1064 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1562 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1065 EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com./"))); | 1563 EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com./"))); |
| 1066 } | 1564 } |
| 1067 | 1565 |
| 1068 { // Should not be able to set host cookie from a subdomain. | 1566 { // Should not be able to set host cookie from a subdomain. |
| 1069 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1567 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1070 GURL url("http://a.b"); | 1568 GURL url("http://a.b"); |
| 1071 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.b")); | 1569 EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.b")); |
| 1072 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=b")); | 1570 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=b")); |
| 1073 EXPECT_EQ("", GetCookies(cm, url)); | 1571 EXPECT_EQ("", GetCookies(cm, url)); |
| 1074 } | 1572 } |
| 1075 | 1573 |
| 1076 { // Same test as above, but explicitly on a known TLD (com). | 1574 { // Same test as above, but explicitly on a known TLD (com). |
| 1077 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1575 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1078 GURL url("http://google.com"); | 1576 GURL url("http://google.com"); |
| 1079 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.com")); | 1577 EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.com")); |
| 1080 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=com")); | 1578 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=com")); |
| 1081 EXPECT_EQ("", GetCookies(cm, url)); | 1579 EXPECT_EQ("", GetCookies(cm, url)); |
| 1082 } | 1580 } |
| 1083 | 1581 |
| 1084 { // Make sure can't set cookie on TLD which is dotted. | 1582 { // Make sure can't set cookie on TLD which is dotted. |
| 1085 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1583 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1086 GURL url("http://google.co.uk"); | 1584 GURL url("http://google.co.uk"); |
| 1087 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.co.uk")); | 1585 EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.co.uk")); |
| 1088 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.uk")); | 1586 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.uk")); |
| 1089 EXPECT_EQ("", GetCookies(cm, url)); | 1587 EXPECT_EQ("", GetCookies(cm, url)); |
| 1090 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.co.uk"))); | 1588 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.co.uk"))); |
| 1091 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.uk"))); | 1589 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.uk"))); |
| 1092 } | 1590 } |
| 1093 | 1591 |
| 1094 { // Intranet URLs should only be able to set host cookies. | 1592 { // Intranet URLs should only be able to set host cookies. |
| 1095 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1593 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1096 GURL url("http://b"); | 1594 GURL url("http://b"); |
| 1097 EXPECT_TRUE(cm->SetCookie(url, "a=1")); | 1595 EXPECT_TRUE(SetCookie(cm, url, "a=1")); |
| 1098 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.b")); | 1596 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.b")); |
| 1099 EXPECT_FALSE(cm->SetCookie(url, "c=3; domain=b")); | 1597 EXPECT_FALSE(SetCookie(cm, url, "c=3; domain=b")); |
| 1100 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1598 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1101 } | 1599 } |
| 1102 } | 1600 } |
| 1103 | 1601 |
| 1104 // Test reading/writing cookies when the domain ends with a period, | 1602 // Test reading/writing cookies when the domain ends with a period, |
| 1105 // as in "www.google.com." | 1603 // as in "www.google.com." |
| 1106 TEST_F(CookieMonsterTest, TestHostEndsWithDot) { | 1604 TEST_F(CookieMonsterTest, TestHostEndsWithDot) { |
| 1107 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1605 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1108 GURL url("http://www.google.com"); | 1606 GURL url("http://www.google.com"); |
| 1109 GURL url_with_dot("http://www.google.com."); | 1607 GURL url_with_dot("http://www.google.com."); |
| 1110 EXPECT_TRUE(cm->SetCookie(url, "a=1")); | 1608 EXPECT_TRUE(SetCookie(cm, url, "a=1")); |
| 1111 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1609 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1112 | 1610 |
| 1113 // Do not share cookie space with the dot version of domain. | 1611 // Do not share cookie space with the dot version of domain. |
| 1114 // Note: this is not what FireFox does, but it _is_ what IE+Safari do. | 1612 // Note: this is not what FireFox does, but it _is_ what IE+Safari do. |
| 1115 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.www.google.com.")); | 1613 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.www.google.com.")); |
| 1116 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1614 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1117 | 1615 |
| 1118 EXPECT_TRUE(cm->SetCookie(url_with_dot, "b=2; domain=.google.com.")); | 1616 EXPECT_TRUE(SetCookie(cm, url_with_dot, "b=2; domain=.google.com.")); |
| 1119 EXPECT_EQ("b=2", GetCookies(cm, url_with_dot)); | 1617 EXPECT_EQ("b=2", GetCookies(cm, url_with_dot)); |
| 1120 | 1618 |
| 1121 // Make sure there weren't any side effects. | 1619 // Make sure there weren't any side effects. |
| 1122 EXPECT_EQ(GetCookies(cm, GURL("http://hopefully-no-cookies.com/")), ""); | 1620 EXPECT_EQ(GetCookies(cm, GURL("http://hopefully-no-cookies.com/")), ""); |
| 1123 EXPECT_EQ("", GetCookies(cm, GURL("http://.com/"))); | 1621 EXPECT_EQ("", GetCookies(cm, GURL("http://.com/"))); |
| 1124 } | 1622 } |
| 1125 | 1623 |
| 1126 TEST_F(CookieMonsterTest, InvalidScheme) { | 1624 TEST_F(CookieMonsterTest, InvalidScheme) { |
| 1127 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1625 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1128 EXPECT_FALSE(cm->SetCookie(GURL(kUrlFtp), kValidCookieLine)); | 1626 EXPECT_FALSE(SetCookie(cm, GURL(kUrlFtp), kValidCookieLine)); |
| 1129 } | 1627 } |
| 1130 | 1628 |
| 1131 TEST_F(CookieMonsterTest, InvalidScheme_Read) { | 1629 TEST_F(CookieMonsterTest, InvalidScheme_Read) { |
| 1132 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1630 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1133 EXPECT_TRUE(cm->SetCookie(GURL(kUrlGoogle), kValidDomainCookieLine)); | 1631 EXPECT_TRUE(SetCookie(cm, GURL(kUrlGoogle), kValidDomainCookieLine)); |
| 1134 EXPECT_EQ("", GetCookies(cm, GURL(kUrlFtp))); | 1632 EXPECT_EQ("", GetCookies(cm, GURL(kUrlFtp))); |
| 1135 } | 1633 } |
| 1136 | 1634 |
| 1137 TEST_F(CookieMonsterTest, PathTest) { | 1635 TEST_F(CookieMonsterTest, PathTest) { |
| 1138 std::string url("http://www.google.izzle"); | 1636 std::string url("http://www.google.izzle"); |
| 1139 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1637 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1140 EXPECT_TRUE(cm->SetCookie(GURL(url), "A=B; path=/wee")); | 1638 EXPECT_TRUE(SetCookie(cm, GURL(url), "A=B; path=/wee")); |
| 1141 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee"))); | 1639 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee"))); |
| 1142 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/"))); | 1640 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/"))); |
| 1143 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war"))); | 1641 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war"))); |
| 1144 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war/more/more"))); | 1642 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war/more/more"))); |
| 1145 EXPECT_EQ("", GetCookies(cm, GURL(url + "/weehee"))); | 1643 EXPECT_EQ("", GetCookies(cm, GURL(url + "/weehee"))); |
| 1146 EXPECT_EQ("", GetCookies(cm, GURL(url + "/"))); | 1644 EXPECT_EQ("", GetCookies(cm, GURL(url + "/"))); |
| 1147 | 1645 |
| 1148 // If we add a 0 length path, it should default to / | 1646 // If we add a 0 length path, it should default to / |
| 1149 EXPECT_TRUE(cm->SetCookie(GURL(url), "A=C; path=")); | 1647 EXPECT_TRUE(SetCookie(cm, GURL(url), "A=C; path=")); |
| 1150 EXPECT_EQ("A=B; A=C", GetCookies(cm, GURL(url + "/wee"))); | 1648 EXPECT_EQ("A=B; A=C", GetCookies(cm, GURL(url + "/wee"))); |
| 1151 EXPECT_EQ("A=C", GetCookies(cm, GURL(url + "/"))); | 1649 EXPECT_EQ("A=C", GetCookies(cm, GURL(url + "/"))); |
| 1152 } | 1650 } |
| 1153 | 1651 |
| 1154 TEST_F(CookieMonsterTest, HttpOnlyTest) { | 1652 TEST_F(CookieMonsterTest, HttpOnlyTest) { |
| 1155 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1653 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1156 CookieOptions options; | 1654 CookieOptions options; |
| 1157 options.set_include_httponly(); | 1655 options.set_include_httponly(); |
| 1158 | 1656 |
| 1159 // Create a httponly cookie. | 1657 // Create a httponly cookie. |
| 1160 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B; httponly", options)); | 1658 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B; httponly", options)); |
| 1161 | 1659 |
| 1162 // Check httponly read protection. | 1660 // Check httponly read protection. |
| 1163 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1661 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1164 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); | 1662 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); |
| 1165 | 1663 |
| 1166 // Check httponly overwrite protection. | 1664 // Check httponly overwrite protection. |
| 1167 EXPECT_FALSE(cm->SetCookie(url_google_, "A=C")); | 1665 EXPECT_FALSE(SetCookie(cm, url_google_, "A=C")); |
| 1168 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1666 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1169 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); | 1667 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); |
| 1170 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=C", options)); | 1668 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=C", options)); |
| 1171 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); | 1669 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); |
| 1172 | 1670 |
| 1173 // Check httponly create protection. | 1671 // Check httponly create protection. |
| 1174 EXPECT_FALSE(cm->SetCookie(url_google_, "B=A; httponly")); | 1672 EXPECT_FALSE(SetCookie(cm, url_google_, "B=A; httponly")); |
| 1175 EXPECT_EQ("A=C", GetCookiesWithOptions(cm, url_google_, options)); | 1673 EXPECT_EQ("A=C", GetCookiesWithOptions(cm, url_google_, options)); |
| 1176 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "B=A; httponly", options)); | 1674 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "B=A; httponly", options)); |
| 1177 EXPECT_EQ("A=C; B=A", GetCookiesWithOptions(cm, url_google_, options)); | 1675 EXPECT_EQ("A=C; B=A", GetCookiesWithOptions(cm, url_google_, options)); |
| 1178 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); | 1676 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); |
| 1179 } | 1677 } |
| 1180 | 1678 |
| 1181 TEST_F(CookieMonsterTest, GetCookiesWithInfo) { | 1679 TEST_F(CookieMonsterTest, GetCookiesWithInfo) { |
| 1182 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1680 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1183 CookieOptions options; | 1681 CookieOptions options; |
| 1184 | 1682 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 CookieMonster::DomainIsHostOnly(tests[i].str)); | 1815 CookieMonster::DomainIsHostOnly(tests[i].str)); |
| 1318 } | 1816 } |
| 1319 } | 1817 } |
| 1320 | 1818 |
| 1321 TEST_F(CookieMonsterTest, TestCookieDeletion) { | 1819 TEST_F(CookieMonsterTest, TestCookieDeletion) { |
| 1322 scoped_refptr<MockPersistentCookieStore> store( | 1820 scoped_refptr<MockPersistentCookieStore> store( |
| 1323 new MockPersistentCookieStore); | 1821 new MockPersistentCookieStore); |
| 1324 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1822 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 1325 | 1823 |
| 1326 // Create a session cookie. | 1824 // Create a session cookie. |
| 1327 EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine)); | 1825 EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
| 1328 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1826 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1329 // Delete it via Max-Age. | 1827 // Delete it via Max-Age. |
| 1330 EXPECT_TRUE(cm->SetCookie(url_google_, | 1828 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1331 std::string(kValidCookieLine) + "; max-age=0")); | 1829 std::string(kValidCookieLine) + "; max-age=0")); |
| 1332 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1830 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1333 | 1831 |
| 1334 // Create a session cookie. | 1832 // Create a session cookie. |
| 1335 EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine)); | 1833 EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
| 1336 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1834 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1337 // Delete it via Expires. | 1835 // Delete it via Expires. |
| 1338 EXPECT_TRUE(cm->SetCookie(url_google_, | 1836 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1339 std::string(kValidCookieLine) + | 1837 std::string(kValidCookieLine) + |
| 1340 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 1838 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
| 1341 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1839 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1342 | 1840 |
| 1343 // Create a persistent cookie. | 1841 // Create a persistent cookie. |
| 1344 EXPECT_TRUE(cm->SetCookie(url_google_, | 1842 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1345 std::string(kValidCookieLine) + | 1843 std::string(kValidCookieLine) + |
| 1346 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1844 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1347 ASSERT_EQ(1u, store->commands().size()); | 1845 ASSERT_EQ(1u, store->commands().size()); |
| 1348 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1846 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1349 | 1847 |
| 1350 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1848 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1351 // Delete it via Max-Age. | 1849 // Delete it via Max-Age. |
| 1352 EXPECT_TRUE(cm->SetCookie(url_google_, | 1850 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1353 std::string(kValidCookieLine) + "; max-age=0")); | 1851 std::string(kValidCookieLine) + "; max-age=0")); |
| 1354 ASSERT_EQ(2u, store->commands().size()); | 1852 ASSERT_EQ(2u, store->commands().size()); |
| 1355 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1853 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1356 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1854 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1357 | 1855 |
| 1358 // Create a persistent cookie. | 1856 // Create a persistent cookie. |
| 1359 EXPECT_TRUE(cm->SetCookie(url_google_, | 1857 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1360 std::string(kValidCookieLine) + | 1858 std::string(kValidCookieLine) + |
| 1361 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1859 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1362 ASSERT_EQ(3u, store->commands().size()); | 1860 ASSERT_EQ(3u, store->commands().size()); |
| 1363 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 1861 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 1364 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1862 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1365 // Delete it via Expires. | 1863 // Delete it via Expires. |
| 1366 EXPECT_TRUE(cm->SetCookie(url_google_, | 1864 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1367 std::string(kValidCookieLine) + | 1865 std::string(kValidCookieLine) + |
| 1368 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 1866 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
| 1369 ASSERT_EQ(4u, store->commands().size()); | 1867 ASSERT_EQ(4u, store->commands().size()); |
| 1370 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 1868 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 1371 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1869 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1372 | 1870 |
| 1373 // Create a persistent cookie. | 1871 // Create a persistent cookie. |
| 1374 EXPECT_TRUE(cm->SetCookie(url_google_, | 1872 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1375 std::string(kValidCookieLine) + | 1873 std::string(kValidCookieLine) + |
| 1376 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1874 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1377 ASSERT_EQ(5u, store->commands().size()); | 1875 ASSERT_EQ(5u, store->commands().size()); |
| 1378 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); | 1876 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
| 1379 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1877 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1380 // Delete it via Expires, with a unix epoch of 0. | 1878 // Delete it via Expires, with a unix epoch of 0. |
| 1381 EXPECT_TRUE(cm->SetCookie(url_google_, | 1879 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1382 std::string(kValidCookieLine) + | 1880 std::string(kValidCookieLine) + |
| 1383 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); | 1881 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); |
| 1384 ASSERT_EQ(6u, store->commands().size()); | 1882 ASSERT_EQ(6u, store->commands().size()); |
| 1385 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[5].type); | 1883 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[5].type); |
| 1386 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1884 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1387 } | 1885 } |
| 1388 | 1886 |
| 1389 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { | 1887 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { |
| 1390 scoped_refptr<MockPersistentCookieStore> store( | 1888 scoped_refptr<MockPersistentCookieStore> store( |
| 1391 new MockPersistentCookieStore); | 1889 new MockPersistentCookieStore); |
| 1392 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1890 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 1393 CookieOptions options; | 1891 CookieOptions options; |
| 1394 options.set_include_httponly(); | 1892 options.set_include_httponly(); |
| 1395 | 1893 |
| 1396 EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine)); | 1894 EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
| 1397 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1895 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1398 | 1896 |
| 1399 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "C=D; httponly", options)); | 1897 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "C=D; httponly", options)); |
| 1400 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm, url_google_, options)); | 1898 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm, url_google_, options)); |
| 1401 | 1899 |
| 1402 EXPECT_EQ(2, cm->DeleteAll(false)); | 1900 EXPECT_EQ(2, DeleteAll(cm)); |
| 1403 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); | 1901 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); |
| 1404 | 1902 |
| 1405 EXPECT_EQ(0u, store->commands().size()); | 1903 EXPECT_EQ(0u, store->commands().size()); |
| 1406 | 1904 |
| 1407 // Create a persistent cookie. | 1905 // Create a persistent cookie. |
| 1408 EXPECT_TRUE(cm->SetCookie(url_google_, | 1906 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1409 std::string(kValidCookieLine) + | 1907 std::string(kValidCookieLine) + |
| 1410 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1908 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1411 ASSERT_EQ(1u, store->commands().size()); | 1909 ASSERT_EQ(1u, store->commands().size()); |
| 1412 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1910 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1413 | 1911 |
| 1414 EXPECT_EQ(1, cm->DeleteAll(true)); // sync_to_store = true. | 1912 EXPECT_EQ(1, DeleteAll(cm)); // sync_to_store = true. |
| 1415 ASSERT_EQ(2u, store->commands().size()); | 1913 ASSERT_EQ(2u, store->commands().size()); |
| 1416 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1914 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1417 | 1915 |
| 1418 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); | 1916 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); |
| 1419 } | 1917 } |
| 1420 | 1918 |
| 1421 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1919 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 1422 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1920 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1423 Time now = Time::Now(); | 1921 Time now = Time::Now(); |
| 1424 | 1922 |
| 1425 // Nothing has been added so nothing should be deleted. | 1923 // Nothing has been added so nothing should be deleted. |
| 1426 EXPECT_EQ(0, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99), | 1924 EXPECT_EQ(0, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99), |
| 1427 Time(), false)); | 1925 Time())); |
| 1428 | 1926 |
| 1429 // Create 3 cookies with creation date of today, yesterday and the day before. | 1927 // Create 3 cookies with creation date of today, yesterday and the day before. |
| 1430 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now)); | 1928 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now)); |
| 1431 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday", | 1929 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday", |
| 1432 now - TimeDelta::FromDays(1))); | 1930 now - TimeDelta::FromDays(1))); |
| 1433 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore", | 1931 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore", |
| 1434 now - TimeDelta::FromDays(2))); | 1932 now - TimeDelta::FromDays(2))); |
| 1435 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays", | 1933 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays", |
| 1436 now - TimeDelta::FromDays(3))); | 1934 now - TimeDelta::FromDays(3))); |
| 1437 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek", | 1935 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek", |
| 1438 now - TimeDelta::FromDays(7))); | 1936 now - TimeDelta::FromDays(7))); |
| 1439 | 1937 |
| 1440 // Try to delete threedays and the daybefore. | 1938 // Try to delete threedays and the daybefore. |
| 1441 EXPECT_EQ(2, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(3), | 1939 EXPECT_EQ(2, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(3), |
| 1442 now - TimeDelta::FromDays(1), | 1940 now - TimeDelta::FromDays(1))); |
| 1443 false)); | |
| 1444 | 1941 |
| 1445 // Try to delete yesterday, also make sure that delete_end is not | 1942 // Try to delete yesterday, also make sure that delete_end is not |
| 1446 // inclusive. | 1943 // inclusive. |
| 1447 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(2), | 1944 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(2), |
| 1448 now, | 1945 now)); |
| 1449 false)); | |
| 1450 | 1946 |
| 1451 // Make sure the delete_begin is inclusive. | 1947 // Make sure the delete_begin is inclusive. |
| 1452 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(7), | 1948 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(7), |
| 1453 now, | 1949 now)); |
| 1454 false)); | |
| 1455 | 1950 |
| 1456 // Delete the last (now) item. | 1951 // Delete the last (now) item. |
| 1457 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, Time(), Time(), false)); | 1952 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, Time(), Time())); |
| 1458 | 1953 |
| 1459 // Really make sure everything is gone. | 1954 // Really make sure everything is gone. |
| 1460 EXPECT_EQ(0, cm->DeleteAll(false)); | 1955 EXPECT_EQ(0, DeleteAll(cm)); |
| 1461 } | 1956 } |
| 1462 | 1957 |
| 1463 TEST_F(CookieMonsterTest, TestSecure) { | 1958 TEST_F(CookieMonsterTest, TestSecure) { |
| 1464 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1959 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1465 | 1960 |
| 1466 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 1961 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 1467 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1962 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1468 EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_)); | 1963 EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_)); |
| 1469 | 1964 |
| 1470 EXPECT_TRUE(cm->SetCookie(url_google_secure_, "A=B; secure")); | 1965 EXPECT_TRUE(SetCookie(cm, url_google_secure_, "A=B; secure")); |
| 1471 // The secure should overwrite the non-secure. | 1966 // The secure should overwrite the non-secure. |
| 1472 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1967 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1473 EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_)); | 1968 EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_)); |
| 1474 | 1969 |
| 1475 EXPECT_TRUE(cm->SetCookie(url_google_secure_, "D=E; secure")); | 1970 EXPECT_TRUE(SetCookie(cm, url_google_secure_, "D=E; secure")); |
| 1476 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1971 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1477 EXPECT_EQ("A=B; D=E", GetCookies(cm, url_google_secure_)); | 1972 EXPECT_EQ("A=B; D=E", GetCookies(cm, url_google_secure_)); |
| 1478 | 1973 |
| 1479 EXPECT_TRUE(cm->SetCookie(url_google_secure_, "A=B")); | 1974 EXPECT_TRUE(SetCookie(cm, url_google_secure_, "A=B")); |
| 1480 // The non-secure should overwrite the secure. | 1975 // The non-secure should overwrite the secure. |
| 1481 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1976 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1482 EXPECT_EQ("D=E; A=B", GetCookies(cm, url_google_secure_)); | 1977 EXPECT_EQ("D=E; A=B", GetCookies(cm, url_google_secure_)); |
| 1483 } | 1978 } |
| 1484 | 1979 |
| 1485 static const int kLastAccessThresholdMilliseconds = 200; | 1980 static const int kLastAccessThresholdMilliseconds = 200; |
| 1486 | 1981 |
| 1487 TEST_F(CookieMonsterTest, TestLastAccess) { | 1982 TEST_F(CookieMonsterTest, TestLastAccess) { |
| 1488 scoped_refptr<CookieMonster> cm( | 1983 scoped_refptr<CookieMonster> cm( |
| 1489 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 1984 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); |
| 1490 | 1985 |
| 1491 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 1986 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 1492 const Time last_access_date(GetFirstCookieAccessDate(cm)); | 1987 const Time last_access_date(GetFirstCookieAccessDate(cm)); |
| 1493 | 1988 |
| 1494 // Reading the cookie again immediately shouldn't update the access date, | 1989 // Reading the cookie again immediately shouldn't update the access date, |
| 1495 // since we're inside the threshold. | 1990 // since we're inside the threshold. |
| 1496 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1991 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1497 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); | 1992 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); |
| 1498 | 1993 |
| 1499 // Reading after a short wait should update the access date. | 1994 // Reading after a short wait should update the access date. |
| 1500 base::PlatformThread::Sleep(kLastAccessThresholdMilliseconds + 20); | 1995 base::PlatformThread::Sleep(kLastAccessThresholdMilliseconds + 20); |
| 1501 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1996 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1502 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm)); | 1997 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm)); |
| 1503 } | 1998 } |
| 1504 | 1999 |
| 1505 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { | 2000 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { |
| 1506 TestHostGarbageCollectHelper( | 2001 TestHostGarbageCollectHelper( |
| 1507 CookieMonster::kDomainMaxCookies, CookieMonster::kDomainPurgeCookies, | 2002 CookieMonster::kDomainMaxCookies, CookieMonster::kDomainPurgeCookies, |
| 1508 CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1); | 2003 CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1); |
| 1509 TestHostGarbageCollectHelper( | 2004 TestHostGarbageCollectHelper( |
| 1510 CookieMonster::kDomainMaxCookies, CookieMonster::kDomainPurgeCookies, | 2005 CookieMonster::kDomainMaxCookies, CookieMonster::kDomainPurgeCookies, |
| 1511 CookieMonster::EKS_DISCARD_RECENT_AND_PURGE_DOMAIN); | 2006 CookieMonster::EKS_DISCARD_RECENT_AND_PURGE_DOMAIN); |
| 1512 } | 2007 } |
| 1513 | 2008 |
| 1514 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. | 2009 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. |
| 1515 TEST_F(CookieMonsterTest, NetUtilCookieTest) { | 2010 TEST_F(CookieMonsterTest, NetUtilCookieTest) { |
| 1516 const GURL test_url("http://mojo.jojo.google.izzle/"); | 2011 const GURL test_url("http://mojo.jojo.google.izzle/"); |
| 1517 | 2012 |
| 1518 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2013 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1519 | 2014 |
| 1520 EXPECT_TRUE(cm->SetCookie(test_url, "foo=bar")); | 2015 EXPECT_TRUE(SetCookie(cm, test_url, "foo=bar")); |
| 1521 std::string value = GetCookies(cm, test_url); | 2016 std::string value = GetCookies(cm, test_url); |
| 1522 EXPECT_EQ("foo=bar", value); | 2017 EXPECT_EQ("foo=bar", value); |
| 1523 | 2018 |
| 1524 // test that we can retrieve all cookies: | 2019 // test that we can retrieve all cookies: |
| 1525 EXPECT_TRUE(cm->SetCookie(test_url, "x=1")); | 2020 EXPECT_TRUE(SetCookie(cm, test_url, "x=1")); |
| 1526 EXPECT_TRUE(cm->SetCookie(test_url, "y=2")); | 2021 EXPECT_TRUE(SetCookie(cm, test_url, "y=2")); |
| 1527 | 2022 |
| 1528 std::string result = GetCookies(cm, test_url); | 2023 std::string result = GetCookies(cm, test_url); |
| 1529 EXPECT_FALSE(result.empty()); | 2024 EXPECT_FALSE(result.empty()); |
| 1530 EXPECT_NE(result.find("x=1"), std::string::npos) << result; | 2025 EXPECT_NE(result.find("x=1"), std::string::npos) << result; |
| 1531 EXPECT_NE(result.find("y=2"), std::string::npos) << result; | 2026 EXPECT_NE(result.find("y=2"), std::string::npos) << result; |
| 1532 } | 2027 } |
| 1533 | 2028 |
| 1534 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) { | 2029 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) { |
| 1535 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2030 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1536 | 2031 |
| 1537 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 2032 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 1538 EXPECT_TRUE(cm->SetCookie(url_google_, "C=D")); | 2033 EXPECT_TRUE(SetCookie(cm, url_google_, "C=D")); |
| 1539 EXPECT_TRUE(cm->SetCookie(url_google_, "E=F")); | 2034 EXPECT_TRUE(SetCookie(cm, url_google_, "E=F")); |
| 1540 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); | 2035 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); |
| 1541 | 2036 |
| 1542 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google_.host(), "C")); | 2037 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google_.host(), "C")); |
| 1543 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); | 2038 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); |
| 1544 | 2039 |
| 1545 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); | 2040 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); |
| 1546 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); | 2041 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); |
| 1547 } | 2042 } |
| 1548 | 2043 |
| 1549 TEST_F(CookieMonsterTest, SetCookieableSchemes) { | 2044 TEST_F(CookieMonsterTest, SetCookieableSchemes) { |
| 1550 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2045 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1551 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); | 2046 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); |
| 1552 | 2047 |
| 1553 // Only cm_foo should allow foo:// cookies. | 2048 // Only cm_foo should allow foo:// cookies. |
| 1554 const char* kSchemes[] = {"foo"}; | 2049 const char* kSchemes[] = {"foo"}; |
| 1555 cm_foo->SetCookieableSchemes(kSchemes, 1); | 2050 cm_foo->SetCookieableSchemes(kSchemes, 1); |
| 1556 | 2051 |
| 1557 GURL foo_url("foo://host/path"); | 2052 GURL foo_url("foo://host/path"); |
| 1558 GURL http_url("http://host/path"); | 2053 GURL http_url("http://host/path"); |
| 1559 | 2054 |
| 1560 EXPECT_TRUE(cm->SetCookie(http_url, "x=1")); | 2055 EXPECT_TRUE(SetCookie(cm, http_url, "x=1")); |
| 1561 EXPECT_FALSE(cm->SetCookie(foo_url, "x=1")); | 2056 EXPECT_FALSE(SetCookie(cm, foo_url, "x=1")); |
| 1562 EXPECT_TRUE(cm_foo->SetCookie(foo_url, "x=1")); | 2057 EXPECT_TRUE(SetCookie(cm_foo, foo_url, "x=1")); |
| 1563 EXPECT_FALSE(cm_foo->SetCookie(http_url, "x=1")); | 2058 EXPECT_FALSE(SetCookie(cm_foo, http_url, "x=1")); |
| 1564 } | 2059 } |
| 1565 | 2060 |
| 1566 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { | 2061 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { |
| 1567 scoped_refptr<CookieMonster> cm( | 2062 scoped_refptr<CookieMonster> cm( |
| 1568 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 2063 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); |
| 1569 | 2064 |
| 1570 // Create an httponly cookie. | 2065 // Create an httponly cookie. |
| 1571 CookieOptions options; | 2066 CookieOptions options; |
| 1572 options.set_include_httponly(); | 2067 options.set_include_httponly(); |
| 1573 | 2068 |
| 1574 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B; httponly", options)); | 2069 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B; httponly", options)); |
| 1575 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, | 2070 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, |
| 1576 "C=D; domain=.google.izzle", | 2071 "C=D; domain=.google.izzle", |
| 1577 options)); | 2072 options)); |
| 1578 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_secure_, | 2073 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_secure_, |
| 1579 "E=F; domain=.google.izzle; secure", | 2074 "E=F; domain=.google.izzle; secure", |
| 1580 options)); | 2075 options)); |
| 1581 | 2076 |
| 1582 const Time last_access_date(GetFirstCookieAccessDate(cm)); | 2077 const Time last_access_date(GetFirstCookieAccessDate(cm)); |
| 1583 | 2078 |
| 1584 base::PlatformThread::Sleep(kLastAccessThresholdMilliseconds + 20); | 2079 base::PlatformThread::Sleep(kLastAccessThresholdMilliseconds + 20); |
| 1585 | 2080 |
| 1586 // Check cookies for url. | 2081 // Check cookies for url. |
| 1587 CookieList cookies = GetAllCookiesForURL(cm, url_google_); | 2082 CookieList cookies = GetAllCookiesForURL(cm, url_google_); |
| 1588 CookieList::iterator it = cookies.begin(); | 2083 CookieList::iterator it = cookies.begin(); |
| 1589 | 2084 |
| 1590 ASSERT_TRUE(it != cookies.end()); | 2085 ASSERT_TRUE(it != cookies.end()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 | 2123 |
| 1629 // Reading after a short wait should not update the access date. | 2124 // Reading after a short wait should not update the access date. |
| 1630 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); | 2125 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); |
| 1631 } | 2126 } |
| 1632 | 2127 |
| 1633 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { | 2128 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { |
| 1634 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2129 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1635 CookieOptions options; | 2130 CookieOptions options; |
| 1636 | 2131 |
| 1637 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_foo_, | 2132 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_foo_, |
| 1638 "A=B; path=/foo;", | 2133 "A=B; path=/foo;", options)); |
| 1639 options)); | |
| 1640 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_bar_, | 2134 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_bar_, |
| 1641 "C=D; path=/bar;", | 2135 "C=D; path=/bar;", options)); |
| 1642 options)); | |
| 1643 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, | 2136 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, |
| 1644 "E=F;", | 2137 "E=F;", options)); |
| 1645 options)); | |
| 1646 | 2138 |
| 1647 CookieList cookies = GetAllCookiesForURL(cm, url_google_foo_); | 2139 CookieList cookies = GetAllCookiesForURL(cm, url_google_foo_); |
| 1648 CookieList::iterator it = cookies.begin(); | 2140 CookieList::iterator it = cookies.begin(); |
| 1649 | 2141 |
| 1650 ASSERT_TRUE(it != cookies.end()); | 2142 ASSERT_TRUE(it != cookies.end()); |
| 1651 EXPECT_EQ("A", it->Name()); | 2143 EXPECT_EQ("A", it->Name()); |
| 1652 EXPECT_EQ("/foo", it->Path()); | 2144 EXPECT_EQ("/foo", it->Path()); |
| 1653 | 2145 |
| 1654 ASSERT_TRUE(++it != cookies.end()); | 2146 ASSERT_TRUE(++it != cookies.end()); |
| 1655 EXPECT_EQ("E", it->Name()); | 2147 EXPECT_EQ("E", it->Name()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1667 ASSERT_TRUE(++it != cookies.end()); | 2159 ASSERT_TRUE(++it != cookies.end()); |
| 1668 EXPECT_EQ("E", it->Name()); | 2160 EXPECT_EQ("E", it->Name()); |
| 1669 EXPECT_EQ("/", it->Path()); | 2161 EXPECT_EQ("/", it->Path()); |
| 1670 | 2162 |
| 1671 ASSERT_TRUE(++it == cookies.end()); | 2163 ASSERT_TRUE(++it == cookies.end()); |
| 1672 } | 2164 } |
| 1673 | 2165 |
| 1674 TEST_F(CookieMonsterTest, DeleteCookieByName) { | 2166 TEST_F(CookieMonsterTest, DeleteCookieByName) { |
| 1675 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2167 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1676 | 2168 |
| 1677 EXPECT_TRUE(cm->SetCookie(url_google_, "A=A1; path=/")); | 2169 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A1; path=/")); |
| 1678 EXPECT_TRUE(cm->SetCookie(url_google_, "A=A2; path=/foo")); | 2170 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A2; path=/foo")); |
| 1679 EXPECT_TRUE(cm->SetCookie(url_google_, "A=A3; path=/bar")); | 2171 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A3; path=/bar")); |
| 1680 EXPECT_TRUE(cm->SetCookie(url_google_, "B=B1; path=/")); | 2172 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B1; path=/")); |
| 1681 EXPECT_TRUE(cm->SetCookie(url_google_, "B=B2; path=/foo")); | 2173 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B2; path=/foo")); |
| 1682 EXPECT_TRUE(cm->SetCookie(url_google_, "B=B3; path=/bar")); | 2174 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B3; path=/bar")); |
| 1683 | 2175 |
| 1684 DeleteCookie(cm, GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); | 2176 DeleteCookie(cm, GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); |
| 1685 | 2177 |
| 1686 CookieList cookies = GetAllCookies(cm); | 2178 CookieList cookies = GetAllCookies(cm); |
| 1687 size_t expected_size = 4; | 2179 size_t expected_size = 4; |
| 1688 EXPECT_EQ(expected_size, cookies.size()); | 2180 EXPECT_EQ(expected_size, cookies.size()); |
| 1689 for (CookieList::iterator it = cookies.begin(); | 2181 for (CookieList::iterator it = cookies.begin(); |
| 1690 it != cookies.end(); ++it) { | 2182 it != cookies.end(); ++it) { |
| 1691 EXPECT_NE("A1", it->Value()); | 2183 EXPECT_NE("A1", it->Value()); |
| 1692 EXPECT_NE("A2", it->Value()); | 2184 EXPECT_NE("A2", it->Value()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 // backing store. | 2227 // backing store. |
| 1736 TEST_F(CookieMonsterTest, OverwritePersistentCookie) { | 2228 TEST_F(CookieMonsterTest, OverwritePersistentCookie) { |
| 1737 GURL url_google("http://www.google.com/"); | 2229 GURL url_google("http://www.google.com/"); |
| 1738 GURL url_chromium("http://chromium.org"); | 2230 GURL url_chromium("http://chromium.org"); |
| 1739 scoped_refptr<MockPersistentCookieStore> store( | 2231 scoped_refptr<MockPersistentCookieStore> store( |
| 1740 new MockPersistentCookieStore); | 2232 new MockPersistentCookieStore); |
| 1741 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 2233 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 1742 | 2234 |
| 1743 // Insert a cookie "a" for path "/path1" | 2235 // Insert a cookie "a" for path "/path1" |
| 1744 EXPECT_TRUE( | 2236 EXPECT_TRUE( |
| 1745 cm->SetCookie(url_google, "a=val1; path=/path1; " | 2237 SetCookie(cm, url_google, "a=val1; path=/path1; " |
| 1746 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2238 "expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1747 ASSERT_EQ(1u, store->commands().size()); | 2239 ASSERT_EQ(1u, store->commands().size()); |
| 1748 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2240 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1749 | 2241 |
| 1750 // Insert a cookie "b" for path "/path1" | 2242 // Insert a cookie "b" for path "/path1" |
| 1751 EXPECT_TRUE( | 2243 EXPECT_TRUE( |
| 1752 cm->SetCookie(url_google, "b=val1; path=/path1; " | 2244 SetCookie(cm, url_google, "b=val1; path=/path1; " |
| 1753 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 2245 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 1754 ASSERT_EQ(2u, store->commands().size()); | 2246 ASSERT_EQ(2u, store->commands().size()); |
| 1755 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[1].type); | 2247 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[1].type); |
| 1756 | 2248 |
| 1757 // Insert a cookie "b" for path "/path1", that is httponly. This should | 2249 // Insert a cookie "b" for path "/path1", that is httponly. This should |
| 1758 // overwrite the non-http-only version. | 2250 // overwrite the non-http-only version. |
| 1759 CookieOptions allow_httponly; | 2251 CookieOptions allow_httponly; |
| 1760 allow_httponly.set_include_httponly(); | 2252 allow_httponly.set_include_httponly(); |
| 1761 EXPECT_TRUE( | 2253 EXPECT_TRUE( |
| 1762 SetCookieWithOptions(cm, url_google, | 2254 SetCookieWithOptions(cm, url_google, |
| 1763 "b=val2; path=/path1; httponly; " | 2255 "b=val2; path=/path1; httponly; " |
| 1764 "expires=Mon, 18-Apr-22 22:50:14 GMT", | 2256 "expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1765 allow_httponly)); | 2257 allow_httponly)); |
| 1766 ASSERT_EQ(4u, store->commands().size()); | 2258 ASSERT_EQ(4u, store->commands().size()); |
| 1767 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); | 2259 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); |
| 1768 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[3].type); | 2260 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[3].type); |
| 1769 | 2261 |
| 1770 // Insert a cookie "a" for path "/path1". This should overwrite. | 2262 // Insert a cookie "a" for path "/path1". This should overwrite. |
| 1771 EXPECT_TRUE(cm->SetCookie(url_google, | 2263 EXPECT_TRUE(SetCookie(cm, url_google, |
| 1772 "a=val33; path=/path1; " | 2264 "a=val33; path=/path1; " |
| 1773 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 2265 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 1774 ASSERT_EQ(6u, store->commands().size()); | 2266 ASSERT_EQ(6u, store->commands().size()); |
| 1775 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[4].type); | 2267 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[4].type); |
| 1776 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[5].type); | 2268 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[5].type); |
| 1777 | 2269 |
| 1778 // Insert a cookie "a" for path "/path2". This should NOT overwrite | 2270 // Insert a cookie "a" for path "/path2". This should NOT overwrite |
| 1779 // cookie "a", since the path is different. | 2271 // cookie "a", since the path is different. |
| 1780 EXPECT_TRUE(cm->SetCookie(url_google, | 2272 EXPECT_TRUE(SetCookie(cm, url_google, |
| 1781 "a=val9; path=/path2; " | 2273 "a=val9; path=/path2; " |
| 1782 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 2274 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 1783 ASSERT_EQ(7u, store->commands().size()); | 2275 ASSERT_EQ(7u, store->commands().size()); |
| 1784 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[6].type); | 2276 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[6].type); |
| 1785 | 2277 |
| 1786 // Insert a cookie "a" for path "/path1", but this time for "chromium.org". | 2278 // Insert a cookie "a" for path "/path1", but this time for "chromium.org". |
| 1787 // Although the name and path match, the hostnames do not, so shouldn't | 2279 // Although the name and path match, the hostnames do not, so shouldn't |
| 1788 // overwrite. | 2280 // overwrite. |
| 1789 EXPECT_TRUE(cm->SetCookie(url_chromium, | 2281 EXPECT_TRUE(SetCookie(cm, url_chromium, |
| 1790 "a=val99; path=/path1; " | 2282 "a=val99; path=/path1; " |
| 1791 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 2283 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 1792 ASSERT_EQ(8u, store->commands().size()); | 2284 ASSERT_EQ(8u, store->commands().size()); |
| 1793 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[7].type); | 2285 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[7].type); |
| 1794 | 2286 |
| 1795 EXPECT_EQ("a=val33", GetCookies(cm, GURL("http://www.google.com/path1"))); | 2287 EXPECT_EQ("a=val33", GetCookies(cm, GURL("http://www.google.com/path1"))); |
| 1796 EXPECT_EQ("a=val9", GetCookies(cm, GURL("http://www.google.com/path2"))); | 2288 EXPECT_EQ("a=val9", GetCookies(cm, GURL("http://www.google.com/path2"))); |
| 1797 EXPECT_EQ("a=val99", GetCookies(cm, GURL("http://chromium.org/path1"))); | 2289 EXPECT_EQ("a=val99", GetCookies(cm, GURL("http://chromium.org/path1"))); |
| 1798 } | 2290 } |
| 1799 | 2291 |
| 1800 // Tests importing from a persistent cookie store that contains duplicate | 2292 // Tests importing from a persistent cookie store that contains duplicate |
| 1801 // equivalent cookies. This situation should be handled by removing the | 2293 // equivalent cookies. This situation should be handled by removing the |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 EXPECT_NE(name1, name2); | 2414 EXPECT_NE(name1, name2); |
| 1923 } | 2415 } |
| 1924 | 2416 |
| 1925 TEST_F(CookieMonsterTest, Delegate) { | 2417 TEST_F(CookieMonsterTest, Delegate) { |
| 1926 scoped_refptr<MockPersistentCookieStore> store( | 2418 scoped_refptr<MockPersistentCookieStore> store( |
| 1927 new MockPersistentCookieStore); | 2419 new MockPersistentCookieStore); |
| 1928 scoped_refptr<MockCookieMonsterDelegate> delegate( | 2420 scoped_refptr<MockCookieMonsterDelegate> delegate( |
| 1929 new MockCookieMonsterDelegate); | 2421 new MockCookieMonsterDelegate); |
| 1930 scoped_refptr<CookieMonster> cm(new CookieMonster(store, delegate)); | 2422 scoped_refptr<CookieMonster> cm(new CookieMonster(store, delegate)); |
| 1931 | 2423 |
| 1932 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 2424 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 1933 EXPECT_TRUE(cm->SetCookie(url_google_, "C=D")); | 2425 EXPECT_TRUE(SetCookie(cm, url_google_, "C=D")); |
| 1934 EXPECT_TRUE(cm->SetCookie(url_google_, "E=F")); | 2426 EXPECT_TRUE(SetCookie(cm, url_google_, "E=F")); |
| 1935 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); | 2427 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); |
| 1936 ASSERT_EQ(3u, delegate->changes().size()); | 2428 ASSERT_EQ(3u, delegate->changes().size()); |
| 1937 EXPECT_FALSE(delegate->changes()[0].second); | 2429 EXPECT_FALSE(delegate->changes()[0].second); |
| 1938 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); | 2430 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); |
| 1939 EXPECT_EQ("A", delegate->changes()[0].first.Name()); | 2431 EXPECT_EQ("A", delegate->changes()[0].first.Name()); |
| 1940 EXPECT_EQ("B", delegate->changes()[0].first.Value()); | 2432 EXPECT_EQ("B", delegate->changes()[0].first.Value()); |
| 1941 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); | 2433 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); |
| 1942 EXPECT_FALSE(delegate->changes()[1].second); | 2434 EXPECT_FALSE(delegate->changes()[1].second); |
| 1943 EXPECT_EQ("C", delegate->changes()[1].first.Name()); | 2435 EXPECT_EQ("C", delegate->changes()[1].first.Name()); |
| 1944 EXPECT_EQ("D", delegate->changes()[1].first.Value()); | 2436 EXPECT_EQ("D", delegate->changes()[1].first.Value()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1956 EXPECT_EQ("C", delegate->changes()[0].first.Name()); | 2448 EXPECT_EQ("C", delegate->changes()[0].first.Name()); |
| 1957 EXPECT_EQ("D", delegate->changes()[0].first.Value()); | 2449 EXPECT_EQ("D", delegate->changes()[0].first.Value()); |
| 1958 delegate->reset(); | 2450 delegate->reset(); |
| 1959 | 2451 |
| 1960 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); | 2452 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); |
| 1961 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); | 2453 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); |
| 1962 EXPECT_EQ(0u, delegate->changes().size()); | 2454 EXPECT_EQ(0u, delegate->changes().size()); |
| 1963 | 2455 |
| 1964 // Insert a cookie "a" for path "/path1" | 2456 // Insert a cookie "a" for path "/path1" |
| 1965 EXPECT_TRUE( | 2457 EXPECT_TRUE( |
| 1966 cm->SetCookie(url_google_, "a=val1; path=/path1; " | 2458 SetCookie(cm, url_google_, "a=val1; path=/path1; " |
| 1967 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2459 "expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1968 ASSERT_EQ(1u, store->commands().size()); | 2460 ASSERT_EQ(1u, store->commands().size()); |
| 1969 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2461 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1970 ASSERT_EQ(1u, delegate->changes().size()); | 2462 ASSERT_EQ(1u, delegate->changes().size()); |
| 1971 EXPECT_FALSE(delegate->changes()[0].second); | 2463 EXPECT_FALSE(delegate->changes()[0].second); |
| 1972 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); | 2464 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); |
| 1973 EXPECT_EQ("a", delegate->changes()[0].first.Name()); | 2465 EXPECT_EQ("a", delegate->changes()[0].first.Name()); |
| 1974 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 2466 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1975 delegate->reset(); | 2467 delegate->reset(); |
| 1976 | 2468 |
| 1977 // Insert a cookie "a" for path "/path1", that is httponly. This should | 2469 // Insert a cookie "a" for path "/path1", that is httponly. This should |
| 1978 // overwrite the non-http-only version. | 2470 // overwrite the non-http-only version. |
| 1979 CookieOptions allow_httponly; | 2471 CookieOptions allow_httponly; |
| 1980 allow_httponly.set_include_httponly(); | 2472 allow_httponly.set_include_httponly(); |
| 1981 EXPECT_TRUE( | 2473 EXPECT_TRUE( |
| 1982 SetCookieWithOptions(cm, url_google_, | 2474 SetCookieWithOptions(cm, url_google_, |
| 1983 "a=val2; path=/path1; httponly; " | 2475 "a=val2; path=/path1; httponly; " |
| 1984 "expires=Mon, 18-Apr-22 22:50:14 GMT", | 2476 "expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1985 allow_httponly)); | 2477 allow_httponly)); |
| 1986 ASSERT_EQ(3u, store->commands().size()); | 2478 ASSERT_EQ(3u, store->commands().size()); |
| 1987 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 2479 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1988 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 2480 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 1989 ASSERT_EQ(2u, delegate->changes().size()); | 2481 ASSERT_EQ(2u, delegate->changes().size()); |
| 1990 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); | 2482 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); |
| 1991 EXPECT_TRUE(delegate->changes()[0].second); | 2483 EXPECT_TRUE(delegate->changes()[0].second); |
| 1992 EXPECT_EQ("a", delegate->changes()[0].first.Name()); | 2484 EXPECT_EQ("a", delegate->changes()[0].first.Name()); |
| 1993 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 2485 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1994 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); | 2486 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); |
| 1995 EXPECT_FALSE(delegate->changes()[1].second); | 2487 EXPECT_FALSE(delegate->changes()[1].second); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 CookieOptions options; | 2628 CookieOptions options; |
| 2137 | 2629 |
| 2138 // Add in three cookies through every public interface to the | 2630 // Add in three cookies through every public interface to the |
| 2139 // CookieMonster and confirm that none of them have duplicate | 2631 // CookieMonster and confirm that none of them have duplicate |
| 2140 // creation times. | 2632 // creation times. |
| 2141 | 2633 |
| 2142 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions | 2634 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions |
| 2143 // are not included as they aren't going to be public for very much | 2635 // are not included as they aren't going to be public for very much |
| 2144 // longer. | 2636 // longer. |
| 2145 | 2637 |
| 2146 // SetCookie, SetCookies, SetCookiesWithOptions, | 2638 // SetCookie, SetCookieWithOptions, SetCookieWithDetails |
| 2147 // SetCookieWithOptions, SetCookieWithDetails | |
| 2148 | 2639 |
| 2149 cm->SetCookie(url_google_, "SetCookie1=A"); | 2640 SetCookie(cm, url_google_, "SetCookie1=A"); |
| 2150 cm->SetCookie(url_google_, "SetCookie2=A"); | 2641 SetCookie(cm, url_google_, "SetCookie2=A"); |
| 2151 cm->SetCookie(url_google_, "SetCookie3=A"); | 2642 SetCookie(cm, url_google_, "SetCookie3=A"); |
| 2152 | |
| 2153 { | |
| 2154 std::vector<std::string> cookie_lines; | |
| 2155 cookie_lines.push_back("setCookies1=A"); | |
| 2156 cookie_lines.push_back("setCookies2=A"); | |
| 2157 cookie_lines.push_back("setCookies4=A"); | |
| 2158 cm->SetCookies(url_google_, cookie_lines); | |
| 2159 } | |
| 2160 | |
| 2161 { | |
| 2162 std::vector<std::string> cookie_lines; | |
| 2163 cookie_lines.push_back("setCookiesWithOptions1=A"); | |
| 2164 cookie_lines.push_back("setCookiesWithOptions2=A"); | |
| 2165 cookie_lines.push_back("setCookiesWithOptions3=A"); | |
| 2166 | |
| 2167 cm->SetCookiesWithOptions(url_google_, cookie_lines, options); | |
| 2168 } | |
| 2169 | 2643 |
| 2170 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions1=A", options); | 2644 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions1=A", options); |
| 2171 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions2=A", options); | 2645 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions2=A", options); |
| 2172 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions3=A", options); | 2646 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions3=A", options); |
| 2173 | 2647 |
| 2174 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails1", "A", | 2648 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails1", "A", |
| 2175 ".google.com", "/", Time(), false, false); | 2649 ".google.com", "/", Time(), false, false); |
| 2176 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails2", "A", | 2650 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails2", "A", |
| 2177 ".google.com", "/", Time(), false, false); | 2651 ".google.com", "/", Time(), false, false); |
| 2178 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails3", "A", | 2652 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails3", "A", |
| 2179 ".google.com", "/", Time(), false, false); | 2653 ".google.com", "/", Time(), false, false); |
| 2180 | 2654 |
| 2181 // Now we check | 2655 // Now we check |
| 2182 CookieList cookie_list(GetAllCookies(cm)); | 2656 CookieList cookie_list(GetAllCookies(cm)); |
| 2183 typedef std::map<int64, CookieMonster::CanonicalCookie> TimeCookieMap; | 2657 typedef std::map<int64, CookieMonster::CanonicalCookie> TimeCookieMap; |
| 2184 TimeCookieMap check_map; | 2658 TimeCookieMap check_map; |
| 2185 for (CookieList::const_iterator it = cookie_list.begin(); | 2659 for (CookieList::const_iterator it = cookie_list.begin(); |
| 2186 it != cookie_list.end(); it++) { | 2660 it != cookie_list.end(); it++) { |
| 2187 const int64 creation_date = it->CreationDate().ToInternalValue(); | 2661 const int64 creation_date = it->CreationDate().ToInternalValue(); |
| 2188 TimeCookieMap::const_iterator | 2662 TimeCookieMap::const_iterator |
| 2189 existing_cookie_it(check_map.find(creation_date)); | 2663 existing_cookie_it(check_map.find(creation_date)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2256 base::Time::Now() + base::TimeDelta::FromSeconds(100), | 2730 base::Time::Now() + base::TimeDelta::FromSeconds(100), |
| 2257 true, false} | 2731 true, false} |
| 2258 }; | 2732 }; |
| 2259 const int INPUT_DELETE = 1; | 2733 const int INPUT_DELETE = 1; |
| 2260 | 2734 |
| 2261 // Create new cookies and flush them to the store. | 2735 // Create new cookies and flush them to the store. |
| 2262 { | 2736 { |
| 2263 scoped_refptr<CookieMonster> cmout(new CookieMonster(store, NULL)); | 2737 scoped_refptr<CookieMonster> cmout(new CookieMonster(store, NULL)); |
| 2264 for (const CookiesInputInfo* p = input_info; | 2738 for (const CookiesInputInfo* p = input_info; |
| 2265 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) { | 2739 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) { |
| 2266 EXPECT_TRUE(cmout->SetCookieWithDetails(GURL(p->gurl), p->name, p->value, | 2740 EXPECT_TRUE(SetCookieWithDetails(cmout, GURL(p->gurl), p->name, p->value, |
| 2267 p->domain, p->path, p->expires, | 2741 p->domain, p->path, p->expires, |
| 2268 p->secure, p->http_only)); | 2742 p->secure, p->http_only)); |
| 2269 } | 2743 } |
| 2270 DeleteCookie(cmout, GURL(std::string(input_info[INPUT_DELETE].gurl) + | 2744 DeleteCookie(cmout, GURL(std::string(input_info[INPUT_DELETE].gurl) + |
| 2271 input_info[INPUT_DELETE].path), | 2745 input_info[INPUT_DELETE].path), |
| 2272 input_info[INPUT_DELETE].name); | 2746 input_info[INPUT_DELETE].name); |
| 2273 } | 2747 } |
| 2274 | 2748 |
| 2275 // Create a new cookie monster and make sure that everything is correct | 2749 // Create a new cookie monster and make sure that everything is correct |
| 2276 { | 2750 { |
| 2277 scoped_refptr<CookieMonster> cmin(new CookieMonster(store, NULL)); | 2751 scoped_refptr<CookieMonster> cmin(new CookieMonster(store, NULL)); |
| 2278 CookieList cookies(GetAllCookies(cmin)); | 2752 CookieList cookies(GetAllCookies(cmin)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2297 EXPECT_EQ(input->expires.ToInternalValue(), | 2771 EXPECT_EQ(input->expires.ToInternalValue(), |
| 2298 output->ExpiryDate().ToInternalValue()); | 2772 output->ExpiryDate().ToInternalValue()); |
| 2299 } | 2773 } |
| 2300 } | 2774 } |
| 2301 } | 2775 } |
| 2302 | 2776 |
| 2303 TEST_F(CookieMonsterTest, CookieOrdering) { | 2777 TEST_F(CookieMonsterTest, CookieOrdering) { |
| 2304 // Put a random set of cookies into a monster and make sure | 2778 // Put a random set of cookies into a monster and make sure |
| 2305 // they're returned in the right order. | 2779 // they're returned in the right order. |
| 2306 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2780 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2307 EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/x.html"), | 2781 EXPECT_TRUE(SetCookie(cm, GURL("http://d.c.b.a.google.com/aa/x.html"), |
| 2308 "c=1")); | 2782 "c=1")); |
| 2309 EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 2783 EXPECT_TRUE(SetCookie(cm, GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 2310 "d=1; domain=b.a.google.com")); | 2784 "d=1; domain=b.a.google.com")); |
| 2311 EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 2785 EXPECT_TRUE(SetCookie(cm, GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 2312 "a=4; domain=b.a.google.com")); | 2786 "a=4; domain=b.a.google.com")); |
| 2313 EXPECT_TRUE(cm->SetCookie(GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 2787 EXPECT_TRUE(SetCookie(cm, GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), |
| 2314 "e=1; domain=c.b.a.google.com")); | 2788 "e=1; domain=c.b.a.google.com")); |
| 2315 EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/bb/x.html"), | 2789 EXPECT_TRUE(SetCookie(cm, GURL("http://d.c.b.a.google.com/aa/bb/x.html"), |
| 2316 "b=1")); | 2790 "b=1")); |
| 2317 EXPECT_TRUE(cm->SetCookie(GURL("http://news.bbc.co.uk/midpath/x.html"), | 2791 EXPECT_TRUE(SetCookie(cm, GURL("http://news.bbc.co.uk/midpath/x.html"), |
| 2318 "g=10")); | 2792 "g=10")); |
| 2319 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", | 2793 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", |
| 2320 GetCookiesWithOptions(cm, | 2794 GetCookiesWithOptions( |
| 2321 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"), | 2795 cm, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"), |
| 2322 CookieOptions())); | 2796 CookieOptions())); |
| 2323 { | 2797 { |
| 2324 unsigned int i = 0; | 2798 unsigned int i = 0; |
| 2325 CookieList cookies(cm->GetAllCookiesForURL( | 2799 CookieList cookies(GetAllCookiesForURL( |
| 2326 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); | 2800 cm, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); |
| 2327 ASSERT_EQ(5u, cookies.size()); | 2801 ASSERT_EQ(5u, cookies.size()); |
| 2328 EXPECT_EQ("d", cookies[i++].Name()); | 2802 EXPECT_EQ("d", cookies[i++].Name()); |
| 2329 EXPECT_EQ("a", cookies[i++].Name()); | 2803 EXPECT_EQ("a", cookies[i++].Name()); |
| 2330 EXPECT_EQ("e", cookies[i++].Name()); | 2804 EXPECT_EQ("e", cookies[i++].Name()); |
| 2331 EXPECT_EQ("b", cookies[i++].Name()); | 2805 EXPECT_EQ("b", cookies[i++].Name()); |
| 2332 EXPECT_EQ("c", cookies[i++].Name()); | 2806 EXPECT_EQ("c", cookies[i++].Name()); |
| 2333 } | 2807 } |
| 2334 | 2808 |
| 2335 { | 2809 { |
| 2336 unsigned int i = 0; | 2810 unsigned int i = 0; |
| 2337 CookieList cookies(GetAllCookies(cm)); | 2811 CookieList cookies(GetAllCookies(cm)); |
| 2338 ASSERT_EQ(6u, cookies.size()); | 2812 ASSERT_EQ(6u, cookies.size()); |
| 2339 EXPECT_EQ("d", cookies[i++].Name()); | 2813 EXPECT_EQ("d", cookies[i++].Name()); |
| 2340 EXPECT_EQ("a", cookies[i++].Name()); | 2814 EXPECT_EQ("a", cookies[i++].Name()); |
| 2341 EXPECT_EQ("e", cookies[i++].Name()); | 2815 EXPECT_EQ("e", cookies[i++].Name()); |
| 2342 EXPECT_EQ("g", cookies[i++].Name()); | 2816 EXPECT_EQ("g", cookies[i++].Name()); |
| 2343 EXPECT_EQ("b", cookies[i++].Name()); | 2817 EXPECT_EQ("b", cookies[i++].Name()); |
| 2344 EXPECT_EQ("c", cookies[i++].Name()); | 2818 EXPECT_EQ("c", cookies[i++].Name()); |
| 2345 } | 2819 } |
| 2346 } | 2820 } |
| 2347 | 2821 |
| 2348 | |
| 2349 // Function for creating a CM with a number of cookies in it, | |
| 2350 // no store (and hence no ability to affect access time). | |
| 2351 static CookieMonster* CreateMonsterForGC(int num_cookies) { | |
| 2352 CookieMonster* cm(new CookieMonster(NULL, NULL)); | |
| 2353 for (int i = 0; i < num_cookies; i++) | |
| 2354 cm->SetCookie(GURL(StringPrintf("http://h%05d.izzle", i)), "a=1"); | |
| 2355 return cm; | |
| 2356 } | |
| 2357 | |
| 2358 // This test and CookieMonstertest.TestGCTimes (in cookie_monster_perftest.cc) | 2822 // This test and CookieMonstertest.TestGCTimes (in cookie_monster_perftest.cc) |
| 2359 // are somewhat complementary twins. This test is probing for whether | 2823 // are somewhat complementary twins. This test is probing for whether |
| 2360 // garbage collection always happens when it should (i.e. that we actually | 2824 // garbage collection always happens when it should (i.e. that we actually |
| 2361 // get rid of cookies when we should). The perftest is probing for | 2825 // get rid of cookies when we should). The perftest is probing for |
| 2362 // whether garbage collection happens when it shouldn't. See comments | 2826 // whether garbage collection happens when it shouldn't. See comments |
| 2363 // before that test for more details. | 2827 // before that test for more details. |
| 2364 TEST_F(CookieMonsterTest, GarbageCollectionTriggers) { | 2828 TEST_F(CookieMonsterTest, GarbageCollectionTriggers) { |
| 2365 // First we check to make sure that a whole lot of recent cookies | 2829 // First we check to make sure that a whole lot of recent cookies |
| 2366 // doesn't get rid of anything after garbage collection is checked for. | 2830 // doesn't get rid of anything after garbage collection is checked for. |
| 2367 { | 2831 { |
| 2368 scoped_refptr<CookieMonster> cm( | 2832 scoped_refptr<CookieMonster> cm( |
| 2369 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); | 2833 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); |
| 2370 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm).size()); | 2834 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm).size()); |
| 2371 cm->SetCookie(GURL("http://newdomain.com"), "b=2"); | 2835 SetCookie(cm, GURL("http://newdomain.com"), "b=2"); |
| 2372 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, GetAllCookies(cm).size()); | 2836 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, GetAllCookies(cm).size()); |
| 2373 } | 2837 } |
| 2374 | 2838 |
| 2375 // Now we explore a series of relationships between cookie last access | 2839 // Now we explore a series of relationships between cookie last access |
| 2376 // time and size of store to make sure we only get rid of cookies when | 2840 // time and size of store to make sure we only get rid of cookies when |
| 2377 // we really should. | 2841 // we really should. |
| 2378 const struct TestCase { | 2842 const struct TestCase { |
| 2379 int num_cookies; | 2843 int num_cookies; |
| 2380 int num_old_cookies; | 2844 int num_old_cookies; |
| 2381 int expected_initial_cookies; | 2845 int expected_initial_cookies; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2426 const TestCase *test_case = &test_cases[ci]; | 2890 const TestCase *test_case = &test_cases[ci]; |
| 2427 scoped_refptr<CookieMonster> cm( | 2891 scoped_refptr<CookieMonster> cm( |
| 2428 CreateMonsterFromStoreForGC( | 2892 CreateMonsterFromStoreForGC( |
| 2429 test_case->num_cookies, test_case->num_old_cookies, | 2893 test_case->num_cookies, test_case->num_old_cookies, |
| 2430 CookieMonster::kSafeFromGlobalPurgeDays * 2)); | 2894 CookieMonster::kSafeFromGlobalPurgeDays * 2)); |
| 2431 cm->SetExpiryAndKeyScheme(schemes[recent_scheme]); | 2895 cm->SetExpiryAndKeyScheme(schemes[recent_scheme]); |
| 2432 EXPECT_EQ(test_case->expected_initial_cookies, | 2896 EXPECT_EQ(test_case->expected_initial_cookies, |
| 2433 static_cast<int>(GetAllCookies(cm).size())) | 2897 static_cast<int>(GetAllCookies(cm).size())) |
| 2434 << "For test case " << ci; | 2898 << "For test case " << ci; |
| 2435 // Will trigger GC | 2899 // Will trigger GC |
| 2436 cm->SetCookie(GURL("http://newdomain.com"), "b=2"); | 2900 SetCookie(cm, GURL("http://newdomain.com"), "b=2"); |
| 2437 EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme], | 2901 EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme], |
| 2438 static_cast<int>((GetAllCookies(cm).size()))) | 2902 static_cast<int>((GetAllCookies(cm).size()))) |
| 2439 << "For test case (" << ci << ", " << recent_scheme << ")"; | 2903 << "For test case (" << ci << ", " << recent_scheme << ")"; |
| 2440 } | 2904 } |
| 2441 } | 2905 } |
| 2442 } | 2906 } |
| 2443 | 2907 |
| 2444 // This test checks that setting a cookie forcing it to be a session only | 2908 // This test checks that setting a cookie forcing it to be a session only |
| 2445 // cookie works as expected. | 2909 // cookie works as expected. |
| 2446 TEST_F(CookieMonsterTest, ForceSessionOnly) { | 2910 TEST_F(CookieMonsterTest, ForceSessionOnly) { |
| 2447 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2911 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2448 CookieOptions options; | 2912 CookieOptions options; |
| 2449 | 2913 |
| 2450 // Set a persistent cookie, but force it to be a session cookie. | 2914 // Set a persistent cookie, but force it to be a session cookie. |
| 2451 options.set_force_session(); | 2915 options.set_force_session(); |
| 2452 ASSERT_TRUE(SetCookieWithOptions(cm, url_google_, | 2916 ASSERT_TRUE(SetCookieWithOptions( |
| 2917 cm, url_google_, |
| 2453 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT", | 2918 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT", |
| 2454 options)); | 2919 options)); |
| 2455 | 2920 |
| 2456 // Get the canonical cookie. | 2921 // Get the canonical cookie. |
| 2457 CookieList cookie_list = GetAllCookies(cm); | 2922 CookieList cookie_list = GetAllCookies(cm); |
| 2458 ASSERT_EQ(1U, cookie_list.size()); | 2923 ASSERT_EQ(1U, cookie_list.size()); |
| 2459 ASSERT_FALSE(cookie_list[0].IsPersistent()); | 2924 ASSERT_FALSE(cookie_list[0].IsPersistent()); |
| 2460 | 2925 |
| 2461 // Use a past expiry date to delete the cookie, but force it to session only. | 2926 // Use a past expiry date to delete the cookie, but force it to session only. |
| 2462 ASSERT_TRUE(SetCookieWithOptions(cm, url_google_, | 2927 ASSERT_TRUE(SetCookieWithOptions( |
| 2928 cm, url_google_, |
| 2463 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", | 2929 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", |
| 2464 options)); | 2930 options)); |
| 2465 | 2931 |
| 2466 // Check that the cookie was deleted. | 2932 // Check that the cookie was deleted. |
| 2467 cookie_list = GetAllCookies(cm); | 2933 cookie_list = GetAllCookies(cm); |
| 2468 ASSERT_EQ(0U, cookie_list.size()); | 2934 ASSERT_EQ(0U, cookie_list.size()); |
| 2469 } | 2935 } |
| 2470 | 2936 |
| 2471 // This test checks that keep expired cookies flag is working. | 2937 // This test checks that keep expired cookies flag is working. |
| 2472 TEST_F(CookieMonsterTest, KeepExpiredCookies) { | 2938 TEST_F(CookieMonsterTest, KeepExpiredCookies) { |
| 2473 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2939 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2474 cm->SetKeepExpiredCookies(); | 2940 cm->SetKeepExpiredCookies(); |
| 2475 CookieOptions options; | 2941 CookieOptions options; |
| 2476 | 2942 |
| 2477 // Set a persistent cookie. | 2943 // Set a persistent cookie. |
| 2478 ASSERT_TRUE(SetCookieWithOptions(cm, url_google_, | 2944 ASSERT_TRUE(SetCookieWithOptions( |
| 2945 cm, url_google_, |
| 2479 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT", | 2946 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT", |
| 2480 options)); | 2947 options)); |
| 2481 | 2948 |
| 2482 // Get the canonical cookie. | 2949 // Get the canonical cookie. |
| 2483 CookieList cookie_list = GetAllCookies(cm); | 2950 CookieList cookie_list = GetAllCookies(cm); |
| 2484 ASSERT_EQ(1U, cookie_list.size()); | 2951 ASSERT_EQ(1U, cookie_list.size()); |
| 2485 | 2952 |
| 2486 // Use a past expiry date to delete the cookie. | 2953 // Use a past expiry date to delete the cookie. |
| 2487 ASSERT_TRUE(SetCookieWithOptions(cm, url_google_, | 2954 ASSERT_TRUE(SetCookieWithOptions( |
| 2955 cm, url_google_, |
| 2488 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", | 2956 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", |
| 2489 options)); | 2957 options)); |
| 2490 | 2958 |
| 2491 // Check that the cookie with the past expiry date is still there. | 2959 // Check that the cookie with the past expiry date is still there. |
| 2492 // GetAllCookies() also triggers garbage collection. | 2960 // GetAllCookies() also triggers garbage collection. |
| 2493 cookie_list = GetAllCookies(cm); | 2961 cookie_list = GetAllCookies(cm); |
| 2494 ASSERT_EQ(1U, cookie_list.size()); | 2962 ASSERT_EQ(1U, cookie_list.size()); |
| 2495 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); | 2963 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); |
| 2496 } | 2964 } |
| 2497 | 2965 |
| 2498 namespace { | 2966 namespace { |
| 2499 | 2967 |
| 2500 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. | 2968 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. |
| 2501 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { | 2969 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { |
| 2502 public: | 2970 public: |
| 2503 FlushablePersistentStore() : flush_count_(0) {} | 2971 FlushablePersistentStore() : flush_count_(0) {} |
| 2504 | 2972 |
| 2505 bool Load(std::vector<CookieMonster::CanonicalCookie*>*) { | 2973 bool Load(const LoadedCallback& loaded_callback) { |
| 2974 std::vector<CookieMonster::CanonicalCookie*> out_cookies; |
| 2975 loaded_callback.Run(out_cookies); |
| 2506 return false; | 2976 return false; |
| 2507 } | 2977 } |
| 2508 | 2978 |
| 2509 void AddCookie(const CookieMonster::CanonicalCookie&) {} | 2979 void AddCookie(const CookieMonster::CanonicalCookie&) {} |
| 2510 void UpdateCookieAccessTime(const CookieMonster::CanonicalCookie&) {} | 2980 void UpdateCookieAccessTime(const CookieMonster::CanonicalCookie&) {} |
| 2511 void DeleteCookie(const CookieMonster::CanonicalCookie&) {} | 2981 void DeleteCookie(const CookieMonster::CanonicalCookie&) {} |
| 2512 void SetClearLocalStateOnExit(bool clear_local_state) {} | 2982 void SetClearLocalStateOnExit(bool clear_local_state) {} |
| 2513 | 2983 |
| 2514 void Flush(Task* completion_callback) { | 2984 void Flush(Task* completion_callback) { |
| 2515 ++flush_count_; | 2985 ++flush_count_; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2645 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", | 3115 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", |
| 2646 base::Time::Now() + base::TimeDelta::FromMinutes(59), | 3116 base::Time::Now() + base::TimeDelta::FromMinutes(59), |
| 2647 false, false)); | 3117 false, false)); |
| 2648 | 3118 |
| 2649 base::Histogram::SampleSet histogram_set_2; | 3119 base::Histogram::SampleSet histogram_set_2; |
| 2650 expired_histogram->SnapshotSample(&histogram_set_2); | 3120 expired_histogram->SnapshotSample(&histogram_set_2); |
| 2651 EXPECT_EQ(histogram_set_1.TotalCount() + 1, | 3121 EXPECT_EQ(histogram_set_1.TotalCount() + 1, |
| 2652 histogram_set_2.TotalCount()); | 3122 histogram_set_2.TotalCount()); |
| 2653 | 3123 |
| 2654 // kValidCookieLine creates a session cookie. | 3124 // kValidCookieLine creates a session cookie. |
| 2655 ASSERT_TRUE(cm->SetCookie(url_google_, kValidCookieLine)); | 3125 ASSERT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
| 2656 expired_histogram->SnapshotSample(&histogram_set_1); | 3126 expired_histogram->SnapshotSample(&histogram_set_1); |
| 2657 EXPECT_EQ(histogram_set_2.TotalCount(), | 3127 EXPECT_EQ(histogram_set_2.TotalCount(), |
| 2658 histogram_set_1.TotalCount()); | 3128 histogram_set_1.TotalCount()); |
| 2659 } | 3129 } |
| 2660 | 3130 |
| 2661 namespace { | 3131 namespace { |
| 2662 | 3132 |
| 2663 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { | 3133 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { |
| 2664 public: | 3134 public: |
| 2665 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} | 3135 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} |
| 2666 | 3136 |
| 2667 // Helper methods for calling the asynchronous CookieMonster methods | 3137 // Helper methods for calling the asynchronous CookieMonster methods |
| 2668 // from a different thread. | 3138 // from a different thread. |
| 2669 | 3139 |
| 2670 void GetCookiesTask(CookieMonster* cm, | 3140 void GetCookiesTask(CookieMonster* cm, |
| 2671 const GURL& url, | 3141 const GURL& url, |
| 2672 GetCookieStringCallback* callback) { | 3142 GetCookieStringCallback* callback) { |
| 2673 cm->GetCookiesAsync( | 3143 cm->GetCookiesWithOptionsAsync( |
| 2674 url, | 3144 url, CookieOptions(), |
| 2675 base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback))); | 3145 base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback))); |
| 2676 } | 3146 } |
| 2677 | 3147 |
| 2678 void GetCookiesWithOptionsTask(CookieMonster* cm, | 3148 void GetCookiesWithOptionsTask(CookieMonster* cm, |
| 2679 const GURL& url, | 3149 const GURL& url, |
| 2680 const CookieOptions& options, | 3150 const CookieOptions& options, |
| 2681 GetCookieStringCallback* callback) { | 3151 GetCookieStringCallback* callback) { |
| 2682 cm->GetCookiesWithOptionsAsync( | 3152 cm->GetCookiesWithOptionsAsync( |
| 2683 url, options, | 3153 url, options, |
| 2684 base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback))); | 3154 base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback))); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2748 const std::string& cookie_name, | 3218 const std::string& cookie_name, |
| 2749 DeleteCookieCallback* callback) { | 3219 DeleteCookieCallback* callback) { |
| 2750 cm->DeleteCookieAsync( | 3220 cm->DeleteCookieAsync( |
| 2751 url, cookie_name, | 3221 url, cookie_name, |
| 2752 base::Bind(&DeleteCookieCallback::Run, base::Unretained(callback))); | 3222 base::Bind(&DeleteCookieCallback::Run, base::Unretained(callback))); |
| 2753 } | 3223 } |
| 2754 | 3224 |
| 2755 void DeleteAllCreatedBetweenTask(CookieMonster* cm, | 3225 void DeleteAllCreatedBetweenTask(CookieMonster* cm, |
| 2756 const base::Time& delete_begin, | 3226 const base::Time& delete_begin, |
| 2757 const base::Time& delete_end, | 3227 const base::Time& delete_end, |
| 2758 bool sync_to_store, | |
| 2759 DeleteCallback* callback) { | 3228 DeleteCallback* callback) { |
| 2760 cm->DeleteAllCreatedBetweenAsync( | 3229 cm->DeleteAllCreatedBetweenAsync( |
| 2761 delete_begin, delete_end, sync_to_store, | 3230 delete_begin, delete_end, |
| 2762 base::Bind(&DeleteCallback::Run, | 3231 base::Bind(&DeleteCallback::Run, |
| 2763 base::Unretained(callback))); | 3232 base::Unretained(callback))); |
| 2764 } | 3233 } |
| 2765 | 3234 |
| 2766 void DeleteAllForHostTask(CookieMonster* cm, | 3235 void DeleteAllForHostTask(CookieMonster* cm, |
| 2767 const GURL& url, | 3236 const GURL& url, |
| 2768 DeleteCallback* callback) { | 3237 DeleteCallback* callback) { |
| 2769 cm->DeleteAllForHostAsync( | 3238 cm->DeleteAllForHostAsync( |
| 2770 url, | 3239 url, |
| 2771 base::Bind(&DeleteCallback::Run, base::Unretained(callback))); | 3240 base::Bind(&DeleteCallback::Run, base::Unretained(callback))); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2791 }; | 3260 }; |
| 2792 | 3261 |
| 2793 } // namespace | 3262 } // namespace |
| 2794 | 3263 |
| 2795 // TODO(ycxiao): Eventually, we will need to create a separate thread, create | 3264 // TODO(ycxiao): Eventually, we will need to create a separate thread, create |
| 2796 // the cookie monster on that thread (or at least its store, i.e., the DB | 3265 // the cookie monster on that thread (or at least its store, i.e., the DB |
| 2797 // thread). | 3266 // thread). |
| 2798 | 3267 |
| 2799 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookies) { | 3268 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookies) { |
| 2800 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 3269 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2801 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 3270 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2802 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 3271 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 2803 GetCookieStringCallback callback(&other_thread_); | 3272 GetCookieStringCallback callback(&other_thread_); |
| 2804 base::Closure task = base::Bind( | 3273 base::Closure task = base::Bind( |
| 2805 &net::MultiThreadedCookieMonsterTest::GetCookiesTask, | 3274 &net::MultiThreadedCookieMonsterTest::GetCookiesTask, |
| 2806 base::Unretained(this), | 3275 base::Unretained(this), |
| 2807 cm, url_google_, &callback); | 3276 cm, url_google_, &callback); |
| 2808 RunOnOtherThread(task); | 3277 RunOnOtherThread(task); |
| 2809 EXPECT_TRUE(callback.did_run()); | 3278 EXPECT_TRUE(callback.did_run()); |
| 2810 EXPECT_EQ("A=B", callback.cookie()); | 3279 EXPECT_EQ("A=B", callback.cookie()); |
| 2811 } | 3280 } |
| 2812 | 3281 |
| 2813 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithOptions) { | 3282 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithOptions) { |
| 2814 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 3283 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2815 CookieOptions options; | 3284 CookieOptions options; |
| 2816 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 3285 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2817 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); | 3286 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); |
| 2818 GetCookieStringCallback callback(&other_thread_); | 3287 GetCookieStringCallback callback(&other_thread_); |
| 2819 base::Closure task = base::Bind( | 3288 base::Closure task = base::Bind( |
| 2820 &net::MultiThreadedCookieMonsterTest::GetCookiesWithOptionsTask, | 3289 &net::MultiThreadedCookieMonsterTest::GetCookiesWithOptionsTask, |
| 2821 base::Unretained(this), | 3290 base::Unretained(this), |
| 2822 cm, url_google_, options, &callback); | 3291 cm, url_google_, options, &callback); |
| 2823 RunOnOtherThread(task); | 3292 RunOnOtherThread(task); |
| 2824 EXPECT_TRUE(callback.did_run()); | 3293 EXPECT_TRUE(callback.did_run()); |
| 2825 EXPECT_EQ("A=B", callback.cookie()); | 3294 EXPECT_EQ("A=B", callback.cookie()); |
| 2826 } | 3295 } |
| 2827 | 3296 |
| 2828 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithInfo) { | 3297 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithInfo) { |
| 2829 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 3298 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2830 CookieOptions options; | 3299 CookieOptions options; |
| 2831 std::string cookie_line; | 3300 std::string cookie_line; |
| 2832 std::vector<CookieStore::CookieInfo> cookie_infos; | 3301 std::vector<CookieStore::CookieInfo> cookie_infos; |
| 2833 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 3302 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2834 GetCookiesWithInfo(cm, url_google_, options, &cookie_line, &cookie_infos); | 3303 GetCookiesWithInfo(cm, url_google_, options, &cookie_line, &cookie_infos); |
| 2835 EXPECT_EQ("A=B", cookie_line); | 3304 EXPECT_EQ("A=B", cookie_line); |
| 2836 EXPECT_EQ(1U, cookie_infos.size()); | 3305 EXPECT_EQ(1U, cookie_infos.size()); |
| 2837 EXPECT_EQ("A", cookie_infos[0].name); | 3306 EXPECT_EQ("A", cookie_infos[0].name); |
| 2838 EXPECT_EQ("", cookie_infos[0].mac_key); | 3307 EXPECT_EQ("", cookie_infos[0].mac_key); |
| 2839 EXPECT_EQ("", cookie_infos[0].mac_algorithm); | 3308 EXPECT_EQ("", cookie_infos[0].mac_algorithm); |
| 2840 GetCookiesWithInfoCallback callback(&other_thread_); | 3309 GetCookiesWithInfoCallback callback(&other_thread_); |
| 2841 base::Closure task = | 3310 base::Closure task = |
| 2842 base::Bind(&net::MultiThreadedCookieMonsterTest::GetCookiesWithInfoTask, | 3311 base::Bind(&net::MultiThreadedCookieMonsterTest::GetCookiesWithInfoTask, |
| 2843 base::Unretained(this), | 3312 base::Unretained(this), |
| 2844 cm, url_google_, options, &callback); | 3313 cm, url_google_, options, &callback); |
| 2845 RunOnOtherThread(task); | 3314 RunOnOtherThread(task); |
| 2846 EXPECT_TRUE(callback.did_run()); | 3315 EXPECT_TRUE(callback.did_run()); |
| 2847 EXPECT_EQ("A=B", callback.cookie_line()); | 3316 EXPECT_EQ("A=B", callback.cookie_line()); |
| 2848 EXPECT_EQ(1U, callback.cookie_info().size()); | 3317 EXPECT_EQ(1U, callback.cookie_info().size()); |
| 2849 EXPECT_EQ("A", callback.cookie_info()[0].name); | 3318 EXPECT_EQ("A", callback.cookie_info()[0].name); |
| 2850 EXPECT_EQ("", callback.cookie_info()[0].mac_key); | 3319 EXPECT_EQ("", callback.cookie_info()[0].mac_key); |
| 2851 EXPECT_EQ("", callback.cookie_info()[0].mac_algorithm); | 3320 EXPECT_EQ("", callback.cookie_info()[0].mac_algorithm); |
| 2852 } | 3321 } |
| 2853 | 3322 |
| 2854 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { | 3323 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { |
| 2855 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 3324 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2856 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 3325 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2857 CookieList cookies = GetAllCookies(cm); | 3326 CookieList cookies = GetAllCookies(cm); |
| 2858 CookieList::const_iterator it = cookies.begin(); | 3327 CookieList::const_iterator it = cookies.begin(); |
| 2859 ASSERT_TRUE(it != cookies.end()); | 3328 ASSERT_TRUE(it != cookies.end()); |
| 2860 EXPECT_EQ("www.google.izzle", it->Domain()); | 3329 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2861 EXPECT_EQ("A", it->Name()); | 3330 EXPECT_EQ("A", it->Name()); |
| 2862 ASSERT_TRUE(++it == cookies.end()); | 3331 ASSERT_TRUE(++it == cookies.end()); |
| 2863 GetCookieListCallback callback(&other_thread_); | 3332 GetCookieListCallback callback(&other_thread_); |
| 2864 base::Closure task = | 3333 base::Closure task = |
| 2865 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, | 3334 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, |
| 2866 base::Unretained(this), | 3335 base::Unretained(this), |
| 2867 cm, &callback); | 3336 cm, &callback); |
| 2868 RunOnOtherThread(task); | 3337 RunOnOtherThread(task); |
| 2869 EXPECT_TRUE(callback.did_run()); | 3338 EXPECT_TRUE(callback.did_run()); |
| 2870 it = callback.cookies().begin(); | 3339 it = callback.cookies().begin(); |
| 2871 ASSERT_TRUE(it != callback.cookies().end()); | 3340 ASSERT_TRUE(it != callback.cookies().end()); |
| 2872 EXPECT_EQ("www.google.izzle", it->Domain()); | 3341 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2873 EXPECT_EQ("A", it->Name()); | 3342 EXPECT_EQ("A", it->Name()); |
| 2874 ASSERT_TRUE(++it == callback.cookies().end()); | 3343 ASSERT_TRUE(++it == callback.cookies().end()); |
| 2875 } | 3344 } |
| 2876 | 3345 |
| 2877 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { | 3346 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { |
| 2878 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 3347 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2879 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 3348 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2880 CookieList cookies = GetAllCookiesForURL(cm, url_google_); | 3349 CookieList cookies = GetAllCookiesForURL(cm, url_google_); |
| 2881 CookieList::const_iterator it = cookies.begin(); | 3350 CookieList::const_iterator it = cookies.begin(); |
| 2882 ASSERT_TRUE(it != cookies.end()); | 3351 ASSERT_TRUE(it != cookies.end()); |
| 2883 EXPECT_EQ("www.google.izzle", it->Domain()); | 3352 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2884 EXPECT_EQ("A", it->Name()); | 3353 EXPECT_EQ("A", it->Name()); |
| 2885 ASSERT_TRUE(++it == cookies.end()); | 3354 ASSERT_TRUE(++it == cookies.end()); |
| 2886 GetCookieListCallback callback(&other_thread_); | 3355 GetCookieListCallback callback(&other_thread_); |
| 2887 base::Closure task = | 3356 base::Closure task = |
| 2888 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, | 3357 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, |
| 2889 base::Unretained(this), | 3358 base::Unretained(this), |
| 2890 cm, url_google_, &callback); | 3359 cm, url_google_, &callback); |
| 2891 RunOnOtherThread(task); | 3360 RunOnOtherThread(task); |
| 2892 EXPECT_TRUE(callback.did_run()); | 3361 EXPECT_TRUE(callback.did_run()); |
| 2893 it = callback.cookies().begin(); | 3362 it = callback.cookies().begin(); |
| 2894 ASSERT_TRUE(it != callback.cookies().end()); | 3363 ASSERT_TRUE(it != callback.cookies().end()); |
| 2895 EXPECT_EQ("www.google.izzle", it->Domain()); | 3364 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2896 EXPECT_EQ("A", it->Name()); | 3365 EXPECT_EQ("A", it->Name()); |
| 2897 ASSERT_TRUE(++it == callback.cookies().end()); | 3366 ASSERT_TRUE(++it == callback.cookies().end()); |
| 2898 } | 3367 } |
| 2899 | 3368 |
| 2900 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { | 3369 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { |
| 2901 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 3370 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2902 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 3371 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2903 CookieOptions options; | 3372 CookieOptions options; |
| 2904 CookieList cookies = | 3373 CookieList cookies = |
| 2905 GetAllCookiesForURLWithOptions(cm, url_google_, options); | 3374 GetAllCookiesForURLWithOptions(cm, url_google_, options); |
| 2906 CookieList::const_iterator it = cookies.begin(); | 3375 CookieList::const_iterator it = cookies.begin(); |
| 2907 ASSERT_TRUE(it != cookies.end()); | 3376 ASSERT_TRUE(it != cookies.end()); |
| 2908 EXPECT_EQ("www.google.izzle", it->Domain()); | 3377 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2909 EXPECT_EQ("A", it->Name()); | 3378 EXPECT_EQ("A", it->Name()); |
| 2910 ASSERT_TRUE(++it == cookies.end()); | 3379 ASSERT_TRUE(++it == cookies.end()); |
| 2911 GetCookieListCallback callback(&other_thread_); | 3380 GetCookieListCallback callback(&other_thread_); |
| 2912 base::Closure task = base::Bind( | 3381 base::Closure task = base::Bind( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2966 RunOnOtherThread(task); | 3435 RunOnOtherThread(task); |
| 2967 EXPECT_TRUE(callback.did_run()); | 3436 EXPECT_TRUE(callback.did_run()); |
| 2968 } | 3437 } |
| 2969 | 3438 |
| 2970 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { | 3439 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { |
| 2971 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 3440 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2972 CookieOptions options; | 3441 CookieOptions options; |
| 2973 Time now = Time::Now(); | 3442 Time now = Time::Now(); |
| 2974 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); | 3443 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); |
| 2975 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99), | 3444 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99), |
| 2976 Time(), false)); | 3445 Time())); |
| 2977 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); | 3446 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); |
| 2978 DeleteCallback callback(&other_thread_); | 3447 DeleteCallback callback(&other_thread_); |
| 2979 base::Closure task = base::Bind( | 3448 base::Closure task = base::Bind( |
| 2980 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, | 3449 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, |
| 2981 base::Unretained(this), | 3450 base::Unretained(this), |
| 2982 cm, now - TimeDelta::FromDays(99), | 3451 cm, now - TimeDelta::FromDays(99), |
| 2983 Time(), false, &callback); | 3452 Time(), &callback); |
| 2984 RunOnOtherThread(task); | 3453 RunOnOtherThread(task); |
| 2985 EXPECT_TRUE(callback.did_run()); | 3454 EXPECT_TRUE(callback.did_run()); |
| 2986 EXPECT_EQ(1, callback.num_deleted()); | 3455 EXPECT_EQ(1, callback.num_deleted()); |
| 2987 } | 3456 } |
| 2988 | 3457 |
| 2989 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { | 3458 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { |
| 2990 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 3459 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2991 CookieOptions options; | 3460 CookieOptions options; |
| 2992 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); | 3461 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); |
| 2993 EXPECT_EQ(1, DeleteAllForHost(cm, url_google_)); | 3462 EXPECT_EQ(1, DeleteAllForHost(cm, url_google_)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3017 base::Closure task = base::Bind( | 3486 base::Closure task = base::Bind( |
| 3018 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, | 3487 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, |
| 3019 base::Unretained(this), | 3488 base::Unretained(this), |
| 3020 cm, *it, &callback); | 3489 cm, *it, &callback); |
| 3021 RunOnOtherThread(task); | 3490 RunOnOtherThread(task); |
| 3022 EXPECT_TRUE(callback.did_run()); | 3491 EXPECT_TRUE(callback.did_run()); |
| 3023 EXPECT_TRUE(callback.result()); | 3492 EXPECT_TRUE(callback.result()); |
| 3024 } | 3493 } |
| 3025 | 3494 |
| 3026 } // namespace net | 3495 } // namespace net |
| OLD | NEW |