Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/test/histogram_tester.h" | 5 #include "base/test/histogram_tester.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using ::testing::ElementsAre; | 14 using ::testing::ElementsAre; |
| 15 using ::testing::IsEmpty; | 15 using ::testing::IsEmpty; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kHistogram1[] = "Test1"; | 19 const char kHistogram1[] = "Test1"; |
| 20 const char kHistogram2[] = "Test2"; | 20 const char kHistogram2[] = "Test2"; |
| 21 const char kHistogram3[] = "Test3"; | 21 const char kHistogram3[] = "Test3"; |
| 22 const char kHistogram4[] = "Test4"; | 22 const char kHistogram4[] = "Test4"; |
| 23 const char kHistogram5[] = "Test5"; | 23 const char kHistogram5[] = "Test5"; |
| 24 const char kHistogramSuffix[] = "Test4.Test5"; | |
| 24 | 25 |
| 25 } // namespace | 26 } // namespace |
| 26 | 27 |
| 27 namespace base { | 28 namespace base { |
| 28 | 29 |
| 29 typedef testing::Test HistogramTesterTest; | 30 typedef testing::Test HistogramTesterTest; |
| 30 | 31 |
| 31 TEST_F(HistogramTesterTest, Scope) { | 32 TEST_F(HistogramTesterTest, Scope) { |
| 32 // Record a histogram before the creation of the recorder. | 33 // Record a histogram before the creation of the recorder. |
| 33 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); | 34 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 111 |
| 111 EXPECT_THAT(tester.GetAllSamples(kHistogram5), | 112 EXPECT_THAT(tester.GetAllSamples(kHistogram5), |
| 112 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); | 113 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); |
| 113 } | 114 } |
| 114 | 115 |
| 115 TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) { | 116 TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) { |
| 116 HistogramTester tester; | 117 HistogramTester tester; |
| 117 EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty()); | 118 EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty()); |
| 118 } | 119 } |
| 119 | 120 |
| 121 // Wrong behaviour for GetTotalCountForPrefix: https://crbug.com/659977 | |
| 122 TEST_F(HistogramTesterTest, DISABLED_TestGetTotalCountsForPrefix) { | |
| 123 HistogramTester tester; | |
| 124 UMA_HISTOGRAM_ENUMERATION(kHistogramSuffix, 2, 5); | |
|
Paweł Hajdan Jr.
2016/10/27 16:55:51
nit: Is it worth extracting this as a constant? In
melandory
2016/10/28 07:30:15
Funnily, in-lining Test4.Test5 triggers the presub
| |
| 125 | |
| 126 EXPECT_TRUE(tester.GetTotalCountsForPrefix("Test5").empty()); | |
| 127 } | |
| 128 | |
| 120 } // namespace base | 129 } // namespace base |
| OLD | NEW |