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_browser_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" |
11 #include "base/metrics/statistics_recorder.h" | 11 #include "base/metrics/statistics_recorder.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
14 | 14 |
15 using base::HistogramBase; | 15 using base::HistogramBase; |
(...skipping 18 matching lines...) Expand all Loading... |
34 int expected_language_is_not_supported, | 34 int expected_language_is_not_supported, |
35 int expected_url_is_not_supported, | 35 int expected_url_is_not_supported, |
36 int expected_similar_languages, | 36 int expected_similar_languages, |
37 int expected_accept_languages, | 37 int expected_accept_languages, |
38 int expected_auto_by_config, | 38 int expected_auto_by_config, |
39 int expected_auto_by_link, | 39 int expected_auto_by_link, |
40 int expected_show_infobar) { | 40 int expected_show_infobar) { |
41 Snapshot(); | 41 Snapshot(); |
42 | 42 |
43 EXPECT_EQ(expected_disabled_by_prefs, GetCountWithoutSnapshot( | 43 EXPECT_EQ(expected_disabled_by_prefs, GetCountWithoutSnapshot( |
44 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_PREFS)); | 44 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS)); |
45 EXPECT_EQ(expected_disabled_by_switch, GetCountWithoutSnapshot( | 45 EXPECT_EQ(expected_disabled_by_switch, GetCountWithoutSnapshot( |
46 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH)); | 46 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH)); |
47 EXPECT_EQ(expected_disabled_by_config, GetCountWithoutSnapshot( | 47 EXPECT_EQ(expected_disabled_by_config, GetCountWithoutSnapshot( |
48 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG)); | 48 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG)); |
49 EXPECT_EQ(expected_language_is_not_supported, GetCountWithoutSnapshot( | 49 EXPECT_EQ(expected_language_is_not_supported, GetCountWithoutSnapshot( |
50 TranslateManagerMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED)); | 50 TranslateBrowserMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED)); |
51 EXPECT_EQ(expected_url_is_not_supported, GetCountWithoutSnapshot( | 51 EXPECT_EQ(expected_url_is_not_supported, GetCountWithoutSnapshot( |
52 TranslateManagerMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED)); | 52 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED)); |
53 EXPECT_EQ(expected_similar_languages, GetCountWithoutSnapshot( | 53 EXPECT_EQ(expected_similar_languages, GetCountWithoutSnapshot( |
54 TranslateManagerMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES)); | 54 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES)); |
55 EXPECT_EQ(expected_accept_languages, GetCountWithoutSnapshot( | 55 EXPECT_EQ(expected_accept_languages, GetCountWithoutSnapshot( |
56 TranslateManagerMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES)); | 56 TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES)); |
57 EXPECT_EQ(expected_auto_by_config, GetCountWithoutSnapshot( | 57 EXPECT_EQ(expected_auto_by_config, GetCountWithoutSnapshot( |
58 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_CONFIG)); | 58 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_CONFIG)); |
59 EXPECT_EQ(expected_auto_by_link, GetCountWithoutSnapshot( | 59 EXPECT_EQ(expected_auto_by_link, GetCountWithoutSnapshot( |
60 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_LINK)); | 60 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_LINK)); |
61 EXPECT_EQ(expected_show_infobar, GetCountWithoutSnapshot( | 61 EXPECT_EQ(expected_show_infobar, GetCountWithoutSnapshot( |
62 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR)); | 62 TranslateBrowserMetrics::INITIATION_STATUS_SHOW_INFOBAR)); |
63 } | 63 } |
64 | 64 |
65 HistogramBase::Count GetTotalCount() { | 65 HistogramBase::Count GetTotalCount() { |
66 Snapshot(); | 66 Snapshot(); |
67 if (!samples_.get()) | 67 if (!samples_.get()) |
68 return 0; | 68 return 0; |
69 HistogramBase::Count count = samples_->TotalCount(); | 69 HistogramBase::Count count = samples_->TotalCount(); |
70 if (!base_samples_.get()) | 70 if (!base_samples_.get()) |
71 return count; | 71 return count; |
72 return count - base_samples_->TotalCount(); | 72 return count - base_samples_->TotalCount(); |
(...skipping 23 matching lines...) Expand all Loading... |
96 | 96 |
97 std::string key_; | 97 std::string key_; |
98 scoped_ptr<HistogramSamples> base_samples_; | 98 scoped_ptr<HistogramSamples> base_samples_; |
99 scoped_ptr<HistogramSamples> samples_; | 99 scoped_ptr<HistogramSamples> samples_; |
100 | 100 |
101 DISALLOW_COPY_AND_ASSIGN(MetricsRecorder); | 101 DISALLOW_COPY_AND_ASSIGN(MetricsRecorder); |
102 }; | 102 }; |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 TEST(TranslateManagerMetricsTest, ReportInitiationStatus) { | 106 TEST(TranslateBrowserMetricsTest, ReportInitiationStatus) { |
107 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 107 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
108 TranslateManagerMetrics::UMA_INITIATION_STATUS)); | 108 TranslateBrowserMetrics::UMA_INITIATION_STATUS)); |
109 | 109 |
110 recorder.CheckInitiationStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 110 recorder.CheckInitiationStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
111 TranslateManagerMetrics::ReportInitiationStatus( | 111 TranslateBrowserMetrics::ReportInitiationStatus( |
112 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); | 112 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); |
113 recorder.CheckInitiationStatus(1, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 113 recorder.CheckInitiationStatus(1, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
114 TranslateManagerMetrics::ReportInitiationStatus( | 114 TranslateBrowserMetrics::ReportInitiationStatus( |
115 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH); | 115 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH); |
116 recorder.CheckInitiationStatus(1, 1, 0, 0, 0, 0, 0, 0, 0, 0); | 116 recorder.CheckInitiationStatus(1, 1, 0, 0, 0, 0, 0, 0, 0, 0); |
117 TranslateManagerMetrics::ReportInitiationStatus( | 117 TranslateBrowserMetrics::ReportInitiationStatus( |
118 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG); | 118 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG); |
119 recorder.CheckInitiationStatus(1, 1, 1, 0, 0, 0, 0, 0, 0, 0); | 119 recorder.CheckInitiationStatus(1, 1, 1, 0, 0, 0, 0, 0, 0, 0); |
120 TranslateManagerMetrics::ReportInitiationStatus( | 120 TranslateBrowserMetrics::ReportInitiationStatus( |
121 TranslateManagerMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED); | 121 TranslateBrowserMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED); |
122 recorder.CheckInitiationStatus(1, 1, 1, 1, 0, 0, 0, 0, 0, 0); | 122 recorder.CheckInitiationStatus(1, 1, 1, 1, 0, 0, 0, 0, 0, 0); |
123 TranslateManagerMetrics::ReportInitiationStatus( | 123 TranslateBrowserMetrics::ReportInitiationStatus( |
124 TranslateManagerMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); | 124 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); |
125 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 0, 0, 0, 0, 0); | 125 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 0, 0, 0, 0, 0); |
126 TranslateManagerMetrics::ReportInitiationStatus( | 126 TranslateBrowserMetrics::ReportInitiationStatus( |
127 TranslateManagerMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); | 127 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); |
128 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 0, 0, 0, 0); | 128 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 0, 0, 0, 0); |
129 TranslateManagerMetrics::ReportInitiationStatus( | 129 TranslateBrowserMetrics::ReportInitiationStatus( |
130 TranslateManagerMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES); | 130 TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES); |
131 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 0, 0, 0); | 131 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 0, 0, 0); |
132 TranslateManagerMetrics::ReportInitiationStatus( | 132 TranslateBrowserMetrics::ReportInitiationStatus( |
133 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_CONFIG); | 133 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_CONFIG); |
134 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 0, 0); | 134 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 0, 0); |
135 TranslateManagerMetrics::ReportInitiationStatus( | 135 TranslateBrowserMetrics::ReportInitiationStatus( |
136 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_LINK); | 136 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_LINK); |
137 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 0); | 137 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 0); |
138 TranslateManagerMetrics::ReportInitiationStatus( | 138 TranslateBrowserMetrics::ReportInitiationStatus( |
139 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR); | 139 TranslateBrowserMetrics::INITIATION_STATUS_SHOW_INFOBAR); |
140 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); | 140 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); |
141 } | 141 } |
142 | 142 |
143 TEST(TranslateManagerMetricsTest, ReportLanguageDetectionError) { | 143 TEST(TranslateBrowserMetricsTest, ReportLanguageDetectionError) { |
144 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 144 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
145 TranslateManagerMetrics::UMA_LANGUAGE_DETECTION_ERROR)); | 145 TranslateBrowserMetrics::UMA_LANGUAGE_DETECTION_ERROR)); |
146 EXPECT_EQ(0, recorder.GetTotalCount()); | 146 EXPECT_EQ(0, recorder.GetTotalCount()); |
147 TranslateManagerMetrics::ReportLanguageDetectionError(); | 147 TranslateBrowserMetrics::ReportLanguageDetectionError(); |
148 EXPECT_EQ(1, recorder.GetTotalCount()); | 148 EXPECT_EQ(1, recorder.GetTotalCount()); |
149 | 149 |
150 } | 150 } |
151 | 151 |
152 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguage) { | |
153 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | |
154 TranslateManagerMetrics::UMA_SERVER_REPORTED_UNSUPPORTED_LANGUAGE)); | |
155 EXPECT_EQ(0, recorder.GetTotalCount()); | |
156 TranslateManagerMetrics::ReportUnsupportedLanguage(); | |
157 EXPECT_EQ(1, recorder.GetTotalCount()); | |
158 } | |
159 | 152 |
160 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguageAtInitiation) { | 153 TEST(TranslateBrowserMetricsTest, ReportedLocalesOnDisabledByPrefs) { |
161 const int ENGLISH = 25966; | 154 const int ENGLISH = 25966; |
162 | 155 |
163 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 156 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
164 TranslateManagerMetrics::UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION)); | 157 TranslateBrowserMetrics::UMA_LOCALES_ON_DISABLED_BY_PREFS)); |
165 EXPECT_EQ(0, recorder.GetTotalCount()); | 158 EXPECT_EQ(0, recorder.GetTotalCount()); |
166 TranslateManagerMetrics::ReportUnsupportedLanguageAtInitiation("en"); | 159 TranslateBrowserMetrics::ReportLocalesOnDisabledByPrefs("en"); |
167 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); | 160 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); |
168 } | 161 } |
169 | 162 |
170 TEST(TranslateManagerMetricsTest, ReportedLocalesOnDisabledByPrefs) { | 163 TEST(TranslateBrowserMetricsTest, ReportedUndisplayableLanguage) { |
171 const int ENGLISH = 25966; | 164 const int ENGLISH = 25966; |
172 | 165 |
173 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 166 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
174 TranslateManagerMetrics::UMA_LOCALES_ON_DISABLED_BY_PREFS)); | 167 TranslateBrowserMetrics::UMA_UNDISPLAYABLE_LANGUAGE)); |
175 EXPECT_EQ(0, recorder.GetTotalCount()); | 168 EXPECT_EQ(0, recorder.GetTotalCount()); |
176 TranslateManagerMetrics::ReportLocalesOnDisabledByPrefs("en"); | 169 TranslateBrowserMetrics::ReportUndisplayableLanguage("en"); |
177 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); | 170 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); |
178 } | 171 } |
| 172 |
| 173 TEST(TranslateBrowserMetricsTest, ReportedUnsupportedLanguageAtInitiation) { |
| 174 const int ENGLISH = 25966; |
| 175 |
| 176 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
| 177 TranslateBrowserMetrics::UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION)); |
| 178 EXPECT_EQ(0, recorder.GetTotalCount()); |
| 179 TranslateBrowserMetrics::ReportUnsupportedLanguageAtInitiation("en"); |
| 180 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); |
| 181 } |
OLD | NEW |