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"; | |
25 | 24 |
26 } // namespace | 25 } // namespace |
27 | 26 |
28 namespace base { | 27 namespace base { |
29 | 28 |
30 typedef testing::Test HistogramTesterTest; | 29 typedef testing::Test HistogramTesterTest; |
31 | 30 |
32 TEST_F(HistogramTesterTest, Scope) { | 31 TEST_F(HistogramTesterTest, Scope) { |
33 // Record a histogram before the creation of the recorder. | 32 // Record a histogram before the creation of the recorder. |
34 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); | 33 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 110 |
112 EXPECT_THAT(tester.GetAllSamples(kHistogram5), | 111 EXPECT_THAT(tester.GetAllSamples(kHistogram5), |
113 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); | 112 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); |
114 } | 113 } |
115 | 114 |
116 TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) { | 115 TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) { |
117 HistogramTester tester; | 116 HistogramTester tester; |
118 EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty()); | 117 EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty()); |
119 } | 118 } |
120 | 119 |
121 // Wrong behaviour for GetTotalCountForPrefix: https://crbug.com/659977 | 120 TEST_F(HistogramTesterTest, TestGetTotalCountsForPrefix) { |
122 TEST_F(HistogramTesterTest, DISABLED_TestGetTotalCountsForPrefix) { | |
123 HistogramTester tester; | 121 HistogramTester tester; |
124 UMA_HISTOGRAM_ENUMERATION(kHistogramSuffix, 2, 5); | 122 UMA_HISTOGRAM_ENUMERATION("Test1.Test2.Test3", 2, 5); |
125 | 123 |
126 EXPECT_TRUE(tester.GetTotalCountsForPrefix("Test5").empty()); | 124 // Regression check for bug https://crbug.com/659977. |
| 125 EXPECT_TRUE(tester.GetTotalCountsForPrefix("Test2.").empty()); |
| 126 |
| 127 EXPECT_EQ(1u, tester.GetTotalCountsForPrefix("Test1.").size()); |
127 } | 128 } |
128 | 129 |
129 } // namespace base | 130 } // namespace base |
OLD | NEW |