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(), |
| 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 |
599 TEST(CanonicalCookieTest, TestPrefixHistograms) { | 657 TEST(CanonicalCookieTest, TestPrefixHistograms) { |
600 base::HistogramTester histograms; | 658 base::HistogramTester histograms; |
601 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; | 659 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; |
602 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; | 660 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; |
603 GURL https_url("https://www.example.test"); | 661 GURL https_url("https://www.example.test"); |
604 base::Time creation_time = base::Time::Now(); | 662 base::Time creation_time = base::Time::Now(); |
605 CookieOptions options; | 663 CookieOptions options; |
606 | 664 |
607 EXPECT_FALSE(CanonicalCookie::Create(https_url, "__Host-A=B;", creation_time, | 665 EXPECT_FALSE(CanonicalCookie::Create(https_url, "__Host-A=B;", creation_time, |
608 options)); | 666 options)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 698 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
641 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", | 699 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", |
642 creation_time, options)); | 700 creation_time, options)); |
643 histograms.ExpectBucketCount(kCookiePrefixHistogram, | 701 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
644 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); | 702 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
645 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, | 703 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
646 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 704 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
647 } | 705 } |
648 | 706 |
649 } // namespace net | 707 } // namespace net |
OLD | NEW |