Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: components/translate/core/browser/translate_browser_metrics_unittest.cc

Issue 2819813002: Translate: remove --disable-translate flag (Closed)
Patch Set: Merge branch 'master' into translate_remove_disable_flag Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/translate/core/browser/translate_browser_metrics.h" 5 #include "components/translate/core/browser/translate_browser_metrics.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 12 matching lines...) Expand all
23 public: 23 public:
24 explicit MetricsRecorder(const char* key) : key_(key) { 24 explicit MetricsRecorder(const char* key) : key_(key) {
25 StatisticsRecorder::Initialize(); 25 StatisticsRecorder::Initialize();
26 26
27 HistogramBase* histogram = StatisticsRecorder::FindHistogram(key_); 27 HistogramBase* histogram = StatisticsRecorder::FindHistogram(key_);
28 if (histogram) 28 if (histogram)
29 base_samples_ = histogram->SnapshotSamples(); 29 base_samples_ = histogram->SnapshotSamples();
30 } 30 }
31 31
32 void CheckInitiationStatus(int expected_disabled_by_prefs, 32 void CheckInitiationStatus(int expected_disabled_by_prefs,
33 int expected_disabled_by_switch,
34 int expected_disabled_by_config, 33 int expected_disabled_by_config,
35 int expected_disabled_by_build, 34 int expected_disabled_by_build,
36 int expected_language_is_not_supported, 35 int expected_language_is_not_supported,
37 int expected_mime_type_is_not_supported, 36 int expected_mime_type_is_not_supported,
38 int expected_url_is_not_supported, 37 int expected_url_is_not_supported,
39 int expected_similar_languages, 38 int expected_similar_languages,
40 int expected_accept_languages, 39 int expected_accept_languages,
41 int expected_auto_by_config, 40 int expected_auto_by_config,
42 int expected_auto_by_link, 41 int expected_auto_by_link,
43 int expected_show_infobar) { 42 int expected_show_infobar) {
44 Snapshot(); 43 Snapshot();
45 44
46 EXPECT_EQ(expected_disabled_by_prefs, 45 EXPECT_EQ(expected_disabled_by_prefs,
47 GetCountWithoutSnapshot(translate::TranslateBrowserMetrics:: 46 GetCountWithoutSnapshot(translate::TranslateBrowserMetrics::
48 INITIATION_STATUS_DISABLED_BY_PREFS)); 47 INITIATION_STATUS_DISABLED_BY_PREFS));
49 EXPECT_EQ( 48 EXPECT_EQ(
50 expected_disabled_by_switch,
51 GetCountWithoutSnapshot(translate::TranslateBrowserMetrics::
52 INITIATION_STATUS_DISABLED_BY_SWITCH));
53 EXPECT_EQ(
54 expected_disabled_by_config, 49 expected_disabled_by_config,
55 GetCountWithoutSnapshot(translate::TranslateBrowserMetrics:: 50 GetCountWithoutSnapshot(translate::TranslateBrowserMetrics::
56 INITIATION_STATUS_DISABLED_BY_CONFIG)); 51 INITIATION_STATUS_DISABLED_BY_CONFIG));
57 EXPECT_EQ( 52 EXPECT_EQ(
58 expected_disabled_by_build, 53 expected_disabled_by_build,
59 GetCountWithoutSnapshot(translate::TranslateBrowserMetrics:: 54 GetCountWithoutSnapshot(translate::TranslateBrowserMetrics::
60 INITIATION_STATUS_DISABLED_BY_KEY)); 55 INITIATION_STATUS_DISABLED_BY_KEY));
61 EXPECT_EQ(expected_language_is_not_supported, 56 EXPECT_EQ(expected_language_is_not_supported,
62 GetCountWithoutSnapshot( 57 GetCountWithoutSnapshot(
63 translate::TranslateBrowserMetrics:: 58 translate::TranslateBrowserMetrics::
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 120
126 DISALLOW_COPY_AND_ASSIGN(MetricsRecorder); 121 DISALLOW_COPY_AND_ASSIGN(MetricsRecorder);
127 }; 122 };
128 123
129 } // namespace 124 } // namespace
130 125
131 TEST(TranslateBrowserMetricsTest, ReportInitiationStatus) { 126 TEST(TranslateBrowserMetricsTest, ReportInitiationStatus) {
132 MetricsRecorder recorder(translate::TranslateBrowserMetrics::GetMetricsName( 127 MetricsRecorder recorder(translate::TranslateBrowserMetrics::GetMetricsName(
133 translate::TranslateBrowserMetrics::UMA_INITIATION_STATUS)); 128 translate::TranslateBrowserMetrics::UMA_INITIATION_STATUS));
134 129
135 recorder.CheckInitiationStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 130 recorder.CheckInitiationStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
136 translate::TranslateBrowserMetrics::ReportInitiationStatus( 131 translate::TranslateBrowserMetrics::ReportInitiationStatus(
137 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); 132 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS);
138 recorder.CheckInitiationStatus(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 133 recorder.CheckInitiationStatus(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
139 translate::TranslateBrowserMetrics::ReportInitiationStatus(
140 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH);
141 recorder.CheckInitiationStatus(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
142 translate::TranslateBrowserMetrics::ReportInitiationStatus( 134 translate::TranslateBrowserMetrics::ReportInitiationStatus(
143 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG); 135 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG);
144 recorder.CheckInitiationStatus(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); 136 recorder.CheckInitiationStatus(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
145 translate::TranslateBrowserMetrics::ReportInitiationStatus( 137 translate::TranslateBrowserMetrics::ReportInitiationStatus(
146 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY); 138 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_KEY);
147 recorder.CheckInitiationStatus(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0); 139 recorder.CheckInitiationStatus(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0);
148 translate::TranslateBrowserMetrics::ReportInitiationStatus( 140 translate::TranslateBrowserMetrics::ReportInitiationStatus(
149 translate::TranslateBrowserMetrics:: 141 translate::TranslateBrowserMetrics::
150 INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED); 142 INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED);
151 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0); 143 recorder.CheckInitiationStatus(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0);
152 translate::TranslateBrowserMetrics::ReportInitiationStatus( 144 translate::TranslateBrowserMetrics::ReportInitiationStatus(
153 translate::TranslateBrowserMetrics:: 145 translate::TranslateBrowserMetrics::
154 INITIATION_STATUS_MIME_TYPE_IS_NOT_SUPPORTED); 146 INITIATION_STATUS_MIME_TYPE_IS_NOT_SUPPORTED);
155 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0); 147 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0);
156 translate::TranslateBrowserMetrics::ReportInitiationStatus( 148 translate::TranslateBrowserMetrics::ReportInitiationStatus(
157 translate::TranslateBrowserMetrics:: 149 translate::TranslateBrowserMetrics::
158 INITIATION_STATUS_URL_IS_NOT_SUPPORTED); 150 INITIATION_STATUS_URL_IS_NOT_SUPPORTED);
159 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0); 151 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0);
160 translate::TranslateBrowserMetrics::ReportInitiationStatus( 152 translate::TranslateBrowserMetrics::ReportInitiationStatus(
161 translate::TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); 153 translate::TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES);
162 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0); 154 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0);
163 translate::TranslateBrowserMetrics::ReportInitiationStatus( 155 translate::TranslateBrowserMetrics::ReportInitiationStatus(
164 translate::TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES); 156 translate::TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES);
165 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0); 157 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0);
166 translate::TranslateBrowserMetrics::ReportInitiationStatus( 158 translate::TranslateBrowserMetrics::ReportInitiationStatus(
167 translate::TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_CONFIG); 159 translate::TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_CONFIG);
168 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0); 160 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0);
169 translate::TranslateBrowserMetrics::ReportInitiationStatus( 161 translate::TranslateBrowserMetrics::ReportInitiationStatus(
170 translate::TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_LINK); 162 translate::TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_LINK);
171 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0); 163 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
172 translate::TranslateBrowserMetrics::ReportInitiationStatus( 164 translate::TranslateBrowserMetrics::ReportInitiationStatus(
173 translate::TranslateBrowserMetrics::INITIATION_STATUS_SHOW_INFOBAR); 165 translate::TranslateBrowserMetrics::INITIATION_STATUS_SHOW_INFOBAR);
174 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1); 166 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
175 } 167 }
176 168
177 TEST(TranslateBrowserMetricsTest, ReportLanguageDetectionError) { 169 TEST(TranslateBrowserMetricsTest, ReportLanguageDetectionError) {
178 MetricsRecorder recorder(translate::TranslateBrowserMetrics::GetMetricsName( 170 MetricsRecorder recorder(translate::TranslateBrowserMetrics::GetMetricsName(
179 translate::TranslateBrowserMetrics::UMA_LANGUAGE_DETECTION_ERROR)); 171 translate::TranslateBrowserMetrics::UMA_LANGUAGE_DETECTION_ERROR));
180 EXPECT_EQ(0, recorder.GetTotalCount()); 172 EXPECT_EQ(0, recorder.GetTotalCount());
181 translate::TranslateBrowserMetrics::ReportLanguageDetectionError(); 173 translate::TranslateBrowserMetrics::ReportLanguageDetectionError();
182 EXPECT_EQ(1, recorder.GetTotalCount()); 174 EXPECT_EQ(1, recorder.GetTotalCount());
183 175
184 } 176 }
(...skipping 23 matching lines...) Expand all
208 const int ENGLISH = 25966; 200 const int ENGLISH = 25966;
209 201
210 MetricsRecorder recorder(translate::TranslateBrowserMetrics::GetMetricsName( 202 MetricsRecorder recorder(translate::TranslateBrowserMetrics::GetMetricsName(
211 translate::TranslateBrowserMetrics:: 203 translate::TranslateBrowserMetrics::
212 UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION)); 204 UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION));
213 EXPECT_EQ(0, recorder.GetTotalCount()); 205 EXPECT_EQ(0, recorder.GetTotalCount());
214 translate::TranslateBrowserMetrics::ReportUnsupportedLanguageAtInitiation( 206 translate::TranslateBrowserMetrics::ReportUnsupportedLanguageAtInitiation(
215 "en"); 207 "en");
216 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); 208 EXPECT_EQ(1, recorder.GetCount(ENGLISH));
217 } 209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698