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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/test/histogram_tester.h" |
8 #include "net/cookies/cookie_constants.h" | 9 #include "net/cookies/cookie_constants.h" |
9 #include "net/cookies/cookie_options.h" | 10 #include "net/cookies/cookie_options.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 TEST(CanonicalCookieTest, Constructor) { | 16 TEST(CanonicalCookieTest, Constructor) { |
16 GURL url("http://www.example.com/test"); | 17 GURL url("http://www.example.com/test"); |
17 base::Time current_time = base::Time::Now(); | 18 base::Time current_time = base::Time::Now(); |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 CanonicalCookie::Create(https_url, "a", "b", "", "", creation_time, | 674 CanonicalCookie::Create(https_url, "a", "b", "", "", creation_time, |
674 creation_time, true, false, false, true, | 675 creation_time, true, false, false, true, |
675 COOKIE_PRIORITY_DEFAULT)); | 676 COOKIE_PRIORITY_DEFAULT)); |
676 | 677 |
677 EXPECT_TRUE(http_cookie_no_secure_extended.get()); | 678 EXPECT_TRUE(http_cookie_no_secure_extended.get()); |
678 EXPECT_FALSE(http_cookie_secure_extended.get()); | 679 EXPECT_FALSE(http_cookie_secure_extended.get()); |
679 EXPECT_TRUE(https_cookie_no_secure_extended.get()); | 680 EXPECT_TRUE(https_cookie_no_secure_extended.get()); |
680 EXPECT_TRUE(https_cookie_secure_extended.get()); | 681 EXPECT_TRUE(https_cookie_secure_extended.get()); |
681 } | 682 } |
682 | 683 |
| 684 namespace { |
| 685 |
| 686 class CanonicalCookiePrefixHistogramTest : public testing::TestWithParam<bool> { |
| 687 }; |
| 688 |
| 689 } // namespace |
| 690 |
| 691 TEST_P(CanonicalCookiePrefixHistogramTest, TestHistograms) { |
| 692 base::HistogramTester histograms; |
| 693 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; |
| 694 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; |
| 695 GURL https_url("https://www.example.test"); |
| 696 base::Time creation_time = base::Time::Now(); |
| 697 CookieOptions options; |
| 698 if (GetParam()) |
| 699 options.set_enforce_prefixes(); |
| 700 |
| 701 scoped_ptr<CanonicalCookie> cookie1 = make_scoped_ptr( |
| 702 CanonicalCookie::Create(https_url, "$Host-A=B;", creation_time, options)); |
| 703 if (GetParam()) |
| 704 EXPECT_EQ(nullptr, cookie1); |
| 705 else |
| 706 EXPECT_NE(nullptr, cookie1); |
| 707 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 708 CanonicalCookie::COOKIE_PREFIX_HOST, 1); |
| 709 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 710 CanonicalCookie::COOKIE_PREFIX_HOST, 1); |
| 711 |
| 712 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
| 713 https_url, "$Host-A=B; Path=/; Secure", creation_time, |
| 714 options))); |
| 715 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 716 CanonicalCookie::COOKIE_PREFIX_HOST, 2); |
| 717 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 718 CanonicalCookie::COOKIE_PREFIX_HOST, 1); |
| 719 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
| 720 https_url, "$HostA=B; Path=/; Secure", creation_time, |
| 721 options))); |
| 722 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 723 CanonicalCookie::COOKIE_PREFIX_HOST, 2); |
| 724 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 725 CanonicalCookie::COOKIE_PREFIX_HOST, 1); |
| 726 |
| 727 scoped_ptr<CanonicalCookie> cookie2 = make_scoped_ptr(CanonicalCookie::Create( |
| 728 https_url, "$Secure-A=B;", creation_time, options)); |
| 729 if (GetParam()) |
| 730 EXPECT_EQ(nullptr, cookie2); |
| 731 else |
| 732 EXPECT_NE(nullptr, cookie2); |
| 733 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 734 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 735 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 736 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 737 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
| 738 https_url, "$Secure-A=B; Path=/; Secure", |
| 739 creation_time, options))); |
| 740 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 741 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
| 742 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 743 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 744 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
| 745 https_url, "$SecureA=B; Path=/; Secure", creation_time, |
| 746 options))); |
| 747 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 748 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
| 749 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 750 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 751 } |
| 752 |
| 753 INSTANTIATE_TEST_CASE_P(CanonicalCookiePrefixHistogramTests, |
| 754 CanonicalCookiePrefixHistogramTest, |
| 755 testing::Values(true, false)); |
| 756 |
683 } // namespace net | 757 } // namespace net |
OLD | NEW |