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

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

Issue 2882063002: Add a SetCanonicalCookie method for CookieMonster. (Closed)
Patch Set: Fix try jobs and do some cleanup. Created 3 years, 7 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
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/canonical_cookie.h" 5 #include "net/cookies/canonical_cookie.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); 589 CanonicalCookie::Create(https_url, "a=b", creation_time, options));
590 std::unique_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( 590 std::unique_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create(
591 https_url, "a=b; Secure", creation_time, options)); 591 https_url, "a=b; Secure", creation_time, options));
592 592
593 EXPECT_TRUE(http_cookie_no_secure.get()); 593 EXPECT_TRUE(http_cookie_no_secure.get());
594 EXPECT_FALSE(http_cookie_secure.get()); 594 EXPECT_FALSE(http_cookie_secure.get());
595 EXPECT_TRUE(https_cookie_no_secure.get()); 595 EXPECT_TRUE(https_cookie_no_secure.get());
596 EXPECT_TRUE(https_cookie_secure.get()); 596 EXPECT_TRUE(https_cookie_secure.get());
597 } 597 }
598 598
599 TEST(CanonicalCookieTest, IsCanonical) {
600 EXPECT_TRUE(CanonicalCookie("A", "B", "x.y", "/path", base::Time(),
601 base::Time(), base::Time(), false, false,
602 CookieSameSite::NO_RESTRICTION,
603 COOKIE_PRIORITY_LOW)
604 .IsCanonical());
605 EXPECT_FALSE(CanonicalCookie("", "B", "x.y", "/path", base::Time(),
606 base::Time(), base::Time(), false, false,
607 CookieSameSite::NO_RESTRICTION,
608 COOKIE_PRIORITY_LOW)
609 .IsCanonical());
610 EXPECT_FALSE(CanonicalCookie("A ", "B", "x.y", "/path", base::Time(),
611 base::Time(), base::Time(), false, false,
612 CookieSameSite::NO_RESTRICTION,
613 COOKIE_PRIORITY_LOW)
614 .IsCanonical());
615 EXPECT_FALSE(CanonicalCookie("A=", "B", "x.y", "/path", base::Time(),
616 base::Time(), base::Time(), false, false,
617 CookieSameSite::NO_RESTRICTION,
618 COOKIE_PRIORITY_LOW)
619 .IsCanonical());
620 EXPECT_FALSE(CanonicalCookie("A", "B;", "x.y", "/path", base::Time(),
621 base::Time(), base::Time(), false, false,
622 CookieSameSite::NO_RESTRICTION,
623 COOKIE_PRIORITY_LOW)
624 .IsCanonical());
625 EXPECT_FALSE(CanonicalCookie("A", "B", ";x.y", "/path", base::Time(),
626 base::Time(), base::Time(), false, false,
627 CookieSameSite::NO_RESTRICTION,
628 COOKIE_PRIORITY_LOW)
629 .IsCanonical());
630 EXPECT_FALSE(CanonicalCookie("A", "B", "x.y ", "/path", base::Time(),
631 base::Time(), base::Time(), false, false,
632 CookieSameSite::NO_RESTRICTION,
633 COOKIE_PRIORITY_LOW)
634 .IsCanonical());
635 EXPECT_FALSE(CanonicalCookie("A", "B", "x.y", "path", base::Time(),
636 base::Time(), base::Time(), false, false,
637 CookieSameSite::NO_RESTRICTION,
638 COOKIE_PRIORITY_LOW)
639 .IsCanonical());
640 EXPECT_FALSE(CanonicalCookie("A", "B", "x.y", "/path ", base::Time(),
641 base::Time(), base::Time(), false, false,
642 CookieSameSite::NO_RESTRICTION,
643 COOKIE_PRIORITY_LOW)
644 .IsCanonical());
645 EXPECT_FALSE(CanonicalCookie("A", "B", "x.y", "/path;", base::Time(),
646 base::Time(), base::Time(), false, false,
647 CookieSameSite::NO_RESTRICTION,
648 COOKIE_PRIORITY_LOW)
649 .IsCanonical());
650 EXPECT_TRUE(CanonicalCookie("A", "B", "x.y", "/path", base::Time(),
651 base::Time(), base::Time(), false, false,
652 CookieSameSite::NO_RESTRICTION,
653 COOKIE_PRIORITY_LOW)
654 .IsCanonical());
655 }
656
657 TEST(CanonicalCookieTest, TestSetCreationDate) {
658 CanonicalCookie cookie("A", "B", "x.y", "/path", base::Time(), base::Time(),
659 base::Time(), false, false,
660 CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_LOW);
661 EXPECT_TRUE(cookie.CreationDate().is_null());
662
663 base::Time now(base::Time::Now());
664 cookie.SetCreationDate(now);
665 EXPECT_EQ(now, cookie.CreationDate());
666 }
667
599 TEST(CanonicalCookieTest, TestPrefixHistograms) { 668 TEST(CanonicalCookieTest, TestPrefixHistograms) {
600 base::HistogramTester histograms; 669 base::HistogramTester histograms;
601 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; 670 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix";
602 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; 671 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked";
603 GURL https_url("https://www.example.test"); 672 GURL https_url("https://www.example.test");
604 base::Time creation_time = base::Time::Now(); 673 base::Time creation_time = base::Time::Now();
605 CookieOptions options; 674 CookieOptions options;
606 675
607 EXPECT_FALSE(CanonicalCookie::Create(https_url, "__Host-A=B;", creation_time, 676 EXPECT_FALSE(CanonicalCookie::Create(https_url, "__Host-A=B;", creation_time,
608 options)); 677 options));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 709 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
641 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", 710 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure",
642 creation_time, options)); 711 creation_time, options));
643 histograms.ExpectBucketCount(kCookiePrefixHistogram, 712 histograms.ExpectBucketCount(kCookiePrefixHistogram,
644 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); 713 CanonicalCookie::COOKIE_PREFIX_SECURE, 2);
645 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, 714 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
646 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 715 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
647 } 716 }
648 717
649 } // namespace net 718 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698