| 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" |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 url_google_bar_(kUrlGoogleBar), | 492 url_google_bar_(kUrlGoogleBar), |
| 493 message_loop_factory_(MessageLoop::current()) {} | 493 message_loop_factory_(MessageLoop::current()) {} |
| 494 | 494 |
| 495 // Helper methods for the asynchronous Cookie Store API that call the | 495 // Helper methods for the asynchronous Cookie Store API that call the |
| 496 // asynchronous method and then pump the loop until the callback is invoked, | 496 // asynchronous method and then pump the loop until the callback is invoked, |
| 497 // finally returning the value. | 497 // finally returning the value. |
| 498 | 498 |
| 499 std::string GetCookies(CookieMonster* cm, const GURL& url) { | 499 std::string GetCookies(CookieMonster* cm, const GURL& url) { |
| 500 DCHECK(cm); | 500 DCHECK(cm); |
| 501 GetCookieStringCallback callback; | 501 GetCookieStringCallback callback; |
| 502 cm->GetCookiesAsync( | 502 cm->GetCookiesWithOptionsAsync( |
| 503 url, base::Bind(&GetCookieStringCallback::Run, | 503 url, CookieOptions(), base::Bind(&GetCookieStringCallback::Run, |
| 504 base::Unretained(&callback))); | 504 base::Unretained(&callback))); |
| 505 RunFor(kTimeout); | 505 RunFor(kTimeout); |
| 506 EXPECT_TRUE(callback.did_run()); | 506 EXPECT_TRUE(callback.did_run()); |
| 507 return callback.cookie(); | 507 return callback.cookie(); |
| 508 } | 508 } |
| 509 | 509 |
| 510 std::string GetCookiesWithOptions(CookieMonster* cm, | 510 std::string GetCookiesWithOptions(CookieMonster* cm, |
| 511 const GURL& url, | 511 const GURL& url, |
| 512 const CookieOptions& options) { | 512 const CookieOptions& options) { |
| 513 DCHECK(cm); | 513 DCHECK(cm); |
| 514 GetCookieStringCallback callback; | 514 GetCookieStringCallback callback; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 DCHECK(cm); | 582 DCHECK(cm); |
| 583 SetCookieCallback callback; | 583 SetCookieCallback callback; |
| 584 cm->SetCookieWithOptionsAsync( | 584 cm->SetCookieWithOptionsAsync( |
| 585 url, cookie_line, options, | 585 url, cookie_line, options, |
| 586 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); | 586 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); |
| 587 RunFor(kTimeout); | 587 RunFor(kTimeout); |
| 588 EXPECT_TRUE(callback.did_run()); | 588 EXPECT_TRUE(callback.did_run()); |
| 589 return callback.result(); | 589 return callback.result(); |
| 590 } | 590 } |
| 591 | 591 |
| 592 bool SetCookie(CookieMonster* cm, |
| 593 const GURL& url, |
| 594 const std::string& cookie_line) { |
| 595 CookieOptions options; |
| 596 return SetCookieWithOptions(cm, url, cookie_line, options); |
| 597 } |
| 598 |
| 592 bool SetCookieWithDetails(CookieMonster* cm, | 599 bool SetCookieWithDetails(CookieMonster* cm, |
| 593 const GURL& url, | 600 const GURL& url, |
| 594 const std::string& name, | 601 const std::string& name, |
| 595 const std::string& value, | 602 const std::string& value, |
| 596 const std::string& domain, | 603 const std::string& domain, |
| 597 const std::string& path, | 604 const std::string& path, |
| 598 const base::Time& expiration_time, | 605 const base::Time& expiration_time, |
| 599 bool secure, bool http_only) { | 606 bool secure, bool http_only) { |
| 600 DCHECK(cm); | 607 DCHECK(cm); |
| 601 SetCookieCallback callback; | 608 SetCookieCallback callback; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 612 const std::string& cookie_name) { | 619 const std::string& cookie_name) { |
| 613 DCHECK(cm); | 620 DCHECK(cm); |
| 614 DeleteCookieCallback callback; | 621 DeleteCookieCallback callback; |
| 615 cm->DeleteCookieAsync(url, cookie_name, | 622 cm->DeleteCookieAsync(url, cookie_name, |
| 616 base::Bind(&DeleteCookieCallback::Run, | 623 base::Bind(&DeleteCookieCallback::Run, |
| 617 base::Unretained(&callback))); | 624 base::Unretained(&callback))); |
| 618 RunFor(kTimeout); | 625 RunFor(kTimeout); |
| 619 EXPECT_TRUE(callback.did_run()); | 626 EXPECT_TRUE(callback.did_run()); |
| 620 } | 627 } |
| 621 | 628 |
| 629 int DeleteAll(CookieMonster*cm, bool sync_to_store) { |
| 630 DCHECK(cm); |
| 631 DeleteCallback callback; |
| 632 cm->DeleteAllAsync( |
| 633 sync_to_store, |
| 634 base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); |
| 635 RunFor(kTimeout); |
| 636 EXPECT_TRUE(callback.did_run()); |
| 637 return callback.num_deleted(); |
| 638 } |
| 639 |
| 622 int DeleteAllCreatedBetween(CookieMonster*cm, | 640 int DeleteAllCreatedBetween(CookieMonster*cm, |
| 623 const base::Time& delete_begin, | 641 const base::Time& delete_begin, |
| 624 const base::Time& delete_end, | 642 const base::Time& delete_end, |
| 625 bool sync_to_store) { | 643 bool sync_to_store) { |
| 626 DCHECK(cm); | 644 DCHECK(cm); |
| 627 DeleteCallback callback; | 645 DeleteCallback callback; |
| 628 cm->DeleteAllCreatedBetweenAsync( | 646 cm->DeleteAllCreatedBetweenAsync( |
| 629 delete_begin, delete_end, sync_to_store, | 647 delete_begin, delete_end, sync_to_store, |
| 630 base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); | 648 base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); |
| 631 RunFor(kTimeout); | 649 RunFor(kTimeout); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 | 686 |
| 669 // Helper for DeleteAllForHost test; repopulates CM with same layout | 687 // Helper for DeleteAllForHost test; repopulates CM with same layout |
| 670 // each time. | 688 // each time. |
| 671 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { | 689 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { |
| 672 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); | 690 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); |
| 673 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); | 691 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); |
| 674 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); | 692 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); |
| 675 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); | 693 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); |
| 676 GURL url_other(kOtherDomain); | 694 GURL url_other(kOtherDomain); |
| 677 | 695 |
| 678 cm->DeleteAll(true); | 696 DeleteAll(cm, true); |
| 679 | 697 |
| 680 // Static population for probe: | 698 // Static population for probe: |
| 681 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) | 699 // * 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) | 700 // * 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) | 701 // * http_only cookie (w.c.b.a) |
| 684 // * Two secure cookies (.c.b.a, w.c.b.a) | 702 // * Two secure cookies (.c.b.a, w.c.b.a) |
| 685 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) | 703 // * 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) | 704 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) |
| 687 | 705 |
| 688 // Domain cookies | 706 // Domain cookies |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 int domain_purge_cookies, | 789 int domain_purge_cookies, |
| 772 CookieMonster::ExpiryAndKeyScheme key_scheme) { | 790 CookieMonster::ExpiryAndKeyScheme key_scheme) { |
| 773 const int more_than_enough_cookies = | 791 const int more_than_enough_cookies = |
| 774 (domain_max_cookies + domain_purge_cookies) * 2; | 792 (domain_max_cookies + domain_purge_cookies) * 2; |
| 775 // Add a bunch of cookies on a single host, should purge them. | 793 // Add a bunch of cookies on a single host, should purge them. |
| 776 { | 794 { |
| 777 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 795 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 778 cm->SetExpiryAndKeyScheme(key_scheme); | 796 cm->SetExpiryAndKeyScheme(key_scheme); |
| 779 for (int i = 0; i < more_than_enough_cookies; ++i) { | 797 for (int i = 0; i < more_than_enough_cookies; ++i) { |
| 780 std::string cookie = base::StringPrintf("a%03d=b", i); | 798 std::string cookie = base::StringPrintf("a%03d=b", i); |
| 781 EXPECT_TRUE(cm->SetCookie(url_google_, cookie)); | 799 EXPECT_TRUE(SetCookie(cm, url_google_, cookie)); |
| 782 std::string cookies = this->GetCookies(cm, url_google_); | 800 std::string cookies = this->GetCookies(cm, url_google_); |
| 783 // Make sure we find it in the cookies. | 801 // Make sure we find it in the cookies. |
| 784 EXPECT_NE(cookies.find(cookie), std::string::npos); | 802 EXPECT_NE(cookies.find(cookie), std::string::npos); |
| 785 // Count the number of cookies. | 803 // Count the number of cookies. |
| 786 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); | 804 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); |
| 787 } | 805 } |
| 788 } | 806 } |
| 789 | 807 |
| 790 // Add a bunch of cookies on multiple hosts within a single eTLD. | 808 // Add a bunch of cookies on multiple hosts within a single eTLD. |
| 791 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies | 809 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies |
| 792 // between them. If we are using the effective domain keying system | 810 // between them. If we are using the effective domain keying system |
| 793 // (EKS_KEEP_RECENT_AND_PURGE_ETLDP1) we shouldn't go above | 811 // (EKS_KEEP_RECENT_AND_PURGE_ETLDP1) we shouldn't go above |
| 794 // kDomainMaxCookies for both together. If we're using the domain | 812 // kDomainMaxCookies for both together. If we're using the domain |
| 795 // keying system (EKS_DISCARD_RECENT_AND_PURGE_DOMAIN), each | 813 // keying system (EKS_DISCARD_RECENT_AND_PURGE_DOMAIN), each |
| 796 // individual domain shouldn't go above kDomainMaxCookies. | 814 // individual domain shouldn't go above kDomainMaxCookies. |
| 797 GURL url_google_specific(kUrlGoogleSpecific); | 815 GURL url_google_specific(kUrlGoogleSpecific); |
| 798 { | 816 { |
| 799 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 817 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 800 cm->SetExpiryAndKeyScheme(key_scheme); | 818 cm->SetExpiryAndKeyScheme(key_scheme); |
| 801 for (int i = 0; i < more_than_enough_cookies; ++i) { | 819 for (int i = 0; i < more_than_enough_cookies; ++i) { |
| 802 std::string cookie_general = base::StringPrintf("a%03d=b", i); | 820 std::string cookie_general = base::StringPrintf("a%03d=b", i); |
| 803 EXPECT_TRUE(cm->SetCookie(url_google_, cookie_general)); | 821 EXPECT_TRUE(SetCookie(cm, url_google_, cookie_general)); |
| 804 std::string cookie_specific = base::StringPrintf("c%03d=b", i); | 822 std::string cookie_specific = base::StringPrintf("c%03d=b", i); |
| 805 EXPECT_TRUE(cm->SetCookie(url_google_specific, cookie_specific)); | 823 EXPECT_TRUE(SetCookie(cm, url_google_specific, cookie_specific)); |
| 806 std::string cookies_general = this->GetCookies(cm, url_google_); | 824 std::string cookies_general = this->GetCookies(cm, url_google_); |
| 807 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); | 825 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); |
| 808 std::string cookies_specific = | 826 std::string cookies_specific = |
| 809 this->GetCookies(cm, url_google_specific); | 827 this->GetCookies(cm, url_google_specific); |
| 810 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos); | 828 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos); |
| 811 if (key_scheme == CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1) { | 829 if (key_scheme == CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1) { |
| 812 EXPECT_LE((CountInString(cookies_general, '=') + | 830 EXPECT_LE((CountInString(cookies_general, '=') + |
| 813 CountInString(cookies_specific, '=')), | 831 CountInString(cookies_specific, '=')), |
| 814 domain_max_cookies); | 832 domain_max_cookies); |
| 815 } else { | 833 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 833 EXPECT_GE(general_cookies, | 851 EXPECT_GE(general_cookies, |
| 834 domain_max_cookies - domain_purge_cookies); | 852 domain_max_cookies - domain_purge_cookies); |
| 835 EXPECT_LE(general_cookies, domain_max_cookies); | 853 EXPECT_LE(general_cookies, domain_max_cookies); |
| 836 EXPECT_GE(specific_cookies, | 854 EXPECT_GE(specific_cookies, |
| 837 domain_max_cookies - domain_purge_cookies); | 855 domain_max_cookies - domain_purge_cookies); |
| 838 EXPECT_LE(specific_cookies, domain_max_cookies); | 856 EXPECT_LE(specific_cookies, domain_max_cookies); |
| 839 } | 857 } |
| 840 } | 858 } |
| 841 } | 859 } |
| 842 | 860 |
| 861 // Function for creating a CM with a number of cookies in it, |
| 862 // no store (and hence no ability to affect access time). |
| 863 CookieMonster* CreateMonsterForGC(int num_cookies) { |
| 864 CookieMonster* cm(new CookieMonster(NULL, NULL)); |
| 865 for (int i = 0; i < num_cookies; i++) { |
| 866 SetCookie(cm, GURL(StringPrintf("http://h%05d.izzle", i)), "a=1"); |
| 867 } |
| 868 return cm; |
| 869 } |
| 870 |
| 843 protected: | 871 protected: |
| 844 GURL url_google_; | 872 GURL url_google_; |
| 845 GURL url_google_secure_; | 873 GURL url_google_secure_; |
| 846 GURL url_google_foo_; | 874 GURL url_google_foo_; |
| 847 GURL url_google_bar_; | 875 GURL url_google_bar_; |
| 848 | 876 |
| 849 ScopedRunnableMethodFactory<MessageLoop> message_loop_factory_; | 877 ScopedRunnableMethodFactory<MessageLoop> message_loop_factory_; |
| 850 }; | 878 }; |
| 851 | 879 |
| 852 } // namespace | 880 } // namespace |
| 853 | 881 |
| 854 TEST_F(CookieMonsterTest, DomainTest) { | 882 TEST_F(CookieMonsterTest, DomainTest) { |
| 855 scoped_refptr<MockPersistentCookieStore> store( | 883 scoped_refptr<MockPersistentCookieStore> store( |
| 856 new MockPersistentCookieStore); | 884 new MockPersistentCookieStore); |
| 857 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 885 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 858 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 886 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 859 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 887 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 860 EXPECT_TRUE(cm->SetCookie(url_google_, "C=D; domain=.google.izzle")); | 888 EXPECT_TRUE(SetCookie(cm, url_google_, "C=D; domain=.google.izzle")); |
| 861 EXPECT_EQ("A=B; C=D", GetCookies(cm, url_google_)); | 889 EXPECT_EQ("A=B; C=D", GetCookies(cm, url_google_)); |
| 862 | 890 |
| 863 // Verify that A=B was set as a host cookie rather than a domain | 891 // 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. | 892 // cookie -- should not be accessible from a sub sub-domain. |
| 865 EXPECT_EQ("C=D", GetCookies(cm, GURL("http://foo.www.google.izzle"))); | 893 EXPECT_EQ("C=D", GetCookies(cm, GURL("http://foo.www.google.izzle"))); |
| 866 | 894 |
| 867 // Test and make sure we find domain cookies on the same domain. | 895 // 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")); | 896 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_)); | 897 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); |
| 870 | 898 |
| 871 // Test setting a domain= that doesn't start w/ a dot, should | 899 // 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. | 900 // 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")); | 901 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_)); | 902 EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_)); |
| 875 | 903 |
| 876 // Test domain enforcement, should fail on a sub-domain or something too deep. | 904 // Test domain enforcement, should fail on a sub-domain or something too deep. |
| 877 EXPECT_FALSE(cm->SetCookie(url_google_, "I=J; domain=.izzle")); | 905 EXPECT_FALSE(SetCookie(cm, url_google_, "I=J; domain=.izzle")); |
| 878 EXPECT_EQ("", GetCookies(cm, GURL("http://a.izzle"))); | 906 EXPECT_EQ("", GetCookies(cm, GURL("http://a.izzle"))); |
| 879 EXPECT_FALSE(cm->SetCookie(url_google_, "K=L; domain=.bla.www.google.izzle")); | 907 EXPECT_FALSE(SetCookie(cm, url_google_, "K=L; domain=.bla.www.google.izzle")); |
| 880 EXPECT_EQ("C=D; E=F; G=H", | 908 EXPECT_EQ("C=D; E=F; G=H", |
| 881 GetCookies(cm, GURL("http://bla.www.google.izzle"))); | 909 GetCookies(cm, GURL("http://bla.www.google.izzle"))); |
| 882 EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_)); | 910 EXPECT_EQ("A=B; C=D; E=F; G=H", GetCookies(cm, url_google_)); |
| 883 | 911 |
| 884 // Nothing was persisted to the backing store. | 912 // Nothing was persisted to the backing store. |
| 885 EXPECT_EQ(0u, store->commands().size()); | 913 EXPECT_EQ(0u, store->commands().size()); |
| 886 } | 914 } |
| 887 | 915 |
| 888 // FireFox recognizes domains containing trailing periods as valid. | 916 // FireFox recognizes domains containing trailing periods as valid. |
| 889 // IE and Safari do not. Assert the expected policy here. | 917 // IE and Safari do not. Assert the expected policy here. |
| 890 TEST_F(CookieMonsterTest, DomainWithTrailingDotTest) { | 918 TEST_F(CookieMonsterTest, DomainWithTrailingDotTest) { |
| 891 scoped_refptr<MockPersistentCookieStore> store( | 919 scoped_refptr<MockPersistentCookieStore> store( |
| 892 new MockPersistentCookieStore); | 920 new MockPersistentCookieStore); |
| 893 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 921 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 894 EXPECT_FALSE(cm->SetCookie(url_google_, "a=1; domain=.www.google.com.")); | 922 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..")); | 923 EXPECT_FALSE(SetCookie(cm, url_google_, "b=2; domain=.www.google.com..")); |
| 896 EXPECT_EQ("", GetCookies(cm, url_google_)); | 924 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 897 | 925 |
| 898 // Nothing was persisted to the backing store. | 926 // Nothing was persisted to the backing store. |
| 899 EXPECT_EQ(0u, store->commands().size()); | 927 EXPECT_EQ(0u, store->commands().size()); |
| 900 } | 928 } |
| 901 | 929 |
| 902 // Test that cookies can bet set on higher level domains. | 930 // Test that cookies can bet set on higher level domains. |
| 903 // http://b/issue?id=896491 | 931 // http://b/issue?id=896491 |
| 904 TEST_F(CookieMonsterTest, ValidSubdomainTest) { | 932 TEST_F(CookieMonsterTest, ValidSubdomainTest) { |
| 905 scoped_refptr<MockPersistentCookieStore> store( | 933 scoped_refptr<MockPersistentCookieStore> store( |
| 906 new MockPersistentCookieStore); | 934 new MockPersistentCookieStore); |
| 907 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 935 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 908 GURL url_abcd("http://a.b.c.d.com"); | 936 GURL url_abcd("http://a.b.c.d.com"); |
| 909 GURL url_bcd("http://b.c.d.com"); | 937 GURL url_bcd("http://b.c.d.com"); |
| 910 GURL url_cd("http://c.d.com"); | 938 GURL url_cd("http://c.d.com"); |
| 911 GURL url_d("http://d.com"); | 939 GURL url_d("http://d.com"); |
| 912 | 940 |
| 913 EXPECT_TRUE(cm->SetCookie(url_abcd, "a=1; domain=.a.b.c.d.com")); | 941 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")); | 942 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")); | 943 EXPECT_TRUE(SetCookie(cm, url_abcd, "c=3; domain=.c.d.com")); |
| 916 EXPECT_TRUE(cm->SetCookie(url_abcd, "d=4; domain=.d.com")); | 944 EXPECT_TRUE(SetCookie(cm, url_abcd, "d=4; domain=.d.com")); |
| 917 | 945 |
| 918 EXPECT_EQ("a=1; b=2; c=3; d=4", GetCookies(cm, url_abcd)); | 946 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)); | 947 EXPECT_EQ("b=2; c=3; d=4", GetCookies(cm, url_bcd)); |
| 920 EXPECT_EQ("c=3; d=4", GetCookies(cm, url_cd)); | 948 EXPECT_EQ("c=3; d=4", GetCookies(cm, url_cd)); |
| 921 EXPECT_EQ("d=4", GetCookies(cm, url_d)); | 949 EXPECT_EQ("d=4", GetCookies(cm, url_d)); |
| 922 | 950 |
| 923 // Check that the same cookie can exist on different sub-domains. | 951 // 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")); | 952 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")); | 953 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)); | 954 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)); | 955 EXPECT_EQ("c=3; d=4; X=cd", GetCookies(cm, url_cd)); |
| 928 | 956 |
| 929 // Nothing was persisted to the backing store. | 957 // Nothing was persisted to the backing store. |
| 930 EXPECT_EQ(0u, store->commands().size()); | 958 EXPECT_EQ(0u, store->commands().size()); |
| 931 } | 959 } |
| 932 | 960 |
| 933 // Test that setting a cookie which specifies an invalid domain has | 961 // 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 | 962 // no side-effect. An invalid domain in this context is one which does |
| 935 // not match the originating domain. | 963 // not match the originating domain. |
| 936 // http://b/issue?id=896472 | 964 // http://b/issue?id=896472 |
| 937 TEST_F(CookieMonsterTest, InvalidDomainTest) { | 965 TEST_F(CookieMonsterTest, InvalidDomainTest) { |
| 938 { | 966 { |
| 939 scoped_refptr<MockPersistentCookieStore> store( | 967 scoped_refptr<MockPersistentCookieStore> store( |
| 940 new MockPersistentCookieStore); | 968 new MockPersistentCookieStore); |
| 941 | 969 |
| 942 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 970 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 943 GURL url_foobar("http://foo.bar.com"); | 971 GURL url_foobar("http://foo.bar.com"); |
| 944 | 972 |
| 945 // More specific sub-domain than allowed. | 973 // More specific sub-domain than allowed. |
| 946 EXPECT_FALSE(cm->SetCookie(url_foobar, "a=1; domain=.yo.foo.bar.com")); | 974 EXPECT_FALSE(SetCookie(cm, url_foobar, "a=1; domain=.yo.foo.bar.com")); |
| 947 | 975 |
| 948 EXPECT_FALSE(cm->SetCookie(url_foobar, "b=2; domain=.foo.com")); | 976 EXPECT_FALSE(SetCookie(cm, url_foobar, "b=2; domain=.foo.com")); |
| 949 EXPECT_FALSE(cm->SetCookie(url_foobar, "c=3; domain=.bar.foo.com")); | 977 EXPECT_FALSE(SetCookie(cm, url_foobar, "c=3; domain=.bar.foo.com")); |
| 950 | 978 |
| 951 // Different TLD, but the rest is a substring. | 979 // Different TLD, but the rest is a substring. |
| 952 EXPECT_FALSE(cm->SetCookie(url_foobar, "d=4; domain=.foo.bar.com.net")); | 980 EXPECT_FALSE(SetCookie(cm, url_foobar, "d=4; domain=.foo.bar.com.net")); |
| 953 | 981 |
| 954 // A substring that isn't really a parent domain. | 982 // A substring that isn't really a parent domain. |
| 955 EXPECT_FALSE(cm->SetCookie(url_foobar, "e=5; domain=ar.com")); | 983 EXPECT_FALSE(SetCookie(cm, url_foobar, "e=5; domain=ar.com")); |
| 956 | 984 |
| 957 // Completely invalid domains: | 985 // Completely invalid domains: |
| 958 EXPECT_FALSE(cm->SetCookie(url_foobar, "f=6; domain=.")); | 986 EXPECT_FALSE(SetCookie(cm, url_foobar, "f=6; domain=.")); |
| 959 EXPECT_FALSE(cm->SetCookie(url_foobar, "g=7; domain=/")); | 987 EXPECT_FALSE(SetCookie(cm, url_foobar, "g=7; domain=/")); |
| 960 EXPECT_FALSE(cm->SetCookie(url_foobar, "h=8; domain=http://foo.bar.com")); | 988 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")); | 989 EXPECT_FALSE(SetCookie(cm, url_foobar, "i=9; domain=..foo.bar.com")); |
| 962 EXPECT_FALSE(cm->SetCookie(url_foobar, "j=10; domain=..bar.com")); | 990 EXPECT_FALSE(SetCookie(cm, url_foobar, "j=10; domain=..bar.com")); |
| 963 | 991 |
| 964 // Make sure there isn't something quirky in the domain canonicalization | 992 // Make sure there isn't something quirky in the domain canonicalization |
| 965 // that supports full URL semantics. | 993 // that supports full URL semantics. |
| 966 EXPECT_FALSE(cm->SetCookie(url_foobar, "k=11; domain=.foo.bar.com?blah")); | 994 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")); | 995 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")); | 996 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:")); | 997 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")); | 998 EXPECT_FALSE(SetCookie(cm, url_foobar, "o=15; domain=.foo.bar.com#sup")); |
| 971 | 999 |
| 972 EXPECT_EQ("", GetCookies(cm, url_foobar)); | 1000 EXPECT_EQ("", GetCookies(cm, url_foobar)); |
| 973 | 1001 |
| 974 // Nothing was persisted to the backing store. | 1002 // Nothing was persisted to the backing store. |
| 975 EXPECT_EQ(0u, store->commands().size()); | 1003 EXPECT_EQ(0u, store->commands().size()); |
| 976 } | 1004 } |
| 977 | 1005 |
| 978 { | 1006 { |
| 979 // Make sure the cookie code hasn't gotten its subdomain string handling | 1007 // 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 | 1008 // reversed, missed a suffix check, etc. It's important here that the two |
| 981 // hosts below have the same domain + registry. | 1009 // hosts below have the same domain + registry. |
| 982 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1010 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 983 GURL url_foocom("http://foo.com.com"); | 1011 GURL url_foocom("http://foo.com.com"); |
| 984 EXPECT_FALSE(cm->SetCookie(url_foocom, "a=1; domain=.foo.com.com.com")); | 1012 EXPECT_FALSE(SetCookie(cm, url_foocom, "a=1; domain=.foo.com.com.com")); |
| 985 EXPECT_EQ("", GetCookies(cm, url_foocom)); | 1013 EXPECT_EQ("", GetCookies(cm, url_foocom)); |
| 986 } | 1014 } |
| 987 } | 1015 } |
| 988 | 1016 |
| 989 // Test the behavior of omitting dot prefix from domain, should | 1017 // Test the behavior of omitting dot prefix from domain, should |
| 990 // function the same as FireFox. | 1018 // function the same as FireFox. |
| 991 // http://b/issue?id=889898 | 1019 // http://b/issue?id=889898 |
| 992 TEST_F(CookieMonsterTest, DomainWithoutLeadingDotTest) { | 1020 TEST_F(CookieMonsterTest, DomainWithoutLeadingDotTest) { |
| 993 { // The omission of dot results in setting a domain cookie. | 1021 { // The omission of dot results in setting a domain cookie. |
| 994 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1022 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 995 GURL url_hosted("http://manage.hosted.filefront.com"); | 1023 GURL url_hosted("http://manage.hosted.filefront.com"); |
| 996 GURL url_filefront("http://www.filefront.com"); | 1024 GURL url_filefront("http://www.filefront.com"); |
| 997 EXPECT_TRUE(cm->SetCookie(url_hosted, "sawAd=1; domain=filefront.com")); | 1025 EXPECT_TRUE(SetCookie(cm, url_hosted, "sawAd=1; domain=filefront.com")); |
| 998 EXPECT_EQ("sawAd=1", GetCookies(cm, url_hosted)); | 1026 EXPECT_EQ("sawAd=1", GetCookies(cm, url_hosted)); |
| 999 EXPECT_EQ("sawAd=1", GetCookies(cm, url_filefront)); | 1027 EXPECT_EQ("sawAd=1", GetCookies(cm, url_filefront)); |
| 1000 } | 1028 } |
| 1001 | 1029 |
| 1002 { // Even when the domains match exactly, don't consider it host cookie. | 1030 { // Even when the domains match exactly, don't consider it host cookie. |
| 1003 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1031 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1004 GURL url("http://www.google.com"); | 1032 GURL url("http://www.google.com"); |
| 1005 EXPECT_TRUE(cm->SetCookie(url, "a=1; domain=www.google.com")); | 1033 EXPECT_TRUE(SetCookie(cm, url, "a=1; domain=www.google.com")); |
| 1006 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1034 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1007 EXPECT_EQ("a=1", GetCookies(cm, GURL("http://sub.www.google.com"))); | 1035 EXPECT_EQ("a=1", GetCookies(cm, GURL("http://sub.www.google.com"))); |
| 1008 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.com"))); | 1036 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.com"))); |
| 1009 } | 1037 } |
| 1010 } | 1038 } |
| 1011 | 1039 |
| 1012 // Test that the domain specified in cookie string is treated case-insensitive | 1040 // Test that the domain specified in cookie string is treated case-insensitive |
| 1013 // http://b/issue?id=896475. | 1041 // http://b/issue?id=896475. |
| 1014 TEST_F(CookieMonsterTest, CaseInsensitiveDomainTest) { | 1042 TEST_F(CookieMonsterTest, CaseInsensitiveDomainTest) { |
| 1015 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1043 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1016 GURL url("http://www.google.com"); | 1044 GURL url("http://www.google.com"); |
| 1017 EXPECT_TRUE(cm->SetCookie(url, "a=1; domain=.GOOGLE.COM")); | 1045 EXPECT_TRUE(SetCookie(cm, url, "a=1; domain=.GOOGLE.COM")); |
| 1018 EXPECT_TRUE(cm->SetCookie(url, "b=2; domain=.wWw.gOOgLE.coM")); | 1046 EXPECT_TRUE(SetCookie(cm, url, "b=2; domain=.wWw.gOOgLE.coM")); |
| 1019 EXPECT_EQ("a=1; b=2", GetCookies(cm, url)); | 1047 EXPECT_EQ("a=1; b=2", GetCookies(cm, url)); |
| 1020 } | 1048 } |
| 1021 | 1049 |
| 1022 TEST_F(CookieMonsterTest, TestIpAddress) { | 1050 TEST_F(CookieMonsterTest, TestIpAddress) { |
| 1023 GURL url_ip("http://1.2.3.4/weee"); | 1051 GURL url_ip("http://1.2.3.4/weee"); |
| 1024 { | 1052 { |
| 1025 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1053 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1026 EXPECT_TRUE(cm->SetCookie(url_ip, kValidCookieLine)); | 1054 EXPECT_TRUE(SetCookie(cm, url_ip, kValidCookieLine)); |
| 1027 EXPECT_EQ("A=B", GetCookies(cm, url_ip)); | 1055 EXPECT_EQ("A=B", GetCookies(cm, url_ip)); |
| 1028 } | 1056 } |
| 1029 | 1057 |
| 1030 { // IP addresses should not be able to set domain cookies. | 1058 { // IP addresses should not be able to set domain cookies. |
| 1031 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1059 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1032 EXPECT_FALSE(cm->SetCookie(url_ip, "b=2; domain=.1.2.3.4")); | 1060 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")); | 1061 EXPECT_FALSE(SetCookie(cm, url_ip, "c=3; domain=.3.4")); |
| 1034 EXPECT_EQ("", GetCookies(cm, url_ip)); | 1062 EXPECT_EQ("", GetCookies(cm, url_ip)); |
| 1035 // It should be allowed to set a cookie if domain= matches the IP address | 1063 // 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. | 1064 // 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")); | 1065 EXPECT_FALSE(SetCookie(cm, url_ip, "b=2; domain=1.2.3.3")); |
| 1038 EXPECT_EQ("", GetCookies(cm, url_ip)); | 1066 EXPECT_EQ("", GetCookies(cm, url_ip)); |
| 1039 EXPECT_TRUE(cm->SetCookie(url_ip, "b=2; domain=1.2.3.4")); | 1067 EXPECT_TRUE(SetCookie(cm, url_ip, "b=2; domain=1.2.3.4")); |
| 1040 EXPECT_EQ("b=2", GetCookies(cm, url_ip)); | 1068 EXPECT_EQ("b=2", GetCookies(cm, url_ip)); |
| 1041 } | 1069 } |
| 1042 } | 1070 } |
| 1043 | 1071 |
| 1044 // Test host cookies, and setting of cookies on TLD. | 1072 // Test host cookies, and setting of cookies on TLD. |
| 1045 TEST_F(CookieMonsterTest, TestNonDottedAndTLD) { | 1073 TEST_F(CookieMonsterTest, TestNonDottedAndTLD) { |
| 1046 { | 1074 { |
| 1047 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1075 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1048 GURL url("http://com/"); | 1076 GURL url("http://com/"); |
| 1049 // Allow setting on "com", (but only as a host cookie). | 1077 // Allow setting on "com", (but only as a host cookie). |
| 1050 EXPECT_TRUE(cm->SetCookie(url, "a=1")); | 1078 EXPECT_TRUE(SetCookie(cm, url, "a=1")); |
| 1051 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.com")); | 1079 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.com")); |
| 1052 EXPECT_FALSE(cm->SetCookie(url, "c=3; domain=com")); | 1080 EXPECT_FALSE(SetCookie(cm, url, "c=3; domain=com")); |
| 1053 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1081 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1054 // Make sure it doesn't show up for a normal .com, it should be a host | 1082 // Make sure it doesn't show up for a normal .com, it should be a host |
| 1055 // not a domain cookie. | 1083 // not a domain cookie. |
| 1056 EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com/"))); | 1084 EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com/"))); |
| 1057 EXPECT_EQ("", GetCookies(cm, GURL("http://.com/"))); | 1085 EXPECT_EQ("", GetCookies(cm, GURL("http://.com/"))); |
| 1058 } | 1086 } |
| 1059 | 1087 |
| 1060 { // http://com. should be treated the same as http://com. | 1088 { // http://com. should be treated the same as http://com. |
| 1061 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1089 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1062 GURL url("http://com./index.html"); | 1090 GURL url("http://com./index.html"); |
| 1063 EXPECT_TRUE(cm->SetCookie(url, "a=1")); | 1091 EXPECT_TRUE(SetCookie(cm, url, "a=1")); |
| 1064 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1092 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1065 EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com./"))); | 1093 EXPECT_EQ("", GetCookies(cm, GURL("http://hopefully-no-cookies.com./"))); |
| 1066 } | 1094 } |
| 1067 | 1095 |
| 1068 { // Should not be able to set host cookie from a subdomain. | 1096 { // Should not be able to set host cookie from a subdomain. |
| 1069 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1097 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1070 GURL url("http://a.b"); | 1098 GURL url("http://a.b"); |
| 1071 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.b")); | 1099 EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.b")); |
| 1072 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=b")); | 1100 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=b")); |
| 1073 EXPECT_EQ("", GetCookies(cm, url)); | 1101 EXPECT_EQ("", GetCookies(cm, url)); |
| 1074 } | 1102 } |
| 1075 | 1103 |
| 1076 { // Same test as above, but explicitly on a known TLD (com). | 1104 { // Same test as above, but explicitly on a known TLD (com). |
| 1077 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1105 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1078 GURL url("http://google.com"); | 1106 GURL url("http://google.com"); |
| 1079 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.com")); | 1107 EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.com")); |
| 1080 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=com")); | 1108 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=com")); |
| 1081 EXPECT_EQ("", GetCookies(cm, url)); | 1109 EXPECT_EQ("", GetCookies(cm, url)); |
| 1082 } | 1110 } |
| 1083 | 1111 |
| 1084 { // Make sure can't set cookie on TLD which is dotted. | 1112 { // Make sure can't set cookie on TLD which is dotted. |
| 1085 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1113 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1086 GURL url("http://google.co.uk"); | 1114 GURL url("http://google.co.uk"); |
| 1087 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.co.uk")); | 1115 EXPECT_FALSE(SetCookie(cm, url, "a=1; domain=.co.uk")); |
| 1088 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.uk")); | 1116 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.uk")); |
| 1089 EXPECT_EQ("", GetCookies(cm, url)); | 1117 EXPECT_EQ("", GetCookies(cm, url)); |
| 1090 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.co.uk"))); | 1118 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.co.uk"))); |
| 1091 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.uk"))); | 1119 EXPECT_EQ("", GetCookies(cm, GURL("http://something-else.uk"))); |
| 1092 } | 1120 } |
| 1093 | 1121 |
| 1094 { // Intranet URLs should only be able to set host cookies. | 1122 { // Intranet URLs should only be able to set host cookies. |
| 1095 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1123 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1096 GURL url("http://b"); | 1124 GURL url("http://b"); |
| 1097 EXPECT_TRUE(cm->SetCookie(url, "a=1")); | 1125 EXPECT_TRUE(SetCookie(cm, url, "a=1")); |
| 1098 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.b")); | 1126 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.b")); |
| 1099 EXPECT_FALSE(cm->SetCookie(url, "c=3; domain=b")); | 1127 EXPECT_FALSE(SetCookie(cm, url, "c=3; domain=b")); |
| 1100 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1128 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1101 } | 1129 } |
| 1102 } | 1130 } |
| 1103 | 1131 |
| 1104 // Test reading/writing cookies when the domain ends with a period, | 1132 // Test reading/writing cookies when the domain ends with a period, |
| 1105 // as in "www.google.com." | 1133 // as in "www.google.com." |
| 1106 TEST_F(CookieMonsterTest, TestHostEndsWithDot) { | 1134 TEST_F(CookieMonsterTest, TestHostEndsWithDot) { |
| 1107 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1135 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1108 GURL url("http://www.google.com"); | 1136 GURL url("http://www.google.com"); |
| 1109 GURL url_with_dot("http://www.google.com."); | 1137 GURL url_with_dot("http://www.google.com."); |
| 1110 EXPECT_TRUE(cm->SetCookie(url, "a=1")); | 1138 EXPECT_TRUE(SetCookie(cm, url, "a=1")); |
| 1111 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1139 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1112 | 1140 |
| 1113 // Do not share cookie space with the dot version of domain. | 1141 // 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. | 1142 // 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.")); | 1143 EXPECT_FALSE(SetCookie(cm, url, "b=2; domain=.www.google.com.")); |
| 1116 EXPECT_EQ("a=1", GetCookies(cm, url)); | 1144 EXPECT_EQ("a=1", GetCookies(cm, url)); |
| 1117 | 1145 |
| 1118 EXPECT_TRUE(cm->SetCookie(url_with_dot, "b=2; domain=.google.com.")); | 1146 EXPECT_TRUE(SetCookie(cm, url_with_dot, "b=2; domain=.google.com.")); |
| 1119 EXPECT_EQ("b=2", GetCookies(cm, url_with_dot)); | 1147 EXPECT_EQ("b=2", GetCookies(cm, url_with_dot)); |
| 1120 | 1148 |
| 1121 // Make sure there weren't any side effects. | 1149 // Make sure there weren't any side effects. |
| 1122 EXPECT_EQ(GetCookies(cm, GURL("http://hopefully-no-cookies.com/")), ""); | 1150 EXPECT_EQ(GetCookies(cm, GURL("http://hopefully-no-cookies.com/")), ""); |
| 1123 EXPECT_EQ("", GetCookies(cm, GURL("http://.com/"))); | 1151 EXPECT_EQ("", GetCookies(cm, GURL("http://.com/"))); |
| 1124 } | 1152 } |
| 1125 | 1153 |
| 1126 TEST_F(CookieMonsterTest, InvalidScheme) { | 1154 TEST_F(CookieMonsterTest, InvalidScheme) { |
| 1127 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1155 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1128 EXPECT_FALSE(cm->SetCookie(GURL(kUrlFtp), kValidCookieLine)); | 1156 EXPECT_FALSE(SetCookie(cm, GURL(kUrlFtp), kValidCookieLine)); |
| 1129 } | 1157 } |
| 1130 | 1158 |
| 1131 TEST_F(CookieMonsterTest, InvalidScheme_Read) { | 1159 TEST_F(CookieMonsterTest, InvalidScheme_Read) { |
| 1132 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1160 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1133 EXPECT_TRUE(cm->SetCookie(GURL(kUrlGoogle), kValidDomainCookieLine)); | 1161 EXPECT_TRUE(SetCookie(cm, GURL(kUrlGoogle), kValidDomainCookieLine)); |
| 1134 EXPECT_EQ("", GetCookies(cm, GURL(kUrlFtp))); | 1162 EXPECT_EQ("", GetCookies(cm, GURL(kUrlFtp))); |
| 1135 } | 1163 } |
| 1136 | 1164 |
| 1137 TEST_F(CookieMonsterTest, PathTest) { | 1165 TEST_F(CookieMonsterTest, PathTest) { |
| 1138 std::string url("http://www.google.izzle"); | 1166 std::string url("http://www.google.izzle"); |
| 1139 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1167 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1140 EXPECT_TRUE(cm->SetCookie(GURL(url), "A=B; path=/wee")); | 1168 EXPECT_TRUE(SetCookie(cm, GURL(url), "A=B; path=/wee")); |
| 1141 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee"))); | 1169 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee"))); |
| 1142 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/"))); | 1170 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/"))); |
| 1143 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war"))); | 1171 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war"))); |
| 1144 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war/more/more"))); | 1172 EXPECT_EQ("A=B", GetCookies(cm, GURL(url + "/wee/war/more/more"))); |
| 1145 EXPECT_EQ("", GetCookies(cm, GURL(url + "/weehee"))); | 1173 EXPECT_EQ("", GetCookies(cm, GURL(url + "/weehee"))); |
| 1146 EXPECT_EQ("", GetCookies(cm, GURL(url + "/"))); | 1174 EXPECT_EQ("", GetCookies(cm, GURL(url + "/"))); |
| 1147 | 1175 |
| 1148 // If we add a 0 length path, it should default to / | 1176 // If we add a 0 length path, it should default to / |
| 1149 EXPECT_TRUE(cm->SetCookie(GURL(url), "A=C; path=")); | 1177 EXPECT_TRUE(SetCookie(cm, GURL(url), "A=C; path=")); |
| 1150 EXPECT_EQ("A=B; A=C", GetCookies(cm, GURL(url + "/wee"))); | 1178 EXPECT_EQ("A=B; A=C", GetCookies(cm, GURL(url + "/wee"))); |
| 1151 EXPECT_EQ("A=C", GetCookies(cm, GURL(url + "/"))); | 1179 EXPECT_EQ("A=C", GetCookies(cm, GURL(url + "/"))); |
| 1152 } | 1180 } |
| 1153 | 1181 |
| 1154 TEST_F(CookieMonsterTest, HttpOnlyTest) { | 1182 TEST_F(CookieMonsterTest, HttpOnlyTest) { |
| 1155 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1183 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1156 CookieOptions options; | 1184 CookieOptions options; |
| 1157 options.set_include_httponly(); | 1185 options.set_include_httponly(); |
| 1158 | 1186 |
| 1159 // Create a httponly cookie. | 1187 // Create a httponly cookie. |
| 1160 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B; httponly", options)); | 1188 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B; httponly", options)); |
| 1161 | 1189 |
| 1162 // Check httponly read protection. | 1190 // Check httponly read protection. |
| 1163 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1191 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1164 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); | 1192 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); |
| 1165 | 1193 |
| 1166 // Check httponly overwrite protection. | 1194 // Check httponly overwrite protection. |
| 1167 EXPECT_FALSE(cm->SetCookie(url_google_, "A=C")); | 1195 EXPECT_FALSE(SetCookie(cm, url_google_, "A=C")); |
| 1168 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1196 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1169 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); | 1197 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); |
| 1170 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=C", options)); | 1198 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=C", options)); |
| 1171 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); | 1199 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); |
| 1172 | 1200 |
| 1173 // Check httponly create protection. | 1201 // Check httponly create protection. |
| 1174 EXPECT_FALSE(cm->SetCookie(url_google_, "B=A; httponly")); | 1202 EXPECT_FALSE(SetCookie(cm, url_google_, "B=A; httponly")); |
| 1175 EXPECT_EQ("A=C", GetCookiesWithOptions(cm, url_google_, options)); | 1203 EXPECT_EQ("A=C", GetCookiesWithOptions(cm, url_google_, options)); |
| 1176 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "B=A; httponly", options)); | 1204 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "B=A; httponly", options)); |
| 1177 EXPECT_EQ("A=C; B=A", GetCookiesWithOptions(cm, url_google_, options)); | 1205 EXPECT_EQ("A=C; B=A", GetCookiesWithOptions(cm, url_google_, options)); |
| 1178 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); | 1206 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); |
| 1179 } | 1207 } |
| 1180 | 1208 |
| 1181 TEST_F(CookieMonsterTest, GetCookiesWithInfo) { | 1209 TEST_F(CookieMonsterTest, GetCookiesWithInfo) { |
| 1182 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1210 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1183 CookieOptions options; | 1211 CookieOptions options; |
| 1184 | 1212 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 CookieMonster::DomainIsHostOnly(tests[i].str)); | 1345 CookieMonster::DomainIsHostOnly(tests[i].str)); |
| 1318 } | 1346 } |
| 1319 } | 1347 } |
| 1320 | 1348 |
| 1321 TEST_F(CookieMonsterTest, TestCookieDeletion) { | 1349 TEST_F(CookieMonsterTest, TestCookieDeletion) { |
| 1322 scoped_refptr<MockPersistentCookieStore> store( | 1350 scoped_refptr<MockPersistentCookieStore> store( |
| 1323 new MockPersistentCookieStore); | 1351 new MockPersistentCookieStore); |
| 1324 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1352 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 1325 | 1353 |
| 1326 // Create a session cookie. | 1354 // Create a session cookie. |
| 1327 EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine)); | 1355 EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
| 1328 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1356 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1329 // Delete it via Max-Age. | 1357 // Delete it via Max-Age. |
| 1330 EXPECT_TRUE(cm->SetCookie(url_google_, | 1358 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1331 std::string(kValidCookieLine) + "; max-age=0")); | 1359 std::string(kValidCookieLine) + "; max-age=0")); |
| 1332 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1360 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1333 | 1361 |
| 1334 // Create a session cookie. | 1362 // Create a session cookie. |
| 1335 EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine)); | 1363 EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
| 1336 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1364 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1337 // Delete it via Expires. | 1365 // Delete it via Expires. |
| 1338 EXPECT_TRUE(cm->SetCookie(url_google_, | 1366 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1339 std::string(kValidCookieLine) + | 1367 std::string(kValidCookieLine) + |
| 1340 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 1368 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
| 1341 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1369 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1342 | 1370 |
| 1343 // Create a persistent cookie. | 1371 // Create a persistent cookie. |
| 1344 EXPECT_TRUE(cm->SetCookie(url_google_, | 1372 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1345 std::string(kValidCookieLine) + | 1373 std::string(kValidCookieLine) + |
| 1346 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1374 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1347 ASSERT_EQ(1u, store->commands().size()); | 1375 ASSERT_EQ(1u, store->commands().size()); |
| 1348 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1376 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1349 | 1377 |
| 1350 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1378 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1351 // Delete it via Max-Age. | 1379 // Delete it via Max-Age. |
| 1352 EXPECT_TRUE(cm->SetCookie(url_google_, | 1380 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1353 std::string(kValidCookieLine) + "; max-age=0")); | 1381 std::string(kValidCookieLine) + "; max-age=0")); |
| 1354 ASSERT_EQ(2u, store->commands().size()); | 1382 ASSERT_EQ(2u, store->commands().size()); |
| 1355 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1383 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1356 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1384 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1357 | 1385 |
| 1358 // Create a persistent cookie. | 1386 // Create a persistent cookie. |
| 1359 EXPECT_TRUE(cm->SetCookie(url_google_, | 1387 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1360 std::string(kValidCookieLine) + | 1388 std::string(kValidCookieLine) + |
| 1361 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1389 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1362 ASSERT_EQ(3u, store->commands().size()); | 1390 ASSERT_EQ(3u, store->commands().size()); |
| 1363 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 1391 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 1364 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1392 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1365 // Delete it via Expires. | 1393 // Delete it via Expires. |
| 1366 EXPECT_TRUE(cm->SetCookie(url_google_, | 1394 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1367 std::string(kValidCookieLine) + | 1395 std::string(kValidCookieLine) + |
| 1368 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 1396 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
| 1369 ASSERT_EQ(4u, store->commands().size()); | 1397 ASSERT_EQ(4u, store->commands().size()); |
| 1370 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 1398 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 1371 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1399 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1372 | 1400 |
| 1373 // Create a persistent cookie. | 1401 // Create a persistent cookie. |
| 1374 EXPECT_TRUE(cm->SetCookie(url_google_, | 1402 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1375 std::string(kValidCookieLine) + | 1403 std::string(kValidCookieLine) + |
| 1376 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1404 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1377 ASSERT_EQ(5u, store->commands().size()); | 1405 ASSERT_EQ(5u, store->commands().size()); |
| 1378 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); | 1406 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
| 1379 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1407 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1380 // Delete it via Expires, with a unix epoch of 0. | 1408 // Delete it via Expires, with a unix epoch of 0. |
| 1381 EXPECT_TRUE(cm->SetCookie(url_google_, | 1409 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1382 std::string(kValidCookieLine) + | 1410 std::string(kValidCookieLine) + |
| 1383 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); | 1411 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); |
| 1384 ASSERT_EQ(6u, store->commands().size()); | 1412 ASSERT_EQ(6u, store->commands().size()); |
| 1385 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[5].type); | 1413 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[5].type); |
| 1386 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1414 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1387 } | 1415 } |
| 1388 | 1416 |
| 1389 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { | 1417 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { |
| 1390 scoped_refptr<MockPersistentCookieStore> store( | 1418 scoped_refptr<MockPersistentCookieStore> store( |
| 1391 new MockPersistentCookieStore); | 1419 new MockPersistentCookieStore); |
| 1392 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1420 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 1393 CookieOptions options; | 1421 CookieOptions options; |
| 1394 options.set_include_httponly(); | 1422 options.set_include_httponly(); |
| 1395 | 1423 |
| 1396 EXPECT_TRUE(cm->SetCookie(url_google_, kValidCookieLine)); | 1424 EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
| 1397 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1425 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1398 | 1426 |
| 1399 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "C=D; httponly", options)); | 1427 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "C=D; httponly", options)); |
| 1400 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm, url_google_, options)); | 1428 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm, url_google_, options)); |
| 1401 | 1429 |
| 1402 EXPECT_EQ(2, cm->DeleteAll(false)); | 1430 EXPECT_EQ(2, DeleteAll(cm, false)); |
| 1403 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); | 1431 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); |
| 1404 | 1432 |
| 1405 EXPECT_EQ(0u, store->commands().size()); | 1433 EXPECT_EQ(0u, store->commands().size()); |
| 1406 | 1434 |
| 1407 // Create a persistent cookie. | 1435 // Create a persistent cookie. |
| 1408 EXPECT_TRUE(cm->SetCookie(url_google_, | 1436 EXPECT_TRUE(SetCookie(cm, url_google_, |
| 1409 std::string(kValidCookieLine) + | 1437 std::string(kValidCookieLine) + |
| 1410 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1438 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1411 ASSERT_EQ(1u, store->commands().size()); | 1439 ASSERT_EQ(1u, store->commands().size()); |
| 1412 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1440 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1413 | 1441 |
| 1414 EXPECT_EQ(1, cm->DeleteAll(true)); // sync_to_store = true. | 1442 EXPECT_EQ(1, DeleteAll(cm, true)); // sync_to_store = true. |
| 1415 ASSERT_EQ(2u, store->commands().size()); | 1443 ASSERT_EQ(2u, store->commands().size()); |
| 1416 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1444 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1417 | 1445 |
| 1418 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); | 1446 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); |
| 1419 } | 1447 } |
| 1420 | 1448 |
| 1421 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1449 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 1422 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1450 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1423 Time now = Time::Now(); | 1451 Time now = Time::Now(); |
| 1424 | 1452 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1450 | 1478 |
| 1451 // Make sure the delete_begin is inclusive. | 1479 // Make sure the delete_begin is inclusive. |
| 1452 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(7), | 1480 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(7), |
| 1453 now, | 1481 now, |
| 1454 false)); | 1482 false)); |
| 1455 | 1483 |
| 1456 // Delete the last (now) item. | 1484 // Delete the last (now) item. |
| 1457 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, Time(), Time(), false)); | 1485 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, Time(), Time(), false)); |
| 1458 | 1486 |
| 1459 // Really make sure everything is gone. | 1487 // Really make sure everything is gone. |
| 1460 EXPECT_EQ(0, cm->DeleteAll(false)); | 1488 EXPECT_EQ(0, DeleteAll(cm, false)); |
| 1461 } | 1489 } |
| 1462 | 1490 |
| 1463 TEST_F(CookieMonsterTest, TestSecure) { | 1491 TEST_F(CookieMonsterTest, TestSecure) { |
| 1464 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1492 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1465 | 1493 |
| 1466 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 1494 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 1467 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1495 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1468 EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_)); | 1496 EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_)); |
| 1469 | 1497 |
| 1470 EXPECT_TRUE(cm->SetCookie(url_google_secure_, "A=B; secure")); | 1498 EXPECT_TRUE(SetCookie(cm, url_google_secure_, "A=B; secure")); |
| 1471 // The secure should overwrite the non-secure. | 1499 // The secure should overwrite the non-secure. |
| 1472 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1500 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1473 EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_)); | 1501 EXPECT_EQ("A=B", GetCookies(cm, url_google_secure_)); |
| 1474 | 1502 |
| 1475 EXPECT_TRUE(cm->SetCookie(url_google_secure_, "D=E; secure")); | 1503 EXPECT_TRUE(SetCookie(cm, url_google_secure_, "D=E; secure")); |
| 1476 EXPECT_EQ("", GetCookies(cm, url_google_)); | 1504 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 1477 EXPECT_EQ("A=B; D=E", GetCookies(cm, url_google_secure_)); | 1505 EXPECT_EQ("A=B; D=E", GetCookies(cm, url_google_secure_)); |
| 1478 | 1506 |
| 1479 EXPECT_TRUE(cm->SetCookie(url_google_secure_, "A=B")); | 1507 EXPECT_TRUE(SetCookie(cm, url_google_secure_, "A=B")); |
| 1480 // The non-secure should overwrite the secure. | 1508 // The non-secure should overwrite the secure. |
| 1481 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1509 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1482 EXPECT_EQ("D=E; A=B", GetCookies(cm, url_google_secure_)); | 1510 EXPECT_EQ("D=E; A=B", GetCookies(cm, url_google_secure_)); |
| 1483 } | 1511 } |
| 1484 | 1512 |
| 1485 static const int kLastAccessThresholdMilliseconds = 200; | 1513 static const int kLastAccessThresholdMilliseconds = 200; |
| 1486 | 1514 |
| 1487 TEST_F(CookieMonsterTest, TestLastAccess) { | 1515 TEST_F(CookieMonsterTest, TestLastAccess) { |
| 1488 scoped_refptr<CookieMonster> cm( | 1516 scoped_refptr<CookieMonster> cm( |
| 1489 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 1517 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); |
| 1490 | 1518 |
| 1491 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 1519 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 1492 const Time last_access_date(GetFirstCookieAccessDate(cm)); | 1520 const Time last_access_date(GetFirstCookieAccessDate(cm)); |
| 1493 | 1521 |
| 1494 // Reading the cookie again immediately shouldn't update the access date, | 1522 // Reading the cookie again immediately shouldn't update the access date, |
| 1495 // since we're inside the threshold. | 1523 // since we're inside the threshold. |
| 1496 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1524 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1497 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); | 1525 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); |
| 1498 | 1526 |
| 1499 // Reading after a short wait should update the access date. | 1527 // Reading after a short wait should update the access date. |
| 1500 base::PlatformThread::Sleep(kLastAccessThresholdMilliseconds + 20); | 1528 base::PlatformThread::Sleep(kLastAccessThresholdMilliseconds + 20); |
| 1501 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1529 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 1502 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm)); | 1530 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm)); |
| 1503 } | 1531 } |
| 1504 | 1532 |
| 1505 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { | 1533 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { |
| 1506 TestHostGarbageCollectHelper( | 1534 TestHostGarbageCollectHelper( |
| 1507 CookieMonster::kDomainMaxCookies, CookieMonster::kDomainPurgeCookies, | 1535 CookieMonster::kDomainMaxCookies, CookieMonster::kDomainPurgeCookies, |
| 1508 CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1); | 1536 CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1); |
| 1509 TestHostGarbageCollectHelper( | 1537 TestHostGarbageCollectHelper( |
| 1510 CookieMonster::kDomainMaxCookies, CookieMonster::kDomainPurgeCookies, | 1538 CookieMonster::kDomainMaxCookies, CookieMonster::kDomainPurgeCookies, |
| 1511 CookieMonster::EKS_DISCARD_RECENT_AND_PURGE_DOMAIN); | 1539 CookieMonster::EKS_DISCARD_RECENT_AND_PURGE_DOMAIN); |
| 1512 } | 1540 } |
| 1513 | 1541 |
| 1514 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. | 1542 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. |
| 1515 TEST_F(CookieMonsterTest, NetUtilCookieTest) { | 1543 TEST_F(CookieMonsterTest, NetUtilCookieTest) { |
| 1516 const GURL test_url("http://mojo.jojo.google.izzle/"); | 1544 const GURL test_url("http://mojo.jojo.google.izzle/"); |
| 1517 | 1545 |
| 1518 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1546 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1519 | 1547 |
| 1520 EXPECT_TRUE(cm->SetCookie(test_url, "foo=bar")); | 1548 EXPECT_TRUE(SetCookie(cm, test_url, "foo=bar")); |
| 1521 std::string value = GetCookies(cm, test_url); | 1549 std::string value = GetCookies(cm, test_url); |
| 1522 EXPECT_EQ("foo=bar", value); | 1550 EXPECT_EQ("foo=bar", value); |
| 1523 | 1551 |
| 1524 // test that we can retrieve all cookies: | 1552 // test that we can retrieve all cookies: |
| 1525 EXPECT_TRUE(cm->SetCookie(test_url, "x=1")); | 1553 EXPECT_TRUE(SetCookie(cm, test_url, "x=1")); |
| 1526 EXPECT_TRUE(cm->SetCookie(test_url, "y=2")); | 1554 EXPECT_TRUE(SetCookie(cm, test_url, "y=2")); |
| 1527 | 1555 |
| 1528 std::string result = GetCookies(cm, test_url); | 1556 std::string result = GetCookies(cm, test_url); |
| 1529 EXPECT_FALSE(result.empty()); | 1557 EXPECT_FALSE(result.empty()); |
| 1530 EXPECT_NE(result.find("x=1"), std::string::npos) << result; | 1558 EXPECT_NE(result.find("x=1"), std::string::npos) << result; |
| 1531 EXPECT_NE(result.find("y=2"), std::string::npos) << result; | 1559 EXPECT_NE(result.find("y=2"), std::string::npos) << result; |
| 1532 } | 1560 } |
| 1533 | 1561 |
| 1534 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) { | 1562 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) { |
| 1535 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1563 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1536 | 1564 |
| 1537 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 1565 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 1538 EXPECT_TRUE(cm->SetCookie(url_google_, "C=D")); | 1566 EXPECT_TRUE(SetCookie(cm, url_google_, "C=D")); |
| 1539 EXPECT_TRUE(cm->SetCookie(url_google_, "E=F")); | 1567 EXPECT_TRUE(SetCookie(cm, url_google_, "E=F")); |
| 1540 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); | 1568 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); |
| 1541 | 1569 |
| 1542 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google_.host(), "C")); | 1570 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google_.host(), "C")); |
| 1543 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); | 1571 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); |
| 1544 | 1572 |
| 1545 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); | 1573 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); |
| 1546 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); | 1574 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); |
| 1547 } | 1575 } |
| 1548 | 1576 |
| 1549 TEST_F(CookieMonsterTest, SetCookieableSchemes) { | 1577 TEST_F(CookieMonsterTest, SetCookieableSchemes) { |
| 1550 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1578 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1551 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); | 1579 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); |
| 1552 | 1580 |
| 1553 // Only cm_foo should allow foo:// cookies. | 1581 // Only cm_foo should allow foo:// cookies. |
| 1554 const char* kSchemes[] = {"foo"}; | 1582 const char* kSchemes[] = {"foo"}; |
| 1555 cm_foo->SetCookieableSchemes(kSchemes, 1); | 1583 cm_foo->SetCookieableSchemes(kSchemes, 1); |
| 1556 | 1584 |
| 1557 GURL foo_url("foo://host/path"); | 1585 GURL foo_url("foo://host/path"); |
| 1558 GURL http_url("http://host/path"); | 1586 GURL http_url("http://host/path"); |
| 1559 | 1587 |
| 1560 EXPECT_TRUE(cm->SetCookie(http_url, "x=1")); | 1588 EXPECT_TRUE(SetCookie(cm, http_url, "x=1")); |
| 1561 EXPECT_FALSE(cm->SetCookie(foo_url, "x=1")); | 1589 EXPECT_FALSE(SetCookie(cm, foo_url, "x=1")); |
| 1562 EXPECT_TRUE(cm_foo->SetCookie(foo_url, "x=1")); | 1590 EXPECT_TRUE(SetCookie(cm_foo, foo_url, "x=1")); |
| 1563 EXPECT_FALSE(cm_foo->SetCookie(http_url, "x=1")); | 1591 EXPECT_FALSE(SetCookie(cm_foo, http_url, "x=1")); |
| 1564 } | 1592 } |
| 1565 | 1593 |
| 1566 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { | 1594 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { |
| 1567 scoped_refptr<CookieMonster> cm( | 1595 scoped_refptr<CookieMonster> cm( |
| 1568 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 1596 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); |
| 1569 | 1597 |
| 1570 // Create an httponly cookie. | 1598 // Create an httponly cookie. |
| 1571 CookieOptions options; | 1599 CookieOptions options; |
| 1572 options.set_include_httponly(); | 1600 options.set_include_httponly(); |
| 1573 | 1601 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 ASSERT_TRUE(++it != cookies.end()); | 1695 ASSERT_TRUE(++it != cookies.end()); |
| 1668 EXPECT_EQ("E", it->Name()); | 1696 EXPECT_EQ("E", it->Name()); |
| 1669 EXPECT_EQ("/", it->Path()); | 1697 EXPECT_EQ("/", it->Path()); |
| 1670 | 1698 |
| 1671 ASSERT_TRUE(++it == cookies.end()); | 1699 ASSERT_TRUE(++it == cookies.end()); |
| 1672 } | 1700 } |
| 1673 | 1701 |
| 1674 TEST_F(CookieMonsterTest, DeleteCookieByName) { | 1702 TEST_F(CookieMonsterTest, DeleteCookieByName) { |
| 1675 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1703 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1676 | 1704 |
| 1677 EXPECT_TRUE(cm->SetCookie(url_google_, "A=A1; path=/")); | 1705 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A1; path=/")); |
| 1678 EXPECT_TRUE(cm->SetCookie(url_google_, "A=A2; path=/foo")); | 1706 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A2; path=/foo")); |
| 1679 EXPECT_TRUE(cm->SetCookie(url_google_, "A=A3; path=/bar")); | 1707 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A3; path=/bar")); |
| 1680 EXPECT_TRUE(cm->SetCookie(url_google_, "B=B1; path=/")); | 1708 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B1; path=/")); |
| 1681 EXPECT_TRUE(cm->SetCookie(url_google_, "B=B2; path=/foo")); | 1709 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B2; path=/foo")); |
| 1682 EXPECT_TRUE(cm->SetCookie(url_google_, "B=B3; path=/bar")); | 1710 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B3; path=/bar")); |
| 1683 | 1711 |
| 1684 DeleteCookie(cm, GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); | 1712 DeleteCookie(cm, GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); |
| 1685 | 1713 |
| 1686 CookieList cookies = GetAllCookies(cm); | 1714 CookieList cookies = GetAllCookies(cm); |
| 1687 size_t expected_size = 4; | 1715 size_t expected_size = 4; |
| 1688 EXPECT_EQ(expected_size, cookies.size()); | 1716 EXPECT_EQ(expected_size, cookies.size()); |
| 1689 for (CookieList::iterator it = cookies.begin(); | 1717 for (CookieList::iterator it = cookies.begin(); |
| 1690 it != cookies.end(); ++it) { | 1718 it != cookies.end(); ++it) { |
| 1691 EXPECT_NE("A1", it->Value()); | 1719 EXPECT_NE("A1", it->Value()); |
| 1692 EXPECT_NE("A2", it->Value()); | 1720 EXPECT_NE("A2", it->Value()); |
| 1693 } | 1721 } |
| 1694 } | 1722 } |
| 1695 | 1723 |
| 1696 TEST_F(CookieMonsterTest, InitializeFromCookieMonster) { | 1724 TEST_F(CookieMonsterTest, InitializeFromCookieMonster) { |
| 1697 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL)); | 1725 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL)); |
| 1698 CookieOptions options; | 1726 CookieOptions options; |
| 1699 | 1727 |
| 1700 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_, | 1728 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_, |
| 1701 "A1=B; path=/foo;", | 1729 "A1=B; path=/foo;", |
| 1702 options)); | 1730 options)); |
| 1703 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_, | 1731 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_, |
| 1704 "A2=D; path=/bar;", | 1732 "A2=D; path=/bar;", |
| 1705 options)); | 1733 options)); |
| 1706 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, | 1734 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, |
| 1707 "A3=F;", | 1735 "A3=F;", |
| 1708 options)); | 1736 options)); |
| 1709 | 1737 |
| 1738 CookieList cookies_1 = GetAllCookies(cm_1); |
| 1710 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL)); | 1739 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL)); |
| 1711 ASSERT_TRUE(cm_2->InitializeFrom(cm_1.get())); | 1740 ASSERT_TRUE(cm_2->InitializeFrom(cookies_1)); |
| 1712 CookieList cookies = cm_2->GetAllCookies(); | 1741 CookieList cookies_2 = GetAllCookies(cm_2); |
| 1713 | 1742 |
| 1714 size_t expected_size = 3; | 1743 size_t expected_size = 3; |
| 1715 EXPECT_EQ(expected_size, cookies.size()); | 1744 EXPECT_EQ(expected_size, cookies_2.size()); |
| 1716 | 1745 |
| 1717 CookieList::iterator it = cookies.begin(); | 1746 CookieList::iterator it = cookies_2.begin(); |
| 1718 | 1747 |
| 1719 ASSERT_TRUE(it != cookies.end()); | 1748 ASSERT_TRUE(it != cookies_2.end()); |
| 1720 EXPECT_EQ("A1", it->Name()); | 1749 EXPECT_EQ("A1", it->Name()); |
| 1721 EXPECT_EQ("/foo", it->Path()); | 1750 EXPECT_EQ("/foo", it->Path()); |
| 1722 | 1751 |
| 1723 ASSERT_TRUE(++it != cookies.end()); | 1752 ASSERT_TRUE(++it != cookies_2.end()); |
| 1724 EXPECT_EQ("A2", it->Name()); | 1753 EXPECT_EQ("A2", it->Name()); |
| 1725 EXPECT_EQ("/bar", it->Path()); | 1754 EXPECT_EQ("/bar", it->Path()); |
| 1726 | 1755 |
| 1727 ASSERT_TRUE(++it != cookies.end()); | 1756 ASSERT_TRUE(++it != cookies_2.end()); |
| 1728 EXPECT_EQ("A3", it->Name()); | 1757 EXPECT_EQ("A3", it->Name()); |
| 1729 EXPECT_EQ("/", it->Path()); | 1758 EXPECT_EQ("/", it->Path()); |
| 1730 } | 1759 } |
| 1731 | 1760 |
| 1732 | 1761 |
| 1733 // Test that overwriting persistent cookies deletes the old one from the | 1762 // Test that overwriting persistent cookies deletes the old one from the |
| 1734 // backing store. | 1763 // backing store. |
| 1735 TEST_F(CookieMonsterTest, OverwritePersistentCookie) { | 1764 TEST_F(CookieMonsterTest, OverwritePersistentCookie) { |
| 1736 GURL url_google("http://www.google.com/"); | 1765 GURL url_google("http://www.google.com/"); |
| 1737 GURL url_chromium("http://chromium.org"); | 1766 GURL url_chromium("http://chromium.org"); |
| 1738 scoped_refptr<MockPersistentCookieStore> store( | 1767 scoped_refptr<MockPersistentCookieStore> store( |
| 1739 new MockPersistentCookieStore); | 1768 new MockPersistentCookieStore); |
| 1740 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1769 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 1741 | 1770 |
| 1742 // Insert a cookie "a" for path "/path1" | 1771 // Insert a cookie "a" for path "/path1" |
| 1743 EXPECT_TRUE( | 1772 EXPECT_TRUE( |
| 1744 cm->SetCookie(url_google, "a=val1; path=/path1; " | 1773 SetCookie(cm, url_google, "a=val1; path=/path1; " |
| 1745 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1774 "expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1746 ASSERT_EQ(1u, store->commands().size()); | 1775 ASSERT_EQ(1u, store->commands().size()); |
| 1747 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1776 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1748 | 1777 |
| 1749 // Insert a cookie "b" for path "/path1" | 1778 // Insert a cookie "b" for path "/path1" |
| 1750 EXPECT_TRUE( | 1779 EXPECT_TRUE( |
| 1751 cm->SetCookie(url_google, "b=val1; path=/path1; " | 1780 SetCookie(cm, url_google, "b=val1; path=/path1; " |
| 1752 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 1781 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 1753 ASSERT_EQ(2u, store->commands().size()); | 1782 ASSERT_EQ(2u, store->commands().size()); |
| 1754 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[1].type); | 1783 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[1].type); |
| 1755 | 1784 |
| 1756 // Insert a cookie "b" for path "/path1", that is httponly. This should | 1785 // Insert a cookie "b" for path "/path1", that is httponly. This should |
| 1757 // overwrite the non-http-only version. | 1786 // overwrite the non-http-only version. |
| 1758 CookieOptions allow_httponly; | 1787 CookieOptions allow_httponly; |
| 1759 allow_httponly.set_include_httponly(); | 1788 allow_httponly.set_include_httponly(); |
| 1760 EXPECT_TRUE( | 1789 EXPECT_TRUE( |
| 1761 SetCookieWithOptions(cm, url_google, | 1790 SetCookieWithOptions(cm, url_google, |
| 1762 "b=val2; path=/path1; httponly; " | 1791 "b=val2; path=/path1; httponly; " |
| 1763 "expires=Mon, 18-Apr-22 22:50:14 GMT", | 1792 "expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1764 allow_httponly)); | 1793 allow_httponly)); |
| 1765 ASSERT_EQ(4u, store->commands().size()); | 1794 ASSERT_EQ(4u, store->commands().size()); |
| 1766 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); | 1795 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); |
| 1767 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[3].type); | 1796 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[3].type); |
| 1768 | 1797 |
| 1769 // Insert a cookie "a" for path "/path1". This should overwrite. | 1798 // Insert a cookie "a" for path "/path1". This should overwrite. |
| 1770 EXPECT_TRUE(cm->SetCookie(url_google, | 1799 EXPECT_TRUE(SetCookie(cm, url_google, |
| 1771 "a=val33; path=/path1; " | 1800 "a=val33; path=/path1; " |
| 1772 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 1801 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 1773 ASSERT_EQ(6u, store->commands().size()); | 1802 ASSERT_EQ(6u, store->commands().size()); |
| 1774 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[4].type); | 1803 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[4].type); |
| 1775 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[5].type); | 1804 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[5].type); |
| 1776 | 1805 |
| 1777 // Insert a cookie "a" for path "/path2". This should NOT overwrite | 1806 // Insert a cookie "a" for path "/path2". This should NOT overwrite |
| 1778 // cookie "a", since the path is different. | 1807 // cookie "a", since the path is different. |
| 1779 EXPECT_TRUE(cm->SetCookie(url_google, | 1808 EXPECT_TRUE(SetCookie(cm, url_google, |
| 1780 "a=val9; path=/path2; " | 1809 "a=val9; path=/path2; " |
| 1781 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 1810 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 1782 ASSERT_EQ(7u, store->commands().size()); | 1811 ASSERT_EQ(7u, store->commands().size()); |
| 1783 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[6].type); | 1812 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[6].type); |
| 1784 | 1813 |
| 1785 // Insert a cookie "a" for path "/path1", but this time for "chromium.org". | 1814 // Insert a cookie "a" for path "/path1", but this time for "chromium.org". |
| 1786 // Although the name and path match, the hostnames do not, so shouldn't | 1815 // Although the name and path match, the hostnames do not, so shouldn't |
| 1787 // overwrite. | 1816 // overwrite. |
| 1788 EXPECT_TRUE(cm->SetCookie(url_chromium, | 1817 EXPECT_TRUE(SetCookie(cm, url_chromium, |
| 1789 "a=val99; path=/path1; " | 1818 "a=val99; path=/path1; " |
| 1790 "expires=Mon, 18-Apr-22 22:50:14 GMT")); | 1819 "expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 1791 ASSERT_EQ(8u, store->commands().size()); | 1820 ASSERT_EQ(8u, store->commands().size()); |
| 1792 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[7].type); | 1821 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[7].type); |
| 1793 | 1822 |
| 1794 EXPECT_EQ("a=val33", GetCookies(cm, GURL("http://www.google.com/path1"))); | 1823 EXPECT_EQ("a=val33", GetCookies(cm, GURL("http://www.google.com/path1"))); |
| 1795 EXPECT_EQ("a=val9", GetCookies(cm, GURL("http://www.google.com/path2"))); | 1824 EXPECT_EQ("a=val9", GetCookies(cm, GURL("http://www.google.com/path2"))); |
| 1796 EXPECT_EQ("a=val99", GetCookies(cm, GURL("http://chromium.org/path1"))); | 1825 EXPECT_EQ("a=val99", GetCookies(cm, GURL("http://chromium.org/path1"))); |
| 1797 } | 1826 } |
| 1798 | 1827 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 EXPECT_NE(name1, name2); | 1950 EXPECT_NE(name1, name2); |
| 1922 } | 1951 } |
| 1923 | 1952 |
| 1924 TEST_F(CookieMonsterTest, Delegate) { | 1953 TEST_F(CookieMonsterTest, Delegate) { |
| 1925 scoped_refptr<MockPersistentCookieStore> store( | 1954 scoped_refptr<MockPersistentCookieStore> store( |
| 1926 new MockPersistentCookieStore); | 1955 new MockPersistentCookieStore); |
| 1927 scoped_refptr<MockCookieMonsterDelegate> delegate( | 1956 scoped_refptr<MockCookieMonsterDelegate> delegate( |
| 1928 new MockCookieMonsterDelegate); | 1957 new MockCookieMonsterDelegate); |
| 1929 scoped_refptr<CookieMonster> cm(new CookieMonster(store, delegate)); | 1958 scoped_refptr<CookieMonster> cm(new CookieMonster(store, delegate)); |
| 1930 | 1959 |
| 1931 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 1960 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 1932 EXPECT_TRUE(cm->SetCookie(url_google_, "C=D")); | 1961 EXPECT_TRUE(SetCookie(cm, url_google_, "C=D")); |
| 1933 EXPECT_TRUE(cm->SetCookie(url_google_, "E=F")); | 1962 EXPECT_TRUE(SetCookie(cm, url_google_, "E=F")); |
| 1934 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); | 1963 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); |
| 1935 ASSERT_EQ(3u, delegate->changes().size()); | 1964 ASSERT_EQ(3u, delegate->changes().size()); |
| 1936 EXPECT_FALSE(delegate->changes()[0].second); | 1965 EXPECT_FALSE(delegate->changes()[0].second); |
| 1937 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); | 1966 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); |
| 1938 EXPECT_EQ("A", delegate->changes()[0].first.Name()); | 1967 EXPECT_EQ("A", delegate->changes()[0].first.Name()); |
| 1939 EXPECT_EQ("B", delegate->changes()[0].first.Value()); | 1968 EXPECT_EQ("B", delegate->changes()[0].first.Value()); |
| 1940 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); | 1969 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); |
| 1941 EXPECT_FALSE(delegate->changes()[1].second); | 1970 EXPECT_FALSE(delegate->changes()[1].second); |
| 1942 EXPECT_EQ("C", delegate->changes()[1].first.Name()); | 1971 EXPECT_EQ("C", delegate->changes()[1].first.Name()); |
| 1943 EXPECT_EQ("D", delegate->changes()[1].first.Value()); | 1972 EXPECT_EQ("D", delegate->changes()[1].first.Value()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1955 EXPECT_EQ("C", delegate->changes()[0].first.Name()); | 1984 EXPECT_EQ("C", delegate->changes()[0].first.Name()); |
| 1956 EXPECT_EQ("D", delegate->changes()[0].first.Value()); | 1985 EXPECT_EQ("D", delegate->changes()[0].first.Value()); |
| 1957 delegate->reset(); | 1986 delegate->reset(); |
| 1958 | 1987 |
| 1959 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); | 1988 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); |
| 1960 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); | 1989 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); |
| 1961 EXPECT_EQ(0u, delegate->changes().size()); | 1990 EXPECT_EQ(0u, delegate->changes().size()); |
| 1962 | 1991 |
| 1963 // Insert a cookie "a" for path "/path1" | 1992 // Insert a cookie "a" for path "/path1" |
| 1964 EXPECT_TRUE( | 1993 EXPECT_TRUE( |
| 1965 cm->SetCookie(url_google_, "a=val1; path=/path1; " | 1994 SetCookie(cm, url_google_, "a=val1; path=/path1; " |
| 1966 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1995 "expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1967 ASSERT_EQ(1u, store->commands().size()); | 1996 ASSERT_EQ(1u, store->commands().size()); |
| 1968 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1997 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1969 ASSERT_EQ(1u, delegate->changes().size()); | 1998 ASSERT_EQ(1u, delegate->changes().size()); |
| 1970 EXPECT_FALSE(delegate->changes()[0].second); | 1999 EXPECT_FALSE(delegate->changes()[0].second); |
| 1971 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); | 2000 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); |
| 1972 EXPECT_EQ("a", delegate->changes()[0].first.Name()); | 2001 EXPECT_EQ("a", delegate->changes()[0].first.Name()); |
| 1973 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 2002 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1974 delegate->reset(); | 2003 delegate->reset(); |
| 1975 | 2004 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 CookieOptions options; | 2164 CookieOptions options; |
| 2136 | 2165 |
| 2137 // Add in three cookies through every public interface to the | 2166 // Add in three cookies through every public interface to the |
| 2138 // CookieMonster and confirm that none of them have duplicate | 2167 // CookieMonster and confirm that none of them have duplicate |
| 2139 // creation times. | 2168 // creation times. |
| 2140 | 2169 |
| 2141 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions | 2170 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions |
| 2142 // are not included as they aren't going to be public for very much | 2171 // are not included as they aren't going to be public for very much |
| 2143 // longer. | 2172 // longer. |
| 2144 | 2173 |
| 2145 // SetCookie, SetCookies, SetCookiesWithOptions, | 2174 // SetCookie, SetCookieWithOptions, SetCookieWithDetails |
| 2146 // SetCookieWithOptions, SetCookieWithDetails | |
| 2147 | 2175 |
| 2148 cm->SetCookie(url_google_, "SetCookie1=A"); | 2176 SetCookie(cm, url_google_, "SetCookie1=A"); |
| 2149 cm->SetCookie(url_google_, "SetCookie2=A"); | 2177 SetCookie(cm, url_google_, "SetCookie2=A"); |
| 2150 cm->SetCookie(url_google_, "SetCookie3=A"); | 2178 SetCookie(cm, url_google_, "SetCookie3=A"); |
| 2151 | |
| 2152 { | |
| 2153 std::vector<std::string> cookie_lines; | |
| 2154 cookie_lines.push_back("setCookies1=A"); | |
| 2155 cookie_lines.push_back("setCookies2=A"); | |
| 2156 cookie_lines.push_back("setCookies4=A"); | |
| 2157 cm->SetCookies(url_google_, cookie_lines); | |
| 2158 } | |
| 2159 | |
| 2160 { | |
| 2161 std::vector<std::string> cookie_lines; | |
| 2162 cookie_lines.push_back("setCookiesWithOptions1=A"); | |
| 2163 cookie_lines.push_back("setCookiesWithOptions2=A"); | |
| 2164 cookie_lines.push_back("setCookiesWithOptions3=A"); | |
| 2165 | |
| 2166 cm->SetCookiesWithOptions(url_google_, cookie_lines, options); | |
| 2167 } | |
| 2168 | 2179 |
| 2169 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions1=A", options); | 2180 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions1=A", options); |
| 2170 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions2=A", options); | 2181 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions2=A", options); |
| 2171 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions3=A", options); | 2182 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions3=A", options); |
| 2172 | 2183 |
| 2173 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails1", "A", | 2184 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails1", "A", |
| 2174 ".google.com", "/", Time(), false, false); | 2185 ".google.com", "/", Time(), false, false); |
| 2175 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails2", "A", | 2186 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails2", "A", |
| 2176 ".google.com", "/", Time(), false, false); | 2187 ".google.com", "/", Time(), false, false); |
| 2177 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails3", "A", | 2188 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails3", "A", |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2255 base::Time::Now() + base::TimeDelta::FromSeconds(100), | 2266 base::Time::Now() + base::TimeDelta::FromSeconds(100), |
| 2256 true, false} | 2267 true, false} |
| 2257 }; | 2268 }; |
| 2258 const int INPUT_DELETE = 1; | 2269 const int INPUT_DELETE = 1; |
| 2259 | 2270 |
| 2260 // Create new cookies and flush them to the store. | 2271 // Create new cookies and flush them to the store. |
| 2261 { | 2272 { |
| 2262 scoped_refptr<CookieMonster> cmout(new CookieMonster(store, NULL)); | 2273 scoped_refptr<CookieMonster> cmout(new CookieMonster(store, NULL)); |
| 2263 for (const CookiesInputInfo* p = input_info; | 2274 for (const CookiesInputInfo* p = input_info; |
| 2264 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) { | 2275 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) { |
| 2265 EXPECT_TRUE(cmout->SetCookieWithDetails(GURL(p->gurl), p->name, p->value, | 2276 EXPECT_TRUE(SetCookieWithDetails(cmout, GURL(p->gurl), p->name, p->value, |
| 2266 p->domain, p->path, p->expires, | 2277 p->domain, p->path, p->expires, |
| 2267 p->secure, p->http_only)); | 2278 p->secure, p->http_only)); |
| 2268 } | 2279 } |
| 2269 DeleteCookie(cmout, GURL(std::string(input_info[INPUT_DELETE].gurl) + | 2280 DeleteCookie(cmout, GURL(std::string(input_info[INPUT_DELETE].gurl) + |
| 2270 input_info[INPUT_DELETE].path), | 2281 input_info[INPUT_DELETE].path), |
| 2271 input_info[INPUT_DELETE].name); | 2282 input_info[INPUT_DELETE].name); |
| 2272 } | 2283 } |
| 2273 | 2284 |
| 2274 // Create a new cookie monster and make sure that everything is correct | 2285 // Create a new cookie monster and make sure that everything is correct |
| 2275 { | 2286 { |
| 2276 scoped_refptr<CookieMonster> cmin(new CookieMonster(store, NULL)); | 2287 scoped_refptr<CookieMonster> cmin(new CookieMonster(store, NULL)); |
| 2277 CookieList cookies(GetAllCookies(cmin)); | 2288 CookieList cookies(GetAllCookies(cmin)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2296 EXPECT_EQ(input->expires.ToInternalValue(), | 2307 EXPECT_EQ(input->expires.ToInternalValue(), |
| 2297 output->ExpiryDate().ToInternalValue()); | 2308 output->ExpiryDate().ToInternalValue()); |
| 2298 } | 2309 } |
| 2299 } | 2310 } |
| 2300 } | 2311 } |
| 2301 | 2312 |
| 2302 TEST_F(CookieMonsterTest, CookieOrdering) { | 2313 TEST_F(CookieMonsterTest, CookieOrdering) { |
| 2303 // Put a random set of cookies into a monster and make sure | 2314 // Put a random set of cookies into a monster and make sure |
| 2304 // they're returned in the right order. | 2315 // they're returned in the right order. |
| 2305 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2316 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2306 EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/x.html"), | 2317 EXPECT_TRUE(SetCookie(cm, GURL("http://d.c.b.a.google.com/aa/x.html"), |
| 2307 "c=1")); | 2318 "c=1")); |
| 2308 EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 2319 EXPECT_TRUE(SetCookie(cm, GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 2309 "d=1; domain=b.a.google.com")); | 2320 "d=1; domain=b.a.google.com")); |
| 2310 EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 2321 EXPECT_TRUE(SetCookie(cm, GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 2311 "a=4; domain=b.a.google.com")); | 2322 "a=4; domain=b.a.google.com")); |
| 2312 EXPECT_TRUE(cm->SetCookie(GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 2323 EXPECT_TRUE(SetCookie(cm, GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), |
| 2313 "e=1; domain=c.b.a.google.com")); | 2324 "e=1; domain=c.b.a.google.com")); |
| 2314 EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/bb/x.html"), | 2325 EXPECT_TRUE(SetCookie(cm, GURL("http://d.c.b.a.google.com/aa/bb/x.html"), |
| 2315 "b=1")); | 2326 "b=1")); |
| 2316 EXPECT_TRUE(cm->SetCookie(GURL("http://news.bbc.co.uk/midpath/x.html"), | 2327 EXPECT_TRUE(SetCookie(cm, GURL("http://news.bbc.co.uk/midpath/x.html"), |
| 2317 "g=10")); | 2328 "g=10")); |
| 2318 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", | 2329 EXPECT_EQ("d=1; a=4; e=1; b=1; c=1", |
| 2319 GetCookiesWithOptions(cm, | 2330 GetCookiesWithOptions(cm, |
| 2320 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"), | 2331 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"), |
| 2321 CookieOptions())); | 2332 CookieOptions())); |
| 2322 { | 2333 { |
| 2323 unsigned int i = 0; | 2334 unsigned int i = 0; |
| 2324 CookieList cookies(cm->GetAllCookiesForURL( | 2335 CookieList cookies(GetAllCookiesForURL( |
| 2336 cm, |
| 2325 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); | 2337 GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); |
| 2326 ASSERT_EQ(5u, cookies.size()); | 2338 ASSERT_EQ(5u, cookies.size()); |
| 2327 EXPECT_EQ("d", cookies[i++].Name()); | 2339 EXPECT_EQ("d", cookies[i++].Name()); |
| 2328 EXPECT_EQ("a", cookies[i++].Name()); | 2340 EXPECT_EQ("a", cookies[i++].Name()); |
| 2329 EXPECT_EQ("e", cookies[i++].Name()); | 2341 EXPECT_EQ("e", cookies[i++].Name()); |
| 2330 EXPECT_EQ("b", cookies[i++].Name()); | 2342 EXPECT_EQ("b", cookies[i++].Name()); |
| 2331 EXPECT_EQ("c", cookies[i++].Name()); | 2343 EXPECT_EQ("c", cookies[i++].Name()); |
| 2332 } | 2344 } |
| 2333 | 2345 |
| 2334 { | 2346 { |
| 2335 unsigned int i = 0; | 2347 unsigned int i = 0; |
| 2336 CookieList cookies(GetAllCookies(cm)); | 2348 CookieList cookies(GetAllCookies(cm)); |
| 2337 ASSERT_EQ(6u, cookies.size()); | 2349 ASSERT_EQ(6u, cookies.size()); |
| 2338 EXPECT_EQ("d", cookies[i++].Name()); | 2350 EXPECT_EQ("d", cookies[i++].Name()); |
| 2339 EXPECT_EQ("a", cookies[i++].Name()); | 2351 EXPECT_EQ("a", cookies[i++].Name()); |
| 2340 EXPECT_EQ("e", cookies[i++].Name()); | 2352 EXPECT_EQ("e", cookies[i++].Name()); |
| 2341 EXPECT_EQ("g", cookies[i++].Name()); | 2353 EXPECT_EQ("g", cookies[i++].Name()); |
| 2342 EXPECT_EQ("b", cookies[i++].Name()); | 2354 EXPECT_EQ("b", cookies[i++].Name()); |
| 2343 EXPECT_EQ("c", cookies[i++].Name()); | 2355 EXPECT_EQ("c", cookies[i++].Name()); |
| 2344 } | 2356 } |
| 2345 } | 2357 } |
| 2346 | 2358 |
| 2347 | |
| 2348 // Function for creating a CM with a number of cookies in it, | |
| 2349 // no store (and hence no ability to affect access time). | |
| 2350 static CookieMonster* CreateMonsterForGC(int num_cookies) { | |
| 2351 CookieMonster* cm(new CookieMonster(NULL, NULL)); | |
| 2352 for (int i = 0; i < num_cookies; i++) | |
| 2353 cm->SetCookie(GURL(StringPrintf("http://h%05d.izzle", i)), "a=1"); | |
| 2354 return cm; | |
| 2355 } | |
| 2356 | |
| 2357 // This test and CookieMonstertest.TestGCTimes (in cookie_monster_perftest.cc) | 2359 // This test and CookieMonstertest.TestGCTimes (in cookie_monster_perftest.cc) |
| 2358 // are somewhat complementary twins. This test is probing for whether | 2360 // are somewhat complementary twins. This test is probing for whether |
| 2359 // garbage collection always happens when it should (i.e. that we actually | 2361 // garbage collection always happens when it should (i.e. that we actually |
| 2360 // get rid of cookies when we should). The perftest is probing for | 2362 // get rid of cookies when we should). The perftest is probing for |
| 2361 // whether garbage collection happens when it shouldn't. See comments | 2363 // whether garbage collection happens when it shouldn't. See comments |
| 2362 // before that test for more details. | 2364 // before that test for more details. |
| 2363 TEST_F(CookieMonsterTest, GarbageCollectionTriggers) { | 2365 TEST_F(CookieMonsterTest, GarbageCollectionTriggers) { |
| 2364 // First we check to make sure that a whole lot of recent cookies | 2366 // First we check to make sure that a whole lot of recent cookies |
| 2365 // doesn't get rid of anything after garbage collection is checked for. | 2367 // doesn't get rid of anything after garbage collection is checked for. |
| 2366 { | 2368 { |
| 2367 scoped_refptr<CookieMonster> cm( | 2369 scoped_refptr<CookieMonster> cm( |
| 2368 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); | 2370 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); |
| 2369 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm).size()); | 2371 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm).size()); |
| 2370 cm->SetCookie(GURL("http://newdomain.com"), "b=2"); | 2372 SetCookie(cm, GURL("http://newdomain.com"), "b=2"); |
| 2371 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, GetAllCookies(cm).size()); | 2373 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, GetAllCookies(cm).size()); |
| 2372 } | 2374 } |
| 2373 | 2375 |
| 2374 // Now we explore a series of relationships between cookie last access | 2376 // Now we explore a series of relationships between cookie last access |
| 2375 // time and size of store to make sure we only get rid of cookies when | 2377 // time and size of store to make sure we only get rid of cookies when |
| 2376 // we really should. | 2378 // we really should. |
| 2377 const struct TestCase { | 2379 const struct TestCase { |
| 2378 int num_cookies; | 2380 int num_cookies; |
| 2379 int num_old_cookies; | 2381 int num_old_cookies; |
| 2380 int expected_initial_cookies; | 2382 int expected_initial_cookies; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2425 const TestCase *test_case = &test_cases[ci]; | 2427 const TestCase *test_case = &test_cases[ci]; |
| 2426 scoped_refptr<CookieMonster> cm( | 2428 scoped_refptr<CookieMonster> cm( |
| 2427 CreateMonsterFromStoreForGC( | 2429 CreateMonsterFromStoreForGC( |
| 2428 test_case->num_cookies, test_case->num_old_cookies, | 2430 test_case->num_cookies, test_case->num_old_cookies, |
| 2429 CookieMonster::kSafeFromGlobalPurgeDays * 2)); | 2431 CookieMonster::kSafeFromGlobalPurgeDays * 2)); |
| 2430 cm->SetExpiryAndKeyScheme(schemes[recent_scheme]); | 2432 cm->SetExpiryAndKeyScheme(schemes[recent_scheme]); |
| 2431 EXPECT_EQ(test_case->expected_initial_cookies, | 2433 EXPECT_EQ(test_case->expected_initial_cookies, |
| 2432 static_cast<int>(GetAllCookies(cm).size())) | 2434 static_cast<int>(GetAllCookies(cm).size())) |
| 2433 << "For test case " << ci; | 2435 << "For test case " << ci; |
| 2434 // Will trigger GC | 2436 // Will trigger GC |
| 2435 cm->SetCookie(GURL("http://newdomain.com"), "b=2"); | 2437 SetCookie(cm, GURL("http://newdomain.com"), "b=2"); |
| 2436 EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme], | 2438 EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme], |
| 2437 static_cast<int>((GetAllCookies(cm).size()))) | 2439 static_cast<int>((GetAllCookies(cm).size()))) |
| 2438 << "For test case (" << ci << ", " << recent_scheme << ")"; | 2440 << "For test case (" << ci << ", " << recent_scheme << ")"; |
| 2439 } | 2441 } |
| 2440 } | 2442 } |
| 2441 } | 2443 } |
| 2442 | 2444 |
| 2443 // This test checks that setting a cookie forcing it to be a session only | 2445 // This test checks that setting a cookie forcing it to be a session only |
| 2444 // cookie works as expected. | 2446 // cookie works as expected. |
| 2445 TEST_F(CookieMonsterTest, ForceSessionOnly) { | 2447 TEST_F(CookieMonsterTest, ForceSessionOnly) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); | 2496 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); |
| 2495 } | 2497 } |
| 2496 | 2498 |
| 2497 namespace { | 2499 namespace { |
| 2498 | 2500 |
| 2499 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. | 2501 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. |
| 2500 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { | 2502 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { |
| 2501 public: | 2503 public: |
| 2502 FlushablePersistentStore() : flush_count_(0) {} | 2504 FlushablePersistentStore() : flush_count_(0) {} |
| 2503 | 2505 |
| 2504 bool Load(std::vector<CookieMonster::CanonicalCookie*>*) { | 2506 bool Load(const LoadedCallback& loaded_callback) { |
| 2507 std::vector<CookieMonster::CanonicalCookie*> out_cookies; |
| 2508 loaded_callback.Run(out_cookies); |
| 2505 return false; | 2509 return false; |
| 2506 } | 2510 } |
| 2507 | 2511 |
| 2508 void AddCookie(const CookieMonster::CanonicalCookie&) {} | 2512 void AddCookie(const CookieMonster::CanonicalCookie&) {} |
| 2509 void UpdateCookieAccessTime(const CookieMonster::CanonicalCookie&) {} | 2513 void UpdateCookieAccessTime(const CookieMonster::CanonicalCookie&) {} |
| 2510 void DeleteCookie(const CookieMonster::CanonicalCookie&) {} | 2514 void DeleteCookie(const CookieMonster::CanonicalCookie&) {} |
| 2511 void SetClearLocalStateOnExit(bool clear_local_state) {} | 2515 void SetClearLocalStateOnExit(bool clear_local_state) {} |
| 2512 | 2516 |
| 2513 void Flush(Task* completion_callback) { | 2517 void Flush(Task* completion_callback) { |
| 2514 ++flush_count_; | 2518 ++flush_count_; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2644 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", | 2648 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", |
| 2645 base::Time::Now() + base::TimeDelta::FromMinutes(59), | 2649 base::Time::Now() + base::TimeDelta::FromMinutes(59), |
| 2646 false, false)); | 2650 false, false)); |
| 2647 | 2651 |
| 2648 base::Histogram::SampleSet histogram_set_2; | 2652 base::Histogram::SampleSet histogram_set_2; |
| 2649 expired_histogram->SnapshotSample(&histogram_set_2); | 2653 expired_histogram->SnapshotSample(&histogram_set_2); |
| 2650 EXPECT_EQ(histogram_set_1.TotalCount() + 1, | 2654 EXPECT_EQ(histogram_set_1.TotalCount() + 1, |
| 2651 histogram_set_2.TotalCount()); | 2655 histogram_set_2.TotalCount()); |
| 2652 | 2656 |
| 2653 // kValidCookieLine creates a session cookie. | 2657 // kValidCookieLine creates a session cookie. |
| 2654 ASSERT_TRUE(cm->SetCookie(url_google_, kValidCookieLine)); | 2658 ASSERT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
| 2655 expired_histogram->SnapshotSample(&histogram_set_1); | 2659 expired_histogram->SnapshotSample(&histogram_set_1); |
| 2656 EXPECT_EQ(histogram_set_2.TotalCount(), | 2660 EXPECT_EQ(histogram_set_2.TotalCount(), |
| 2657 histogram_set_1.TotalCount()); | 2661 histogram_set_1.TotalCount()); |
| 2658 } | 2662 } |
| 2659 | 2663 |
| 2660 namespace { | 2664 namespace { |
| 2661 | 2665 |
| 2662 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { | 2666 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { |
| 2663 public: | 2667 public: |
| 2664 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} | 2668 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} |
| 2665 | 2669 |
| 2666 // Helper methods for calling the asynchronous CookieMonster methods | 2670 // Helper methods for calling the asynchronous CookieMonster methods |
| 2667 // from a different thread. | 2671 // from a different thread. |
| 2668 | 2672 |
| 2669 void GetCookiesTask(CookieMonster* cm, | 2673 void GetCookiesTask(CookieMonster* cm, |
| 2670 const GURL& url, | 2674 const GURL& url, |
| 2671 GetCookieStringCallback* callback) { | 2675 GetCookieStringCallback* callback) { |
| 2672 cm->GetCookiesAsync( | 2676 cm->GetCookiesWithOptionsAsync( |
| 2673 url, | 2677 url, CookieOptions(), |
| 2674 base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback))); | 2678 base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback))); |
| 2675 } | 2679 } |
| 2676 | 2680 |
| 2677 void GetCookiesWithOptionsTask(CookieMonster* cm, | 2681 void GetCookiesWithOptionsTask(CookieMonster* cm, |
| 2678 const GURL& url, | 2682 const GURL& url, |
| 2679 const CookieOptions& options, | 2683 const CookieOptions& options, |
| 2680 GetCookieStringCallback* callback) { | 2684 GetCookieStringCallback* callback) { |
| 2681 cm->GetCookiesWithOptionsAsync( | 2685 cm->GetCookiesWithOptionsAsync( |
| 2682 url, options, | 2686 url, options, |
| 2683 base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback))); | 2687 base::Bind(&GetCookieStringCallback::Run, base::Unretained(callback))); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2790 }; | 2794 }; |
| 2791 | 2795 |
| 2792 } // namespace | 2796 } // namespace |
| 2793 | 2797 |
| 2794 // TODO(ycxiao): Eventually, we will need to create a separate thread, create | 2798 // TODO(ycxiao): Eventually, we will need to create a separate thread, create |
| 2795 // the cookie monster on that thread (or at least its store, i.e., the DB | 2799 // the cookie monster on that thread (or at least its store, i.e., the DB |
| 2796 // thread). | 2800 // thread). |
| 2797 | 2801 |
| 2798 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookies) { | 2802 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookies) { |
| 2799 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2803 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2800 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 2804 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2801 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 2805 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 2802 GetCookieStringCallback callback(&other_thread_); | 2806 GetCookieStringCallback callback(&other_thread_); |
| 2803 base::Closure task = base::Bind( | 2807 base::Closure task = base::Bind( |
| 2804 &net::MultiThreadedCookieMonsterTest::GetCookiesTask, | 2808 &net::MultiThreadedCookieMonsterTest::GetCookiesTask, |
| 2805 base::Unretained(this), | 2809 base::Unretained(this), |
| 2806 cm, url_google_, &callback); | 2810 cm, url_google_, &callback); |
| 2807 RunOnOtherThread(task); | 2811 RunOnOtherThread(task); |
| 2808 EXPECT_TRUE(callback.did_run()); | 2812 EXPECT_TRUE(callback.did_run()); |
| 2809 EXPECT_EQ("A=B", callback.cookie()); | 2813 EXPECT_EQ("A=B", callback.cookie()); |
| 2810 } | 2814 } |
| 2811 | 2815 |
| 2812 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithOptions) { | 2816 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithOptions) { |
| 2813 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2817 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2814 CookieOptions options; | 2818 CookieOptions options; |
| 2815 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 2819 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2816 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); | 2820 EXPECT_EQ("A=B", GetCookiesWithOptions(cm, url_google_, options)); |
| 2817 GetCookieStringCallback callback(&other_thread_); | 2821 GetCookieStringCallback callback(&other_thread_); |
| 2818 base::Closure task = base::Bind( | 2822 base::Closure task = base::Bind( |
| 2819 &net::MultiThreadedCookieMonsterTest::GetCookiesWithOptionsTask, | 2823 &net::MultiThreadedCookieMonsterTest::GetCookiesWithOptionsTask, |
| 2820 base::Unretained(this), | 2824 base::Unretained(this), |
| 2821 cm, url_google_, options, &callback); | 2825 cm, url_google_, options, &callback); |
| 2822 RunOnOtherThread(task); | 2826 RunOnOtherThread(task); |
| 2823 EXPECT_TRUE(callback.did_run()); | 2827 EXPECT_TRUE(callback.did_run()); |
| 2824 EXPECT_EQ("A=B", callback.cookie()); | 2828 EXPECT_EQ("A=B", callback.cookie()); |
| 2825 } | 2829 } |
| 2826 | 2830 |
| 2827 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithInfo) { | 2831 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetCookiesWithInfo) { |
| 2828 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2832 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2829 CookieOptions options; | 2833 CookieOptions options; |
| 2830 std::string cookie_line; | 2834 std::string cookie_line; |
| 2831 std::vector<CookieStore::CookieInfo> cookie_infos; | 2835 std::vector<CookieStore::CookieInfo> cookie_infos; |
| 2832 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 2836 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2833 GetCookiesWithInfo(cm, url_google_, options, &cookie_line, &cookie_infos); | 2837 GetCookiesWithInfo(cm, url_google_, options, &cookie_line, &cookie_infos); |
| 2834 EXPECT_EQ("A=B", cookie_line); | 2838 EXPECT_EQ("A=B", cookie_line); |
| 2835 EXPECT_EQ(1U, cookie_infos.size()); | 2839 EXPECT_EQ(1U, cookie_infos.size()); |
| 2836 EXPECT_EQ("A", cookie_infos[0].name); | 2840 EXPECT_EQ("A", cookie_infos[0].name); |
| 2837 EXPECT_EQ("", cookie_infos[0].mac_key); | 2841 EXPECT_EQ("", cookie_infos[0].mac_key); |
| 2838 EXPECT_EQ("", cookie_infos[0].mac_algorithm); | 2842 EXPECT_EQ("", cookie_infos[0].mac_algorithm); |
| 2839 GetCookiesWithInfoCallback callback(&other_thread_); | 2843 GetCookiesWithInfoCallback callback(&other_thread_); |
| 2840 base::Closure task = | 2844 base::Closure task = |
| 2841 base::Bind(&net::MultiThreadedCookieMonsterTest::GetCookiesWithInfoTask, | 2845 base::Bind(&net::MultiThreadedCookieMonsterTest::GetCookiesWithInfoTask, |
| 2842 base::Unretained(this), | 2846 base::Unretained(this), |
| 2843 cm, url_google_, options, &callback); | 2847 cm, url_google_, options, &callback); |
| 2844 RunOnOtherThread(task); | 2848 RunOnOtherThread(task); |
| 2845 EXPECT_TRUE(callback.did_run()); | 2849 EXPECT_TRUE(callback.did_run()); |
| 2846 EXPECT_EQ("A=B", callback.cookie_line()); | 2850 EXPECT_EQ("A=B", callback.cookie_line()); |
| 2847 EXPECT_EQ(1U, callback.cookie_info().size()); | 2851 EXPECT_EQ(1U, callback.cookie_info().size()); |
| 2848 EXPECT_EQ("A", callback.cookie_info()[0].name); | 2852 EXPECT_EQ("A", callback.cookie_info()[0].name); |
| 2849 EXPECT_EQ("", callback.cookie_info()[0].mac_key); | 2853 EXPECT_EQ("", callback.cookie_info()[0].mac_key); |
| 2850 EXPECT_EQ("", callback.cookie_info()[0].mac_algorithm); | 2854 EXPECT_EQ("", callback.cookie_info()[0].mac_algorithm); |
| 2851 } | 2855 } |
| 2852 | 2856 |
| 2853 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { | 2857 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { |
| 2854 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2858 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2855 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 2859 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2856 CookieList cookies = GetAllCookies(cm); | 2860 CookieList cookies = GetAllCookies(cm); |
| 2857 CookieList::const_iterator it = cookies.begin(); | 2861 CookieList::const_iterator it = cookies.begin(); |
| 2858 ASSERT_TRUE(it != cookies.end()); | 2862 ASSERT_TRUE(it != cookies.end()); |
| 2859 EXPECT_EQ("www.google.izzle", it->Domain()); | 2863 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2860 EXPECT_EQ("A", it->Name()); | 2864 EXPECT_EQ("A", it->Name()); |
| 2861 ASSERT_TRUE(++it == cookies.end()); | 2865 ASSERT_TRUE(++it == cookies.end()); |
| 2862 GetCookieListCallback callback(&other_thread_); | 2866 GetCookieListCallback callback(&other_thread_); |
| 2863 base::Closure task = | 2867 base::Closure task = |
| 2864 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, | 2868 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, |
| 2865 base::Unretained(this), | 2869 base::Unretained(this), |
| 2866 cm, &callback); | 2870 cm, &callback); |
| 2867 RunOnOtherThread(task); | 2871 RunOnOtherThread(task); |
| 2868 EXPECT_TRUE(callback.did_run()); | 2872 EXPECT_TRUE(callback.did_run()); |
| 2869 it = callback.cookies().begin(); | 2873 it = callback.cookies().begin(); |
| 2870 ASSERT_TRUE(it != callback.cookies().end()); | 2874 ASSERT_TRUE(it != callback.cookies().end()); |
| 2871 EXPECT_EQ("www.google.izzle", it->Domain()); | 2875 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2872 EXPECT_EQ("A", it->Name()); | 2876 EXPECT_EQ("A", it->Name()); |
| 2873 ASSERT_TRUE(++it == callback.cookies().end()); | 2877 ASSERT_TRUE(++it == callback.cookies().end()); |
| 2874 } | 2878 } |
| 2875 | 2879 |
| 2876 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { | 2880 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { |
| 2877 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2881 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2878 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 2882 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2879 CookieList cookies = GetAllCookiesForURL(cm, url_google_); | 2883 CookieList cookies = GetAllCookiesForURL(cm, url_google_); |
| 2880 CookieList::const_iterator it = cookies.begin(); | 2884 CookieList::const_iterator it = cookies.begin(); |
| 2881 ASSERT_TRUE(it != cookies.end()); | 2885 ASSERT_TRUE(it != cookies.end()); |
| 2882 EXPECT_EQ("www.google.izzle", it->Domain()); | 2886 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2883 EXPECT_EQ("A", it->Name()); | 2887 EXPECT_EQ("A", it->Name()); |
| 2884 ASSERT_TRUE(++it == cookies.end()); | 2888 ASSERT_TRUE(++it == cookies.end()); |
| 2885 GetCookieListCallback callback(&other_thread_); | 2889 GetCookieListCallback callback(&other_thread_); |
| 2886 base::Closure task = | 2890 base::Closure task = |
| 2887 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, | 2891 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, |
| 2888 base::Unretained(this), | 2892 base::Unretained(this), |
| 2889 cm, url_google_, &callback); | 2893 cm, url_google_, &callback); |
| 2890 RunOnOtherThread(task); | 2894 RunOnOtherThread(task); |
| 2891 EXPECT_TRUE(callback.did_run()); | 2895 EXPECT_TRUE(callback.did_run()); |
| 2892 it = callback.cookies().begin(); | 2896 it = callback.cookies().begin(); |
| 2893 ASSERT_TRUE(it != callback.cookies().end()); | 2897 ASSERT_TRUE(it != callback.cookies().end()); |
| 2894 EXPECT_EQ("www.google.izzle", it->Domain()); | 2898 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2895 EXPECT_EQ("A", it->Name()); | 2899 EXPECT_EQ("A", it->Name()); |
| 2896 ASSERT_TRUE(++it == callback.cookies().end()); | 2900 ASSERT_TRUE(++it == callback.cookies().end()); |
| 2897 } | 2901 } |
| 2898 | 2902 |
| 2899 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { | 2903 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { |
| 2900 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2904 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2901 EXPECT_TRUE(cm->SetCookie(url_google_, "A=B")); | 2905 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 2902 CookieOptions options; | 2906 CookieOptions options; |
| 2903 CookieList cookies = | 2907 CookieList cookies = |
| 2904 GetAllCookiesForURLWithOptions(cm, url_google_, options); | 2908 GetAllCookiesForURLWithOptions(cm, url_google_, options); |
| 2905 CookieList::const_iterator it = cookies.begin(); | 2909 CookieList::const_iterator it = cookies.begin(); |
| 2906 ASSERT_TRUE(it != cookies.end()); | 2910 ASSERT_TRUE(it != cookies.end()); |
| 2907 EXPECT_EQ("www.google.izzle", it->Domain()); | 2911 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2908 EXPECT_EQ("A", it->Name()); | 2912 EXPECT_EQ("A", it->Name()); |
| 2909 ASSERT_TRUE(++it == cookies.end()); | 2913 ASSERT_TRUE(++it == cookies.end()); |
| 2910 GetCookieListCallback callback(&other_thread_); | 2914 GetCookieListCallback callback(&other_thread_); |
| 2911 base::Closure task = base::Bind( | 2915 base::Closure task = base::Bind( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3016 base::Closure task = base::Bind( | 3020 base::Closure task = base::Bind( |
| 3017 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, | 3021 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, |
| 3018 base::Unretained(this), | 3022 base::Unretained(this), |
| 3019 cm, *it, &callback); | 3023 cm, *it, &callback); |
| 3020 RunOnOtherThread(task); | 3024 RunOnOtherThread(task); |
| 3021 EXPECT_TRUE(callback.did_run()); | 3025 EXPECT_TRUE(callback.did_run()); |
| 3022 EXPECT_TRUE(callback.result()); | 3026 EXPECT_TRUE(callback.result()); |
| 3023 } | 3027 } |
| 3024 | 3028 |
| 3025 } // namespace net | 3029 } // namespace net |
| OLD | NEW |