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

Side by Side Diff: chrome/browser/translate/translate_manager_metrics_unittest.cc

Issue 15970002: Add the new UMA key 'Translate.LocalesOnDisabledByPrefs'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (Rebasing) Created 7 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 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
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, GetCountInternal(
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, GetCountInternal(
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, GetCountInternal(
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, GetCountInternal(
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, GetCountInternal(
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, GetCountInternal(
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, GetCountInternal(
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, GetCountInternal(
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, GetCountInternal(
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, GetCountInternal(
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 GetCountInternal(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 GetCountInternal(HistogramBase::Sample value) {
Takashi Toyoshima 2013/05/27 07:39:03 [optional] this function name is vague. can you re
hajimehoshi 2013/05/27 08:24:21 Ok, I'll rename this at https://chromiumcodereview
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 EXPECT_EQ(1, recorder.GetTotalCount()); 151 EXPECT_EQ(1, recorder.GetTotalCount());
147 } 152 }
148 153
149 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguage) { 154 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguage) {
150 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( 155 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName(
151 TranslateManagerMetrics::UMA_SERVER_REPORTED_UNSUPPORTED_LANGUAGE)); 156 TranslateManagerMetrics::UMA_SERVER_REPORTED_UNSUPPORTED_LANGUAGE));
152 EXPECT_EQ(0, recorder.GetTotalCount()); 157 EXPECT_EQ(0, recorder.GetTotalCount());
153 TranslateManagerMetrics::ReportUnsupportedLanguage(); 158 TranslateManagerMetrics::ReportUnsupportedLanguage();
154 EXPECT_EQ(1, recorder.GetTotalCount()); 159 EXPECT_EQ(1, recorder.GetTotalCount());
155 } 160 }
161
162 TEST(TranslateManagerMetricsTest, ReportedLocalesOnDisabledByPrefs) {
163 const int ENGLISH = 25966;
164
165 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName(
166 TranslateManagerMetrics::UMA_LOCALES_ON_DISABLED_BY_PREFS));
167 EXPECT_EQ(0, recorder.GetTotalCount());
168 TranslateManagerMetrics::ReportLocalesOnDisabledByPrefs("en");
169 EXPECT_EQ(1, recorder.GetCount(ENGLISH));
170 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_manager_metrics.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698