OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/translate/translate_manager_metrics.h" | 5 #include "chrome/browser/translate/translate_manager_metrics.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 int expected_disabled_by_config, | 36 int expected_disabled_by_config, |
37 int expected_language_is_not_supported, | 37 int expected_language_is_not_supported, |
38 int expected_url_is_not_supported, | 38 int expected_url_is_not_supported, |
39 int expected_similar_languages, | 39 int expected_similar_languages, |
40 int expected_accept_languages, | 40 int expected_accept_languages, |
41 int expected_auto_by_config, | 41 int expected_auto_by_config, |
42 int expected_auto_by_link, | 42 int expected_auto_by_link, |
43 int expected_show_infobar) { | 43 int expected_show_infobar) { |
44 Snapshot(); | 44 Snapshot(); |
45 | 45 |
46 EXPECT_EQ(expected_disabled_by_prefs, GetCount( | 46 EXPECT_EQ(expected_disabled_by_prefs, GetCountWithoutSnapshot( |
47 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_PREFS)); | 47 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_PREFS)); |
48 EXPECT_EQ(expected_disabled_by_switch, GetCount( | 48 EXPECT_EQ(expected_disabled_by_switch, GetCountWithoutSnapshot( |
49 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH)); | 49 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH)); |
50 EXPECT_EQ(expected_disabled_by_config, GetCount( | 50 EXPECT_EQ(expected_disabled_by_config, GetCountWithoutSnapshot( |
51 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG)); | 51 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG)); |
52 EXPECT_EQ(expected_language_is_not_supported, GetCount( | 52 EXPECT_EQ(expected_language_is_not_supported, GetCountWithoutSnapshot( |
53 TranslateManagerMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED)); | 53 TranslateManagerMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED)); |
54 EXPECT_EQ(expected_url_is_not_supported, GetCount( | 54 EXPECT_EQ(expected_url_is_not_supported, GetCountWithoutSnapshot( |
55 TranslateManagerMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED)); | 55 TranslateManagerMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED)); |
56 EXPECT_EQ(expected_similar_languages, GetCount( | 56 EXPECT_EQ(expected_similar_languages, GetCountWithoutSnapshot( |
57 TranslateManagerMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES)); | 57 TranslateManagerMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES)); |
58 EXPECT_EQ(expected_accept_languages, GetCount( | 58 EXPECT_EQ(expected_accept_languages, GetCountWithoutSnapshot( |
59 TranslateManagerMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES)); | 59 TranslateManagerMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES)); |
60 EXPECT_EQ(expected_auto_by_config, GetCount( | 60 EXPECT_EQ(expected_auto_by_config, GetCountWithoutSnapshot( |
61 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_CONFIG)); | 61 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_CONFIG)); |
62 EXPECT_EQ(expected_auto_by_link, GetCount( | 62 EXPECT_EQ(expected_auto_by_link, GetCountWithoutSnapshot( |
63 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_LINK)); | 63 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_LINK)); |
64 EXPECT_EQ(expected_show_infobar, GetCount( | 64 EXPECT_EQ(expected_show_infobar, GetCountWithoutSnapshot( |
65 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR)); | 65 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR)); |
66 } | 66 } |
67 | 67 |
68 HistogramBase::Count GetTotalCount() { | 68 HistogramBase::Count GetTotalCount() { |
69 Snapshot(); | 69 Snapshot(); |
70 if (!samples_.get()) | 70 if (!samples_.get()) |
71 return 0; | 71 return 0; |
72 HistogramBase::Count count = samples_->TotalCount(); | 72 HistogramBase::Count count = samples_->TotalCount(); |
73 if (!base_samples_.get()) | 73 if (!base_samples_.get()) |
74 return count; | 74 return count; |
75 return count - base_samples_->TotalCount(); | 75 return count - base_samples_->TotalCount(); |
76 } | 76 } |
77 | 77 |
| 78 HistogramBase::Count GetCount(HistogramBase::Sample value) { |
| 79 Snapshot(); |
| 80 return GetCountWithoutSnapshot(value); |
| 81 } |
| 82 |
78 private: | 83 private: |
79 void Snapshot() { | 84 void Snapshot() { |
80 HistogramBase* histogram = StatisticsRecorder::FindHistogram(key_); | 85 HistogramBase* histogram = StatisticsRecorder::FindHistogram(key_); |
81 if (!histogram) | 86 if (!histogram) |
82 return; | 87 return; |
83 samples_ = histogram->SnapshotSamples(); | 88 samples_ = histogram->SnapshotSamples(); |
84 } | 89 } |
85 | 90 |
86 HistogramBase::Count GetCount(HistogramBase::Sample value) { | 91 HistogramBase::Count GetCountWithoutSnapshot(HistogramBase::Sample value) { |
87 if (!samples_.get()) | 92 if (!samples_.get()) |
88 return 0; | 93 return 0; |
89 HistogramBase::Count count = samples_->GetCount(value); | 94 HistogramBase::Count count = samples_->GetCount(value); |
90 if (!base_samples_.get()) | 95 if (!base_samples_.get()) |
91 return count; | 96 return count; |
92 return count - base_samples_->GetCount(value); | 97 return count - base_samples_->GetCount(value); |
93 } | 98 } |
94 | 99 |
95 std::string key_; | 100 std::string key_; |
96 scoped_ptr<HistogramSamples> base_samples_; | 101 scoped_ptr<HistogramSamples> base_samples_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR); | 142 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR); |
138 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); | 143 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); |
139 } | 144 } |
140 | 145 |
141 TEST(TranslateManagerMetricsTest, ReportLanguageDetectionError) { | 146 TEST(TranslateManagerMetricsTest, ReportLanguageDetectionError) { |
142 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 147 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( |
143 TranslateManagerMetrics::UMA_LANGUAGE_DETECTION_ERROR)); | 148 TranslateManagerMetrics::UMA_LANGUAGE_DETECTION_ERROR)); |
144 EXPECT_EQ(0, recorder.GetTotalCount()); | 149 EXPECT_EQ(0, recorder.GetTotalCount()); |
145 TranslateManagerMetrics::ReportLanguageDetectionError(); | 150 TranslateManagerMetrics::ReportLanguageDetectionError(); |
146 EXPECT_EQ(1, recorder.GetTotalCount()); | 151 EXPECT_EQ(1, recorder.GetTotalCount()); |
| 152 |
147 } | 153 } |
148 | 154 |
149 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguage) { | 155 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguage) { |
150 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 156 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( |
151 TranslateManagerMetrics::UMA_SERVER_REPORTED_UNSUPPORTED_LANGUAGE)); | 157 TranslateManagerMetrics::UMA_SERVER_REPORTED_UNSUPPORTED_LANGUAGE)); |
152 EXPECT_EQ(0, recorder.GetTotalCount()); | 158 EXPECT_EQ(0, recorder.GetTotalCount()); |
153 TranslateManagerMetrics::ReportUnsupportedLanguage(); | 159 TranslateManagerMetrics::ReportUnsupportedLanguage(); |
154 EXPECT_EQ(1, recorder.GetTotalCount()); | 160 EXPECT_EQ(1, recorder.GetTotalCount()); |
155 } | 161 } |
| 162 |
| 163 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguageAtInitiation) { |
| 164 const int ENGLISH = 25966; |
| 165 |
| 166 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( |
| 167 TranslateManagerMetrics::UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION)); |
| 168 EXPECT_EQ(0, recorder.GetTotalCount()); |
| 169 TranslateManagerMetrics::ReportUnsupportedLanguageAtInitiation("en"); |
| 170 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); |
| 171 } |
OLD | NEW |