| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 virtual ~NewMockPersistentCookieStore() {} | 64 virtual ~NewMockPersistentCookieStore() {} |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu"; | 67 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu"; |
| 68 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu"; | 68 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu"; |
| 69 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu"; | 69 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu"; |
| 70 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu"; | 70 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu"; |
| 71 const char kOtherDomain[] = "http://www.mit.edu"; | 71 const char kOtherDomain[] = "http://www.mit.edu"; |
| 72 | 72 |
| 73 struct CookieMonsterTestTraits { | 73 struct CookieMonsterTestTraits { |
| 74 static scoped_refptr<CookieStore> Create() { | 74 static scoped_ptr<CookieStore> Create() { |
| 75 return new CookieMonster(NULL, NULL); | 75 return make_scoped_ptr(new CookieMonster(nullptr, nullptr)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 static const bool supports_http_only = true; | 78 static const bool supports_http_only = true; |
| 79 static const bool supports_non_dotted_domains = true; | 79 static const bool supports_non_dotted_domains = true; |
| 80 static const bool preserves_trailing_dots = true; | 80 static const bool preserves_trailing_dots = true; |
| 81 static const bool filters_schemes = true; | 81 static const bool filters_schemes = true; |
| 82 static const bool has_path_prefix_bug = false; | 82 static const bool has_path_prefix_bug = false; |
| 83 static const int creation_time_granularity_in_ms = 0; | 83 static const int creation_time_granularity_in_ms = 0; |
| 84 static const bool enforce_strict_secure = false; | 84 static const bool enforce_strict_secure = false; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 struct CookieMonsterEnforcingStrictSecure { | 87 struct CookieMonsterEnforcingStrictSecure { |
| 88 static scoped_refptr<CookieStore> Create() { | 88 static scoped_ptr<CookieStore> Create() { |
| 89 return new CookieMonster(NULL, NULL); | 89 return make_scoped_ptr(new CookieMonster(nullptr, nullptr)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 static const bool supports_http_only = true; | 92 static const bool supports_http_only = true; |
| 93 static const bool supports_non_dotted_domains = true; | 93 static const bool supports_non_dotted_domains = true; |
| 94 static const bool preserves_trailing_dots = true; | 94 static const bool preserves_trailing_dots = true; |
| 95 static const bool filters_schemes = true; | 95 static const bool filters_schemes = true; |
| 96 static const bool has_path_prefix_bug = false; | 96 static const bool has_path_prefix_bug = false; |
| 97 static const int creation_time_granularity_in_ms = 0; | 97 static const int creation_time_granularity_in_ms = 0; |
| 98 static const bool enforce_strict_secure = true; | 98 static const bool enforce_strict_secure = true; |
| 99 }; | 99 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 cm->DeleteAllCreatedBetweenForHostAsync( | 159 cm->DeleteAllCreatedBetweenForHostAsync( |
| 160 delete_begin, delete_end, url, | 160 delete_begin, delete_end, url, |
| 161 base::Bind(&ResultSavingCookieCallback<int>::Run, | 161 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 162 base::Unretained(&callback))); | 162 base::Unretained(&callback))); |
| 163 callback.WaitUntilDone(); | 163 callback.WaitUntilDone(); |
| 164 return callback.result(); | 164 return callback.result(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Helper for DeleteAllForHost test; repopulates CM with same layout | 167 // Helper for DeleteAllForHost test; repopulates CM with same layout |
| 168 // each time. | 168 // each time. |
| 169 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { | 169 void PopulateCmForDeleteAllForHost(CookieMonster* cm) { |
| 170 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); | 170 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); |
| 171 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); | 171 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); |
| 172 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); | 172 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); |
| 173 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); | 173 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); |
| 174 GURL url_other(kOtherDomain); | 174 GURL url_other(kOtherDomain); |
| 175 | 175 |
| 176 this->DeleteAll(cm.get()); | 176 this->DeleteAll(cm); |
| 177 | 177 |
| 178 // Static population for probe: | 178 // Static population for probe: |
| 179 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) | 179 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) |
| 180 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) | 180 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) |
| 181 // * http_only cookie (w.c.b.a) | 181 // * http_only cookie (w.c.b.a) |
| 182 // * same_site cookie (w.c.b.a) | 182 // * same_site cookie (w.c.b.a) |
| 183 // * Two secure cookies (.c.b.a, w.c.b.a) | 183 // * Two secure cookies (.c.b.a, w.c.b.a) |
| 184 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) | 184 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) |
| 185 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) | 185 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) |
| 186 | 186 |
| 187 // Domain cookies | 187 // Domain cookies |
| 188 EXPECT_TRUE(this->SetCookieWithDetails( | 188 EXPECT_TRUE(this->SetCookieWithDetails( |
| 189 cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", | 189 cm, url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", "/", |
| 190 "/", base::Time(), base::Time(), base::Time(), false, false, false, | 190 base::Time(), base::Time(), base::Time(), false, false, false, |
| 191 COOKIE_PRIORITY_DEFAULT)); | 191 COOKIE_PRIORITY_DEFAULT)); |
| 192 EXPECT_TRUE(this->SetCookieWithDetails( | 192 EXPECT_TRUE(this->SetCookieWithDetails( |
| 193 cm.get(), url_top_level_domain_plus_2, "dom_2", "X", | 193 cm, url_top_level_domain_plus_2, "dom_2", "X", ".math.harvard.edu", "/", |
| 194 ".math.harvard.edu", "/", base::Time(), base::Time(), base::Time(), | 194 base::Time(), base::Time(), base::Time(), false, false, false, |
| 195 false, false, false, COOKIE_PRIORITY_DEFAULT)); | 195 COOKIE_PRIORITY_DEFAULT)); |
| 196 EXPECT_TRUE(this->SetCookieWithDetails( | 196 EXPECT_TRUE(this->SetCookieWithDetails( |
| 197 cm.get(), url_top_level_domain_plus_3, "dom_3", "X", | 197 cm, url_top_level_domain_plus_3, "dom_3", "X", |
| 198 ".bourbaki.math.harvard.edu", "/", base::Time(), base::Time(), | 198 ".bourbaki.math.harvard.edu", "/", base::Time(), base::Time(), |
| 199 base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); | 199 base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); |
| 200 | 200 |
| 201 // Host cookies | 201 // Host cookies |
| 202 EXPECT_TRUE(this->SetCookieWithDetails( | 202 EXPECT_TRUE(this->SetCookieWithDetails( |
| 203 cm.get(), url_top_level_domain_plus_1, "host_1", "X", std::string(), | 203 cm, url_top_level_domain_plus_1, "host_1", "X", std::string(), "/", |
| 204 "/", base::Time(), base::Time(), base::Time(), false, false, false, | 204 base::Time(), base::Time(), base::Time(), false, false, false, |
| 205 COOKIE_PRIORITY_DEFAULT)); | 205 COOKIE_PRIORITY_DEFAULT)); |
| 206 EXPECT_TRUE(this->SetCookieWithDetails( | 206 EXPECT_TRUE(this->SetCookieWithDetails( |
| 207 cm.get(), url_top_level_domain_plus_2, "host_2", "X", std::string(), | 207 cm, url_top_level_domain_plus_2, "host_2", "X", std::string(), "/", |
| 208 "/", base::Time(), base::Time(), base::Time(), false, false, false, | 208 base::Time(), base::Time(), base::Time(), false, false, false, |
| 209 COOKIE_PRIORITY_DEFAULT)); | 209 COOKIE_PRIORITY_DEFAULT)); |
| 210 EXPECT_TRUE(this->SetCookieWithDetails( | 210 EXPECT_TRUE(this->SetCookieWithDetails( |
| 211 cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(), | 211 cm, url_top_level_domain_plus_3, "host_3", "X", std::string(), "/", |
| 212 "/", base::Time(), base::Time(), base::Time(), false, false, false, | 212 base::Time(), base::Time(), base::Time(), false, false, false, |
| 213 COOKIE_PRIORITY_DEFAULT)); | 213 COOKIE_PRIORITY_DEFAULT)); |
| 214 | 214 |
| 215 // http_only cookie | 215 // http_only cookie |
| 216 EXPECT_TRUE(this->SetCookieWithDetails( | 216 EXPECT_TRUE(this->SetCookieWithDetails( |
| 217 cm.get(), url_top_level_domain_plus_2, "httpo_check", "x", | 217 cm, url_top_level_domain_plus_2, "httpo_check", "x", std::string(), "/", |
| 218 std::string(), "/", base::Time(), base::Time(), base::Time(), false, | 218 base::Time(), base::Time(), base::Time(), false, true, false, |
| 219 true, false, COOKIE_PRIORITY_DEFAULT)); | 219 COOKIE_PRIORITY_DEFAULT)); |
| 220 | 220 |
| 221 // same-site cookie | 221 // same-site cookie |
| 222 EXPECT_TRUE(this->SetCookieWithDetails( | 222 EXPECT_TRUE(this->SetCookieWithDetails( |
| 223 cm.get(), url_top_level_domain_plus_2, "firstp_check", "x", | 223 cm, url_top_level_domain_plus_2, "firstp_check", "x", std::string(), |
| 224 std::string(), "/", base::Time(), base::Time(), base::Time(), false, | 224 "/", base::Time(), base::Time(), base::Time(), false, false, true, |
| 225 false, true, COOKIE_PRIORITY_DEFAULT)); | 225 COOKIE_PRIORITY_DEFAULT)); |
| 226 | 226 |
| 227 // Secure cookies | 227 // Secure cookies |
| 228 EXPECT_TRUE(this->SetCookieWithDetails( | 228 EXPECT_TRUE(this->SetCookieWithDetails( |
| 229 cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X", | 229 cm, url_top_level_domain_plus_2_secure, "sec_dom", "X", |
| 230 ".math.harvard.edu", "/", base::Time(), base::Time(), base::Time(), | 230 ".math.harvard.edu", "/", base::Time(), base::Time(), base::Time(), |
| 231 true, false, false, COOKIE_PRIORITY_DEFAULT)); | 231 true, false, false, COOKIE_PRIORITY_DEFAULT)); |
| 232 EXPECT_TRUE(this->SetCookieWithDetails( | 232 EXPECT_TRUE(this->SetCookieWithDetails( |
| 233 cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X", | 233 cm, url_top_level_domain_plus_2_secure, "sec_host", "X", std::string(), |
| 234 std::string(), "/", base::Time(), base::Time(), base::Time(), true, | 234 "/", base::Time(), base::Time(), base::Time(), true, false, false, |
| 235 false, false, COOKIE_PRIORITY_DEFAULT)); | 235 COOKIE_PRIORITY_DEFAULT)); |
| 236 | 236 |
| 237 // Domain path cookies | 237 // Domain path cookies |
| 238 EXPECT_TRUE(this->SetCookieWithDetails( | 238 EXPECT_TRUE(this->SetCookieWithDetails( |
| 239 cm.get(), url_top_level_domain_plus_2, "dom_path_1", "X", | 239 cm, url_top_level_domain_plus_2, "dom_path_1", "X", ".math.harvard.edu", |
| 240 ".math.harvard.edu", "/dir1", base::Time(), base::Time(), base::Time(), | 240 "/dir1", base::Time(), base::Time(), base::Time(), false, false, false, |
| 241 false, false, false, COOKIE_PRIORITY_DEFAULT)); | 241 COOKIE_PRIORITY_DEFAULT)); |
| 242 EXPECT_TRUE(this->SetCookieWithDetails( | 242 EXPECT_TRUE(this->SetCookieWithDetails( |
| 243 cm.get(), url_top_level_domain_plus_2, "dom_path_2", "X", | 243 cm, url_top_level_domain_plus_2, "dom_path_2", "X", ".math.harvard.edu", |
| 244 ".math.harvard.edu", "/dir1/dir2", base::Time(), base::Time(), | 244 "/dir1/dir2", base::Time(), base::Time(), base::Time(), false, false, |
| 245 base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); | 245 false, COOKIE_PRIORITY_DEFAULT)); |
| 246 | 246 |
| 247 // Host path cookies | 247 // Host path cookies |
| 248 EXPECT_TRUE(this->SetCookieWithDetails( | 248 EXPECT_TRUE(this->SetCookieWithDetails( |
| 249 cm.get(), url_top_level_domain_plus_2, "host_path_1", "X", | 249 cm, url_top_level_domain_plus_2, "host_path_1", "X", std::string(), |
| 250 std::string(), "/dir1", base::Time(), base::Time(), base::Time(), false, | 250 "/dir1", base::Time(), base::Time(), base::Time(), false, false, false, |
| 251 false, false, COOKIE_PRIORITY_DEFAULT)); | 251 COOKIE_PRIORITY_DEFAULT)); |
| 252 EXPECT_TRUE(this->SetCookieWithDetails( | 252 EXPECT_TRUE(this->SetCookieWithDetails( |
| 253 cm.get(), url_top_level_domain_plus_2, "host_path_2", "X", | 253 cm, url_top_level_domain_plus_2, "host_path_2", "X", std::string(), |
| 254 std::string(), "/dir1/dir2", base::Time(), base::Time(), base::Time(), | 254 "/dir1/dir2", base::Time(), base::Time(), base::Time(), false, false, |
| 255 false, false, false, COOKIE_PRIORITY_DEFAULT)); | 255 false, COOKIE_PRIORITY_DEFAULT)); |
| 256 | 256 |
| 257 EXPECT_EQ(14U, this->GetAllCookies(cm.get()).size()); | 257 EXPECT_EQ(14U, this->GetAllCookies(cm).size()); |
| 258 } | 258 } |
| 259 | 259 |
| 260 Time GetFirstCookieAccessDate(CookieMonster* cm) { | 260 Time GetFirstCookieAccessDate(CookieMonster* cm) { |
| 261 const CookieList all_cookies(this->GetAllCookies(cm)); | 261 const CookieList all_cookies(this->GetAllCookies(cm)); |
| 262 return all_cookies.front().LastAccessDate(); | 262 return all_cookies.front().LastAccessDate(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool FindAndDeleteCookie(CookieMonster* cm, | 265 bool FindAndDeleteCookie(CookieMonster* cm, |
| 266 const std::string& domain, | 266 const std::string& domain, |
| 267 const std::string& name) { | 267 const std::string& name) { |
| 268 CookieList cookies = this->GetAllCookies(cm); | 268 CookieList cookies = this->GetAllCookies(cm); |
| 269 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) | 269 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) |
| 270 if (it->Domain() == domain && it->Name() == name) | 270 if (it->Domain() == domain && it->Name() == name) |
| 271 return this->DeleteCanonicalCookie(cm, *it); | 271 return this->DeleteCanonicalCookie(cm, *it); |
| 272 return false; | 272 return false; |
| 273 } | 273 } |
| 274 | 274 |
| 275 int CountInString(const std::string& str, char c) { | 275 int CountInString(const std::string& str, char c) { |
| 276 return std::count(str.begin(), str.end(), c); | 276 return std::count(str.begin(), str.end(), c); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void TestHostGarbageCollectHelper() { | 279 void TestHostGarbageCollectHelper() { |
| 280 int domain_max_cookies = CookieMonster::kDomainMaxCookies; | 280 int domain_max_cookies = CookieMonster::kDomainMaxCookies; |
| 281 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies; | 281 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies; |
| 282 const int more_than_enough_cookies = | 282 const int more_than_enough_cookies = |
| 283 (domain_max_cookies + domain_purge_cookies) * 2; | 283 (domain_max_cookies + domain_purge_cookies) * 2; |
| 284 // Add a bunch of cookies on a single host, should purge them. | 284 // Add a bunch of cookies on a single host, should purge them. |
| 285 { | 285 { |
| 286 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 286 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 287 for (int i = 0; i < more_than_enough_cookies; ++i) { | 287 for (int i = 0; i < more_than_enough_cookies; ++i) { |
| 288 std::string cookie = base::StringPrintf("a%03d=b", i); | 288 std::string cookie = base::StringPrintf("a%03d=b", i); |
| 289 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), cookie)); | 289 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), cookie)); |
| 290 std::string cookies = | 290 std::string cookies = |
| 291 this->GetCookies(cm.get(), http_www_google_.url()); | 291 this->GetCookies(cm.get(), http_www_google_.url()); |
| 292 // Make sure we find it in the cookies. | 292 // Make sure we find it in the cookies. |
| 293 EXPECT_NE(cookies.find(cookie), std::string::npos); | 293 EXPECT_NE(cookies.find(cookie), std::string::npos); |
| 294 // Count the number of cookies. | 294 // Count the number of cookies. |
| 295 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); | 295 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 | 298 |
| 299 // Add a bunch of cookies on multiple hosts within a single eTLD. | 299 // Add a bunch of cookies on multiple hosts within a single eTLD. |
| 300 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies | 300 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies |
| 301 // between them. We shouldn't go above kDomainMaxCookies for both together. | 301 // between them. We shouldn't go above kDomainMaxCookies for both together. |
| 302 GURL url_google_specific(http_www_google_.Format("http://www.gmail.%D")); | 302 GURL url_google_specific(http_www_google_.Format("http://www.gmail.%D")); |
| 303 { | 303 { |
| 304 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 304 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 305 for (int i = 0; i < more_than_enough_cookies; ++i) { | 305 for (int i = 0; i < more_than_enough_cookies; ++i) { |
| 306 std::string cookie_general = base::StringPrintf("a%03d=b", i); | 306 std::string cookie_general = base::StringPrintf("a%03d=b", i); |
| 307 EXPECT_TRUE( | 307 EXPECT_TRUE( |
| 308 SetCookie(cm.get(), http_www_google_.url(), cookie_general)); | 308 SetCookie(cm.get(), http_www_google_.url(), cookie_general)); |
| 309 std::string cookie_specific = base::StringPrintf("c%03d=b", i); | 309 std::string cookie_specific = base::StringPrintf("c%03d=b", i); |
| 310 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific)); | 310 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific)); |
| 311 std::string cookies_general = | 311 std::string cookies_general = |
| 312 this->GetCookies(cm.get(), http_www_google_.url()); | 312 this->GetCookies(cm.get(), http_www_google_.url()); |
| 313 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); | 313 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); |
| 314 std::string cookies_specific = | 314 std::string cookies_specific = |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 // of cookies to create. Cookies are created in the order they appear in | 437 // of cookies to create. Cookies are created in the order they appear in |
| 438 // cookie_entries. The value of cookie_entries[x].num_cookies specifies how | 438 // cookie_entries. The value of cookie_entries[x].num_cookies specifies how |
| 439 // many cookies of that type to create consecutively, while if | 439 // many cookies of that type to create consecutively, while if |
| 440 // cookie_entries[x].is_secure is |true|, those cookies will be marke as | 440 // cookie_entries[x].is_secure is |true|, those cookies will be marke as |
| 441 // Secure. | 441 // Secure. |
| 442 void TestSecureCookieEviction(const CookiesEntry* cookie_entries, | 442 void TestSecureCookieEviction(const CookiesEntry* cookie_entries, |
| 443 size_t num_cookie_entries, | 443 size_t num_cookie_entries, |
| 444 size_t expected_secure_cookies, | 444 size_t expected_secure_cookies, |
| 445 size_t expected_non_secure_cookies, | 445 size_t expected_non_secure_cookies, |
| 446 const AltHosts* alt_host_entries) { | 446 const AltHosts* alt_host_entries) { |
| 447 scoped_refptr<CookieMonster> cm; | 447 scoped_ptr<CookieMonster> cm; |
| 448 | 448 |
| 449 if (alt_host_entries == nullptr) { | 449 if (alt_host_entries == nullptr) { |
| 450 cm = new CookieMonster(nullptr, nullptr); | 450 cm.reset(new CookieMonster(nullptr, nullptr)); |
| 451 } else { | 451 } else { |
| 452 // When generating all of these cookies on alternate hosts, they need to | 452 // When generating all of these cookies on alternate hosts, they need to |
| 453 // be all older than the max "safe" date for GC, which is currently 30 | 453 // be all older than the max "safe" date for GC, which is currently 30 |
| 454 // days, so we set them to 60. | 454 // days, so we set them to 60. |
| 455 cm = CreateMonsterFromStoreForGC( | 455 cm = CreateMonsterFromStoreForGC( |
| 456 alt_host_entries->first, alt_host_entries->first, | 456 alt_host_entries->first, alt_host_entries->first, |
| 457 alt_host_entries->second, alt_host_entries->second, 60); | 457 alt_host_entries->second, alt_host_entries->second, 60); |
| 458 } | 458 } |
| 459 | 459 |
| 460 int next_cookie_id = 0; | 460 int next_cookie_id = 0; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 488 | 488 |
| 489 void TestPriorityAwareGarbageCollectHelper() { | 489 void TestPriorityAwareGarbageCollectHelper() { |
| 490 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 490 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
| 491 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 491 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
| 492 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 492 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
| 493 CookieMonster::kDomainPurgeCookies); | 493 CookieMonster::kDomainPurgeCookies); |
| 494 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); | 494 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); |
| 495 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); | 495 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); |
| 496 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); | 496 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); |
| 497 | 497 |
| 498 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 498 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 499 | 499 |
| 500 // Each test case adds 181 cookies, so 31 cookies are evicted. | 500 // Each test case adds 181 cookies, so 31 cookies are evicted. |
| 501 // Cookie same priority, repeated for each priority. | 501 // Cookie same priority, repeated for each priority. |
| 502 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); | 502 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); |
| 503 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); | 503 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); |
| 504 TestPriorityCookieCase(cm.get(), "181H", 0U, 0U, 150U); | 504 TestPriorityCookieCase(cm.get(), "181H", 0U, 0U, 150U); |
| 505 | 505 |
| 506 // Pairwise scenarios. | 506 // Pairwise scenarios. |
| 507 // Round 1 => none; round2 => 31M; round 3 => none. | 507 // Round 1 => none; round2 => 31M; round 3 => none. |
| 508 TestPriorityCookieCase(cm.get(), "10H 171M", 0U, 140U, 10U); | 508 TestPriorityCookieCase(cm.get(), "10H 171M", 0U, 140U, 10U); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 // Specifically, for each asynchronous method, verify that: | 706 // Specifically, for each asynchronous method, verify that: |
| 707 // 1. invoking it on an uninitialized cookie store causes the store to begin | 707 // 1. invoking it on an uninitialized cookie store causes the store to begin |
| 708 // chain-loading its backing data or loading data for a specific domain key | 708 // chain-loading its backing data or loading data for a specific domain key |
| 709 // (eTLD+1). | 709 // (eTLD+1). |
| 710 // 2. The initial invocation does not complete until the loading completes. | 710 // 2. The initial invocation does not complete until the loading completes. |
| 711 // 3. Invocations after the loading has completed complete immediately. | 711 // 3. Invocations after the loading has completed complete immediately. |
| 712 class DeferredCookieTaskTest : public CookieMonsterTest { | 712 class DeferredCookieTaskTest : public CookieMonsterTest { |
| 713 protected: | 713 protected: |
| 714 DeferredCookieTaskTest() : expect_load_called_(false) { | 714 DeferredCookieTaskTest() : expect_load_called_(false) { |
| 715 persistent_store_ = new NewMockPersistentCookieStore(); | 715 persistent_store_ = new NewMockPersistentCookieStore(); |
| 716 cookie_monster_ = new CookieMonster(persistent_store_.get(), NULL); | 716 cookie_monster_.reset(new CookieMonster(persistent_store_.get(), nullptr)); |
| 717 } | 717 } |
| 718 | 718 |
| 719 // Defines a cookie to be returned from PersistentCookieStore::Load | 719 // Defines a cookie to be returned from PersistentCookieStore::Load |
| 720 void DeclareLoadedCookie(const std::string& key, | 720 void DeclareLoadedCookie(const std::string& key, |
| 721 const std::string& cookie_line, | 721 const std::string& cookie_line, |
| 722 const base::Time& creation_time) { | 722 const base::Time& creation_time) { |
| 723 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_); | 723 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_); |
| 724 } | 724 } |
| 725 | 725 |
| 726 // Runs the message loop, waiting until PersistentCookieStore::Load is called. | 726 // Runs the message loop, waiting until PersistentCookieStore::Load is called. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; | 795 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; |
| 796 // Stores the callback passed from the CookieMonster to the | 796 // Stores the callback passed from the CookieMonster to the |
| 797 // PersistentCookieStore::LoadCookiesForKey | 797 // PersistentCookieStore::LoadCookiesForKey |
| 798 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> | 798 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> |
| 799 loaded_for_key_callbacks_; | 799 loaded_for_key_callbacks_; |
| 800 // base::RunLoop used to wait for PersistentCookieStore::Load to be called. | 800 // base::RunLoop used to wait for PersistentCookieStore::Load to be called. |
| 801 base::RunLoop load_run_loop_; | 801 base::RunLoop load_run_loop_; |
| 802 // Indicates whether ExpectLoadCall() has been called. | 802 // Indicates whether ExpectLoadCall() has been called. |
| 803 bool expect_load_called_; | 803 bool expect_load_called_; |
| 804 // Stores the CookieMonster under test. | 804 // Stores the CookieMonster under test. |
| 805 scoped_refptr<CookieMonster> cookie_monster_; | 805 scoped_ptr<CookieMonster> cookie_monster_; |
| 806 // Stores the mock PersistentCookieStore. | 806 // Stores the mock PersistentCookieStore. |
| 807 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; | 807 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; |
| 808 }; | 808 }; |
| 809 | 809 |
| 810 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { | 810 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { |
| 811 DeclareLoadedCookie(http_www_google_.host(), | 811 DeclareLoadedCookie(http_www_google_.host(), |
| 812 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 812 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 813 Time::Now() + TimeDelta::FromDays(3)); | 813 Time::Now() + TimeDelta::FromDays(3)); |
| 814 | 814 |
| 815 MockGetCookiesCallback get_cookies_callback; | 815 MockGetCookiesCallback get_cookies_callback; |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 base::RunLoop loop; | 1138 base::RunLoop loop; |
| 1139 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) | 1139 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) |
| 1140 .WillOnce(QuitRunLoop(&loop)); | 1140 .WillOnce(QuitRunLoop(&loop)); |
| 1141 | 1141 |
| 1142 CompleteLoading(); | 1142 CompleteLoading(); |
| 1143 loop.Run(); | 1143 loop.Run(); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { | 1146 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { |
| 1147 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1147 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1148 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1148 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1149 CookieOptions options; | 1149 CookieOptions options; |
| 1150 options.set_include_httponly(); | 1150 options.set_include_httponly(); |
| 1151 | 1151 |
| 1152 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); | 1152 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); |
| 1153 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1153 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 1154 | 1154 |
| 1155 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1155 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
| 1156 "C=D; httponly", options)); | 1156 "C=D; httponly", options)); |
| 1157 EXPECT_EQ("A=B; C=D", | 1157 EXPECT_EQ("A=B; C=D", |
| 1158 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1158 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1171 | 1171 |
| 1172 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. | 1172 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. |
| 1173 ASSERT_EQ(2u, store->commands().size()); | 1173 ASSERT_EQ(2u, store->commands().size()); |
| 1174 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1174 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1175 | 1175 |
| 1176 EXPECT_EQ("", | 1176 EXPECT_EQ("", |
| 1177 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1177 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); |
| 1178 } | 1178 } |
| 1179 | 1179 |
| 1180 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1180 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 1181 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1181 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1182 Time now = Time::Now(); | 1182 Time now = Time::Now(); |
| 1183 | 1183 |
| 1184 // Nothing has been added so nothing should be deleted. | 1184 // Nothing has been added so nothing should be deleted. |
| 1185 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), | 1185 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
| 1186 Time())); | 1186 Time())); |
| 1187 | 1187 |
| 1188 // Create 3 cookies with creation date of today, yesterday and the day before. | 1188 // Create 3 cookies with creation date of today, yesterday and the day before. |
| 1189 EXPECT_TRUE( | 1189 EXPECT_TRUE( |
| 1190 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); | 1190 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); |
| 1191 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1191 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1213 // Delete the last (now) item. | 1213 // Delete the last (now) item. |
| 1214 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); | 1214 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); |
| 1215 | 1215 |
| 1216 // Really make sure everything is gone. | 1216 // Really make sure everything is gone. |
| 1217 EXPECT_EQ(0, DeleteAll(cm.get())); | 1217 EXPECT_EQ(0, DeleteAll(cm.get())); |
| 1218 } | 1218 } |
| 1219 | 1219 |
| 1220 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; | 1220 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; |
| 1221 | 1221 |
| 1222 TEST_F(CookieMonsterTest, TestLastAccess) { | 1222 TEST_F(CookieMonsterTest, TestLastAccess) { |
| 1223 scoped_refptr<CookieMonster> cm( | 1223 scoped_ptr<CookieMonster> cm( |
| 1224 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 1224 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); |
| 1225 | 1225 |
| 1226 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1226 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
| 1227 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1227 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
| 1228 | 1228 |
| 1229 // Reading the cookie again immediately shouldn't update the access date, | 1229 // Reading the cookie again immediately shouldn't update the access date, |
| 1230 // since we're inside the threshold. | 1230 // since we're inside the threshold. |
| 1231 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1231 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 1232 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1232 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1233 | 1233 |
| 1234 // Reading after a short wait will update the access date, if the cookie | 1234 // Reading after a short wait will update the access date, if the cookie |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1261 | 1261 |
| 1262 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { | 1262 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { |
| 1263 TestHostGarbageCollectHelper(); | 1263 TestHostGarbageCollectHelper(); |
| 1264 } | 1264 } |
| 1265 | 1265 |
| 1266 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) { | 1266 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) { |
| 1267 TestPriorityAwareGarbageCollectHelper(); | 1267 TestPriorityAwareGarbageCollectHelper(); |
| 1268 } | 1268 } |
| 1269 | 1269 |
| 1270 TEST_F(CookieMonsterTest, SetCookieableSchemes) { | 1270 TEST_F(CookieMonsterTest, SetCookieableSchemes) { |
| 1271 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1271 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1272 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); | 1272 scoped_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, nullptr)); |
| 1273 | 1273 |
| 1274 // Only cm_foo should allow foo:// cookies. | 1274 // Only cm_foo should allow foo:// cookies. |
| 1275 std::vector<std::string> schemes; | 1275 std::vector<std::string> schemes; |
| 1276 schemes.push_back("foo"); | 1276 schemes.push_back("foo"); |
| 1277 cm_foo->SetCookieableSchemes(schemes); | 1277 cm_foo->SetCookieableSchemes(schemes); |
| 1278 | 1278 |
| 1279 GURL foo_url("foo://host/path"); | 1279 GURL foo_url("foo://host/path"); |
| 1280 GURL http_url("http://host/path"); | 1280 GURL http_url("http://host/path"); |
| 1281 | 1281 |
| 1282 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); | 1282 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); |
| 1283 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); | 1283 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); |
| 1284 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); | 1284 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); |
| 1285 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); | 1285 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { | 1288 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { |
| 1289 scoped_refptr<CookieMonster> cm( | 1289 scoped_ptr<CookieMonster> cm( |
| 1290 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 1290 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); |
| 1291 | 1291 |
| 1292 // Create an httponly cookie. | 1292 // Create an httponly cookie. |
| 1293 CookieOptions options; | 1293 CookieOptions options; |
| 1294 options.set_include_httponly(); | 1294 options.set_include_httponly(); |
| 1295 | 1295 |
| 1296 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1296 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
| 1297 "A=B; httponly", options)); | 1297 "A=B; httponly", options)); |
| 1298 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1298 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
| 1299 http_www_google_.Format("C=D; domain=.%D"), | 1299 http_www_google_.Format("C=D; domain=.%D"), |
| 1300 options)); | 1300 options)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); | 1348 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); |
| 1349 EXPECT_EQ("E", it->Name()); | 1349 EXPECT_EQ("E", it->Name()); |
| 1350 | 1350 |
| 1351 ASSERT_TRUE(++it == cookies.end()); | 1351 ASSERT_TRUE(++it == cookies.end()); |
| 1352 | 1352 |
| 1353 // Reading after a short wait should not update the access date. | 1353 // Reading after a short wait should not update the access date. |
| 1354 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1354 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1355 } | 1355 } |
| 1356 | 1356 |
| 1357 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { | 1357 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { |
| 1358 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1358 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1359 CookieOptions options; | 1359 CookieOptions options; |
| 1360 | 1360 |
| 1361 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(), | 1361 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(), |
| 1362 "A=B; path=/foo;", options)); | 1362 "A=B; path=/foo;", options)); |
| 1363 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(), | 1363 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(), |
| 1364 "C=D; path=/bar;", options)); | 1364 "C=D; path=/bar;", options)); |
| 1365 EXPECT_TRUE( | 1365 EXPECT_TRUE( |
| 1366 SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options)); | 1366 SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options)); |
| 1367 | 1367 |
| 1368 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url()); | 1368 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1386 EXPECT_EQ("/bar", it->Path()); | 1386 EXPECT_EQ("/bar", it->Path()); |
| 1387 | 1387 |
| 1388 ASSERT_TRUE(++it != cookies.end()); | 1388 ASSERT_TRUE(++it != cookies.end()); |
| 1389 EXPECT_EQ("E", it->Name()); | 1389 EXPECT_EQ("E", it->Name()); |
| 1390 EXPECT_EQ("/", it->Path()); | 1390 EXPECT_EQ("/", it->Path()); |
| 1391 | 1391 |
| 1392 ASSERT_TRUE(++it == cookies.end()); | 1392 ASSERT_TRUE(++it == cookies.end()); |
| 1393 } | 1393 } |
| 1394 | 1394 |
| 1395 TEST_F(CookieMonsterTest, CookieSorting) { | 1395 TEST_F(CookieMonsterTest, CookieSorting) { |
| 1396 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1396 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1397 | 1397 |
| 1398 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); | 1398 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); |
| 1399 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); | 1399 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); |
| 1400 EXPECT_TRUE( | 1400 EXPECT_TRUE( |
| 1401 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); | 1401 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); |
| 1402 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); | 1402 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); |
| 1403 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); | 1403 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); |
| 1404 EXPECT_TRUE( | 1404 EXPECT_TRUE( |
| 1405 SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar")); | 1405 SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar")); |
| 1406 | 1406 |
| 1407 // Re-set cookie which should not change sort order. | 1407 // Re-set cookie which should not change sort order. |
| 1408 EXPECT_TRUE( | 1408 EXPECT_TRUE( |
| 1409 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); | 1409 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); |
| 1410 | 1410 |
| 1411 CookieList cookies = GetAllCookies(cm.get()); | 1411 CookieList cookies = GetAllCookies(cm.get()); |
| 1412 ASSERT_EQ(6u, cookies.size()); | 1412 ASSERT_EQ(6u, cookies.size()); |
| 1413 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the | 1413 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the |
| 1414 // initial creation-time from above, and the sort order should not change. | 1414 // initial creation-time from above, and the sort order should not change. |
| 1415 // Chrome's current implementation deviates from the spec so capturing this to | 1415 // Chrome's current implementation deviates from the spec so capturing this to |
| 1416 // avoid any inadvertent changes to this behavior. | 1416 // avoid any inadvertent changes to this behavior. |
| 1417 EXPECT_EQ("A3", cookies[0].Value()); | 1417 EXPECT_EQ("A3", cookies[0].Value()); |
| 1418 EXPECT_EQ("B3", cookies[1].Value()); | 1418 EXPECT_EQ("B3", cookies[1].Value()); |
| 1419 EXPECT_EQ("B2", cookies[2].Value()); | 1419 EXPECT_EQ("B2", cookies[2].Value()); |
| 1420 EXPECT_EQ("A2", cookies[3].Value()); | 1420 EXPECT_EQ("A2", cookies[3].Value()); |
| 1421 EXPECT_EQ("B1", cookies[4].Value()); | 1421 EXPECT_EQ("B1", cookies[4].Value()); |
| 1422 EXPECT_EQ("A1", cookies[5].Value()); | 1422 EXPECT_EQ("A1", cookies[5].Value()); |
| 1423 } | 1423 } |
| 1424 | 1424 |
| 1425 TEST_F(CookieMonsterTest, DeleteCookieByName) { |
| 1426 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1427 |
| 1428 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); |
| 1429 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); |
| 1430 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/bar")); |
| 1431 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); |
| 1432 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); |
| 1433 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/bar")); |
| 1434 |
| 1435 DeleteCookie(cm.get(), http_www_google_.AppendPath("foo/bar"), "A"); |
| 1436 |
| 1437 CookieList cookies = GetAllCookies(cm.get()); |
| 1438 size_t expected_size = 4; |
| 1439 EXPECT_EQ(expected_size, cookies.size()); |
| 1440 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) { |
| 1441 EXPECT_NE("A1", it->Value()); |
| 1442 EXPECT_NE("A2", it->Value()); |
| 1443 } |
| 1444 } |
| 1445 |
| 1425 // Tests importing from a persistent cookie store that contains duplicate | 1446 // Tests importing from a persistent cookie store that contains duplicate |
| 1426 // equivalent cookies. This situation should be handled by removing the | 1447 // equivalent cookies. This situation should be handled by removing the |
| 1427 // duplicate cookie (both from the in-memory cache, and from the backing store). | 1448 // duplicate cookie (both from the in-memory cache, and from the backing store). |
| 1428 // | 1449 // |
| 1429 // This is a regression test for: http://crbug.com/17855. | 1450 // This is a regression test for: http://crbug.com/17855. |
| 1430 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { | 1451 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { |
| 1431 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1452 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1432 | 1453 |
| 1433 // We will fill some initial cookies into the PersistentCookieStore, | 1454 // We will fill some initial cookies into the PersistentCookieStore, |
| 1434 // to simulate a database with 4 duplicates. Note that we need to | 1455 // to simulate a database with 4 duplicates. Note that we need to |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); | 1492 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); |
| 1472 | 1493 |
| 1473 // Insert 1 cookie with name "Y" on path "/". | 1494 // Insert 1 cookie with name "Y" on path "/". |
| 1474 AddCookieToList("www.google.com", | 1495 AddCookieToList("www.google.com", |
| 1475 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1496 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1476 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); | 1497 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); |
| 1477 | 1498 |
| 1478 // Inject our initial cookies into the mock PersistentCookieStore. | 1499 // Inject our initial cookies into the mock PersistentCookieStore. |
| 1479 store->SetLoadExpectation(true, initial_cookies); | 1500 store->SetLoadExpectation(true, initial_cookies); |
| 1480 | 1501 |
| 1481 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1502 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1482 | 1503 |
| 1483 // Verify that duplicates were not imported for path "/". | 1504 // Verify that duplicates were not imported for path "/". |
| 1484 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). | 1505 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). |
| 1485 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); | 1506 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); |
| 1486 | 1507 |
| 1487 // Verify that same-named cookie on a different path ("/x2") didn't get | 1508 // Verify that same-named cookie on a different path ("/x2") didn't get |
| 1488 // messed up. | 1509 // messed up. |
| 1489 EXPECT_EQ("X=a1; X=3; Y=a", | 1510 EXPECT_EQ("X=a1; X=3; Y=a", |
| 1490 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); | 1511 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); |
| 1491 | 1512 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1519 AddCookieToList("www.google.com", "X=4; path=/", now, &initial_cookies); | 1540 AddCookieToList("www.google.com", "X=4; path=/", now, &initial_cookies); |
| 1520 | 1541 |
| 1521 AddCookieToList("www.google.com", "Y=1; path=/", earlier, &initial_cookies); | 1542 AddCookieToList("www.google.com", "Y=1; path=/", earlier, &initial_cookies); |
| 1522 AddCookieToList("www.google.com", "Y=2; path=/", earlier, &initial_cookies); | 1543 AddCookieToList("www.google.com", "Y=2; path=/", earlier, &initial_cookies); |
| 1523 AddCookieToList("www.google.com", "Y=3; path=/", earlier, &initial_cookies); | 1544 AddCookieToList("www.google.com", "Y=3; path=/", earlier, &initial_cookies); |
| 1524 AddCookieToList("www.google.com", "Y=4; path=/", earlier, &initial_cookies); | 1545 AddCookieToList("www.google.com", "Y=4; path=/", earlier, &initial_cookies); |
| 1525 | 1546 |
| 1526 // Inject our initial cookies into the mock PersistentCookieStore. | 1547 // Inject our initial cookies into the mock PersistentCookieStore. |
| 1527 store->SetLoadExpectation(true, initial_cookies); | 1548 store->SetLoadExpectation(true, initial_cookies); |
| 1528 | 1549 |
| 1529 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1550 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1530 | 1551 |
| 1531 CookieList list(GetAllCookies(cm.get())); | 1552 CookieList list(GetAllCookies(cm.get())); |
| 1532 EXPECT_EQ(2U, list.size()); | 1553 EXPECT_EQ(2U, list.size()); |
| 1533 // Confirm that we have one of each. | 1554 // Confirm that we have one of each. |
| 1534 std::string name1(list[0].Name()); | 1555 std::string name1(list[0].Name()); |
| 1535 std::string name2(list[1].Name()); | 1556 std::string name2(list[1].Name()); |
| 1536 EXPECT_TRUE(name1 == "X" || name2 == "X"); | 1557 EXPECT_TRUE(name1 == "X" || name2 == "X"); |
| 1537 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); | 1558 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); |
| 1538 EXPECT_NE(name1, name2); | 1559 EXPECT_NE(name1, name2); |
| 1539 } | 1560 } |
| 1540 | 1561 |
| 1541 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { | 1562 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { |
| 1542 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1563 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1543 scoped_refptr<MockCookieMonsterDelegate> delegate( | 1564 scoped_refptr<MockCookieMonsterDelegate> delegate( |
| 1544 new MockCookieMonsterDelegate); | 1565 new MockCookieMonsterDelegate); |
| 1545 scoped_refptr<CookieMonster> cm( | 1566 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), delegate.get())); |
| 1546 new CookieMonster(store.get(), delegate.get())); | |
| 1547 | 1567 |
| 1548 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1568 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
| 1549 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D")); | 1569 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D")); |
| 1550 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F")); | 1570 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F")); |
| 1551 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url())); | 1571 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url())); |
| 1552 ASSERT_EQ(3u, delegate->changes().size()); | 1572 ASSERT_EQ(3u, delegate->changes().size()); |
| 1553 EXPECT_FALSE(delegate->changes()[0].second); | 1573 EXPECT_FALSE(delegate->changes()[0].second); |
| 1554 EXPECT_EQ(http_www_google_.url().host(), | 1574 EXPECT_EQ(http_www_google_.url().host(), |
| 1555 delegate->changes()[0].first.Domain()); | 1575 delegate->changes()[0].first.Domain()); |
| 1556 EXPECT_EQ("A", delegate->changes()[0].first.Name()); | 1576 EXPECT_EQ("A", delegate->changes()[0].first.Name()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 1635 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1616 EXPECT_EQ(http_www_google_.url().host(), | 1636 EXPECT_EQ(http_www_google_.url().host(), |
| 1617 delegate->changes()[1].first.Domain()); | 1637 delegate->changes()[1].first.Domain()); |
| 1618 EXPECT_FALSE(delegate->changes()[1].second); | 1638 EXPECT_FALSE(delegate->changes()[1].second); |
| 1619 EXPECT_EQ("a", delegate->changes()[1].first.Name()); | 1639 EXPECT_EQ("a", delegate->changes()[1].first.Name()); |
| 1620 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); | 1640 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); |
| 1621 delegate->reset(); | 1641 delegate->reset(); |
| 1622 } | 1642 } |
| 1623 | 1643 |
| 1624 TEST_F(CookieMonsterTest, DeleteAllForHost) { | 1644 TEST_F(CookieMonsterTest, DeleteAllForHost) { |
| 1625 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1645 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1626 | 1646 |
| 1627 // Test probes: | 1647 // Test probes: |
| 1628 // * Non-secure URL, mid-level (http://w.c.b.a) | 1648 // * Non-secure URL, mid-level (http://w.c.b.a) |
| 1629 // * Secure URL, mid-level (https://w.c.b.a) | 1649 // * Secure URL, mid-level (https://w.c.b.a) |
| 1630 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx) | 1650 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx) |
| 1631 // All three tests should nuke only the midlevel host cookie, | 1651 // All three tests should nuke only the midlevel host cookie, |
| 1632 // the http_only cookie, the host secure cookie, and the two host | 1652 // the http_only cookie, the host secure cookie, and the two host |
| 1633 // path cookies. http_only, secure, and paths are ignored by | 1653 // path cookies. http_only, secure, and paths are ignored by |
| 1634 // this call, and domain cookies arent touched. | 1654 // this call, and domain cookies arent touched. |
| 1635 PopulateCmForDeleteAllForHost(cm); | 1655 PopulateCmForDeleteAllForHost(cm.get()); |
| 1636 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1656 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1637 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1657 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1638 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1658 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
| 1639 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1659 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1640 EXPECT_EQ("dom_1=X; host_1=X", | 1660 EXPECT_EQ("dom_1=X; host_1=X", |
| 1641 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1661 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1642 EXPECT_EQ( | 1662 EXPECT_EQ( |
| 1643 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " | 1663 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " |
| 1644 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1664 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
| 1645 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1665 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1646 std::string("/dir1/dir2/xxx")))); | 1666 std::string("/dir1/dir2/xxx")))); |
| 1647 | 1667 |
| 1648 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost(cm.get(), base::Time(), | 1668 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost(cm.get(), base::Time(), |
| 1649 base::Time::Now(), | 1669 base::Time::Now(), |
| 1650 GURL(kTopLevelDomainPlus2))); | 1670 GURL(kTopLevelDomainPlus2))); |
| 1651 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1671 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1652 | 1672 |
| 1653 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1673 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1654 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1674 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1655 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1675 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1656 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1676 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1657 EXPECT_EQ("dom_1=X; host_1=X", | 1677 EXPECT_EQ("dom_1=X; host_1=X", |
| 1658 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1678 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1659 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1679 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1660 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1680 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1661 std::string("/dir1/dir2/xxx")))); | 1681 std::string("/dir1/dir2/xxx")))); |
| 1662 | 1682 |
| 1663 PopulateCmForDeleteAllForHost(cm); | 1683 PopulateCmForDeleteAllForHost(cm.get()); |
| 1664 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost( | 1684 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost( |
| 1665 cm.get(), base::Time(), base::Time::Now(), | 1685 cm.get(), base::Time(), base::Time::Now(), |
| 1666 GURL(kTopLevelDomainPlus2Secure))); | 1686 GURL(kTopLevelDomainPlus2Secure))); |
| 1667 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1687 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1668 | 1688 |
| 1669 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1689 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1670 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1690 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1671 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1691 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1672 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1692 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1673 EXPECT_EQ("dom_1=X; host_1=X", | 1693 EXPECT_EQ("dom_1=X; host_1=X", |
| 1674 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1694 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1675 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1695 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1676 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1696 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1677 std::string("/dir1/dir2/xxx")))); | 1697 std::string("/dir1/dir2/xxx")))); |
| 1678 | 1698 |
| 1679 PopulateCmForDeleteAllForHost(cm); | 1699 PopulateCmForDeleteAllForHost(cm.get()); |
| 1680 EXPECT_EQ(6, | 1700 EXPECT_EQ(6, |
| 1681 DeleteAllCreatedBetweenForHost( | 1701 DeleteAllCreatedBetweenForHost( |
| 1682 cm.get(), base::Time(), base::Time::Now(), | 1702 cm.get(), base::Time(), base::Time::Now(), |
| 1683 GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/xxx")))); | 1703 GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/xxx")))); |
| 1684 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1704 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1685 | 1705 |
| 1686 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1706 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1687 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1707 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1688 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1708 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1689 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1709 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1690 EXPECT_EQ("dom_1=X; host_1=X", | 1710 EXPECT_EQ("dom_1=X; host_1=X", |
| 1691 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1711 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1692 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1712 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1693 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1713 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1694 std::string("/dir1/dir2/xxx")))); | 1714 std::string("/dir1/dir2/xxx")))); |
| 1695 } | 1715 } |
| 1696 | 1716 |
| 1697 TEST_F(CookieMonsterTest, UniqueCreationTime) { | 1717 TEST_F(CookieMonsterTest, UniqueCreationTime) { |
| 1698 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1718 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1699 CookieOptions options; | 1719 CookieOptions options; |
| 1700 | 1720 |
| 1701 // Add in three cookies through every public interface to the | 1721 // Add in three cookies through every public interface to the |
| 1702 // CookieMonster and confirm that none of them have duplicate | 1722 // CookieMonster and confirm that none of them have duplicate |
| 1703 // creation times. | 1723 // creation times. |
| 1704 | 1724 |
| 1705 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions | 1725 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions |
| 1706 // are not included as they aren't going to be public for very much | 1726 // are not included as they aren't going to be public for very much |
| 1707 // longer. | 1727 // longer. |
| 1708 | 1728 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 if (existing_cookie_it == check_map.end()) { | 1771 if (existing_cookie_it == check_map.end()) { |
| 1752 check_map.insert( | 1772 check_map.insert( |
| 1753 TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it)); | 1773 TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it)); |
| 1754 } | 1774 } |
| 1755 } | 1775 } |
| 1756 } | 1776 } |
| 1757 | 1777 |
| 1758 // Mainly a test of GetEffectiveDomain, or more specifically, of the | 1778 // Mainly a test of GetEffectiveDomain, or more specifically, of the |
| 1759 // expected behavior of GetEffectiveDomain within the CookieMonster. | 1779 // expected behavior of GetEffectiveDomain within the CookieMonster. |
| 1760 TEST_F(CookieMonsterTest, GetKey) { | 1780 TEST_F(CookieMonsterTest, GetKey) { |
| 1761 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1781 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1762 | 1782 |
| 1763 // This test is really only interesting if GetKey() actually does something. | 1783 // This test is really only interesting if GetKey() actually does something. |
| 1764 EXPECT_EQ("google.com", cm->GetKey("www.google.com")); | 1784 EXPECT_EQ("google.com", cm->GetKey("www.google.com")); |
| 1765 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); | 1785 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); |
| 1766 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); | 1786 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); |
| 1767 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); | 1787 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); |
| 1768 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); | 1788 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); |
| 1769 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); | 1789 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); |
| 1770 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); | 1790 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); |
| 1771 | 1791 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1817 "/another/path/to/cookie", | 1837 "/another/path/to/cookie", |
| 1818 base::Time::Now() + base::TimeDelta::FromSeconds(100), | 1838 base::Time::Now() + base::TimeDelta::FromSeconds(100), |
| 1819 true, | 1839 true, |
| 1820 false, | 1840 false, |
| 1821 true, | 1841 true, |
| 1822 COOKIE_PRIORITY_DEFAULT}}; | 1842 COOKIE_PRIORITY_DEFAULT}}; |
| 1823 const int INPUT_DELETE = 1; | 1843 const int INPUT_DELETE = 1; |
| 1824 | 1844 |
| 1825 // Create new cookies and flush them to the store. | 1845 // Create new cookies and flush them to the store. |
| 1826 { | 1846 { |
| 1827 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); | 1847 scoped_ptr<CookieMonster> cmout(new CookieMonster(store.get(), nullptr)); |
| 1828 for (const CookiesInputInfo* p = input_info; | 1848 for (const CookiesInputInfo* p = input_info; |
| 1829 p < &input_info[arraysize(input_info)]; p++) { | 1849 p < &input_info[arraysize(input_info)]; p++) { |
| 1830 EXPECT_TRUE(SetCookieWithDetails( | 1850 EXPECT_TRUE(SetCookieWithDetails( |
| 1831 cmout.get(), p->url, p->name, p->value, p->domain, p->path, | 1851 cmout.get(), p->url, p->name, p->value, p->domain, p->path, |
| 1832 base::Time(), p->expiration_time, base::Time(), p->secure, | 1852 base::Time(), p->expiration_time, base::Time(), p->secure, |
| 1833 p->http_only, p->same_site, p->priority)); | 1853 p->http_only, p->same_site, p->priority)); |
| 1834 } | 1854 } |
| 1835 GURL del_url(input_info[INPUT_DELETE] | 1855 GURL del_url(input_info[INPUT_DELETE] |
| 1836 .url.Resolve(input_info[INPUT_DELETE].path) | 1856 .url.Resolve(input_info[INPUT_DELETE].path) |
| 1837 .spec()); | 1857 .spec()); |
| 1838 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); | 1858 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); |
| 1839 } | 1859 } |
| 1840 | 1860 |
| 1841 // Create a new cookie monster and make sure that everything is correct | 1861 // Create a new cookie monster and make sure that everything is correct |
| 1842 { | 1862 { |
| 1843 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); | 1863 scoped_ptr<CookieMonster> cmin(new CookieMonster(store.get(), nullptr)); |
| 1844 CookieList cookies(GetAllCookies(cmin.get())); | 1864 CookieList cookies(GetAllCookies(cmin.get())); |
| 1845 ASSERT_EQ(2u, cookies.size()); | 1865 ASSERT_EQ(2u, cookies.size()); |
| 1846 // Ordering is path length, then creation time. So second cookie | 1866 // Ordering is path length, then creation time. So second cookie |
| 1847 // will come first, and we need to swap them. | 1867 // will come first, and we need to swap them. |
| 1848 std::swap(cookies[0], cookies[1]); | 1868 std::swap(cookies[0], cookies[1]); |
| 1849 for (int output_index = 0; output_index < 2; output_index++) { | 1869 for (int output_index = 0; output_index < 2; output_index++) { |
| 1850 int input_index = output_index * 2; | 1870 int input_index = output_index * 2; |
| 1851 const CookiesInputInfo* input = &input_info[input_index]; | 1871 const CookiesInputInfo* input = &input_info[input_index]; |
| 1852 const CanonicalCookie* output = &cookies[output_index]; | 1872 const CanonicalCookie* output = &cookies[output_index]; |
| 1853 | 1873 |
| 1854 EXPECT_EQ(input->name, output->Name()); | 1874 EXPECT_EQ(input->name, output->Name()); |
| 1855 EXPECT_EQ(input->value, output->Value()); | 1875 EXPECT_EQ(input->value, output->Value()); |
| 1856 EXPECT_EQ(input->url.host(), output->Domain()); | 1876 EXPECT_EQ(input->url.host(), output->Domain()); |
| 1857 EXPECT_EQ(input->path, output->Path()); | 1877 EXPECT_EQ(input->path, output->Path()); |
| 1858 EXPECT_LE(current.ToInternalValue(), | 1878 EXPECT_LE(current.ToInternalValue(), |
| 1859 output->CreationDate().ToInternalValue()); | 1879 output->CreationDate().ToInternalValue()); |
| 1860 EXPECT_EQ(input->secure, output->IsSecure()); | 1880 EXPECT_EQ(input->secure, output->IsSecure()); |
| 1861 EXPECT_EQ(input->http_only, output->IsHttpOnly()); | 1881 EXPECT_EQ(input->http_only, output->IsHttpOnly()); |
| 1862 EXPECT_EQ(input->same_site, output->IsSameSite()); | 1882 EXPECT_EQ(input->same_site, output->IsSameSite()); |
| 1863 EXPECT_TRUE(output->IsPersistent()); | 1883 EXPECT_TRUE(output->IsPersistent()); |
| 1864 EXPECT_EQ(input->expiration_time.ToInternalValue(), | 1884 EXPECT_EQ(input->expiration_time.ToInternalValue(), |
| 1865 output->ExpiryDate().ToInternalValue()); | 1885 output->ExpiryDate().ToInternalValue()); |
| 1866 } | 1886 } |
| 1867 } | 1887 } |
| 1868 } | 1888 } |
| 1869 | 1889 |
| 1870 TEST_F(CookieMonsterTest, CookieListOrdering) { | 1890 TEST_F(CookieMonsterTest, CookieListOrdering) { |
| 1871 // Put a random set of cookies into a monster and make sure | 1891 // Put a random set of cookies into a monster and make sure |
| 1872 // they're returned in the right order. | 1892 // they're returned in the right order. |
| 1873 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1893 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1874 EXPECT_TRUE( | 1894 EXPECT_TRUE( |
| 1875 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); | 1895 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); |
| 1876 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 1896 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 1877 "d=1; domain=b.a.google.com")); | 1897 "d=1; domain=b.a.google.com")); |
| 1878 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 1898 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 1879 "a=4; domain=b.a.google.com")); | 1899 "a=4; domain=b.a.google.com")); |
| 1880 EXPECT_TRUE(SetCookie(cm.get(), | 1900 EXPECT_TRUE(SetCookie(cm.get(), |
| 1881 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 1901 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), |
| 1882 "e=1; domain=c.b.a.google.com")); | 1902 "e=1; domain=c.b.a.google.com")); |
| 1883 EXPECT_TRUE(SetCookie(cm.get(), | 1903 EXPECT_TRUE(SetCookie(cm.get(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 #if defined(OS_WIN) | 1940 #if defined(OS_WIN) |
| 1921 #define MAYBE_GarbageCollectionTriggers DISABLED_GarbageCollectionTriggers | 1941 #define MAYBE_GarbageCollectionTriggers DISABLED_GarbageCollectionTriggers |
| 1922 #else | 1942 #else |
| 1923 #define MAYBE_GarbageCollectionTriggers GarbageCollectionTriggers | 1943 #define MAYBE_GarbageCollectionTriggers GarbageCollectionTriggers |
| 1924 #endif | 1944 #endif |
| 1925 | 1945 |
| 1926 TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) { | 1946 TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) { |
| 1927 // First we check to make sure that a whole lot of recent cookies | 1947 // First we check to make sure that a whole lot of recent cookies |
| 1928 // doesn't get rid of anything after garbage collection is checked for. | 1948 // doesn't get rid of anything after garbage collection is checked for. |
| 1929 { | 1949 { |
| 1930 scoped_refptr<CookieMonster> cm( | 1950 scoped_ptr<CookieMonster> cm( |
| 1931 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); | 1951 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); |
| 1932 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm.get()).size()); | 1952 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm.get()).size()); |
| 1933 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 1953 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
| 1934 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, | 1954 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, |
| 1935 GetAllCookies(cm.get()).size()); | 1955 GetAllCookies(cm.get()).size()); |
| 1936 } | 1956 } |
| 1937 | 1957 |
| 1938 // Now we explore a series of relationships between cookie last access | 1958 // Now we explore a series of relationships between cookie last access |
| 1939 // time and size of store to make sure we only get rid of cookies when | 1959 // time and size of store to make sure we only get rid of cookies when |
| 1940 // we really should. | 1960 // we really should. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1962 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}, | 1982 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}, |
| 1963 {// Old cookies enough to bring below our purge line (which we | 1983 {// Old cookies enough to bring below our purge line (which we |
| 1964 // shouldn't do). | 1984 // shouldn't do). |
| 1965 CookieMonster::kMaxCookies * 2, | 1985 CookieMonster::kMaxCookies * 2, |
| 1966 CookieMonster::kMaxCookies * 3 / 2, | 1986 CookieMonster::kMaxCookies * 3 / 2, |
| 1967 CookieMonster::kMaxCookies * 2, | 1987 CookieMonster::kMaxCookies * 2, |
| 1968 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}}; | 1988 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}}; |
| 1969 | 1989 |
| 1970 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { | 1990 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { |
| 1971 const TestCase* test_case = &test_cases[ci]; | 1991 const TestCase* test_case = &test_cases[ci]; |
| 1972 scoped_refptr<CookieMonster> cm(CreateMonsterFromStoreForGC( | 1992 scoped_ptr<CookieMonster> cm = CreateMonsterFromStoreForGC( |
| 1973 test_case->num_cookies, test_case->num_old_cookies, 0, 0, | 1993 test_case->num_cookies, test_case->num_old_cookies, 0, 0, |
| 1974 CookieMonster::kSafeFromGlobalPurgeDays * 2)); | 1994 CookieMonster::kSafeFromGlobalPurgeDays * 2); |
| 1975 EXPECT_EQ(test_case->expected_initial_cookies, | 1995 EXPECT_EQ(test_case->expected_initial_cookies, |
| 1976 GetAllCookies(cm.get()).size()) | 1996 GetAllCookies(cm.get()).size()) |
| 1977 << "For test case " << ci; | 1997 << "For test case " << ci; |
| 1978 // Will trigger GC | 1998 // Will trigger GC |
| 1979 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 1999 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
| 1980 EXPECT_EQ(test_case->expected_cookies_after_set, | 2000 EXPECT_EQ(test_case->expected_cookies_after_set, |
| 1981 GetAllCookies(cm.get()).size()) | 2001 GetAllCookies(cm.get()).size()) |
| 1982 << "For test case " << ci; | 2002 << "For test case " << ci; |
| 1983 } | 2003 } |
| 1984 } | 2004 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 | 2057 |
| 2038 volatile int callback_count_; | 2058 volatile int callback_count_; |
| 2039 }; | 2059 }; |
| 2040 | 2060 |
| 2041 } // namespace | 2061 } // namespace |
| 2042 | 2062 |
| 2043 // Test that FlushStore() is forwarded to the store and callbacks are posted. | 2063 // Test that FlushStore() is forwarded to the store and callbacks are posted. |
| 2044 TEST_F(CookieMonsterTest, FlushStore) { | 2064 TEST_F(CookieMonsterTest, FlushStore) { |
| 2045 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); | 2065 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); |
| 2046 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2066 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2047 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2067 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2048 | 2068 |
| 2049 ASSERT_EQ(0, store->flush_count()); | 2069 ASSERT_EQ(0, store->flush_count()); |
| 2050 ASSERT_EQ(0, counter->callback_count()); | 2070 ASSERT_EQ(0, counter->callback_count()); |
| 2051 | 2071 |
| 2052 // Before initialization, FlushStore() should just run the callback. | 2072 // Before initialization, FlushStore() should just run the callback. |
| 2053 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); | 2073 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); |
| 2054 base::MessageLoop::current()->RunUntilIdle(); | 2074 base::MessageLoop::current()->RunUntilIdle(); |
| 2055 | 2075 |
| 2056 ASSERT_EQ(0, store->flush_count()); | 2076 ASSERT_EQ(0, store->flush_count()); |
| 2057 ASSERT_EQ(1, counter->callback_count()); | 2077 ASSERT_EQ(1, counter->callback_count()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2072 ASSERT_EQ(2, counter->callback_count()); | 2092 ASSERT_EQ(2, counter->callback_count()); |
| 2073 | 2093 |
| 2074 // NULL callback is still safe. | 2094 // NULL callback is still safe. |
| 2075 cm->FlushStore(base::Closure()); | 2095 cm->FlushStore(base::Closure()); |
| 2076 base::MessageLoop::current()->RunUntilIdle(); | 2096 base::MessageLoop::current()->RunUntilIdle(); |
| 2077 | 2097 |
| 2078 ASSERT_EQ(2, store->flush_count()); | 2098 ASSERT_EQ(2, store->flush_count()); |
| 2079 ASSERT_EQ(2, counter->callback_count()); | 2099 ASSERT_EQ(2, counter->callback_count()); |
| 2080 | 2100 |
| 2081 // If there's no backing store, FlushStore() is always a safe no-op. | 2101 // If there's no backing store, FlushStore() is always a safe no-op. |
| 2082 cm = new CookieMonster(NULL, NULL); | 2102 cm.reset(new CookieMonster(nullptr, nullptr)); |
| 2083 GetAllCookies(cm.get()); // Force init. | 2103 GetAllCookies(cm.get()); // Force init. |
| 2084 cm->FlushStore(base::Closure()); | 2104 cm->FlushStore(base::Closure()); |
| 2085 base::MessageLoop::current()->RunUntilIdle(); | 2105 base::MessageLoop::current()->RunUntilIdle(); |
| 2086 | 2106 |
| 2087 ASSERT_EQ(2, counter->callback_count()); | 2107 ASSERT_EQ(2, counter->callback_count()); |
| 2088 | 2108 |
| 2089 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); | 2109 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); |
| 2090 base::MessageLoop::current()->RunUntilIdle(); | 2110 base::MessageLoop::current()->RunUntilIdle(); |
| 2091 | 2111 |
| 2092 ASSERT_EQ(3, counter->callback_count()); | 2112 ASSERT_EQ(3, counter->callback_count()); |
| 2093 } | 2113 } |
| 2094 | 2114 |
| 2095 TEST_F(CookieMonsterTest, SetAllCookies) { | 2115 TEST_F(CookieMonsterTest, SetAllCookies) { |
| 2096 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2116 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2097 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2117 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2098 cm->SetPersistSessionCookies(true); | 2118 cm->SetPersistSessionCookies(true); |
| 2099 | 2119 |
| 2100 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2120 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); |
| 2101 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2121 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); |
| 2102 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2122 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); |
| 2103 | 2123 |
| 2104 CookieList list; | 2124 CookieList list; |
| 2105 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B", | 2125 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B", |
| 2106 http_www_google_.url().host(), "/", | 2126 http_www_google_.url().host(), "/", |
| 2107 base::Time::Now(), base::Time(), base::Time(), | 2127 base::Time::Now(), base::Time(), base::Time(), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2133 ASSERT_TRUE(++it != cookies.end()); | 2153 ASSERT_TRUE(++it != cookies.end()); |
| 2134 EXPECT_EQ("A", it->Name()); | 2154 EXPECT_EQ("A", it->Name()); |
| 2135 EXPECT_EQ("B", it->Value()); | 2155 EXPECT_EQ("B", it->Value()); |
| 2136 | 2156 |
| 2137 ASSERT_TRUE(++it != cookies.end()); | 2157 ASSERT_TRUE(++it != cookies.end()); |
| 2138 EXPECT_EQ("Y", it->Name()); | 2158 EXPECT_EQ("Y", it->Name()); |
| 2139 EXPECT_EQ("Z", it->Value()); | 2159 EXPECT_EQ("Z", it->Value()); |
| 2140 } | 2160 } |
| 2141 | 2161 |
| 2142 TEST_F(CookieMonsterTest, ComputeCookieDiff) { | 2162 TEST_F(CookieMonsterTest, ComputeCookieDiff) { |
| 2143 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2163 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2144 | 2164 |
| 2145 base::Time now = base::Time::Now(); | 2165 base::Time now = base::Time::Now(); |
| 2146 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); | 2166 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); |
| 2147 | 2167 |
| 2148 CanonicalCookie cookie1(http_www_google_.url(), "A", "B", | 2168 CanonicalCookie cookie1(http_www_google_.url(), "A", "B", |
| 2149 http_www_google_.url().host(), "/", creation_time, | 2169 http_www_google_.url().host(), "/", creation_time, |
| 2150 base::Time(), base::Time(), false, false, false, | 2170 base::Time(), base::Time(), false, false, false, |
| 2151 COOKIE_PRIORITY_DEFAULT); | 2171 COOKIE_PRIORITY_DEFAULT); |
| 2152 CanonicalCookie cookie2(http_www_google_.url(), "C", "D", | 2172 CanonicalCookie cookie2(http_www_google_.url(), "C", "D", |
| 2153 http_www_google_.url().host(), "/", creation_time, | 2173 http_www_google_.url().host(), "/", creation_time, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 EXPECT_FALSE(IsCookieInList(cookie7, cookies_to_add)); | 2270 EXPECT_FALSE(IsCookieInList(cookie7, cookies_to_add)); |
| 2251 EXPECT_FALSE(IsCookieInList(cookie7, cookies_to_delete)); | 2271 EXPECT_FALSE(IsCookieInList(cookie7, cookies_to_delete)); |
| 2252 EXPECT_TRUE(IsCookieInList(cookie7_with_new_path, cookies_to_add)); | 2272 EXPECT_TRUE(IsCookieInList(cookie7_with_new_path, cookies_to_add)); |
| 2253 EXPECT_FALSE(IsCookieInList(cookie7_with_new_path, cookies_to_delete)); | 2273 EXPECT_FALSE(IsCookieInList(cookie7_with_new_path, cookies_to_delete)); |
| 2254 } | 2274 } |
| 2255 | 2275 |
| 2256 // Check that DeleteAll does flush (as a sanity check that flush_count() | 2276 // Check that DeleteAll does flush (as a sanity check that flush_count() |
| 2257 // works). | 2277 // works). |
| 2258 TEST_F(CookieMonsterTest, DeleteAll) { | 2278 TEST_F(CookieMonsterTest, DeleteAll) { |
| 2259 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2279 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2260 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2280 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2261 cm->SetPersistSessionCookies(true); | 2281 cm->SetPersistSessionCookies(true); |
| 2262 | 2282 |
| 2263 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/")); | 2283 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/")); |
| 2264 | 2284 |
| 2265 ASSERT_EQ(0, store->flush_count()); | 2285 ASSERT_EQ(0, store->flush_count()); |
| 2266 EXPECT_EQ(1, DeleteAll(cm.get())); | 2286 EXPECT_EQ(1, DeleteAll(cm.get())); |
| 2267 EXPECT_EQ(1, store->flush_count()); | 2287 EXPECT_EQ(1, store->flush_count()); |
| 2268 } | 2288 } |
| 2269 | 2289 |
| 2270 TEST_F(CookieMonsterTest, HistogramCheck) { | 2290 TEST_F(CookieMonsterTest, HistogramCheck) { |
| 2271 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2291 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2272 // Should match call in InitializeHistograms, but doesn't really matter | 2292 // Should match call in InitializeHistograms, but doesn't really matter |
| 2273 // since the histogram should have been initialized by the CM construction | 2293 // since the histogram should have been initialized by the CM construction |
| 2274 // above. | 2294 // above. |
| 2275 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( | 2295 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( |
| 2276 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2296 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
| 2277 base::Histogram::kUmaTargetedHistogramFlag); | 2297 base::Histogram::kUmaTargetedHistogramFlag); |
| 2278 | 2298 |
| 2279 scoped_ptr<base::HistogramSamples> samples1( | 2299 scoped_ptr<base::HistogramSamples> samples1( |
| 2280 expired_histogram->SnapshotSamples()); | 2300 expired_histogram->SnapshotSamples()); |
| 2281 ASSERT_TRUE(SetCookieWithDetails( | 2301 ASSERT_TRUE(SetCookieWithDetails( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2300 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; | 2320 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |
| 2301 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 2321 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
| 2302 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); | 2322 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); |
| 2303 ASSERT_FALSE(cookie->IsPersistent()); | 2323 ASSERT_FALSE(cookie->IsPersistent()); |
| 2304 } | 2324 } |
| 2305 | 2325 |
| 2306 // Test that CookieMonster writes session cookies into the underlying | 2326 // Test that CookieMonster writes session cookies into the underlying |
| 2307 // CookieStore if the "persist session cookies" option is on. | 2327 // CookieStore if the "persist session cookies" option is on. |
| 2308 TEST_F(CookieMonsterTest, PersistSessionCookies) { | 2328 TEST_F(CookieMonsterTest, PersistSessionCookies) { |
| 2309 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2329 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2310 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2330 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2311 cm->SetPersistSessionCookies(true); | 2331 cm->SetPersistSessionCookies(true); |
| 2312 | 2332 |
| 2313 // All cookies set with SetCookie are session cookies. | 2333 // All cookies set with SetCookie are session cookies. |
| 2314 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 2334 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
| 2315 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2335 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 2316 | 2336 |
| 2317 // The cookie was written to the backing store. | 2337 // The cookie was written to the backing store. |
| 2318 EXPECT_EQ(1u, store->commands().size()); | 2338 EXPECT_EQ(1u, store->commands().size()); |
| 2319 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2339 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 2320 EXPECT_EQ("A", store->commands()[0].cookie.Name()); | 2340 EXPECT_EQ("A", store->commands()[0].cookie.Name()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2336 EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url())); | 2356 EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url())); |
| 2337 EXPECT_EQ(4u, store->commands().size()); | 2357 EXPECT_EQ(4u, store->commands().size()); |
| 2338 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2358 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 2339 EXPECT_EQ("A", store->commands()[3].cookie.Name()); | 2359 EXPECT_EQ("A", store->commands()[3].cookie.Name()); |
| 2340 EXPECT_EQ("C", store->commands()[3].cookie.Value()); | 2360 EXPECT_EQ("C", store->commands()[3].cookie.Value()); |
| 2341 } | 2361 } |
| 2342 | 2362 |
| 2343 // Test the commands sent to the persistent cookie store. | 2363 // Test the commands sent to the persistent cookie store. |
| 2344 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { | 2364 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { |
| 2345 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2365 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2346 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2366 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2347 | 2367 |
| 2348 // Add a cookie. | 2368 // Add a cookie. |
| 2349 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 2369 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), |
| 2350 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2370 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 2351 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2371 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 2352 ASSERT_EQ(1u, store->commands().size()); | 2372 ASSERT_EQ(1u, store->commands().size()); |
| 2353 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2373 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 2354 // Remove it. | 2374 // Remove it. |
| 2355 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0")); | 2375 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0")); |
| 2356 this->MatchCookieLines(std::string(), | 2376 this->MatchCookieLines(std::string(), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2405 "boo", | 2425 "boo", |
| 2406 domain, path, now2, later, now2, false, false, false, | 2426 domain, path, now2, later, now2, false, false, false, |
| 2407 COOKIE_PRIORITY_DEFAULT); | 2427 COOKIE_PRIORITY_DEFAULT); |
| 2408 initial_cookies.push_back(cc); | 2428 initial_cookies.push_back(cc); |
| 2409 | 2429 |
| 2410 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); | 2430 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); |
| 2411 | 2431 |
| 2412 // Inject our initial cookies into the mock PersistentCookieStore. | 2432 // Inject our initial cookies into the mock PersistentCookieStore. |
| 2413 store->SetLoadExpectation(true, initial_cookies); | 2433 store->SetLoadExpectation(true, initial_cookies); |
| 2414 | 2434 |
| 2415 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2435 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2416 | 2436 |
| 2417 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2437 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
| 2418 } | 2438 } |
| 2419 | 2439 |
| 2420 // Test that cookie source schemes are histogrammed correctly. | 2440 // Test that cookie source schemes are histogrammed correctly. |
| 2421 TEST_F(CookieMonsterTest, CookieSourceHistogram) { | 2441 TEST_F(CookieMonsterTest, CookieSourceHistogram) { |
| 2422 base::HistogramTester histograms; | 2442 base::HistogramTester histograms; |
| 2423 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; | 2443 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; |
| 2424 | 2444 |
| 2425 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2445 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2426 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2446 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2427 | 2447 |
| 2428 histograms.ExpectTotalCount(cookie_source_histogram, 0); | 2448 histograms.ExpectTotalCount(cookie_source_histogram, 0); |
| 2429 | 2449 |
| 2430 // Set a secure cookie on a cryptographic scheme. | 2450 // Set a secure cookie on a cryptographic scheme. |
| 2431 EXPECT_TRUE( | 2451 EXPECT_TRUE( |
| 2432 SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure")); | 2452 SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure")); |
| 2433 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2453 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2434 histograms.ExpectBucketCount( | 2454 histograms.ExpectBucketCount( |
| 2435 cookie_source_histogram, | 2455 cookie_source_histogram, |
| 2436 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2456 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2483 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2503 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); |
| 2484 } | 2504 } |
| 2485 | 2505 |
| 2486 // Test that cookie delete equivalent histograms are recorded correctly when | 2506 // Test that cookie delete equivalent histograms are recorded correctly when |
| 2487 // strict secure cookies are not enabled. | 2507 // strict secure cookies are not enabled. |
| 2488 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { | 2508 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { |
| 2489 base::HistogramTester histograms; | 2509 base::HistogramTester histograms; |
| 2490 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 2510 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
| 2491 | 2511 |
| 2492 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2512 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2493 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2513 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2494 | 2514 |
| 2495 // Set a secure cookie from a secure origin | 2515 // Set a secure cookie from a secure origin |
| 2496 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 2516 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); |
| 2497 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2517 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2498 histograms.ExpectBucketCount(cookie_source_histogram, | 2518 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2499 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2519 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2500 1); | 2520 1); |
| 2501 | 2521 |
| 2502 // Set a new cookie with a different name from a variety of origins (including | 2522 // Set a new cookie with a different name from a variety of origins (including |
| 2503 // the same one). | 2523 // the same one). |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2548 // already existing cookie and is not equivalent. | 2568 // already existing cookie and is not equivalent. |
| 2549 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | 2569 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), |
| 2550 "A=E; secure; path=/some/other/path")); | 2570 "A=E; secure; path=/some/other/path")); |
| 2551 histograms.ExpectTotalCount(cookie_source_histogram, 9); | 2571 histograms.ExpectTotalCount(cookie_source_histogram, 9); |
| 2552 histograms.ExpectBucketCount(cookie_source_histogram, | 2572 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2553 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2573 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2554 7); | 2574 7); |
| 2555 } | 2575 } |
| 2556 | 2576 |
| 2557 TEST_F(CookieMonsterStrictSecureTest, SetSecureCookies) { | 2577 TEST_F(CookieMonsterStrictSecureTest, SetSecureCookies) { |
| 2558 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2578 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2559 GURL http_url("http://www.google.com"); | 2579 GURL http_url("http://www.google.com"); |
| 2560 GURL http_superdomain_url("http://google.com"); | 2580 GURL http_superdomain_url("http://google.com"); |
| 2561 GURL https_url("https://www.google.com"); | 2581 GURL https_url("https://www.google.com"); |
| 2562 | 2582 |
| 2563 // A non-secure cookie can be created from either a URL with a secure or | 2583 // A non-secure cookie can be created from either a URL with a secure or |
| 2564 // insecure scheme. | 2584 // insecure scheme. |
| 2565 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); | 2585 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); |
| 2566 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); | 2586 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); |
| 2567 | 2587 |
| 2568 // A secure cookie cannot be created from a URL with an insecure scheme. | 2588 // A secure cookie cannot be created from a URL with an insecure scheme. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2741 // global purge goal (3000), but the secure cookies are not evicted. | 2761 // global purge goal (3000), but the secure cookies are not evicted. |
| 2742 const CookiesEntry test14[] = {{1U, true}}; | 2762 const CookiesEntry test14[] = {{1U, true}}; |
| 2743 const AltHosts test14_alt_hosts(1500, 1800); | 2763 const AltHosts test14_alt_hosts(1500, 1800); |
| 2744 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, | 2764 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, |
| 2745 &test14_alt_hosts); | 2765 &test14_alt_hosts); |
| 2746 } | 2766 } |
| 2747 | 2767 |
| 2748 // Tests that strict secure cookies doesn't trip equivalent cookie checks | 2768 // Tests that strict secure cookies doesn't trip equivalent cookie checks |
| 2749 // accidentally. Regression test for https://crbug.com/569943. | 2769 // accidentally. Regression test for https://crbug.com/569943. |
| 2750 TEST_F(CookieMonsterStrictSecureTest, EquivalentCookies) { | 2770 TEST_F(CookieMonsterStrictSecureTest, EquivalentCookies) { |
| 2751 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2771 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2752 GURL http_url("http://www.google.com"); | 2772 GURL http_url("http://www.google.com"); |
| 2753 GURL http_superdomain_url("http://google.com"); | 2773 GURL http_superdomain_url("http://google.com"); |
| 2754 GURL https_url("https://www.google.com"); | 2774 GURL https_url("https://www.google.com"); |
| 2755 | 2775 |
| 2756 // Tests that non-equivalent cookies because of the path attribute can be set | 2776 // Tests that non-equivalent cookies because of the path attribute can be set |
| 2757 // successfully. | 2777 // successfully. |
| 2758 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 2778 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 2759 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); | 2779 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); |
| 2760 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); | 2780 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); |
| 2761 | 2781 |
| 2762 // Tests that non-equivalent cookies because of the domain attribute can be | 2782 // Tests that non-equivalent cookies because of the domain attribute can be |
| 2763 // set successfully. | 2783 // set successfully. |
| 2764 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 2784 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 2765 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); | 2785 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); |
| 2766 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); | 2786 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); |
| 2767 } | 2787 } |
| 2768 | 2788 |
| 2769 // Test that cookie delete equivalent histograms are recorded correctly for | 2789 // Test that cookie delete equivalent histograms are recorded correctly for |
| 2770 // strict secure cookies. | 2790 // strict secure cookies. |
| 2771 TEST_F(CookieMonsterStrictSecureTest, CookieDeleteEquivalentHistogramTest) { | 2791 TEST_F(CookieMonsterStrictSecureTest, CookieDeleteEquivalentHistogramTest) { |
| 2772 base::HistogramTester histograms; | 2792 base::HistogramTester histograms; |
| 2773 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 2793 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
| 2774 | 2794 |
| 2775 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2795 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2776 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2796 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2777 | 2797 |
| 2778 // Set a secure cookie from a secure origin | 2798 // Set a secure cookie from a secure origin |
| 2779 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 2799 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); |
| 2780 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2800 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2781 histograms.ExpectBucketCount(cookie_source_histogram, | 2801 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2782 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2802 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2783 1); | 2803 1); |
| 2784 | 2804 |
| 2785 // Set a new cookie with a different name from a variety of origins (including | 2805 // Set a new cookie with a different name from a variety of origins (including |
| 2786 // the same one). | 2806 // the same one). |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2841 histograms.ExpectBucketCount(cookie_source_histogram, | 2861 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2842 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2862 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2843 7); | 2863 7); |
| 2844 } | 2864 } |
| 2845 | 2865 |
| 2846 class CookieMonsterNotificationTest : public CookieMonsterTest { | 2866 class CookieMonsterNotificationTest : public CookieMonsterTest { |
| 2847 public: | 2867 public: |
| 2848 CookieMonsterNotificationTest() | 2868 CookieMonsterNotificationTest() |
| 2849 : test_url_("http://www.google.com/foo"), | 2869 : test_url_("http://www.google.com/foo"), |
| 2850 store_(new MockPersistentCookieStore), | 2870 store_(new MockPersistentCookieStore), |
| 2851 monster_(new CookieMonster(store_.get(), NULL)) {} | 2871 monster_(new CookieMonster(store_.get(), nullptr)) {} |
| 2852 | 2872 |
| 2853 ~CookieMonsterNotificationTest() override {} | 2873 ~CookieMonsterNotificationTest() override {} |
| 2854 | 2874 |
| 2855 CookieMonster* monster() { return monster_.get(); } | 2875 CookieMonster* monster() { return monster_.get(); } |
| 2856 | 2876 |
| 2857 protected: | 2877 protected: |
| 2858 const GURL test_url_; | 2878 const GURL test_url_; |
| 2859 | 2879 |
| 2860 private: | 2880 private: |
| 2861 scoped_refptr<MockPersistentCookieStore> store_; | 2881 scoped_refptr<MockPersistentCookieStore> store_; |
| 2862 scoped_refptr<CookieMonster> monster_; | 2882 scoped_ptr<CookieMonster> monster_; |
| 2863 }; | 2883 }; |
| 2864 | 2884 |
| 2865 void RecordCookieChanges(std::vector<CanonicalCookie>* out_cookies, | 2885 void RecordCookieChanges(std::vector<CanonicalCookie>* out_cookies, |
| 2866 std::vector<bool>* out_removes, | 2886 std::vector<bool>* out_removes, |
| 2867 const CanonicalCookie& cookie, | 2887 const CanonicalCookie& cookie, |
| 2868 bool removed) { | 2888 bool removed) { |
| 2869 DCHECK(out_cookies); | 2889 DCHECK(out_cookies); |
| 2870 out_cookies->push_back(cookie); | 2890 out_cookies->push_back(cookie); |
| 2871 if (out_removes) | 2891 if (out_removes) |
| 2872 out_removes->push_back(removed); | 2892 out_removes->push_back(removed); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2993 monster()->AddCallbackForCookie( | 3013 monster()->AddCallbackForCookie( |
| 2994 test_url_, "abc", | 3014 test_url_, "abc", |
| 2995 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3015 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 2996 SetCookie(monster(), test_url_, "abc=def"); | 3016 SetCookie(monster(), test_url_, "abc=def"); |
| 2997 base::MessageLoop::current()->RunUntilIdle(); | 3017 base::MessageLoop::current()->RunUntilIdle(); |
| 2998 EXPECT_EQ(1U, cookies0.size()); | 3018 EXPECT_EQ(1U, cookies0.size()); |
| 2999 EXPECT_EQ(1U, cookies0.size()); | 3019 EXPECT_EQ(1U, cookies0.size()); |
| 3000 } | 3020 } |
| 3001 | 3021 |
| 3002 } // namespace net | 3022 } // namespace net |
| OLD | NEW |