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

Unified Diff: base/metrics/histogram_unittest.cc

Issue 141393002: Return a NULL histogram pointer on construction error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, git cl format Created 6 years, 9 months 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 | « base/metrics/histogram.cc ('k') | chrome/browser/extensions/api/metrics_private/metrics_apitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_unittest.cc
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc
index e7a01aa5af3d54bf1973f959822b1d989bd8417a..5fbd28a1069de2bc66072fedafec62be247e8b12 100644
--- a/base/metrics/histogram_unittest.cc
+++ b/base/metrics/histogram_unittest.cc
@@ -443,6 +443,32 @@ TEST_F(HistogramTest, CustomHistogramSerializeInfo) {
EXPECT_FALSE(iter.SkipBytes(1));
}
+TEST_F(HistogramTest, BadConstruction) {
+ HistogramBase* histogram = Histogram::FactoryGet(
+ "BadConstruction", 0, 100, 8, HistogramBase::kNoFlags);
+ EXPECT_TRUE(histogram->HasConstructionArguments(1, 100, 8));
+
+ // Try to get the same histogram name with different arguments.
+ HistogramBase* bad_histogram = Histogram::FactoryGet(
+ "BadConstruction", 0, 100, 7, HistogramBase::kNoFlags);
+ EXPECT_EQ(NULL, bad_histogram);
+ bad_histogram = Histogram::FactoryGet(
+ "BadConstruction", 0, 99, 8, HistogramBase::kNoFlags);
+ EXPECT_EQ(NULL, bad_histogram);
+
+ HistogramBase* linear_histogram = LinearHistogram::FactoryGet(
+ "BadConstructionLinear", 0, 100, 8, HistogramBase::kNoFlags);
+ EXPECT_TRUE(linear_histogram->HasConstructionArguments(1, 100, 8));
+
+ // Try to get the same histogram name with different arguments.
+ bad_histogram = LinearHistogram::FactoryGet(
+ "BadConstructionLinear", 0, 100, 7, HistogramBase::kNoFlags);
+ EXPECT_EQ(NULL, bad_histogram);
+ bad_histogram = LinearHistogram::FactoryGet(
+ "BadConstructionLinear", 10, 100, 8, HistogramBase::kNoFlags);
+ EXPECT_EQ(NULL, bad_histogram);
+}
+
#if GTEST_HAS_DEATH_TEST
// For Histogram, LinearHistogram and CustomHistogram, the minimum for a
// declared range is 1, while the maximum is (HistogramBase::kSampleType_MAX -
« no previous file with comments | « base/metrics/histogram.cc ('k') | chrome/browser/extensions/api/metrics_private/metrics_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698