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/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 Loading... | |
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(), | |
mmenke
2017/06/09 18:25:49
Some of these should use IP addresses, both v4 and
mmenke
2017/06/09 18:25:49
Also, if we choose to anything about the base last
Randy Smith (Not in Mondays)
2017/06/09 19:38:33
Current belief is that we're not going to do anyth
Randy Smith (Not in Mondays)
2017/06/09 19:38:33
Done, though give them a scan--I have no confidenc
| |
601 base::Time(), base::Time(), false, false, | |
602 CookieSameSite::NO_RESTRICTION, | |
603 COOKIE_PRIORITY_LOW) | |
604 .IsCanonical()); | |
605 EXPECT_TRUE(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(), | |
mmenke
2017/06/09 18:25:49
I think these each need comments - fixuring out wh
Randy Smith (Not in Mondays)
2017/06/09 19:38:33
Completely fair--even writing them was that. I de
| |
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", "", base::Time(), base::Time(), | |
641 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_FALSE(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 EXPECT_TRUE(CanonicalCookie("A", "B", "x.y", "/path", base::Time(), | |
656 base::Time(), base::Time(), false, false, | |
657 CookieSameSite::NO_RESTRICTION, | |
658 COOKIE_PRIORITY_LOW) | |
659 .IsCanonical()); | |
660 } | |
661 | |
599 TEST(CanonicalCookieTest, TestPrefixHistograms) { | 662 TEST(CanonicalCookieTest, TestPrefixHistograms) { |
600 base::HistogramTester histograms; | 663 base::HistogramTester histograms; |
601 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; | 664 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; |
602 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; | 665 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; |
603 GURL https_url("https://www.example.test"); | 666 GURL https_url("https://www.example.test"); |
604 base::Time creation_time = base::Time::Now(); | 667 base::Time creation_time = base::Time::Now(); |
605 CookieOptions options; | 668 CookieOptions options; |
606 | 669 |
607 EXPECT_FALSE(CanonicalCookie::Create(https_url, "__Host-A=B;", creation_time, | 670 EXPECT_FALSE(CanonicalCookie::Create(https_url, "__Host-A=B;", creation_time, |
608 options)); | 671 options)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 703 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
641 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", | 704 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", |
642 creation_time, options)); | 705 creation_time, options)); |
643 histograms.ExpectBucketCount(kCookiePrefixHistogram, | 706 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
644 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); | 707 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
645 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, | 708 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
646 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 709 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
647 } | 710 } |
648 | 711 |
649 } // namespace net | 712 } // namespace net |
OLD | NEW |