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 14 matching lines...) Expand all Loading... |
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 base::HistogramBase::Sample sample, | 33 base::HistogramBase::Sample sample, |
34 base::HistogramBase::Count expected_count) { | 34 base::HistogramBase::Count expected_count) { |
35 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); | 35 base::HistogramBase* histogram = |
36 EXPECT_NE(static_cast<base::Histogram*>(NULL), histogram) | 36 base::StatisticsRecorder::FindHistogram(name); |
| 37 EXPECT_NE(static_cast<base::HistogramBase*>(NULL), histogram) |
37 << "Histogram \"" << name << "\" does not exist."; | 38 << "Histogram \"" << name << "\" does not exist."; |
38 | 39 |
39 if (histogram) { | 40 if (histogram) { |
40 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | 41 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); |
41 CheckBucketCount(name, sample, expected_count, *samples); | 42 CheckBucketCount(name, sample, expected_count, *samples); |
42 CheckTotalCount(name, expected_count, *samples); | 43 CheckTotalCount(name, expected_count, *samples); |
43 } | 44 } |
44 } | 45 } |
45 | 46 |
46 void UMAHistogramHelper::ExpectTotalCount( | 47 void UMAHistogramHelper::ExpectTotalCount( |
47 const std::string& name, | 48 const std::string& name, |
48 base::HistogramBase::Count count) { | 49 base::HistogramBase::Count count) { |
49 base::Histogram* histogram = base::StatisticsRecorder::FindHistogram(name); | 50 base::HistogramBase* histogram = |
50 EXPECT_NE(static_cast<base::Histogram*>(NULL), histogram) | 51 base::StatisticsRecorder::FindHistogram(name); |
| 52 EXPECT_NE(static_cast<base::HistogramBase*>(NULL), histogram) |
51 << "Histogram \"" << name << "\" does not exist."; | 53 << "Histogram \"" << name << "\" does not exist."; |
52 | 54 |
53 if (histogram) { | 55 if (histogram) { |
54 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | 56 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); |
55 CheckTotalCount(name, count, *samples); | 57 CheckTotalCount(name, count, *samples); |
56 } | 58 } |
57 } | 59 } |
58 | 60 |
59 void UMAHistogramHelper::FetchCallback() { | 61 void UMAHistogramHelper::FetchCallback() { |
60 MessageLoopForUI::current()->Quit(); | 62 MessageLoopForUI::current()->Quit(); |
(...skipping 12 matching lines...) Expand all Loading... |
73 | 75 |
74 void UMAHistogramHelper::CheckTotalCount( | 76 void UMAHistogramHelper::CheckTotalCount( |
75 const std::string& name, | 77 const std::string& name, |
76 base::HistogramBase::Count expected_count, | 78 base::HistogramBase::Count expected_count, |
77 base::HistogramSamples& samples) { | 79 base::HistogramSamples& samples) { |
78 EXPECT_EQ(expected_count, samples.TotalCount()) | 80 EXPECT_EQ(expected_count, samples.TotalCount()) |
79 << "Histogram \"" << name | 81 << "Histogram \"" << name |
80 << "\" does not have the right total number of samples (" | 82 << "\" does not have the right total number of samples (" |
81 << expected_count << ")."; | 83 << expected_count << ")."; |
82 } | 84 } |
OLD | NEW |