Adding UseCounter specific for extensions
Replaced Blink.UseCounter.Features by Blink.UseCounter.Extensions.Features when
URL protocol is chrome-extension://
BUG=687169
Review-Url: https://codereview.chromium.org/2796283005
Cr-Original-Commit-Position: refs/heads/master@{#473409}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: fc32d83f891bf73c8ce299d6813baf812907a8c8
diff --git a/test/histogram_tester.cc b/test/histogram_tester.cc
index 5ca3c2f..485f30f 100644
--- a/test/histogram_tester.cc
+++ b/test/histogram_tester.cc
@@ -95,6 +95,31 @@
return samples;
}
+HistogramBase::Count HistogramTester::GetBucketCount(
+ const std::string& name,
+ HistogramBase::Sample sample) const {
+ HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
+ EXPECT_NE(nullptr, histogram)
+ << "Histogram \"" << name << "\" does not exist.";
+ HistogramBase::Count count = 0;
+ if (histogram) {
+ std::unique_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
+ GetBucketCountForSamples(name, sample, *samples, &count);
+ }
+ return count;
+}
+
+void HistogramTester::GetBucketCountForSamples(
+ const std::string& name,
+ HistogramBase::Sample sample,
+ const HistogramSamples& samples,
+ HistogramBase::Count* count) const {
+ *count = samples.GetCount(sample);
+ auto histogram_data = histograms_snapshot_.find(name);
+ if (histogram_data != histograms_snapshot_.end())
+ *count -= histogram_data->second->GetCount(sample);
+}
+
HistogramTester::CountsMap HistogramTester::GetTotalCountsForPrefix(
const std::string& prefix) const {
EXPECT_TRUE(prefix.find('.') != std::string::npos)
@@ -147,10 +172,8 @@
HistogramBase::Sample sample,
HistogramBase::Count expected_count,
const HistogramSamples& samples) const {
- int actual_count = samples.GetCount(sample);
- auto histogram_data = histograms_snapshot_.find(name);
- if (histogram_data != histograms_snapshot_.end())
- actual_count -= histogram_data->second->GetCount(sample);
+ int actual_count;
+ GetBucketCountForSamples(name, sample, samples, &actual_count);
EXPECT_EQ(expected_count, actual_count)
<< "Histogram \"" << name
diff --git a/test/histogram_tester.h b/test/histogram_tester.h
index ecf33f8..1bd024c 100644
--- a/test/histogram_tester.h
+++ b/test/histogram_tester.h
@@ -78,6 +78,10 @@
// histogram_tester.GetAllSamples("HistogramName"));
std::vector<Bucket> GetAllSamples(const std::string& name) const;
+ // Returns the value of the |sample| bucket for ths histogram |name|.
+ HistogramBase::Count GetBucketCount(const std::string& name,
+ HistogramBase::Sample sample) const;
+
// Finds histograms whose names start with |prefix|, and returns them along
// with the counts of any samples added since the creation of this object.
// Histograms that are unchanged are omitted from the result. The return value
@@ -119,6 +123,14 @@
Histogram::Count expected_count,
const HistogramSamples& samples) const;
+ // Sets the value for |count| to be the value in the |sample| bucket. The
+ // bucket's current value is determined from |samples| and is modified based
+ // on the snapshot stored for histogram |name|.
+ void GetBucketCountForSamples(const std::string& name,
+ HistogramBase::Sample sample,
+ const HistogramSamples& samples,
+ HistogramBase::Count* count) const;
+
// Used to determine the histogram changes made during this instance's
// lifecycle.
std::map<std::string, std::unique_ptr<HistogramSamples>> histograms_snapshot_;