| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() { |
| 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 Loading... |
| 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()); |
| 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 } |
| OLD | NEW |