Index: testing/perf/scoped_histogram_result_printer_unittest.cc |
diff --git a/testing/perf/scoped_histogram_result_printer_unittest.cc b/testing/perf/scoped_histogram_result_printer_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b84adae88beb6cc34d87d44fac80aa706f6a8b35 |
--- /dev/null |
+++ b/testing/perf/scoped_histogram_result_printer_unittest.cc |
@@ -0,0 +1,90 @@ |
+// Copyright (c) 2016 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 "testing/perf/scoped_histogram_result_printer.h" |
+ |
+#include "base/metrics/histogram_macros.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest-spi.h" |
+ |
+namespace { |
+using testing::_; |
+ |
+const char kFakeHistogram[] = "FakeHistogramName"; |
+const char kFakeMeasurement[] = "FakeMeasurement"; |
+ |
+struct MockedPrinter { |
+ MOCK_METHOD2(PrintHistogram, |
+ void(const base::HistogramSamples&, const std::string&)); |
+ perf_test::HistogramPrinter GetCallback() { |
+ return base::Bind(&MockedPrinter::PrintHistogram, base::Unretained(this)); |
+ } |
+}; |
+ |
+void StrictIsNotFoundTest() { |
+ MockedPrinter perf_printer; |
+ EXPECT_CALL(perf_printer, PrintHistogram(_, _)).Times(0); |
+ |
+ perf_test::ScopedHistogramResultPrinter scoped_printer( |
+ perf_printer.GetCallback()); |
+ |
+ scoped_printer.AddHistogramStrict(kFakeHistogram, kFakeMeasurement); |
+} |
+ |
+void NothingIsAddedToStrictTest() { |
+ MockedPrinter perf_printer; |
+ EXPECT_CALL(perf_printer, PrintHistogram(_, _)).Times(0); |
+ |
+ { SCOPED_UMA_HISTOGRAM_TIMER(kFakeHistogram); } |
+ |
+ perf_test::ScopedHistogramResultPrinter scoped_printer( |
+ perf_printer.GetCallback()); |
+ |
+ scoped_printer.AddHistogramStrict(kFakeHistogram, kFakeMeasurement); |
+} |
+ |
+} // namespace |
+ |
+namespace perf_test { |
+ |
+class ScopedHistogramResultPrinterTest : public testing::Test {}; |
+ |
+TEST_F(ScopedHistogramResultPrinterTest, StrictIsNotFound) { |
+ EXPECT_NONFATAL_FAILURE(StrictIsNotFoundTest(), " wasn't found"); |
+} |
+ |
+TEST_F(ScopedHistogramResultPrinterTest, StrictIsFound) { |
+ MockedPrinter perf_printer; |
+ EXPECT_CALL(perf_printer, PrintHistogram(_, _)); |
+ |
+ ScopedHistogramResultPrinter scoped_printer(perf_printer.GetCallback()); |
+ |
+ scoped_printer.AddHistogramStrict(kFakeHistogram, kFakeMeasurement); |
+ SCOPED_UMA_HISTOGRAM_TIMER(kFakeHistogram); |
+} |
+ |
+TEST_F(ScopedHistogramResultPrinterTest, NothingIsAddedToStrict) { |
+ EXPECT_NONFATAL_FAILURE(NothingIsAddedToStrictTest(), |
+ "Nothing was added in "); |
+} |
+ |
+TEST_F(ScopedHistogramResultPrinterTest, NiceIsNotFound) { |
+ MockedPrinter perf_printer; |
+ EXPECT_CALL(perf_printer, PrintHistogram(_, _)).Times(0); |
+ |
+ ScopedHistogramResultPrinter scoped_printer(perf_printer.GetCallback()); |
+ |
+ scoped_printer.AddHistogramNice(kFakeHistogram, kFakeMeasurement); |
+} |
+ |
+TEST_F(ScopedHistogramResultPrinterTest, NothingIsAddedToNice) { |
+ MockedPrinter perf_printer; |
+ EXPECT_CALL(perf_printer, PrintHistogram(_, _)).Times(0); |
+ |
+ { SCOPED_UMA_HISTOGRAM_TIMER(kFakeHistogram); } |
+ ScopedHistogramResultPrinter scoped_printer(perf_printer.GetCallback()); |
+ scoped_printer.AddHistogramNice(kFakeHistogram, kFakeMeasurement); |
+} |
+ |
+} // namespace perf_test |