OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cookies/cookie_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 Loading... |
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 | |
603 // https://tools.ietf.org/html/draft-west-cookie-priority#section-3, it | |
604 // seems that quotas are a mechanism for preventing another application on | |
605 // the same doman from DoS'ing an application by constantly evicting *all* | |
606 // lower priority cookies. | |
607 // | |
608 // Unfortunately, this has never strictly worked in our implementation. Take | |
609 // the following test as an example: | |
610 // TestPriorityCookieCase(cm.get(), "50LN 131HN", 30U, 0U, 120U, 150U, 0U); | |
611 // | |
612 // According to this theory, we would expect eviction to proceed as: | |
613 // Round 1 => 20L; round 2 => 0; round 3 => 11H | 602 // Round 1 => 20L; round 2 => 0; round 3 => 11H |
614 // thus resulting in 30L and 120H at the end. | 603 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 | 604 // Round 1 => 20L; round 2 => 0; round 3 => 11H |
629 TestPriorityCookieCase(cm.get(), "131HN 50LN", 30U, 0U, 120U, 150U, 0U); | 605 TestPriorityCookieCase(cm.get(), "131HN 50LN", 30U, 0U, 120U, 150U, 0U); |
630 // Round 1 => 20L; round 2 => none; round 3 => 11H. | 606 // Round 1 => 20L; round 2 => none; round 3 => 11H. |
631 TestPriorityCookieCase(cm.get(), "50HN 50LN 81HN", 30U, 0U, 120U, 150U, 0U); | 607 TestPriorityCookieCase(cm.get(), "50HN 50LN 81HN", 30U, 0U, 120U, 150U, 0U); |
632 // Round 1 => 20L; round 2 => none; round 3 => 11H. | 608 // Round 1 => 20L; round 2 => none; round 3 => 11H. |
633 TestPriorityCookieCase(cm.get(), "81HN 50LN 50HN", 30U, 0U, 120U, 150U, 0U); | 609 TestPriorityCookieCase(cm.get(), "81HN 50LN 50HN", 30U, 0U, 120U, 150U, 0U); |
634 } | 610 } |
635 | 611 |
636 void TestPriorityAwareGarbageCollectHelperSecure() { | 612 void TestPriorityAwareGarbageCollectHelperSecure() { |
637 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 613 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
638 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 614 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
639 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 615 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
640 CookieMonster::kDomainPurgeCookies); | 616 CookieMonster::kDomainPurgeCookies); |
641 | 617 |
642 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 618 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
643 | 619 |
644 // Each test case adds 181 cookies, so 31 cookies are evicted. | 620 // Each test case adds 181 cookies, so 31 cookies are evicted. |
645 // Cookie same priority, repeated for each priority. | 621 // Cookie same priority, repeated for each priority. |
| 622 // Round 1 => 31L; round2 => none; round 3 => none. |
646 TestPriorityCookieCase(cm.get(), "181LS", 150U, 0U, 0U, 0U, 150U); | 623 TestPriorityCookieCase(cm.get(), "181LS", 150U, 0U, 0U, 0U, 150U); |
| 624 // Round 1 => none; round2 => 31M; round 3 => none. |
647 TestPriorityCookieCase(cm.get(), "181MS", 0U, 150U, 0U, 0U, 150U); | 625 TestPriorityCookieCase(cm.get(), "181MS", 0U, 150U, 0U, 0U, 150U); |
| 626 // Round 1 => none; round2 => none; round 3 => 31H. |
648 TestPriorityCookieCase(cm.get(), "181HS", 0U, 0U, 150U, 0U, 150U); | 627 TestPriorityCookieCase(cm.get(), "181HS", 0U, 0U, 150U, 0U, 150U); |
649 | 628 |
650 // Pairwise scenarios. | 629 // Pairwise scenarios. |
651 // Round 1 => none; round2 => 31M; round 3 => none. | 630 // Round 1 => none; round2 => 31M; round 3 => none. |
652 TestPriorityCookieCase(cm.get(), "10HS 171MS", 0U, 140U, 10U, 0U, 150U); | 631 TestPriorityCookieCase(cm.get(), "10HS 171MS", 0U, 140U, 10U, 0U, 150U); |
653 // Round 1 => 10L; round2 => 21M; round 3 => none. | 632 // Round 1 => 10L; round2 => 21M; round 3 => none. |
654 TestPriorityCookieCase(cm.get(), "141MS 40LS", 30U, 120U, 0U, 0U, 150U); | 633 TestPriorityCookieCase(cm.get(), "141MS 40LS", 30U, 120U, 0U, 0U, 150U); |
655 // Round 1 => none; round2 => none; round 3 => 31H. | 634 // Round 1 => none; round2 => 30M; round 3 => 1H. |
656 TestPriorityCookieCase(cm.get(), "101HS 80MS", 0U, 80U, 70U, 0U, 150U); | 635 TestPriorityCookieCase(cm.get(), "101HS 80MS", 0U, 50U, 100U, 0U, 150U); |
657 | 636 |
658 // For {low, medium} priorities right on quota, different orders. | 637 // For {low, medium} priorities right on quota, different orders. |
659 // Round 1 => 1L; round 2 => none, round3 => 30L. | 638 // Round 1 => 1L; round 2 => none, round3 => 30H. |
660 TestPriorityCookieCase(cm.get(), "31LS 50MS 100HS", 0U, 50U, 100U, 0U, | 639 TestPriorityCookieCase(cm.get(), "31LS 50MS 100HS", 30U, 50U, 70U, 0U, |
661 150U); | 640 150U); |
662 // Round 1 => none; round 2 => 1M, round3 => 30M. | 641 // Round 1 => none; round 2 => 1M, round3 => 30H. |
663 TestPriorityCookieCase(cm.get(), "51MS 100HS 30LS", 30U, 20U, 100U, 0U, | 642 TestPriorityCookieCase(cm.get(), "51MS 100HS 30LS", 30U, 50U, 70U, 0U, |
664 150U); | 643 150U); |
665 // Round 1 => none; round 2 => none; round3 => 31H. | 644 // Round 1 => none; round 2 => none; round3 => 31H. |
666 TestPriorityCookieCase(cm.get(), "101HS 50MS 30LS", 30U, 50U, 70U, 0U, | 645 TestPriorityCookieCase(cm.get(), "101HS 50MS 30LS", 30U, 50U, 70U, 0U, |
667 150U); | 646 150U); |
668 | 647 |
669 // Round 1 => 10L; round 2 => 10M; round3 => 11H. | 648 // Round 1 => 10L; round 2 => 10M; round3 => 11H. |
670 TestPriorityCookieCase(cm.get(), "81HS 60MS 40LS", 30U, 50U, 70U, 0U, 150U); | 649 TestPriorityCookieCase(cm.get(), "81HS 60MS 40LS", 30U, 50U, 70U, 0U, 150U); |
671 | 650 |
672 // More complex scenarios. | 651 // More complex scenarios. |
673 // Round 1 => 10L; round 2 => 10M; round 3 => 11H. | 652 // Round 1 => 10L; round 2 => 10M; round 3 => 11H. |
674 TestPriorityCookieCase(cm.get(), "21HS 60MS 40LS 60HS", 30U, 50U, 70U, 0U, | 653 TestPriorityCookieCase(cm.get(), "21HS 60MS 40LS 60HS", 30U, 50U, 70U, 0U, |
675 150U); | 654 150U); |
676 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none. | 655 // Round 1 => 10L; round 2 => 21M; round 3 => none. |
677 TestPriorityCookieCase(cm.get(), "11HS 10MS 20LS 110MS 20LS 10HS", 20U, | 656 TestPriorityCookieCase(cm.get(), "11HS 10MS 20LS 110MS 20LS 10HS", 30U, 99U, |
678 109U, 21U, 0U, 150U); | 657 21U, 0U, 150U); |
679 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H. | 658 // Round 1 => none; round 2 => none; round 3 => 31H. |
680 TestPriorityCookieCase(cm.get(), "11LS 10MS 140HS 10MS 10LS", 10U, 10U, | 659 TestPriorityCookieCase(cm.get(), "11LS 10MS 140HS 10MS 10LS", 21U, 20U, |
681 130U, 0U, 150U); | 660 109U, 0U, 150U); |
682 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H. | 661 // Round 1 => none; round 2 => 21M; round 3 => 10H. |
683 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 60MS 90HS", 0U, 60U, 90U, | 662 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 60MS 90HS", 10U, 50U, 90U, |
684 0U, 150U); | 663 0U, 150U); |
685 // Round 1 => none; round 2 => 10L, 21M; round 3 => none. | 664 // Round 1 => none; round 2 => 31M; round 3 => none. |
686 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 90MS 60HS", 0U, 80U, 70U, | 665 TestPriorityCookieCase(cm.get(), "11MS 10HS 10LS 90MS 60HS", 10U, 70U, 70U, |
687 0U, 150U); | 666 0U, 150U); |
688 } | 667 } |
689 | 668 |
690 void TestPriorityAwareGarbageCollectHelperMixed() { | 669 void TestPriorityAwareGarbageCollectHelperMixed() { |
691 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 670 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
692 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 671 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
693 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 672 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
694 CookieMonster::kDomainPurgeCookies); | 673 CookieMonster::kDomainPurgeCookies); |
695 | 674 |
696 std::unique_ptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 675 std::unique_ptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
697 | 676 |
698 // Each test case adds 180 secure cookies, and some non-secure cookie. The | 677 // 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 | 678 // secure cookies take priority, so the non-secure cookie is removed, along |
700 // with 30 secure cookies. Repeated for each priority, and with the | 679 // with 30 secure cookies. Repeated for each priority, and with the |
701 // non-secure cookie as older and newer. | 680 // non-secure cookie as older and newer. |
| 681 // Round 1 => 1LN; round 2 => 30LS; round 3 => none. |
| 682 // Round 4 => none; round 5 => none; round 6 => none. |
702 TestPriorityCookieCase(cm.get(), "1LN 180LS", 150U, 0U, 0U, 0U, 150U); | 683 TestPriorityCookieCase(cm.get(), "1LN 180LS", 150U, 0U, 0U, 0U, 150U); |
| 684 // Round 1 => none; round 2 => none; round 3 => 1MN. |
| 685 // Round 4 => none; round 5 => 30MS; round 6 => none. |
703 TestPriorityCookieCase(cm.get(), "1MN 180MS", 0U, 150U, 0U, 0U, 150U); | 686 TestPriorityCookieCase(cm.get(), "1MN 180MS", 0U, 150U, 0U, 0U, 150U); |
| 687 // Round 1 => none; round 2 => none; round 3 => none. |
| 688 // Round 4 => 1HN; round 5 => none; round 6 => 30HS. |
704 TestPriorityCookieCase(cm.get(), "1HN 180HS", 0U, 0U, 150U, 0U, 150U); | 689 TestPriorityCookieCase(cm.get(), "1HN 180HS", 0U, 0U, 150U, 0U, 150U); |
| 690 // Round 1 => 1LN; round 2 => 30LS; round 3 => none. |
| 691 // Round 4 => none; round 5 => none; round 6 => none. |
705 TestPriorityCookieCase(cm.get(), "180LS 1LN", 150U, 0U, 0U, 0U, 150U); | 692 TestPriorityCookieCase(cm.get(), "180LS 1LN", 150U, 0U, 0U, 0U, 150U); |
| 693 // Round 1 => none; round 2 => none; round 3 => 1MN. |
| 694 // Round 4 => none; round 5 => 30MS; round 6 => none. |
706 TestPriorityCookieCase(cm.get(), "180MS 1MN", 0U, 150U, 0U, 0U, 150U); | 695 TestPriorityCookieCase(cm.get(), "180MS 1MN", 0U, 150U, 0U, 0U, 150U); |
| 696 // Round 1 => none; round 2 => none; round 3 => none. |
| 697 // Round 4 => 1HN; round 5 => none; round 6 => 30HS. |
707 TestPriorityCookieCase(cm.get(), "180HS 1HN", 0U, 0U, 150U, 0U, 150U); | 698 TestPriorityCookieCase(cm.get(), "180HS 1HN", 0U, 0U, 150U, 0U, 150U); |
708 | 699 |
709 // Low-priority secure cookies are removed before higher priority non-secure | 700 // Low-priority secure cookies are removed before higher priority non-secure |
710 // cookies. | 701 // cookies. |
| 702 // Round 1 => none; round 2 => 31LS; round 3 => none. |
| 703 // Round 4 => none; round 5 => none; round 6 => none. |
711 TestPriorityCookieCase(cm.get(), "180LS 1MN", 149U, 1U, 0U, 1U, 149U); | 704 TestPriorityCookieCase(cm.get(), "180LS 1MN", 149U, 1U, 0U, 1U, 149U); |
| 705 // Round 1 => none; round 2 => 31LS; round 3 => none. |
| 706 // Round 4 => none; round 5 => none; round 6 => none. |
712 TestPriorityCookieCase(cm.get(), "180LS 1HN", 149U, 0U, 1U, 1U, 149U); | 707 TestPriorityCookieCase(cm.get(), "180LS 1HN", 149U, 0U, 1U, 1U, 149U); |
| 708 // Round 1 => none; round 2 => 31LS; round 3 => none. |
| 709 // Round 4 => none; round 5 => none; round 6 => none. |
713 TestPriorityCookieCase(cm.get(), "1MN 180LS", 149U, 1U, 0U, 1U, 149U); | 710 TestPriorityCookieCase(cm.get(), "1MN 180LS", 149U, 1U, 0U, 1U, 149U); |
| 711 // Round 1 => none; round 2 => 31LS; round 3 => none. |
| 712 // Round 4 => none; round 5 => none; round 6 => none. |
714 TestPriorityCookieCase(cm.get(), "1HN 180LS", 149U, 0U, 1U, 1U, 149U); | 713 TestPriorityCookieCase(cm.get(), "1HN 180LS", 149U, 0U, 1U, 1U, 149U); |
715 | 714 |
716 // Higher-priority non-secure cookies are removed before any secure cookie | 715 // Higher-priority non-secure cookies are removed before any secure cookie |
717 // with greater than low-priority. | 716 // with greater than low-priority. Is it true? How about the quota? |
718 TestPriorityCookieCase(cm.get(), "180MS 1HN", 0U, 150U, 0U, 0U, 150U); | 717 // Round 1 => none; round 2 => none; round 3 => none. |
719 TestPriorityCookieCase(cm.get(), "1HN 180MS", 0U, 150U, 0U, 0U, 150U); | 718 // Round 4 => none; round 5 => 31MS; round 6 => none. |
| 719 TestPriorityCookieCase(cm.get(), "180MS 1HN", 0U, 149U, 1U, 1U, 149U); |
| 720 // Round 1 => none; round 2 => none; round 3 => none. |
| 721 // Round 4 => none; round 5 => 31MS; round 6 => none. |
| 722 TestPriorityCookieCase(cm.get(), "1HN 180MS", 0U, 149U, 1U, 1U, 149U); |
720 | 723 |
721 // Pairwise: | 724 // Pairwise: |
| 725 // Round 1 => 31LN; round 2 => none; round 3 => none. |
| 726 // Round 4 => none; round 5 => none; round 6 => none. |
722 TestPriorityCookieCase(cm.get(), "1LS 180LN", 150U, 0U, 0U, 149U, 1U); | 727 TestPriorityCookieCase(cm.get(), "1LS 180LN", 150U, 0U, 0U, 149U, 1U); |
| 728 // Round 1 => 31LN; round 2 => none; round 3 => none. |
| 729 // Round 4 => none; round 5 => none; round 6 => none. |
723 TestPriorityCookieCase(cm.get(), "100LS 81LN", 150U, 0U, 0U, 50U, 100U); | 730 TestPriorityCookieCase(cm.get(), "100LS 81LN", 150U, 0U, 0U, 50U, 100U); |
| 731 // Round 1 => 31LN; round 2 => none; round 3 => none. |
| 732 // Round 4 => none; round 5 => none; round 6 => none. |
724 TestPriorityCookieCase(cm.get(), "150LS 31LN", 150U, 0U, 0U, 0U, 150U); | 733 TestPriorityCookieCase(cm.get(), "150LS 31LN", 150U, 0U, 0U, 0U, 150U); |
725 TestPriorityCookieCase(cm.get(), "1LS 180HN", 0U, 0U, 150U, 150U, 0U); | 734 // Round 1 => none; round 2 => none; round 3 => none. |
| 735 // Round 4 => 31HN; round 5 => none; round 6 => none. |
| 736 TestPriorityCookieCase(cm.get(), "1LS 180HN", 1U, 0U, 149U, 149U, 1U); |
| 737 // Round 1 => none; round 2 => 31LS; round 3 => none. |
| 738 // Round 4 => none; round 5 => none; round 6 => none. |
726 TestPriorityCookieCase(cm.get(), "100LS 81HN", 69U, 0U, 81U, 81U, 69U); | 739 TestPriorityCookieCase(cm.get(), "100LS 81HN", 69U, 0U, 81U, 81U, 69U); |
| 740 // Round 1 => none; round 2 => 31LS; round 3 => none. |
| 741 // Round 4 => none; round 5 => none; round 6 => none. |
727 TestPriorityCookieCase(cm.get(), "150LS 31HN", 119U, 0U, 31U, 31U, 119U); | 742 TestPriorityCookieCase(cm.get(), "150LS 31HN", 119U, 0U, 31U, 31U, 119U); |
728 | 743 |
729 // Quota calculations inside non-secure/secure blocks remain in place: | 744 // Quota calculations inside non-secure/secure blocks remain in place: |
730 // Round 1 => 20LS; round 2 => none; round 3 => 11HN. | 745 // Round 1 => none; round 2 => 20LS; round 3 => none. |
| 746 // Round 4 => 11HN; round 5 => none; round 6 => none. |
731 TestPriorityCookieCase(cm.get(), "50HN 50LS 81HS", 30U, 0U, 120U, 39U, | 747 TestPriorityCookieCase(cm.get(), "50HN 50LS 81HS", 30U, 0U, 120U, 39U, |
732 111U); | 748 111U); |
733 // Round 1 => none; round 2 => 10LS, 21MN; round 3 => none. | 749 // Round 1 => none; round 2 => none; round 3 => 31MN. |
734 TestPriorityCookieCase(cm.get(), "11MS 10HN 10LS 90MN 60HN", 0U, 80U, 70U, | 750 // Round 4 => none; round 5 => none; round 6 => none. |
735 139U, 11U); | 751 TestPriorityCookieCase(cm.get(), "11MS 10HN 10LS 90MN 60HN", 10U, 70U, 70U, |
| 752 129U, 21U); |
| 753 // Round 1 => 31LN; round 2 => none; round 3 => none. |
| 754 // Round 4 => none; round 5 => none; round 6 => none. |
| 755 TestPriorityCookieCase(cm.get(), "40LS 40LN 101HS", 49U, 0U, 101U, 9U, |
| 756 141U); |
736 | 757 |
737 // Multiple GC rounds end up with consistent behavior: | 758 // Multiple GC rounds end up with consistent behavior: |
738 TestPriorityCookieCase(cm.get(), "100HS 100LN 100MN", 0, 76U, 100U, 76U, | 759 // GC is started as soon as there are 181 cookies in the store. |
739 100U); | 760 // On each major round it tries to preserve the quota for each priority. |
| 761 // It is not aware about more cookies going in. |
| 762 // 1 GC notices there are 181 cookies - 100HS 81LN 0MN |
| 763 // Round 1 => 31LN; round 2 => none; round 3 => none. |
| 764 // Round 4 => none; round 5 => none; round 6 => none. |
| 765 // 2 GC notices there are 181 cookies - 100HS 69LN 12MN |
| 766 // Round 1 => 31LN; round 2 => none; round 3 => none. |
| 767 // Round 4 => none; round 5 => none; round 6 => none. |
| 768 // 3 GC notices there are 181 cookies - 100HS 38LN 43MN |
| 769 // Round 1 => 8LN; round 2 => none; round 3 => none. |
| 770 // Round 4 => none; round 5 => none; round 6 => 23HS. |
| 771 // 4 GC notcies there are 181 cookies - 77HS 30LN 74MN |
| 772 // Round 1 => none; round 2 => none; round 3 => 24MN. |
| 773 // Round 4 => none; round 5 => none; round 6 => 7HS. |
| 774 TestPriorityCookieCase(cm.get(), "100HS 100LN 100MN", 30U, 76U, 70U, 106U, |
| 775 70U); |
740 } | 776 } |
741 | 777 |
742 // Function for creating a CM with a number of cookies in it, | 778 // Function for creating a CM with a number of cookies in it, |
743 // no store (and hence no ability to affect access time). | 779 // no store (and hence no ability to affect access time). |
744 CookieMonster* CreateMonsterForGC(int num_cookies) { | 780 CookieMonster* CreateMonsterForGC(int num_cookies) { |
745 CookieMonster* cm(new CookieMonster(NULL, NULL)); | 781 CookieMonster* cm(new CookieMonster(NULL, NULL)); |
746 for (int i = 0; i < num_cookies; i++) { | 782 for (int i = 0; i < num_cookies; i++) { |
747 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); | 783 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); |
748 } | 784 } |
749 return cm; | 785 return cm; |
(...skipping 2698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3448 monster()->AddCallbackForCookie( | 3484 monster()->AddCallbackForCookie( |
3449 test_url_, "abc", | 3485 test_url_, "abc", |
3450 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3486 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3451 SetCookie(monster(), test_url_, "abc=def"); | 3487 SetCookie(monster(), test_url_, "abc=def"); |
3452 base::MessageLoop::current()->RunUntilIdle(); | 3488 base::MessageLoop::current()->RunUntilIdle(); |
3453 EXPECT_EQ(1U, cookies0.size()); | 3489 EXPECT_EQ(1U, cookies0.size()); |
3454 EXPECT_EQ(1U, cookies0.size()); | 3490 EXPECT_EQ(1U, cookies0.size()); |
3455 } | 3491 } |
3456 | 3492 |
3457 } // namespace net | 3493 } // namespace net |
OLD | NEW |