Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(779)

Side by Side Diff: net/cookies/cookie_monster_unittest.cc

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/cookies/cookie_monster_store_test.cc ('k') | net/cookies/cookie_store_test_helpers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 // Helper for DeleteAllForHost test; repopulates CM with same layout 216 // Helper for DeleteAllForHost test; repopulates CM with same layout
217 // each time. 217 // each time.
218 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { 218 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) {
219 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); 219 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1);
220 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); 220 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2);
221 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); 221 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure);
222 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); 222 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3);
223 GURL url_other(kOtherDomain); 223 GURL url_other(kOtherDomain);
224 224
225 DeleteAll(cm); 225 DeleteAll(cm.get());
226 226
227 // Static population for probe: 227 // Static population for probe:
228 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) 228 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a)
229 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) 229 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a)
230 // * http_only cookie (w.c.b.a) 230 // * http_only cookie (w.c.b.a)
231 // * Two secure cookies (.c.b.a, w.c.b.a) 231 // * Two secure cookies (.c.b.a, w.c.b.a)
232 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) 232 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2)
233 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) 233 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2)
234 234
235 // Domain cookies 235 // Domain cookies
236 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_1, 236 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
237 "dom_1", "X", ".harvard.edu", "/", 237 url_top_level_domain_plus_1,
238 base::Time(), false, false, 238 "dom_1",
239 "X",
240 ".harvard.edu",
241 "/",
242 base::Time(),
243 false,
244 false,
239 COOKIE_PRIORITY_DEFAULT)); 245 COOKIE_PRIORITY_DEFAULT));
240 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, 246 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
241 "dom_2", "X", ".math.harvard.edu", 247 url_top_level_domain_plus_2,
242 "/", base::Time(), false, false, 248 "dom_2",
249 "X",
250 ".math.harvard.edu",
251 "/",
252 base::Time(),
253 false,
254 false,
243 COOKIE_PRIORITY_DEFAULT)); 255 COOKIE_PRIORITY_DEFAULT));
244 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_3, 256 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
245 "dom_3", "X", 257 url_top_level_domain_plus_3,
246 ".bourbaki.math.harvard.edu", "/", 258 "dom_3",
247 base::Time(), false, false, 259 "X",
260 ".bourbaki.math.harvard.edu",
261 "/",
262 base::Time(),
263 false,
264 false,
248 COOKIE_PRIORITY_DEFAULT)); 265 COOKIE_PRIORITY_DEFAULT));
249 266
250 // Host cookies 267 // Host cookies
251 EXPECT_TRUE(this->SetCookieWithDetails(cm, 268 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
252 url_top_level_domain_plus_1, 269 url_top_level_domain_plus_1,
253 "host_1", 270 "host_1",
254 "X", 271 "X",
255 std::string(), 272 std::string(),
256 "/", 273 "/",
257 base::Time(), 274 base::Time(),
258 false, 275 false,
259 false, 276 false,
260 COOKIE_PRIORITY_DEFAULT)); 277 COOKIE_PRIORITY_DEFAULT));
261 EXPECT_TRUE(this->SetCookieWithDetails(cm, 278 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
262 url_top_level_domain_plus_2, 279 url_top_level_domain_plus_2,
263 "host_2", 280 "host_2",
264 "X", 281 "X",
265 std::string(), 282 std::string(),
266 "/", 283 "/",
267 base::Time(), 284 base::Time(),
268 false, 285 false,
269 false, 286 false,
270 COOKIE_PRIORITY_DEFAULT)); 287 COOKIE_PRIORITY_DEFAULT));
271 EXPECT_TRUE(this->SetCookieWithDetails(cm, 288 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
272 url_top_level_domain_plus_3, 289 url_top_level_domain_plus_3,
273 "host_3", 290 "host_3",
274 "X", 291 "X",
275 std::string(), 292 std::string(),
276 "/", 293 "/",
277 base::Time(), 294 base::Time(),
278 false, 295 false,
279 false, 296 false,
280 COOKIE_PRIORITY_DEFAULT)); 297 COOKIE_PRIORITY_DEFAULT));
281 298
282 // Http_only cookie 299 // Http_only cookie
283 EXPECT_TRUE(this->SetCookieWithDetails(cm, 300 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
284 url_top_level_domain_plus_2, 301 url_top_level_domain_plus_2,
285 "httpo_check", 302 "httpo_check",
286 "X", 303 "X",
287 std::string(), 304 std::string(),
288 "/", 305 "/",
289 base::Time(), 306 base::Time(),
290 false, 307 false,
291 true, 308 true,
292 COOKIE_PRIORITY_DEFAULT)); 309 COOKIE_PRIORITY_DEFAULT));
293 310
294 // Secure cookies 311 // Secure cookies
295 EXPECT_TRUE(this->SetCookieWithDetails(cm, 312 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
296 url_top_level_domain_plus_2_secure, 313 url_top_level_domain_plus_2_secure,
297 "sec_dom", "X", ".math.harvard.edu", 314 "sec_dom",
298 "/", base::Time(), true, false, 315 "X",
316 ".math.harvard.edu",
317 "/",
318 base::Time(),
319 true,
320 false,
299 COOKIE_PRIORITY_DEFAULT)); 321 COOKIE_PRIORITY_DEFAULT));
300 EXPECT_TRUE(this->SetCookieWithDetails(cm, 322 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
301 url_top_level_domain_plus_2_secure, 323 url_top_level_domain_plus_2_secure,
302 "sec_host", 324 "sec_host",
303 "X", 325 "X",
304 std::string(), 326 std::string(),
305 "/", 327 "/",
306 base::Time(), 328 base::Time(),
307 true, 329 true,
308 false, 330 false,
309 COOKIE_PRIORITY_DEFAULT)); 331 COOKIE_PRIORITY_DEFAULT));
310 332
311 // Domain path cookies 333 // Domain path cookies
312 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, 334 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
313 "dom_path_1", "X", 335 url_top_level_domain_plus_2,
314 ".math.harvard.edu", "/dir1", 336 "dom_path_1",
315 base::Time(), false, false, 337 "X",
338 ".math.harvard.edu",
339 "/dir1",
340 base::Time(),
341 false,
342 false,
316 COOKIE_PRIORITY_DEFAULT)); 343 COOKIE_PRIORITY_DEFAULT));
317 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, 344 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
318 "dom_path_2", "X", 345 url_top_level_domain_plus_2,
319 ".math.harvard.edu", "/dir1/dir2", 346 "dom_path_2",
320 base::Time(), false, false, 347 "X",
348 ".math.harvard.edu",
349 "/dir1/dir2",
350 base::Time(),
351 false,
352 false,
321 COOKIE_PRIORITY_DEFAULT)); 353 COOKIE_PRIORITY_DEFAULT));
322 354
323 // Host path cookies 355 // Host path cookies
324 EXPECT_TRUE(this->SetCookieWithDetails(cm, 356 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
325 url_top_level_domain_plus_2, 357 url_top_level_domain_plus_2,
326 "host_path_1", 358 "host_path_1",
327 "X", 359 "X",
328 std::string(), 360 std::string(),
329 "/dir1", 361 "/dir1",
330 base::Time(), 362 base::Time(),
331 false, 363 false,
332 false, 364 false,
333 COOKIE_PRIORITY_DEFAULT)); 365 COOKIE_PRIORITY_DEFAULT));
334 EXPECT_TRUE(this->SetCookieWithDetails(cm, 366 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(),
335 url_top_level_domain_plus_2, 367 url_top_level_domain_plus_2,
336 "host_path_2", 368 "host_path_2",
337 "X", 369 "X",
338 std::string(), 370 std::string(),
339 "/dir1/dir2", 371 "/dir1/dir2",
340 base::Time(), 372 base::Time(),
341 false, 373 false,
342 false, 374 false,
343 COOKIE_PRIORITY_DEFAULT)); 375 COOKIE_PRIORITY_DEFAULT));
344 376
345 EXPECT_EQ(13U, this->GetAllCookies(cm).size()); 377 EXPECT_EQ(13U, this->GetAllCookies(cm.get()).size());
346 } 378 }
347 379
348 Time GetFirstCookieAccessDate(CookieMonster* cm) { 380 Time GetFirstCookieAccessDate(CookieMonster* cm) {
349 const CookieList all_cookies(this->GetAllCookies(cm)); 381 const CookieList all_cookies(this->GetAllCookies(cm));
350 return all_cookies.front().LastAccessDate(); 382 return all_cookies.front().LastAccessDate();
351 } 383 }
352 384
353 bool FindAndDeleteCookie(CookieMonster* cm, 385 bool FindAndDeleteCookie(CookieMonster* cm,
354 const std::string& domain, 386 const std::string& domain,
355 const std::string& name) { 387 const std::string& name) {
(...skipping 12 matching lines...) Expand all
368 void TestHostGarbageCollectHelper() { 400 void TestHostGarbageCollectHelper() {
369 int domain_max_cookies = CookieMonster::kDomainMaxCookies; 401 int domain_max_cookies = CookieMonster::kDomainMaxCookies;
370 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies; 402 int domain_purge_cookies = CookieMonster::kDomainPurgeCookies;
371 const int more_than_enough_cookies = 403 const int more_than_enough_cookies =
372 (domain_max_cookies + domain_purge_cookies) * 2; 404 (domain_max_cookies + domain_purge_cookies) * 2;
373 // Add a bunch of cookies on a single host, should purge them. 405 // Add a bunch of cookies on a single host, should purge them.
374 { 406 {
375 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 407 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
376 for (int i = 0; i < more_than_enough_cookies; ++i) { 408 for (int i = 0; i < more_than_enough_cookies; ++i) {
377 std::string cookie = base::StringPrintf("a%03d=b", i); 409 std::string cookie = base::StringPrintf("a%03d=b", i);
378 EXPECT_TRUE(SetCookie(cm, url_google_, cookie)); 410 EXPECT_TRUE(SetCookie(cm.get(), url_google_, cookie));
379 std::string cookies = this->GetCookies(cm, url_google_); 411 std::string cookies = this->GetCookies(cm.get(), url_google_);
380 // Make sure we find it in the cookies. 412 // Make sure we find it in the cookies.
381 EXPECT_NE(cookies.find(cookie), std::string::npos); 413 EXPECT_NE(cookies.find(cookie), std::string::npos);
382 // Count the number of cookies. 414 // Count the number of cookies.
383 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies); 415 EXPECT_LE(CountInString(cookies, '='), domain_max_cookies);
384 } 416 }
385 } 417 }
386 418
387 // Add a bunch of cookies on multiple hosts within a single eTLD. 419 // Add a bunch of cookies on multiple hosts within a single eTLD.
388 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies 420 // Should keep at least kDomainMaxCookies - kDomainPurgeCookies
389 // between them. We shouldn't go above kDomainMaxCookies for both together. 421 // between them. We shouldn't go above kDomainMaxCookies for both together.
390 GURL url_google_specific(kUrlGoogleSpecific); 422 GURL url_google_specific(kUrlGoogleSpecific);
391 { 423 {
392 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 424 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
393 for (int i = 0; i < more_than_enough_cookies; ++i) { 425 for (int i = 0; i < more_than_enough_cookies; ++i) {
394 std::string cookie_general = base::StringPrintf("a%03d=b", i); 426 std::string cookie_general = base::StringPrintf("a%03d=b", i);
395 EXPECT_TRUE(SetCookie(cm, url_google_, cookie_general)); 427 EXPECT_TRUE(SetCookie(cm.get(), url_google_, cookie_general));
396 std::string cookie_specific = base::StringPrintf("c%03d=b", i); 428 std::string cookie_specific = base::StringPrintf("c%03d=b", i);
397 EXPECT_TRUE(SetCookie(cm, url_google_specific, cookie_specific)); 429 EXPECT_TRUE(SetCookie(cm.get(), url_google_specific, cookie_specific));
398 std::string cookies_general = this->GetCookies(cm, url_google_); 430 std::string cookies_general = this->GetCookies(cm.get(), url_google_);
399 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos); 431 EXPECT_NE(cookies_general.find(cookie_general), std::string::npos);
400 std::string cookies_specific = 432 std::string cookies_specific =
401 this->GetCookies(cm, url_google_specific); 433 this->GetCookies(cm.get(), url_google_specific);
402 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos); 434 EXPECT_NE(cookies_specific.find(cookie_specific), std::string::npos);
403 EXPECT_LE((CountInString(cookies_general, '=') + 435 EXPECT_LE((CountInString(cookies_general, '=') +
404 CountInString(cookies_specific, '=')), 436 CountInString(cookies_specific, '=')),
405 domain_max_cookies); 437 domain_max_cookies);
406 } 438 }
407 // After all this, there should be at least 439 // After all this, there should be at least
408 // kDomainMaxCookies - kDomainPurgeCookies for both URLs. 440 // kDomainMaxCookies - kDomainPurgeCookies for both URLs.
409 std::string cookies_general = this->GetCookies(cm, url_google_); 441 std::string cookies_general = this->GetCookies(cm.get(), url_google_);
410 std::string cookies_specific = this->GetCookies(cm, url_google_specific); 442 std::string cookies_specific =
443 this->GetCookies(cm.get(), url_google_specific);
411 int total_cookies = (CountInString(cookies_general, '=') + 444 int total_cookies = (CountInString(cookies_general, '=') +
412 CountInString(cookies_specific, '=')); 445 CountInString(cookies_specific, '='));
413 EXPECT_GE(total_cookies, domain_max_cookies - domain_purge_cookies); 446 EXPECT_GE(total_cookies, domain_max_cookies - domain_purge_cookies);
414 EXPECT_LE(total_cookies, domain_max_cookies); 447 EXPECT_LE(total_cookies, domain_max_cookies);
415 } 448 }
416 } 449 }
417 450
418 CookiePriority CharToPriority(char ch) { 451 CookiePriority CharToPriority(char ch) {
419 switch (ch) { 452 switch (ch) {
420 case 'L': 453 case 'L':
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 CookieMonster::kDomainPurgeCookies); 553 CookieMonster::kDomainPurgeCookies);
521 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); 554 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow);
522 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); 555 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium);
523 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); 556 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh);
524 557
525 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 558 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
526 cm->SetPriorityAwareGarbageCollection(true); 559 cm->SetPriorityAwareGarbageCollection(true);
527 560
528 // Each test case adds 181 cookies, so 31 cookies are evicted. 561 // Each test case adds 181 cookies, so 31 cookies are evicted.
529 // Cookie same priority, repeated for each priority. 562 // Cookie same priority, repeated for each priority.
530 TestPriorityCookieCase(cm, "181L", 150U, 0U, 0U); 563 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U);
531 TestPriorityCookieCase(cm, "181M", 0U, 150U, 0U); 564 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U);
532 TestPriorityCookieCase(cm, "181H", 0U, 0U, 150U); 565 TestPriorityCookieCase(cm.get(), "181H", 0U, 0U, 150U);
533 566
534 // Pairwise scenarios. 567 // Pairwise scenarios.
535 // Round 1 => none; round2 => 31M; round 3 => none. 568 // Round 1 => none; round2 => 31M; round 3 => none.
536 TestPriorityCookieCase(cm, "10H 171M", 0U, 140U, 10U); 569 TestPriorityCookieCase(cm.get(), "10H 171M", 0U, 140U, 10U);
537 // Round 1 => 10L; round2 => 21M; round 3 => none. 570 // Round 1 => 10L; round2 => 21M; round 3 => none.
538 TestPriorityCookieCase(cm, "141M 40L", 30U, 120U, 0U); 571 TestPriorityCookieCase(cm.get(), "141M 40L", 30U, 120U, 0U);
539 // Round 1 => none; round2 => none; round 3 => 31H. 572 // Round 1 => none; round2 => none; round 3 => 31H.
540 TestPriorityCookieCase(cm, "101H 80M", 0U, 80U, 70U); 573 TestPriorityCookieCase(cm.get(), "101H 80M", 0U, 80U, 70U);
541 574
542 // For {low, medium} priorities right on quota, different orders. 575 // For {low, medium} priorities right on quota, different orders.
543 // Round 1 => 1L; round 2 => none, round3 => 30L. 576 // Round 1 => 1L; round 2 => none, round3 => 30L.
544 TestPriorityCookieCase(cm, "31L 50M 100H", 0U, 50U, 100U); 577 TestPriorityCookieCase(cm.get(), "31L 50M 100H", 0U, 50U, 100U);
545 // Round 1 => none; round 2 => 1M, round3 => 30M. 578 // Round 1 => none; round 2 => 1M, round3 => 30M.
546 TestPriorityCookieCase(cm, "51M 100H 30L", 30U, 20U, 100U); 579 TestPriorityCookieCase(cm.get(), "51M 100H 30L", 30U, 20U, 100U);
547 // Round 1 => none; round 2 => none; round3 => 31H. 580 // Round 1 => none; round 2 => none; round3 => 31H.
548 TestPriorityCookieCase(cm, "101H 50M 30L", 30U, 50U, 70U); 581 TestPriorityCookieCase(cm.get(), "101H 50M 30L", 30U, 50U, 70U);
549 582
550 // Round 1 => 10L; round 2 => 10M; round3 => 11H. 583 // Round 1 => 10L; round 2 => 10M; round3 => 11H.
551 TestPriorityCookieCase(cm, "81H 60M 40L", 30U, 50U, 70U); 584 TestPriorityCookieCase(cm.get(), "81H 60M 40L", 30U, 50U, 70U);
552 585
553 // More complex scenarios. 586 // More complex scenarios.
554 // Round 1 => 10L; round 2 => 10M; round 3 => 11H. 587 // Round 1 => 10L; round 2 => 10M; round 3 => 11H.
555 TestPriorityCookieCase(cm, "21H 60M 40L 60H", 30U, 50U, 70U); 588 TestPriorityCookieCase(cm.get(), "21H 60M 40L 60H", 30U, 50U, 70U);
556 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none. 589 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none.
557 TestPriorityCookieCase(cm, "11H 10M 20L 110M 20L 10H", 20U, 109U, 21U); 590 TestPriorityCookieCase(
591 cm.get(), "11H 10M 20L 110M 20L 10H", 20U, 109U, 21U);
558 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H. 592 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H.
559 TestPriorityCookieCase(cm, "11L 10M 140H 10M 10L", 10U, 10U, 130U); 593 TestPriorityCookieCase(cm.get(), "11L 10M 140H 10M 10L", 10U, 10U, 130U);
560 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H. 594 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H.
561 TestPriorityCookieCase(cm, "11M 10H 10L 60M 90H", 0U, 60U, 90U); 595 TestPriorityCookieCase(cm.get(), "11M 10H 10L 60M 90H", 0U, 60U, 90U);
562 // Round 1 => none; round 2 => 10L, 21M; round 3 => none. 596 // Round 1 => none; round 2 => 10L, 21M; round 3 => none.
563 TestPriorityCookieCase(cm, "11M 10H 10L 90M 60H", 0U, 80U, 70U); 597 TestPriorityCookieCase(cm.get(), "11M 10H 10L 90M 60H", 0U, 80U, 70U);
564 } 598 }
565 599
566 // Function for creating a CM with a number of cookies in it, 600 // Function for creating a CM with a number of cookies in it,
567 // no store (and hence no ability to affect access time). 601 // no store (and hence no ability to affect access time).
568 CookieMonster* CreateMonsterForGC(int num_cookies) { 602 CookieMonster* CreateMonsterForGC(int num_cookies) {
569 CookieMonster* cm(new CookieMonster(NULL, NULL)); 603 CookieMonster* cm(new CookieMonster(NULL, NULL));
570 for (int i = 0; i < num_cookies; i++) { 604 for (int i = 0; i < num_cookies; i++) {
571 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); 605 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1");
572 } 606 }
573 return cm; 607 return cm;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 testing::Action<void(void)> action) { 792 testing::Action<void(void)> action) {
759 EXPECT_CALL(*this, Begin()).WillOnce(action); 793 EXPECT_CALL(*this, Begin()).WillOnce(action);
760 ExpectLoadCall(); 794 ExpectLoadCall();
761 ExpectLoadForKeyCall(key, false); 795 ExpectLoadForKeyCall(key, false);
762 Begin(); 796 Begin();
763 } 797 }
764 798
765 // Declares an expectation that PersistentCookieStore::Load will be called, 799 // Declares an expectation that PersistentCookieStore::Load will be called,
766 // saving the provided callback and sending a quit to the message loop. 800 // saving the provided callback and sending a quit to the message loop.
767 void ExpectLoadCall() { 801 void ExpectLoadCall() {
768 EXPECT_CALL(*persistent_store_, Load(testing::_)).WillOnce(testing::DoAll( 802 EXPECT_CALL(*persistent_store_.get(), Load(testing::_))
769 testing::SaveArg<0>(&loaded_callback_), 803 .WillOnce(testing::DoAll(testing::SaveArg<0>(&loaded_callback_),
770 QuitCurrentMessageLoop())); 804 QuitCurrentMessageLoop()));
771 } 805 }
772 806
773 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey 807 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey
774 // will be called, saving the provided callback and sending a quit to the 808 // will be called, saving the provided callback and sending a quit to the
775 // message loop. 809 // message loop.
776 void ExpectLoadForKeyCall(std::string key, bool quit_queue) { 810 void ExpectLoadForKeyCall(std::string key, bool quit_queue) {
777 if (quit_queue) 811 if (quit_queue)
778 EXPECT_CALL(*persistent_store_, LoadCookiesForKey(key, testing::_)). 812 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_))
779 WillOnce(testing::DoAll( 813 .WillOnce(
780 PushCallbackAction(&loaded_for_key_callbacks_), 814 testing::DoAll(PushCallbackAction(&loaded_for_key_callbacks_),
781 QuitCurrentMessageLoop())); 815 QuitCurrentMessageLoop()));
782 else 816 else
783 EXPECT_CALL(*persistent_store_, LoadCookiesForKey(key, testing::_)). 817 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_))
784 WillOnce(PushCallbackAction(&loaded_for_key_callbacks_)); 818 .WillOnce(PushCallbackAction(&loaded_for_key_callbacks_));
785 } 819 }
786 820
787 // Invokes the initial action. 821 // Invokes the initial action.
788 MOCK_METHOD0(Begin, void(void)); 822 MOCK_METHOD0(Begin, void(void));
789 823
790 // Returns the CookieMonster instance under test. 824 // Returns the CookieMonster instance under test.
791 CookieMonster& cookie_monster() { return *cookie_monster_; } 825 CookieMonster& cookie_monster() { return *cookie_monster_.get(); }
792 826
793 private: 827 private:
794 // Declares that mock expectations in this test suite are strictly ordered. 828 // Declares that mock expectations in this test suite are strictly ordered.
795 testing::InSequence in_sequence_; 829 testing::InSequence in_sequence_;
796 // Holds cookies to be returned from PersistentCookieStore::Load or 830 // Holds cookies to be returned from PersistentCookieStore::Load or
797 // PersistentCookieStore::LoadCookiesForKey. 831 // PersistentCookieStore::LoadCookiesForKey.
798 std::vector<CanonicalCookie*> loaded_cookies_; 832 std::vector<CanonicalCookie*> loaded_cookies_;
799 // Stores the callback passed from the CookieMonster to the 833 // Stores the callback passed from the CookieMonster to the
800 // PersistentCookieStore::Load 834 // PersistentCookieStore::Load
801 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; 835 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 QuitCurrentMessageLoop()); 1105 QuitCurrentMessageLoop());
1072 EXPECT_CALL(set_cookies_callback, Invoke(true)); 1106 EXPECT_CALL(set_cookies_callback, Invoke(true));
1073 EXPECT_CALL(delete_cookie_callback, Invoke()); 1107 EXPECT_CALL(delete_cookie_callback, Invoke());
1074 1108
1075 CompleteLoadingAndWait(); 1109 CompleteLoadingAndWait();
1076 } 1110 }
1077 1111
1078 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { 1112 TEST_F(CookieMonsterTest, TestCookieDeleteAll) {
1079 scoped_refptr<MockPersistentCookieStore> store( 1113 scoped_refptr<MockPersistentCookieStore> store(
1080 new MockPersistentCookieStore); 1114 new MockPersistentCookieStore);
1081 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 1115 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
1082 CookieOptions options; 1116 CookieOptions options;
1083 options.set_include_httponly(); 1117 options.set_include_httponly();
1084 1118
1085 EXPECT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); 1119 EXPECT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine));
1086 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); 1120 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_));
1087 1121
1088 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "C=D; httponly", options)); 1122 EXPECT_TRUE(
1089 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm, url_google_, options)); 1123 SetCookieWithOptions(cm.get(), url_google_, "C=D; httponly", options));
1124 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm.get(), url_google_, options));
1090 1125
1091 EXPECT_EQ(2, DeleteAll(cm)); 1126 EXPECT_EQ(2, DeleteAll(cm.get()));
1092 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); 1127 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options));
1093 EXPECT_EQ(0u, store->commands().size()); 1128 EXPECT_EQ(0u, store->commands().size());
1094 1129
1095 // Create a persistent cookie. 1130 // Create a persistent cookie.
1096 EXPECT_TRUE(SetCookie(cm, url_google_, 1131 EXPECT_TRUE(SetCookie(
1097 std::string(kValidCookieLine) + 1132 cm.get(),
1098 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); 1133 url_google_,
1134 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
1099 ASSERT_EQ(1u, store->commands().size()); 1135 ASSERT_EQ(1u, store->commands().size());
1100 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); 1136 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
1101 1137
1102 EXPECT_EQ(1, DeleteAll(cm)); // sync_to_store = true. 1138 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true.
1103 ASSERT_EQ(2u, store->commands().size()); 1139 ASSERT_EQ(2u, store->commands().size());
1104 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 1140 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
1105 1141
1106 EXPECT_EQ("", GetCookiesWithOptions(cm, url_google_, options)); 1142 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options));
1107 } 1143 }
1108 1144
1109 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { 1145 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) {
1110 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1146 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1111 Time now = Time::Now(); 1147 Time now = Time::Now();
1112 1148
1113 // Nothing has been added so nothing should be deleted. 1149 // Nothing has been added so nothing should be deleted.
1114 EXPECT_EQ(0, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99), 1150 EXPECT_EQ(
1115 Time())); 1151 0,
1152 DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time()));
1116 1153
1117 // Create 3 cookies with creation date of today, yesterday and the day before. 1154 // Create 3 cookies with creation date of today, yesterday and the day before.
1118 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now)); 1155 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now));
1119 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday", 1156 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday",
1120 now - TimeDelta::FromDays(1))); 1157 now - TimeDelta::FromDays(1)));
1121 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore", 1158 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore",
1122 now - TimeDelta::FromDays(2))); 1159 now - TimeDelta::FromDays(2)));
1123 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays", 1160 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays",
1124 now - TimeDelta::FromDays(3))); 1161 now - TimeDelta::FromDays(3)));
1125 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek", 1162 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek",
1126 now - TimeDelta::FromDays(7))); 1163 now - TimeDelta::FromDays(7)));
1127 1164
1128 // Try to delete threedays and the daybefore. 1165 // Try to delete threedays and the daybefore.
1129 EXPECT_EQ(2, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(3), 1166 EXPECT_EQ(2,
1130 now - TimeDelta::FromDays(1))); 1167 DeleteAllCreatedBetween(cm.get(),
1168 now - TimeDelta::FromDays(3),
1169 now - TimeDelta::FromDays(1)));
1131 1170
1132 // Try to delete yesterday, also make sure that delete_end is not 1171 // Try to delete yesterday, also make sure that delete_end is not
1133 // inclusive. 1172 // inclusive.
1134 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(2), 1173 EXPECT_EQ(
1135 now)); 1174 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now));
1136 1175
1137 // Make sure the delete_begin is inclusive. 1176 // Make sure the delete_begin is inclusive.
1138 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(7), 1177 EXPECT_EQ(
1139 now)); 1178 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now));
1140 1179
1141 // Delete the last (now) item. 1180 // Delete the last (now) item.
1142 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, Time(), Time())); 1181 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), Time(), Time()));
1143 1182
1144 // Really make sure everything is gone. 1183 // Really make sure everything is gone.
1145 EXPECT_EQ(0, DeleteAll(cm)); 1184 EXPECT_EQ(0, DeleteAll(cm.get()));
1146 } 1185 }
1147 1186
1148 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20; 1187 static const int kAccessDelayMs = kLastAccessThresholdMilliseconds + 20;
1149 1188
1150 TEST_F(CookieMonsterTest, TestLastAccess) { 1189 TEST_F(CookieMonsterTest, TestLastAccess) {
1151 scoped_refptr<CookieMonster> cm( 1190 scoped_refptr<CookieMonster> cm(
1152 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); 1191 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
1153 1192
1154 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); 1193 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
1155 const Time last_access_date(GetFirstCookieAccessDate(cm)); 1194 const Time last_access_date(GetFirstCookieAccessDate(cm.get()));
1156 1195
1157 // Reading the cookie again immediately shouldn't update the access date, 1196 // Reading the cookie again immediately shouldn't update the access date,
1158 // since we're inside the threshold. 1197 // since we're inside the threshold.
1159 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); 1198 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_));
1160 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); 1199 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get()));
1161 1200
1162 // Reading after a short wait should update the access date. 1201 // Reading after a short wait should update the access date.
1163 base::PlatformThread::Sleep( 1202 base::PlatformThread::Sleep(
1164 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); 1203 base::TimeDelta::FromMilliseconds(kAccessDelayMs));
1165 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); 1204 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_));
1166 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm)); 1205 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm.get()));
1167 } 1206 }
1168 1207
1169 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { 1208 TEST_F(CookieMonsterTest, TestHostGarbageCollection) {
1170 TestHostGarbageCollectHelper(); 1209 TestHostGarbageCollectHelper();
1171 } 1210 }
1172 1211
1173 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) { 1212 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) {
1174 TestPriorityAwareGarbageCollectHelper(); 1213 TestPriorityAwareGarbageCollectHelper();
1175 } 1214 }
1176 1215
1177 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) { 1216 TEST_F(CookieMonsterTest, TestDeleteSingleCookie) {
1178 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1217 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1179 1218
1180 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); 1219 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
1181 EXPECT_TRUE(SetCookie(cm, url_google_, "C=D")); 1220 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D"));
1182 EXPECT_TRUE(SetCookie(cm, url_google_, "E=F")); 1221 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F"));
1183 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); 1222 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_));
1184 1223
1185 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google_.host(), "C")); 1224 EXPECT_TRUE(FindAndDeleteCookie(cm.get(), url_google_.host(), "C"));
1186 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); 1225 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_));
1187 1226
1188 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); 1227 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E"));
1189 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); 1228 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_));
1190 } 1229 }
1191 1230
1192 TEST_F(CookieMonsterTest, SetCookieableSchemes) { 1231 TEST_F(CookieMonsterTest, SetCookieableSchemes) {
1193 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1232 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1194 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); 1233 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL));
1195 1234
1196 // Only cm_foo should allow foo:// cookies. 1235 // Only cm_foo should allow foo:// cookies.
1197 const char* kSchemes[] = {"foo"}; 1236 const char* kSchemes[] = {"foo"};
1198 cm_foo->SetCookieableSchemes(kSchemes, 1); 1237 cm_foo->SetCookieableSchemes(kSchemes, 1);
1199 1238
1200 GURL foo_url("foo://host/path"); 1239 GURL foo_url("foo://host/path");
1201 GURL http_url("http://host/path"); 1240 GURL http_url("http://host/path");
1202 1241
1203 EXPECT_TRUE(SetCookie(cm, http_url, "x=1")); 1242 EXPECT_TRUE(SetCookie(cm.get(), http_url, "x=1"));
1204 EXPECT_FALSE(SetCookie(cm, foo_url, "x=1")); 1243 EXPECT_FALSE(SetCookie(cm.get(), foo_url, "x=1"));
1205 EXPECT_TRUE(SetCookie(cm_foo, foo_url, "x=1")); 1244 EXPECT_TRUE(SetCookie(cm_foo.get(), foo_url, "x=1"));
1206 EXPECT_FALSE(SetCookie(cm_foo, http_url, "x=1")); 1245 EXPECT_FALSE(SetCookie(cm_foo.get(), http_url, "x=1"));
1207 } 1246 }
1208 1247
1209 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { 1248 TEST_F(CookieMonsterTest, GetAllCookiesForURL) {
1210 scoped_refptr<CookieMonster> cm( 1249 scoped_refptr<CookieMonster> cm(
1211 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); 1250 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds));
1212 1251
1213 // Create an httponly cookie. 1252 // Create an httponly cookie.
1214 CookieOptions options; 1253 CookieOptions options;
1215 options.set_include_httponly(); 1254 options.set_include_httponly();
1216 1255
1217 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B; httponly", options)); 1256 EXPECT_TRUE(
1218 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, 1257 SetCookieWithOptions(cm.get(), url_google_, "A=B; httponly", options));
1219 "C=D; domain=.google.izzle", 1258 EXPECT_TRUE(SetCookieWithOptions(
1220 options)); 1259 cm.get(), url_google_, "C=D; domain=.google.izzle", options));
1221 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_secure_, 1260 EXPECT_TRUE(SetCookieWithOptions(cm.get(),
1261 url_google_secure_,
1222 "E=F; domain=.google.izzle; secure", 1262 "E=F; domain=.google.izzle; secure",
1223 options)); 1263 options));
1224 1264
1225 const Time last_access_date(GetFirstCookieAccessDate(cm)); 1265 const Time last_access_date(GetFirstCookieAccessDate(cm.get()));
1226 1266
1227 base::PlatformThread::Sleep( 1267 base::PlatformThread::Sleep(
1228 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); 1268 base::TimeDelta::FromMilliseconds(kAccessDelayMs));
1229 1269
1230 // Check cookies for url. 1270 // Check cookies for url.
1231 CookieList cookies = GetAllCookiesForURL(cm, url_google_); 1271 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_);
1232 CookieList::iterator it = cookies.begin(); 1272 CookieList::iterator it = cookies.begin();
1233 1273
1234 ASSERT_TRUE(it != cookies.end()); 1274 ASSERT_TRUE(it != cookies.end());
1235 EXPECT_EQ("www.google.izzle", it->Domain()); 1275 EXPECT_EQ("www.google.izzle", it->Domain());
1236 EXPECT_EQ("A", it->Name()); 1276 EXPECT_EQ("A", it->Name());
1237 1277
1238 ASSERT_TRUE(++it != cookies.end()); 1278 ASSERT_TRUE(++it != cookies.end());
1239 EXPECT_EQ(".google.izzle", it->Domain()); 1279 EXPECT_EQ(".google.izzle", it->Domain());
1240 EXPECT_EQ("C", it->Name()); 1280 EXPECT_EQ("C", it->Name());
1241 1281
1242 ASSERT_TRUE(++it == cookies.end()); 1282 ASSERT_TRUE(++it == cookies.end());
1243 1283
1244 // Check cookies for url excluding http-only cookies. 1284 // Check cookies for url excluding http-only cookies.
1245 cookies = 1285 cookies =
1246 GetAllCookiesForURLWithOptions(cm, url_google_, CookieOptions()); 1286 GetAllCookiesForURLWithOptions(cm.get(), url_google_, CookieOptions());
1247 it = cookies.begin(); 1287 it = cookies.begin();
1248 1288
1249 ASSERT_TRUE(it != cookies.end()); 1289 ASSERT_TRUE(it != cookies.end());
1250 EXPECT_EQ(".google.izzle", it->Domain()); 1290 EXPECT_EQ(".google.izzle", it->Domain());
1251 EXPECT_EQ("C", it->Name()); 1291 EXPECT_EQ("C", it->Name());
1252 1292
1253 ASSERT_TRUE(++it == cookies.end()); 1293 ASSERT_TRUE(++it == cookies.end());
1254 1294
1255 // Test secure cookies. 1295 // Test secure cookies.
1256 cookies = GetAllCookiesForURL(cm, url_google_secure_); 1296 cookies = GetAllCookiesForURL(cm.get(), url_google_secure_);
1257 it = cookies.begin(); 1297 it = cookies.begin();
1258 1298
1259 ASSERT_TRUE(it != cookies.end()); 1299 ASSERT_TRUE(it != cookies.end());
1260 EXPECT_EQ("www.google.izzle", it->Domain()); 1300 EXPECT_EQ("www.google.izzle", it->Domain());
1261 EXPECT_EQ("A", it->Name()); 1301 EXPECT_EQ("A", it->Name());
1262 1302
1263 ASSERT_TRUE(++it != cookies.end()); 1303 ASSERT_TRUE(++it != cookies.end());
1264 EXPECT_EQ(".google.izzle", it->Domain()); 1304 EXPECT_EQ(".google.izzle", it->Domain());
1265 EXPECT_EQ("C", it->Name()); 1305 EXPECT_EQ("C", it->Name());
1266 1306
1267 ASSERT_TRUE(++it != cookies.end()); 1307 ASSERT_TRUE(++it != cookies.end());
1268 EXPECT_EQ(".google.izzle", it->Domain()); 1308 EXPECT_EQ(".google.izzle", it->Domain());
1269 EXPECT_EQ("E", it->Name()); 1309 EXPECT_EQ("E", it->Name());
1270 1310
1271 ASSERT_TRUE(++it == cookies.end()); 1311 ASSERT_TRUE(++it == cookies.end());
1272 1312
1273 // Reading after a short wait should not update the access date. 1313 // Reading after a short wait should not update the access date.
1274 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); 1314 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get()));
1275 } 1315 }
1276 1316
1277 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { 1317 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) {
1278 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1318 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1279 CookieOptions options; 1319 CookieOptions options;
1280 1320
1281 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_foo_, 1321 EXPECT_TRUE(SetCookieWithOptions(
1282 "A=B; path=/foo;", options)); 1322 cm.get(), url_google_foo_, "A=B; path=/foo;", options));
1283 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_bar_, 1323 EXPECT_TRUE(SetCookieWithOptions(
1284 "C=D; path=/bar;", options)); 1324 cm.get(), url_google_bar_, "C=D; path=/bar;", options));
1285 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, 1325 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "E=F;", options));
1286 "E=F;", options));
1287 1326
1288 CookieList cookies = GetAllCookiesForURL(cm, url_google_foo_); 1327 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_);
1289 CookieList::iterator it = cookies.begin(); 1328 CookieList::iterator it = cookies.begin();
1290 1329
1291 ASSERT_TRUE(it != cookies.end()); 1330 ASSERT_TRUE(it != cookies.end());
1292 EXPECT_EQ("A", it->Name()); 1331 EXPECT_EQ("A", it->Name());
1293 EXPECT_EQ("/foo", it->Path()); 1332 EXPECT_EQ("/foo", it->Path());
1294 1333
1295 ASSERT_TRUE(++it != cookies.end()); 1334 ASSERT_TRUE(++it != cookies.end());
1296 EXPECT_EQ("E", it->Name()); 1335 EXPECT_EQ("E", it->Name());
1297 EXPECT_EQ("/", it->Path()); 1336 EXPECT_EQ("/", it->Path());
1298 1337
1299 ASSERT_TRUE(++it == cookies.end()); 1338 ASSERT_TRUE(++it == cookies.end());
1300 1339
1301 cookies = GetAllCookiesForURL(cm, url_google_bar_); 1340 cookies = GetAllCookiesForURL(cm.get(), url_google_bar_);
1302 it = cookies.begin(); 1341 it = cookies.begin();
1303 1342
1304 ASSERT_TRUE(it != cookies.end()); 1343 ASSERT_TRUE(it != cookies.end());
1305 EXPECT_EQ("C", it->Name()); 1344 EXPECT_EQ("C", it->Name());
1306 EXPECT_EQ("/bar", it->Path()); 1345 EXPECT_EQ("/bar", it->Path());
1307 1346
1308 ASSERT_TRUE(++it != cookies.end()); 1347 ASSERT_TRUE(++it != cookies.end());
1309 EXPECT_EQ("E", it->Name()); 1348 EXPECT_EQ("E", it->Name());
1310 EXPECT_EQ("/", it->Path()); 1349 EXPECT_EQ("/", it->Path());
1311 1350
1312 ASSERT_TRUE(++it == cookies.end()); 1351 ASSERT_TRUE(++it == cookies.end());
1313 } 1352 }
1314 1353
1315 TEST_F(CookieMonsterTest, DeleteCookieByName) { 1354 TEST_F(CookieMonsterTest, DeleteCookieByName) {
1316 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1355 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1317 1356
1318 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A1; path=/")); 1357 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A1; path=/"));
1319 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A2; path=/foo")); 1358 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A2; path=/foo"));
1320 EXPECT_TRUE(SetCookie(cm, url_google_, "A=A3; path=/bar")); 1359 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/bar"));
1321 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B1; path=/")); 1360 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/"));
1322 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B2; path=/foo")); 1361 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo"));
1323 EXPECT_TRUE(SetCookie(cm, url_google_, "B=B3; path=/bar")); 1362 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/bar"));
1324 1363
1325 DeleteCookie(cm, GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); 1364 DeleteCookie(cm.get(), GURL(std::string(kUrlGoogle) + "/foo/bar"), "A");
1326 1365
1327 CookieList cookies = GetAllCookies(cm); 1366 CookieList cookies = GetAllCookies(cm.get());
1328 size_t expected_size = 4; 1367 size_t expected_size = 4;
1329 EXPECT_EQ(expected_size, cookies.size()); 1368 EXPECT_EQ(expected_size, cookies.size());
1330 for (CookieList::iterator it = cookies.begin(); 1369 for (CookieList::iterator it = cookies.begin();
1331 it != cookies.end(); ++it) { 1370 it != cookies.end(); ++it) {
1332 EXPECT_NE("A1", it->Value()); 1371 EXPECT_NE("A1", it->Value());
1333 EXPECT_NE("A2", it->Value()); 1372 EXPECT_NE("A2", it->Value());
1334 } 1373 }
1335 } 1374 }
1336 1375
1337 TEST_F(CookieMonsterTest, InitializeFromCookieMonster) { 1376 TEST_F(CookieMonsterTest, InitializeFromCookieMonster) {
1338 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL)); 1377 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL));
1339 CookieOptions options; 1378 CookieOptions options;
1340 1379
1341 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_, 1380 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_,
1342 "A1=B; path=/foo;", 1381 "A1=B; path=/foo;",
1343 options)); 1382 options));
1344 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_, 1383 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_,
1345 "A2=D; path=/bar;", 1384 "A2=D; path=/bar;",
1346 options)); 1385 options));
1347 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, 1386 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_,
1348 "A3=F;", 1387 "A3=F;",
1349 options)); 1388 options));
1350 1389
1351 CookieList cookies_1 = GetAllCookies(cm_1); 1390 CookieList cookies_1 = GetAllCookies(cm_1.get());
1352 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL)); 1391 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL));
1353 ASSERT_TRUE(cm_2->InitializeFrom(cookies_1)); 1392 ASSERT_TRUE(cm_2->InitializeFrom(cookies_1));
1354 CookieList cookies_2 = GetAllCookies(cm_2); 1393 CookieList cookies_2 = GetAllCookies(cm_2.get());
1355 1394
1356 size_t expected_size = 3; 1395 size_t expected_size = 3;
1357 EXPECT_EQ(expected_size, cookies_2.size()); 1396 EXPECT_EQ(expected_size, cookies_2.size());
1358 1397
1359 CookieList::iterator it = cookies_2.begin(); 1398 CookieList::iterator it = cookies_2.begin();
1360 1399
1361 ASSERT_TRUE(it != cookies_2.end()); 1400 ASSERT_TRUE(it != cookies_2.end());
1362 EXPECT_EQ("A1", it->Name()); 1401 EXPECT_EQ("A1", it->Name());
1363 EXPECT_EQ("/foo", it->Path()); 1402 EXPECT_EQ("/foo", it->Path());
1364 1403
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 1467
1429 // Insert 1 cookie with name "Y" on path "/". 1468 // Insert 1 cookie with name "Y" on path "/".
1430 AddCookieToList("www.google.com", 1469 AddCookieToList("www.google.com",
1431 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1470 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1432 Time::Now() + TimeDelta::FromDays(10), 1471 Time::Now() + TimeDelta::FromDays(10),
1433 &initial_cookies); 1472 &initial_cookies);
1434 1473
1435 // Inject our initial cookies into the mock PersistentCookieStore. 1474 // Inject our initial cookies into the mock PersistentCookieStore.
1436 store->SetLoadExpectation(true, initial_cookies); 1475 store->SetLoadExpectation(true, initial_cookies);
1437 1476
1438 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 1477 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
1439 1478
1440 // Verify that duplicates were not imported for path "/". 1479 // Verify that duplicates were not imported for path "/".
1441 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). 1480 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4).
1442 EXPECT_EQ("X=3; Y=a", GetCookies(cm, GURL("http://www.google.com/"))); 1481 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/")));
1443 1482
1444 // Verify that same-named cookie on a different path ("/x2") didn't get 1483 // Verify that same-named cookie on a different path ("/x2") didn't get
1445 // messed up. 1484 // messed up.
1446 EXPECT_EQ("X=a1; X=3; Y=a", 1485 EXPECT_EQ("X=a1; X=3; Y=a",
1447 GetCookies(cm, GURL("http://www.google.com/2/x"))); 1486 GetCookies(cm.get(), GURL("http://www.google.com/2/x")));
1448 1487
1449 // Verify that the PersistentCookieStore was told to kill its 4 duplicates. 1488 // Verify that the PersistentCookieStore was told to kill its 4 duplicates.
1450 ASSERT_EQ(4u, store->commands().size()); 1489 ASSERT_EQ(4u, store->commands().size());
1451 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type); 1490 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type);
1452 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 1491 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
1453 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); 1492 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type);
1454 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); 1493 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
1455 } 1494 }
1456 1495
1457 // Tests importing from a persistent cookie store that contains cookies 1496 // Tests importing from a persistent cookie store that contains cookies
(...skipping 19 matching lines...) Expand all
1477 AddCookieToList("www.google.com", "X=4; path=/", now, &initial_cookies); 1516 AddCookieToList("www.google.com", "X=4; path=/", now, &initial_cookies);
1478 1517
1479 AddCookieToList("www.google.com", "Y=1; path=/", earlier, &initial_cookies); 1518 AddCookieToList("www.google.com", "Y=1; path=/", earlier, &initial_cookies);
1480 AddCookieToList("www.google.com", "Y=2; path=/", earlier, &initial_cookies); 1519 AddCookieToList("www.google.com", "Y=2; path=/", earlier, &initial_cookies);
1481 AddCookieToList("www.google.com", "Y=3; path=/", earlier, &initial_cookies); 1520 AddCookieToList("www.google.com", "Y=3; path=/", earlier, &initial_cookies);
1482 AddCookieToList("www.google.com", "Y=4; path=/", earlier, &initial_cookies); 1521 AddCookieToList("www.google.com", "Y=4; path=/", earlier, &initial_cookies);
1483 1522
1484 // Inject our initial cookies into the mock PersistentCookieStore. 1523 // Inject our initial cookies into the mock PersistentCookieStore.
1485 store->SetLoadExpectation(true, initial_cookies); 1524 store->SetLoadExpectation(true, initial_cookies);
1486 1525
1487 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 1526 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
1488 1527
1489 CookieList list(GetAllCookies(cm)); 1528 CookieList list(GetAllCookies(cm.get()));
1490 EXPECT_EQ(2U, list.size()); 1529 EXPECT_EQ(2U, list.size());
1491 // Confirm that we have one of each. 1530 // Confirm that we have one of each.
1492 std::string name1(list[0].Name()); 1531 std::string name1(list[0].Name());
1493 std::string name2(list[1].Name()); 1532 std::string name2(list[1].Name());
1494 EXPECT_TRUE(name1 == "X" || name2 == "X"); 1533 EXPECT_TRUE(name1 == "X" || name2 == "X");
1495 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); 1534 EXPECT_TRUE(name1 == "Y" || name2 == "Y");
1496 EXPECT_NE(name1, name2); 1535 EXPECT_NE(name1, name2);
1497 } 1536 }
1498 1537
1499 TEST_F(CookieMonsterTest, Delegate) { 1538 TEST_F(CookieMonsterTest, Delegate) {
1500 scoped_refptr<MockPersistentCookieStore> store( 1539 scoped_refptr<MockPersistentCookieStore> store(
1501 new MockPersistentCookieStore); 1540 new MockPersistentCookieStore);
1502 scoped_refptr<MockCookieMonsterDelegate> delegate( 1541 scoped_refptr<MockCookieMonsterDelegate> delegate(
1503 new MockCookieMonsterDelegate); 1542 new MockCookieMonsterDelegate);
1504 scoped_refptr<CookieMonster> cm(new CookieMonster(store, delegate)); 1543 scoped_refptr<CookieMonster> cm(
1544 new CookieMonster(store.get(), delegate.get()));
1505 1545
1506 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); 1546 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
1507 EXPECT_TRUE(SetCookie(cm, url_google_, "C=D")); 1547 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D"));
1508 EXPECT_TRUE(SetCookie(cm, url_google_, "E=F")); 1548 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F"));
1509 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm, url_google_)); 1549 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_));
1510 ASSERT_EQ(3u, delegate->changes().size()); 1550 ASSERT_EQ(3u, delegate->changes().size());
1511 EXPECT_FALSE(delegate->changes()[0].second); 1551 EXPECT_FALSE(delegate->changes()[0].second);
1512 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); 1552 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain());
1513 EXPECT_EQ("A", delegate->changes()[0].first.Name()); 1553 EXPECT_EQ("A", delegate->changes()[0].first.Name());
1514 EXPECT_EQ("B", delegate->changes()[0].first.Value()); 1554 EXPECT_EQ("B", delegate->changes()[0].first.Value());
1515 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); 1555 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain());
1516 EXPECT_FALSE(delegate->changes()[1].second); 1556 EXPECT_FALSE(delegate->changes()[1].second);
1517 EXPECT_EQ("C", delegate->changes()[1].first.Name()); 1557 EXPECT_EQ("C", delegate->changes()[1].first.Name());
1518 EXPECT_EQ("D", delegate->changes()[1].first.Value()); 1558 EXPECT_EQ("D", delegate->changes()[1].first.Value());
1519 EXPECT_EQ(url_google_.host(), delegate->changes()[2].first.Domain()); 1559 EXPECT_EQ(url_google_.host(), delegate->changes()[2].first.Domain());
1520 EXPECT_FALSE(delegate->changes()[2].second); 1560 EXPECT_FALSE(delegate->changes()[2].second);
1521 EXPECT_EQ("E", delegate->changes()[2].first.Name()); 1561 EXPECT_EQ("E", delegate->changes()[2].first.Name());
1522 EXPECT_EQ("F", delegate->changes()[2].first.Value()); 1562 EXPECT_EQ("F", delegate->changes()[2].first.Value());
1523 delegate->reset(); 1563 delegate->reset();
1524 1564
1525 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google_.host(), "C")); 1565 EXPECT_TRUE(FindAndDeleteCookie(cm.get(), url_google_.host(), "C"));
1526 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); 1566 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_));
1527 ASSERT_EQ(1u, delegate->changes().size()); 1567 ASSERT_EQ(1u, delegate->changes().size());
1528 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); 1568 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain());
1529 EXPECT_TRUE(delegate->changes()[0].second); 1569 EXPECT_TRUE(delegate->changes()[0].second);
1530 EXPECT_EQ("C", delegate->changes()[0].first.Name()); 1570 EXPECT_EQ("C", delegate->changes()[0].first.Name());
1531 EXPECT_EQ("D", delegate->changes()[0].first.Value()); 1571 EXPECT_EQ("D", delegate->changes()[0].first.Value());
1532 delegate->reset(); 1572 delegate->reset();
1533 1573
1534 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); 1574 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E"));
1535 EXPECT_EQ("A=B; E=F", GetCookies(cm, url_google_)); 1575 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_));
1536 EXPECT_EQ(0u, delegate->changes().size()); 1576 EXPECT_EQ(0u, delegate->changes().size());
1537 1577
1538 // Insert a cookie "a" for path "/path1" 1578 // Insert a cookie "a" for path "/path1"
1539 EXPECT_TRUE( 1579 EXPECT_TRUE(SetCookie(cm.get(),
1540 SetCookie(cm, url_google_, "a=val1; path=/path1; " 1580 url_google_,
1541 "expires=Mon, 18-Apr-22 22:50:13 GMT")); 1581 "a=val1; path=/path1; "
1582 "expires=Mon, 18-Apr-22 22:50:13 GMT"));
1542 ASSERT_EQ(1u, store->commands().size()); 1583 ASSERT_EQ(1u, store->commands().size());
1543 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); 1584 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
1544 ASSERT_EQ(1u, delegate->changes().size()); 1585 ASSERT_EQ(1u, delegate->changes().size());
1545 EXPECT_FALSE(delegate->changes()[0].second); 1586 EXPECT_FALSE(delegate->changes()[0].second);
1546 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); 1587 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain());
1547 EXPECT_EQ("a", delegate->changes()[0].first.Name()); 1588 EXPECT_EQ("a", delegate->changes()[0].first.Name());
1548 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); 1589 EXPECT_EQ("val1", delegate->changes()[0].first.Value());
1549 delegate->reset(); 1590 delegate->reset();
1550 1591
1551 // Insert a cookie "a" for path "/path1", that is httponly. This should 1592 // Insert a cookie "a" for path "/path1", that is httponly. This should
1552 // overwrite the non-http-only version. 1593 // overwrite the non-http-only version.
1553 CookieOptions allow_httponly; 1594 CookieOptions allow_httponly;
1554 allow_httponly.set_include_httponly(); 1595 allow_httponly.set_include_httponly();
1555 EXPECT_TRUE( 1596 EXPECT_TRUE(SetCookieWithOptions(cm.get(),
1556 SetCookieWithOptions(cm, url_google_, 1597 url_google_,
1557 "a=val2; path=/path1; httponly; " 1598 "a=val2; path=/path1; httponly; "
1558 "expires=Mon, 18-Apr-22 22:50:14 GMT", 1599 "expires=Mon, 18-Apr-22 22:50:14 GMT",
1559 allow_httponly)); 1600 allow_httponly));
1560 ASSERT_EQ(3u, store->commands().size()); 1601 ASSERT_EQ(3u, store->commands().size());
1561 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 1602 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
1562 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); 1603 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
1563 ASSERT_EQ(2u, delegate->changes().size()); 1604 ASSERT_EQ(2u, delegate->changes().size());
1564 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); 1605 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain());
1565 EXPECT_TRUE(delegate->changes()[0].second); 1606 EXPECT_TRUE(delegate->changes()[0].second);
1566 EXPECT_EQ("a", delegate->changes()[0].first.Name()); 1607 EXPECT_EQ("a", delegate->changes()[0].first.Name());
1567 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); 1608 EXPECT_EQ("val1", delegate->changes()[0].first.Value());
1568 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); 1609 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain());
1569 EXPECT_FALSE(delegate->changes()[1].second); 1610 EXPECT_FALSE(delegate->changes()[1].second);
1570 EXPECT_EQ("a", delegate->changes()[1].first.Name()); 1611 EXPECT_EQ("a", delegate->changes()[1].first.Name());
1571 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); 1612 EXPECT_EQ("val2", delegate->changes()[1].first.Value());
1572 delegate->reset(); 1613 delegate->reset();
1573 } 1614 }
1574 1615
1575 TEST_F(CookieMonsterTest, SetCookieWithDetails) { 1616 TEST_F(CookieMonsterTest, SetCookieWithDetails) {
1576 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1617 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1577 1618
1578 EXPECT_TRUE(SetCookieWithDetails( 1619 EXPECT_TRUE(SetCookieWithDetails(cm.get(),
1579 cm, url_google_foo_, "A", "B", std::string(), "/foo", base::Time(), 1620 url_google_foo_,
1580 false, false, COOKIE_PRIORITY_DEFAULT)); 1621 "A",
1581 EXPECT_TRUE(SetCookieWithDetails( 1622 "B",
1582 cm, url_google_bar_, "C", "D", "google.izzle", "/bar", base::Time(), 1623 std::string(),
1583 false, true, COOKIE_PRIORITY_DEFAULT)); 1624 "/foo",
1584 EXPECT_TRUE(SetCookieWithDetails( 1625 base::Time(),
1585 cm, url_google_, "E", "F", std::string(), std::string(), base::Time(), 1626 false,
1586 true, false, COOKIE_PRIORITY_DEFAULT)); 1627 false,
1628 COOKIE_PRIORITY_DEFAULT));
1629 EXPECT_TRUE(SetCookieWithDetails(cm.get(),
1630 url_google_bar_,
1631 "C",
1632 "D",
1633 "google.izzle",
1634 "/bar",
1635 base::Time(),
1636 false,
1637 true,
1638 COOKIE_PRIORITY_DEFAULT));
1639 EXPECT_TRUE(SetCookieWithDetails(cm.get(),
1640 url_google_,
1641 "E",
1642 "F",
1643 std::string(),
1644 std::string(),
1645 base::Time(),
1646 true,
1647 false,
1648 COOKIE_PRIORITY_DEFAULT));
1587 1649
1588 // Test that malformed attributes fail to set the cookie. 1650 // Test that malformed attributes fail to set the cookie.
1589 EXPECT_FALSE(SetCookieWithDetails( 1651 EXPECT_FALSE(SetCookieWithDetails(cm.get(),
1590 cm, url_google_foo_, " A", "B", std::string(), "/foo", base::Time(), 1652 url_google_foo_,
1591 false, false, COOKIE_PRIORITY_DEFAULT)); 1653 " A",
1592 EXPECT_FALSE(SetCookieWithDetails( 1654 "B",
1593 cm, url_google_foo_, "A;", "B", std::string(), "/foo", base::Time(), 1655 std::string(),
1594 false, false, COOKIE_PRIORITY_DEFAULT)); 1656 "/foo",
1595 EXPECT_FALSE(SetCookieWithDetails( 1657 base::Time(),
1596 cm, url_google_foo_, "A=", "B", std::string(), "/foo", base::Time(), 1658 false,
1597 false, false, COOKIE_PRIORITY_DEFAULT)); 1659 false,
1598 EXPECT_FALSE(SetCookieWithDetails( 1660 COOKIE_PRIORITY_DEFAULT));
1599 cm, url_google_foo_, "A", "B", "google.ozzzzzzle", "foo", base::Time(), 1661 EXPECT_FALSE(SetCookieWithDetails(cm.get(),
1600 false, false, COOKIE_PRIORITY_DEFAULT)); 1662 url_google_foo_,
1601 EXPECT_FALSE(SetCookieWithDetails( 1663 "A;",
1602 cm, url_google_foo_, "A=", "B", std::string(), "foo", base::Time(), 1664 "B",
1603 false, false, COOKIE_PRIORITY_DEFAULT)); 1665 std::string(),
1666 "/foo",
1667 base::Time(),
1668 false,
1669 false,
1670 COOKIE_PRIORITY_DEFAULT));
1671 EXPECT_FALSE(SetCookieWithDetails(cm.get(),
1672 url_google_foo_,
1673 "A=",
1674 "B",
1675 std::string(),
1676 "/foo",
1677 base::Time(),
1678 false,
1679 false,
1680 COOKIE_PRIORITY_DEFAULT));
1681 EXPECT_FALSE(SetCookieWithDetails(cm.get(),
1682 url_google_foo_,
1683 "A",
1684 "B",
1685 "google.ozzzzzzle",
1686 "foo",
1687 base::Time(),
1688 false,
1689 false,
1690 COOKIE_PRIORITY_DEFAULT));
1691 EXPECT_FALSE(SetCookieWithDetails(cm.get(),
1692 url_google_foo_,
1693 "A=",
1694 "B",
1695 std::string(),
1696 "foo",
1697 base::Time(),
1698 false,
1699 false,
1700 COOKIE_PRIORITY_DEFAULT));
1604 1701
1605 CookieList cookies = GetAllCookiesForURL(cm, url_google_foo_); 1702 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_);
1606 CookieList::iterator it = cookies.begin(); 1703 CookieList::iterator it = cookies.begin();
1607 1704
1608 ASSERT_TRUE(it != cookies.end()); 1705 ASSERT_TRUE(it != cookies.end());
1609 EXPECT_EQ("A", it->Name()); 1706 EXPECT_EQ("A", it->Name());
1610 EXPECT_EQ("B", it->Value()); 1707 EXPECT_EQ("B", it->Value());
1611 EXPECT_EQ("www.google.izzle", it->Domain()); 1708 EXPECT_EQ("www.google.izzle", it->Domain());
1612 EXPECT_EQ("/foo", it->Path()); 1709 EXPECT_EQ("/foo", it->Path());
1613 EXPECT_FALSE(it->IsPersistent()); 1710 EXPECT_FALSE(it->IsPersistent());
1614 EXPECT_FALSE(it->IsSecure()); 1711 EXPECT_FALSE(it->IsSecure());
1615 EXPECT_FALSE(it->IsHttpOnly()); 1712 EXPECT_FALSE(it->IsHttpOnly());
1616 1713
1617 ASSERT_TRUE(++it == cookies.end()); 1714 ASSERT_TRUE(++it == cookies.end());
1618 1715
1619 cookies = GetAllCookiesForURL(cm, url_google_bar_); 1716 cookies = GetAllCookiesForURL(cm.get(), url_google_bar_);
1620 it = cookies.begin(); 1717 it = cookies.begin();
1621 1718
1622 ASSERT_TRUE(it != cookies.end()); 1719 ASSERT_TRUE(it != cookies.end());
1623 EXPECT_EQ("C", it->Name()); 1720 EXPECT_EQ("C", it->Name());
1624 EXPECT_EQ("D", it->Value()); 1721 EXPECT_EQ("D", it->Value());
1625 EXPECT_EQ(".google.izzle", it->Domain()); 1722 EXPECT_EQ(".google.izzle", it->Domain());
1626 EXPECT_EQ("/bar", it->Path()); 1723 EXPECT_EQ("/bar", it->Path());
1627 EXPECT_FALSE(it->IsSecure()); 1724 EXPECT_FALSE(it->IsSecure());
1628 EXPECT_TRUE(it->IsHttpOnly()); 1725 EXPECT_TRUE(it->IsHttpOnly());
1629 1726
1630 ASSERT_TRUE(++it == cookies.end()); 1727 ASSERT_TRUE(++it == cookies.end());
1631 1728
1632 cookies = GetAllCookiesForURL(cm, url_google_secure_); 1729 cookies = GetAllCookiesForURL(cm.get(), url_google_secure_);
1633 it = cookies.begin(); 1730 it = cookies.begin();
1634 1731
1635 ASSERT_TRUE(it != cookies.end()); 1732 ASSERT_TRUE(it != cookies.end());
1636 EXPECT_EQ("E", it->Name()); 1733 EXPECT_EQ("E", it->Name());
1637 EXPECT_EQ("F", it->Value()); 1734 EXPECT_EQ("F", it->Value());
1638 EXPECT_EQ("/", it->Path()); 1735 EXPECT_EQ("/", it->Path());
1639 EXPECT_EQ("www.google.izzle", it->Domain()); 1736 EXPECT_EQ("www.google.izzle", it->Domain());
1640 EXPECT_TRUE(it->IsSecure()); 1737 EXPECT_TRUE(it->IsSecure());
1641 EXPECT_FALSE(it->IsHttpOnly()); 1738 EXPECT_FALSE(it->IsHttpOnly());
1642 1739
1643 ASSERT_TRUE(++it == cookies.end()); 1740 ASSERT_TRUE(++it == cookies.end());
1644 } 1741 }
1645 1742
1646 TEST_F(CookieMonsterTest, DeleteAllForHost) { 1743 TEST_F(CookieMonsterTest, DeleteAllForHost) {
1647 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1744 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1648 1745
1649 // Test probes: 1746 // Test probes:
1650 // * Non-secure URL, mid-level (http://w.c.b.a) 1747 // * Non-secure URL, mid-level (http://w.c.b.a)
1651 // * Secure URL, mid-level (https://w.c.b.a) 1748 // * Secure URL, mid-level (https://w.c.b.a)
1652 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx) 1749 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx)
1653 // All three tests should nuke only the midlevel host cookie, 1750 // All three tests should nuke only the midlevel host cookie,
1654 // the http_only cookie, the host secure cookie, and the two host 1751 // the http_only cookie, the host secure cookie, and the two host
1655 // path cookies. http_only, secure, and paths are ignored by 1752 // path cookies. http_only, secure, and paths are ignored by
1656 // this call, and domain cookies arent touched. 1753 // this call, and domain cookies arent touched.
1657 PopulateCmForDeleteAllForHost(cm); 1754 PopulateCmForDeleteAllForHost(cm);
1658 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", 1755 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1659 GetCookies(cm, GURL(kTopLevelDomainPlus3))); 1756 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3)));
1660 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", 1757 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X",
1661 GetCookies(cm, GURL(kTopLevelDomainPlus2Secure))); 1758 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1662 EXPECT_EQ("dom_1=X; host_1=X", GetCookies(cm, GURL(kTopLevelDomainPlus1))); 1759 EXPECT_EQ("dom_1=X; host_1=X",
1760 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
1663 EXPECT_EQ("dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " 1761 EXPECT_EQ("dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; "
1664 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", 1762 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X",
1665 GetCookies(cm, GURL(kTopLevelDomainPlus2Secure + 1763 GetCookies(cm.get(),
1666 std::string("/dir1/dir2/xxx")))); 1764 GURL(kTopLevelDomainPlus2Secure +
1765 std::string("/dir1/dir2/xxx"))));
1667 1766
1668 EXPECT_EQ(5, DeleteAllForHost(cm, GURL(kTopLevelDomainPlus2))); 1767 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2)));
1669 EXPECT_EQ(8U, GetAllCookies(cm).size()); 1768 EXPECT_EQ(8U, GetAllCookies(cm.get()).size());
1670 1769
1671 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", 1770 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1672 GetCookies(cm, GURL(kTopLevelDomainPlus3))); 1771 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3)));
1673 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", 1772 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1674 GetCookies(cm, GURL(kTopLevelDomainPlus2Secure))); 1773 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1675 EXPECT_EQ("dom_1=X; host_1=X", GetCookies(cm, GURL(kTopLevelDomainPlus1))); 1774 EXPECT_EQ("dom_1=X; host_1=X",
1775 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
1676 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", 1776 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1677 GetCookies(cm, GURL(kTopLevelDomainPlus2Secure + 1777 GetCookies(cm.get(),
1678 std::string("/dir1/dir2/xxx")))); 1778 GURL(kTopLevelDomainPlus2Secure +
1779 std::string("/dir1/dir2/xxx"))));
1679 1780
1680 PopulateCmForDeleteAllForHost(cm); 1781 PopulateCmForDeleteAllForHost(cm);
1681 EXPECT_EQ(5, DeleteAllForHost(cm, GURL(kTopLevelDomainPlus2Secure))); 1782 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1682 EXPECT_EQ(8U, GetAllCookies(cm).size()); 1783 EXPECT_EQ(8U, GetAllCookies(cm.get()).size());
1683 1784
1684 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", 1785 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1685 GetCookies(cm, GURL(kTopLevelDomainPlus3))); 1786 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3)));
1686 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", 1787 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1687 GetCookies(cm, GURL(kTopLevelDomainPlus2Secure))); 1788 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1688 EXPECT_EQ("dom_1=X; host_1=X", GetCookies(cm, GURL(kTopLevelDomainPlus1))); 1789 EXPECT_EQ("dom_1=X; host_1=X",
1790 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
1689 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", 1791 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1690 GetCookies(cm, GURL(kTopLevelDomainPlus2Secure + 1792 GetCookies(cm.get(),
1691 std::string("/dir1/dir2/xxx")))); 1793 GURL(kTopLevelDomainPlus2Secure +
1794 std::string("/dir1/dir2/xxx"))));
1692 1795
1693 PopulateCmForDeleteAllForHost(cm); 1796 PopulateCmForDeleteAllForHost(cm);
1694 EXPECT_EQ(5, DeleteAllForHost(cm, GURL(kTopLevelDomainPlus2Secure + 1797 EXPECT_EQ(5,
1695 std::string("/dir1/xxx")))); 1798 DeleteAllForHost(
1696 EXPECT_EQ(8U, GetAllCookies(cm).size()); 1799 cm.get(),
1800 GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/xxx"))));
1801 EXPECT_EQ(8U, GetAllCookies(cm.get()).size());
1697 1802
1698 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", 1803 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1699 GetCookies(cm, GURL(kTopLevelDomainPlus3))); 1804 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3)));
1700 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", 1805 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1701 GetCookies(cm, GURL(kTopLevelDomainPlus2Secure))); 1806 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure)));
1702 EXPECT_EQ("dom_1=X; host_1=X", GetCookies(cm, GURL(kTopLevelDomainPlus1))); 1807 EXPECT_EQ("dom_1=X; host_1=X",
1808 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1)));
1703 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", 1809 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1704 GetCookies(cm, GURL(kTopLevelDomainPlus2Secure + 1810 GetCookies(cm.get(),
1705 std::string("/dir1/dir2/xxx")))); 1811 GURL(kTopLevelDomainPlus2Secure +
1812 std::string("/dir1/dir2/xxx"))));
1706 } 1813 }
1707 1814
1708 TEST_F(CookieMonsterTest, UniqueCreationTime) { 1815 TEST_F(CookieMonsterTest, UniqueCreationTime) {
1709 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1816 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1710 CookieOptions options; 1817 CookieOptions options;
1711 1818
1712 // Add in three cookies through every public interface to the 1819 // Add in three cookies through every public interface to the
1713 // CookieMonster and confirm that none of them have duplicate 1820 // CookieMonster and confirm that none of them have duplicate
1714 // creation times. 1821 // creation times.
1715 1822
1716 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions 1823 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions
1717 // are not included as they aren't going to be public for very much 1824 // are not included as they aren't going to be public for very much
1718 // longer. 1825 // longer.
1719 1826
1720 // SetCookie, SetCookieWithOptions, SetCookieWithDetails 1827 // SetCookie, SetCookieWithOptions, SetCookieWithDetails
1721 1828
1722 SetCookie(cm, url_google_, "SetCookie1=A"); 1829 SetCookie(cm.get(), url_google_, "SetCookie1=A");
1723 SetCookie(cm, url_google_, "SetCookie2=A"); 1830 SetCookie(cm.get(), url_google_, "SetCookie2=A");
1724 SetCookie(cm, url_google_, "SetCookie3=A"); 1831 SetCookie(cm.get(), url_google_, "SetCookie3=A");
1725 1832
1726 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions1=A", options); 1833 SetCookieWithOptions(
1727 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions2=A", options); 1834 cm.get(), url_google_, "setCookieWithOptions1=A", options);
1728 SetCookieWithOptions(cm, url_google_, "setCookieWithOptions3=A", options); 1835 SetCookieWithOptions(
1836 cm.get(), url_google_, "setCookieWithOptions2=A", options);
1837 SetCookieWithOptions(
1838 cm.get(), url_google_, "setCookieWithOptions3=A", options);
1729 1839
1730 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails1", "A", 1840 SetCookieWithDetails(cm.get(),
1731 ".google.com", "/", Time(), false, false, 1841 url_google_,
1842 "setCookieWithDetails1",
1843 "A",
1844 ".google.com",
1845 "/",
1846 Time(),
1847 false,
1848 false,
1732 COOKIE_PRIORITY_DEFAULT); 1849 COOKIE_PRIORITY_DEFAULT);
1733 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails2", "A", 1850 SetCookieWithDetails(cm.get(),
1734 ".google.com", "/", Time(), false, false, 1851 url_google_,
1852 "setCookieWithDetails2",
1853 "A",
1854 ".google.com",
1855 "/",
1856 Time(),
1857 false,
1858 false,
1735 COOKIE_PRIORITY_DEFAULT); 1859 COOKIE_PRIORITY_DEFAULT);
1736 SetCookieWithDetails(cm, url_google_, "setCookieWithDetails3", "A", 1860 SetCookieWithDetails(cm.get(),
1737 ".google.com", "/", Time(), false, false, 1861 url_google_,
1862 "setCookieWithDetails3",
1863 "A",
1864 ".google.com",
1865 "/",
1866 Time(),
1867 false,
1868 false,
1738 COOKIE_PRIORITY_DEFAULT); 1869 COOKIE_PRIORITY_DEFAULT);
1739 1870
1740 // Now we check 1871 // Now we check
1741 CookieList cookie_list(GetAllCookies(cm)); 1872 CookieList cookie_list(GetAllCookies(cm.get()));
1742 typedef std::map<int64, CanonicalCookie> TimeCookieMap; 1873 typedef std::map<int64, CanonicalCookie> TimeCookieMap;
1743 TimeCookieMap check_map; 1874 TimeCookieMap check_map;
1744 for (CookieList::const_iterator it = cookie_list.begin(); 1875 for (CookieList::const_iterator it = cookie_list.begin();
1745 it != cookie_list.end(); it++) { 1876 it != cookie_list.end(); it++) {
1746 const int64 creation_date = it->CreationDate().ToInternalValue(); 1877 const int64 creation_date = it->CreationDate().ToInternalValue();
1747 TimeCookieMap::const_iterator 1878 TimeCookieMap::const_iterator
1748 existing_cookie_it(check_map.find(creation_date)); 1879 existing_cookie_it(check_map.find(creation_date));
1749 EXPECT_TRUE(existing_cookie_it == check_map.end()) 1880 EXPECT_TRUE(existing_cookie_it == check_map.end())
1750 << "Cookie " << it->Name() << " has same creation date (" 1881 << "Cookie " << it->Name() << " has same creation date ("
1751 << it->CreationDate().ToInternalValue() 1882 << it->CreationDate().ToInternalValue()
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), 1931 "/path/from/cookie", expires + TimeDelta::FromSeconds(10),
1801 true, true, COOKIE_PRIORITY_DEFAULT}, 1932 true, true, COOKIE_PRIORITY_DEFAULT},
1802 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", 1933 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie",
1803 base::Time::Now() + base::TimeDelta::FromSeconds(100), 1934 base::Time::Now() + base::TimeDelta::FromSeconds(100),
1804 true, false, COOKIE_PRIORITY_DEFAULT} 1935 true, false, COOKIE_PRIORITY_DEFAULT}
1805 }; 1936 };
1806 const int INPUT_DELETE = 1; 1937 const int INPUT_DELETE = 1;
1807 1938
1808 // Create new cookies and flush them to the store. 1939 // Create new cookies and flush them to the store.
1809 { 1940 {
1810 scoped_refptr<CookieMonster> cmout(new CookieMonster(store, NULL)); 1941 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL));
1811 for (const CookiesInputInfo* p = input_info; 1942 for (const CookiesInputInfo* p = input_info;
1812 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) { 1943 p < &input_info[ARRAYSIZE_UNSAFE(input_info)];
1813 EXPECT_TRUE(SetCookieWithDetails(cmout, p->url, p->name, p->value, 1944 p++) {
1814 p->domain, p->path, p->expiration_time, 1945 EXPECT_TRUE(SetCookieWithDetails(cmout.get(),
1815 p->secure, p->http_only, p->priority)); 1946 p->url,
1947 p->name,
1948 p->value,
1949 p->domain,
1950 p->path,
1951 p->expiration_time,
1952 p->secure,
1953 p->http_only,
1954 p->priority));
1816 } 1955 }
1817 GURL del_url(input_info[INPUT_DELETE].url.Resolve( 1956 GURL del_url(input_info[INPUT_DELETE].url.Resolve(
1818 input_info[INPUT_DELETE].path).spec()); 1957 input_info[INPUT_DELETE].path).spec());
1819 DeleteCookie(cmout, del_url, input_info[INPUT_DELETE].name); 1958 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name);
1820 } 1959 }
1821 1960
1822 // Create a new cookie monster and make sure that everything is correct 1961 // Create a new cookie monster and make sure that everything is correct
1823 { 1962 {
1824 scoped_refptr<CookieMonster> cmin(new CookieMonster(store, NULL)); 1963 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL));
1825 CookieList cookies(GetAllCookies(cmin)); 1964 CookieList cookies(GetAllCookies(cmin.get()));
1826 ASSERT_EQ(2u, cookies.size()); 1965 ASSERT_EQ(2u, cookies.size());
1827 // Ordering is path length, then creation time. So second cookie 1966 // Ordering is path length, then creation time. So second cookie
1828 // will come first, and we need to swap them. 1967 // will come first, and we need to swap them.
1829 std::swap(cookies[0], cookies[1]); 1968 std::swap(cookies[0], cookies[1]);
1830 for (int output_index = 0; output_index < 2; output_index++) { 1969 for (int output_index = 0; output_index < 2; output_index++) {
1831 int input_index = output_index * 2; 1970 int input_index = output_index * 2;
1832 const CookiesInputInfo* input = &input_info[input_index]; 1971 const CookiesInputInfo* input = &input_info[input_index];
1833 const CanonicalCookie* output = &cookies[output_index]; 1972 const CanonicalCookie* output = &cookies[output_index];
1834 1973
1835 EXPECT_EQ(input->name, output->Name()); 1974 EXPECT_EQ(input->name, output->Name());
1836 EXPECT_EQ(input->value, output->Value()); 1975 EXPECT_EQ(input->value, output->Value());
1837 EXPECT_EQ(input->url.host(), output->Domain()); 1976 EXPECT_EQ(input->url.host(), output->Domain());
1838 EXPECT_EQ(input->path, output->Path()); 1977 EXPECT_EQ(input->path, output->Path());
1839 EXPECT_LE(current.ToInternalValue(), 1978 EXPECT_LE(current.ToInternalValue(),
1840 output->CreationDate().ToInternalValue()); 1979 output->CreationDate().ToInternalValue());
1841 EXPECT_EQ(input->secure, output->IsSecure()); 1980 EXPECT_EQ(input->secure, output->IsSecure());
1842 EXPECT_EQ(input->http_only, output->IsHttpOnly()); 1981 EXPECT_EQ(input->http_only, output->IsHttpOnly());
1843 EXPECT_TRUE(output->IsPersistent()); 1982 EXPECT_TRUE(output->IsPersistent());
1844 EXPECT_EQ(input->expiration_time.ToInternalValue(), 1983 EXPECT_EQ(input->expiration_time.ToInternalValue(),
1845 output->ExpiryDate().ToInternalValue()); 1984 output->ExpiryDate().ToInternalValue());
1846 } 1985 }
1847 } 1986 }
1848 } 1987 }
1849 1988
1850 TEST_F(CookieMonsterTest, CookieListOrdering) { 1989 TEST_F(CookieMonsterTest, CookieListOrdering) {
1851 // Put a random set of cookies into a monster and make sure 1990 // Put a random set of cookies into a monster and make sure
1852 // they're returned in the right order. 1991 // they're returned in the right order.
1853 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1992 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1854 EXPECT_TRUE(SetCookie(cm, GURL("http://d.c.b.a.google.com/aa/x.html"), 1993 EXPECT_TRUE(
1855 "c=1")); 1994 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1"));
1856 EXPECT_TRUE(SetCookie(cm, GURL("http://b.a.google.com/aa/bb/cc/x.html"), 1995 EXPECT_TRUE(SetCookie(cm.get(),
1996 GURL("http://b.a.google.com/aa/bb/cc/x.html"),
1857 "d=1; domain=b.a.google.com")); 1997 "d=1; domain=b.a.google.com"));
1858 EXPECT_TRUE(SetCookie(cm, GURL("http://b.a.google.com/aa/bb/cc/x.html"), 1998 EXPECT_TRUE(SetCookie(cm.get(),
1999 GURL("http://b.a.google.com/aa/bb/cc/x.html"),
1859 "a=4; domain=b.a.google.com")); 2000 "a=4; domain=b.a.google.com"));
1860 EXPECT_TRUE(SetCookie(cm, GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), 2001 EXPECT_TRUE(SetCookie(cm.get(),
2002 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"),
1861 "e=1; domain=c.b.a.google.com")); 2003 "e=1; domain=c.b.a.google.com"));
1862 EXPECT_TRUE(SetCookie(cm, GURL("http://d.c.b.a.google.com/aa/bb/x.html"), 2004 EXPECT_TRUE(SetCookie(
1863 "b=1")); 2005 cm.get(), GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1"));
1864 EXPECT_TRUE(SetCookie(cm, GURL("http://news.bbc.co.uk/midpath/x.html"), 2006 EXPECT_TRUE(SetCookie(
1865 "g=10")); 2007 cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10"));
1866 { 2008 {
1867 unsigned int i = 0; 2009 unsigned int i = 0;
1868 CookieList cookies(GetAllCookiesForURL( 2010 CookieList cookies(GetAllCookiesForURL(
1869 cm, GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); 2011 cm.get(), GURL("http://d.c.b.a.google.com/aa/bb/cc/dd")));
1870 ASSERT_EQ(5u, cookies.size()); 2012 ASSERT_EQ(5u, cookies.size());
1871 EXPECT_EQ("d", cookies[i++].Name()); 2013 EXPECT_EQ("d", cookies[i++].Name());
1872 EXPECT_EQ("a", cookies[i++].Name()); 2014 EXPECT_EQ("a", cookies[i++].Name());
1873 EXPECT_EQ("e", cookies[i++].Name()); 2015 EXPECT_EQ("e", cookies[i++].Name());
1874 EXPECT_EQ("b", cookies[i++].Name()); 2016 EXPECT_EQ("b", cookies[i++].Name());
1875 EXPECT_EQ("c", cookies[i++].Name()); 2017 EXPECT_EQ("c", cookies[i++].Name());
1876 } 2018 }
1877 2019
1878 { 2020 {
1879 unsigned int i = 0; 2021 unsigned int i = 0;
1880 CookieList cookies(GetAllCookies(cm)); 2022 CookieList cookies(GetAllCookies(cm.get()));
1881 ASSERT_EQ(6u, cookies.size()); 2023 ASSERT_EQ(6u, cookies.size());
1882 EXPECT_EQ("d", cookies[i++].Name()); 2024 EXPECT_EQ("d", cookies[i++].Name());
1883 EXPECT_EQ("a", cookies[i++].Name()); 2025 EXPECT_EQ("a", cookies[i++].Name());
1884 EXPECT_EQ("e", cookies[i++].Name()); 2026 EXPECT_EQ("e", cookies[i++].Name());
1885 EXPECT_EQ("g", cookies[i++].Name()); 2027 EXPECT_EQ("g", cookies[i++].Name());
1886 EXPECT_EQ("b", cookies[i++].Name()); 2028 EXPECT_EQ("b", cookies[i++].Name());
1887 EXPECT_EQ("c", cookies[i++].Name()); 2029 EXPECT_EQ("c", cookies[i++].Name());
1888 } 2030 }
1889 } 2031 }
1890 2032
(...skipping 10 matching lines...) Expand all
1901 #else 2043 #else
1902 #define MAYBE_GarbageCollectionTriggers GarbageCollectionTriggers 2044 #define MAYBE_GarbageCollectionTriggers GarbageCollectionTriggers
1903 #endif 2045 #endif
1904 2046
1905 TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) { 2047 TEST_F(CookieMonsterTest, MAYBE_GarbageCollectionTriggers) {
1906 // First we check to make sure that a whole lot of recent cookies 2048 // First we check to make sure that a whole lot of recent cookies
1907 // doesn't get rid of anything after garbage collection is checked for. 2049 // doesn't get rid of anything after garbage collection is checked for.
1908 { 2050 {
1909 scoped_refptr<CookieMonster> cm( 2051 scoped_refptr<CookieMonster> cm(
1910 CreateMonsterForGC(CookieMonster::kMaxCookies * 2)); 2052 CreateMonsterForGC(CookieMonster::kMaxCookies * 2));
1911 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm).size()); 2053 EXPECT_EQ(CookieMonster::kMaxCookies * 2, GetAllCookies(cm.get()).size());
1912 SetCookie(cm, GURL("http://newdomain.com"), "b=2"); 2054 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2");
1913 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, GetAllCookies(cm).size()); 2055 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1,
2056 GetAllCookies(cm.get()).size());
1914 } 2057 }
1915 2058
1916 // Now we explore a series of relationships between cookie last access 2059 // Now we explore a series of relationships between cookie last access
1917 // time and size of store to make sure we only get rid of cookies when 2060 // time and size of store to make sure we only get rid of cookies when
1918 // we really should. 2061 // we really should.
1919 const struct TestCase { 2062 const struct TestCase {
1920 size_t num_cookies; 2063 size_t num_cookies;
1921 size_t num_old_cookies; 2064 size_t num_old_cookies;
1922 size_t expected_initial_cookies; 2065 size_t expected_initial_cookies;
1923 // Indexed by ExpiryAndKeyScheme 2066 // Indexed by ExpiryAndKeyScheme
(...skipping 26 matching lines...) Expand all
1950 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies 2093 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies
1951 } 2094 }
1952 }; 2095 };
1953 2096
1954 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) { 2097 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) {
1955 const TestCase *test_case = &test_cases[ci]; 2098 const TestCase *test_case = &test_cases[ci];
1956 scoped_refptr<CookieMonster> cm( 2099 scoped_refptr<CookieMonster> cm(
1957 CreateMonsterFromStoreForGC( 2100 CreateMonsterFromStoreForGC(
1958 test_case->num_cookies, test_case->num_old_cookies, 2101 test_case->num_cookies, test_case->num_old_cookies,
1959 CookieMonster::kSafeFromGlobalPurgeDays * 2)); 2102 CookieMonster::kSafeFromGlobalPurgeDays * 2));
1960 EXPECT_EQ(test_case->expected_initial_cookies, GetAllCookies(cm).size()) 2103 EXPECT_EQ(test_case->expected_initial_cookies,
1961 << "For test case " << ci; 2104 GetAllCookies(cm.get()).size()) << "For test case " << ci;
1962 // Will trigger GC 2105 // Will trigger GC
1963 SetCookie(cm, GURL("http://newdomain.com"), "b=2"); 2106 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2");
1964 EXPECT_EQ(test_case->expected_cookies_after_set, GetAllCookies(cm).size()) 2107 EXPECT_EQ(test_case->expected_cookies_after_set,
1965 << "For test case " << ci; 2108 GetAllCookies(cm.get()).size()) << "For test case " << ci;
1966 } 2109 }
1967 } 2110 }
1968 2111
1969 // This test checks that keep expired cookies flag is working. 2112 // This test checks that keep expired cookies flag is working.
1970 TEST_F(CookieMonsterTest, KeepExpiredCookies) { 2113 TEST_F(CookieMonsterTest, KeepExpiredCookies) {
1971 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2114 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1972 cm->SetKeepExpiredCookies(); 2115 cm->SetKeepExpiredCookies();
1973 CookieOptions options; 2116 CookieOptions options;
1974 2117
1975 // Set a persistent cookie. 2118 // Set a persistent cookie.
1976 ASSERT_TRUE(SetCookieWithOptions( 2119 ASSERT_TRUE(SetCookieWithOptions(
1977 cm, url_google_, 2120 cm.get(),
2121 url_google_,
1978 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT", 2122 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT",
1979 options)); 2123 options));
1980 2124
1981 // Get the canonical cookie. 2125 // Get the canonical cookie.
1982 CookieList cookie_list = GetAllCookies(cm); 2126 CookieList cookie_list = GetAllCookies(cm.get());
1983 ASSERT_EQ(1U, cookie_list.size()); 2127 ASSERT_EQ(1U, cookie_list.size());
1984 2128
1985 // Use a past expiry date to delete the cookie. 2129 // Use a past expiry date to delete the cookie.
1986 ASSERT_TRUE(SetCookieWithOptions( 2130 ASSERT_TRUE(SetCookieWithOptions(
1987 cm, url_google_, 2131 cm.get(),
2132 url_google_,
1988 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", 2133 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
1989 options)); 2134 options));
1990 2135
1991 // Check that the cookie with the past expiry date is still there. 2136 // Check that the cookie with the past expiry date is still there.
1992 // GetAllCookies() also triggers garbage collection. 2137 // GetAllCookies() also triggers garbage collection.
1993 cookie_list = GetAllCookies(cm); 2138 cookie_list = GetAllCookies(cm.get());
1994 ASSERT_EQ(1U, cookie_list.size()); 2139 ASSERT_EQ(1U, cookie_list.size());
1995 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); 2140 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now()));
1996 } 2141 }
1997 2142
1998 namespace { 2143 namespace {
1999 2144
2000 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. 2145 // Mock PersistentCookieStore that keeps track of the number of Flush() calls.
2001 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { 2146 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore {
2002 public: 2147 public:
2003 FlushablePersistentStore() : flush_count_(0) {} 2148 FlushablePersistentStore() : flush_count_(0) {}
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 2201
2057 volatile int callback_count_; 2202 volatile int callback_count_;
2058 }; 2203 };
2059 2204
2060 } // namespace 2205 } // namespace
2061 2206
2062 // Test that FlushStore() is forwarded to the store and callbacks are posted. 2207 // Test that FlushStore() is forwarded to the store and callbacks are posted.
2063 TEST_F(CookieMonsterTest, FlushStore) { 2208 TEST_F(CookieMonsterTest, FlushStore) {
2064 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); 2209 scoped_refptr<CallbackCounter> counter(new CallbackCounter());
2065 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); 2210 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore());
2066 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 2211 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2067 2212
2068 ASSERT_EQ(0, store->flush_count()); 2213 ASSERT_EQ(0, store->flush_count());
2069 ASSERT_EQ(0, counter->callback_count()); 2214 ASSERT_EQ(0, counter->callback_count());
2070 2215
2071 // Before initialization, FlushStore() should just run the callback. 2216 // Before initialization, FlushStore() should just run the callback.
2072 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); 2217 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get()));
2073 base::MessageLoop::current()->RunUntilIdle(); 2218 base::MessageLoop::current()->RunUntilIdle();
2074 2219
2075 ASSERT_EQ(0, store->flush_count()); 2220 ASSERT_EQ(0, store->flush_count());
2076 ASSERT_EQ(1, counter->callback_count()); 2221 ASSERT_EQ(1, counter->callback_count());
2077 2222
2078 // NULL callback is safe. 2223 // NULL callback is safe.
2079 cm->FlushStore(base::Closure()); 2224 cm->FlushStore(base::Closure());
2080 base::MessageLoop::current()->RunUntilIdle(); 2225 base::MessageLoop::current()->RunUntilIdle();
2081 2226
2082 ASSERT_EQ(0, store->flush_count()); 2227 ASSERT_EQ(0, store->flush_count());
2083 ASSERT_EQ(1, counter->callback_count()); 2228 ASSERT_EQ(1, counter->callback_count());
2084 2229
2085 // After initialization, FlushStore() should delegate to the store. 2230 // After initialization, FlushStore() should delegate to the store.
2086 GetAllCookies(cm); // Force init. 2231 GetAllCookies(cm.get()); // Force init.
2087 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); 2232 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get()));
2088 base::MessageLoop::current()->RunUntilIdle(); 2233 base::MessageLoop::current()->RunUntilIdle();
2089 2234
2090 ASSERT_EQ(1, store->flush_count()); 2235 ASSERT_EQ(1, store->flush_count());
2091 ASSERT_EQ(2, counter->callback_count()); 2236 ASSERT_EQ(2, counter->callback_count());
2092 2237
2093 // NULL callback is still safe. 2238 // NULL callback is still safe.
2094 cm->FlushStore(base::Closure()); 2239 cm->FlushStore(base::Closure());
2095 base::MessageLoop::current()->RunUntilIdle(); 2240 base::MessageLoop::current()->RunUntilIdle();
2096 2241
2097 ASSERT_EQ(2, store->flush_count()); 2242 ASSERT_EQ(2, store->flush_count());
2098 ASSERT_EQ(2, counter->callback_count()); 2243 ASSERT_EQ(2, counter->callback_count());
2099 2244
2100 // If there's no backing store, FlushStore() is always a safe no-op. 2245 // If there's no backing store, FlushStore() is always a safe no-op.
2101 cm = new CookieMonster(NULL, NULL); 2246 cm = new CookieMonster(NULL, NULL);
2102 GetAllCookies(cm); // Force init. 2247 GetAllCookies(cm.get()); // Force init.
2103 cm->FlushStore(base::Closure()); 2248 cm->FlushStore(base::Closure());
2104 base::MessageLoop::current()->RunUntilIdle(); 2249 base::MessageLoop::current()->RunUntilIdle();
2105 2250
2106 ASSERT_EQ(2, counter->callback_count()); 2251 ASSERT_EQ(2, counter->callback_count());
2107 2252
2108 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get())); 2253 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter.get()));
2109 base::MessageLoop::current()->RunUntilIdle(); 2254 base::MessageLoop::current()->RunUntilIdle();
2110 2255
2111 ASSERT_EQ(3, counter->callback_count()); 2256 ASSERT_EQ(3, counter->callback_count());
2112 } 2257 }
2113 2258
2114 TEST_F(CookieMonsterTest, HistogramCheck) { 2259 TEST_F(CookieMonsterTest, HistogramCheck) {
2115 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2260 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2116 // Should match call in InitializeHistograms, but doesn't really matter 2261 // Should match call in InitializeHistograms, but doesn't really matter
2117 // since the histogram should have been initialized by the CM construction 2262 // since the histogram should have been initialized by the CM construction
2118 // above. 2263 // above.
2119 base::HistogramBase* expired_histogram = 2264 base::HistogramBase* expired_histogram =
2120 base::Histogram::FactoryGet( 2265 base::Histogram::FactoryGet(
2121 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, 2266 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50,
2122 base::Histogram::kUmaTargetedHistogramFlag); 2267 base::Histogram::kUmaTargetedHistogramFlag);
2123 2268
2124 scoped_ptr<base::HistogramSamples> samples1( 2269 scoped_ptr<base::HistogramSamples> samples1(
2125 expired_histogram->SnapshotSamples()); 2270 expired_histogram->SnapshotSamples());
2126 ASSERT_TRUE(SetCookieWithDetails( 2271 ASSERT_TRUE(
2127 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", 2272 SetCookieWithDetails(cm.get(),
2128 base::Time::Now() + base::TimeDelta::FromMinutes(59), 2273 GURL("http://fake.a.url"),
2129 false, false, COOKIE_PRIORITY_DEFAULT)); 2274 "a",
2275 "b",
2276 "a.url",
2277 "/",
2278 base::Time::Now() + base::TimeDelta::FromMinutes(59),
2279 false,
2280 false,
2281 COOKIE_PRIORITY_DEFAULT));
2130 2282
2131 scoped_ptr<base::HistogramSamples> samples2( 2283 scoped_ptr<base::HistogramSamples> samples2(
2132 expired_histogram->SnapshotSamples()); 2284 expired_histogram->SnapshotSamples());
2133 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); 2285 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount());
2134 2286
2135 // kValidCookieLine creates a session cookie. 2287 // kValidCookieLine creates a session cookie.
2136 ASSERT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); 2288 ASSERT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine));
2137 2289
2138 scoped_ptr<base::HistogramSamples> samples3( 2290 scoped_ptr<base::HistogramSamples> samples3(
2139 expired_histogram->SnapshotSamples()); 2291 expired_histogram->SnapshotSamples());
2140 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); 2292 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount());
2141 } 2293 }
2142 2294
2143 namespace { 2295 namespace {
2144 2296
2145 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { 2297 class MultiThreadedCookieMonsterTest : public CookieMonsterTest {
2146 public: 2298 public:
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 other_thread_.Stop(); 2376 other_thread_.Stop();
2225 } 2377 }
2226 2378
2227 Thread other_thread_; 2379 Thread other_thread_;
2228 }; 2380 };
2229 2381
2230 } // namespace 2382 } // namespace
2231 2383
2232 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { 2384 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) {
2233 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2385 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2234 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); 2386 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
2235 CookieList cookies = GetAllCookies(cm); 2387 CookieList cookies = GetAllCookies(cm.get());
2236 CookieList::const_iterator it = cookies.begin(); 2388 CookieList::const_iterator it = cookies.begin();
2237 ASSERT_TRUE(it != cookies.end()); 2389 ASSERT_TRUE(it != cookies.end());
2238 EXPECT_EQ("www.google.izzle", it->Domain()); 2390 EXPECT_EQ("www.google.izzle", it->Domain());
2239 EXPECT_EQ("A", it->Name()); 2391 EXPECT_EQ("A", it->Name());
2240 ASSERT_TRUE(++it == cookies.end()); 2392 ASSERT_TRUE(++it == cookies.end());
2241 GetCookieListCallback callback(&other_thread_); 2393 GetCookieListCallback callback(&other_thread_);
2242 base::Closure task = 2394 base::Closure task =
2243 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, 2395 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask,
2244 base::Unretained(this), 2396 base::Unretained(this),
2245 cm, &callback); 2397 cm, &callback);
2246 RunOnOtherThread(task); 2398 RunOnOtherThread(task);
2247 EXPECT_TRUE(callback.did_run()); 2399 EXPECT_TRUE(callback.did_run());
2248 it = callback.cookies().begin(); 2400 it = callback.cookies().begin();
2249 ASSERT_TRUE(it != callback.cookies().end()); 2401 ASSERT_TRUE(it != callback.cookies().end());
2250 EXPECT_EQ("www.google.izzle", it->Domain()); 2402 EXPECT_EQ("www.google.izzle", it->Domain());
2251 EXPECT_EQ("A", it->Name()); 2403 EXPECT_EQ("A", it->Name());
2252 ASSERT_TRUE(++it == callback.cookies().end()); 2404 ASSERT_TRUE(++it == callback.cookies().end());
2253 } 2405 }
2254 2406
2255 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { 2407 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) {
2256 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2408 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2257 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); 2409 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
2258 CookieList cookies = GetAllCookiesForURL(cm, url_google_); 2410 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_);
2259 CookieList::const_iterator it = cookies.begin(); 2411 CookieList::const_iterator it = cookies.begin();
2260 ASSERT_TRUE(it != cookies.end()); 2412 ASSERT_TRUE(it != cookies.end());
2261 EXPECT_EQ("www.google.izzle", it->Domain()); 2413 EXPECT_EQ("www.google.izzle", it->Domain());
2262 EXPECT_EQ("A", it->Name()); 2414 EXPECT_EQ("A", it->Name());
2263 ASSERT_TRUE(++it == cookies.end()); 2415 ASSERT_TRUE(++it == cookies.end());
2264 GetCookieListCallback callback(&other_thread_); 2416 GetCookieListCallback callback(&other_thread_);
2265 base::Closure task = 2417 base::Closure task =
2266 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, 2418 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask,
2267 base::Unretained(this), 2419 base::Unretained(this),
2268 cm, url_google_, &callback); 2420 cm, url_google_, &callback);
2269 RunOnOtherThread(task); 2421 RunOnOtherThread(task);
2270 EXPECT_TRUE(callback.did_run()); 2422 EXPECT_TRUE(callback.did_run());
2271 it = callback.cookies().begin(); 2423 it = callback.cookies().begin();
2272 ASSERT_TRUE(it != callback.cookies().end()); 2424 ASSERT_TRUE(it != callback.cookies().end());
2273 EXPECT_EQ("www.google.izzle", it->Domain()); 2425 EXPECT_EQ("www.google.izzle", it->Domain());
2274 EXPECT_EQ("A", it->Name()); 2426 EXPECT_EQ("A", it->Name());
2275 ASSERT_TRUE(++it == callback.cookies().end()); 2427 ASSERT_TRUE(++it == callback.cookies().end());
2276 } 2428 }
2277 2429
2278 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { 2430 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) {
2279 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2431 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2280 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); 2432 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
2281 CookieOptions options; 2433 CookieOptions options;
2282 CookieList cookies = 2434 CookieList cookies =
2283 GetAllCookiesForURLWithOptions(cm, url_google_, options); 2435 GetAllCookiesForURLWithOptions(cm.get(), url_google_, options);
2284 CookieList::const_iterator it = cookies.begin(); 2436 CookieList::const_iterator it = cookies.begin();
2285 ASSERT_TRUE(it != cookies.end()); 2437 ASSERT_TRUE(it != cookies.end());
2286 EXPECT_EQ("www.google.izzle", it->Domain()); 2438 EXPECT_EQ("www.google.izzle", it->Domain());
2287 EXPECT_EQ("A", it->Name()); 2439 EXPECT_EQ("A", it->Name());
2288 ASSERT_TRUE(++it == cookies.end()); 2440 ASSERT_TRUE(++it == cookies.end());
2289 GetCookieListCallback callback(&other_thread_); 2441 GetCookieListCallback callback(&other_thread_);
2290 base::Closure task = base::Bind( 2442 base::Closure task = base::Bind(
2291 &net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask, 2443 &net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask,
2292 base::Unretained(this), 2444 base::Unretained(this),
2293 cm, url_google_, options, &callback); 2445 cm, url_google_, options, &callback);
2294 RunOnOtherThread(task); 2446 RunOnOtherThread(task);
2295 EXPECT_TRUE(callback.did_run()); 2447 EXPECT_TRUE(callback.did_run());
2296 it = callback.cookies().begin(); 2448 it = callback.cookies().begin();
2297 ASSERT_TRUE(it != callback.cookies().end()); 2449 ASSERT_TRUE(it != callback.cookies().end());
2298 EXPECT_EQ("www.google.izzle", it->Domain()); 2450 EXPECT_EQ("www.google.izzle", it->Domain());
2299 EXPECT_EQ("A", it->Name()); 2451 EXPECT_EQ("A", it->Name());
2300 ASSERT_TRUE(++it == callback.cookies().end()); 2452 ASSERT_TRUE(++it == callback.cookies().end());
2301 } 2453 }
2302 2454
2303 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { 2455 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) {
2304 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2456 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2305 EXPECT_TRUE(SetCookieWithDetails( 2457 EXPECT_TRUE(SetCookieWithDetails(cm.get(),
2306 cm, url_google_foo_, 2458 url_google_foo_,
2307 "A", "B", std::string(), "/foo", base::Time(), 2459 "A",
2308 false, false, COOKIE_PRIORITY_DEFAULT)); 2460 "B",
2461 std::string(),
2462 "/foo",
2463 base::Time(),
2464 false,
2465 false,
2466 COOKIE_PRIORITY_DEFAULT));
2309 BoolResultCookieCallback callback(&other_thread_); 2467 BoolResultCookieCallback callback(&other_thread_);
2310 base::Closure task = base::Bind( 2468 base::Closure task = base::Bind(
2311 &net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, 2469 &net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask,
2312 base::Unretained(this), 2470 base::Unretained(this),
2313 cm, url_google_foo_, &callback); 2471 cm, url_google_foo_, &callback);
2314 RunOnOtherThread(task); 2472 RunOnOtherThread(task);
2315 EXPECT_TRUE(callback.did_run()); 2473 EXPECT_TRUE(callback.did_run());
2316 EXPECT_TRUE(callback.result()); 2474 EXPECT_TRUE(callback.result());
2317 } 2475 }
2318 2476
2319 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { 2477 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) {
2320 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2478 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2321 CookieOptions options; 2479 CookieOptions options;
2322 Time now = Time::Now(); 2480 Time now = Time::Now();
2323 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2481 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
2324 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99), 2482 EXPECT_EQ(
2325 Time())); 2483 1,
2326 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2484 DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time()));
2485 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
2327 IntResultCookieCallback callback(&other_thread_); 2486 IntResultCookieCallback callback(&other_thread_);
2328 base::Closure task = base::Bind( 2487 base::Closure task = base::Bind(
2329 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, 2488 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask,
2330 base::Unretained(this), 2489 base::Unretained(this),
2331 cm, now - TimeDelta::FromDays(99), 2490 cm, now - TimeDelta::FromDays(99),
2332 Time(), &callback); 2491 Time(), &callback);
2333 RunOnOtherThread(task); 2492 RunOnOtherThread(task);
2334 EXPECT_TRUE(callback.did_run()); 2493 EXPECT_TRUE(callback.did_run());
2335 EXPECT_EQ(1, callback.result()); 2494 EXPECT_EQ(1, callback.result());
2336 } 2495 }
2337 2496
2338 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { 2497 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) {
2339 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2498 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2340 CookieOptions options; 2499 CookieOptions options;
2341 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2500 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
2342 EXPECT_EQ(1, DeleteAllForHost(cm, url_google_)); 2501 EXPECT_EQ(1, DeleteAllForHost(cm.get(), url_google_));
2343 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2502 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
2344 IntResultCookieCallback callback(&other_thread_); 2503 IntResultCookieCallback callback(&other_thread_);
2345 base::Closure task = base::Bind( 2504 base::Closure task = base::Bind(
2346 &net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask, 2505 &net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask,
2347 base::Unretained(this), 2506 base::Unretained(this),
2348 cm, url_google_, &callback); 2507 cm, url_google_, &callback);
2349 RunOnOtherThread(task); 2508 RunOnOtherThread(task);
2350 EXPECT_TRUE(callback.did_run()); 2509 EXPECT_TRUE(callback.did_run());
2351 EXPECT_EQ(1, callback.result()); 2510 EXPECT_EQ(1, callback.result());
2352 } 2511 }
2353 2512
2354 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { 2513 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) {
2355 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2514 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2356 CookieOptions options; 2515 CookieOptions options;
2357 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2516 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
2358 CookieList cookies = GetAllCookies(cm); 2517 CookieList cookies = GetAllCookies(cm.get());
2359 CookieList::iterator it = cookies.begin(); 2518 CookieList::iterator it = cookies.begin();
2360 EXPECT_TRUE(DeleteCanonicalCookie(cm, *it)); 2519 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it));
2361 2520
2362 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2521 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options));
2363 BoolResultCookieCallback callback(&other_thread_); 2522 BoolResultCookieCallback callback(&other_thread_);
2364 cookies = GetAllCookies(cm); 2523 cookies = GetAllCookies(cm.get());
2365 it = cookies.begin(); 2524 it = cookies.begin();
2366 base::Closure task = base::Bind( 2525 base::Closure task = base::Bind(
2367 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, 2526 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask,
2368 base::Unretained(this), 2527 base::Unretained(this),
2369 cm, *it, &callback); 2528 cm, *it, &callback);
2370 RunOnOtherThread(task); 2529 RunOnOtherThread(task);
2371 EXPECT_TRUE(callback.did_run()); 2530 EXPECT_TRUE(callback.did_run());
2372 EXPECT_TRUE(callback.result()); 2531 EXPECT_TRUE(callback.result());
2373 } 2532 }
2374 2533
2375 TEST_F(CookieMonsterTest, InvalidExpiryTime) { 2534 TEST_F(CookieMonsterTest, InvalidExpiryTime) {
2376 std::string cookie_line = 2535 std::string cookie_line =
2377 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; 2536 std::string(kValidCookieLine) + "; expires=Blarg arg arg";
2378 scoped_ptr<CanonicalCookie> cookie( 2537 scoped_ptr<CanonicalCookie> cookie(
2379 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(), 2538 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(),
2380 CookieOptions())); 2539 CookieOptions()));
2381 ASSERT_FALSE(cookie->IsPersistent()); 2540 ASSERT_FALSE(cookie->IsPersistent());
2382 } 2541 }
2383 2542
2384 // Test that CookieMonster writes session cookies into the underlying 2543 // Test that CookieMonster writes session cookies into the underlying
2385 // CookieStore if the "persist session cookies" option is on. 2544 // CookieStore if the "persist session cookies" option is on.
2386 TEST_F(CookieMonsterTest, PersistSessionCookies) { 2545 TEST_F(CookieMonsterTest, PersistSessionCookies) {
2387 scoped_refptr<MockPersistentCookieStore> store( 2546 scoped_refptr<MockPersistentCookieStore> store(
2388 new MockPersistentCookieStore); 2547 new MockPersistentCookieStore);
2389 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 2548 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2390 cm->SetPersistSessionCookies(true); 2549 cm->SetPersistSessionCookies(true);
2391 2550
2392 // All cookies set with SetCookie are session cookies. 2551 // All cookies set with SetCookie are session cookies.
2393 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); 2552 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B"));
2394 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); 2553 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_));
2395 2554
2396 // The cookie was written to the backing store. 2555 // The cookie was written to the backing store.
2397 EXPECT_EQ(1u, store->commands().size()); 2556 EXPECT_EQ(1u, store->commands().size());
2398 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); 2557 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
2399 EXPECT_EQ("A", store->commands()[0].cookie.Name()); 2558 EXPECT_EQ("A", store->commands()[0].cookie.Name());
2400 EXPECT_EQ("B", store->commands()[0].cookie.Value()); 2559 EXPECT_EQ("B", store->commands()[0].cookie.Value());
2401 2560
2402 // Modify the cookie. 2561 // Modify the cookie.
2403 EXPECT_TRUE(SetCookie(cm, url_google_, "A=C")); 2562 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=C"));
2404 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); 2563 EXPECT_EQ("A=C", GetCookies(cm.get(), url_google_));
2405 EXPECT_EQ(3u, store->commands().size()); 2564 EXPECT_EQ(3u, store->commands().size());
2406 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 2565 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
2407 EXPECT_EQ("A", store->commands()[1].cookie.Name()); 2566 EXPECT_EQ("A", store->commands()[1].cookie.Name());
2408 EXPECT_EQ("B", store->commands()[1].cookie.Value()); 2567 EXPECT_EQ("B", store->commands()[1].cookie.Value());
2409 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); 2568 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
2410 EXPECT_EQ("A", store->commands()[2].cookie.Name()); 2569 EXPECT_EQ("A", store->commands()[2].cookie.Name());
2411 EXPECT_EQ("C", store->commands()[2].cookie.Value()); 2570 EXPECT_EQ("C", store->commands()[2].cookie.Value());
2412 2571
2413 // Delete the cookie. 2572 // Delete the cookie.
2414 DeleteCookie(cm, url_google_, "A"); 2573 DeleteCookie(cm.get(), url_google_, "A");
2415 EXPECT_EQ("", GetCookies(cm, url_google_)); 2574 EXPECT_EQ("", GetCookies(cm.get(), url_google_));
2416 EXPECT_EQ(4u, store->commands().size()); 2575 EXPECT_EQ(4u, store->commands().size());
2417 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); 2576 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
2418 EXPECT_EQ("A", store->commands()[3].cookie.Name()); 2577 EXPECT_EQ("A", store->commands()[3].cookie.Name());
2419 EXPECT_EQ("C", store->commands()[3].cookie.Value()); 2578 EXPECT_EQ("C", store->commands()[3].cookie.Value());
2420 } 2579 }
2421 2580
2422 // Test the commands sent to the persistent cookie store. 2581 // Test the commands sent to the persistent cookie store.
2423 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { 2582 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) {
2424 scoped_refptr<MockPersistentCookieStore> store( 2583 scoped_refptr<MockPersistentCookieStore> store(
2425 new MockPersistentCookieStore); 2584 new MockPersistentCookieStore);
2426 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 2585 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2427 2586
2428 // Add a cookie. 2587 // Add a cookie.
2429 EXPECT_TRUE(SetCookie(cm, url_google_, 2588 EXPECT_TRUE(SetCookie(
2430 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); 2589 cm.get(), url_google_, "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
2431 this->MatchCookieLines("A=B", GetCookies(cm, url_google_)); 2590 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_));
2432 ASSERT_EQ(1u, store->commands().size()); 2591 ASSERT_EQ(1u, store->commands().size());
2433 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); 2592 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type);
2434 // Remove it. 2593 // Remove it.
2435 EXPECT_TRUE(SetCookie(cm, url_google_,"A=B; max-age=0")); 2594 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; max-age=0"));
2436 this->MatchCookieLines(std::string(), GetCookies(cm, url_google_)); 2595 this->MatchCookieLines(std::string(), GetCookies(cm.get(), url_google_));
2437 ASSERT_EQ(2u, store->commands().size()); 2596 ASSERT_EQ(2u, store->commands().size());
2438 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); 2597 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type);
2439 2598
2440 // Add a cookie. 2599 // Add a cookie.
2441 EXPECT_TRUE(SetCookie(cm, url_google_, 2600 EXPECT_TRUE(SetCookie(
2442 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); 2601 cm.get(), url_google_, "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT"));
2443 this->MatchCookieLines("A=B", GetCookies(cm, url_google_)); 2602 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_));
2444 ASSERT_EQ(3u, store->commands().size()); 2603 ASSERT_EQ(3u, store->commands().size());
2445 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); 2604 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type);
2446 // Overwrite it. 2605 // Overwrite it.
2447 EXPECT_TRUE(SetCookie(cm, url_google_, 2606 EXPECT_TRUE(SetCookie(
2448 "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT")); 2607 cm.get(), url_google_, "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT"));
2449 this->MatchCookieLines("A=Foo", GetCookies(cm, url_google_)); 2608 this->MatchCookieLines("A=Foo", GetCookies(cm.get(), url_google_));
2450 ASSERT_EQ(5u, store->commands().size()); 2609 ASSERT_EQ(5u, store->commands().size());
2451 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); 2610 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
2452 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); 2611 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type);
2453 2612
2454 // Create some non-persistent cookies and check that they don't go to the 2613 // Create some non-persistent cookies and check that they don't go to the
2455 // persistent storage. 2614 // persistent storage.
2456 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); 2615 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=Bar"));
2457 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); 2616 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm.get(), url_google_));
2458 EXPECT_EQ(5u, store->commands().size()); 2617 EXPECT_EQ(5u, store->commands().size());
2459 } 2618 }
2460 2619
2461 } // namespace net 2620 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster_store_test.cc ('k') | net/cookies/cookie_store_test_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698