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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 return new CookieMonster(NULL, NULL); | 94 return new CookieMonster(NULL, NULL); |
95 } | 95 } |
96 | 96 |
97 static const bool is_cookie_monster = true; | 97 static const bool is_cookie_monster = true; |
98 static const bool supports_http_only = true; | 98 static const bool supports_http_only = true; |
99 static const bool supports_non_dotted_domains = true; | 99 static const bool supports_non_dotted_domains = true; |
100 static const bool preserves_trailing_dots = true; | 100 static const bool preserves_trailing_dots = true; |
101 static const bool filters_schemes = true; | 101 static const bool filters_schemes = true; |
102 static const bool has_path_prefix_bug = false; | 102 static const bool has_path_prefix_bug = false; |
103 static const int creation_time_granularity_in_ms = 0; | 103 static const int creation_time_granularity_in_ms = 0; |
| 104 static const bool enforces_prefixes = true; |
104 }; | 105 }; |
105 | 106 |
106 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 107 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
107 CookieStoreTest, | 108 CookieStoreTest, |
108 CookieMonsterTestTraits); | 109 CookieMonsterTestTraits); |
109 | 110 |
110 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 111 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
111 MultiThreadedCookieStoreTest, | 112 MultiThreadedCookieStoreTest, |
112 CookieMonsterTestTraits); | 113 CookieMonsterTestTraits); |
113 | 114 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 const std::string& path, | 155 const std::string& path, |
155 const base::Time& expiration_time, | 156 const base::Time& expiration_time, |
156 bool secure, | 157 bool secure, |
157 bool http_only, | 158 bool http_only, |
158 bool first_party_only, | 159 bool first_party_only, |
159 CookiePriority priority) { | 160 CookiePriority priority) { |
160 DCHECK(cm); | 161 DCHECK(cm); |
161 ResultSavingCookieCallback<bool> callback; | 162 ResultSavingCookieCallback<bool> callback; |
162 cm->SetCookieWithDetailsAsync( | 163 cm->SetCookieWithDetailsAsync( |
163 url, name, value, domain, path, expiration_time, secure, http_only, | 164 url, name, value, domain, path, expiration_time, secure, http_only, |
164 first_party_only, priority, | 165 first_party_only, false /* enforce prefixes */, priority, |
165 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 166 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
166 base::Unretained(&callback))); | 167 base::Unretained(&callback))); |
167 RunFor(kTimeout); | 168 RunFor(kTimeout); |
168 EXPECT_TRUE(callback.did_run()); | 169 EXPECT_TRUE(callback.did_run()); |
169 return callback.result(); | 170 return callback.result(); |
170 } | 171 } |
171 | 172 |
172 bool SetAllCookies(CookieMonster* cm, const CookieList& list) { | 173 bool SetAllCookies(CookieMonster* cm, const CookieList& list) { |
173 DCHECK(cm); | 174 DCHECK(cm); |
174 ResultSavingCookieCallback<bool> callback; | 175 ResultSavingCookieCallback<bool> callback; |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 cookie_monster, | 661 cookie_monster, |
661 delete_begin, | 662 delete_begin, |
662 delete_end, | 663 delete_end, |
663 callback) { | 664 callback) { |
664 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, | 665 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, |
665 callback->AsCallback()); | 666 callback->AsCallback()); |
666 } | 667 } |
667 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { | 668 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { |
668 cookie_monster->SetCookieWithDetailsAsync( | 669 cookie_monster->SetCookieWithDetailsAsync( |
669 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, | 670 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, |
670 cc.secure, cc.http_only, cc.first_party_only, cc.priority, | 671 cc.secure, cc.http_only, cc.first_party_only, |
671 callback->AsCallback()); | 672 false /* enforce prefixes */, cc.priority, callback->AsCallback()); |
672 } | 673 } |
673 | 674 |
674 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { | 675 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { |
675 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); | 676 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); |
676 } | 677 } |
677 | 678 |
678 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { | 679 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { |
679 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); | 680 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); |
680 } | 681 } |
681 | 682 |
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 std::string value = "B"; | 2420 std::string value = "B"; |
2420 std::string domain = std::string(); | 2421 std::string domain = std::string(); |
2421 std::string path = "/foo"; | 2422 std::string path = "/foo"; |
2422 base::Time expiration_time = base::Time(); | 2423 base::Time expiration_time = base::Time(); |
2423 bool secure = false; | 2424 bool secure = false; |
2424 bool http_only = false; | 2425 bool http_only = false; |
2425 bool first_party_only = false; | 2426 bool first_party_only = false; |
2426 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; | 2427 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; |
2427 cm->SetCookieWithDetailsAsync( | 2428 cm->SetCookieWithDetailsAsync( |
2428 url, name, value, domain, path, expiration_time, secure, http_only, | 2429 url, name, value, domain, path, expiration_time, secure, http_only, |
2429 first_party_only, priority, | 2430 first_party_only, false /* enforce prefixes */, priority, |
2430 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 2431 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
2431 base::Unretained(callback))); | 2432 base::Unretained(callback))); |
2432 } | 2433 } |
2433 | 2434 |
2434 void DeleteAllCreatedBetweenTask(CookieMonster* cm, | 2435 void DeleteAllCreatedBetweenTask(CookieMonster* cm, |
2435 const base::Time& delete_begin, | 2436 const base::Time& delete_begin, |
2436 const base::Time& delete_end, | 2437 const base::Time& delete_end, |
2437 ResultSavingCookieCallback<int>* callback) { | 2438 ResultSavingCookieCallback<int>* callback) { |
2438 cm->DeleteAllCreatedBetweenAsync( | 2439 cm->DeleteAllCreatedBetweenAsync( |
2439 delete_begin, delete_end, | 2440 delete_begin, delete_end, |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2894 histograms.ExpectTotalCount(cookie_source_histogram, 5); | 2895 histograms.ExpectTotalCount(cookie_source_histogram, 5); |
2895 | 2896 |
2896 // Set a non-Secure cookie on a non-cryptographic scheme. | 2897 // Set a non-Secure cookie on a non-cryptographic scheme. |
2897 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "H=I; path=/")); | 2898 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "H=I; path=/")); |
2898 histograms.ExpectTotalCount(cookie_source_histogram, 6); | 2899 histograms.ExpectTotalCount(cookie_source_histogram, 6); |
2899 histograms.ExpectBucketCount( | 2900 histograms.ExpectBucketCount( |
2900 cookie_source_histogram, | 2901 cookie_source_histogram, |
2901 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2902 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); |
2902 } | 2903 } |
2903 | 2904 |
| 2905 TEST_F(CookieMonsterTest, SecureCookiePrefix) { |
| 2906 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2907 // A $Secure- cookie must be Secure. |
| 2908 EXPECT_FALSE(SetCookie(cm.get(), url_google_, "$Secure-A=B")); |
| 2909 EXPECT_FALSE(SetCookie(cm.get(), url_google_, "$Secure-A=B; httponly")); |
| 2910 |
| 2911 // A typoed prefix does not have to be Secure. |
| 2912 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "$secure-A=B; Secure")); |
| 2913 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "$secure-A=C;")); |
| 2914 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "$SecureA=B; Secure")); |
| 2915 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "$SecureA=C;")); |
| 2916 |
| 2917 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "$Secure-A=B; Secure")); |
| 2918 // A $Secure- cookie can't be overwritten with a non-Secure cookie |
| 2919 // either. |
| 2920 EXPECT_FALSE(SetCookie(cm.get(), url_google_, "$Secure-A=C;")); |
| 2921 } |
| 2922 |
2904 class CookieMonsterNotificationTest : public CookieMonsterTest { | 2923 class CookieMonsterNotificationTest : public CookieMonsterTest { |
2905 public: | 2924 public: |
2906 CookieMonsterNotificationTest() | 2925 CookieMonsterNotificationTest() |
2907 : test_url_("http://www.google.com/foo"), | 2926 : test_url_("http://www.google.com/foo"), |
2908 store_(new MockPersistentCookieStore), | 2927 store_(new MockPersistentCookieStore), |
2909 monster_(new CookieMonster(store_.get(), NULL)) {} | 2928 monster_(new CookieMonster(store_.get(), NULL)) {} |
2910 | 2929 |
2911 ~CookieMonsterNotificationTest() override {} | 2930 ~CookieMonsterNotificationTest() override {} |
2912 | 2931 |
2913 CookieMonster* monster() { return monster_.get(); } | 2932 CookieMonster* monster() { return monster_.get(); } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3051 monster()->AddCallbackForCookie( | 3070 monster()->AddCallbackForCookie( |
3052 test_url_, "abc", | 3071 test_url_, "abc", |
3053 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3072 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3054 SetCookie(monster(), test_url_, "abc=def"); | 3073 SetCookie(monster(), test_url_, "abc=def"); |
3055 base::MessageLoop::current()->RunUntilIdle(); | 3074 base::MessageLoop::current()->RunUntilIdle(); |
3056 EXPECT_EQ(1U, cookies0.size()); | 3075 EXPECT_EQ(1U, cookies0.size()); |
3057 EXPECT_EQ(1U, cookies0.size()); | 3076 EXPECT_EQ(1U, cookies0.size()); |
3058 } | 3077 } |
3059 | 3078 |
3060 } // namespace net | 3079 } // namespace net |
OLD | NEW |