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

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

Issue 1976073002: Making cookies eviction quotas match spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 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
« no previous file with comments | « 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_monster.h" 5 #include "net/cookies/cookie_monster.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 // Cookie same priority, repeated for each priority. 558 // Cookie same priority, repeated for each priority.
559 TestPriorityCookieCase(cm.get(), "181LN", 150U, 0U, 0U, 150U, 0U); 559 TestPriorityCookieCase(cm.get(), "181LN", 150U, 0U, 0U, 150U, 0U);
560 TestPriorityCookieCase(cm.get(), "181MN", 0U, 150U, 0U, 150U, 0U); 560 TestPriorityCookieCase(cm.get(), "181MN", 0U, 150U, 0U, 150U, 0U);
561 TestPriorityCookieCase(cm.get(), "181HN", 0U, 0U, 150U, 150U, 0U); 561 TestPriorityCookieCase(cm.get(), "181HN", 0U, 0U, 150U, 150U, 0U);
562 562
563 // Pairwise scenarios. 563 // Pairwise scenarios.
564 // Round 1 => none; round2 => 31M; round 3 => none. 564 // Round 1 => none; round2 => 31M; round 3 => none.
565 TestPriorityCookieCase(cm.get(), "10HN 171MN", 0U, 140U, 10U, 150U, 0U); 565 TestPriorityCookieCase(cm.get(), "10HN 171MN", 0U, 140U, 10U, 150U, 0U);
566 // Round 1 => 10L; round2 => 21M; round 3 => none. 566 // Round 1 => 10L; round2 => 21M; round 3 => none.
567 TestPriorityCookieCase(cm.get(), "141MN 40LN", 30U, 120U, 0U, 150U, 0U); 567 TestPriorityCookieCase(cm.get(), "141MN 40LN", 30U, 120U, 0U, 150U, 0U);
568 // Round 1 => none; round2 => none; round 3 => 31H. 568 // Round 1 => none; round2 => 30M; round 3 => 1H.
569 TestPriorityCookieCase(cm.get(), "101HN 80MN", 0U, 80U, 70U, 150U, 0U); 569 TestPriorityCookieCase(cm.get(), "101HN 80MN", 0U, 50U, 100U, 150U, 0U);
570 570
571 // For {low, medium} priorities right on quota, different orders. 571 // For {low, medium} priorities right on quota, different orders.
572 // Round 1 => 1L; round 2 => none, round3 => 30L. 572 // Round 1 => 1L; round 2 => none, round3 => 30H.
573 TestPriorityCookieCase(cm.get(), "31LN 50MN 100HN", 0U, 50U, 100U, 150U, 573 TestPriorityCookieCase(cm.get(), "31LN 50MN 100HN", 30U, 50U, 70U, 150U,
574 0U); 574 0U);
575 // Round 1 => none; round 2 => 1M, round3 => 30M. 575 // Round 1 => none; round 2 => 1M, round3 => 30H.
576 TestPriorityCookieCase(cm.get(), "51MN 100HN 30LN", 30U, 20U, 100U, 150U, 576 TestPriorityCookieCase(cm.get(), "51MN 100HN 30LN", 30U, 50U, 70U, 150U,
577 0U); 577 0U);
578 // Round 1 => none; round 2 => none; round3 => 31H. 578 // Round 1 => none; round 2 => none; round3 => 31H.
579 TestPriorityCookieCase(cm.get(), "101HN 50MN 30LN", 30U, 50U, 70U, 150U, 579 TestPriorityCookieCase(cm.get(), "101HN 50MN 30LN", 30U, 50U, 70U, 150U,
580 0U); 580 0U);
581 581
582 // Round 1 => 10L; round 2 => 10M; round3 => 11H. 582 // Round 1 => 10L; round 2 => 10M; round3 => 11H.
583 TestPriorityCookieCase(cm.get(), "81HN 60MN 40LN", 30U, 50U, 70U, 150U, 0U); 583 TestPriorityCookieCase(cm.get(), "81HN 60MN 40LN", 30U, 50U, 70U, 150U, 0U);
584 584
585 // More complex scenarios. 585 // More complex scenarios.
586 // Round 1 => 10L; round 2 => 10M; round 3 => 11H. 586 // Round 1 => 10L; round 2 => 10M; round 3 => 11H.
587 TestPriorityCookieCase(cm.get(), "21HN 60MN 40LN 60HN", 30U, 50U, 70U, 150U, 587 TestPriorityCookieCase(cm.get(), "21HN 60MN 40LN 60HN", 30U, 50U, 70U, 150U,
588 0U); 588 0U);
589 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none. 589 // Round 1 => 10L; round 2 => 21M; round 3 => 0H.
590 TestPriorityCookieCase(cm.get(), "11HN 10MN 20LN 110MN 20LN 10HN", 20U, 590 TestPriorityCookieCase(cm.get(), "11HN 10MN 20LN 110MN 20LN 10HN", 30U, 99U,
591 109U, 21U, 150U, 0U); 591 21U, 150U, 0U);
592 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H. 592 // Round 1 => none; round 2 => none; round 3 => 31H.
593 TestPriorityCookieCase(cm.get(), "11LN 10MN 140HN 10MN 10LN", 10U, 10U, 593 TestPriorityCookieCase(cm.get(), "11LN 10MN 140HN 10MN 10LN", 21U, 20U,
594 130U, 150U, 0U); 594 109U, 150U, 0U);
595 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H. 595 // Round 1 => none; round 2 => 21M; round 3 => 10H.
596 TestPriorityCookieCase(cm.get(), "11MN 10HN 10LN 60MN 90HN", 0U, 60U, 90U, 596 TestPriorityCookieCase(cm.get(), "11MN 10HN 10LN 60MN 90HN", 10U, 50U, 90U,
597 150U, 0U); 597 150U, 0U);
598 // Round 1 => none; round 2 => 10L, 21M; round 3 => none. 598 // Round 1 => none; round 2 => 31M; round 3 => none.
599 TestPriorityCookieCase(cm.get(), "11MN 10HN 10LN 90MN 60HN", 0U, 80U, 70U, 599 TestPriorityCookieCase(cm.get(), "11MN 10HN 10LN 90MN 60HN", 10U, 70U, 70U,
600 150U, 0U); 600 150U, 0U);
601 601
602 // TODO(jww): According to 602 // // TODO(jww): According to
603 // https://tools.ietf.org/html/draft-west-cookie-priority#section-3, it 603 // // https://tools.ietf.org/html/draft-west-cookie-priority#section-3,
jww 2016/06/03 22:26:25 Your bug fixes what this comment is discussing, ri
604 // seems that quotas are a mechanism for preventing another application on 604 // it
605 // the same doman from DoS'ing an application by constantly evicting *all* 605 // // seems that quotas are a mechanism for preventing another
606 // lower priority cookies. 606 // application on
607 // 607 // // the same doman from DoS'ing an application by constantly evicting
608 // Unfortunately, this has never strictly worked in our implementation. Take 608 // *all*
609 // the following test as an example: 609 // // lower priority cookies.
610 // TestPriorityCookieCase(cm.get(), "50LN 131HN", 30U, 0U, 120U, 150U, 0U); 610 // //
611 // 611 // // Unfortunately, this has never strictly worked in our
612 // According to this theory, we would expect eviction to proceed as: 612 // implementation. Take
613 // // the following test as an example:
614 // // TestPriorityCookieCase(cm.get(), "50LN 131HN", 30U, 0U, 120U, 150U,
615 // 0U);
616 // //
617 // // According to this theory, we would expect eviction to proceed as:
618 // // Round 1 => 20L; round 2 => 0; round 3 => 11H
619 // // thus resulting in 30L and 120H at the end.
620 // //
621 // // However, what happens in practice is that the cookies left are 19L
622 // and
623 // // 131H. This is because the quotas are accumulated over the rounds
624 // and what
625 // // priority they apply to is lost information. Since in the last round
626 // all
627 // // that is known is a total quota, and the low-priority cookies are
628 // least
629 // // recently accessed, they are evicted first to get down to 150
630 // cookies.
631 // //
632 // // We should address this and uncomment the test below when it is
633 // fixed.
634 // //
635 // // See https://crbug.com/609550
636 // //
613 // Round 1 => 20L; round 2 => 0; round 3 => 11H 637 // Round 1 => 20L; round 2 => 0; round 3 => 11H
614 // thus resulting in 30L and 120H at the end. 638 TestPriorityCookieCase(cm.get(), "50LN 131HN", 30U, 0U, 120U, 150U, 0U);
615 //
616 // However, what happens in practice is that the cookies left are 19L and
617 // 131H. This is because the quotas are accumulated over the rounds and what
618 // priority they apply to is lost information. Since in the last round all
619 // that is known is a total quota, and the low-priority cookies are least
620 // recently accessed, they are evicted first to get down to 150 cookies.
621 //
622 // We should address this and uncomment the test below when it is fixed.
623 //
624 // See https://crbug.com/609550
625 //
626 // Round 1 => 20L; round 2 => 0; round 3 => 11H
627 // TestPriorityCookieCase(cm.get(), "50LN 131HN", 30U, 0U, 120U, 150U, 0U);
628 // Round 1 => 20L; round 2 => 0; round 3 => 11H 639 // Round 1 => 20L; round 2 => 0; round 3 => 11H
629 TestPriorityCookieCase(cm.get(), "131HN 50LN", 30U, 0U, 120U, 150U, 0U); 640 TestPriorityCookieCase(cm.get(), "131HN 50LN", 30U, 0U, 120U, 150U, 0U);
630 // Round 1 => 20L; round 2 => none; round 3 => 11H. 641 // Round 1 => 20L; round 2 => none; round 3 => 11H.
631 TestPriorityCookieCase(cm.get(), "50HN 50LN 81HN", 30U, 0U, 120U, 150U, 0U); 642 TestPriorityCookieCase(cm.get(), "50HN 50LN 81HN", 30U, 0U, 120U, 150U, 0U);
632 // Round 1 => 20L; round 2 => none; round 3 => 11H. 643 // Round 1 => 20L; round 2 => none; round 3 => 11H.
633 TestPriorityCookieCase(cm.get(), "81HN 50LN 50HN", 30U, 0U, 120U, 150U, 0U); 644 TestPriorityCookieCase(cm.get(), "81HN 50LN 50HN", 30U, 0U, 120U, 150U, 0U);
634 } 645 }
635 646
636 void TestPriorityAwareGarbageCollectHelperSecure() { 647 void TestPriorityAwareGarbageCollectHelperSecure() {
637 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. 648 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint.
638 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); 649 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies);
639 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - 650 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
640 CookieMonster::kDomainPurgeCookies); 651 CookieMonster::kDomainPurgeCookies);
641 652
642 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); 653 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
643 654
644 // Each test case adds 181 cookies, so 31 cookies are evicted. 655 // Each test case adds 181 cookies, so 31 cookies are evicted.
645 // Cookie same priority, repeated for each priority. 656 // Cookie same priority, repeated for each priority.
657 // Round 1 => 31L; round2 => none; round 3 => none.
646 TestPriorityCookieCase(cm.get(), "181LS", 150U, 0U, 0U, 0U, 150U); 658 TestPriorityCookieCase(cm.get(), "181LS", 150U, 0U, 0U, 0U, 150U);
659 // Round 1 => none; round2 => 31M; round 3 => none.
647 TestPriorityCookieCase(cm.get(), "181MS", 0U, 150U, 0U, 0U, 150U); 660 TestPriorityCookieCase(cm.get(), "181MS", 0U, 150U, 0U, 0U, 150U);
661 // Round 1 => none; round2 => none; round 3 => 31H.
648 TestPriorityCookieCase(cm.get(), "181HS", 0U, 0U, 150U, 0U, 150U); 662 TestPriorityCookieCase(cm.get(), "181HS", 0U, 0U, 150U, 0U, 150U);
649 663
650 // Pairwise scenarios. 664 // Pairwise scenarios.
651 // Round 1 => none; round2 => 31M; round 3 => none. 665 // Round 1 => none; round2 => 31M; round 3 => none.
652 TestPriorityCookieCase(cm.get(), "10HS 171MS", 0U, 140U, 10U, 0U, 150U); 666 TestPriorityCookieCase(cm.get(), "10HS 171MS", 0U, 140U, 10U, 0U, 150U);
653 // Round 1 => 10L; round2 => 21M; round 3 => none. 667 // Round 1 => 10L; round2 => 21M; round 3 => none.
654 TestPriorityCookieCase(cm.get(), "141MS 40LS", 30U, 120U, 0U, 0U, 150U); 668 TestPriorityCookieCase(cm.get(), "141MS 40LS", 30U, 120U, 0U, 0U, 150U);
655 // Round 1 => none; round2 => none; round 3 => 31H. 669 // Round 1 => none; round2 => 30M; round 3 => 1H.
656 TestPriorityCookieCase(cm.get(), "101HS 80MS", 0U, 80U, 70U, 0U, 150U); 670 TestPriorityCookieCase(cm.get(), "101HS 80MS", 0U, 50U, 100U, 0U, 150U);
657 671
658 // For {low, medium} priorities right on quota, different orders. 672 // For {low, medium} priorities right on quota, different orders.
659 // Round 1 => 1L; round 2 => none, round3 => 30L. 673 // Round 1 => 1L; round 2 => none, round3 => 30H.
660 TestPriorityCookieCase(cm.get(), "31LS 50MS 100HS", 0U, 50U, 100U, 0U, 674 TestPriorityCookieCase(cm.get(), "31LS 50MS 100HS", 30U, 50U, 70U, 0U,
661 150U); 675 150U);
662 // Round 1 => none; round 2 => 1M, round3 => 30M. 676 // Round 1 => none; round 2 => 1M, round3 => 30H.
663 TestPriorityCookieCase(cm.get(), "51MS 100HS 30LS", 30U, 20U, 100U, 0U, 677 TestPriorityCookieCase(cm.get(), "51MS 100HS 30LS", 30U, 50U, 70U, 0U,
664 150U); 678 150U);
665 // Round 1 => none; round 2 => none; round3 => 31H. 679 // Round 1 => none; round 2 => none; round3 => 31H.
666 TestPriorityCookieCase(cm.get(), "101HS 50MS 30LS", 30U, 50U, 70U, 0U, 680 TestPriorityCookieCase(cm.get(), "101HS 50MS 30LS", 30U, 50U, 70U, 0U,
667 150U); 681 150U);
668 682
669 // Round 1 => 10L; round 2 => 10M; round3 => 11H. 683 // Round 1 => 10L; round 2 => 10M; round3 => 11H.
670 TestPriorityCookieCase(cm.get(), "81HS 60MS 40LS", 30U, 50U, 70U, 0U, 150U); 684 TestPriorityCookieCase(cm.get(), "81HS 60MS 40LS", 30U, 50U, 70U, 0U, 150U);
671 685
672 // More complex scenarios. 686 // More complex scenarios.
673 // Round 1 => 10L; round 2 => 10M; round 3 => 11H. 687 // Round 1 => 10L; round 2 => 10M; round 3 => 11H.
674 TestPriorityCookieCase(cm.get(), "21HS 60MS 40LS 60HS", 30U, 50U, 70U, 0U, 688 TestPriorityCookieCase(cm.get(), "21HS 60MS 40LS 60HS", 30U, 50U, 70U, 0U,
675 150U); 689 150U);
676 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none. 690 // Round 1 => 10L; round 2 => 21M; round 3 => none.
677 TestPriorityCookieCase(cm.get(), "11HS 10MS 20LS 110MS 20LS 10HS", 20U, 691 TestPriorityCookieCase(cm.get(), "11HS 10MS 20LS 110MS 20LS 10HS", 30U, 99U,
678 109U, 21U, 0U, 150U); 692 21U, 0U, 150U);
679 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H. 693 // Round 1 => none; round 2 => none; round 3 => 31H.
680 TestPriorityCookieCase(cm.get(), "11LS 10MS 140HS 10MS 10LS", 10U, 10U, 694 TestPriorityCookieCase(cm.get(), "11LS 10MS 140HS 10MS 10LS", 21U, 20U,
681 130U, 0U, 150U); 695 109U, 0U, 150U);
682 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H. 696 // Round 1 => none; round 2 => 21M; round 3 => 10H.
683 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 60MS 90HS", 0U, 60U, 90U, 697 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 60MS 90HS", 10U, 50U, 90U,
684 0U, 150U); 698 0U, 150U);
685 // Round 1 => none; round 2 => 10L, 21M; round 3 => none. 699 // Round 1 => none; round 2 => 31M; round 3 => none.
686 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 90MS 60HS", 0U, 80U, 70U, 700 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 90MS 60HS", 10U, 70U, 70U,
687 0U, 150U); 701 0U, 150U);
688 } 702 }
689 703
690 void TestPriorityAwareGarbageCollectHelperMixed() { 704 void TestPriorityAwareGarbageCollectHelperMixed() {
691 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. 705 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint.
692 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); 706 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies);
693 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - 707 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies -
694 CookieMonster::kDomainPurgeCookies); 708 CookieMonster::kDomainPurgeCookies);
695 709
696 std::unique_ptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 710 std::unique_ptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
697 711
698 // Each test case adds 180 secure cookies, and some non-secure cookie. The 712 // Each test case adds 180 secure cookies, and some non-secure cookie. The
699 // secure cookies take priority, so the non-secure cookie is removed, along 713 // secure cookies take priority, so the non-secure cookie is removed, along
700 // with 30 secure cookies. Repeated for each priority, and with the 714 // with 30 secure cookies. Repeated for each priority, and with the
701 // non-secure cookie as older and newer. 715 // non-secure cookie as older and newer.
716 // Round 1 => 1LN; round 2 => 30LS; round 3 => none.
717 // Round 4 => none; round 5 => none; round 6 => none.
702 TestPriorityCookieCase(cm.get(), "1LN 180LS", 150U, 0U, 0U, 0U, 150U); 718 TestPriorityCookieCase(cm.get(), "1LN 180LS", 150U, 0U, 0U, 0U, 150U);
719 // Round 1 => none; round 2 => none; round 3 => 1MN.
720 // Round 4 => none; round 5 => 30MS; round 6 => none.
703 TestPriorityCookieCase(cm.get(), "1MN 180MS", 0U, 150U, 0U, 0U, 150U); 721 TestPriorityCookieCase(cm.get(), "1MN 180MS", 0U, 150U, 0U, 0U, 150U);
722 // Round 1 => none; round 2 => none; round 3 => none.
723 // Round 4 => 1HN; round 5 => none; round 6 => 30HS.
704 TestPriorityCookieCase(cm.get(), "1HN 180HS", 0U, 0U, 150U, 0U, 150U); 724 TestPriorityCookieCase(cm.get(), "1HN 180HS", 0U, 0U, 150U, 0U, 150U);
725 // Round 1 => 1LN; round 2 => 30LS; round 3 => none.
726 // Round 4 => none; round 5 => none; round 6 => none.
705 TestPriorityCookieCase(cm.get(), "180LS 1LN", 150U, 0U, 0U, 0U, 150U); 727 TestPriorityCookieCase(cm.get(), "180LS 1LN", 150U, 0U, 0U, 0U, 150U);
728 // Round 1 => none; round 2 => none; round 3 => 1MN.
729 // Round 4 => none; round 5 => 30MS; round 6 => none.
706 TestPriorityCookieCase(cm.get(), "180MS 1MN", 0U, 150U, 0U, 0U, 150U); 730 TestPriorityCookieCase(cm.get(), "180MS 1MN", 0U, 150U, 0U, 0U, 150U);
731 // Round 1 => none; round 2 => none; round 3 => none.
732 // Round 4 => 1HN; round 5 => none; round 6 => 30HS.
707 TestPriorityCookieCase(cm.get(), "180HS 1HN", 0U, 0U, 150U, 0U, 150U); 733 TestPriorityCookieCase(cm.get(), "180HS 1HN", 0U, 0U, 150U, 0U, 150U);
708 734
709 // Low-priority secure cookies are removed before higher priority non-secure 735 // Low-priority secure cookies are removed before higher priority non-secure
710 // cookies. 736 // cookies.
737 // Round 1 => none; round 2 => 31LS; round 3 => none.
738 // Round 4 => none; round 5 => none; round 6 => none.
711 TestPriorityCookieCase(cm.get(), "180LS 1MN", 149U, 1U, 0U, 1U, 149U); 739 TestPriorityCookieCase(cm.get(), "180LS 1MN", 149U, 1U, 0U, 1U, 149U);
740 // Round 1 => none; round 2 => 31LS; round 3 => none.
741 // Round 4 => none; round 5 => none; round 6 => none.
712 TestPriorityCookieCase(cm.get(), "180LS 1HN", 149U, 0U, 1U, 1U, 149U); 742 TestPriorityCookieCase(cm.get(), "180LS 1HN", 149U, 0U, 1U, 1U, 149U);
743 // Round 1 => none; round 2 => 31LS; round 3 => none.
744 // Round 4 => none; round 5 => none; round 6 => none.
713 TestPriorityCookieCase(cm.get(), "1MN 180LS", 149U, 1U, 0U, 1U, 149U); 745 TestPriorityCookieCase(cm.get(), "1MN 180LS", 149U, 1U, 0U, 1U, 149U);
746 // Round 1 => none; round 2 => 31LS; round 3 => none.
747 // Round 4 => none; round 5 => none; round 6 => none.
714 TestPriorityCookieCase(cm.get(), "1HN 180LS", 149U, 0U, 1U, 1U, 149U); 748 TestPriorityCookieCase(cm.get(), "1HN 180LS", 149U, 0U, 1U, 1U, 149U);
715 749
716 // Higher-priority non-secure cookies are removed before any secure cookie 750 // Higher-priority non-secure cookies are removed before any secure cookie
717 // with greater than low-priority. 751 // with greater than low-priority. Is it true? How about the quota?
718 TestPriorityCookieCase(cm.get(), "180MS 1HN", 0U, 150U, 0U, 0U, 150U); 752 // Round 1 => none; round 2 => none; round 3 => none.
719 TestPriorityCookieCase(cm.get(), "1HN 180MS", 0U, 150U, 0U, 0U, 150U); 753 // Round 4 => none; round 5 => 31MS; round 6 => none.
754 TestPriorityCookieCase(cm.get(), "180MS 1HN", 0U, 149U, 1U, 1U, 149U);
755 // Round 1 => none; round 2 => none; round 3 => none.
756 // Round 4 => none; round 5 => 31MS; round 6 => none.
757 TestPriorityCookieCase(cm.get(), "1HN 180MS", 0U, 149U, 1U, 1U, 149U);
720 758
721 // Pairwise: 759 // Pairwise:
760 // Round 1 => 31LN; round 2 => none; round 3 => none.
761 // Round 4 => none; round 5 => none; round 6 => none.
722 TestPriorityCookieCase(cm.get(), "1LS 180LN", 150U, 0U, 0U, 149U, 1U); 762 TestPriorityCookieCase(cm.get(), "1LS 180LN", 150U, 0U, 0U, 149U, 1U);
763 // Round 1 => 31LN; round 2 => none; round 3 => none.
764 // Round 4 => none; round 5 => none; round 6 => none.
723 TestPriorityCookieCase(cm.get(), "100LS 81LN", 150U, 0U, 0U, 50U, 100U); 765 TestPriorityCookieCase(cm.get(), "100LS 81LN", 150U, 0U, 0U, 50U, 100U);
766 // Round 1 => 31LN; round 2 => none; round 3 => none.
767 // Round 4 => none; round 5 => none; round 6 => none.
724 TestPriorityCookieCase(cm.get(), "150LS 31LN", 150U, 0U, 0U, 0U, 150U); 768 TestPriorityCookieCase(cm.get(), "150LS 31LN", 150U, 0U, 0U, 0U, 150U);
725 TestPriorityCookieCase(cm.get(), "1LS 180HN", 0U, 0U, 150U, 150U, 0U); 769 // Round 1 => none; round 2 => none; round 3 => none.
770 // Round 4 => 31HN; round 5 => none; round 6 => none.
771 TestPriorityCookieCase(cm.get(), "1LS 180HN", 1U, 0U, 149U, 149U, 1U);
772 // Round 1 => none; round 2 => 31LS; round 3 => none.
773 // Round 4 => none; round 5 => none; round 6 => none.
726 TestPriorityCookieCase(cm.get(), "100LS 81HN", 69U, 0U, 81U, 81U, 69U); 774 TestPriorityCookieCase(cm.get(), "100LS 81HN", 69U, 0U, 81U, 81U, 69U);
775 // Round 1 => none; round 2 => 31LS; round 3 => none.
776 // Round 4 => none; round 5 => none; round 6 => none.
727 TestPriorityCookieCase(cm.get(), "150LS 31HN", 119U, 0U, 31U, 31U, 119U); 777 TestPriorityCookieCase(cm.get(), "150LS 31HN", 119U, 0U, 31U, 31U, 119U);
728 778
729 // Quota calculations inside non-secure/secure blocks remain in place: 779 // Quota calculations inside non-secure/secure blocks remain in place:
730 // Round 1 => 20LS; round 2 => none; round 3 => 11HN. 780 // Round 1 => none; round 2 => 20LS; round 3 => none.
781 // Round 4 => 11HN; round 5 => none; round 6 => none.
731 TestPriorityCookieCase(cm.get(), "50HN 50LS 81HS", 30U, 0U, 120U, 39U, 782 TestPriorityCookieCase(cm.get(), "50HN 50LS 81HS", 30U, 0U, 120U, 39U,
732 111U); 783 111U);
733 // Round 1 => none; round 2 => 10LS, 21MN; round 3 => none. 784 // Round 1 => none; round 2 => none; round 3 => 31MN.
734 TestPriorityCookieCase(cm.get(), "11MS 10HN 10LS 90MN 60HN", 0U, 80U, 70U, 785 // Round 4 => none; round 5 => none; round 6 => none.
735 139U, 11U); 786 TestPriorityCookieCase(cm.get(), "11MS 10HN 10LS 90MN 60HN", 10U, 70U, 70U,
787 129U, 21U);
788 // Round 1 => 31LN; round 2 => none; round 3 => none.
789 // Round 4 => none; round 5 => none; round 6 => none.
790 TestPriorityCookieCase(cm.get(), "40LS 40LN 101HS", 49U, 0U, 101U, 9U,
791 141U);
736 792
737 // Multiple GC rounds end up with consistent behavior: 793 // Multiple GC rounds end up with consistent behavior:
738 TestPriorityCookieCase(cm.get(), "100HS 100LN 100MN", 0, 76U, 100U, 76U, 794 // GC is started as soon as there are 181 cookies in the store.
739 100U); 795 // On each major round it tries to preserve the quota for each priority.
796 // It is not aware about more cookies going in.
797 // 1 GC notices there are 181 cookies - 100HS 81LN 0MN
798 // Round 1 => 31LN; round 2 => none; round 3 => none.
799 // Round 4 => none; round 5 => none; round 6 => none.
800 // 2 GC notices there are 181 cookies - 100HS 69LN 12MN
801 // Round 1 => 31LN; round 2 => none; round 3 => none.
802 // Round 4 => none; round 5 => none; round 6 => none.
803 // 3 GC notices there are 181 cookies - 100HS 38LN 43MN
804 // Round 1 => 8LN; round 2 => none; round 3 => none.
805 // Round 4 => none; round 5 => none; round 6 => 23HS.
806 // 4 GC notcies there are 181 cookies - 77HS 30LN 74MN
807 // Round 1 => none; round 2 => none; round 3 => 24MN.
808 // Round 4 => none; round 5 => none; round 6 => 7HS.
809 TestPriorityCookieCase(cm.get(), "100HS 100LN 100MN", 30U, 76U, 70U, 106U,
810 70U);
740 } 811 }
741 812
742 // Function for creating a CM with a number of cookies in it, 813 // Function for creating a CM with a number of cookies in it,
743 // no store (and hence no ability to affect access time). 814 // no store (and hence no ability to affect access time).
744 CookieMonster* CreateMonsterForGC(int num_cookies) { 815 CookieMonster* CreateMonsterForGC(int num_cookies) {
745 CookieMonster* cm(new CookieMonster(NULL, NULL)); 816 CookieMonster* cm(new CookieMonster(NULL, NULL));
746 for (int i = 0; i < num_cookies; i++) { 817 for (int i = 0; i < num_cookies; i++) {
747 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); 818 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1");
748 } 819 }
749 return cm; 820 return cm;
(...skipping 2698 matching lines...) Expand 10 before | Expand all | Expand 10 after
3448 monster()->AddCallbackForCookie( 3519 monster()->AddCallbackForCookie(
3449 test_url_, "abc", 3520 test_url_, "abc",
3450 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3521 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3451 SetCookie(monster(), test_url_, "abc=def"); 3522 SetCookie(monster(), test_url_, "abc=def");
3452 base::MessageLoop::current()->RunUntilIdle(); 3523 base::MessageLoop::current()->RunUntilIdle();
3453 EXPECT_EQ(1U, cookies0.size()); 3524 EXPECT_EQ(1U, cookies0.size());
3454 EXPECT_EQ(1U, cookies0.size()); 3525 EXPECT_EQ(1U, cookies0.size());
3455 } 3526 }
3456 3527
3457 } // namespace net 3528 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698