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

Unified Diff: base/test/histogram_tester.cc

Issue 2796283005: Adding UseCounter specific for extensions (Closed)
Patch Set: Codereview: added tester ExpectTotalCountExcept to simplify UseCounter unit tests Created 3 years, 7 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
Index: base/test/histogram_tester.cc
diff --git a/base/test/histogram_tester.cc b/base/test/histogram_tester.cc
index 5ca3c2fe9e8dd6145f05741fdf6022be49e877e0..cdc67bc121e5ff33cf80df1898bc396a91ba4624 100644
--- a/base/test/histogram_tester.cc
+++ b/base/test/histogram_tester.cc
@@ -61,6 +61,21 @@ void HistogramTester::ExpectBucketCount(
}
}
+void HistogramTester::ExpectTotalCountExcept(const std::string& name,
Nico 2017/05/09 19:36:45 Move this below ExpectTotalCount() so order in cc
lunalu1 2017/05/10 19:39:38 Done.
+ HistogramBase::Sample sample,
+ HistogramBase::Count count) const {
+ HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
+ EXPECT_NE(nullptr, histogram)
+ << "Histogram \"" << name << "\" does not exist.";
+ if (histogram) {
+ std::unique_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
+ CheckTotalCountExcept(name, sample, count, *samples);
+ } else {
+ // No histogram means there were zero samples.
+ EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist.";
+ }
+}
+
void HistogramTester::ExpectTotalCount(const std::string& name,
HistogramBase::Count count) const {
HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
@@ -173,6 +188,27 @@ void HistogramTester::CheckTotalCount(const std::string& name,
<< expected_count << "). It has (" << actual_count << ").";
}
+void HistogramTester::CheckTotalCountExcept(
Nico 2017/05/09 19:36:45 The new code in this file looks pretty similar to
lunalu1 2017/05/10 19:39:38 IMHO, we can implement getters (privately if we do
+ const std::string& name,
+ HistogramBase::Sample sample,
+ HistogramBase::Count expected_count,
+ const HistogramSamples& samples) const {
+ int actual_total_count = samples.TotalCount();
+ int actual_bucket_count = samples.GetCount(sample);
+
+ auto histogram_data = histograms_snapshot_.find(name);
+ if (histogram_data != histograms_snapshot_.end()) {
+ actual_total_count -= histogram_data->second->TotalCount();
+ actual_bucket_count -= histogram_data->second->GetCount(sample);
+ }
+ int actual_count = actual_total_count - actual_bucket_count;
+
+ EXPECT_EQ(expected_count, actual_count)
+ << "Histogram \"" << name
+ << "\" does not have the right total number of samples ("
+ << expected_count << "). It has (" << actual_count << ").";
+}
+
bool Bucket::operator==(const Bucket& other) const {
return min == other.min && count == other.count;
}

Powered by Google App Engine
This is Rietveld 408576698