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

Unified Diff: net/cookies/canonical_cookie_unittest.cc

Issue 1455693007: Add cookie prefix metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/canonical_cookie_unittest.cc
diff --git a/net/cookies/canonical_cookie_unittest.cc b/net/cookies/canonical_cookie_unittest.cc
index 5f031220526e932e3d5a2c0907d17454059db44a..73c7c86fc4a7b4572ca44df08d6588e54ec40ad2 100644
--- a/net/cookies/canonical_cookie_unittest.cc
+++ b/net/cookies/canonical_cookie_unittest.cc
@@ -5,6 +5,7 @@
#include "net/cookies/canonical_cookie.h"
#include "base/memory/scoped_ptr.h"
+#include "base/test/histogram_tester.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_options.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -680,4 +681,77 @@ TEST(CanonicalCookieTest, EnforceSecureCookiesRequireSecureScheme) {
EXPECT_TRUE(https_cookie_secure_extended.get());
}
+namespace {
+
+class CanonicalCookiePrefixHistogramTest : public testing::TestWithParam<bool> {
+};
+
+} // namespace
+
+TEST_P(CanonicalCookiePrefixHistogramTest, TestHistograms) {
+ base::HistogramTester histograms;
+ const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix";
+ const char kCookiePrefixBlockedHistogram[] = "Cookie.CookiePrefixBlocked";
+ GURL https_url("https://www.example.test");
+ base::Time creation_time = base::Time::Now();
+ CookieOptions options;
+ if (GetParam())
+ options.set_enforce_prefixes();
+
+ scoped_ptr<CanonicalCookie> cookie1 = make_scoped_ptr(
+ CanonicalCookie::Create(https_url, "$Host-A=B;", creation_time, options));
+ if (GetParam())
+ EXPECT_EQ(nullptr, cookie1);
+ else
+ EXPECT_NE(nullptr, cookie1);
+ histograms.ExpectBucketCount(kCookiePrefixHistogram,
+ CanonicalCookie::COOKIE_PREFIX_HOST, 1);
+ histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
+ CanonicalCookie::COOKIE_PREFIX_HOST, 1);
+
+ EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create(
+ https_url, "$Host-A=B; Path=/; Secure", creation_time,
+ options)));
+ histograms.ExpectBucketCount(kCookiePrefixHistogram,
+ CanonicalCookie::COOKIE_PREFIX_HOST, 2);
+ histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
+ CanonicalCookie::COOKIE_PREFIX_HOST, 1);
+ EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create(
+ https_url, "$HostA=B; Path=/; Secure", creation_time,
+ options)));
+ histograms.ExpectBucketCount(kCookiePrefixHistogram,
+ CanonicalCookie::COOKIE_PREFIX_HOST, 2);
+ histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
+ CanonicalCookie::COOKIE_PREFIX_HOST, 1);
+
+ scoped_ptr<CanonicalCookie> cookie2 = make_scoped_ptr(CanonicalCookie::Create(
+ https_url, "$Secure-A=B;", creation_time, options));
+ if (GetParam())
+ EXPECT_EQ(nullptr, cookie2);
+ else
+ EXPECT_NE(nullptr, cookie2);
+ histograms.ExpectBucketCount(kCookiePrefixHistogram,
+ CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
+ histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
+ CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
+ EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create(
+ https_url, "$Secure-A=B; Path=/; Secure",
+ creation_time, options)));
+ histograms.ExpectBucketCount(kCookiePrefixHistogram,
+ CanonicalCookie::COOKIE_PREFIX_SECURE, 2);
+ histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
+ CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
+ EXPECT_NE(nullptr, make_scoped_ptr(CanonicalCookie::Create(
+ https_url, "$SecureA=B; Path=/; Secure", creation_time,
+ options)));
+ histograms.ExpectBucketCount(kCookiePrefixHistogram,
+ CanonicalCookie::COOKIE_PREFIX_SECURE, 2);
+ histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
+ CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
+}
+
+INSTANTIATE_TEST_CASE_P(CanonicalCookiePrefixHistogramTests,
+ CanonicalCookiePrefixHistogramTest,
+ testing::Values(true, false));
+
} // namespace net
« no previous file with comments | « net/cookies/canonical_cookie.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698