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

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

Issue 14762014: Translate: move UMA related code in TranslateManager to TranslateManagerMetrics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 EXPECT_EQ(expected_accept_languages, GetCount( 58 EXPECT_EQ(expected_accept_languages, GetCount(
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, GetCount(
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, GetCount(
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, GetCount(
65 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR)); 65 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR));
66 } 66 }
67 67
68 HistogramBase::Count GetTotalCount() {
MAD 2013/05/15 01:32:48 Why not make get public, and explicitly get the co
69 Snapshot();
70 if (!samples_.get())
71 return 0;
72 HistogramBase::Count count = samples_->TotalCount();
73 if (!base_samples_.get())
74 return count;
75 return count - base_samples_->TotalCount();
76 }
77
68 private: 78 private:
69 void Snapshot() { 79 void Snapshot() {
70 HistogramBase* histogram = StatisticsRecorder::FindHistogram(key_); 80 HistogramBase* histogram = StatisticsRecorder::FindHistogram(key_);
71 if (!histogram) 81 if (!histogram)
72 return; 82 return;
73 samples_ = histogram->SnapshotSamples(); 83 samples_ = histogram->SnapshotSamples();
74 } 84 }
75 85
76 HistogramBase::Count GetCount(HistogramBase::Sample value) { 86 HistogramBase::Count GetCount(HistogramBase::Sample value) {
77 if (!samples_.get()) 87 if (!samples_.get())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 TranslateManagerMetrics::ReportInitiationStatus( 130 TranslateManagerMetrics::ReportInitiationStatus(
121 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_CONFIG); 131 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_CONFIG);
122 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 0, 0); 132 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 0, 0);
123 TranslateManagerMetrics::ReportInitiationStatus( 133 TranslateManagerMetrics::ReportInitiationStatus(
124 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_LINK); 134 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_LINK);
125 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 0); 135 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
126 TranslateManagerMetrics::ReportInitiationStatus( 136 TranslateManagerMetrics::ReportInitiationStatus(
127 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR); 137 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR);
128 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); 138 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
129 } 139 }
140
141 TEST(TranslateManagerMetricsTest, ReportLanguageDetectionError) {
142 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName(
143 TranslateManagerMetrics::UMA_LANGUAGE_DETECTION_ERROR));
144 EXPECT_EQ(0, recorder.GetTotalCount());
145 TranslateManagerMetrics::ReportLanguageDetectionError();
146 EXPECT_EQ(1, recorder.GetTotalCount());
MAD 2013/05/15 01:32:48 As suggested before, we would be better making sur
Takashi Toyoshima 2013/05/15 07:35:04 I'n not sure I understand your comments correctly
MAD 2013/05/15 12:22:24 Ho! My goof... I forgot about the constructor rece
147 }
148
149 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguage) {
150 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName(
151 TranslateManagerMetrics::UMA_SERVER_REPORTED_UNSUPPORTED_LANGUAGE));
152 EXPECT_EQ(0, recorder.GetTotalCount());
153 TranslateManagerMetrics::ReportUnsupportedLanguage();
154 EXPECT_EQ(1, recorder.GetTotalCount());
155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698