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

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

Issue 1705753002: Evict non-secure cookies less agressively. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« net/cookies/cookie_monster.cc ('K') | « net/cookies/cookie_monster.cc ('k') | no next file » | 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 case 'H': 346 case 'H':
347 return COOKIE_PRIORITY_HIGH; 347 return COOKIE_PRIORITY_HIGH;
348 } 348 }
349 NOTREACHED(); 349 NOTREACHED();
350 return COOKIE_PRIORITY_DEFAULT; 350 return COOKIE_PRIORITY_DEFAULT;
351 } 351 }
352 352
353 // Instantiates a CookieMonster, adds multiple cookies (to http_www_google_) 353 // Instantiates a CookieMonster, adds multiple cookies (to http_www_google_)
354 // with priorities specified by |coded_priority_str|, and tests priority-aware 354 // with priorities specified by |coded_priority_str|, and tests priority-aware
355 // domain cookie eviction. 355 // domain cookie eviction.
356 // |coded_priority_str| specifies a run-length-encoded string of priorities. 356 //
357 // Example: "2M 3L M 4H" means "MMLLLMHHHH", and speicifies sequential (i.e., 357 // Example: |coded_priority_string| of "2MN 3LS MN 4HN" specifies sequential
358 // from least- to most-recently accessed) insertion of 2 medium-priority 358 // (i.e., from least- to most-recently accessed) insertion of 2
359 // cookies, 3 low-priority cookies, 1 medium-priority cookie, and 4 359 // medium-priority non-secure cookies, 3 low-priority secure cookies, 1
360 // high-priority cookies. 360 // medium-priority non-secure cookie, and 4 high-priority non-secure cookies.
361 //
361 // Within each priority, only the least-accessed cookies should be evicted. 362 // Within each priority, only the least-accessed cookies should be evicted.
362 // Thus, to describe expected suriving cookies, it suffices to specify the 363 // Thus, to describe expected suriving cookies, it suffices to specify the
363 // expected population of surviving cookies per priority, i.e., 364 // expected population of surviving cookies per priority, i.e.,
364 // |expected_low_count|, |expected_medium_count|, and |expected_high_count|. 365 // |expected_low_count|, |expected_medium_count|, and |expected_high_count|.
365 void TestPriorityCookieCase(CookieMonster* cm, 366 void TestPriorityCookieCase(CookieMonster* cm,
366 const std::string& coded_priority_str, 367 const std::string& coded_priority_str,
367 size_t expected_low_count, 368 size_t expected_low_count,
368 size_t expected_medium_count, 369 size_t expected_medium_count,
369 size_t expected_high_count) { 370 size_t expected_high_count,
371 size_t expected_nonsecure,
372 size_t expected_secure) {
373 SCOPED_TRACE(coded_priority_str.c_str());
370 this->DeleteAll(cm); 374 this->DeleteAll(cm);
371 int next_cookie_id = 0; 375 int next_cookie_id = 0;
372 std::vector<CookiePriority> priority_list; 376 // A list of cookie IDs, indexed by secure status, then by priority.
373 std::vector<int> id_list[3]; // Indexed by CookiePriority. 377 std::vector<std::vector<std::vector<int>>> id_list{{{}, {}, {}},
378 {{}, {}, {}}};
379 // A list of all the cookies stored, along with their properties.
380 std::vector<std::pair<bool, CookiePriority>> cookie_data;
374 381
375 // Parse |coded_priority_str| and add cookies. 382 // Parse |coded_priority_str| and add cookies.
376 for (const std::string& token : 383 for (const std::string& token :
377 base::SplitString(coded_priority_str, " ", base::TRIM_WHITESPACE, 384 base::SplitString(coded_priority_str, " ", base::TRIM_WHITESPACE,
378 base::SPLIT_WANT_ALL)) { 385 base::SPLIT_WANT_ALL)) {
379 DCHECK(!token.empty()); 386 DCHECK(!token.empty());
380 // Take last character as priority. 387
381 CookiePriority priority = CharToPriority(token.back()); 388 // Take last character as security status, then discard it.
382 std::string priority_str = CookiePriorityToString(priority); 389 bool is_secure = token[token.size() - 1] == 'S';
390
391 // The second-to-last character is the priority. Grab and discard it.
392 CookiePriority priority = CharToPriority(token[token.size() - 2]);
393
383 // The rest of the string (possibly empty) specifies repetition. 394 // The rest of the string (possibly empty) specifies repetition.
384 int rep = 1; 395 int rep = 1;
385 if (!token.empty()) { 396 if (!token.empty()) {
386 bool result = base::StringToInt( 397 bool result = base::StringToInt(
387 base::StringPiece(token.begin(), token.end() - 1), &rep); 398 base::StringPiece(token.begin(), token.end() - 2), &rep);
388 DCHECK(result); 399 DCHECK(result);
389 } 400 }
390 for (; rep > 0; --rep, ++next_cookie_id) { 401 for (; rep > 0; --rep, ++next_cookie_id) {
391 std::string cookie = base::StringPrintf( 402 std::string cookie =
392 "a%d=b;priority=%s", next_cookie_id, priority_str.c_str()); 403 base::StringPrintf("a%d=b;priority=%s;%s", next_cookie_id,
393 EXPECT_TRUE(SetCookie(cm, http_www_google_.url(), cookie)); 404 CookiePriorityToString(priority).c_str(),
394 priority_list.push_back(priority); 405 is_secure ? "secure" : "");
395 id_list[priority].push_back(next_cookie_id); 406 EXPECT_TRUE(SetCookie(cm, https_www_google_.url(), cookie));
407 cookie_data.push_back(std::make_pair(is_secure, priority));
408 id_list[is_secure][priority].push_back(next_cookie_id);
396 } 409 }
397 } 410 }
398 411
399 int num_cookies = static_cast<int>(priority_list.size()); 412 int num_cookies = static_cast<int>(cookie_data.size());
400 std::vector<int> surviving_id_list[3]; // Indexed by CookiePriority. 413 // A list of cookie IDs, indexed by secure status, then by priority.
414 std::vector<std::vector<std::vector<int>>> surviving_id_list{{{}, {}, {}},
415 {{}, {}, {}}};
401 416
402 // Parse the list of cookies 417 // Parse the list of cookies
403 std::string cookie_str = this->GetCookies(cm, http_www_google_.url()); 418 std::string cookie_str = this->GetCookies(cm, https_www_google_.url());
419 size_t num_nonsecure = 0;
420 size_t num_secure = 0;
404 for (const std::string& token : base::SplitString( 421 for (const std::string& token : base::SplitString(
405 cookie_str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 422 cookie_str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
406 // Assuming *it is "a#=b", so extract and parse "#" portion. 423 // Assuming *it is "a#=b", so extract and parse "#" portion.
407 int id = -1; 424 int id = -1;
408 bool result = base::StringToInt( 425 bool result = base::StringToInt(
409 base::StringPiece(token.begin() + 1, token.end() - 2), &id); 426 base::StringPiece(token.begin() + 1, token.end() - 2), &id);
410 DCHECK(result); 427 DCHECK(result);
411 DCHECK_GE(id, 0); 428 DCHECK_GE(id, 0);
412 DCHECK_LT(id, num_cookies); 429 DCHECK_LT(id, num_cookies);
413 surviving_id_list[priority_list[id]].push_back(id); 430 surviving_id_list[cookie_data[id].first][cookie_data[id].second]
431 .push_back(id);
432 if (cookie_data[id].first)
433 num_secure += 1;
434 else
435 num_nonsecure += 1;
414 } 436 }
415 437
438 EXPECT_EQ(expected_nonsecure, num_nonsecure);
439 EXPECT_EQ(expected_secure, num_secure);
440
416 // Validate each priority. 441 // Validate each priority.
417 size_t expected_count[3] = { 442 size_t expected_count[3] = {
418 expected_low_count, expected_medium_count, expected_high_count}; 443 expected_low_count, expected_medium_count, expected_high_count};
419 for (int i = 0; i < 3; ++i) { 444 for (int i = 0; i < 3; ++i) {
420 DCHECK_LE(surviving_id_list[i].size(), id_list[i].size()); 445 size_t num_for_priority =
421 EXPECT_EQ(expected_count[i], surviving_id_list[i].size()); 446 surviving_id_list[0][i].size() + surviving_id_list[1][i].size();
447 EXPECT_EQ(expected_count[i], num_for_priority);
422 // Verify that the remaining cookies are the most recent among those 448 // Verify that the remaining cookies are the most recent among those
423 // with the same priorities. 449 // with the same priorities.
424 if (expected_count[i] == surviving_id_list[i].size()) { 450 if (expected_count[i] == num_for_priority) {
425 std::sort(surviving_id_list[i].begin(), surviving_id_list[i].end()); 451 // Non-secure:
426 EXPECT_TRUE(std::equal(surviving_id_list[i].begin(), 452 std::sort(surviving_id_list[0][i].begin(),
427 surviving_id_list[i].end(), 453 surviving_id_list[0][i].end());
428 id_list[i].end() - expected_count[i])); 454 EXPECT_TRUE(std::equal(
455 surviving_id_list[0][i].begin(), surviving_id_list[0][i].end(),
456 id_list[0][i].end() - surviving_id_list[0][i].size()));
457
458 // Secure:
459 std::sort(surviving_id_list[1][i].begin(),
460 surviving_id_list[1][i].end());
461 EXPECT_TRUE(std::equal(
462 surviving_id_list[1][i].begin(), surviving_id_list[1][i].end(),
463 id_list[1][i].end() - surviving_id_list[1][i].size()));
429 } 464 }
430 } 465 }
431 } 466 }
432 467
433 // Represents a number of cookies to create, if they are Secure cookies, and 468 // Represents a number of cookies to create, if they are Secure cookies, and
434 // a url to add them to. 469 // a url to add them to.
435 struct CookiesEntry { 470 struct CookiesEntry {
436 size_t num_cookies; 471 size_t num_cookies;
437 bool is_secure; 472 bool is_secure;
438 }; 473 };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (cookie.IsSecure()) 520 if (cookie.IsSecure())
486 ++total_secure_cookies; 521 ++total_secure_cookies;
487 else 522 else
488 ++total_non_secure_cookies; 523 ++total_non_secure_cookies;
489 } 524 }
490 525
491 EXPECT_EQ(expected_secure_cookies, total_secure_cookies); 526 EXPECT_EQ(expected_secure_cookies, total_secure_cookies);
492 EXPECT_EQ(expected_non_secure_cookies, total_non_secure_cookies); 527 EXPECT_EQ(expected_non_secure_cookies, total_non_secure_cookies);
493 } 528 }
494 529
495 void TestPriorityAwareGarbageCollectHelper() { 530 void TestPriorityAwareGarbageCollectHelperNonSecure() {
496 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. 531 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint.
497 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); 532 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies);
498 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - 533 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
499 CookieMonster::kDomainPurgeCookies); 534 CookieMonster::kDomainPurgeCookies);
500 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow);
501 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium);
502 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh);
503 535
504 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 536 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
505 537
506 // Each test case adds 181 cookies, so 31 cookies are evicted. 538 // Each test case adds 181 cookies, so 31 cookies are evicted.
507 // Cookie same priority, repeated for each priority. 539 // Cookie same priority, repeated for each priority.
508 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); 540 TestPriorityCookieCase(cm.get(), "181LN", 150U, 0U, 0U, 150U, 0U);
509 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); 541 TestPriorityCookieCase(cm.get(), "181MN", 0U, 150U, 0U, 150U, 0U);
510 TestPriorityCookieCase(cm.get(), "181H", 0U, 0U, 150U); 542 TestPriorityCookieCase(cm.get(), "181HN", 0U, 0U, 150U, 150U, 0U);
511 543
512 // Pairwise scenarios. 544 // Pairwise scenarios.
513 // Round 1 => none; round2 => 31M; round 3 => none. 545 // Round 1 => none; round2 => 31M; round 3 => none.
514 TestPriorityCookieCase(cm.get(), "10H 171M", 0U, 140U, 10U); 546 TestPriorityCookieCase(cm.get(), "10HN 171MN", 0U, 140U, 10U, 150U, 0U);
515 // Round 1 => 10L; round2 => 21M; round 3 => none. 547 // Round 1 => 10L; round2 => 21M; round 3 => none.
516 TestPriorityCookieCase(cm.get(), "141M 40L", 30U, 120U, 0U); 548 TestPriorityCookieCase(cm.get(), "141MN 40LN", 30U, 120U, 0U, 150U, 0U);
517 // Round 1 => none; round2 => none; round 3 => 31H. 549 // Round 1 => none; round2 => none; round 3 => 31H.
518 TestPriorityCookieCase(cm.get(), "101H 80M", 0U, 80U, 70U); 550 TestPriorityCookieCase(cm.get(), "101HN 80MN", 0U, 80U, 70U, 150U, 0U);
519 551
520 // For {low, medium} priorities right on quota, different orders. 552 // For {low, medium} priorities right on quota, different orders.
521 // Round 1 => 1L; round 2 => none, round3 => 30L. 553 // Round 1 => 1L; round 2 => none, round3 => 30L.
522 TestPriorityCookieCase(cm.get(), "31L 50M 100H", 0U, 50U, 100U); 554 TestPriorityCookieCase(cm.get(), "31LN 50MN 100HN", 0U, 50U, 100U, 150U,
555 0U);
523 // Round 1 => none; round 2 => 1M, round3 => 30M. 556 // Round 1 => none; round 2 => 1M, round3 => 30M.
524 TestPriorityCookieCase(cm.get(), "51M 100H 30L", 30U, 20U, 100U); 557 TestPriorityCookieCase(cm.get(), "51MN 100HN 30LN", 30U, 20U, 100U, 150U,
558 0U);
525 // Round 1 => none; round 2 => none; round3 => 31H. 559 // Round 1 => none; round 2 => none; round3 => 31H.
526 TestPriorityCookieCase(cm.get(), "101H 50M 30L", 30U, 50U, 70U); 560 TestPriorityCookieCase(cm.get(), "101HN 50MN 30LN", 30U, 50U, 70U, 150U,
561 0U);
527 562
528 // Round 1 => 10L; round 2 => 10M; round3 => 11H. 563 // Round 1 => 10L; round 2 => 10M; round3 => 11H.
529 TestPriorityCookieCase(cm.get(), "81H 60M 40L", 30U, 50U, 70U); 564 TestPriorityCookieCase(cm.get(), "81HN 60MN 40LN", 30U, 50U, 70U, 150U, 0U);
530 565
531 // More complex scenarios. 566 // More complex scenarios.
532 // Round 1 => 10L; round 2 => 10M; round 3 => 11H. 567 // Round 1 => 10L; round 2 => 10M; round 3 => 11H.
533 TestPriorityCookieCase(cm.get(), "21H 60M 40L 60H", 30U, 50U, 70U); 568 TestPriorityCookieCase(cm.get(), "21HN 60MN 40LN 60HN", 30U, 50U, 70U, 150U,
569 0U);
534 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none. 570 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none.
535 TestPriorityCookieCase(cm.get(), "11H 10M 20L 110M 20L 10H", 20U, 109U, 571 TestPriorityCookieCase(cm.get(), "11HN 10MN 20LN 110MN 20LN 10HN", 20U,
536 21U); 572 109U, 21U, 150U, 0U);
537 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H. 573 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H.
538 TestPriorityCookieCase(cm.get(), "11L 10M 140H 10M 10L", 10U, 10U, 130U); 574 TestPriorityCookieCase(cm.get(), "11LN 10MN 140HN 10MN 10LN", 10U, 10U,
575 130U, 150U, 0U);
539 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H. 576 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H.
540 TestPriorityCookieCase(cm.get(), "11M 10H 10L 60M 90H", 0U, 60U, 90U); 577 TestPriorityCookieCase(cm.get(), "11MN 10HN 10LN 60MN 90HN", 0U, 60U, 90U,
578 150U, 0U);
541 // Round 1 => none; round 2 => 10L, 21M; round 3 => none. 579 // Round 1 => none; round 2 => 10L, 21M; round 3 => none.
542 TestPriorityCookieCase(cm.get(), "11M 10H 10L 90M 60H", 0U, 80U, 70U); 580 TestPriorityCookieCase(cm.get(), "11MN 10HN 10LN 90MN 60HN", 0U, 80U, 70U,
581 150U, 0U);
582 }
583
584 void TestPriorityAwareGarbageCollectHelperSecure() {
585 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint.
586 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies);
587 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
588 CookieMonster::kDomainPurgeCookies);
589
590 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
591
592 // Each test case adds 181 cookies, so 31 cookies are evicted.
593 // Cookie same priority, repeated for each priority.
594 TestPriorityCookieCase(cm.get(), "181LS", 150U, 0U, 0U, 0U, 150U);
595 TestPriorityCookieCase(cm.get(), "181MS", 0U, 150U, 0U, 0U, 150U);
596 TestPriorityCookieCase(cm.get(), "181HS", 0U, 0U, 150U, 0U, 150U);
597
598 // Pairwise scenarios.
599 // Round 1 => none; round2 => 31M; round 3 => none.
600 TestPriorityCookieCase(cm.get(), "10HS 171MS", 0U, 140U, 10U, 0U, 150U);
601 // Round 1 => 10L; round2 => 21M; round 3 => none.
602 TestPriorityCookieCase(cm.get(), "141MS 40LS", 30U, 120U, 0U, 0U, 150U);
603 // Round 1 => none; round2 => none; round 3 => 31H.
604 TestPriorityCookieCase(cm.get(), "101HS 80MS", 0U, 80U, 70U, 0U, 150U);
605
606 // For {low, medium} priorities right on quota, different orders.
607 // Round 1 => 1L; round 2 => none, round3 => 30L.
608 TestPriorityCookieCase(cm.get(), "31LS 50MS 100HS", 0U, 50U, 100U, 0U,
609 150U);
610 // Round 1 => none; round 2 => 1M, round3 => 30M.
611 TestPriorityCookieCase(cm.get(), "51MS 100HS 30LS", 30U, 20U, 100U, 0U,
612 150U);
613 // Round 1 => none; round 2 => none; round3 => 31H.
614 TestPriorityCookieCase(cm.get(), "101HS 50MS 30LS", 30U, 50U, 70U, 0U,
615 150U);
616
617 // Round 1 => 10L; round 2 => 10M; round3 => 11H.
618 TestPriorityCookieCase(cm.get(), "81HS 60MS 40LS", 30U, 50U, 70U, 0U, 150U);
619
620 // More complex scenarios.
621 // Round 1 => 10L; round 2 => 10M; round 3 => 11H.
622 TestPriorityCookieCase(cm.get(), "21HS 60MS 40LS 60HS", 30U, 50U, 70U, 0U,
623 150U);
624 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none.
625 TestPriorityCookieCase(cm.get(), "11HS 10MS 20LS 110MS 20LS 10HS", 20U,
626 109U, 21U, 0U, 150U);
627 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H.
628 TestPriorityCookieCase(cm.get(), "11LS 10MS 140HS 10MS 10LS", 10U, 10U,
629 130U, 0U, 150U);
630 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H.
631 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 60MS 90HS", 0U, 60U, 90U,
632 0U, 150U);
633 // Round 1 => none; round 2 => 10L, 21M; round 3 => none.
634 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 90MS 60HS", 0U, 80U, 70U,
635 0U, 150U);
636 }
637
638 void TestPriorityAwareGarbageCollectHelperMixed() {
639 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint.
640 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies);
641 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
642 CookieMonster::kDomainPurgeCookies);
643
644 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
645
646 // Each test case adds 180 secure cookies, and some non-secure cookie. The
jww 2016/02/18 01:05:19 Maybe add a few sanity check cases with > 180 cook
647 // secure cookies take priority, so the non-secure cookie is removed, along
648 // with 30 secure cookies. Repeated for each priority, and with the
649 // non-secure cookie as older and newer.
650 TestPriorityCookieCase(cm.get(), "1LN 180LS", 150U, 0U, 0U, 0U, 150U);
651 TestPriorityCookieCase(cm.get(), "1MN 180MS", 0U, 150U, 0U, 0U, 150U);
652 TestPriorityCookieCase(cm.get(), "1HN 180HS", 0U, 0U, 150U, 0U, 150U);
653 TestPriorityCookieCase(cm.get(), "180LS 1LN", 150U, 0U, 0U, 0U, 150U);
654 TestPriorityCookieCase(cm.get(), "180MS 1MN", 0U, 150U, 0U, 0U, 150U);
655 TestPriorityCookieCase(cm.get(), "180HS 1HN", 0U, 0U, 150U, 0U, 150U);
656
657 // Higher-priority non-secure cookies are removed before any secure cookie.
658 TestPriorityCookieCase(cm.get(), "180LS 1MN", 150U, 0U, 0U, 0U, 150U);
659 TestPriorityCookieCase(cm.get(), "180LS 1HN", 150U, 0U, 0U, 0U, 150U);
660 TestPriorityCookieCase(cm.get(), "180MS 1HN", 0U, 150U, 0U, 0U, 150U);
661 TestPriorityCookieCase(cm.get(), "1MN 180LS", 150U, 0U, 0U, 0U, 150U);
662 TestPriorityCookieCase(cm.get(), "1HN 180LS", 150U, 0U, 0U, 0U, 150U);
663 TestPriorityCookieCase(cm.get(), "1HN 180MS", 0U, 150U, 0U, 0U, 150U);
664
665 // Pairwise:
666 TestPriorityCookieCase(cm.get(), "1LS 180LN", 150U, 0U, 0U, 149U, 1U);
667 TestPriorityCookieCase(cm.get(), "100LS 81LN", 150U, 0U, 0U, 50U, 100U);
668 TestPriorityCookieCase(cm.get(), "150LS 31LN", 150U, 0U, 0U, 0U, 150U);
669 TestPriorityCookieCase(cm.get(), "1LS 180HN", 1U, 0U, 149U, 149U, 1U);
670 TestPriorityCookieCase(cm.get(), "100LS 81HN", 100U, 0U, 50U, 50U, 100U);
671 TestPriorityCookieCase(cm.get(), "150LS 31HN", 150U, 0U, 0U, 0U, 150U);
672
673 // Quota calculations inside non-secure/secure blocks remain in place:
674 TestPriorityCookieCase(cm.get(), "50HN 50LS 81HS", 50U, 0U, 100U, 19U,
675 131U);
543 } 676 }
544 677
545 // Function for creating a CM with a number of cookies in it, 678 // Function for creating a CM with a number of cookies in it,
546 // no store (and hence no ability to affect access time). 679 // no store (and hence no ability to affect access time).
547 CookieMonster* CreateMonsterForGC(int num_cookies) { 680 CookieMonster* CreateMonsterForGC(int num_cookies) {
548 CookieMonster* cm(new CookieMonster(NULL, NULL)); 681 CookieMonster* cm(new CookieMonster(NULL, NULL));
549 for (int i = 0; i < num_cookies; i++) { 682 for (int i = 0; i < num_cookies; i++) {
550 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); 683 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1");
551 } 684 }
552 return cm; 685 return cm;
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 base::PlatformThread::Sleep( 1374 base::PlatformThread::Sleep(
1242 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); 1375 base::TimeDelta::FromMilliseconds(kAccessDelayMs));
1243 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url())); 1376 EXPECT_EQ("A=B", GetCookies(cm.get(), http_www_google_.url()));
1244 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm.get())); 1377 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm.get()));
1245 } 1378 }
1246 1379
1247 TEST_F(CookieMonsterTest, TestHostGarbageCollection) { 1380 TEST_F(CookieMonsterTest, TestHostGarbageCollection) {
1248 TestHostGarbageCollectHelper(); 1381 TestHostGarbageCollectHelper();
1249 } 1382 }
1250 1383
1251 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollection) { 1384 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionNonSecure) {
1252 TestPriorityAwareGarbageCollectHelper(); 1385 TestPriorityAwareGarbageCollectHelperNonSecure();
1386 }
1387
1388 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionSecure) {
1389 TestPriorityAwareGarbageCollectHelperSecure();
1390 }
1391
1392 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionMixed) {
1393 TestPriorityAwareGarbageCollectHelperMixed();
1253 } 1394 }
1254 1395
1255 TEST_F(CookieMonsterTest, SetCookieableSchemes) { 1396 TEST_F(CookieMonsterTest, SetCookieableSchemes) {
1256 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 1397 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
1257 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL)); 1398 scoped_refptr<CookieMonster> cm_foo(new CookieMonster(NULL, NULL));
1258 1399
1259 // Only cm_foo should allow foo:// cookies. 1400 // Only cm_foo should allow foo:// cookies.
1260 std::vector<std::string> schemes; 1401 std::vector<std::string> schemes;
1261 schemes.push_back("foo"); 1402 schemes.push_back("foo");
1262 cm_foo->SetCookieableSchemes(schemes); 1403 cm_foo->SetCookieableSchemes(schemes);
(...skipping 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 monster()->AddCallbackForCookie( 3464 monster()->AddCallbackForCookie(
3324 test_url_, "abc", 3465 test_url_, "abc",
3325 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3466 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3326 SetCookie(monster(), test_url_, "abc=def"); 3467 SetCookie(monster(), test_url_, "abc=def");
3327 base::MessageLoop::current()->RunUntilIdle(); 3468 base::MessageLoop::current()->RunUntilIdle();
3328 EXPECT_EQ(1U, cookies0.size()); 3469 EXPECT_EQ(1U, cookies0.size());
3329 EXPECT_EQ(1U, cookies0.size()); 3470 EXPECT_EQ(1U, cookies0.size());
3330 } 3471 }
3331 3472
3332 } // namespace net 3473 } // namespace net
OLDNEW
« net/cookies/cookie_monster.cc ('K') | « net/cookies/cookie_monster.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698