OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "testing/perf/scoped_histogram_result_printer.h" |
| 6 |
| 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest-spi.h" |
| 10 |
| 11 namespace { |
| 12 using testing::_; |
| 13 |
| 14 const char kFakeHistogram[] = "FakeHistogramName"; |
| 15 const char kFakeMeasurement[] = "FakeMeasurement"; |
| 16 |
| 17 struct MockedPrinter { |
| 18 MOCK_METHOD2(PrintHistogram, |
| 19 void(const base::HistogramSamples&, const std::string&)); |
| 20 perf_test::HistogramPrinter GetCallback() { |
| 21 return base::Bind(&MockedPrinter::PrintHistogram, base::Unretained(this)); |
| 22 } |
| 23 }; |
| 24 |
| 25 void StrictIsNotFoundTest() { |
| 26 MockedPrinter perf_printer; |
| 27 EXPECT_CALL(perf_printer, PrintHistogram(_, _)).Times(0); |
| 28 |
| 29 perf_test::ScopedHistogramResultPrinter scoped_printer( |
| 30 perf_printer.GetCallback()); |
| 31 |
| 32 scoped_printer.AddHistogramStrict(kFakeHistogram, kFakeMeasurement); |
| 33 } |
| 34 |
| 35 void NothingIsAddedToStrictTest() { |
| 36 MockedPrinter perf_printer; |
| 37 EXPECT_CALL(perf_printer, PrintHistogram(_, _)).Times(0); |
| 38 |
| 39 { SCOPED_UMA_HISTOGRAM_TIMER(kFakeHistogram); } |
| 40 |
| 41 perf_test::ScopedHistogramResultPrinter scoped_printer( |
| 42 perf_printer.GetCallback()); |
| 43 |
| 44 scoped_printer.AddHistogramStrict(kFakeHistogram, kFakeMeasurement); |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 namespace perf_test { |
| 50 |
| 51 class ScopedHistogramResultPrinterTest : public testing::Test {}; |
| 52 |
| 53 TEST_F(ScopedHistogramResultPrinterTest, StrictIsNotFound) { |
| 54 EXPECT_NONFATAL_FAILURE(StrictIsNotFoundTest(), " wasn't found"); |
| 55 } |
| 56 |
| 57 TEST_F(ScopedHistogramResultPrinterTest, StrictIsFound) { |
| 58 MockedPrinter perf_printer; |
| 59 EXPECT_CALL(perf_printer, PrintHistogram(_, _)); |
| 60 |
| 61 ScopedHistogramResultPrinter scoped_printer(perf_printer.GetCallback()); |
| 62 |
| 63 scoped_printer.AddHistogramStrict(kFakeHistogram, kFakeMeasurement); |
| 64 SCOPED_UMA_HISTOGRAM_TIMER(kFakeHistogram); |
| 65 } |
| 66 |
| 67 TEST_F(ScopedHistogramResultPrinterTest, NothingIsAddedToStrict) { |
| 68 EXPECT_NONFATAL_FAILURE(NothingIsAddedToStrictTest(), |
| 69 "Nothing was added in "); |
| 70 } |
| 71 |
| 72 TEST_F(ScopedHistogramResultPrinterTest, NiceIsNotFound) { |
| 73 MockedPrinter perf_printer; |
| 74 EXPECT_CALL(perf_printer, PrintHistogram(_, _)).Times(0); |
| 75 |
| 76 ScopedHistogramResultPrinter scoped_printer(perf_printer.GetCallback()); |
| 77 |
| 78 scoped_printer.AddHistogramNice(kFakeHistogram, kFakeMeasurement); |
| 79 } |
| 80 |
| 81 TEST_F(ScopedHistogramResultPrinterTest, NothingIsAddedToNice) { |
| 82 MockedPrinter perf_printer; |
| 83 EXPECT_CALL(perf_printer, PrintHistogram(_, _)).Times(0); |
| 84 |
| 85 { SCOPED_UMA_HISTOGRAM_TIMER(kFakeHistogram); } |
| 86 ScopedHistogramResultPrinter scoped_printer(perf_printer.GetCallback()); |
| 87 scoped_printer.AddHistogramNice(kFakeHistogram, kFakeMeasurement); |
| 88 } |
| 89 |
| 90 } // namespace perf_test |
OLD | NEW |