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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 // Rules don't apply for a typoed prefix. | 532 // Rules don't apply for a typoed prefix. |
532 EXPECT_NE(nullptr, | 533 EXPECT_NE(nullptr, |
533 make_scoped_ptr(CanonicalCookie::Create( | 534 make_scoped_ptr(CanonicalCookie::Create( |
534 http_url, "$host-A=B; Domain=" + domain + "; Path=/; Secure;", | 535 http_url, "$host-A=B; Domain=" + domain + "; Path=/; Secure;", |
535 creation_time, options))); | 536 creation_time, options))); |
536 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( | 537 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
537 https_url, "$HostA=B; Domain=" + domain + "; Secure;", | 538 https_url, "$HostA=B; Domain=" + domain + "; Secure;", |
538 creation_time, options))); | 539 creation_time, options))); |
539 } | 540 } |
540 | 541 |
| 542 namespace { |
| 543 |
| 544 class CanonicalCookiePrefixHistogramTest : public testing::TestWithParam<bool> { |
| 545 }; |
| 546 |
| 547 } // namespace |
| 548 |
| 549 TEST_P(CanonicalCookiePrefixHistogramTest, TestHistograms) { |
| 550 base::HistogramTester histograms; |
| 551 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; |
| 552 const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked"; |
| 553 GURL https_url("https://www.example.test"); |
| 554 base::Time creation_time = base::Time::Now(); |
| 555 CookieOptions options; |
| 556 if (GetParam()) |
| 557 options.set_enforce_prefixes(); |
| 558 |
| 559 scoped_ptr<CanonicalCookie> cookie1 = make_scoped_ptr( |
| 560 CanonicalCookie::Create(https_url, "$Host-A=B;", creation_time, options)); |
| 561 if (GetParam()) |
| 562 EXPECT_EQ(nullptr, cookie1); |
| 563 else |
| 564 EXPECT_NE(nullptr, cookie1); |
| 565 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 566 CanonicalCookie::COOKIE_PREFIX_HOST, 1); |
| 567 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 568 CanonicalCookie::COOKIE_PREFIX_HOST, 1); |
| 569 |
| 570 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
| 571 https_url, "$Host-A=B; Path=/; Secure", creation_time, |
| 572 options))); |
| 573 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 574 CanonicalCookie::COOKIE_PREFIX_HOST, 2); |
| 575 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 576 CanonicalCookie::COOKIE_PREFIX_HOST, 1); |
| 577 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
| 578 https_url, "$HostA=B; Path=/; Secure", creation_time, |
| 579 options))); |
| 580 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 581 CanonicalCookie::COOKIE_PREFIX_HOST, 2); |
| 582 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 583 CanonicalCookie::COOKIE_PREFIX_HOST, 1); |
| 584 |
| 585 scoped_ptr<CanonicalCookie> cookie2 = make_scoped_ptr(CanonicalCookie::Create( |
| 586 https_url, "$Secure-A=B;", creation_time, options)); |
| 587 if (GetParam()) |
| 588 EXPECT_EQ(nullptr, cookie2); |
| 589 else |
| 590 EXPECT_NE(nullptr, cookie2); |
| 591 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 592 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 593 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 594 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 595 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
| 596 https_url, "$Secure-A=B; Path=/; Secure", |
| 597 creation_time, options))); |
| 598 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 599 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
| 600 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 601 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 602 EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create( |
| 603 https_url, "$SecureA=B; Path=/; Secure", creation_time, |
| 604 options))); |
| 605 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
| 606 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
| 607 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
| 608 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
| 609 } |
| 610 |
| 611 INSTANTIATE_TEST_CASE_P(CanonicalCookiePrefixHistogramTests, |
| 612 CanonicalCookiePrefixHistogramTest, |
| 613 testing::Values(true, false)); |
| 614 |
541 } // namespace net | 615 } // namespace net |
OLD | NEW |