OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cookies/cookie_monster.h" | 5 #include "net/cookies/cookie_monster.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 static std::unique_ptr<CookieStore> Create() { | 101 static std::unique_ptr<CookieStore> Create() { |
102 return base::MakeUnique<CookieMonster>(nullptr, nullptr); | 102 return base::MakeUnique<CookieMonster>(nullptr, nullptr); |
103 } | 103 } |
104 | 104 |
105 static const bool supports_http_only = true; | 105 static const bool supports_http_only = true; |
106 static const bool supports_non_dotted_domains = true; | 106 static const bool supports_non_dotted_domains = true; |
107 static const bool preserves_trailing_dots = true; | 107 static const bool preserves_trailing_dots = true; |
108 static const bool filters_schemes = true; | 108 static const bool filters_schemes = true; |
109 static const bool has_path_prefix_bug = false; | 109 static const bool has_path_prefix_bug = false; |
110 static const int creation_time_granularity_in_ms = 0; | 110 static const int creation_time_granularity_in_ms = 0; |
111 static const bool enforce_strict_secure = false; | |
112 }; | |
113 | |
114 struct CookieMonsterEnforcingStrictSecure { | |
115 static std::unique_ptr<CookieStore> Create() { | |
116 return base::MakeUnique<CookieMonster>(nullptr, nullptr); | |
117 } | |
118 | |
119 static const bool supports_http_only = true; | |
120 static const bool supports_non_dotted_domains = true; | |
121 static const bool preserves_trailing_dots = true; | |
122 static const bool filters_schemes = true; | |
123 static const bool has_path_prefix_bug = false; | |
124 static const int creation_time_granularity_in_ms = 0; | |
125 static const bool enforce_strict_secure = true; | |
126 }; | 111 }; |
127 | 112 |
128 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 113 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
129 CookieStoreTest, | 114 CookieStoreTest, |
130 CookieMonsterTestTraits); | 115 CookieMonsterTestTraits); |
131 | 116 |
132 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonsterStrictSecure, | |
133 CookieStoreTest, | |
134 CookieMonsterEnforcingStrictSecure); | |
135 | |
136 template <typename T> | 117 template <typename T> |
137 class CookieMonsterTestBase : public CookieStoreTest<T> { | 118 class CookieMonsterTestBase : public CookieStoreTest<T> { |
138 public: | 119 public: |
139 using CookieStoreTest<T>::SetCookie; | 120 using CookieStoreTest<T>::SetCookie; |
140 | 121 |
141 protected: | 122 protected: |
142 using CookieStoreTest<T>::http_www_google_; | 123 using CookieStoreTest<T>::http_www_google_; |
143 using CookieStoreTest<T>::https_www_google_; | 124 using CookieStoreTest<T>::https_www_google_; |
144 | 125 |
145 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, | 126 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 it->Priority() == cookie.Priority()) { | 779 it->Priority() == cookie.Priority()) { |
799 return true; | 780 return true; |
800 } | 781 } |
801 } | 782 } |
802 | 783 |
803 return false; | 784 return false; |
804 } | 785 } |
805 }; | 786 }; |
806 | 787 |
807 using CookieMonsterTest = CookieMonsterTestBase<CookieMonsterTestTraits>; | 788 using CookieMonsterTest = CookieMonsterTestBase<CookieMonsterTestTraits>; |
808 using CookieMonsterStrictSecureTest = | |
809 CookieMonsterTestBase<CookieMonsterEnforcingStrictSecure>; | |
810 | 789 |
811 // TODO(erikwright): Replace the other callbacks and synchronous helper methods | 790 // TODO(erikwright): Replace the other callbacks and synchronous helper methods |
812 // in this test suite with these Mocks. | 791 // in this test suite with these Mocks. |
813 using MockClosure = base::MockCallback<base::Closure>; | 792 using MockClosure = base::MockCallback<base::Closure>; |
814 using MockGetCookiesCallback = | 793 using MockGetCookiesCallback = |
815 base::MockCallback<CookieStore::GetCookiesCallback>; | 794 base::MockCallback<CookieStore::GetCookiesCallback>; |
816 using MockSetCookiesCallback = | 795 using MockSetCookiesCallback = |
817 base::MockCallback<CookieStore::SetCookiesCallback>; | 796 base::MockCallback<CookieStore::SetCookiesCallback>; |
818 using MockGetCookieListCallback = | 797 using MockGetCookieListCallback = |
819 base::MockCallback<CookieMonster::GetCookieListCallback>; | 798 base::MockCallback<CookieMonster::GetCookieListCallback>; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 delete_begin, | 836 delete_begin, |
858 delete_end, | 837 delete_end, |
859 callback) { | 838 callback) { |
860 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, | 839 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, |
861 callback->Get()); | 840 callback->Get()); |
862 } | 841 } |
863 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { | 842 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { |
864 cookie_monster->SetCookieWithDetailsAsync( | 843 cookie_monster->SetCookieWithDetailsAsync( |
865 cc.url, cc.name, cc.value, cc.domain, cc.path, base::Time(), | 844 cc.url, cc.name, cc.value, cc.domain, cc.path, base::Time(), |
866 cc.expiration_time, base::Time(), cc.secure, cc.http_only, cc.same_site, | 845 cc.expiration_time, base::Time(), cc.secure, cc.http_only, cc.same_site, |
867 false /* enforces strict secure cookies */, cc.priority, callback->Get()); | 846 cc.priority, callback->Get()); |
868 } | 847 } |
869 | 848 |
870 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { | 849 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { |
871 cookie_monster->GetAllCookiesAsync(callback->Get()); | 850 cookie_monster->GetAllCookiesAsync(callback->Get()); |
872 } | 851 } |
873 | 852 |
874 ACTION_P5(DeleteAllCreatedBetweenWithPredicateAction, | 853 ACTION_P5(DeleteAllCreatedBetweenWithPredicateAction, |
875 cookie_monster, | 854 cookie_monster, |
876 delete_begin, | 855 delete_begin, |
877 delete_end, | 856 delete_end, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 CompleteLoading(); | 1035 CompleteLoading(); |
1057 loop.Run(); | 1036 loop.Run(); |
1058 } | 1037 } |
1059 | 1038 |
1060 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { | 1039 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { |
1061 MockSetCookiesCallback set_cookies_callback; | 1040 MockSetCookiesCallback set_cookies_callback; |
1062 CookieList list; | 1041 CookieList list; |
1063 list.push_back(*CanonicalCookie::Create( | 1042 list.push_back(*CanonicalCookie::Create( |
1064 http_www_google_.url(), "A", "B", http_www_google_.domain(), "/", | 1043 http_www_google_.url(), "A", "B", http_www_google_.domain(), "/", |
1065 base::Time::Now(), base::Time(), false, true, | 1044 base::Time::Now(), base::Time(), false, true, |
1066 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 1045 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
1067 list.push_back(*CanonicalCookie::Create( | 1046 list.push_back(*CanonicalCookie::Create( |
1068 http_www_google_.url(), "C", "D", http_www_google_.domain(), "/", | 1047 http_www_google_.url(), "C", "D", http_www_google_.domain(), "/", |
1069 base::Time::Now(), base::Time(), false, true, | 1048 base::Time::Now(), base::Time(), false, true, |
1070 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 1049 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
1071 | 1050 |
1072 BeginWith( | 1051 BeginWith( |
1073 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 1052 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
1074 | 1053 |
1075 WaitForLoadCall(); | 1054 WaitForLoadCall(); |
1076 | 1055 |
1077 EXPECT_CALL(set_cookies_callback, Run(true)) | 1056 EXPECT_CALL(set_cookies_callback, Run(true)) |
1078 .WillOnce( | 1057 .WillOnce( |
1079 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 1058 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
1080 base::RunLoop loop; | 1059 base::RunLoop loop; |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 } | 1537 } |
1559 | 1538 |
1560 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionNonSecure) { | 1539 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionNonSecure) { |
1561 TestPriorityAwareGarbageCollectHelperNonSecure(); | 1540 TestPriorityAwareGarbageCollectHelperNonSecure(); |
1562 } | 1541 } |
1563 | 1542 |
1564 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionSecure) { | 1543 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionSecure) { |
1565 TestPriorityAwareGarbageCollectHelperSecure(); | 1544 TestPriorityAwareGarbageCollectHelperSecure(); |
1566 } | 1545 } |
1567 | 1546 |
1568 TEST_F(CookieMonsterStrictSecureTest, TestPriorityAwareGarbageCollectionMixed) { | 1547 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionMixed) { |
1569 TestPriorityAwareGarbageCollectHelperMixed(); | 1548 TestPriorityAwareGarbageCollectHelperMixed(); |
1570 } | 1549 } |
1571 | 1550 |
1572 TEST_F(CookieMonsterTest, SetCookieableSchemes) { | 1551 TEST_F(CookieMonsterTest, SetCookieableSchemes) { |
1573 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1552 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
1574 std::unique_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, nullptr)); | 1553 std::unique_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, nullptr)); |
1575 | 1554 |
1576 // Only cm_foo should allow foo:// cookies. | 1555 // Only cm_foo should allow foo:// cookies. |
1577 std::vector<std::string> schemes; | 1556 std::vector<std::string> schemes; |
1578 schemes.push_back("foo"); | 1557 schemes.push_back("foo"); |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2550 cm->SetPersistSessionCookies(true); | 2529 cm->SetPersistSessionCookies(true); |
2551 | 2530 |
2552 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2531 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); |
2553 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2532 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); |
2554 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2533 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); |
2555 | 2534 |
2556 CookieList list; | 2535 CookieList list; |
2557 list.push_back(*CanonicalCookie::Create( | 2536 list.push_back(*CanonicalCookie::Create( |
2558 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", | 2537 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", |
2559 base::Time::Now(), base::Time(), false, false, | 2538 base::Time::Now(), base::Time(), false, false, |
2560 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2539 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
2561 list.push_back(*CanonicalCookie::Create( | 2540 list.push_back(*CanonicalCookie::Create( |
2562 http_www_google_.url(), "W", "X", http_www_google_.url().host(), "/bar", | 2541 http_www_google_.url(), "W", "X", http_www_google_.url().host(), "/bar", |
2563 base::Time::Now(), base::Time(), false, false, | 2542 base::Time::Now(), base::Time(), false, false, |
2564 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2543 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
2565 list.push_back(*CanonicalCookie::Create( | 2544 list.push_back(*CanonicalCookie::Create( |
2566 http_www_google_.url(), "Y", "Z", http_www_google_.url().host(), "/", | 2545 http_www_google_.url(), "Y", "Z", http_www_google_.url().host(), "/", |
2567 base::Time::Now(), base::Time(), false, false, | 2546 base::Time::Now(), base::Time(), false, false, |
2568 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2547 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
2569 | 2548 |
2570 // SetAllCookies must not flush. | 2549 // SetAllCookies must not flush. |
2571 ASSERT_EQ(0, store->flush_count()); | 2550 ASSERT_EQ(0, store->flush_count()); |
2572 EXPECT_TRUE(SetAllCookies(cm.get(), list)); | 2551 EXPECT_TRUE(SetAllCookies(cm.get(), list)); |
2573 EXPECT_EQ(0, store->flush_count()); | 2552 EXPECT_EQ(0, store->flush_count()); |
2574 | 2553 |
2575 CookieList cookies = GetAllCookies(cm.get()); | 2554 CookieList cookies = GetAllCookies(cm.get()); |
2576 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. | 2555 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. |
2577 EXPECT_EQ(expected_size, cookies.size()); | 2556 EXPECT_EQ(expected_size, cookies.size()); |
2578 CookieList::iterator it = cookies.begin(); | 2557 CookieList::iterator it = cookies.begin(); |
(...skipping 14 matching lines...) Expand all Loading... |
2593 | 2572 |
2594 TEST_F(CookieMonsterTest, ComputeCookieDiff) { | 2573 TEST_F(CookieMonsterTest, ComputeCookieDiff) { |
2595 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2574 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
2596 | 2575 |
2597 base::Time now = base::Time::Now(); | 2576 base::Time now = base::Time::Now(); |
2598 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); | 2577 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); |
2599 | 2578 |
2600 std::unique_ptr<CanonicalCookie> cookie1(CanonicalCookie::Create( | 2579 std::unique_ptr<CanonicalCookie> cookie1(CanonicalCookie::Create( |
2601 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", | 2580 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", |
2602 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2581 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2603 false, COOKIE_PRIORITY_DEFAULT)); | 2582 COOKIE_PRIORITY_DEFAULT)); |
2604 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( | 2583 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( |
2605 http_www_google_.url(), "C", "D", http_www_google_.url().host(), "/", | 2584 http_www_google_.url(), "C", "D", http_www_google_.url().host(), "/", |
2606 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2585 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2607 false, COOKIE_PRIORITY_DEFAULT)); | 2586 COOKIE_PRIORITY_DEFAULT)); |
2608 std::unique_ptr<CanonicalCookie> cookie3(CanonicalCookie::Create( | 2587 std::unique_ptr<CanonicalCookie> cookie3(CanonicalCookie::Create( |
2609 http_www_google_.url(), "E", "F", http_www_google_.url().host(), "/", | 2588 http_www_google_.url(), "E", "F", http_www_google_.url().host(), "/", |
2610 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2589 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2611 false, COOKIE_PRIORITY_DEFAULT)); | 2590 COOKIE_PRIORITY_DEFAULT)); |
2612 std::unique_ptr<CanonicalCookie> cookie4(CanonicalCookie::Create( | 2591 std::unique_ptr<CanonicalCookie> cookie4(CanonicalCookie::Create( |
2613 http_www_google_.url(), "G", "H", http_www_google_.url().host(), "/", | 2592 http_www_google_.url(), "G", "H", http_www_google_.url().host(), "/", |
2614 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2593 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2615 false, COOKIE_PRIORITY_DEFAULT)); | 2594 COOKIE_PRIORITY_DEFAULT)); |
2616 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( | 2595 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( |
2617 CanonicalCookie::Create( | 2596 CanonicalCookie::Create( |
2618 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), | 2597 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), |
2619 "/", creation_time, base::Time(), false, false, | 2598 "/", creation_time, base::Time(), false, false, |
2620 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2599 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
2621 std::unique_ptr<CanonicalCookie> cookie5(CanonicalCookie::Create( | 2600 std::unique_ptr<CanonicalCookie> cookie5(CanonicalCookie::Create( |
2622 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", | 2601 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", |
2623 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2602 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2624 false, COOKIE_PRIORITY_DEFAULT)); | 2603 COOKIE_PRIORITY_DEFAULT)); |
2625 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( | 2604 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( |
2626 CanonicalCookie::Create( | 2605 CanonicalCookie::Create( |
2627 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", | 2606 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", |
2628 now, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, false, | 2607 now, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2629 COOKIE_PRIORITY_DEFAULT)); | 2608 COOKIE_PRIORITY_DEFAULT)); |
2630 std::unique_ptr<CanonicalCookie> cookie6(CanonicalCookie::Create( | 2609 std::unique_ptr<CanonicalCookie> cookie6(CanonicalCookie::Create( |
2631 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/foo", | 2610 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/foo", |
2632 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2611 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2633 false, COOKIE_PRIORITY_DEFAULT)); | 2612 COOKIE_PRIORITY_DEFAULT)); |
2634 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( | 2613 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( |
2635 CanonicalCookie::Create( | 2614 CanonicalCookie::Create( |
2636 http_www_google_.url(), "K", "L", http_www_google_.url().host(), | 2615 http_www_google_.url(), "K", "L", http_www_google_.url().host(), |
2637 "/bar", creation_time, base::Time(), false, false, | 2616 "/bar", creation_time, base::Time(), false, false, |
2638 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2617 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
2639 std::unique_ptr<CanonicalCookie> cookie7(CanonicalCookie::Create( | 2618 std::unique_ptr<CanonicalCookie> cookie7(CanonicalCookie::Create( |
2640 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/foo", | 2619 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/foo", |
2641 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2620 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2642 false, COOKIE_PRIORITY_DEFAULT)); | 2621 COOKIE_PRIORITY_DEFAULT)); |
2643 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( | 2622 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( |
2644 CanonicalCookie::Create( | 2623 CanonicalCookie::Create( |
2645 http_www_google_.url(), "M", "N", http_www_google_.url().host(), | 2624 http_www_google_.url(), "M", "N", http_www_google_.url().host(), |
2646 "/bar", creation_time, base::Time(), false, false, | 2625 "/bar", creation_time, base::Time(), false, false, |
2647 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2626 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
2648 | 2627 |
2649 CookieList old_cookies; | 2628 CookieList old_cookies; |
2650 old_cookies.push_back(*cookie1); | 2629 old_cookies.push_back(*cookie1); |
2651 old_cookies.push_back(*cookie2); | 2630 old_cookies.push_back(*cookie2); |
2652 old_cookies.push_back(*cookie4); | 2631 old_cookies.push_back(*cookie4); |
2653 old_cookies.push_back(*cookie5); | 2632 old_cookies.push_back(*cookie5); |
2654 old_cookies.push_back(*cookie6); | 2633 old_cookies.push_back(*cookie6); |
2655 old_cookies.push_back(*cookie7); | 2634 old_cookies.push_back(*cookie7); |
2656 | 2635 |
2657 CookieList new_cookies; | 2636 CookieList new_cookies; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2854 | 2833 |
2855 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); | 2834 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); |
2856 | 2835 |
2857 // We have to manually build this cookie because it contains a control | 2836 // We have to manually build this cookie because it contains a control |
2858 // character, and our cookie line parser rejects control characters. | 2837 // character, and our cookie line parser rejects control characters. |
2859 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create( | 2838 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create( |
2860 url, "baz", | 2839 url, "baz", |
2861 "\x05" | 2840 "\x05" |
2862 "boo", | 2841 "boo", |
2863 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE, | 2842 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE, |
2864 false, COOKIE_PRIORITY_DEFAULT); | 2843 COOKIE_PRIORITY_DEFAULT); |
2865 initial_cookies.push_back(std::move(cc)); | 2844 initial_cookies.push_back(std::move(cc)); |
2866 | 2845 |
2867 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); | 2846 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); |
2868 | 2847 |
2869 // Inject our initial cookies into the mock PersistentCookieStore. | 2848 // Inject our initial cookies into the mock PersistentCookieStore. |
2870 store->SetLoadExpectation(true, std::move(initial_cookies)); | 2849 store->SetLoadExpectation(true, std::move(initial_cookies)); |
2871 | 2850 |
2872 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2851 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2873 | 2852 |
2874 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2853 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
(...skipping 18 matching lines...) Expand all Loading... |
2893 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2872 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
2894 | 2873 |
2895 // Set a non-secure cookie on a cryptographic scheme. | 2874 // Set a non-secure cookie on a cryptographic scheme. |
2896 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "C=D; path=/;")); | 2875 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "C=D; path=/;")); |
2897 histograms.ExpectTotalCount(cookie_source_histogram, 2); | 2876 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
2898 histograms.ExpectBucketCount( | 2877 histograms.ExpectBucketCount( |
2899 cookie_source_histogram, | 2878 cookie_source_histogram, |
2900 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2879 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
2901 | 2880 |
2902 // Set a secure cookie on a non-cryptographic scheme. | 2881 // Set a secure cookie on a non-cryptographic scheme. |
2903 EXPECT_TRUE( | 2882 EXPECT_FALSE( |
2904 SetCookie(cm.get(), http_www_google_.url(), "D=E; path=/; Secure")); | 2883 SetCookie(cm.get(), http_www_google_.url(), "D=E; path=/; Secure")); |
2905 histograms.ExpectTotalCount(cookie_source_histogram, 3); | 2884 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
2906 histograms.ExpectBucketCount( | 2885 histograms.ExpectBucketCount( |
2907 cookie_source_histogram, | 2886 cookie_source_histogram, |
2908 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2887 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 0); |
2909 | 2888 |
2910 // Overwrite a secure cookie (set by a cryptographic scheme) on a | 2889 // Overwrite a secure cookie (set by a cryptographic scheme) on a |
2911 // non-cryptographic scheme. | 2890 // non-cryptographic scheme. |
2912 EXPECT_TRUE( | 2891 EXPECT_FALSE( |
2913 SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/; Secure")); | 2892 SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/; Secure")); |
2914 histograms.ExpectTotalCount(cookie_source_histogram, 4); | 2893 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
2915 histograms.ExpectBucketCount( | 2894 histograms.ExpectBucketCount( |
2916 cookie_source_histogram, | 2895 cookie_source_histogram, |
2917 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2896 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
2918 histograms.ExpectBucketCount( | 2897 histograms.ExpectBucketCount( |
2919 cookie_source_histogram, | 2898 cookie_source_histogram, |
2920 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 2); | 2899 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 0); |
2921 | 2900 |
2922 // Test that clearing a secure cookie on a http:// URL does not get | 2901 // Test that attempting to clear a secure cookie on a http:// URL does |
2923 // counted. | 2902 // nothing. |
2924 EXPECT_TRUE( | 2903 EXPECT_TRUE( |
2925 SetCookie(cm.get(), https_www_google_.url(), "F=G; path=/; Secure")); | 2904 SetCookie(cm.get(), https_www_google_.url(), "F=G; path=/; Secure")); |
2926 histograms.ExpectTotalCount(cookie_source_histogram, 5); | 2905 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
2927 std::string cookies1 = GetCookies(cm.get(), https_www_google_.url()); | 2906 std::string cookies1 = GetCookies(cm.get(), https_www_google_.url()); |
2928 EXPECT_NE(std::string::npos, cookies1.find("F=G")); | 2907 EXPECT_NE(std::string::npos, cookies1.find("F=G")); |
2929 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 2908 EXPECT_FALSE(SetCookie(cm.get(), http_www_google_.url(), |
2930 "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT")); | 2909 "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT")); |
2931 std::string cookies2 = GetCookies(cm.get(), https_www_google_.url()); | 2910 std::string cookies2 = GetCookies(cm.get(), https_www_google_.url()); |
2932 EXPECT_EQ(std::string::npos, cookies2.find("F=G")); | 2911 EXPECT_NE(std::string::npos, cookies2.find("F=G")); |
2933 histograms.ExpectTotalCount(cookie_source_histogram, 5); | 2912 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
2934 | 2913 |
2935 // Set a non-secure cookie on a non-cryptographic scheme. | 2914 // Set a non-secure cookie on a non-cryptographic scheme. |
2936 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/")); | 2915 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/")); |
2937 histograms.ExpectTotalCount(cookie_source_histogram, 6); | 2916 histograms.ExpectTotalCount(cookie_source_histogram, 4); |
2938 histograms.ExpectBucketCount( | 2917 histograms.ExpectBucketCount( |
2939 cookie_source_histogram, | 2918 cookie_source_histogram, |
2940 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2919 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); |
2941 } | 2920 } |
2942 | 2921 |
2943 // Test that cookie delete equivalent histograms are recorded correctly when | 2922 // Test that cookie delete equivalent histograms are recorded correctly. |
2944 // strict secure cookies are not enabled. | |
2945 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { | 2923 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { |
2946 base::HistogramTester histograms; | 2924 base::HistogramTester histograms; |
2947 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 2925 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
2948 | 2926 |
2949 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2927 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2950 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2928 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2951 | 2929 |
2952 // Set a secure cookie from a secure origin | 2930 // Set a secure cookie from a secure origin |
2953 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 2931 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); |
2954 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2932 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
2955 histograms.ExpectBucketCount(cookie_source_histogram, | 2933 histograms.ExpectBucketCount(cookie_source_histogram, |
2956 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2934 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
2957 1); | 2935 1); |
2958 | 2936 |
2959 // Set a new cookie with a different name from a variety of origins (including | 2937 // Set a new cookie with a different name from a variety of origins (including |
2960 // the same one). | 2938 // the same one). |
2961 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "B=A;")); | 2939 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "B=A;")); |
2962 histograms.ExpectTotalCount(cookie_source_histogram, 2); | 2940 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
2963 histograms.ExpectBucketCount(cookie_source_histogram, | 2941 histograms.ExpectBucketCount(cookie_source_histogram, |
2964 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2942 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
2965 2); | 2943 2); |
2966 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=A;")); | 2944 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=A;")); |
2967 histograms.ExpectTotalCount(cookie_source_histogram, 3); | 2945 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
2968 histograms.ExpectBucketCount(cookie_source_histogram, | 2946 histograms.ExpectBucketCount(cookie_source_histogram, |
2969 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2947 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
2970 3); | 2948 3); |
2971 | 2949 |
2972 // Set a non-secure cookie from an insecure origin that matches the name of an | 2950 // Set a non-secure cookie from an insecure origin that matches the name of an |
2973 // already existing cookie and additionally is equivalent to the existing | 2951 // already existing cookie and additionally is equivalent to the existing |
2974 // cookie. | 2952 // cookie. This should fail since it's trying to overwrite a secure cookie. |
2975 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B;")); | 2953 EXPECT_FALSE(SetCookie(cm.get(), http_www_google_.url(), "A=B;")); |
2976 histograms.ExpectTotalCount(cookie_source_histogram, 5); | 2954 histograms.ExpectTotalCount(cookie_source_histogram, 6); |
2977 histograms.ExpectBucketCount(cookie_source_histogram, | 2955 histograms.ExpectBucketCount(cookie_source_histogram, |
2978 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2956 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
2979 4); | 2957 4); |
2980 histograms.ExpectBucketCount(cookie_source_histogram, | 2958 histograms.ExpectBucketCount(cookie_source_histogram, |
2981 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, | 2959 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, |
2982 1); | 2960 0); |
| 2961 histograms.ExpectBucketCount( |
| 2962 cookie_source_histogram, |
| 2963 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 1); |
| 2964 histograms.ExpectBucketCount( |
| 2965 cookie_source_histogram, |
| 2966 CookieMonster::COOKIE_DELETE_EQUIVALENT_WOULD_HAVE_DELETED, 1); |
2983 | 2967 |
2984 // Set a non-secure cookie from an insecure origin that matches the name of an | 2968 // Set a non-secure cookie from an insecure origin that matches the name of an |
2985 // already existing cookie but is not equivalent. | 2969 // already existing cookie but is not equivalent. This should fail since it's |
2986 EXPECT_TRUE( | 2970 // trying to shadow a secure cookie. |
| 2971 EXPECT_FALSE( |
2987 SetCookie(cm.get(), http_www_google_.url(), "A=C; path=/some/path")); | 2972 SetCookie(cm.get(), http_www_google_.url(), "A=C; path=/some/path")); |
2988 histograms.ExpectTotalCount(cookie_source_histogram, 6); | 2973 histograms.ExpectTotalCount(cookie_source_histogram, 8); |
2989 histograms.ExpectBucketCount(cookie_source_histogram, | 2974 histograms.ExpectBucketCount(cookie_source_histogram, |
2990 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2975 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
2991 5); | 2976 5); |
| 2977 histograms.ExpectBucketCount( |
| 2978 cookie_source_histogram, |
| 2979 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 2); |
2992 | 2980 |
2993 // Set a secure cookie from a secure origin that matches the name of an | 2981 // Set a secure cookie from a secure origin that matches the name of an |
2994 // already existing cookies and is equivalent. | 2982 // already existing cookies and is equivalent. |
2995 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=D; secure")); | 2983 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=D; secure")); |
2996 histograms.ExpectTotalCount(cookie_source_histogram, 8); | 2984 histograms.ExpectTotalCount(cookie_source_histogram, 10); |
2997 histograms.ExpectBucketCount(cookie_source_histogram, | 2985 histograms.ExpectBucketCount(cookie_source_histogram, |
2998 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2986 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
2999 6); | 2987 6); |
3000 histograms.ExpectBucketCount(cookie_source_histogram, | 2988 histograms.ExpectBucketCount(cookie_source_histogram, |
3001 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, | 2989 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, |
3002 2); | 2990 1); |
3003 | 2991 |
3004 // Set a secure cookie from a secure origin that matches the name of an | 2992 // Set a secure cookie from a secure origin that matches the name of an |
3005 // already existing cookie and is not equivalent. | 2993 // already existing cookie and is not equivalent. |
3006 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | 2994 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), |
3007 "A=E; secure; path=/some/other/path")); | 2995 "A=E; secure; path=/some/other/path")); |
3008 histograms.ExpectTotalCount(cookie_source_histogram, 9); | 2996 histograms.ExpectTotalCount(cookie_source_histogram, 11); |
3009 histograms.ExpectBucketCount(cookie_source_histogram, | 2997 histograms.ExpectBucketCount(cookie_source_histogram, |
3010 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2998 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
3011 7); | 2999 7); |
3012 } | 3000 } |
3013 | 3001 |
3014 TEST_F(CookieMonsterStrictSecureTest, SetSecureCookies) { | 3002 TEST_F(CookieMonsterTest, SetSecureCookies) { |
3015 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3003 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
3016 GURL http_url("http://www.google.com"); | 3004 GURL http_url("http://www.google.com"); |
3017 GURL http_superdomain_url("http://google.com"); | 3005 GURL http_superdomain_url("http://google.com"); |
3018 GURL https_url("https://www.google.com"); | 3006 GURL https_url("https://www.google.com"); |
3019 | 3007 |
3020 // A non-secure cookie can be created from either a URL with a secure or | 3008 // A non-secure cookie can be created from either a URL with a secure or |
3021 // insecure scheme. | 3009 // insecure scheme. |
3022 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); | 3010 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); |
3023 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); | 3011 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); |
3024 | 3012 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3070 // so the insecure examples aren't trying to overwrite the one above. | 3058 // so the insecure examples aren't trying to overwrite the one above. |
3071 EXPECT_TRUE(SetCookie(cm.get(), https_url, "B=C; Secure; domain=google.com")); | 3059 EXPECT_TRUE(SetCookie(cm.get(), https_url, "B=C; Secure; domain=google.com")); |
3072 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D; domain=google.com")); | 3060 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D; domain=google.com")); |
3073 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D")); | 3061 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D")); |
3074 EXPECT_FALSE(SetCookie(cm.get(), http_superdomain_url, "B=D")); | 3062 EXPECT_FALSE(SetCookie(cm.get(), http_superdomain_url, "B=D")); |
3075 | 3063 |
3076 // Verify that if an httponly version of the cookie exists, adding a Secure | 3064 // Verify that if an httponly version of the cookie exists, adding a Secure |
3077 // version of the cookie still does not overwrite it. | 3065 // version of the cookie still does not overwrite it. |
3078 CookieOptions include_httponly; | 3066 CookieOptions include_httponly; |
3079 include_httponly.set_include_httponly(); | 3067 include_httponly.set_include_httponly(); |
3080 include_httponly.set_enforce_strict_secure(); | |
3081 EXPECT_TRUE(SetCookieWithOptions(cm.get(), https_url, "C=D; httponly", | 3068 EXPECT_TRUE(SetCookieWithOptions(cm.get(), https_url, "C=D; httponly", |
3082 include_httponly)); | 3069 include_httponly)); |
3083 // Note that the lack of an explicit options object below uses the default, | 3070 // Note that the lack of an explicit options object below uses the default, |
3084 // which in this case includes "exclude_httponly = true". | 3071 // which in this case includes "exclude_httponly = true". |
3085 EXPECT_FALSE(SetCookie(cm.get(), https_url, "C=E; Secure")); | 3072 EXPECT_FALSE(SetCookie(cm.get(), https_url, "C=E; Secure")); |
3086 } | 3073 } |
3087 | 3074 |
3088 // Tests for behavior if strict secure cookies is enabled. | 3075 // Tests for behavior for strict secure cookies. |
3089 TEST_F(CookieMonsterStrictSecureTest, EvictSecureCookies) { | 3076 TEST_F(CookieMonsterTest, EvictSecureCookies) { |
3090 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 3077 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
3091 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 3078 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
3092 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 3079 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
3093 CookieMonster::kDomainPurgeCookies); | 3080 CookieMonster::kDomainPurgeCookies); |
3094 DCHECK_EQ(3300U, CookieMonster::kMaxCookies); | 3081 DCHECK_EQ(3300U, CookieMonster::kMaxCookies); |
3095 DCHECK_EQ(30, CookieMonster::kSafeFromGlobalPurgeDays); | 3082 DCHECK_EQ(30, CookieMonster::kSafeFromGlobalPurgeDays); |
3096 | 3083 |
3097 // If secure cookies for one domain hit the per domain limit (180), a | 3084 // If secure cookies for one domain hit the per domain limit (180), a |
3098 // non-secure cookie will not evict them (and, in fact, the non-secure cookie | 3085 // non-secure cookie will not evict them (and, in fact, the non-secure cookie |
3099 // will be removed right after creation). | 3086 // will be removed right after creation). |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3208 // cookies are removed so that the global total number of cookies is at the | 3195 // cookies are removed so that the global total number of cookies is at the |
3209 // global purge goal (3000), but the secure cookies are not evicted. | 3196 // global purge goal (3000), but the secure cookies are not evicted. |
3210 const CookiesEntry test14[] = {{1U, true}}; | 3197 const CookiesEntry test14[] = {{1U, true}}; |
3211 const AltHosts test14_alt_hosts(1500, 1800); | 3198 const AltHosts test14_alt_hosts(1500, 1800); |
3212 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, | 3199 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, |
3213 &test14_alt_hosts); | 3200 &test14_alt_hosts); |
3214 } | 3201 } |
3215 | 3202 |
3216 // Tests that strict secure cookies doesn't trip equivalent cookie checks | 3203 // Tests that strict secure cookies doesn't trip equivalent cookie checks |
3217 // accidentally. Regression test for https://crbug.com/569943. | 3204 // accidentally. Regression test for https://crbug.com/569943. |
3218 TEST_F(CookieMonsterStrictSecureTest, EquivalentCookies) { | 3205 TEST_F(CookieMonsterTest, EquivalentCookies) { |
3219 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3206 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
3220 GURL http_url("http://www.google.com"); | 3207 GURL http_url("http://www.google.com"); |
3221 GURL http_superdomain_url("http://google.com"); | 3208 GURL http_superdomain_url("http://google.com"); |
3222 GURL https_url("https://www.google.com"); | 3209 GURL https_url("https://www.google.com"); |
3223 | 3210 |
3224 // Tests that non-equivalent cookies because of the path attribute can be set | 3211 // Tests that non-equivalent cookies because of the path attribute can be set |
3225 // successfully. | 3212 // successfully. |
3226 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3213 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
3227 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); | 3214 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); |
3228 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); | 3215 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); |
3229 | 3216 |
3230 // Tests that non-equivalent cookies because of the domain attribute can be | 3217 // Tests that non-equivalent cookies because of the domain attribute can be |
3231 // set successfully. | 3218 // set successfully. |
3232 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3219 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
3233 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); | 3220 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); |
3234 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); | 3221 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); |
3235 } | 3222 } |
3236 | 3223 |
3237 // Test that cookie delete equivalent histograms are recorded correctly for | |
3238 // strict secure cookies. | |
3239 TEST_F(CookieMonsterStrictSecureTest, CookieDeleteEquivalentHistogramTest) { | |
3240 base::HistogramTester histograms; | |
3241 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | |
3242 | |
3243 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | |
3244 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | |
3245 | |
3246 // Set a secure cookie from a secure origin | |
3247 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | |
3248 histograms.ExpectTotalCount(cookie_source_histogram, 1); | |
3249 histograms.ExpectBucketCount(cookie_source_histogram, | |
3250 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
3251 1); | |
3252 | |
3253 // Set a new cookie with a different name from a variety of origins (including | |
3254 // the same one). | |
3255 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "B=A;")); | |
3256 histograms.ExpectTotalCount(cookie_source_histogram, 2); | |
3257 histograms.ExpectBucketCount(cookie_source_histogram, | |
3258 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
3259 2); | |
3260 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=A;")); | |
3261 histograms.ExpectTotalCount(cookie_source_histogram, 3); | |
3262 histograms.ExpectBucketCount(cookie_source_histogram, | |
3263 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
3264 3); | |
3265 | |
3266 // Set a non-secure cookie from an insecure origin that matches the name of an | |
3267 // already existing cookie and additionally is equivalent to the existing | |
3268 // cookie. | |
3269 EXPECT_FALSE(SetCookie(cm.get(), http_www_google_.url(), "A=B;")); | |
3270 histograms.ExpectTotalCount(cookie_source_histogram, 6); | |
3271 histograms.ExpectBucketCount(cookie_source_histogram, | |
3272 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
3273 4); | |
3274 histograms.ExpectBucketCount( | |
3275 cookie_source_histogram, | |
3276 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 1); | |
3277 histograms.ExpectBucketCount( | |
3278 cookie_source_histogram, | |
3279 CookieMonster::COOKIE_DELETE_EQUIVALENT_WOULD_HAVE_DELETED, 1); | |
3280 | |
3281 // Set a non-secure cookie from an insecure origin that matches the name of an | |
3282 // already existing cookie but is not equivalent. | |
3283 EXPECT_FALSE( | |
3284 SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/some/path")); | |
3285 histograms.ExpectTotalCount(cookie_source_histogram, 8); | |
3286 histograms.ExpectBucketCount(cookie_source_histogram, | |
3287 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
3288 5); | |
3289 histograms.ExpectBucketCount( | |
3290 cookie_source_histogram, | |
3291 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 2); | |
3292 | |
3293 // Set a secure cookie from a secure origin that matches the name of an | |
3294 // already existing cookies and is equivalent. | |
3295 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; secure")); | |
3296 histograms.ExpectTotalCount(cookie_source_histogram, 10); | |
3297 histograms.ExpectBucketCount(cookie_source_histogram, | |
3298 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
3299 6); | |
3300 histograms.ExpectBucketCount(cookie_source_histogram, | |
3301 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, | |
3302 1); | |
3303 | |
3304 // Set a secure cookie from a secure origin that matches the name of an | |
3305 // already existing cookie and is not equivalent. | |
3306 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | |
3307 "A=C; secure; path=/some/path")); | |
3308 histograms.ExpectTotalCount(cookie_source_histogram, 11); | |
3309 histograms.ExpectBucketCount(cookie_source_histogram, | |
3310 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
3311 7); | |
3312 } | |
3313 | |
3314 class CookieMonsterNotificationTest : public CookieMonsterTest { | 3224 class CookieMonsterNotificationTest : public CookieMonsterTest { |
3315 public: | 3225 public: |
3316 CookieMonsterNotificationTest() | 3226 CookieMonsterNotificationTest() |
3317 : test_url_("http://www.google.com/foo"), | 3227 : test_url_("http://www.google.com/foo"), |
3318 store_(new MockPersistentCookieStore), | 3228 store_(new MockPersistentCookieStore), |
3319 monster_(new CookieMonster(store_.get(), nullptr)) {} | 3229 monster_(new CookieMonster(store_.get(), nullptr)) {} |
3320 | 3230 |
3321 ~CookieMonsterNotificationTest() override {} | 3231 ~CookieMonsterNotificationTest() override {} |
3322 | 3232 |
3323 CookieMonster* monster() { return monster_.get(); } | 3233 CookieMonster* monster() { return monster_.get(); } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3461 monster()->AddCallbackForCookie( | 3371 monster()->AddCallbackForCookie( |
3462 test_url_, "abc", | 3372 test_url_, "abc", |
3463 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3373 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3464 SetCookie(monster(), test_url_, "abc=def"); | 3374 SetCookie(monster(), test_url_, "abc=def"); |
3465 base::RunLoop().RunUntilIdle(); | 3375 base::RunLoop().RunUntilIdle(); |
3466 EXPECT_EQ(1U, cookies0.size()); | 3376 EXPECT_EQ(1U, cookies0.size()); |
3467 EXPECT_EQ(1U, cookies0.size()); | 3377 EXPECT_EQ(1U, cookies0.size()); |
3468 } | 3378 } |
3469 | 3379 |
3470 } // namespace net | 3380 } // namespace net |
OLD | NEW |