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

Unified Diff: base/test/histogram_tester.cc

Issue 1264123002: HistogramTester::GetHistogramSamplesSinceCreation never returns null (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sql tests simplified Created 5 years, 5 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 | « no previous file | base/test/histogram_tester_unittest.cc » ('j') | base/test/histogram_tester_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/histogram_tester.cc
diff --git a/base/test/histogram_tester.cc b/base/test/histogram_tester.cc
index 0bff2f841c1d66fcccc13be29fef0adf9a8a5c17..051f599f45a360f7afc31f897c051260a34fecde 100644
--- a/base/test/histogram_tester.cc
+++ b/base/test/histogram_tester.cc
@@ -6,6 +6,7 @@
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_samples.h"
+#include "base/metrics/sample_map.h"
#include "base/metrics/statistics_recorder.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -112,8 +113,14 @@ HistogramTester::CountsMap HistogramTester::GetTotalCountsForPrefix(
scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation(
const std::string& histogram_name) const {
HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
+ // Whether the histogram exists or not may not depend on the current test
+ // calling this method, but rather on which tests ran before and possibly
+ // generated a histogram or not (see http://crbug.com/473689). To provide a
+ // response which is independent of the previously run tests, this method
+ // creates empty samples in the absence of the histogram, rather than
+ // returning null.
if (!histogram)
- return scoped_ptr<HistogramSamples>();
+ return scoped_ptr<HistogramSamples>(new SampleMap);
scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples());
auto original_samples_it = histograms_snapshot_.find(histogram_name);
if (original_samples_it != histograms_snapshot_.end())
« no previous file with comments | « no previous file | base/test/histogram_tester_unittest.cc » ('j') | base/test/histogram_tester_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698