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