| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 // of cookies to create. Cookies are created in the order they appear in | 470 // of cookies to create. Cookies are created in the order they appear in |
| 471 // cookie_entries. The value of cookie_entries[x].num_cookies specifies how | 471 // cookie_entries. The value of cookie_entries[x].num_cookies specifies how |
| 472 // many cookies of that type to create consecutively, while if | 472 // many cookies of that type to create consecutively, while if |
| 473 // cookie_entries[x].is_secure is |true|, those cookies will be marke as | 473 // cookie_entries[x].is_secure is |true|, those cookies will be marke as |
| 474 // Secure. | 474 // Secure. |
| 475 void TestSecureCookieEviction(const CookiesEntry* cookie_entries, | 475 void TestSecureCookieEviction(const CookiesEntry* cookie_entries, |
| 476 size_t num_cookie_entries, | 476 size_t num_cookie_entries, |
| 477 size_t expected_secure_cookies, | 477 size_t expected_secure_cookies, |
| 478 size_t expected_non_secure_cookies, | 478 size_t expected_non_secure_cookies, |
| 479 const AltHosts* alt_host_entries) { | 479 const AltHosts* alt_host_entries) { |
| 480 scoped_refptr<CookieMonster> cm; | 480 scoped_ptr<CookieMonster> cm; |
| 481 | 481 |
| 482 if (alt_host_entries == nullptr) { | 482 if (alt_host_entries == nullptr) { |
| 483 cm = new CookieMonster(nullptr, nullptr); | 483 cm.reset(new CookieMonster(nullptr, nullptr)); |
| 484 } else { | 484 } else { |
| 485 // When generating all of these cookies on alternate hosts, they need to | 485 // When generating all of these cookies on alternate hosts, they need to |
| 486 // be all older than the max "safe" date for GC, which is currently 30 | 486 // be all older than the max "safe" date for GC, which is currently 30 |
| 487 // days, so we set them to 60. | 487 // days, so we set them to 60. |
| 488 cm = CreateMonsterFromStoreForGC( | 488 cm = CreateMonsterFromStoreForGC( |
| 489 alt_host_entries->first, alt_host_entries->first, | 489 alt_host_entries->first, alt_host_entries->first, |
| 490 alt_host_entries->second, alt_host_entries->second, 60); | 490 alt_host_entries->second, alt_host_entries->second, 60); |
| 491 } | 491 } |
| 492 | 492 |
| 493 int next_cookie_id = 0; | 493 int next_cookie_id = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 518 EXPECT_EQ(expected_secure_cookies, total_secure_cookies); | 518 EXPECT_EQ(expected_secure_cookies, total_secure_cookies); |
| 519 EXPECT_EQ(expected_non_secure_cookies, total_non_secure_cookies); | 519 EXPECT_EQ(expected_non_secure_cookies, total_non_secure_cookies); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void TestPriorityAwareGarbageCollectHelperNonSecure() { | 522 void TestPriorityAwareGarbageCollectHelperNonSecure() { |
| 523 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 523 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
| 524 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 524 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
| 525 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 525 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
| 526 CookieMonster::kDomainPurgeCookies); | 526 CookieMonster::kDomainPurgeCookies); |
| 527 | 527 |
| 528 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 528 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 529 | 529 |
| 530 // Each test case adds 181 cookies, so 31 cookies are evicted. | 530 // Each test case adds 181 cookies, so 31 cookies are evicted. |
| 531 // Cookie same priority, repeated for each priority. | 531 // Cookie same priority, repeated for each priority. |
| 532 TestPriorityCookieCase(cm.get(), "181LN", 150U, 0U, 0U, 150U, 0U); | 532 TestPriorityCookieCase(cm.get(), "181LN", 150U, 0U, 0U, 150U, 0U); |
| 533 TestPriorityCookieCase(cm.get(), "181MN", 0U, 150U, 0U, 150U, 0U); | 533 TestPriorityCookieCase(cm.get(), "181MN", 0U, 150U, 0U, 150U, 0U); |
| 534 TestPriorityCookieCase(cm.get(), "181HN", 0U, 0U, 150U, 150U, 0U); | 534 TestPriorityCookieCase(cm.get(), "181HN", 0U, 0U, 150U, 150U, 0U); |
| 535 | 535 |
| 536 // Pairwise scenarios. | 536 // Pairwise scenarios. |
| 537 // Round 1 => none; round2 => 31M; round 3 => none. | 537 // Round 1 => none; round2 => 31M; round 3 => none. |
| 538 TestPriorityCookieCase(cm.get(), "10HN 171MN", 0U, 140U, 10U, 150U, 0U); | 538 TestPriorityCookieCase(cm.get(), "10HN 171MN", 0U, 140U, 10U, 150U, 0U); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 TestPriorityCookieCase(cm.get(), "11MN 10HN 10LN 90MN 60HN", 0U, 80U, 70U, | 572 TestPriorityCookieCase(cm.get(), "11MN 10HN 10LN 90MN 60HN", 0U, 80U, 70U, |
| 573 150U, 0U); | 573 150U, 0U); |
| 574 } | 574 } |
| 575 | 575 |
| 576 void TestPriorityAwareGarbageCollectHelperSecure() { | 576 void TestPriorityAwareGarbageCollectHelperSecure() { |
| 577 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 577 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
| 578 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 578 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
| 579 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 579 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
| 580 CookieMonster::kDomainPurgeCookies); | 580 CookieMonster::kDomainPurgeCookies); |
| 581 | 581 |
| 582 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 582 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 583 | 583 |
| 584 // Each test case adds 181 cookies, so 31 cookies are evicted. | 584 // Each test case adds 181 cookies, so 31 cookies are evicted. |
| 585 // Cookie same priority, repeated for each priority. | 585 // Cookie same priority, repeated for each priority. |
| 586 TestPriorityCookieCase(cm.get(), "181LS", 150U, 0U, 0U, 0U, 150U); | 586 TestPriorityCookieCase(cm.get(), "181LS", 150U, 0U, 0U, 0U, 150U); |
| 587 TestPriorityCookieCase(cm.get(), "181MS", 0U, 150U, 0U, 0U, 150U); | 587 TestPriorityCookieCase(cm.get(), "181MS", 0U, 150U, 0U, 0U, 150U); |
| 588 TestPriorityCookieCase(cm.get(), "181HS", 0U, 0U, 150U, 0U, 150U); | 588 TestPriorityCookieCase(cm.get(), "181HS", 0U, 0U, 150U, 0U, 150U); |
| 589 | 589 |
| 590 // Pairwise scenarios. | 590 // Pairwise scenarios. |
| 591 // Round 1 => none; round2 => 31M; round 3 => none. | 591 // Round 1 => none; round2 => 31M; round 3 => none. |
| 592 TestPriorityCookieCase(cm.get(), "10HS 171MS", 0U, 140U, 10U, 0U, 150U); | 592 TestPriorityCookieCase(cm.get(), "10HS 171MS", 0U, 140U, 10U, 0U, 150U); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 90MS 60HS", 0U, 80U, 70U, | 626 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 90MS 60HS", 0U, 80U, 70U, |
| 627 0U, 150U); | 627 0U, 150U); |
| 628 } | 628 } |
| 629 | 629 |
| 630 void TestPriorityAwareGarbageCollectHelperMixed() { | 630 void TestPriorityAwareGarbageCollectHelperMixed() { |
| 631 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 631 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
| 632 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 632 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
| 633 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 633 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
| 634 CookieMonster::kDomainPurgeCookies); | 634 CookieMonster::kDomainPurgeCookies); |
| 635 | 635 |
| 636 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 636 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 637 | 637 |
| 638 // Each test case adds 180 secure cookies, and some non-secure cookie. The | 638 // Each test case adds 180 secure cookies, and some non-secure cookie. The |
| 639 // secure cookies take priority, so the non-secure cookie is removed, along | 639 // secure cookies take priority, so the non-secure cookie is removed, along |
| 640 // with 30 secure cookies. Repeated for each priority, and with the | 640 // with 30 secure cookies. Repeated for each priority, and with the |
| 641 // non-secure cookie as older and newer. | 641 // non-secure cookie as older and newer. |
| 642 TestPriorityCookieCase(cm.get(), "1LN 180LS", 150U, 0U, 0U, 0U, 150U); | 642 TestPriorityCookieCase(cm.get(), "1LN 180LS", 150U, 0U, 0U, 0U, 150U); |
| 643 TestPriorityCookieCase(cm.get(), "1MN 180MS", 0U, 150U, 0U, 0U, 150U); | 643 TestPriorityCookieCase(cm.get(), "1MN 180MS", 0U, 150U, 0U, 0U, 150U); |
| 644 TestPriorityCookieCase(cm.get(), "1HN 180HS", 0U, 0U, 150U, 0U, 150U); | 644 TestPriorityCookieCase(cm.get(), "1HN 180HS", 0U, 0U, 150U, 0U, 150U); |
| 645 TestPriorityCookieCase(cm.get(), "180LS 1LN", 150U, 0U, 0U, 0U, 150U); | 645 TestPriorityCookieCase(cm.get(), "180LS 1LN", 150U, 0U, 0U, 0U, 150U); |
| 646 TestPriorityCookieCase(cm.get(), "180MS 1MN", 0U, 150U, 0U, 0U, 150U); | 646 TestPriorityCookieCase(cm.get(), "180MS 1MN", 0U, 150U, 0U, 0U, 150U); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 // Specifically, for each asynchronous method, verify that: | 843 // Specifically, for each asynchronous method, verify that: |
| 844 // 1. invoking it on an uninitialized cookie store causes the store to begin | 844 // 1. invoking it on an uninitialized cookie store causes the store to begin |
| 845 // chain-loading its backing data or loading data for a specific domain key | 845 // chain-loading its backing data or loading data for a specific domain key |
| 846 // (eTLD+1). | 846 // (eTLD+1). |
| 847 // 2. The initial invocation does not complete until the loading completes. | 847 // 2. The initial invocation does not complete until the loading completes. |
| 848 // 3. Invocations after the loading has completed complete immediately. | 848 // 3. Invocations after the loading has completed complete immediately. |
| 849 class DeferredCookieTaskTest : public CookieMonsterTest { | 849 class DeferredCookieTaskTest : public CookieMonsterTest { |
| 850 protected: | 850 protected: |
| 851 DeferredCookieTaskTest() : expect_load_called_(false) { | 851 DeferredCookieTaskTest() : expect_load_called_(false) { |
| 852 persistent_store_ = new NewMockPersistentCookieStore(); | 852 persistent_store_ = new NewMockPersistentCookieStore(); |
| 853 cookie_monster_ = new CookieMonster(persistent_store_.get(), NULL); | 853 cookie_monster_.reset(new CookieMonster(persistent_store_.get(), nullptr)); |
| 854 } | 854 } |
| 855 | 855 |
| 856 // Defines a cookie to be returned from PersistentCookieStore::Load | 856 // Defines a cookie to be returned from PersistentCookieStore::Load |
| 857 void DeclareLoadedCookie(const std::string& key, | 857 void DeclareLoadedCookie(const std::string& key, |
| 858 const std::string& cookie_line, | 858 const std::string& cookie_line, |
| 859 const base::Time& creation_time) { | 859 const base::Time& creation_time) { |
| 860 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_); | 860 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_); |
| 861 } | 861 } |
| 862 | 862 |
| 863 // Runs the message loop, waiting until PersistentCookieStore::Load is called. | 863 // Runs the message loop, waiting until PersistentCookieStore::Load is called. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; | 932 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; |
| 933 // Stores the callback passed from the CookieMonster to the | 933 // Stores the callback passed from the CookieMonster to the |
| 934 // PersistentCookieStore::LoadCookiesForKey | 934 // PersistentCookieStore::LoadCookiesForKey |
| 935 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> | 935 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> |
| 936 loaded_for_key_callbacks_; | 936 loaded_for_key_callbacks_; |
| 937 // base::RunLoop used to wait for PersistentCookieStore::Load to be called. | 937 // base::RunLoop used to wait for PersistentCookieStore::Load to be called. |
| 938 base::RunLoop load_run_loop_; | 938 base::RunLoop load_run_loop_; |
| 939 // Indicates whether ExpectLoadCall() has been called. | 939 // Indicates whether ExpectLoadCall() has been called. |
| 940 bool expect_load_called_; | 940 bool expect_load_called_; |
| 941 // Stores the CookieMonster under test. | 941 // Stores the CookieMonster under test. |
| 942 scoped_refptr<CookieMonster> cookie_monster_; | 942 scoped_ptr<CookieMonster> cookie_monster_; |
| 943 // Stores the mock PersistentCookieStore. | 943 // Stores the mock PersistentCookieStore. |
| 944 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; | 944 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; |
| 945 }; | 945 }; |
| 946 | 946 |
| 947 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { | 947 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { |
| 948 DeclareLoadedCookie(http_www_google_.host(), | 948 DeclareLoadedCookie(http_www_google_.host(), |
| 949 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 949 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 950 Time::Now() + TimeDelta::FromDays(3)); | 950 Time::Now() + TimeDelta::FromDays(3)); |
| 951 | 951 |
| 952 MockGetCookiesCallback get_cookies_callback; | 952 MockGetCookiesCallback get_cookies_callback; |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 base::RunLoop loop; | 1275 base::RunLoop loop; |
| 1276 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) | 1276 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) |
| 1277 .WillOnce(QuitRunLoop(&loop)); | 1277 .WillOnce(QuitRunLoop(&loop)); |
| 1278 | 1278 |
| 1279 CompleteLoading(); | 1279 CompleteLoading(); |
| 1280 loop.Run(); | 1280 loop.Run(); |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { | 1283 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { |
| 1284 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1284 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1285 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1285 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1286 CookieOptions options; | 1286 CookieOptions options; |
| 1287 options.set_include_httponly(); | 1287 options.set_include_httponly(); |
| 1288 | 1288 |
| 1289 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); | 1289 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); |
| 1290 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1290 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 1291 | 1291 |
| 1292 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1292 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
| 1293 "C=D; httponly", options)); | 1293 "C=D; httponly", options)); |
| 1294 EXPECT_EQ("A=B; C=D", | 1294 EXPECT_EQ("A=B; C=D", |
| 1295 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1295 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1308 | 1308 |
| 1309 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. | 1309 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. |
| 1310 ASSERT_EQ(2u, store->commands().size()); | 1310 ASSERT_EQ(2u, store->commands().size()); |
| 1311 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1311 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1312 | 1312 |
| 1313 EXPECT_EQ("", | 1313 EXPECT_EQ("", |
| 1314 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); | 1314 GetCookiesWithOptions(cm.get(), http_www_google_.url(), options)); |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1317 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 1318 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1318 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1319 Time now = Time::Now(); | 1319 Time now = Time::Now(); |
| 1320 | 1320 |
| 1321 // Nothing has been added so nothing should be deleted. | 1321 // Nothing has been added so nothing should be deleted. |
| 1322 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), | 1322 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
| 1323 Time())); | 1323 Time())); |
| 1324 | 1324 |
| 1325 // Create 3 cookies with creation date of today, yesterday and the day before. | 1325 // Create 3 cookies with creation date of today, yesterday and the day before. |
| 1326 EXPECT_TRUE( | 1326 EXPECT_TRUE( |
| 1327 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); | 1327 cm->SetCookieWithCreationTime(http_www_google_.url(), "T-0=Now", now)); |
| 1328 EXPECT_TRUE(cm->SetCookieWithCreationTime( | 1328 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1350 // Delete the last (now) item. | 1350 // Delete the last (now) item. |
| 1351 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); | 1351 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time())); |
| 1352 | 1352 |
| 1353 // Really make sure everything is gone. | 1353 // Really make sure everything is gone. |
| 1354 EXPECT_EQ(0, DeleteAll(cm.get())); | 1354 EXPECT_EQ(0, DeleteAll(cm.get())); |
| 1355 } | 1355 } |
| 1356 | 1356 |
| 1357 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; | 1357 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; |
| 1358 | 1358 |
| 1359 TEST_F(CookieMonsterTest, TestLastAccess) { | 1359 TEST_F(CookieMonsterTest, TestLastAccess) { |
| 1360 scoped_refptr<CookieMonster> cm( | 1360 scoped_ptr<CookieMonster> cm( |
| 1361 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 1361 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); |
| 1362 | 1362 |
| 1363 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1363 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
| 1364 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1364 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
| 1365 | 1365 |
| 1366 // Reading the cookie again immediately shouldn't update the access date, | 1366 // Reading the cookie again immediately shouldn't update the access date, |
| 1367 // since we're inside the threshold. | 1367 // since we're inside the threshold. |
| 1368 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 1368 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 1369 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1369 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1370 | 1370 |
| 1371 // Reading after a short wait will update the access date, if the cookie | 1371 // Reading after a short wait will update the access date, if the cookie |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 | 1406 |
| 1407 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionSecure) { | 1407 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionSecure) { |
| 1408 TestPriorityAwareGarbageCollectHelperSecure(); | 1408 TestPriorityAwareGarbageCollectHelperSecure(); |
| 1409 } | 1409 } |
| 1410 | 1410 |
| 1411 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionMixed) { | 1411 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionMixed) { |
| 1412 TestPriorityAwareGarbageCollectHelperMixed(); | 1412 TestPriorityAwareGarbageCollectHelperMixed(); |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 TEST_F(CookieMonsterTest, SetCookieableSchemes) { | 1415 TEST_F(CookieMonsterTest, SetCookieableSchemes) { |
| 1416 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1416 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1417 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); | 1417 scoped_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, nullptr)); |
| 1418 | 1418 |
| 1419 // Only cm_foo should allow foo:// cookies. | 1419 // Only cm_foo should allow foo:// cookies. |
| 1420 std::vector<std::string> schemes; | 1420 std::vector<std::string> schemes; |
| 1421 schemes.push_back("foo"); | 1421 schemes.push_back("foo"); |
| 1422 cm_foo->SetCookieableSchemes(schemes); | 1422 cm_foo->SetCookieableSchemes(schemes); |
| 1423 | 1423 |
| 1424 GURL foo_url("foo://host/path"); | 1424 GURL foo_url("foo://host/path"); |
| 1425 GURL http_url("http://host/path"); | 1425 GURL http_url("http://host/path"); |
| 1426 | 1426 |
| 1427 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); | 1427 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1")); |
| 1428 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); | 1428 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1")); |
| 1429 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); | 1429 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1")); |
| 1430 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); | 1430 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1")); |
| 1431 } | 1431 } |
| 1432 | 1432 |
| 1433 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { | 1433 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { |
| 1434 scoped_refptr<CookieMonster> cm( | 1434 scoped_ptr<CookieMonster> cm( |
| 1435 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 1435 new CookieMonster(nullptr, nullptr, kLastAccessThresholdMilliseconds)); |
| 1436 | 1436 |
| 1437 // Create an httponly cookie. | 1437 // Create an httponly cookie. |
| 1438 CookieOptions options; | 1438 CookieOptions options; |
| 1439 options.set_include_httponly(); | 1439 options.set_include_httponly(); |
| 1440 | 1440 |
| 1441 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1441 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
| 1442 "A=B; httponly", options)); | 1442 "A=B; httponly", options)); |
| 1443 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1443 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
| 1444 http_www_google_.Format("C=D; domain=.%D"), | 1444 http_www_google_.Format("C=D; domain=.%D"), |
| 1445 options)); | 1445 options)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); | 1493 EXPECT_EQ(http_www_google_.Format(".%D"), it->Domain()); |
| 1494 EXPECT_EQ("E", it->Name()); | 1494 EXPECT_EQ("E", it->Name()); |
| 1495 | 1495 |
| 1496 ASSERT_TRUE(++it == cookies.end()); | 1496 ASSERT_TRUE(++it == cookies.end()); |
| 1497 | 1497 |
| 1498 // Reading after a short wait should not update the access date. | 1498 // Reading after a short wait should not update the access date. |
| 1499 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); | 1499 EXPECT_EQ(last_access_date, GetFirstCookieAccessDate(cm.get())); |
| 1500 } | 1500 } |
| 1501 | 1501 |
| 1502 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { | 1502 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { |
| 1503 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1503 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1504 CookieOptions options; | 1504 CookieOptions options; |
| 1505 | 1505 |
| 1506 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(), | 1506 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_foo_.url(), |
| 1507 "A=B; path=/foo;", options)); | 1507 "A=B; path=/foo;", options)); |
| 1508 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(), | 1508 EXPECT_TRUE(SetCookieWithOptions(cm.get(), www_google_bar_.url(), |
| 1509 "C=D; path=/bar;", options)); | 1509 "C=D; path=/bar;", options)); |
| 1510 EXPECT_TRUE( | 1510 EXPECT_TRUE( |
| 1511 SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options)); | 1511 SetCookieWithOptions(cm.get(), http_www_google_.url(), "E=F;", options)); |
| 1512 | 1512 |
| 1513 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url()); | 1513 CookieList cookies = GetAllCookiesForURL(cm.get(), www_google_foo_.url()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1531 EXPECT_EQ("/bar", it->Path()); | 1531 EXPECT_EQ("/bar", it->Path()); |
| 1532 | 1532 |
| 1533 ASSERT_TRUE(++it != cookies.end()); | 1533 ASSERT_TRUE(++it != cookies.end()); |
| 1534 EXPECT_EQ("E", it->Name()); | 1534 EXPECT_EQ("E", it->Name()); |
| 1535 EXPECT_EQ("/", it->Path()); | 1535 EXPECT_EQ("/", it->Path()); |
| 1536 | 1536 |
| 1537 ASSERT_TRUE(++it == cookies.end()); | 1537 ASSERT_TRUE(++it == cookies.end()); |
| 1538 } | 1538 } |
| 1539 | 1539 |
| 1540 TEST_F(CookieMonsterTest, CookieSorting) { | 1540 TEST_F(CookieMonsterTest, CookieSorting) { |
| 1541 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1541 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1542 | 1542 |
| 1543 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); | 1543 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); |
| 1544 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); | 1544 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); |
| 1545 EXPECT_TRUE( | 1545 EXPECT_TRUE( |
| 1546 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); | 1546 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); |
| 1547 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); | 1547 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); |
| 1548 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); | 1548 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); |
| 1549 EXPECT_TRUE( | 1549 EXPECT_TRUE( |
| 1550 SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar")); | 1550 SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/foo/bar")); |
| 1551 | 1551 |
| 1552 // Re-set cookie which should not change sort order. | 1552 // Re-set cookie which should not change sort order. |
| 1553 EXPECT_TRUE( | 1553 EXPECT_TRUE( |
| 1554 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); | 1554 SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/foo/bar")); |
| 1555 | 1555 |
| 1556 CookieList cookies = GetAllCookies(cm.get()); | 1556 CookieList cookies = GetAllCookies(cm.get()); |
| 1557 ASSERT_EQ(6u, cookies.size()); | 1557 ASSERT_EQ(6u, cookies.size()); |
| 1558 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the | 1558 // According to RFC 6265 5.3 (11) re-setting this cookie should retain the |
| 1559 // initial creation-time from above, and the sort order should not change. | 1559 // initial creation-time from above, and the sort order should not change. |
| 1560 // Chrome's current implementation deviates from the spec so capturing this to | 1560 // Chrome's current implementation deviates from the spec so capturing this to |
| 1561 // avoid any inadvertent changes to this behavior. | 1561 // avoid any inadvertent changes to this behavior. |
| 1562 EXPECT_EQ("A3", cookies[0].Value()); | 1562 EXPECT_EQ("A3", cookies[0].Value()); |
| 1563 EXPECT_EQ("B3", cookies[1].Value()); | 1563 EXPECT_EQ("B3", cookies[1].Value()); |
| 1564 EXPECT_EQ("B2", cookies[2].Value()); | 1564 EXPECT_EQ("B2", cookies[2].Value()); |
| 1565 EXPECT_EQ("A2", cookies[3].Value()); | 1565 EXPECT_EQ("A2", cookies[3].Value()); |
| 1566 EXPECT_EQ("B1", cookies[4].Value()); | 1566 EXPECT_EQ("B1", cookies[4].Value()); |
| 1567 EXPECT_EQ("A1", cookies[5].Value()); | 1567 EXPECT_EQ("A1", cookies[5].Value()); |
| 1568 } | 1568 } |
| 1569 | 1569 |
| 1570 TEST_F(CookieMonsterTest, DeleteCookieByName) { | 1570 TEST_F(CookieMonsterTest, DeleteCookieByName) { |
| 1571 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1571 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1572 | 1572 |
| 1573 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); | 1573 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A1; path=/")); |
| 1574 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); | 1574 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A2; path=/foo")); |
| 1575 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/bar")); | 1575 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=A3; path=/bar")); |
| 1576 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); | 1576 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B1; path=/")); |
| 1577 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); | 1577 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B2; path=/foo")); |
| 1578 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/bar")); | 1578 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "B=B3; path=/bar")); |
| 1579 | 1579 |
| 1580 DeleteCookie(cm.get(), http_www_google_.AppendPath("foo/bar"), "A"); | 1580 DeleteCookie(cm.get(), http_www_google_.AppendPath("foo/bar"), "A"); |
| 1581 | 1581 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); | 1637 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); |
| 1638 | 1638 |
| 1639 // Insert 1 cookie with name "Y" on path "/". | 1639 // Insert 1 cookie with name "Y" on path "/". |
| 1640 AddCookieToList("www.google.com", | 1640 AddCookieToList("www.google.com", |
| 1641 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1641 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1642 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); | 1642 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); |
| 1643 | 1643 |
| 1644 // Inject our initial cookies into the mock PersistentCookieStore. | 1644 // Inject our initial cookies into the mock PersistentCookieStore. |
| 1645 store->SetLoadExpectation(true, initial_cookies); | 1645 store->SetLoadExpectation(true, initial_cookies); |
| 1646 | 1646 |
| 1647 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1647 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1648 | 1648 |
| 1649 // Verify that duplicates were not imported for path "/". | 1649 // Verify that duplicates were not imported for path "/". |
| 1650 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). | 1650 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). |
| 1651 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); | 1651 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); |
| 1652 | 1652 |
| 1653 // Verify that same-named cookie on a different path ("/x2") didn't get | 1653 // Verify that same-named cookie on a different path ("/x2") didn't get |
| 1654 // messed up. | 1654 // messed up. |
| 1655 EXPECT_EQ("X=a1; X=3; Y=a", | 1655 EXPECT_EQ("X=a1; X=3; Y=a", |
| 1656 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); | 1656 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); |
| 1657 | 1657 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1685 AddCookieToList("www.google.com", "X=4; path=/", now, &initial_cookies); | 1685 AddCookieToList("www.google.com", "X=4; path=/", now, &initial_cookies); |
| 1686 | 1686 |
| 1687 AddCookieToList("www.google.com", "Y=1; path=/", earlier, &initial_cookies); | 1687 AddCookieToList("www.google.com", "Y=1; path=/", earlier, &initial_cookies); |
| 1688 AddCookieToList("www.google.com", "Y=2; path=/", earlier, &initial_cookies); | 1688 AddCookieToList("www.google.com", "Y=2; path=/", earlier, &initial_cookies); |
| 1689 AddCookieToList("www.google.com", "Y=3; path=/", earlier, &initial_cookies); | 1689 AddCookieToList("www.google.com", "Y=3; path=/", earlier, &initial_cookies); |
| 1690 AddCookieToList("www.google.com", "Y=4; path=/", earlier, &initial_cookies); | 1690 AddCookieToList("www.google.com", "Y=4; path=/", earlier, &initial_cookies); |
| 1691 | 1691 |
| 1692 // Inject our initial cookies into the mock PersistentCookieStore. | 1692 // Inject our initial cookies into the mock PersistentCookieStore. |
| 1693 store->SetLoadExpectation(true, initial_cookies); | 1693 store->SetLoadExpectation(true, initial_cookies); |
| 1694 | 1694 |
| 1695 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1695 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 1696 | 1696 |
| 1697 CookieList list(GetAllCookies(cm.get())); | 1697 CookieList list(GetAllCookies(cm.get())); |
| 1698 EXPECT_EQ(2U, list.size()); | 1698 EXPECT_EQ(2U, list.size()); |
| 1699 // Confirm that we have one of each. | 1699 // Confirm that we have one of each. |
| 1700 std::string name1(list[0].Name()); | 1700 std::string name1(list[0].Name()); |
| 1701 std::string name2(list[1].Name()); | 1701 std::string name2(list[1].Name()); |
| 1702 EXPECT_TRUE(name1 == "X" || name2 == "X"); | 1702 EXPECT_TRUE(name1 == "X" || name2 == "X"); |
| 1703 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); | 1703 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); |
| 1704 EXPECT_NE(name1, name2); | 1704 EXPECT_NE(name1, name2); |
| 1705 } | 1705 } |
| 1706 | 1706 |
| 1707 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { | 1707 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { |
| 1708 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1708 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1709 scoped_refptr<MockCookieMonsterDelegate> delegate( | 1709 scoped_refptr<MockCookieMonsterDelegate> delegate( |
| 1710 new MockCookieMonsterDelegate); | 1710 new MockCookieMonsterDelegate); |
| 1711 scoped_refptr<CookieMonster> cm( | 1711 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), delegate.get())); |
| 1712 new CookieMonster(store.get(), delegate.get())); | |
| 1713 | 1712 |
| 1714 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 1713 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
| 1715 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D")); | 1714 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=D")); |
| 1716 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F")); | 1715 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "E=F")); |
| 1717 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url())); | 1716 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), http_www_google_.url())); |
| 1718 ASSERT_EQ(3u, delegate->changes().size()); | 1717 ASSERT_EQ(3u, delegate->changes().size()); |
| 1719 EXPECT_FALSE(delegate->changes()[0].second); | 1718 EXPECT_FALSE(delegate->changes()[0].second); |
| 1720 EXPECT_EQ(http_www_google_.url().host(), | 1719 EXPECT_EQ(http_www_google_.url().host(), |
| 1721 delegate->changes()[0].first.Domain()); | 1720 delegate->changes()[0].first.Domain()); |
| 1722 EXPECT_EQ("A", delegate->changes()[0].first.Name()); | 1721 EXPECT_EQ("A", delegate->changes()[0].first.Name()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 1780 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1782 EXPECT_EQ(http_www_google_.url().host(), | 1781 EXPECT_EQ(http_www_google_.url().host(), |
| 1783 delegate->changes()[1].first.Domain()); | 1782 delegate->changes()[1].first.Domain()); |
| 1784 EXPECT_FALSE(delegate->changes()[1].second); | 1783 EXPECT_FALSE(delegate->changes()[1].second); |
| 1785 EXPECT_EQ("a", delegate->changes()[1].first.Name()); | 1784 EXPECT_EQ("a", delegate->changes()[1].first.Name()); |
| 1786 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); | 1785 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); |
| 1787 delegate->reset(); | 1786 delegate->reset(); |
| 1788 } | 1787 } |
| 1789 | 1788 |
| 1790 TEST_F(CookieMonsterTest, DeleteAllForHost) { | 1789 TEST_F(CookieMonsterTest, DeleteAllForHost) { |
| 1791 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1790 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1792 | 1791 |
| 1793 // Test probes: | 1792 // Test probes: |
| 1794 // * Non-secure URL, mid-level (http://w.c.b.a) | 1793 // * Non-secure URL, mid-level (http://w.c.b.a) |
| 1795 // * Secure URL, mid-level (https://w.c.b.a) | 1794 // * Secure URL, mid-level (https://w.c.b.a) |
| 1796 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx) | 1795 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx) |
| 1797 // All three tests should nuke only the midlevel host cookie, | 1796 // All three tests should nuke only the midlevel host cookie, |
| 1798 // the http_only cookie, the host secure cookie, and the two host | 1797 // the http_only cookie, the host secure cookie, and the two host |
| 1799 // path cookies. http_only, secure, and paths are ignored by | 1798 // path cookies. http_only, secure, and paths are ignored by |
| 1800 // this call, and domain cookies arent touched. | 1799 // this call, and domain cookies arent touched. |
| 1801 PopulateCmForDeleteAllForHost(cm); | 1800 PopulateCmForDeleteAllForHost(cm.get()); |
| 1802 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1801 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1803 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1802 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1804 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1803 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
| 1805 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1804 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1806 EXPECT_EQ("dom_1=X; host_1=X", | 1805 EXPECT_EQ("dom_1=X; host_1=X", |
| 1807 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1806 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1808 EXPECT_EQ( | 1807 EXPECT_EQ( |
| 1809 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " | 1808 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " |
| 1810 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1809 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
| 1811 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1810 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1812 std::string("/dir1/dir2/xxx")))); | 1811 std::string("/dir1/dir2/xxx")))); |
| 1813 | 1812 |
| 1814 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost(cm.get(), base::Time(), | 1813 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost(cm.get(), base::Time(), |
| 1815 base::Time::Now(), | 1814 base::Time::Now(), |
| 1816 GURL(kTopLevelDomainPlus2))); | 1815 GURL(kTopLevelDomainPlus2))); |
| 1817 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1816 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1818 | 1817 |
| 1819 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1818 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1820 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1819 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1821 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1820 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1822 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1821 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1823 EXPECT_EQ("dom_1=X; host_1=X", | 1822 EXPECT_EQ("dom_1=X; host_1=X", |
| 1824 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1823 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1825 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1824 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1826 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1825 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1827 std::string("/dir1/dir2/xxx")))); | 1826 std::string("/dir1/dir2/xxx")))); |
| 1828 | 1827 |
| 1829 PopulateCmForDeleteAllForHost(cm); | 1828 PopulateCmForDeleteAllForHost(cm.get()); |
| 1830 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost( | 1829 EXPECT_EQ(6, DeleteAllCreatedBetweenForHost( |
| 1831 cm.get(), base::Time(), base::Time::Now(), | 1830 cm.get(), base::Time(), base::Time::Now(), |
| 1832 GURL(kTopLevelDomainPlus2Secure))); | 1831 GURL(kTopLevelDomainPlus2Secure))); |
| 1833 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1832 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1834 | 1833 |
| 1835 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1834 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1836 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1835 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1837 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1836 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1838 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1837 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1839 EXPECT_EQ("dom_1=X; host_1=X", | 1838 EXPECT_EQ("dom_1=X; host_1=X", |
| 1840 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1839 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1841 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1840 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1842 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1841 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1843 std::string("/dir1/dir2/xxx")))); | 1842 std::string("/dir1/dir2/xxx")))); |
| 1844 | 1843 |
| 1845 PopulateCmForDeleteAllForHost(cm); | 1844 PopulateCmForDeleteAllForHost(cm.get()); |
| 1846 EXPECT_EQ(6, | 1845 EXPECT_EQ(6, |
| 1847 DeleteAllCreatedBetweenForHost( | 1846 DeleteAllCreatedBetweenForHost( |
| 1848 cm.get(), base::Time(), base::Time::Now(), | 1847 cm.get(), base::Time(), base::Time::Now(), |
| 1849 GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/xxx")))); | 1848 GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/xxx")))); |
| 1850 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1849 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1851 | 1850 |
| 1852 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1851 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1853 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1852 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1854 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1853 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1855 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1854 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1856 EXPECT_EQ("dom_1=X; host_1=X", | 1855 EXPECT_EQ("dom_1=X; host_1=X", |
| 1857 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1856 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1858 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1857 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1859 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1858 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1860 std::string("/dir1/dir2/xxx")))); | 1859 std::string("/dir1/dir2/xxx")))); |
| 1861 } | 1860 } |
| 1862 | 1861 |
| 1863 TEST_F(CookieMonsterTest, UniqueCreationTime) { | 1862 TEST_F(CookieMonsterTest, UniqueCreationTime) { |
| 1864 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1863 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1865 CookieOptions options; | 1864 CookieOptions options; |
| 1866 | 1865 |
| 1867 // Add in three cookies through every public interface to the | 1866 // Add in three cookies through every public interface to the |
| 1868 // CookieMonster and confirm that none of them have duplicate | 1867 // CookieMonster and confirm that none of them have duplicate |
| 1869 // creation times. | 1868 // creation times. |
| 1870 | 1869 |
| 1871 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions | 1870 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions |
| 1872 // are not included as they aren't going to be public for very much | 1871 // are not included as they aren't going to be public for very much |
| 1873 // longer. | 1872 // longer. |
| 1874 | 1873 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 if (existing_cookie_it == check_map.end()) { | 1916 if (existing_cookie_it == check_map.end()) { |
| 1918 check_map.insert( | 1917 check_map.insert( |
| 1919 TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it)); | 1918 TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it)); |
| 1920 } | 1919 } |
| 1921 } | 1920 } |
| 1922 } | 1921 } |
| 1923 | 1922 |
| 1924 // Mainly a test of GetEffectiveDomain, or more specifically, of the | 1923 // Mainly a test of GetEffectiveDomain, or more specifically, of the |
| 1925 // expected behavior of GetEffectiveDomain within the CookieMonster. | 1924 // expected behavior of GetEffectiveDomain within the CookieMonster. |
| 1926 TEST_F(CookieMonsterTest, GetKey) { | 1925 TEST_F(CookieMonsterTest, GetKey) { |
| 1927 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1926 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1928 | 1927 |
| 1929 // This test is really only interesting if GetKey() actually does something. | 1928 // This test is really only interesting if GetKey() actually does something. |
| 1930 EXPECT_EQ("google.com", cm->GetKey("www.google.com")); | 1929 EXPECT_EQ("google.com", cm->GetKey("www.google.com")); |
| 1931 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); | 1930 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); |
| 1932 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); | 1931 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); |
| 1933 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); | 1932 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); |
| 1934 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); | 1933 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); |
| 1935 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); | 1934 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); |
| 1936 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); | 1935 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); |
| 1937 | 1936 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 "/another/path/to/cookie", | 1982 "/another/path/to/cookie", |
| 1984 base::Time::Now() + base::TimeDelta::FromSeconds(100), | 1983 base::Time::Now() + base::TimeDelta::FromSeconds(100), |
| 1985 true, | 1984 true, |
| 1986 false, | 1985 false, |
| 1987 true, | 1986 true, |
| 1988 COOKIE_PRIORITY_DEFAULT}}; | 1987 COOKIE_PRIORITY_DEFAULT}}; |
| 1989 const int INPUT_DELETE = 1; | 1988 const int INPUT_DELETE = 1; |
| 1990 | 1989 |
| 1991 // Create new cookies and flush them to the store. | 1990 // Create new cookies and flush them to the store. |
| 1992 { | 1991 { |
| 1993 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); | 1992 scoped_ptr<CookieMonster> cmout(new CookieMonster(store.get(), nullptr)); |
| 1994 for (const CookiesInputInfo* p = input_info; | 1993 for (const CookiesInputInfo* p = input_info; |
| 1995 p < &input_info[arraysize(input_info)]; p++) { | 1994 p < &input_info[arraysize(input_info)]; p++) { |
| 1996 EXPECT_TRUE(SetCookieWithDetails( | 1995 EXPECT_TRUE(SetCookieWithDetails( |
| 1997 cmout.get(), p->url, p->name, p->value, p->domain, p->path, | 1996 cmout.get(), p->url, p->name, p->value, p->domain, p->path, |
| 1998 base::Time(), p->expiration_time, base::Time(), p->secure, | 1997 base::Time(), p->expiration_time, base::Time(), p->secure, |
| 1999 p->http_only, p->same_site, p->priority)); | 1998 p->http_only, p->same_site, p->priority)); |
| 2000 } | 1999 } |
| 2001 GURL del_url(input_info[INPUT_DELETE] | 2000 GURL del_url(input_info[INPUT_DELETE] |
| 2002 .url.Resolve(input_info[INPUT_DELETE].path) | 2001 .url.Resolve(input_info[INPUT_DELETE].path) |
| 2003 .spec()); | 2002 .spec()); |
| 2004 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); | 2003 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); |
| 2005 } | 2004 } |
| 2006 | 2005 |
| 2007 // Create a new cookie monster and make sure that everything is correct | 2006 // Create a new cookie monster and make sure that everything is correct |
| 2008 { | 2007 { |
| 2009 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); | 2008 scoped_ptr<CookieMonster> cmin(new CookieMonster(store.get(), nullptr)); |
| 2010 CookieList cookies(GetAllCookies(cmin.get())); | 2009 CookieList cookies(GetAllCookies(cmin.get())); |
| 2011 ASSERT_EQ(2u, cookies.size()); | 2010 ASSERT_EQ(2u, cookies.size()); |
| 2012 // Ordering is path length, then creation time. So second cookie | 2011 // Ordering is path length, then creation time. So second cookie |
| 2013 // will come first, and we need to swap them. | 2012 // will come first, and we need to swap them. |
| 2014 std::swap(cookies[0], cookies[1]); | 2013 std::swap(cookies[0], cookies[1]); |
| 2015 for (int output_index = 0; output_index < 2; output_index++) { | 2014 for (int output_index = 0; output_index < 2; output_index++) { |
| 2016 int input_index = output_index * 2; | 2015 int input_index = output_index * 2; |
| 2017 const CookiesInputInfo* input = &input_info[input_index]; | 2016 const CookiesInputInfo* input = &input_info[input_index]; |
| 2018 const CanonicalCookie* output = &cookies[output_index]; | 2017 const CanonicalCookie* output = &cookies[output_index]; |
| 2019 | 2018 |
| 2020 EXPECT_EQ(input->name, output->Name()); | 2019 EXPECT_EQ(input->name, output->Name()); |
| 2021 EXPECT_EQ(input->value, output->Value()); | 2020 EXPECT_EQ(input->value, output->Value()); |
| 2022 EXPECT_EQ(input->url.host(), output->Domain()); | 2021 EXPECT_EQ(input->url.host(), output->Domain()); |
| 2023 EXPECT_EQ(input->path, output->Path()); | 2022 EXPECT_EQ(input->path, output->Path()); |
| 2024 EXPECT_LE(current.ToInternalValue(), | 2023 EXPECT_LE(current.ToInternalValue(), |
| 2025 output->CreationDate().ToInternalValue()); | 2024 output->CreationDate().ToInternalValue()); |
| 2026 EXPECT_EQ(input->secure, output->IsSecure()); | 2025 EXPECT_EQ(input->secure, output->IsSecure()); |
| 2027 EXPECT_EQ(input->http_only, output->IsHttpOnly()); | 2026 EXPECT_EQ(input->http_only, output->IsHttpOnly()); |
| 2028 EXPECT_EQ(input->same_site, output->IsSameSite()); | 2027 EXPECT_EQ(input->same_site, output->IsSameSite()); |
| 2029 EXPECT_TRUE(output->IsPersistent()); | 2028 EXPECT_TRUE(output->IsPersistent()); |
| 2030 EXPECT_EQ(input->expiration_time.ToInternalValue(), | 2029 EXPECT_EQ(input->expiration_time.ToInternalValue(), |
| 2031 output->ExpiryDate().ToInternalValue()); | 2030 output->ExpiryDate().ToInternalValue()); |
| 2032 } | 2031 } |
| 2033 } | 2032 } |
| 2034 } | 2033 } |
| 2035 | 2034 |
| 2036 TEST_F(CookieMonsterTest, CookieListOrdering) { | 2035 TEST_F(CookieMonsterTest, CookieListOrdering) { |
| 2037 // Put a random set of cookies into a monster and make sure | 2036 // Put a random set of cookies into a monster and make sure |
| 2038 // they're returned in the right order. | 2037 // they're returned in the right order. |
| 2039 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2038 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2040 EXPECT_TRUE( | 2039 EXPECT_TRUE( |
| 2041 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); | 2040 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); |
| 2042 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 2041 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 2043 "d=1; domain=b.a.google.com")); | 2042 "d=1; domain=b.a.google.com")); |
| 2044 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | 2043 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 2045 "a=4; domain=b.a.google.com")); | 2044 "a=4; domain=b.a.google.com")); |
| 2046 EXPECT_TRUE(SetCookie(cm.get(), | 2045 EXPECT_TRUE(SetCookie(cm.get(), |
| 2047 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 2046 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), |
| 2048 "e=1; domain=c.b.a.google.com")); | 2047 "e=1; domain=c.b.a.google.com")); |
| 2049 EXPECT_TRUE(SetCookie(cm.get(), | 2048 EXPECT_TRUE(SetCookie(cm.get(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2086 #if defined(OS_WIN) | 2085 #if defined(OS_WIN) |
| 2087 #define MAYBE_GarbageCollectionTriggers DISABLED_GarbageCollectionTriggers | 2086 #define MAYBE_GarbageCollectionTriggers DISABLED_GarbageCollectionTriggers |
| 2088 #else | 2087 #else |
| 2089 #define MAYBE_GarbageCollectionTriggers GarbageCollectionTriggers | 2088 #define MAYBE_GarbageCollectionTriggers GarbageCollectionTriggers |
| 2090 #endif | 2089 #endif |
| 2091 | 2090 |
| 2092 TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) { | 2091 TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) { |
| 2093 // First we check to make sure that a whole lot of recent cookies | 2092 // First we check to make sure that a whole lot of recent cookies |
| 2094 // doesn't get rid of anything after garbage collection is checked for. | 2093 // doesn't get rid of anything after garbage collection is checked for. |
| 2095 { | 2094 { |
| 2096 scoped_refptr<CookieMonster> cm( | 2095 scoped_ptr<CookieMonster> cm( |
| 2097 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); | 2096 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); |
| 2098 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm.get()).size()); | 2097 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm.get()).size()); |
| 2099 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 2098 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
| 2100 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, | 2099 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, |
| 2101 GetAllCookies(cm.get()).size()); | 2100 GetAllCookies(cm.get()).size()); |
| 2102 } | 2101 } |
| 2103 | 2102 |
| 2104 // Now we explore a series of relationships between cookie last access | 2103 // Now we explore a series of relationships between cookie last access |
| 2105 // time and size of store to make sure we only get rid of cookies when | 2104 // time and size of store to make sure we only get rid of cookies when |
| 2106 // we really should. | 2105 // we really should. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2128 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}, | 2127 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}, |
| 2129 {// Old cookies enough to bring below our purge line (which we | 2128 {// Old cookies enough to bring below our purge line (which we |
| 2130 // shouldn't do). | 2129 // shouldn't do). |
| 2131 CookieMonster::kMaxCookies * 2, | 2130 CookieMonster::kMaxCookies * 2, |
| 2132 CookieMonster::kMaxCookies * 3 / 2, | 2131 CookieMonster::kMaxCookies * 3 / 2, |
| 2133 CookieMonster::kMaxCookies * 2, | 2132 CookieMonster::kMaxCookies * 2, |
| 2134 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}}; | 2133 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}}; |
| 2135 | 2134 |
| 2136 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { | 2135 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { |
| 2137 const TestCase* test_case = &test_cases[ci]; | 2136 const TestCase* test_case = &test_cases[ci]; |
| 2138 scoped_refptr<CookieMonster> cm(CreateMonsterFromStoreForGC( | 2137 scoped_ptr<CookieMonster> cm = CreateMonsterFromStoreForGC( |
| 2139 test_case->num_cookies, test_case->num_old_cookies, 0, 0, | 2138 test_case->num_cookies, test_case->num_old_cookies, 0, 0, |
| 2140 CookieMonster::kSafeFromGlobalPurgeDays * 2)); | 2139 CookieMonster::kSafeFromGlobalPurgeDays * 2); |
| 2141 EXPECT_EQ(test_case->expected_initial_cookies, | 2140 EXPECT_EQ(test_case->expected_initial_cookies, |
| 2142 GetAllCookies(cm.get()).size()) | 2141 GetAllCookies(cm.get()).size()) |
| 2143 << "For test case " << ci; | 2142 << "For test case " << ci; |
| 2144 // Will trigger GC | 2143 // Will trigger GC |
| 2145 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 2144 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
| 2146 EXPECT_EQ(test_case->expected_cookies_after_set, | 2145 EXPECT_EQ(test_case->expected_cookies_after_set, |
| 2147 GetAllCookies(cm.get()).size()) | 2146 GetAllCookies(cm.get()).size()) |
| 2148 << "For test case " << ci; | 2147 << "For test case " << ci; |
| 2149 } | 2148 } |
| 2150 } | 2149 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2203 | 2202 |
| 2204 volatile int callback_count_; | 2203 volatile int callback_count_; |
| 2205 }; | 2204 }; |
| 2206 | 2205 |
| 2207 } // namespace | 2206 } // namespace |
| 2208 | 2207 |
| 2209 // Test that FlushStore() is forwarded to the store and callbacks are posted. | 2208 // Test that FlushStore() is forwarded to the store and callbacks are posted. |
| 2210 TEST_F(CookieMonsterTest, FlushStore) { | 2209 TEST_F(CookieMonsterTest, FlushStore) { |
| 2211 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); | 2210 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); |
| 2212 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2211 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2213 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2212 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2214 | 2213 |
| 2215 ASSERT_EQ(0, store->flush_count()); | 2214 ASSERT_EQ(0, store->flush_count()); |
| 2216 ASSERT_EQ(0, counter->callback_count()); | 2215 ASSERT_EQ(0, counter->callback_count()); |
| 2217 | 2216 |
| 2218 // Before initialization, FlushStore() should just run the callback. | 2217 // Before initialization, FlushStore() should just run the callback. |
| 2219 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); | 2218 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); |
| 2220 base::MessageLoop::current()->RunUntilIdle(); | 2219 base::MessageLoop::current()->RunUntilIdle(); |
| 2221 | 2220 |
| 2222 ASSERT_EQ(0, store->flush_count()); | 2221 ASSERT_EQ(0, store->flush_count()); |
| 2223 ASSERT_EQ(1, counter->callback_count()); | 2222 ASSERT_EQ(1, counter->callback_count()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2238 ASSERT_EQ(2, counter->callback_count()); | 2237 ASSERT_EQ(2, counter->callback_count()); |
| 2239 | 2238 |
| 2240 // NULL callback is still safe. | 2239 // NULL callback is still safe. |
| 2241 cm->FlushStore(base::Closure()); | 2240 cm->FlushStore(base::Closure()); |
| 2242 base::MessageLoop::current()->RunUntilIdle(); | 2241 base::MessageLoop::current()->RunUntilIdle(); |
| 2243 | 2242 |
| 2244 ASSERT_EQ(2, store->flush_count()); | 2243 ASSERT_EQ(2, store->flush_count()); |
| 2245 ASSERT_EQ(2, counter->callback_count()); | 2244 ASSERT_EQ(2, counter->callback_count()); |
| 2246 | 2245 |
| 2247 // If there's no backing store, FlushStore() is always a safe no-op. | 2246 // If there's no backing store, FlushStore() is always a safe no-op. |
| 2248 cm = new CookieMonster(NULL, NULL); | 2247 cm.reset(new CookieMonster(nullptr, nullptr)); |
| 2249 GetAllCookies(cm.get()); // Force init. | 2248 GetAllCookies(cm.get()); // Force init. |
| 2250 cm->FlushStore(base::Closure()); | 2249 cm->FlushStore(base::Closure()); |
| 2251 base::MessageLoop::current()->RunUntilIdle(); | 2250 base::MessageLoop::current()->RunUntilIdle(); |
| 2252 | 2251 |
| 2253 ASSERT_EQ(2, counter->callback_count()); | 2252 ASSERT_EQ(2, counter->callback_count()); |
| 2254 | 2253 |
| 2255 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); | 2254 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); |
| 2256 base::MessageLoop::current()->RunUntilIdle(); | 2255 base::MessageLoop::current()->RunUntilIdle(); |
| 2257 | 2256 |
| 2258 ASSERT_EQ(3, counter->callback_count()); | 2257 ASSERT_EQ(3, counter->callback_count()); |
| 2259 } | 2258 } |
| 2260 | 2259 |
| 2261 TEST_F(CookieMonsterTest, SetAllCookies) { | 2260 TEST_F(CookieMonsterTest, SetAllCookies) { |
| 2262 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2261 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2263 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2262 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2264 cm->SetPersistSessionCookies(true); | 2263 cm->SetPersistSessionCookies(true); |
| 2265 | 2264 |
| 2266 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2265 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); |
| 2267 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2266 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); |
| 2268 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2267 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); |
| 2269 | 2268 |
| 2270 CookieList list; | 2269 CookieList list; |
| 2271 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B", | 2270 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B", |
| 2272 http_www_google_.url().host(), "/", | 2271 http_www_google_.url().host(), "/", |
| 2273 base::Time::Now(), base::Time(), base::Time(), | 2272 base::Time::Now(), base::Time(), base::Time(), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2299 ASSERT_TRUE(++it != cookies.end()); | 2298 ASSERT_TRUE(++it != cookies.end()); |
| 2300 EXPECT_EQ("A", it->Name()); | 2299 EXPECT_EQ("A", it->Name()); |
| 2301 EXPECT_EQ("B", it->Value()); | 2300 EXPECT_EQ("B", it->Value()); |
| 2302 | 2301 |
| 2303 ASSERT_TRUE(++it != cookies.end()); | 2302 ASSERT_TRUE(++it != cookies.end()); |
| 2304 EXPECT_EQ("Y", it->Name()); | 2303 EXPECT_EQ("Y", it->Name()); |
| 2305 EXPECT_EQ("Z", it->Value()); | 2304 EXPECT_EQ("Z", it->Value()); |
| 2306 } | 2305 } |
| 2307 | 2306 |
| 2308 TEST_F(CookieMonsterTest, ComputeCookieDiff) { | 2307 TEST_F(CookieMonsterTest, ComputeCookieDiff) { |
| 2309 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2308 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2310 | 2309 |
| 2311 base::Time now = base::Time::Now(); | 2310 base::Time now = base::Time::Now(); |
| 2312 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); | 2311 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); |
| 2313 | 2312 |
| 2314 CanonicalCookie cookie1(http_www_google_.url(), "A", "B", | 2313 CanonicalCookie cookie1(http_www_google_.url(), "A", "B", |
| 2315 http_www_google_.url().host(), "/", creation_time, | 2314 http_www_google_.url().host(), "/", creation_time, |
| 2316 base::Time(), base::Time(), false, false, false, | 2315 base::Time(), base::Time(), false, false, false, |
| 2317 COOKIE_PRIORITY_DEFAULT); | 2316 COOKIE_PRIORITY_DEFAULT); |
| 2318 CanonicalCookie cookie2(http_www_google_.url(), "C", "D", | 2317 CanonicalCookie cookie2(http_www_google_.url(), "C", "D", |
| 2319 http_www_google_.url().host(), "/", creation_time, | 2318 http_www_google_.url().host(), "/", creation_time, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2416 EXPECT_FALSE(IsCookieInList(cookie7, cookies_to_add)); | 2415 EXPECT_FALSE(IsCookieInList(cookie7, cookies_to_add)); |
| 2417 EXPECT_FALSE(IsCookieInList(cookie7, cookies_to_delete)); | 2416 EXPECT_FALSE(IsCookieInList(cookie7, cookies_to_delete)); |
| 2418 EXPECT_TRUE(IsCookieInList(cookie7_with_new_path, cookies_to_add)); | 2417 EXPECT_TRUE(IsCookieInList(cookie7_with_new_path, cookies_to_add)); |
| 2419 EXPECT_FALSE(IsCookieInList(cookie7_with_new_path, cookies_to_delete)); | 2418 EXPECT_FALSE(IsCookieInList(cookie7_with_new_path, cookies_to_delete)); |
| 2420 } | 2419 } |
| 2421 | 2420 |
| 2422 // Check that DeleteAll does flush (as a sanity check that flush_count() | 2421 // Check that DeleteAll does flush (as a sanity check that flush_count() |
| 2423 // works). | 2422 // works). |
| 2424 TEST_F(CookieMonsterTest, DeleteAll) { | 2423 TEST_F(CookieMonsterTest, DeleteAll) { |
| 2425 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2424 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2426 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2425 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2427 cm->SetPersistSessionCookies(true); | 2426 cm->SetPersistSessionCookies(true); |
| 2428 | 2427 |
| 2429 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/")); | 2428 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "X=Y; path=/")); |
| 2430 | 2429 |
| 2431 ASSERT_EQ(0, store->flush_count()); | 2430 ASSERT_EQ(0, store->flush_count()); |
| 2432 EXPECT_EQ(1, DeleteAll(cm.get())); | 2431 EXPECT_EQ(1, DeleteAll(cm.get())); |
| 2433 EXPECT_EQ(1, store->flush_count()); | 2432 EXPECT_EQ(1, store->flush_count()); |
| 2434 } | 2433 } |
| 2435 | 2434 |
| 2436 TEST_F(CookieMonsterTest, HistogramCheck) { | 2435 TEST_F(CookieMonsterTest, HistogramCheck) { |
| 2437 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2436 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2438 // Should match call in InitializeHistograms, but doesn't really matter | 2437 // Should match call in InitializeHistograms, but doesn't really matter |
| 2439 // since the histogram should have been initialized by the CM construction | 2438 // since the histogram should have been initialized by the CM construction |
| 2440 // above. | 2439 // above. |
| 2441 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( | 2440 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( |
| 2442 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2441 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
| 2443 base::Histogram::kUmaTargetedHistogramFlag); | 2442 base::Histogram::kUmaTargetedHistogramFlag); |
| 2444 | 2443 |
| 2445 scoped_ptr<base::HistogramSamples> samples1( | 2444 scoped_ptr<base::HistogramSamples> samples1( |
| 2446 expired_histogram->SnapshotSamples()); | 2445 expired_histogram->SnapshotSamples()); |
| 2447 ASSERT_TRUE(SetCookieWithDetails( | 2446 ASSERT_TRUE(SetCookieWithDetails( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2466 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; | 2465 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |
| 2467 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 2466 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
| 2468 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); | 2467 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); |
| 2469 ASSERT_FALSE(cookie->IsPersistent()); | 2468 ASSERT_FALSE(cookie->IsPersistent()); |
| 2470 } | 2469 } |
| 2471 | 2470 |
| 2472 // Test that CookieMonster writes session cookies into the underlying | 2471 // Test that CookieMonster writes session cookies into the underlying |
| 2473 // CookieStore if the "persist session cookies" option is on. | 2472 // CookieStore if the "persist session cookies" option is on. |
| 2474 TEST_F(CookieMonsterTest, PersistSessionCookies) { | 2473 TEST_F(CookieMonsterTest, PersistSessionCookies) { |
| 2475 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2474 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2476 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2475 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2477 cm->SetPersistSessionCookies(true); | 2476 cm->SetPersistSessionCookies(true); |
| 2478 | 2477 |
| 2479 // All cookies set with SetCookie are session cookies. | 2478 // All cookies set with SetCookie are session cookies. |
| 2480 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); | 2479 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B")); |
| 2481 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2480 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 2482 | 2481 |
| 2483 // The cookie was written to the backing store. | 2482 // The cookie was written to the backing store. |
| 2484 EXPECT_EQ(1u, store->commands().size()); | 2483 EXPECT_EQ(1u, store->commands().size()); |
| 2485 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2484 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 2486 EXPECT_EQ("A", store->commands()[0].cookie.Name()); | 2485 EXPECT_EQ("A", store->commands()[0].cookie.Name()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2502 EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url())); | 2501 EXPECT_EQ("", GetCookies(cm.get(), http_www_google_.url())); |
| 2503 EXPECT_EQ(4u, store->commands().size()); | 2502 EXPECT_EQ(4u, store->commands().size()); |
| 2504 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2503 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 2505 EXPECT_EQ("A", store->commands()[3].cookie.Name()); | 2504 EXPECT_EQ("A", store->commands()[3].cookie.Name()); |
| 2506 EXPECT_EQ("C", store->commands()[3].cookie.Value()); | 2505 EXPECT_EQ("C", store->commands()[3].cookie.Value()); |
| 2507 } | 2506 } |
| 2508 | 2507 |
| 2509 // Test the commands sent to the persistent cookie store. | 2508 // Test the commands sent to the persistent cookie store. |
| 2510 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { | 2509 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { |
| 2511 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2510 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2512 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2511 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2513 | 2512 |
| 2514 // Add a cookie. | 2513 // Add a cookie. |
| 2515 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 2514 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), |
| 2516 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2515 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 2517 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url())); | 2516 this->MatchCookieLines("A=B", GetCookies(cm.get(), http_www_google_.url())); |
| 2518 ASSERT_EQ(1u, store->commands().size()); | 2517 ASSERT_EQ(1u, store->commands().size()); |
| 2519 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2518 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 2520 // Remove it. | 2519 // Remove it. |
| 2521 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0")); | 2520 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B; max-age=0")); |
| 2522 this->MatchCookieLines(std::string(), | 2521 this->MatchCookieLines(std::string(), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2571 "boo", | 2570 "boo", |
| 2572 domain, path, now2, later, now2, false, false, false, | 2571 domain, path, now2, later, now2, false, false, false, |
| 2573 COOKIE_PRIORITY_DEFAULT); | 2572 COOKIE_PRIORITY_DEFAULT); |
| 2574 initial_cookies.push_back(cc); | 2573 initial_cookies.push_back(cc); |
| 2575 | 2574 |
| 2576 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); | 2575 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); |
| 2577 | 2576 |
| 2578 // Inject our initial cookies into the mock PersistentCookieStore. | 2577 // Inject our initial cookies into the mock PersistentCookieStore. |
| 2579 store->SetLoadExpectation(true, initial_cookies); | 2578 store->SetLoadExpectation(true, initial_cookies); |
| 2580 | 2579 |
| 2581 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2580 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2582 | 2581 |
| 2583 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2582 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
| 2584 } | 2583 } |
| 2585 | 2584 |
| 2586 // Test that cookie source schemes are histogrammed correctly. | 2585 // Test that cookie source schemes are histogrammed correctly. |
| 2587 TEST_F(CookieMonsterTest, CookieSourceHistogram) { | 2586 TEST_F(CookieMonsterTest, CookieSourceHistogram) { |
| 2588 base::HistogramTester histograms; | 2587 base::HistogramTester histograms; |
| 2589 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; | 2588 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; |
| 2590 | 2589 |
| 2591 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2590 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2592 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2591 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2593 | 2592 |
| 2594 histograms.ExpectTotalCount(cookie_source_histogram, 0); | 2593 histograms.ExpectTotalCount(cookie_source_histogram, 0); |
| 2595 | 2594 |
| 2596 // Set a secure cookie on a cryptographic scheme. | 2595 // Set a secure cookie on a cryptographic scheme. |
| 2597 EXPECT_TRUE( | 2596 EXPECT_TRUE( |
| 2598 SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure")); | 2597 SetCookie(cm.get(), https_www_google_.url(), "A=B; path=/; Secure")); |
| 2599 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2598 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2600 histograms.ExpectBucketCount( | 2599 histograms.ExpectBucketCount( |
| 2601 cookie_source_histogram, | 2600 cookie_source_histogram, |
| 2602 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2601 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2649 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2648 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); |
| 2650 } | 2649 } |
| 2651 | 2650 |
| 2652 // Test that cookie delete equivalent histograms are recorded correctly when | 2651 // Test that cookie delete equivalent histograms are recorded correctly when |
| 2653 // strict secure cookies are not enabled. | 2652 // strict secure cookies are not enabled. |
| 2654 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { | 2653 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { |
| 2655 base::HistogramTester histograms; | 2654 base::HistogramTester histograms; |
| 2656 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 2655 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
| 2657 | 2656 |
| 2658 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2657 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2659 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2658 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2660 | 2659 |
| 2661 // Set a secure cookie from a secure origin | 2660 // Set a secure cookie from a secure origin |
| 2662 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 2661 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); |
| 2663 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2662 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2664 histograms.ExpectBucketCount(cookie_source_histogram, | 2663 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2665 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2664 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2666 1); | 2665 1); |
| 2667 | 2666 |
| 2668 // Set a new cookie with a different name from a variety of origins (including | 2667 // Set a new cookie with a different name from a variety of origins (including |
| 2669 // the same one). | 2668 // the same one). |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2714 // already existing cookie and is not equivalent. | 2713 // already existing cookie and is not equivalent. |
| 2715 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | 2714 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), |
| 2716 "A=E; secure; path=/some/other/path")); | 2715 "A=E; secure; path=/some/other/path")); |
| 2717 histograms.ExpectTotalCount(cookie_source_histogram, 9); | 2716 histograms.ExpectTotalCount(cookie_source_histogram, 9); |
| 2718 histograms.ExpectBucketCount(cookie_source_histogram, | 2717 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2719 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2718 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2720 7); | 2719 7); |
| 2721 } | 2720 } |
| 2722 | 2721 |
| 2723 TEST_F(CookieMonsterStrictSecureTest, SetSecureCookies) { | 2722 TEST_F(CookieMonsterStrictSecureTest, SetSecureCookies) { |
| 2724 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2723 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2725 GURL http_url("http://www.google.com"); | 2724 GURL http_url("http://www.google.com"); |
| 2726 GURL http_superdomain_url("http://google.com"); | 2725 GURL http_superdomain_url("http://google.com"); |
| 2727 GURL https_url("https://www.google.com"); | 2726 GURL https_url("https://www.google.com"); |
| 2728 | 2727 |
| 2729 // A non-secure cookie can be created from either a URL with a secure or | 2728 // A non-secure cookie can be created from either a URL with a secure or |
| 2730 // insecure scheme. | 2729 // insecure scheme. |
| 2731 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); | 2730 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); |
| 2732 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); | 2731 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); |
| 2733 | 2732 |
| 2734 // A secure cookie cannot be created from a URL with an insecure scheme. | 2733 // A secure cookie cannot be created from a URL with an insecure scheme. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2909 // global purge goal (3000), but the secure cookies are not evicted. | 2908 // global purge goal (3000), but the secure cookies are not evicted. |
| 2910 const CookiesEntry test14[] = {{1U, true}}; | 2909 const CookiesEntry test14[] = {{1U, true}}; |
| 2911 const AltHosts test14_alt_hosts(1500, 1800); | 2910 const AltHosts test14_alt_hosts(1500, 1800); |
| 2912 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, | 2911 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, |
| 2913 &test14_alt_hosts); | 2912 &test14_alt_hosts); |
| 2914 } | 2913 } |
| 2915 | 2914 |
| 2916 // Tests that strict secure cookies doesn't trip equivalent cookie checks | 2915 // Tests that strict secure cookies doesn't trip equivalent cookie checks |
| 2917 // accidentally. Regression test for https://crbug.com/569943. | 2916 // accidentally. Regression test for https://crbug.com/569943. |
| 2918 TEST_F(CookieMonsterStrictSecureTest, EquivalentCookies) { | 2917 TEST_F(CookieMonsterStrictSecureTest, EquivalentCookies) { |
| 2919 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2918 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2920 GURL http_url("http://www.google.com"); | 2919 GURL http_url("http://www.google.com"); |
| 2921 GURL http_superdomain_url("http://google.com"); | 2920 GURL http_superdomain_url("http://google.com"); |
| 2922 GURL https_url("https://www.google.com"); | 2921 GURL https_url("https://www.google.com"); |
| 2923 | 2922 |
| 2924 // Tests that non-equivalent cookies because of the path attribute can be set | 2923 // Tests that non-equivalent cookies because of the path attribute can be set |
| 2925 // successfully. | 2924 // successfully. |
| 2926 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 2925 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 2927 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); | 2926 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); |
| 2928 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); | 2927 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); |
| 2929 | 2928 |
| 2930 // Tests that non-equivalent cookies because of the domain attribute can be | 2929 // Tests that non-equivalent cookies because of the domain attribute can be |
| 2931 // set successfully. | 2930 // set successfully. |
| 2932 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 2931 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 2933 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); | 2932 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); |
| 2934 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); | 2933 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); |
| 2935 } | 2934 } |
| 2936 | 2935 |
| 2937 // Test that cookie delete equivalent histograms are recorded correctly for | 2936 // Test that cookie delete equivalent histograms are recorded correctly for |
| 2938 // strict secure cookies. | 2937 // strict secure cookies. |
| 2939 TEST_F(CookieMonsterStrictSecureTest, CookieDeleteEquivalentHistogramTest) { | 2938 TEST_F(CookieMonsterStrictSecureTest, CookieDeleteEquivalentHistogramTest) { |
| 2940 base::HistogramTester histograms; | 2939 base::HistogramTester histograms; |
| 2941 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 2940 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
| 2942 | 2941 |
| 2943 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2942 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2944 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2943 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2945 | 2944 |
| 2946 // Set a secure cookie from a secure origin | 2945 // Set a secure cookie from a secure origin |
| 2947 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 2946 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); |
| 2948 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2947 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2949 histograms.ExpectBucketCount(cookie_source_histogram, | 2948 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2950 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2949 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2951 1); | 2950 1); |
| 2952 | 2951 |
| 2953 // Set a new cookie with a different name from a variety of origins (including | 2952 // Set a new cookie with a different name from a variety of origins (including |
| 2954 // the same one). | 2953 // the same one). |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3009 histograms.ExpectBucketCount(cookie_source_histogram, | 3008 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3010 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3009 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3011 7); | 3010 7); |
| 3012 } | 3011 } |
| 3013 | 3012 |
| 3014 class CookieMonsterNotificationTest : public CookieMonsterTest { | 3013 class CookieMonsterNotificationTest : public CookieMonsterTest { |
| 3015 public: | 3014 public: |
| 3016 CookieMonsterNotificationTest() | 3015 CookieMonsterNotificationTest() |
| 3017 : test_url_("http://www.google.com/foo"), | 3016 : test_url_("http://www.google.com/foo"), |
| 3018 store_(new MockPersistentCookieStore), | 3017 store_(new MockPersistentCookieStore), |
| 3019 monster_(new CookieMonster(store_.get(), NULL)) {} | 3018 monster_(new CookieMonster(store_.get(), nullptr)) {} |
| 3020 | 3019 |
| 3021 ~CookieMonsterNotificationTest() override {} | 3020 ~CookieMonsterNotificationTest() override {} |
| 3022 | 3021 |
| 3023 CookieMonster* monster() { return monster_.get(); } | 3022 CookieMonster* monster() { return monster_.get(); } |
| 3024 | 3023 |
| 3025 protected: | 3024 protected: |
| 3026 const GURL test_url_; | 3025 const GURL test_url_; |
| 3027 | 3026 |
| 3028 private: | 3027 private: |
| 3029 scoped_refptr<MockPersistentCookieStore> store_; | 3028 scoped_refptr<MockPersistentCookieStore> store_; |
| 3030 scoped_refptr<CookieMonster> monster_; | 3029 scoped_ptr<CookieMonster> monster_; |
| 3031 }; | 3030 }; |
| 3032 | 3031 |
| 3033 void RecordCookieChanges(std::vector<CanonicalCookie>* out_cookies, | 3032 void RecordCookieChanges(std::vector<CanonicalCookie>* out_cookies, |
| 3034 std::vector<bool>* out_removes, | 3033 std::vector<bool>* out_removes, |
| 3035 const CanonicalCookie& cookie, | 3034 const CanonicalCookie& cookie, |
| 3036 bool removed) { | 3035 bool removed) { |
| 3037 DCHECK(out_cookies); | 3036 DCHECK(out_cookies); |
| 3038 out_cookies->push_back(cookie); | 3037 out_cookies->push_back(cookie); |
| 3039 if (out_removes) | 3038 if (out_removes) |
| 3040 out_removes->push_back(removed); | 3039 out_removes->push_back(removed); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3161 monster()->AddCallbackForCookie( | 3160 monster()->AddCallbackForCookie( |
| 3162 test_url_, "abc", | 3161 test_url_, "abc", |
| 3163 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3162 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 3164 SetCookie(monster(), test_url_, "abc=def"); | 3163 SetCookie(monster(), test_url_, "abc=def"); |
| 3165 base::MessageLoop::current()->RunUntilIdle(); | 3164 base::MessageLoop::current()->RunUntilIdle(); |
| 3166 EXPECT_EQ(1U, cookies0.size()); | 3165 EXPECT_EQ(1U, cookies0.size()); |
| 3167 EXPECT_EQ(1U, cookies0.size()); | 3166 EXPECT_EQ(1U, cookies0.size()); |
| 3168 } | 3167 } |
| 3169 | 3168 |
| 3170 } // namespace net | 3169 } // namespace net |
| OLD | NEW |