OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/base/uma_histogram_helper.h" | 5 #include "chrome/test/base/uma_histogram_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/statistics_recorder.h" | 8 #include "base/metrics/statistics_recorder.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // If this call times out, it means that a child process is not | 23 // If this call times out, it means that a child process is not |
24 // responding, which is something we should not ignore. The timeout is | 24 // responding, which is something we should not ignore. The timeout is |
25 // set to be longer than the normal browser test timeout so that it will | 25 // set to be longer than the normal browser test timeout so that it will |
26 // be prempted by the normal timeout. | 26 // be prempted by the normal timeout. |
27 TestTimeouts::action_max_timeout()*2); | 27 TestTimeouts::action_max_timeout()*2); |
28 content::RunMessageLoop(); | 28 content::RunMessageLoop(); |
29 } | 29 } |
30 | 30 |
31 void UMAHistogramHelper::ExpectUniqueSample( | 31 void UMAHistogramHelper::ExpectUniqueSample( |
32 const std::string& name, | 32 const std::string& name, |
33 size_t bucket_id, | 33 base::HistogramBase::Sample sample, |
34 base::Histogram::Count expected_count) { | 34 base::HistogramBase::Count expected_count) { |
35 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); | 35 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); |
36 EXPECT_NE(static_cast<base::Histogram*>(NULL), histogram) << | 36 EXPECT_NE(static_cast<base::Histogram*>(NULL), histogram) |
37 "Histogram \"" << name << "\" does not exist."; | 37 << "Histogram \"" << name << "\" does not exist."; |
38 | 38 |
39 if (histogram) { | 39 if (histogram) { |
40 base::Histogram::SampleSet samples; | 40 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); |
41 histogram->SnapshotSample(&samples); | 41 CheckBucketCount(name, sample, expected_count, *samples); |
42 CheckBucketCount(name, bucket_id, expected_count, samples); | 42 CheckTotalCount(name, expected_count, *samples); |
43 CheckTotalCount(name, expected_count, samples); | |
44 } | 43 } |
45 } | 44 } |
46 | 45 |
47 void UMAHistogramHelper::ExpectTotalCount(const std::string& name, | 46 void UMAHistogramHelper::ExpectTotalCount( |
48 base::Histogram::Count count) { | 47 const std::string& name, |
| 48 base::HistogramBase::Count count) { |
49 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); | 49 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); |
50 EXPECT_NE((base::Histogram*)NULL, histogram) << "Histogram \"" << name << | 50 EXPECT_NE(static_cast<base::Histogram*>(NULL), histogram) |
51 "\" does not exist."; | 51 << "Histogram \"" << name << "\" does not exist."; |
52 | 52 |
53 if (histogram) { | 53 if (histogram) { |
54 base::Histogram::SampleSet samples; | 54 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); |
55 histogram->SnapshotSample(&samples); | 55 CheckTotalCount(name, count, *samples); |
56 CheckTotalCount(name, count, samples); | |
57 } | 56 } |
58 } | 57 } |
59 | 58 |
60 void UMAHistogramHelper::FetchCallback() { | 59 void UMAHistogramHelper::FetchCallback() { |
61 MessageLoopForUI::current()->Quit(); | 60 MessageLoopForUI::current()->Quit(); |
62 } | 61 } |
63 | 62 |
64 void UMAHistogramHelper::CheckBucketCount(const std::string& name, | 63 void UMAHistogramHelper::CheckBucketCount( |
65 size_t bucket_id, | 64 const std::string& name, |
66 base::Histogram::Count expected_count, | 65 base::HistogramBase::Sample sample, |
67 base::Histogram::SampleSet& samples) { | 66 base::HistogramBase::Count expected_count, |
68 EXPECT_EQ(expected_count, samples.counts(bucket_id)) << "Histogram \"" << | 67 base::HistogramSamples& samples) { |
69 name << "\" does not have the right number of samples (" << | 68 EXPECT_EQ(expected_count, samples.GetCount(sample)) |
70 expected_count << ") in the expected bucket (" << bucket_id << ")."; | 69 << "Histogram \"" << name |
| 70 << "\" does not have the right number of samples (" << expected_count |
| 71 << ") in the expected bucket (" << sample << ")."; |
71 } | 72 } |
72 | 73 |
73 void UMAHistogramHelper::CheckTotalCount(const std::string& name, | 74 void UMAHistogramHelper::CheckTotalCount( |
74 base::Histogram::Count expected_count, | 75 const std::string& name, |
75 base::Histogram::SampleSet& samples) { | 76 base::HistogramBase::Count expected_count, |
76 EXPECT_EQ(expected_count, samples.TotalCount()) << "Histogram \"" << name << | 77 base::HistogramSamples& samples) { |
77 "\" does not have the right total number of samples (" << | 78 EXPECT_EQ(expected_count, samples.TotalCount()) |
78 expected_count << ")."; | 79 << "Histogram \"" << name |
| 80 << "\" does not have the right total number of samples (" |
| 81 << expected_count << ")."; |
79 } | 82 } |
OLD | NEW |