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_store_unittest.h" | 5 #include "net/cookies/cookie_store_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 return new CookieMonster(NULL, NULL); | 93 return new CookieMonster(NULL, NULL); |
94 } | 94 } |
95 | 95 |
96 static const bool is_cookie_monster = true; | 96 static const bool is_cookie_monster = true; |
97 static const bool supports_http_only = true; | 97 static const bool supports_http_only = true; |
98 static const bool supports_non_dotted_domains = true; | 98 static const bool supports_non_dotted_domains = true; |
99 static const bool preserves_trailing_dots = true; | 99 static const bool preserves_trailing_dots = true; |
100 static const bool filters_schemes = true; | 100 static const bool filters_schemes = true; |
101 static const bool has_path_prefix_bug = false; | 101 static const bool has_path_prefix_bug = false; |
102 static const int creation_time_granularity_in_ms = 0; | 102 static const int creation_time_granularity_in_ms = 0; |
| 103 static const bool enforces_prefixes = true; |
103 }; | 104 }; |
104 | 105 |
105 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 106 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
106 CookieStoreTest, | 107 CookieStoreTest, |
107 CookieMonsterTestTraits); | 108 CookieMonsterTestTraits); |
108 | 109 |
109 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 110 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
110 MultiThreadedCookieStoreTest, | 111 MultiThreadedCookieStoreTest, |
111 CookieMonsterTestTraits); | 112 CookieMonsterTestTraits); |
112 | 113 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 const std::string& path, | 154 const std::string& path, |
154 const base::Time& expiration_time, | 155 const base::Time& expiration_time, |
155 bool secure, | 156 bool secure, |
156 bool http_only, | 157 bool http_only, |
157 bool first_party_only, | 158 bool first_party_only, |
158 CookiePriority priority) { | 159 CookiePriority priority) { |
159 DCHECK(cm); | 160 DCHECK(cm); |
160 ResultSavingCookieCallback<bool> callback; | 161 ResultSavingCookieCallback<bool> callback; |
161 cm->SetCookieWithDetailsAsync( | 162 cm->SetCookieWithDetailsAsync( |
162 url, name, value, domain, path, expiration_time, secure, http_only, | 163 url, name, value, domain, path, expiration_time, secure, http_only, |
163 first_party_only, priority, | 164 first_party_only, false /* enforce prefixes */, priority, |
164 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 165 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
165 base::Unretained(&callback))); | 166 base::Unretained(&callback))); |
166 RunFor(kTimeout); | 167 RunFor(kTimeout); |
167 EXPECT_TRUE(callback.did_run()); | 168 EXPECT_TRUE(callback.did_run()); |
168 return callback.result(); | 169 return callback.result(); |
169 } | 170 } |
170 | 171 |
171 bool SetAllCookies(CookieMonster* cm, const CookieList& list) { | 172 bool SetAllCookies(CookieMonster* cm, const CookieList& list) { |
172 DCHECK(cm); | 173 DCHECK(cm); |
173 ResultSavingCookieCallback<bool> callback; | 174 ResultSavingCookieCallback<bool> callback; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 cookie_monster, | 664 cookie_monster, |
664 delete_begin, | 665 delete_begin, |
665 delete_end, | 666 delete_end, |
666 callback) { | 667 callback) { |
667 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, | 668 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, |
668 callback->AsCallback()); | 669 callback->AsCallback()); |
669 } | 670 } |
670 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { | 671 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { |
671 cookie_monster->SetCookieWithDetailsAsync( | 672 cookie_monster->SetCookieWithDetailsAsync( |
672 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, | 673 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, |
673 cc.secure, cc.http_only, cc.first_party_only, cc.priority, | 674 cc.secure, cc.http_only, cc.first_party_only, |
674 callback->AsCallback()); | 675 false /* enforce prefixes */, cc.priority, callback->AsCallback()); |
675 } | 676 } |
676 | 677 |
677 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { | 678 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { |
678 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); | 679 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); |
679 } | 680 } |
680 | 681 |
681 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { | 682 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { |
682 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); | 683 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); |
683 } | 684 } |
684 | 685 |
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2468 std::string value = "B"; | 2469 std::string value = "B"; |
2469 std::string domain = std::string(); | 2470 std::string domain = std::string(); |
2470 std::string path = "/foo"; | 2471 std::string path = "/foo"; |
2471 base::Time expiration_time = base::Time(); | 2472 base::Time expiration_time = base::Time(); |
2472 bool secure = false; | 2473 bool secure = false; |
2473 bool http_only = false; | 2474 bool http_only = false; |
2474 bool first_party_only = false; | 2475 bool first_party_only = false; |
2475 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; | 2476 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; |
2476 cm->SetCookieWithDetailsAsync( | 2477 cm->SetCookieWithDetailsAsync( |
2477 url, name, value, domain, path, expiration_time, secure, http_only, | 2478 url, name, value, domain, path, expiration_time, secure, http_only, |
2478 first_party_only, priority, | 2479 first_party_only, false /* enforce prefixes */, priority, |
2479 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 2480 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
2480 base::Unretained(callback))); | 2481 base::Unretained(callback))); |
2481 } | 2482 } |
2482 | 2483 |
2483 void DeleteAllCreatedBetweenTask(CookieMonster* cm, | 2484 void DeleteAllCreatedBetweenTask(CookieMonster* cm, |
2484 const base::Time& delete_begin, | 2485 const base::Time& delete_begin, |
2485 const base::Time& delete_end, | 2486 const base::Time& delete_end, |
2486 ResultSavingCookieCallback<int>* callback) { | 2487 ResultSavingCookieCallback<int>* callback) { |
2487 cm->DeleteAllCreatedBetweenAsync( | 2488 cm->DeleteAllCreatedBetweenAsync( |
2488 delete_begin, delete_end, | 2489 delete_begin, delete_end, |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2959 histograms.ExpectTotalCount(cookie_source_histogram, 5); | 2960 histograms.ExpectTotalCount(cookie_source_histogram, 5); |
2960 | 2961 |
2961 // Set a non-Secure cookie on a non-cryptographic scheme. | 2962 // Set a non-Secure cookie on a non-cryptographic scheme. |
2962 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/")); | 2963 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/")); |
2963 histograms.ExpectTotalCount(cookie_source_histogram, 6); | 2964 histograms.ExpectTotalCount(cookie_source_histogram, 6); |
2964 histograms.ExpectBucketCount( | 2965 histograms.ExpectBucketCount( |
2965 cookie_source_histogram, | 2966 cookie_source_histogram, |
2966 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2967 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); |
2967 } | 2968 } |
2968 | 2969 |
| 2970 TEST_F(CookieMonsterTest, SecureCookiePrefix) { |
| 2971 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2972 // A $Secure- cookie must be Secure. |
| 2973 EXPECT_FALSE(SetCookie(cm.get(), https_www_google_.url(), "$Secure-A=B")); |
| 2974 EXPECT_FALSE( |
| 2975 SetCookie(cm.get(), https_www_google_.url(), "$Secure-A=B; httponly")); |
| 2976 |
| 2977 // A typoed prefix does not have to be Secure. |
| 2978 EXPECT_TRUE( |
| 2979 SetCookie(cm.get(), https_www_google_.url(), "$secure-A=B; Secure")); |
| 2980 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "$secure-A=C;")); |
| 2981 EXPECT_TRUE( |
| 2982 SetCookie(cm.get(), https_www_google_.url(), "$SecureA=B; Secure")); |
| 2983 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "$SecureA=C;")); |
| 2984 |
| 2985 EXPECT_TRUE( |
| 2986 SetCookie(cm.get(), https_www_google_.url(), "$Secure-A=B; Secure")); |
| 2987 |
| 2988 // A $Secure- cookie can't be set on a non-secure origin. |
| 2989 EXPECT_FALSE( |
| 2990 SetCookie(cm.get(), http_www_google_.url(), "$Secure-A=B; Secure")); |
| 2991 } |
| 2992 |
2969 class CookieMonsterNotificationTest : public CookieMonsterTest { | 2993 class CookieMonsterNotificationTest : public CookieMonsterTest { |
2970 public: | 2994 public: |
2971 CookieMonsterNotificationTest() | 2995 CookieMonsterNotificationTest() |
2972 : test_url_("http://www.google.com/foo"), | 2996 : test_url_("http://www.google.com/foo"), |
2973 store_(new MockPersistentCookieStore), | 2997 store_(new MockPersistentCookieStore), |
2974 monster_(new CookieMonster(store_.get(), NULL)) {} | 2998 monster_(new CookieMonster(store_.get(), NULL)) {} |
2975 | 2999 |
2976 ~CookieMonsterNotificationTest() override {} | 3000 ~CookieMonsterNotificationTest() override {} |
2977 | 3001 |
2978 CookieMonster* monster() { return monster_.get(); } | 3002 CookieMonster* monster() { return monster_.get(); } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3116 monster()->AddCallbackForCookie( | 3140 monster()->AddCallbackForCookie( |
3117 test_url_, "abc", | 3141 test_url_, "abc", |
3118 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3142 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3119 SetCookie(monster(), test_url_, "abc=def"); | 3143 SetCookie(monster(), test_url_, "abc=def"); |
3120 base::MessageLoop::current()->RunUntilIdle(); | 3144 base::MessageLoop::current()->RunUntilIdle(); |
3121 EXPECT_EQ(1U, cookies0.size()); | 3145 EXPECT_EQ(1U, cookies0.size()); |
3122 EXPECT_EQ(1U, cookies0.size()); | 3146 EXPECT_EQ(1U, cookies0.size()); |
3123 } | 3147 } |
3124 | 3148 |
3125 } // namespace net | 3149 } // namespace net |
OLD | NEW |