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 const char kHistogramSuffix[] = "Test4.Test5.Test6"; |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 | 29 |
30 typedef testing::Test HistogramTesterTest; | 30 typedef testing::Test HistogramTesterTest; |
31 | 31 |
32 TEST_F(HistogramTesterTest, Scope) { | 32 TEST_F(HistogramTesterTest, Scope) { |
33 // Record a histogram before the creation of the recorder. | 33 // Record a histogram before the creation of the recorder. |
34 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); | 34 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 | 111 |
112 EXPECT_THAT(tester.GetAllSamples(kHistogram5), | 112 EXPECT_THAT(tester.GetAllSamples(kHistogram5), |
113 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); | 113 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); |
114 } | 114 } |
115 | 115 |
116 TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) { | 116 TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) { |
117 HistogramTester tester; | 117 HistogramTester tester; |
118 EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty()); | 118 EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty()); |
119 } | 119 } |
120 | 120 |
121 // Wrong behaviour for GetTotalCountForPrefix: https://crbug.com/659977 | 121 TEST_F(HistogramTesterTest, TestGetTotalCountsForPrefix) { |
122 TEST_F(HistogramTesterTest, DISABLED_TestGetTotalCountsForPrefix) { | |
123 HistogramTester tester; | 122 HistogramTester tester; |
124 UMA_HISTOGRAM_ENUMERATION(kHistogramSuffix, 2, 5); | 123 UMA_HISTOGRAM_ENUMERATION(kHistogramSuffix, 2, 5); |
Ilya Sherman
2017/01/12 20:32:41
Optional nit: I think it would be clearer to inlin
pkalinnikov
2017/01/13 10:28:59
Done.
| |
125 | 124 |
126 EXPECT_TRUE(tester.GetTotalCountsForPrefix("Test5").empty()); | 125 // Regression check for bug https://crbug.com/659977. |
126 EXPECT_TRUE(tester.GetTotalCountsForPrefix("Test5.").empty()); | |
127 | |
128 EXPECT_EQ(1u, tester.GetTotalCountsForPrefix("Test4.").size()); | |
127 } | 129 } |
128 | 130 |
129 } // namespace base | 131 } // namespace base |
OLD | NEW |