summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/BUILD.gn2
-rw-r--r--base/base.gyp6
-rw-r--r--base/test/BUILD.gn4
-rw-r--r--base/test/histogram_tester.cc122
-rw-r--r--base/test/histogram_tester.h81
-rw-r--r--base/test/histogram_tester_unittest.cc81
-rw-r--r--base/test/statistics_delta_reader.cc44
-rw-r--r--base/test/statistics_delta_reader.h45
-rw-r--r--base/test/statistics_delta_reader_unittest.cc34
-rw-r--r--chrome/browser/accessibility/browser_accessibility_state_browsertest.cc5
-rw-r--r--chrome/browser/chromeos/external_metrics_unittest.cc16
-rw-r--r--chrome/browser/prerender/prerender_browsertest.cc153
-rw-r--r--chrome/browser/signin/account_reconcilor_unittest.cc71
-rw-r--r--chrome/browser/spellchecker/spellcheck_host_metrics_unittest.cc66
-rw-r--r--chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm56
-rw-r--r--chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc160
-rw-r--r--chrome/browser/ui/passwords/manage_passwords_ui_controller_unittest.cc2
-rw-r--r--chrome/browser/ui/views/passwords/manage_passwords_view_test.cc5
-rw-r--r--chrome/browser/ui/views/passwords/manage_passwords_view_test.h4
-rw-r--r--chrome/browser/ui/views/profiles/profile_chooser_view_browsertest.cc3
-rw-r--r--chrome/chrome_tests_unit.gypi2
-rw-r--r--chrome/renderer/net/net_error_helper_core_unittest.cc137
-rw-r--r--chrome/test/base/uma_histogram_helper.cc127
-rw-r--r--chrome/test/base/uma_histogram_helper.h74
-rw-r--r--chrome/test/nacl/nacl_browsertest_uma.cc27
-rw-r--r--components/suggestions/blacklist_store_unittest.cc24
-rw-r--r--content/public/test/browser_test_utils.cc16
-rw-r--r--content/public/test/browser_test_utils.h4
-rw-r--r--net/spdy/spdy_session_unittest.cc21
-rw-r--r--net/url_request/url_request_throttler_unittest.cc20
30 files changed, 595 insertions, 817 deletions
diff --git a/base/BUILD.gn b/base/BUILD.gn
index deeed07..e65a277 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -1223,7 +1223,7 @@ test("base_unittests") {
"template_util_unittest.cc",
"test/expectations/expectation_unittest.cc",
"test/expectations/parser_unittest.cc",
- "test/statistics_delta_reader_unittest.cc",
+ "test/histogram_tester_unittest.cc",
"test/test_reg_util_win_unittest.cc",
"test/trace_event_analyzer_unittest.cc",
"threading/non_thread_safe_unittest.cc",
diff --git a/base/base.gyp b/base/base.gyp
index e1d6793..e6c45ea 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -592,7 +592,7 @@
'template_util_unittest.cc',
'test/expectations/expectation_unittest.cc',
'test/expectations/parser_unittest.cc',
- 'test/statistics_delta_reader_unittest.cc',
+ 'test/histogram_tester_unittest.cc',
'test/test_reg_util_win_unittest.cc',
'test/trace_event_analyzer_unittest.cc',
'threading/non_thread_safe_unittest.cc',
@@ -902,8 +902,8 @@
'test/simple_test_clock.h',
'test/simple_test_tick_clock.cc',
'test/simple_test_tick_clock.h',
- 'test/statistics_delta_reader.cc',
- 'test/statistics_delta_reader.h',
+ 'test/histogram_tester.cc',
+ 'test/histogram_tester.h',
'test/task_runner_test_template.cc',
'test/task_runner_test_template.h',
'test/test_file_util.cc',
diff --git a/base/test/BUILD.gn b/base/test/BUILD.gn
index 3aefb72e..c55400d 100644
--- a/base/test/BUILD.gn
+++ b/base/test/BUILD.gn
@@ -16,6 +16,8 @@ source_set("test_support") {
"expectations/parser.h",
"gtest_xml_util.cc",
"gtest_xml_util.h",
+ "histogram_tester.cc",
+ "histogram_tester.h",
"launcher/test_launcher.cc",
"launcher/test_launcher.h",
"launcher/test_result.cc",
@@ -56,8 +58,6 @@ source_set("test_support") {
"simple_test_clock.h",
"simple_test_tick_clock.cc",
"simple_test_tick_clock.h",
- "statistics_delta_reader.cc",
- "statistics_delta_reader.h",
"task_runner_test_template.cc",
"task_runner_test_template.h",
"test_file_util.cc",
diff --git a/base/test/histogram_tester.cc b/base/test/histogram_tester.cc
new file mode 100644
index 0000000..412059a
--- /dev/null
+++ b/base/test/histogram_tester.cc
@@ -0,0 +1,122 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/histogram_tester.h"
+
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_samples.h"
+#include "base/metrics/statistics_recorder.h"
+#include "base/stl_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+HistogramTester::HistogramTester() {
+ StatisticsRecorder::Initialize(); // Safe to call multiple times.
+
+ // Record any histogram data that exists when the object is created so it can
+ // be subtracted later.
+ StatisticsRecorder::Histograms histograms;
+ StatisticsRecorder::GetSnapshot(std::string(), &histograms);
+ for (size_t i = 0; i < histograms.size(); ++i) {
+ histograms_snapshot_[histograms[i]->histogram_name()] =
+ histograms[i]->SnapshotSamples().release();
+ }
+}
+
+HistogramTester::~HistogramTester() {
+ STLDeleteValues(&histograms_snapshot_);
+}
+
+void HistogramTester::ExpectUniqueSample(
+ const std::string& name,
+ base::HistogramBase::Sample sample,
+ base::HistogramBase::Count expected_count) const {
+ base::HistogramBase* histogram =
+ base::StatisticsRecorder::FindHistogram(name);
+ EXPECT_NE(static_cast<base::HistogramBase*>(NULL), histogram)
+ << "Histogram \"" << name << "\" does not exist.";
+
+ if (histogram) {
+ scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
+ CheckBucketCount(name, sample, expected_count, *samples);
+ CheckTotalCount(name, expected_count, *samples);
+ }
+}
+
+void HistogramTester::ExpectBucketCount(
+ const std::string& name,
+ base::HistogramBase::Sample sample,
+ base::HistogramBase::Count expected_count) const {
+ base::HistogramBase* histogram =
+ base::StatisticsRecorder::FindHistogram(name);
+ EXPECT_NE(static_cast<base::HistogramBase*>(NULL), histogram)
+ << "Histogram \"" << name << "\" does not exist.";
+
+ if (histogram) {
+ scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
+ CheckBucketCount(name, sample, expected_count, *samples);
+ }
+}
+
+void HistogramTester::ExpectTotalCount(const std::string& name,
+ base::HistogramBase::Count count) const {
+ base::HistogramBase* histogram =
+ base::StatisticsRecorder::FindHistogram(name);
+ if (histogram) {
+ scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
+ CheckTotalCount(name, count, *samples);
+ } else {
+ // No histogram means there were zero samples.
+ EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist.";
+ }
+}
+
+scoped_ptr<HistogramSamples> HistogramTester::GetHistogramSamplesSinceCreation(
+ const std::string& histogram_name) {
+ HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
+ if (!histogram)
+ return scoped_ptr<HistogramSamples>();
+ scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples());
+ HistogramSamples* named_original_samples =
+ histograms_snapshot_[histogram_name];
+ if (named_original_samples)
+ named_samples->Subtract(*named_original_samples);
+ return named_samples.Pass();
+}
+
+void HistogramTester::CheckBucketCount(
+ const std::string& name,
+ base::HistogramBase::Sample sample,
+ base::HistogramBase::Count expected_count,
+ base::HistogramSamples& samples) const {
+ int actual_count = samples.GetCount(sample);
+ std::map<std::string, HistogramSamples*>::const_iterator histogram_data;
+ histogram_data = histograms_snapshot_.find(name);
+ if (histogram_data != histograms_snapshot_.end())
+ actual_count -= histogram_data->second->GetCount(sample);
+
+ EXPECT_EQ(expected_count, actual_count)
+ << "Histogram \"" << name
+ << "\" does not have the right number of samples (" << expected_count
+ << ") in the expected bucket (" << sample << "). It has (" << actual_count
+ << ").";
+}
+
+void HistogramTester::CheckTotalCount(const std::string& name,
+ base::HistogramBase::Count expected_count,
+ base::HistogramSamples& samples) const {
+ int actual_count = samples.TotalCount();
+ std::map<std::string, HistogramSamples*>::const_iterator histogram_data;
+ histogram_data = histograms_snapshot_.find(name);
+ if (histogram_data != histograms_snapshot_.end())
+ actual_count -= histogram_data->second->TotalCount();
+
+ EXPECT_EQ(expected_count, actual_count)
+ << "Histogram \"" << name
+ << "\" does not have the right total number of samples ("
+ << expected_count << "). It has (" << actual_count << ").";
+}
+
+} // namespace base
diff --git a/base/test/histogram_tester.h b/base/test/histogram_tester.h
new file mode 100644
index 0000000..b672308
--- /dev/null
+++ b/base/test/histogram_tester.h
@@ -0,0 +1,81 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TEST_HISTOGRAM_TESTER_H_
+#define BASE_TEST_HISTOGRAM_TESTER_H_
+
+#include <map>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_base.h"
+
+namespace base {
+
+class HistogramSamples;
+
+// HistogramTester provides a simple interface for examining histograms, UMA
+// or otherwise. Tests can use this interface to verify that histogram data is
+// getting logged as intended.
+class HistogramTester {
+ public:
+ // The constructor will call StatisticsRecorder::Initialize() for you. Also,
+ // this takes a snapshot of all current histograms counts.
+ HistogramTester();
+ ~HistogramTester();
+
+ // We know the exact number of samples in a bucket, and that no other bucket
+ // should have samples. Measures the diff from the snapshot taken when this
+ // object was constructed.
+ void ExpectUniqueSample(const std::string& name,
+ base::HistogramBase::Sample sample,
+ base::HistogramBase::Count expected_count) const;
+
+ // We know the exact number of samples in a bucket, but other buckets may
+ // have samples as well. Measures the diff from the snapshot taken when this
+ // object was constructed.
+ void ExpectBucketCount(const std::string& name,
+ base::HistogramBase::Sample sample,
+ base::HistogramBase::Count expected_count) const;
+
+ // We don't know the values of the samples, but we know how many there are.
+ // This measures the diff from the snapshot taken when this object was
+ // constructed.
+ void ExpectTotalCount(const std::string& name,
+ base::HistogramBase::Count count) const;
+
+ // Access a modified HistogramSamples containing only what has been logged
+ // to the histogram since the creation of this object.
+ scoped_ptr<HistogramSamples> GetHistogramSamplesSinceCreation(
+ const std::string& histogram_name);
+
+ private:
+ // Verifies and asserts that value in the |sample| bucket matches the
+ // |expected_count|. The bucket's current value is determined from |samples|
+ // and is modified based on the snapshot stored for histogram |name|.
+ void CheckBucketCount(const std::string& name,
+ base::HistogramBase::Sample sample,
+ base::Histogram::Count expected_count,
+ base::HistogramSamples& samples) const;
+
+ // Verifies that the total number of values recorded for the histogram |name|
+ // is |expected_count|. This is checked against |samples| minus the snapshot
+ // that was taken for |name|.
+ void CheckTotalCount(const std::string& name,
+ base::Histogram::Count expected_count,
+ base::HistogramSamples& samples) const;
+
+ // Used to determine the histogram changes made during this instance's
+ // lifecycle. This instance takes ownership of the samples, which are deleted
+ // when the instance is destroyed.
+ std::map<std::string, HistogramSamples*> histograms_snapshot_;
+
+ DISALLOW_COPY_AND_ASSIGN(HistogramTester);
+};
+
+} // namespace base
+
+#endif // BASE_TEST_HISTOGRAM_TESTER_H_
diff --git a/base/test/histogram_tester_unittest.cc b/base/test/histogram_tester_unittest.cc
new file mode 100644
index 0000000..a03ee13
--- /dev/null
+++ b/base/test/histogram_tester_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/histogram_tester.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_samples.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+const std::string kHistogram1 = "Test1";
+const std::string kHistogram2 = "Test2";
+const std::string kHistogram3 = "Test3";
+const std::string kHistogram4 = "Test4";
+
+typedef testing::Test HistogramTesterTest;
+
+TEST_F(HistogramTesterTest, Scope) {
+ // Record a histogram before the creation of the recorder.
+ UMA_HISTOGRAM_BOOLEAN(kHistogram1, true);
+
+ HistogramTester tester;
+
+ // Verify that no histogram is recorded.
+ scoped_ptr<HistogramSamples> samples(
+ tester.GetHistogramSamplesSinceCreation(kHistogram1));
+ EXPECT_FALSE(samples);
+
+ // Record a histogram after the creation of the recorder.
+ UMA_HISTOGRAM_BOOLEAN(kHistogram1, true);
+
+ // Verify that one histogram is recorded.
+ samples = tester.GetHistogramSamplesSinceCreation(kHistogram1);
+ EXPECT_TRUE(samples);
+ EXPECT_EQ(1, samples->TotalCount());
+}
+
+TEST_F(HistogramTesterTest, TestUniqueSample) {
+ HistogramTester tester;
+
+ // Record into a sample thrice
+ UMA_HISTOGRAM_COUNTS_100(kHistogram2, 2);
+ UMA_HISTOGRAM_COUNTS_100(kHistogram2, 2);
+ UMA_HISTOGRAM_COUNTS_100(kHistogram2, 2);
+
+ tester.ExpectUniqueSample(kHistogram2, 2, 3);
+}
+
+TEST_F(HistogramTesterTest, TestBucketsSample) {
+ HistogramTester tester;
+
+ // Record into a sample twice
+ UMA_HISTOGRAM_COUNTS_100(kHistogram3, 2);
+ UMA_HISTOGRAM_COUNTS_100(kHistogram3, 2);
+ UMA_HISTOGRAM_COUNTS_100(kHistogram3, 2);
+ UMA_HISTOGRAM_COUNTS_100(kHistogram3, 2);
+ UMA_HISTOGRAM_COUNTS_100(kHistogram3, 3);
+
+ tester.ExpectBucketCount(kHistogram3, 2, 4);
+ tester.ExpectBucketCount(kHistogram3, 3, 1);
+
+ tester.ExpectTotalCount(kHistogram3, 5);
+}
+
+TEST_F(HistogramTesterTest, TestBucketsSampleWithScope) {
+ // Record into a sample twice, once before the tester creation and once after.
+ UMA_HISTOGRAM_COUNTS_100(kHistogram4, 2);
+
+ HistogramTester tester;
+ UMA_HISTOGRAM_COUNTS_100(kHistogram4, 3);
+
+ tester.ExpectBucketCount(kHistogram4, 2, 0);
+ tester.ExpectBucketCount(kHistogram4, 3, 1);
+
+ tester.ExpectTotalCount(kHistogram4, 1);
+}
+
+} // namespace base
diff --git a/base/test/statistics_delta_reader.cc b/base/test/statistics_delta_reader.cc
deleted file mode 100644
index 93ce1ad..0000000
--- a/base/test/statistics_delta_reader.cc
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/test/statistics_delta_reader.h"
-
-#include "base/metrics/histogram.h"
-#include "base/metrics/histogram_samples.h"
-#include "base/metrics/statistics_recorder.h"
-#include "base/stl_util.h"
-
-namespace base {
-
-StatisticsDeltaReader::StatisticsDeltaReader() {
- StatisticsRecorder::Initialize(); // Safe to call multiple times.
-
- // Record any histogram data that exists when the object is created so it can
- // be subtracted later.
- StatisticsRecorder::Histograms histograms;
- StatisticsRecorder::GetSnapshot(std::string(), &histograms);
- for (size_t i = 0; i < histograms.size(); ++i) {
- original_samples_[histograms[i]->histogram_name()] =
- histograms[i]->SnapshotSamples().release();
- }
-}
-
-StatisticsDeltaReader::~StatisticsDeltaReader() {
- STLDeleteValues(&original_samples_);
-}
-
-scoped_ptr<HistogramSamples>
- StatisticsDeltaReader::GetHistogramSamplesSinceCreation(
- const std::string& histogram_name) {
- HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
- if (!histogram)
- return scoped_ptr<HistogramSamples>();
- scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples());
- HistogramSamples* named_original_samples = original_samples_[histogram_name];
- if (named_original_samples)
- named_samples->Subtract(*named_original_samples);
- return named_samples.Pass();
-}
-
-} // namespace base
diff --git a/base/test/statistics_delta_reader.h b/base/test/statistics_delta_reader.h
deleted file mode 100644
index 26d87c5..0000000
--- a/base/test/statistics_delta_reader.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_TEST_STATISTICS_DELTA_READER_H_
-#define BASE_TEST_STATISTICS_DELTA_READER_H_
-
-#include <map>
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-
-namespace base {
-
-class HistogramSamples;
-
-// This class acts as a differential reader for histogram samples, enabling
-// tests to check that metrics were recorded as they should be.
-//
-// This class is DEPRECATED.
-// TODO(mlerman): Remove all references to this class with UMAHistogramHelper
-// references. crbug.com/384011
-class StatisticsDeltaReader {
- public:
- StatisticsDeltaReader();
- ~StatisticsDeltaReader();
-
- // Returns the histogram data accumulated since this instance was created.
- // Returns NULL if no samples are available.
- scoped_ptr<HistogramSamples> GetHistogramSamplesSinceCreation(
- const std::string& histogram_name);
-
- private:
- // Used to determine the histogram changes made during this instance's
- // lifecycle. This instance takes ownership of the samples, which are deleted
- // when the instance is destroyed.
- std::map<std::string, HistogramSamples*> original_samples_;
-
- DISALLOW_COPY_AND_ASSIGN(StatisticsDeltaReader);
-};
-
-} // namespace base
-
-#endif // BASE_TEST_STATISTICS_DELTA_READER_H_
diff --git a/base/test/statistics_delta_reader_unittest.cc b/base/test/statistics_delta_reader_unittest.cc
deleted file mode 100644
index 55180d1..0000000
--- a/base/test/statistics_delta_reader_unittest.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/test/statistics_delta_reader.h"
-
-#include "base/memory/scoped_ptr.h"
-#include "base/metrics/histogram.h"
-#include "base/metrics/histogram_samples.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-
-TEST(StatisticsDeltaReaderTest, Scope) {
- // Record a histogram before the creation of the recorder.
- UMA_HISTOGRAM_BOOLEAN("Test", true);
-
- StatisticsDeltaReader reader;
-
- // Verify that no histogram is recorded.
- scoped_ptr<HistogramSamples> samples(
- reader.GetHistogramSamplesSinceCreation("Test"));
- EXPECT_FALSE(samples);
-
- // Record a histogram after the creation of the recorder.
- UMA_HISTOGRAM_BOOLEAN("Test", true);
-
- // Verify that one histogram is recorded.
- samples = reader.GetHistogramSamplesSinceCreation("Test");
- EXPECT_TRUE(samples);
- EXPECT_EQ(1, samples->TotalCount());
-}
-
-} // namespace base
diff --git a/chrome/browser/accessibility/browser_accessibility_state_browsertest.cc b/chrome/browser/accessibility/browser_accessibility_state_browsertest.cc
index f23f218..f75dd00 100644
--- a/chrome/browser/accessibility/browser_accessibility_state_browsertest.cc
+++ b/chrome/browser/accessibility/browser_accessibility_state_browsertest.cc
@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/test/histogram_tester.h"
#include "content/public/browser/browser_accessibility_state.h"
#include "chrome/test/base/in_process_browser_test.h"
-#include "chrome/test/base/uma_histogram_helper.h"
namespace content {
@@ -15,10 +15,9 @@ class BrowserAccessibilityStateImplTest : public InProcessBrowserTest {
};
IN_PROC_BROWSER_TEST_F(BrowserAccessibilityStateImplTest, TestHistograms) {
- UMAHistogramHelper histograms;
+ base::HistogramTester histograms;
BrowserAccessibilityState::GetInstance()->UpdateHistogramsForTesting();
- histograms.Fetch();
histograms.ExpectTotalCount("Accessibility.State", 1);
#if defined(OS_WIN)
histograms.ExpectTotalCount("Accessibility.WinScreenReader", 1);
diff --git a/chrome/browser/chromeos/external_metrics_unittest.cc b/chrome/browser/chromeos/external_metrics_unittest.cc
index 47faa07..0dd69e4 100644
--- a/chrome/browser/chromeos/external_metrics_unittest.cc
+++ b/chrome/browser/chromeos/external_metrics_unittest.cc
@@ -6,8 +6,8 @@
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/statistics_recorder.h"
+#include "base/test/histogram_tester.h"
#include "chrome/browser/chromeos/external_metrics.h"
-#include "chrome/test/base/uma_histogram_helper.h"
#include "components/metrics/serialization/metric_sample.h"
#include "components/metrics/serialization/serialization_utils.h"
#include "content/public/test/test_browser_thread_bundle.h"
@@ -20,8 +20,6 @@ class ExternalMetricsTest : public testing::Test {
ASSERT_TRUE(dir_.CreateUniqueTempDir());
external_metrics_ = ExternalMetrics::CreateForTesting(
dir_.path().Append("testfile").value());
-
- base::StatisticsRecorder::Initialize();
}
base::ScopedTempDir dir_;
@@ -37,6 +35,8 @@ TEST_F(ExternalMetricsTest, HandleMissingFile) {
}
TEST_F(ExternalMetricsTest, CanReceiveHistogram) {
+ base::HistogramTester histogram_tester;
+
scoped_ptr<metrics::MetricSample> hist =
metrics::MetricSample::HistogramSample("foo", 2, 1, 100, 10);
@@ -45,12 +45,12 @@ TEST_F(ExternalMetricsTest, CanReceiveHistogram) {
EXPECT_EQ(1, external_metrics_->CollectEvents());
- UMAHistogramHelper helper;
- helper.Fetch();
- helper.ExpectTotalCount("foo", 1);
+ histogram_tester.ExpectTotalCount("foo", 1);
}
TEST_F(ExternalMetricsTest, IncorrectHistogramsAreDiscarded) {
+ base::HistogramTester histogram_tester;
+
// Malformed histogram (min > max).
scoped_ptr<metrics::MetricSample> hist =
metrics::MetricSample::HistogramSample("bar", 30, 200, 20, 10);
@@ -60,9 +60,7 @@ TEST_F(ExternalMetricsTest, IncorrectHistogramsAreDiscarded) {
external_metrics_->CollectEvents();
- UMAHistogramHelper helper;
- helper.Fetch();
- helper.ExpectTotalCount("bar", 0);
+ histogram_tester.ExpectTotalCount("bar", 0);
}
} // namespace chromeos
diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc
index 4c96662..65d4bb9 100644
--- a/chrome/browser/prerender/prerender_browsertest.cc
+++ b/chrome/browser/prerender/prerender_browsertest.cc
@@ -17,6 +17,7 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/histogram_tester.h"
#include "base/test/test_timeouts.h"
#include "base/values.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
@@ -64,7 +65,6 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
-#include "chrome/test/base/uma_histogram_helper.h"
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/navigation_controller.h"
@@ -1503,6 +1503,8 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
js).c_str()));
}
+ const base::HistogramTester& histogram_tester() { return histogram_tester_; }
+
protected:
bool autostart_test_server_;
@@ -1653,21 +1655,21 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
std::string loader_path_;
std::string loader_query_;
Browser* explicitly_set_browser_;
+ base::HistogramTester histogram_tester_;
};
// Checks that a page is correctly prerendered in the case of a
// <link rel=prerender> tag and then loaded into a tab in response to a
// navigation.
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) {
- UMAHistogramHelper histograms;
-
PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
EXPECT_EQ(1, GetPrerenderDomContentLoadedEventCountForLinkNumber(0));
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0);
- histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.none_PerceivedPLTMatchedComplete", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.websame_PrerenderNotSwappedInPLT", 1);
ChannelDestructionWatcher channel_close_watcher;
channel_close_watcher.WatchChannel(
@@ -1675,10 +1677,10 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) {
NavigateToDestURL();
channel_close_watcher.WaitForChannelClose();
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 1);
- histograms.ExpectTotalCount(
+ histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
+ 1);
+ histogram_tester().ExpectTotalCount(
"Prerender.websame_PerceivedPLTMatchedComplete", 1);
ASSERT_TRUE(IsEmptyPrerenderLinkManager());
@@ -1686,21 +1688,20 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) {
// Checks that cross-domain prerenders emit the correct histograms.
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageCrossDomain) {
- UMAHistogramHelper histograms;
-
PrerenderTestURL(GetCrossDomainTestUrl("files/prerender/prerender_page.html"),
FINAL_STATUS_USED, 1);
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0);
- histograms.ExpectTotalCount("Prerender.webcross_PrerenderNotSwappedInPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.none_PerceivedPLTMatchedComplete", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.webcross_PrerenderNotSwappedInPLT", 1);
NavigateToDestURL();
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.webcross_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.webcross_PerceivedPLTMatched", 1);
- histograms.ExpectTotalCount(
+ histogram_tester().ExpectTotalCount("Prerender.webcross_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.webcross_PerceivedPLTMatched",
+ 1);
+ histogram_tester().ExpectTotalCount(
"Prerender.webcross_PerceivedPLTMatchedComplete", 1);
}
@@ -2079,7 +2080,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
PrerenderLocationReplaceGWSHistograms) {
DisableJavascriptCalls();
- UMAHistogramHelper histograms;
// The loader page should look like Google.
const std::string kGoogleDotCom("www.google.com");
@@ -2105,14 +2105,15 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
EXPECT_TRUE(DidPrerenderPass(prerender->contents()->prerender_contents()));
EXPECT_EQ(1, prerender->number_of_loads());
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.none_PerceivedPLTMatchedComplete", 0);
// Although there is a client redirect, it is dropped from histograms because
// it is a Google URL. The target page itself does not load until after the
// swap.
- histograms.ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT", 0);
+ histogram_tester().ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT",
+ 0);
GURL navigate_url = test_server()->GetURL(
"files/prerender/prerender_location_replace.html?" +
@@ -2130,15 +2131,16 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
EXPECT_TRUE(DidDisplayPass(GetActiveWebContents()));
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT", 0);
- histograms.ExpectTotalCount("Prerender.gws_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.gws_PerceivedPLTMatched", 1);
- histograms.ExpectTotalCount(
+ histogram_tester().ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT",
+ 0);
+ histogram_tester().ExpectTotalCount("Prerender.gws_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.gws_PerceivedPLTMatched", 1);
+ histogram_tester().ExpectTotalCount(
"Prerender.gws_PerceivedPLTMatchedComplete", 1);
// The client redirect does /not/ count as a miss because it's a Google URL.
- histograms.ExpectTotalCount("Prerender.PerceivedPLTFirstAfterMiss", 0);
+ histogram_tester().ExpectTotalCount("Prerender.PerceivedPLTFirstAfterMiss",
+ 0);
}
// Checks that client-issued redirects work with prerendering.
@@ -3343,24 +3345,24 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, ControlGroupRendererInitiated) {
// account for the MatchComplete case, and it must have a final status of
// FINAL_STATUS_WOULD_HAVE_BEEN_USED.
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) {
- UMAHistogramHelper histograms;
std::vector<FinalStatus> expected_final_status_queue;
expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD);
expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED);
PrerenderTestURL("files/prerender/prerender_xhr_put.html",
expected_final_status_queue, 1);
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0);
- histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.none_PerceivedPLTMatchedComplete", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.websame_PrerenderNotSwappedInPLT", 1);
NavigateToDestURL();
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount(
+ histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
+ 0);
+ histogram_tester().ExpectTotalCount(
"Prerender.websame_PerceivedPLTMatchedComplete", 1);
}
@@ -3368,8 +3370,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) {
// progress does not also classify the previous navigation as a MatchComplete.
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
MatchCompleteDummyCancelNavigation) {
- UMAHistogramHelper histograms;
-
// Arrange for a URL to hang.
const GURL kNoCommitUrl("http://never-respond.example.com");
base::FilePath file(FILE_PATH_LITERAL(
@@ -3386,11 +3386,12 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED);
PrerenderTestURL("files/prerender/prerender_xhr_put.html",
expected_final_status_queue, 1);
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0);
- histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.none_PerceivedPLTMatchedComplete", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.websame_PrerenderNotSwappedInPLT", 1);
// Open the hanging URL in a new tab. Wait for both the new tab to open and
// the hanging request to be scheduled.
@@ -3403,13 +3404,14 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
// should forcibly complete the previous navigation and also complete a
// WOULD_HAVE_BEEN_PRERENDERED navigation.
NavigateToDestURL();
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 2);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0);
- histograms.ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount(
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 2);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.none_PerceivedPLTMatchedComplete", 0);
+ histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
+ 0);
+ histogram_tester().ExpectTotalCount(
"Prerender.websame_PerceivedPLTMatchedComplete", 1);
}
@@ -3792,7 +3794,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, CancelMatchCompleteDummy) {
// visible. Also test the right histogram events are emitted in this case.
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDeferredImage) {
DisableJavascriptCalls();
- UMAHistogramHelper histograms;
// The prerender will not completely load until after the swap, so wait for a
// title change before calling DidPrerenderPass.
@@ -3804,11 +3805,12 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDeferredImage) {
EXPECT_EQ(1, GetPrerenderDomContentLoadedEventCountForLinkNumber(0));
EXPECT_TRUE(DidPrerenderPass(prerender->contents()->prerender_contents()));
EXPECT_EQ(0, prerender->number_of_loads());
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0);
- histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 0);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.none_PerceivedPLTMatchedComplete", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.websame_PrerenderNotSwappedInPLT", 0);
// Swap.
NavigationOrSwapObserver swap_observer(current_browser()->tab_strip_model(),
@@ -3824,11 +3826,12 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDeferredImage) {
// Now check DidDisplayPass.
EXPECT_TRUE(DidDisplayPass(GetActiveWebContents()));
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 0);
- histograms.ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 1);
- histograms.ExpectTotalCount(
+ histogram_tester().ExpectTotalCount(
+ "Prerender.websame_PrerenderNotSwappedInPLT", 0);
+ histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
+ 1);
+ histogram_tester().ExpectTotalCount(
"Prerender.websame_PerceivedPLTMatchedComplete", 1);
}
@@ -4173,14 +4176,12 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPing) {
}
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPPLTNormalNavigation) {
- UMAHistogramHelper histograms;
-
GURL url = test_server()->GetURL("files/prerender/prerender_page.html");
ui_test_utils::NavigateToURL(current_browser(), url);
- histograms.Fetch();
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
- histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
+ histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
+ histogram_tester().ExpectTotalCount(
+ "Prerender.none_PerceivedPLTMatchedComplete", 0);
}
IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
diff --git a/chrome/browser/signin/account_reconcilor_unittest.cc b/chrome/browser/signin/account_reconcilor_unittest.cc
index 501df05..e1a5af9 100644
--- a/chrome/browser/signin/account_reconcilor_unittest.cc
+++ b/chrome/browser/signin/account_reconcilor_unittest.cc
@@ -6,6 +6,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/histogram_tester.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/prefs/pref_service_syncable.h"
@@ -20,7 +21,6 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
-#include "chrome/test/base/uma_histogram_helper.h"
#include "components/signin/core/browser/account_reconcilor.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
@@ -36,13 +36,6 @@
namespace {
const char kTestEmail[] = "user@gmail.com";
-const char* const kHistogramsToSnapshot[] = {
- "Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
- "Signin.Reconciler.AddedToCookieJar.FirstRun",
- "Signin.Reconciler.AddedToChrome.FirstRun",
- "Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun",
- "Signin.Reconciler.AddedToCookieJar.SubsequentRun",
- "Signin.Reconciler.AddedToChrome.SubsequentRun"};
class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> {
public:
@@ -100,7 +93,7 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
TestingProfile* profile() { return profile_; }
FakeSigninManagerForTesting* signin_manager() { return signin_manager_; }
FakeProfileOAuth2TokenService* token_service() { return token_service_; }
- UMAHistogramHelper* histogram_helper() { return &histogram_helper_; }
+ base::HistogramTester* histogram_tester() { return &histogram_tester_; }
void SetFakeResponse(const std::string& url,
const std::string& data,
@@ -129,7 +122,7 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
MockAccountReconcilor* mock_reconcilor_;
net::FakeURLFetcherFactory url_fetcher_factory_;
scoped_ptr<TestingProfileManager> testing_profile_manager_;
- UMAHistogramHelper histogram_helper_;
+ base::HistogramTester histogram_tester_;
DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest);
};
@@ -175,10 +168,6 @@ void AccountReconcilorTest::SetUp() {
token_service_ =
static_cast<FakeProfileOAuth2TokenService*>(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile()));
-
- // Take a new snapshot of the concerned histograms before each test
- histogram_helper_.PrepareSnapshot(kHistogramsToSnapshot,
- arraysize(kHistogramsToSnapshot));
}
MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() {
@@ -396,10 +385,9 @@ TEST_P(AccountReconcilorTest, StartReconcileNoop) {
ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
ASSERT_FALSE(reconcilor->is_reconcile_started_);
- histogram_helper()->Fetch();
- histogram_helper()->ExpectTotalCount(
+ histogram_tester()->ExpectTotalCount(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
signin_metrics::ACCOUNTS_SAME,
1);
@@ -445,8 +433,7 @@ TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) {
ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
ASSERT_FALSE(reconcilor->is_reconcile_started_);
- histogram_helper()->Fetch();
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
signin_metrics::ACCOUNTS_SAME,
1);
@@ -490,10 +477,9 @@ TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) {
ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
ASSERT_FALSE(reconcilor->is_reconcile_started_);
- histogram_helper()->Fetch();
- histogram_helper()->ExpectTotalCount(
+ histogram_tester()->ExpectTotalCount(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun", 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
signin_metrics::ACCOUNTS_SAME,
1);
@@ -525,14 +511,13 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
GoogleServiceAuthError::AuthErrorNone());
ASSERT_FALSE(reconcilor->is_reconcile_started_);
- histogram_helper()->Fetch();
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
signin_metrics::ACCOUNTS_SAME,
1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
}
@@ -571,14 +556,13 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
reconcilor, "other@gmail.com", GoogleServiceAuthError::AuthErrorNone());
ASSERT_FALSE(reconcilor->is_reconcile_started_);
- histogram_helper()->Fetch();
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
signin_metrics::ACCOUNTS_SAME,
1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
// Do another pass after I've added a third account to the token service
@@ -612,22 +596,21 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
reconcilor, "third@gmail.com", GoogleServiceAuthError::AuthErrorNone());
ASSERT_FALSE(reconcilor->is_reconcile_started_);
- histogram_helper()->Fetch();
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
signin_metrics::ACCOUNTS_SAME,
1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToCookieJar.FirstRun", 1, 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.SubsequentRun",
signin_metrics::ACCOUNTS_SAME,
1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToCookieJar.SubsequentRun", 1, 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToChrome.SubsequentRun", 0, 1);
}
@@ -655,14 +638,13 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToChrome) {
SimulateRefreshTokenFetched(reconcilor, "other@gmail.com", "");
ASSERT_FALSE(reconcilor->is_reconcile_started_);
- histogram_helper()->Fetch();
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
signin_metrics::ACCOUNTS_SAME,
1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToCookieJar.FirstRun", 0, 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToChrome.FirstRun", 1, 1);
}
@@ -698,14 +680,13 @@ TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
GoogleServiceAuthError::AuthErrorNone());
ASSERT_FALSE(reconcilor->is_reconcile_started_);
- histogram_helper()->Fetch();
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.DifferentPrimaryAccounts.FirstRun",
signin_metrics::COOKIE_AND_TOKEN_PRIMARIES_DIFFERENT,
1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToCookieJar.FirstRun", 2, 1);
- histogram_helper()->ExpectUniqueSample(
+ histogram_tester()->ExpectUniqueSample(
"Signin.Reconciler.AddedToChrome.FirstRun", 0, 1);
}
diff --git a/chrome/browser/spellchecker/spellcheck_host_metrics_unittest.cc b/chrome/browser/spellchecker/spellcheck_host_metrics_unittest.cc
index 2a00597..9c458f5 100644
--- a/chrome/browser/spellchecker/spellcheck_host_metrics_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_host_metrics_unittest.cc
@@ -10,7 +10,7 @@
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/test/statistics_delta_reader.h"
+#include "base/test/histogram_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_WIN)
@@ -41,23 +41,19 @@ class SpellcheckHostMetricsTest : public testing::Test {
TEST_F(SpellcheckHostMetricsTest, RecordEnabledStats) {
const char kMetricName[] = "SpellCheck.Enabled";
- base::StatisticsDeltaReader statistics_delta_reader1;
+ base::HistogramTester histogram_tester1;
metrics()->RecordEnabledStats(false);
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader1.GetHistogramSamplesSinceCreation(kMetricName));
- EXPECT_EQ(1, samples->GetCount(0));
- EXPECT_EQ(0, samples->GetCount(1));
+ histogram_tester1.ExpectBucketCount(kMetricName, 0, 1);
+ histogram_tester1.ExpectBucketCount(kMetricName, 1, 0);
- base::StatisticsDeltaReader statistics_delta_reader2;
+ base::HistogramTester histogram_tester2;
metrics()->RecordEnabledStats(true);
- samples =
- statistics_delta_reader2.GetHistogramSamplesSinceCreation(kMetricName);
- EXPECT_EQ(0, samples->GetCount(0));
- EXPECT_EQ(1, samples->GetCount(1));
+ histogram_tester2.ExpectBucketCount(kMetricName, 0, 0);
+ histogram_tester2.ExpectBucketCount(kMetricName, 1, 1);
}
TEST_F(SpellcheckHostMetricsTest, CustomWordStats) {
@@ -72,63 +68,47 @@ TEST_F(SpellcheckHostMetricsTest, CustomWordStats) {
// available or because the histogram just isn't there: crbug.com/230534.
EXPECT_TRUE(base::StatisticsRecorder::IsActive());
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
SpellCheckHostMetrics::RecordCustomWordCountStats(23);
-
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- "SpellCheck.CustomWords"));
- EXPECT_EQ(23, samples->sum());
+ histogram_tester.ExpectBucketCount("SpellCheck.CustomWords", 23, 1);
}
TEST_F(SpellcheckHostMetricsTest, RecordWordCountsDiscardsDuplicates) {
// This test ensures that RecordWordCounts only records metrics if they
// have changed from the last invocation.
- const char* histogramName[] = {
- "SpellCheck.CheckedWords",
- "SpellCheck.MisspelledWords",
- "SpellCheck.ReplacedWords",
- "SpellCheck.UniqueWords",
- "SpellCheck.ShownSuggestions"
- };
+ const char* const histogram_names[] = {
+ "SpellCheck.CheckedWords", "SpellCheck.MisspelledWords",
+ "SpellCheck.ReplacedWords", "SpellCheck.UniqueWords",
+ "SpellCheck.ShownSuggestions"};
// Ensure all histograms exist.
metrics()->RecordCheckedWordStats(base::ASCIIToUTF16("test"), false);
RecordWordCountsForTesting();
- // Start the reader.
- base::StatisticsDeltaReader statistics_delta_reader;
+ // Create the tester, taking a snapshot of current histogram samples.
+ base::HistogramTester histogram_tester;
// Nothing changed, so this invocation should not affect any histograms.
RecordWordCountsForTesting();
// Get samples for all affected histograms.
- scoped_ptr<base::HistogramSamples> samples;
- for (size_t i = 0; i < arraysize(histogramName); ++i) {
- samples = statistics_delta_reader.GetHistogramSamplesSinceCreation(
- histogramName[i]);
- EXPECT_EQ(0, samples->TotalCount());
- }
+ for (size_t i = 0; i < arraysize(histogram_names); ++i)
+ histogram_tester.ExpectTotalCount(histogram_names[i], 0);
}
TEST_F(SpellcheckHostMetricsTest, RecordSpellingServiceStats) {
const char kMetricName[] = "SpellCheck.SpellingService.Enabled";
- base::StatisticsDeltaReader statistics_delta_reader1;
+ base::HistogramTester histogram_tester1;
metrics()->RecordSpellingServiceStats(false);
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader1.GetHistogramSamplesSinceCreation(kMetricName));
- EXPECT_EQ(1, samples->GetCount(0));
- EXPECT_EQ(0, samples->GetCount(1));
+ histogram_tester1.ExpectBucketCount(kMetricName, 0, 1);
+ histogram_tester1.ExpectBucketCount(kMetricName, 1, 0);
- base::StatisticsDeltaReader statistics_delta_reader2;
+ base::HistogramTester histogram_tester2;
metrics()->RecordSpellingServiceStats(true);
-
- samples =
- statistics_delta_reader2.GetHistogramSamplesSinceCreation(kMetricName);
- EXPECT_EQ(0, samples->GetCount(0));
- EXPECT_EQ(1, samples->GetCount(1));
+ histogram_tester2.ExpectBucketCount(kMetricName, 0, 0);
+ histogram_tester2.ExpectBucketCount(kMetricName, 1, 1);
}
diff --git a/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm
index 0637f24..0c88842 100644
--- a/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm
@@ -8,7 +8,7 @@
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/sys_string_conversions.h"
-#include "base/test/statistics_delta_reader.h"
+#include "base/test/histogram_tester.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#include "components/autofill/core/browser/password_generator.h"
#include "components/autofill/core/common/password_form.h"
@@ -81,24 +81,14 @@ TEST_F(PasswordGenerationBubbleControllerTest, Regenerate) {
}
TEST_F(PasswordGenerationBubbleControllerTest, UMALogging) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
[controller() showWindow:nil];
// Do nothing.
CloseController();
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(kHistogramName));
- EXPECT_EQ(
- 1,
- samples->GetCount(autofill::password_generation::IGNORE_FEATURE));
- EXPECT_EQ(
- 0,
- samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING));
- EXPECT_EQ(
- 0,
- samples->GetCount(
- autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD));
+ histogram_tester.ExpectUniqueSample(
+ kHistogramName, autofill::password_generation::IGNORE_FEATURE, 1);
SetUpController();
@@ -107,18 +97,11 @@ TEST_F(PasswordGenerationBubbleControllerTest, UMALogging) {
[controller() fillPassword:nil];
CloseController();
- samples =
- statistics_delta_reader.GetHistogramSamplesSinceCreation(kHistogramName);
- EXPECT_EQ(
- 1,
- samples->GetCount(autofill::password_generation::IGNORE_FEATURE));
- EXPECT_EQ(
- 1,
- samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING));
- EXPECT_EQ(
- 0,
- samples->GetCount(
- autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD));
+ histogram_tester.ExpectBucketCount(
+ kHistogramName, autofill::password_generation::IGNORE_FEATURE, 1);
+ histogram_tester.ExpectBucketCount(
+ kHistogramName, autofill::password_generation::ACCEPT_AFTER_EDITING, 1);
+ histogram_tester.ExpectTotalCount(kHistogramName, 2);
SetUpController();
@@ -126,16 +109,13 @@ TEST_F(PasswordGenerationBubbleControllerTest, UMALogging) {
[controller() fillPassword:nil];
CloseController();
- samples =
- statistics_delta_reader.GetHistogramSamplesSinceCreation(kHistogramName);
- EXPECT_EQ(
- 1,
- samples->GetCount(autofill::password_generation::IGNORE_FEATURE));
- EXPECT_EQ(
- 1,
- samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING));
- EXPECT_EQ(
- 1,
- samples->GetCount(
- autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD));
+ histogram_tester.ExpectBucketCount(
+ kHistogramName, autofill::password_generation::IGNORE_FEATURE, 1);
+ histogram_tester.ExpectBucketCount(
+ kHistogramName, autofill::password_generation::ACCEPT_AFTER_EDITING, 1);
+ histogram_tester.ExpectBucketCount(
+ kHistogramName,
+ autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD,
+ 1);
+ histogram_tester.ExpectTotalCount(kHistogramName, 3);
}
diff --git a/chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc b/chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc
index 69771f1..adb385b 100644
--- a/chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc
+++ b/chrome/browser/ui/passwords/manage_passwords_bubble_model_unittest.cc
@@ -5,7 +5,7 @@
#include "base/metrics/histogram_samples.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/test/statistics_delta_reader.h"
+#include "base/test/histogram_tester.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h"
@@ -85,7 +85,7 @@ TEST_F(ManagePasswordsBubbleModelTest, DefaultValues) {
}
TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutLogging) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
model_->OnBubbleHidden();
EXPECT_EQ(model_->dismissal_reason(),
password_manager::metrics_util::NOT_DISPLAYED);
@@ -93,13 +93,13 @@ TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutLogging) {
EXPECT_FALSE(controller()->never_saved_password());
scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
+ histogram_tester.GetHistogramSamplesSinceCreation(
kUIDismissalReasonMetric));
EXPECT_EQ(NULL, samples.get());
}
TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutInteraction) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
PretendPasswordWaiting();
model_->OnBubbleHidden();
EXPECT_EQ(model_->dismissal_reason(),
@@ -109,26 +109,14 @@ TEST_F(ManagePasswordsBubbleModelTest, CloseWithoutInteraction) {
EXPECT_FALSE(controller()->saved_password());
EXPECT_FALSE(controller()->never_saved_password());
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kUIDismissalReasonMetric));
- EXPECT_EQ(
- 1,
- samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
+ histogram_tester.ExpectUniqueSample(
+ kUIDismissalReasonMetric,
+ password_manager::metrics_util::NO_DIRECT_INTERACTION,
+ 1);
}
TEST_F(ManagePasswordsBubbleModelTest, ClickSave) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
PretendPasswordWaiting();
model_->OnSaveClicked();
model_->OnBubbleHidden();
@@ -138,26 +126,14 @@ TEST_F(ManagePasswordsBubbleModelTest, ClickSave) {
EXPECT_TRUE(controller()->saved_password());
EXPECT_FALSE(controller()->never_saved_password());
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kUIDismissalReasonMetric));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
- EXPECT_EQ(1, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
+ histogram_tester.ExpectUniqueSample(
+ kUIDismissalReasonMetric,
+ password_manager::metrics_util::CLICKED_SAVE,
+ 1);
}
TEST_F(ManagePasswordsBubbleModelTest, ClickNope) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
PretendPasswordWaiting();
model_->OnNopeClicked();
model_->OnBubbleHidden();
@@ -167,26 +143,14 @@ TEST_F(ManagePasswordsBubbleModelTest, ClickNope) {
EXPECT_FALSE(controller()->saved_password());
EXPECT_FALSE(controller()->never_saved_password());
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kUIDismissalReasonMetric));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
- EXPECT_EQ(1, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
+ histogram_tester.ExpectUniqueSample(
+ kUIDismissalReasonMetric,
+ password_manager::metrics_util::CLICKED_NOPE,
+ 1);
}
TEST_F(ManagePasswordsBubbleModelTest, ClickNever) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
PretendPasswordWaiting();
model_->OnNeverForThisSiteClicked();
model_->OnBubbleHidden();
@@ -196,26 +160,14 @@ TEST_F(ManagePasswordsBubbleModelTest, ClickNever) {
EXPECT_FALSE(controller()->saved_password());
EXPECT_TRUE(controller()->never_saved_password());
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kUIDismissalReasonMetric));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
- EXPECT_EQ(1,
- samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
+ histogram_tester.ExpectUniqueSample(
+ kUIDismissalReasonMetric,
+ password_manager::metrics_util::CLICKED_NEVER,
+ 1);
}
TEST_F(ManagePasswordsBubbleModelTest, ClickManage) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
PretendManagingPasswords();
model_->OnManageLinkClicked();
model_->OnBubbleHidden();
@@ -225,26 +177,14 @@ TEST_F(ManagePasswordsBubbleModelTest, ClickManage) {
EXPECT_FALSE(controller()->saved_password());
EXPECT_FALSE(controller()->never_saved_password());
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kUIDismissalReasonMetric));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
- EXPECT_EQ(1,
- samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
+ histogram_tester.ExpectUniqueSample(
+ kUIDismissalReasonMetric,
+ password_manager::metrics_util::CLICKED_MANAGE,
+ 1);
}
TEST_F(ManagePasswordsBubbleModelTest, ClickDone) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
PretendManagingPasswords();
model_->OnDoneClicked();
model_->OnBubbleHidden();
@@ -254,26 +194,14 @@ TEST_F(ManagePasswordsBubbleModelTest, ClickDone) {
EXPECT_FALSE(controller()->saved_password());
EXPECT_FALSE(controller()->never_saved_password());
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kUIDismissalReasonMetric));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
- EXPECT_EQ(1, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
+ histogram_tester.ExpectUniqueSample(
+ kUIDismissalReasonMetric,
+ password_manager::metrics_util::CLICKED_DONE,
+ 1);
}
TEST_F(ManagePasswordsBubbleModelTest, ClickUnblacklist) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
PretendBlacklisted();
model_->OnUnblacklistClicked();
model_->OnBubbleHidden();
@@ -283,22 +211,10 @@ TEST_F(ManagePasswordsBubbleModelTest, ClickUnblacklist) {
EXPECT_FALSE(controller()->saved_password());
EXPECT_FALSE(controller()->never_saved_password());
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kUIDismissalReasonMetric));
- EXPECT_EQ(
- 0,
- samples->GetCount(password_manager::metrics_util::NO_DIRECT_INTERACTION));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_SAVE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_NOPE));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_NEVER));
- EXPECT_EQ(0,
- samples->GetCount(password_manager::metrics_util::CLICKED_MANAGE));
- EXPECT_EQ(0, samples->GetCount(password_manager::metrics_util::CLICKED_DONE));
- EXPECT_EQ(
- 1,
- samples->GetCount(password_manager::metrics_util::CLICKED_UNBLACKLIST));
+ histogram_tester.ExpectUniqueSample(
+ kUIDismissalReasonMetric,
+ password_manager::metrics_util::CLICKED_UNBLACKLIST,
+ 1);
}
TEST_F(ManagePasswordsBubbleModelTest, PasswordPendingUserDecision) {
diff --git a/chrome/browser/ui/passwords/manage_passwords_ui_controller_unittest.cc b/chrome/browser/ui/passwords/manage_passwords_ui_controller_unittest.cc
index a92d977..0aa2a1e 100644
--- a/chrome/browser/ui/passwords/manage_passwords_ui_controller_unittest.cc
+++ b/chrome/browser/ui/passwords/manage_passwords_ui_controller_unittest.cc
@@ -2,10 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/metrics/histogram_samples.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/test/statistics_delta_reader.h"
#include "base/time/time.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
diff --git a/chrome/browser/ui/views/passwords/manage_passwords_view_test.cc b/chrome/browser/ui/views/passwords/manage_passwords_view_test.cc
index da4401e..618217d 100644
--- a/chrome/browser/ui/views/passwords/manage_passwords_view_test.cc
+++ b/chrome/browser/ui/views/passwords/manage_passwords_view_test.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/ui/views/passwords/manage_passwords_view_test.h"
-#include "base/test/statistics_delta_reader.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
@@ -104,6 +103,6 @@ base::HistogramSamples* ManagePasswordsViewTest::GetSamples(
const char* histogram) {
// Ensure that everything has been properly recorded before pulling samples.
content::RunAllPendingInMessageLoop();
- return statistics_reader_.GetHistogramSamplesSinceCreation(
- histogram).release();
+ return histogram_tester_.GetHistogramSamplesSinceCreation(histogram)
+ .release();
}
diff --git a/chrome/browser/ui/views/passwords/manage_passwords_view_test.h b/chrome/browser/ui/views/passwords/manage_passwords_view_test.h
index 6f1a49c..518674b 100644
--- a/chrome/browser/ui/views/passwords/manage_passwords_view_test.h
+++ b/chrome/browser/ui/views/passwords/manage_passwords_view_test.h
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_VIEW_TEST_H_
#include "base/metrics/histogram_samples.h"
-#include "base/test/statistics_delta_reader.h"
+#include "base/test/histogram_tester.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/autofill/core/common/password_form.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -52,7 +52,7 @@ class ManagePasswordsViewTest : public InProcessBrowserTest {
private:
autofill::PasswordForm test_form_;
- base::StatisticsDeltaReader statistics_reader_;
+ base::HistogramTester histogram_tester_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsViewTest);
};
diff --git a/chrome/browser/ui/views/profiles/profile_chooser_view_browsertest.cc b/chrome/browser/ui/views/profiles/profile_chooser_view_browsertest.cc
index ce4fec8..19dc37c 100644
--- a/chrome/browser/ui/views/profiles/profile_chooser_view_browsertest.cc
+++ b/chrome/browser/ui/views/profiles/profile_chooser_view_browsertest.cc
@@ -8,6 +8,7 @@
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/histogram_tester.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
@@ -25,7 +26,6 @@
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
-#include "chrome/test/base/uma_histogram_helper.h"
#include "components/signin/core/common/profile_management_switches.h"
#include "content/public/test/test_utils.h"
#include "ui/views/controls/button/label_button.h"
@@ -86,7 +86,6 @@ void ProfileChooserViewBrowserTest::OpenProfileChooserView() {
// TODO(mlerman): Re-enable the test to MAYBE_ViewProfileUMA once there is a
// launch plan for EnableAccountConsistency.
IN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, DISABLED_ViewProfileUMA) {
- // If multiprofile mode is not enabled, you can't switch between profiles.
if (!profiles::IsMultipleProfilesEnabled())
return;
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 2d4e59b..3648fa2 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -194,8 +194,6 @@
'test/base/tracing.h',
'test/base/ui_test_utils.cc',
'test/base/ui_test_utils.h',
- 'test/base/uma_histogram_helper.cc',
- 'test/base/uma_histogram_helper.h',
'test/logging/win/file_logger.cc',
'test/logging/win/file_logger.h',
'test/logging/win/log_file_printer.cc',
diff --git a/chrome/renderer/net/net_error_helper_core_unittest.cc b/chrome/renderer/net/net_error_helper_core_unittest.cc
index eee80f7..3ff1dee 100644
--- a/chrome/renderer/net/net_error_helper_core_unittest.cc
+++ b/chrome/renderer/net/net_error_helper_core_unittest.cc
@@ -13,11 +13,11 @@
#include "base/logging.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/stringprintf.h"
+#include "base/test/histogram_tester.h"
#include "base/timer/mock_timer.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "chrome/common/net/net_error_info.h"
-#include "chrome/test/base/uma_histogram_helper.h"
#include "content/public/common/url_constants.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -2230,37 +2230,11 @@ TEST_F(NetErrorHelperCoreAutoReloadTest, ShownWhileNotReloading) {
EXPECT_TRUE(timer()->IsRunning());
}
-// Return the count for the named histogram, or 0 if there is no histogram by
-// that name. This function is error-tolerant because histograms that have no
-// data points may not be registered, and the unit tests below still need to be
-// able to check that they haven't changed.
-int GetHistogramCount(const char *name) {
- base::HistogramBase* histogram =
- base::StatisticsRecorder::FindHistogram(name);
- if (!histogram)
- return 0;
- scoped_ptr<base::HistogramSamples> samples = histogram->SnapshotSamples();
- if (!samples)
- return 0;
- return samples->TotalCount();
-}
-
-void ExpectHistogramDelta(const char *name, int old_count, int delta) {
- int new_count = GetHistogramCount(name);
- EXPECT_EQ(old_count + delta, new_count) << "For histogram " << name;
-}
-
class NetErrorHelperCoreHistogramTest
: public NetErrorHelperCoreAutoReloadTest {
public:
virtual void SetUp() OVERRIDE {
NetErrorHelperCoreAutoReloadTest::SetUp();
- StoreOldCounts();
- }
-
- void ExpectDelta(const char *name, int delta) {
- DCHECK(old_counts_.count(name) == 1);
- ExpectHistogramDelta(name, old_counts_[name], delta);
}
static const char kCountAtStop[];
@@ -2269,15 +2243,8 @@ class NetErrorHelperCoreHistogramTest
static const char kErrorAtSuccess[];
static const char kErrorAtFirstSuccess[];
- private:
- void StoreOldCounts() {
- for (size_t i = 0; kHistogramNames[i]; i++)
- old_counts_[kHistogramNames[i]] = GetHistogramCount(kHistogramNames[i]);
- }
-
- static const char *kHistogramNames[];
-
- std::map<std::string, int> old_counts_;
+ protected:
+ base::HistogramTester histogram_tester_;
};
const char NetErrorHelperCoreHistogramTest::kCountAtStop[] =
@@ -2290,14 +2257,6 @@ const char NetErrorHelperCoreHistogramTest::kErrorAtSuccess[] =
"Net.AutoReload.ErrorAtSuccess";
const char NetErrorHelperCoreHistogramTest::kErrorAtFirstSuccess[] =
"Net.AutoReload.ErrorAtFirstSuccess";
-const char *NetErrorHelperCoreHistogramTest::kHistogramNames[] = {
- kCountAtStop,
- kErrorAtStop,
- kCountAtSuccess,
- kErrorAtSuccess,
- kErrorAtFirstSuccess,
- NULL
-};
// Test that the success histograms are updated when auto-reload succeeds at the
// first attempt, and that the failure histograms are not updated.
@@ -2308,11 +2267,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, SuccessAtFirstAttempt) {
// All of CountAtSuccess, ErrorAtSuccess, and ErrorAtFirstSuccess should
// reflect this successful load. The failure histograms should be unchanged.
- ExpectDelta(kCountAtSuccess, 1);
- ExpectDelta(kErrorAtSuccess, 1);
- ExpectDelta(kErrorAtFirstSuccess, 1);
- ExpectDelta(kCountAtStop, 0);
- ExpectDelta(kErrorAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 0);
}
// Test that the success histograms are updated when auto-reload succeeds but
@@ -2329,11 +2288,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, SuccessAtSecondAttempt) {
// CountAtSuccess and ErrorAtSuccess should reflect this successful load, but
// not ErrorAtFirstSuccess since it wasn't a first success.
- ExpectDelta(kCountAtSuccess, 1);
- ExpectDelta(kErrorAtSuccess, 1);
- ExpectDelta(kErrorAtFirstSuccess, 0);
- ExpectDelta(kCountAtStop, 0);
- ExpectDelta(kErrorAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 0);
}
// Test that a user stop (caused by the user pressing the 'Stop' button)
@@ -2348,11 +2307,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, UserStop) {
core()->OnStop();
// CountAtStop and ErrorAtStop should reflect the failure.
- ExpectDelta(kCountAtSuccess, 0);
- ExpectDelta(kErrorAtSuccess, 0);
- ExpectDelta(kErrorAtFirstSuccess, 0);
- ExpectDelta(kCountAtStop, 1);
- ExpectDelta(kErrorAtStop, 1);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 1);
}
// Test that a user stop (caused by the user pressing the 'Stop' button)
@@ -2366,11 +2325,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, OtherPageLoaded) {
NetErrorHelperCore::NON_ERROR_PAGE);
core()->OnStop();
- ExpectDelta(kCountAtSuccess, 0);
- ExpectDelta(kErrorAtSuccess, 0);
- ExpectDelta(kErrorAtFirstSuccess, 0);
- ExpectDelta(kCountAtStop, 1);
- ExpectDelta(kErrorAtStop, 1);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 1);
}
// Test that a commit of a different URL (caused by the user navigating to a
@@ -2386,11 +2345,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, OtherPageLoadedAfterTimerFires) {
kTestUrl);
core()->OnFinishLoad(NetErrorHelperCore::MAIN_FRAME);
- ExpectDelta(kCountAtSuccess, 0);
- ExpectDelta(kErrorAtSuccess, 0);
- ExpectDelta(kErrorAtFirstSuccess, 0);
- ExpectDelta(kCountAtStop, 1);
- ExpectDelta(kErrorAtStop, 1);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 1);
}
// Test that a commit of the same URL with an auto-reload attempt in flight
@@ -2400,11 +2359,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, SamePageLoadedAfterTimerFires) {
timer()->Fire();
DoSuccessLoad();
- ExpectDelta(kCountAtSuccess, 1);
- ExpectDelta(kErrorAtSuccess, 1);
- ExpectDelta(kErrorAtFirstSuccess, 1);
- ExpectDelta(kCountAtStop, 0);
- ExpectDelta(kErrorAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 0);
}
TEST_F(NetErrorHelperCoreHistogramTest, SamePageLoadedAfterLoadStarts) {
@@ -2416,11 +2375,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, SamePageLoadedAfterLoadStarts) {
// User does a manual reload
DoSuccessLoad();
- ExpectDelta(kCountAtSuccess, 1);
- ExpectDelta(kErrorAtSuccess, 1);
- ExpectDelta(kErrorAtFirstSuccess, 1);
- ExpectDelta(kCountAtStop, 0);
- ExpectDelta(kErrorAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 1);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 0);
}
// In this test case, the user presses the reload button manually after an
@@ -2434,11 +2393,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, ErrorPageLoadedAfterTimerFires) {
default_url()));
DoErrorLoad(net::ERR_CONNECTION_RESET);
- ExpectDelta(kCountAtSuccess, 0);
- ExpectDelta(kErrorAtSuccess, 0);
- ExpectDelta(kErrorAtFirstSuccess, 0);
- ExpectDelta(kCountAtStop, 0);
- ExpectDelta(kErrorAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 0);
}
TEST_F(NetErrorHelperCoreHistogramTest, SuccessPageLoadedBeforeTimerFires) {
@@ -2448,11 +2407,11 @@ TEST_F(NetErrorHelperCoreHistogramTest, SuccessPageLoadedBeforeTimerFires) {
core()->OnCommitLoad(NetErrorHelperCore::MAIN_FRAME,
GURL(kFailedHttpsUrl));
- ExpectDelta(kCountAtSuccess, 0);
- ExpectDelta(kErrorAtSuccess, 0);
- ExpectDelta(kErrorAtFirstSuccess, 0);
- ExpectDelta(kCountAtStop, 1);
- ExpectDelta(kErrorAtStop, 1);
+ histogram_tester_.ExpectTotalCount(kCountAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kErrorAtFirstSuccess, 0);
+ histogram_tester_.ExpectTotalCount(kCountAtStop, 1);
+ histogram_tester_.ExpectTotalCount(kErrorAtStop, 1);
}
diff --git a/chrome/test/base/uma_histogram_helper.cc b/chrome/test/base/uma_histogram_helper.cc
deleted file mode 100644
index 21ff6f7..0000000
--- a/chrome/test/base/uma_histogram_helper.cc
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/test/base/uma_histogram_helper.h"
-
-#include "base/bind.h"
-#include "base/metrics/statistics_recorder.h"
-#include "base/test/test_timeouts.h"
-#include "chrome/test/base/ui_test_utils.h"
-#include "content/public/browser/histogram_fetcher.h"
-
-UMAHistogramHelper::UMAHistogramHelper() {
- base::StatisticsRecorder::Initialize();
-}
-
-UMAHistogramHelper::~UMAHistogramHelper() {
-}
-
-void UMAHistogramHelper::PrepareSnapshot(const char* const histogram_names[],
- size_t num_histograms) {
- for (size_t i = 0; i < num_histograms; ++i) {
- std::string histogram_name = histogram_names[i];
-
- base::HistogramBase* histogram =
- base::StatisticsRecorder::FindHistogram(histogram_name);
- // If there is no histogram present, then don't record a snapshot. The logic
- // in the Expect* methods will act to treat no histogram equivalent to
- // samples with zeros.
- if (histogram) {
- histogram_snapshots[histogram_name] =
- make_linked_ptr(histogram->SnapshotSamples().release());
- }
- }
-}
-
-void UMAHistogramHelper::Fetch() {
- base::Closure callback = base::Bind(&UMAHistogramHelper::FetchCallback,
- base::Unretained(this));
-
- content::FetchHistogramsAsynchronously(
- base::MessageLoop::current(),
- callback,
- // If this call times out, it means that a child process is not
- // responding, which is something we should not ignore. The timeout is
- // set to be longer than the normal browser test timeout so that it will
- // be prempted by the normal timeout.
- TestTimeouts::action_max_timeout() * 2);
- content::RunMessageLoop();
-}
-
-void UMAHistogramHelper::ExpectUniqueSample(
- const std::string& name,
- base::HistogramBase::Sample sample,
- base::HistogramBase::Count expected_count) {
- base::HistogramBase* histogram =
- base::StatisticsRecorder::FindHistogram(name);
- EXPECT_NE(static_cast<base::HistogramBase*>(NULL), histogram)
- << "Histogram \"" << name << "\" does not exist.";
-
- if (histogram) {
- scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
- CheckBucketCount(name, sample, expected_count, *samples);
- CheckTotalCount(name, expected_count, *samples);
- }
-}
-
-void UMAHistogramHelper::ExpectBucketCount(
- const std::string& name,
- base::HistogramBase::Sample sample,
- base::HistogramBase::Count expected_count) {
- base::HistogramBase* histogram =
- base::StatisticsRecorder::FindHistogram(name);
- EXPECT_NE(static_cast<base::HistogramBase*>(NULL), histogram)
- << "Histogram \"" << name << "\" does not exist.";
-
- if (histogram) {
- scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
- CheckBucketCount(name, sample, expected_count, *samples);
- }
-}
-
-void UMAHistogramHelper::ExpectTotalCount(
- const std::string& name,
- base::HistogramBase::Count count) {
- base::HistogramBase* histogram =
- base::StatisticsRecorder::FindHistogram(name);
- if (histogram) {
- scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples());
- CheckTotalCount(name, count, *samples);
- } else {
- // No histogram means there were zero samples.
- EXPECT_EQ(count, 0) << "Histogram \"" << name << "\" does not exist.";
- }
-}
-
-void UMAHistogramHelper::FetchCallback() {
- base::MessageLoopForUI::current()->Quit();
-}
-
-void UMAHistogramHelper::CheckBucketCount(
- const std::string& name,
- base::HistogramBase::Sample sample,
- base::HistogramBase::Count expected_count,
- base::HistogramSamples& samples) {
- int actual_count = samples.GetCount(sample);
- if (histogram_snapshots.count(name))
- actual_count -= histogram_snapshots[name]->GetCount(sample);
- EXPECT_EQ(expected_count, actual_count)
- << "Histogram \"" << name
- << "\" does not have the right number of samples (" << expected_count
- << ") in the expected bucket (" << sample << "). It has (" << actual_count
- << ").";
-}
-
-void UMAHistogramHelper::CheckTotalCount(
- const std::string& name,
- base::HistogramBase::Count expected_count,
- base::HistogramSamples& samples) {
- int actual_count = samples.TotalCount();
- if (histogram_snapshots.count(name))
- actual_count -= histogram_snapshots[name]->TotalCount();
- EXPECT_EQ(expected_count, actual_count)
- << "Histogram \"" << name
- << "\" does not have the right total number of samples ("
- << expected_count << "). It has (" << actual_count << ").";
-}
diff --git a/chrome/test/base/uma_histogram_helper.h b/chrome/test/base/uma_histogram_helper.h
deleted file mode 100644
index 2feb4d5..0000000
--- a/chrome/test/base/uma_histogram_helper.h
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_
-#define CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_
-
-#include "base/memory/linked_ptr.h"
-#include "base/metrics/histogram.h"
-#include "base/metrics/histogram_base.h"
-#include "base/metrics/histogram_samples.h"
-
-// UMAHistogramHelper provides a simple interface for examining UMA histograms.
-// Tests can use this interface to verify that UMA data is getting logged as
-// intended.
-class UMAHistogramHelper {
- public:
- // UMAHistogramHelper should be created before the execution of the test case.
- UMAHistogramHelper();
-
- ~UMAHistogramHelper();
-
- // Parameters should be string literals of all histograms to snapshot.
- // Call this before executing the test code. This method can be called
- // multiple times. The existing snapshots are preserved, except when one of
- // the |histogram_names| was previously passed as a parameter, then a new
- // snapshot will replace the existing one.
- void PrepareSnapshot(const char* const histogram_names[],
- size_t num_histograms);
-
- // Each child process may have its own histogram data, make sure this data
- // gets accumulated into the browser process before we examine the histograms.
- void Fetch();
-
- // We know the exact number of samples in a bucket, and that no other bucket
- // should have samples. If |PrepareSnapshot| was called for the histogram
- // named |name| then the |expected_count| is the diff from the snapshot.
- void ExpectUniqueSample(const std::string& name,
- base::HistogramBase::Sample sample,
- base::HistogramBase::Count expected_count);
-
- // We know the exact number of samples in a bucket, but other buckets may
- // have samples as well. If |PrepareSnapshot| was called for histogram named
- // |name| then the |expected_count| is the diff from the snapshot.
- void ExpectBucketCount(const std::string& name,
- base::HistogramBase::Sample sample,
- base::HistogramBase::Count expected_count);
-
- // We don't know the values of the samples, but we know how many there are. If
- // |PrepareSnapshot| was called for |name| histogram, then the
- // |count| is the diff from the snapshot.
- void ExpectTotalCount(const std::string& name,
- base::HistogramBase::Count count);
-
- private:
- void FetchCallback();
-
- void CheckBucketCount(const std::string& name,
- base::HistogramBase::Sample sample,
- base::Histogram::Count expected_count,
- base::HistogramSamples& samples);
-
- void CheckTotalCount(const std::string& name,
- base::Histogram::Count expected_count,
- base::HistogramSamples& samples);
-
- DISALLOW_COPY_AND_ASSIGN(UMAHistogramHelper);
-
- // The map from histogram names to their snapshots
- std::map<std::string, linked_ptr<base::HistogramSamples> >
- histogram_snapshots;
-};
-
-#endif // CHROME_TEST_BASE_UMA_HISTOGRAM_HELPER_H_
diff --git a/chrome/test/nacl/nacl_browsertest_uma.cc b/chrome/test/nacl/nacl_browsertest_uma.cc
index f7ee54b..e04670f 100644
--- a/chrome/test/nacl/nacl_browsertest_uma.cc
+++ b/chrome/test/nacl/nacl_browsertest_uma.cc
@@ -2,22 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/test/base/uma_histogram_helper.h"
+#include "base/test/histogram_tester.h"
#include "chrome/test/nacl/nacl_browsertest_util.h"
#include "components/nacl/browser/nacl_browser.h"
+#include "content/public/test/browser_test_utils.h"
#include "native_client/src/trusted/service_runtime/nacl_error_code.h"
#include "ppapi/c/private/ppb_nacl_private.h"
namespace {
NACL_BROWSER_TEST_F(NaClBrowserTest, SuccessfulLoadUMA, {
+ base::HistogramTester histograms;
// Load a NaCl module to generate UMA data.
RunLoadTest(FILE_PATH_LITERAL("nacl_load_test.html"));
// Make sure histograms from child processes have been accumulated in the
// browser brocess.
- UMAHistogramHelper histograms;
- histograms.Fetch();
+ content::FetchHistogramsFromChildProcesses();
// Did the plugin report success?
histograms.ExpectUniqueSample("NaCl.LoadStatus.Plugin",
@@ -88,6 +89,7 @@ class NaClBrowserTestNewlibVcacheExtension:
IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibVcacheExtension,
ValidationCacheOfMainNexe) {
+ base::HistogramTester histograms;
// Hardcoded extension AppID that corresponds to the hardcoded
// public key in the manifest.json file. We need to load the extension
// nexe from the same origin, so we can't just try to load the extension
@@ -98,9 +100,8 @@ IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibVcacheExtension,
RunNaClIntegrationTest(full_url, true);
// Make sure histograms from child processes have been accumulated in the
- // browser process.
- UMAHistogramHelper histograms;
- histograms.Fetch();
+ // browser brocess.
+ content::FetchHistogramsFromChildProcesses();
// Should have received 2 validation queries (one for IRT and one for NEXE),
// and responded with a miss.
histograms.ExpectBucketCount("NaCl.ValidationCache.Query",
@@ -113,7 +114,7 @@ IN_PROC_BROWSER_TEST_F(NaClBrowserTestNewlibVcacheExtension,
// Load it again to hit the cache.
RunNaClIntegrationTest(full_url, true);
- histograms.Fetch();
+ content::FetchHistogramsFromChildProcesses();
// Should have received 2 more validation queries later (IRT and NEXE),
// and responded with a hit.
histograms.ExpectBucketCount("NaCl.ValidationCache.Query",
@@ -134,6 +135,9 @@ class NaClBrowserTestGLibcVcacheExtension:
IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibcVcacheExtension,
ValidationCacheOfMainNexe) {
+ // Make sure histograms from child processes have been accumulated in the
+ // browser process.
+ base::HistogramTester histograms;
// Hardcoded extension AppID that corresponds to the hardcoded
// public key in the manifest.json file. We need to load the extension
// nexe from the same origin, so we can't just try to load the extension
@@ -143,10 +147,6 @@ IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibcVcacheExtension,
FILE_PATH_LITERAL("extension_validation_cache.html");
RunNaClIntegrationTest(full_url, true);
- // Make sure histograms from child processes have been accumulated in the
- // browser process.
- UMAHistogramHelper histograms;
- histograms.Fetch();
// Should have received 9 validation queries, which respond with misses:
// - the IRT
// - ld.so (the initial nexe)
@@ -167,7 +167,6 @@ IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibcVcacheExtension,
// Load it again to hit the cache.
RunNaClIntegrationTest(full_url, true);
- histograms.Fetch();
// Should have received 9 more validation queries and responded with hits.
histograms.ExpectBucketCount("NaCl.ValidationCache.Query",
nacl::NaClBrowser::CACHE_HIT, 9);
@@ -178,11 +177,11 @@ IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibcVcacheExtension,
// Test that validation for the 2 PNaCl translator nexes can be cached.
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl,
ValidationCacheOfTranslatorNexes) {
+ base::HistogramTester histograms;
// Run a load test w/ one pexe cache identity.
RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));
- UMAHistogramHelper histograms;
- histograms.Fetch();
+ content::FetchHistogramsFromChildProcesses();
// Should have received 3 validation queries:
// - One for IRT for actual application
// - Two for two translator nexes
diff --git a/components/suggestions/blacklist_store_unittest.cc b/components/suggestions/blacklist_store_unittest.cc
index 399875e..63d0611 100644
--- a/components/suggestions/blacklist_store_unittest.cc
+++ b/components/suggestions/blacklist_store_unittest.cc
@@ -8,9 +8,8 @@
#include <string>
#include "base/memory/scoped_ptr.h"
-#include "base/metrics/histogram_samples.h"
-#include "base/metrics/statistics_recorder.h"
-#include "base/test/statistics_delta_reader.h"
+
+#include "base/test/histogram_tester.h"
#include "components/pref_registry/testing_pref_service_syncable.h"
#include "components/suggestions/proto/suggestions.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -133,16 +132,14 @@ TEST_F(BlacklistStoreTest, GetFirstUrlFromBlacklist) {
}
TEST_F(BlacklistStoreTest, LogsBlacklistSize) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
// Create a first store - blacklist is empty at this point.
scoped_ptr<BlacklistStore> blacklist_store(
new BlacklistStore(pref_service()));
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- "Suggestions.LocalBlacklistSize"));
- EXPECT_EQ(1, samples->TotalCount());
- EXPECT_EQ(1, samples->GetCount(0));
+
+ histogram_tester.ExpectTotalCount("Suggestions.LocalBlacklistSize", 1);
+ histogram_tester.ExpectUniqueSample("Suggestions.LocalBlacklistSize", 0, 1);
// Add some content to the blacklist.
EXPECT_TRUE(blacklist_store->BlacklistUrl(GURL(kTestUrlA)));
@@ -150,11 +147,10 @@ TEST_F(BlacklistStoreTest, LogsBlacklistSize) {
// Create a new BlacklistStore and verify the counts.
blacklist_store.reset(new BlacklistStore(pref_service()));
- samples = statistics_delta_reader.GetHistogramSamplesSinceCreation(
- "Suggestions.LocalBlacklistSize");
- EXPECT_EQ(2, samples->TotalCount());
- EXPECT_EQ(1, samples->GetCount(0));
- EXPECT_EQ(1, samples->GetCount(2));
+
+ histogram_tester.ExpectTotalCount("Suggestions.LocalBlacklistSize", 2);
+ histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 0, 1);
+ histogram_tester.ExpectBucketCount("Suggestions.LocalBlacklistSize", 2, 1);
}
} // namespace suggestions
diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc
index 079312c..d28b8aa 100644
--- a/content/public/test/browser_test_utils.cc
+++ b/content/public/test/browser_test_utils.cc
@@ -4,6 +4,7 @@
#include "content/public/test/browser_test_utils.h"
+#include "base/bind.h"
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/path_service.h"
@@ -19,6 +20,7 @@
#include "content/common/input/synthetic_web_input_event_builders.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/dom_operation_notification_details.h"
+#include "content/public/browser/histogram_fetcher.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h"
@@ -586,6 +588,20 @@ bool SetCookie(BrowserContext* browser_context,
return result;
}
+void FetchHistogramsFromChildProcesses() {
+ scoped_refptr<content::MessageLoopRunner> runner = new MessageLoopRunner;
+
+ FetchHistogramsAsynchronously(
+ base::MessageLoop::current(),
+ runner->QuitClosure(),
+ // If this call times out, it means that a child process is not
+ // responding, which is something we should not ignore. The timeout is
+ // set to be longer than the normal browser test timeout so that it will
+ // be prempted by the normal timeout.
+ TestTimeouts::action_max_timeout());
+ runner->Run();
+}
+
TitleWatcher::TitleWatcher(WebContents* web_contents,
const base::string16& expected_title)
: WebContentsObserver(web_contents),
diff --git a/content/public/test/browser_test_utils.h b/content/public/test/browser_test_utils.h
index 4c64501..8880fda 100644
--- a/content/public/test/browser_test_utils.h
+++ b/content/public/test/browser_test_utils.h
@@ -188,6 +188,10 @@ bool SetCookie(BrowserContext* browser_context,
const GURL& url,
const std::string& value);
+// Fetch the histograms data from other processes. This should be called after
+// the test code has been executed but before performing assertions.
+void FetchHistogramsFromChildProcesses();
+
// Watches title changes on a WebContents, blocking until an expected title is
// set.
class TitleWatcher : public WebContentsObserver {
diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc
index 87f8116..86e503c 100644
--- a/net/spdy/spdy_session_unittest.cc
+++ b/net/spdy/spdy_session_unittest.cc
@@ -9,7 +9,7 @@
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
-#include "base/test/statistics_delta_reader.h"
+#include "base/test/histogram_tester.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_log_unittest.h"
@@ -1792,25 +1792,26 @@ TEST_P(SpdySessionTest, SynCompressionHistograms) {
EXPECT_TRUE(spdy_stream->HasUrlFromHeaders());
// Write request headers & capture resulting histogram update.
- base::StatisticsDeltaReader statistics_delta_reader;
- data.RunFor(1);
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- "Net.SpdySynStreamCompressionPercentage"));
+ base::HistogramTester histogram_tester;
+ data.RunFor(1);
// Regression test of compression performance under the request fixture.
switch (spdy_util_.spdy_version()) {
case SPDY2:
- EXPECT_EQ(samples->GetCount(0), 1);
+ histogram_tester.ExpectBucketCount(
+ "Net.SpdySynStreamCompressionPercentage", 0, 1);
break;
case SPDY3:
- EXPECT_EQ(samples->GetCount(30), 1);
+ histogram_tester.ExpectBucketCount(
+ "Net.SpdySynStreamCompressionPercentage", 30, 1);
break;
case SPDY4:
- EXPECT_EQ(samples->GetCount(82), 1);
+ histogram_tester.ExpectBucketCount(
+ "Net.SpdySynStreamCompressionPercentage", 82, 1);
break;
case SPDY5:
- EXPECT_EQ(samples->GetCount(82), 1);
+ histogram_tester.ExpectBucketCount(
+ "Net.SpdySynStreamCompressionPercentage", 82, 1);
break;
default:
NOTREACHED();
diff --git a/net/url_request/url_request_throttler_unittest.cc b/net/url_request/url_request_throttler_unittest.cc
index 9ae9c7b..4d08cbc 100644
--- a/net/url_request/url_request_throttler_unittest.cc
+++ b/net/url_request/url_request_throttler_unittest.cc
@@ -10,7 +10,7 @@
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
-#include "base/test/statistics_delta_reader.h"
+#include "base/test/histogram_tester.h"
#include "base/time/time.h"
#include "net/base/load_flags.h"
#include "net/base/request_priority.h"
@@ -209,7 +209,7 @@ TEST_F(URLRequestThrottlerEntryTest, CanThrottleRequest) {
}
TEST_F(URLRequestThrottlerEntryTest, InterfaceDuringExponentialBackoff) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
entry_->set_exponential_backoff_release_time(
entry_->fake_time_now_ + TimeDelta::FromMilliseconds(1));
EXPECT_TRUE(entry_->ShouldRejectRequest(request_,
@@ -220,15 +220,12 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceDuringExponentialBackoff) {
EXPECT_FALSE(entry_->ShouldRejectRequest(request_,
context_.network_delegate()));
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kRequestThrottledHistogramName));
- ASSERT_EQ(1, samples->GetCount(0));
- ASSERT_EQ(1, samples->GetCount(1));
+ histogram_tester.ExpectBucketCount(kRequestThrottledHistogramName, 0, 1);
+ histogram_tester.ExpectBucketCount(kRequestThrottledHistogramName, 1, 1);
}
TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) {
- base::StatisticsDeltaReader statistics_delta_reader;
+ base::HistogramTester histogram_tester;
entry_->set_exponential_backoff_release_time(entry_->fake_time_now_);
EXPECT_FALSE(entry_->ShouldRejectRequest(request_,
context_.network_delegate()));
@@ -237,11 +234,8 @@ TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) {
EXPECT_FALSE(entry_->ShouldRejectRequest(request_,
context_.network_delegate()));
- scoped_ptr<base::HistogramSamples> samples(
- statistics_delta_reader.GetHistogramSamplesSinceCreation(
- kRequestThrottledHistogramName));
- ASSERT_EQ(2, samples->GetCount(0));
- ASSERT_EQ(0, samples->GetCount(1));
+ histogram_tester.ExpectBucketCount(kRequestThrottledHistogramName, 0, 2);
+ histogram_tester.ExpectBucketCount(kRequestThrottledHistogramName, 1, 0);
}
TEST_F(URLRequestThrottlerEntryTest, InterfaceUpdateFailure) {