| 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 21 matching lines...) Expand all Loading... |
| 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, GetCountWithoutSnapshot( | 46 EXPECT_EQ(expected_disabled_by_prefs, GetCountWithoutSnapshot( |
| 47 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_PREFS)); | 47 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS)); |
| 48 EXPECT_EQ(expected_disabled_by_switch, GetCountWithoutSnapshot( | 48 EXPECT_EQ(expected_disabled_by_switch, GetCountWithoutSnapshot( |
| 49 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH)); | 49 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH)); |
| 50 EXPECT_EQ(expected_disabled_by_config, GetCountWithoutSnapshot( | 50 EXPECT_EQ(expected_disabled_by_config, GetCountWithoutSnapshot( |
| 51 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG)); | 51 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG)); |
| 52 EXPECT_EQ(expected_language_is_not_supported, GetCountWithoutSnapshot( | 52 EXPECT_EQ(expected_language_is_not_supported, GetCountWithoutSnapshot( |
| 53 TranslateManagerMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED)); | 53 TranslateBrowserMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED)); |
| 54 EXPECT_EQ(expected_url_is_not_supported, GetCountWithoutSnapshot( | 54 EXPECT_EQ(expected_url_is_not_supported, GetCountWithoutSnapshot( |
| 55 TranslateManagerMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED)); | 55 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED)); |
| 56 EXPECT_EQ(expected_similar_languages, GetCountWithoutSnapshot( | 56 EXPECT_EQ(expected_similar_languages, GetCountWithoutSnapshot( |
| 57 TranslateManagerMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES)); | 57 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES)); |
| 58 EXPECT_EQ(expected_accept_languages, GetCountWithoutSnapshot( | 58 EXPECT_EQ(expected_accept_languages, GetCountWithoutSnapshot( |
| 59 TranslateManagerMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES)); | 59 TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES)); |
| 60 EXPECT_EQ(expected_auto_by_config, GetCountWithoutSnapshot( | 60 EXPECT_EQ(expected_auto_by_config, GetCountWithoutSnapshot( |
| 61 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_CONFIG)); | 61 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_CONFIG)); |
| 62 EXPECT_EQ(expected_auto_by_link, GetCountWithoutSnapshot( | 62 EXPECT_EQ(expected_auto_by_link, GetCountWithoutSnapshot( |
| 63 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_LINK)); | 63 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_LINK)); |
| 64 EXPECT_EQ(expected_show_infobar, GetCountWithoutSnapshot( | 64 EXPECT_EQ(expected_show_infobar, GetCountWithoutSnapshot( |
| 65 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR)); | 65 TranslateBrowserMetrics::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(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 99 | 99 |
| 100 std::string key_; | 100 std::string key_; |
| 101 scoped_ptr<HistogramSamples> base_samples_; | 101 scoped_ptr<HistogramSamples> base_samples_; |
| 102 scoped_ptr<HistogramSamples> samples_; | 102 scoped_ptr<HistogramSamples> samples_; |
| 103 | 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(MetricsRecorder); | 104 DISALLOW_COPY_AND_ASSIGN(MetricsRecorder); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 TEST(TranslateManagerMetricsTest, ReportInitiationStatus) { | 109 TEST(TranslateBrowserMetricsTest, ReportInitiationStatus) { |
| 110 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 110 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
| 111 TranslateManagerMetrics::UMA_INITIATION_STATUS)); | 111 TranslateBrowserMetrics::UMA_INITIATION_STATUS)); |
| 112 | 112 |
| 113 recorder.CheckInitiationStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 113 recorder.CheckInitiationStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
| 114 TranslateManagerMetrics::ReportInitiationStatus( | 114 TranslateBrowserMetrics::ReportInitiationStatus( |
| 115 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); | 115 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS); |
| 116 recorder.CheckInitiationStatus(1, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 116 recorder.CheckInitiationStatus(1, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
| 117 TranslateManagerMetrics::ReportInitiationStatus( | 117 TranslateBrowserMetrics::ReportInitiationStatus( |
| 118 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH); | 118 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH); |
| 119 recorder.CheckInitiationStatus(1, 1, 0, 0, 0, 0, 0, 0, 0, 0); | 119 recorder.CheckInitiationStatus(1, 1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 120 TranslateManagerMetrics::ReportInitiationStatus( | 120 TranslateBrowserMetrics::ReportInitiationStatus( |
| 121 TranslateManagerMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG); | 121 TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_CONFIG); |
| 122 recorder.CheckInitiationStatus(1, 1, 1, 0, 0, 0, 0, 0, 0, 0); | 122 recorder.CheckInitiationStatus(1, 1, 1, 0, 0, 0, 0, 0, 0, 0); |
| 123 TranslateManagerMetrics::ReportInitiationStatus( | 123 TranslateBrowserMetrics::ReportInitiationStatus( |
| 124 TranslateManagerMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED); | 124 TranslateBrowserMetrics::INITIATION_STATUS_LANGUAGE_IS_NOT_SUPPORTED); |
| 125 recorder.CheckInitiationStatus(1, 1, 1, 1, 0, 0, 0, 0, 0, 0); | 125 recorder.CheckInitiationStatus(1, 1, 1, 1, 0, 0, 0, 0, 0, 0); |
| 126 TranslateManagerMetrics::ReportInitiationStatus( | 126 TranslateBrowserMetrics::ReportInitiationStatus( |
| 127 TranslateManagerMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); | 127 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); |
| 128 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 0, 0, 0, 0, 0); | 128 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 0, 0, 0, 0, 0); |
| 129 TranslateManagerMetrics::ReportInitiationStatus( | 129 TranslateBrowserMetrics::ReportInitiationStatus( |
| 130 TranslateManagerMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); | 130 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); |
| 131 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 0, 0, 0, 0); | 131 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 0, 0, 0, 0); |
| 132 TranslateManagerMetrics::ReportInitiationStatus( | 132 TranslateBrowserMetrics::ReportInitiationStatus( |
| 133 TranslateManagerMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES); | 133 TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES); |
| 134 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 0, 0, 0); | 134 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 0, 0, 0); |
| 135 TranslateManagerMetrics::ReportInitiationStatus( | 135 TranslateBrowserMetrics::ReportInitiationStatus( |
| 136 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_CONFIG); | 136 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_CONFIG); |
| 137 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 0, 0); | 137 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 0, 0); |
| 138 TranslateManagerMetrics::ReportInitiationStatus( | 138 TranslateBrowserMetrics::ReportInitiationStatus( |
| 139 TranslateManagerMetrics::INITIATION_STATUS_AUTO_BY_LINK); | 139 TranslateBrowserMetrics::INITIATION_STATUS_AUTO_BY_LINK); |
| 140 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 0); | 140 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 0); |
| 141 TranslateManagerMetrics::ReportInitiationStatus( | 141 TranslateBrowserMetrics::ReportInitiationStatus( |
| 142 TranslateManagerMetrics::INITIATION_STATUS_SHOW_INFOBAR); | 142 TranslateBrowserMetrics::INITIATION_STATUS_SHOW_INFOBAR); |
| 143 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); | 143 recorder.CheckInitiationStatus(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST(TranslateManagerMetricsTest, ReportLanguageDetectionError) { | 146 TEST(TranslateBrowserMetricsTest, ReportLanguageDetectionError) { |
| 147 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 147 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
| 148 TranslateManagerMetrics::UMA_LANGUAGE_DETECTION_ERROR)); | 148 TranslateBrowserMetrics::UMA_LANGUAGE_DETECTION_ERROR)); |
| 149 EXPECT_EQ(0, recorder.GetTotalCount()); | 149 EXPECT_EQ(0, recorder.GetTotalCount()); |
| 150 TranslateManagerMetrics::ReportLanguageDetectionError(); | 150 TranslateBrowserMetrics::ReportLanguageDetectionError(); |
| 151 EXPECT_EQ(1, recorder.GetTotalCount()); | 151 EXPECT_EQ(1, recorder.GetTotalCount()); |
| 152 | 152 |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguage) { | 155 TEST(TranslateBrowserMetricsTest, ReportedUnsupportedLanguageAtInitiation) { |
| 156 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 156 const int ENGLISH = 25966; |
| 157 TranslateManagerMetrics::UMA_SERVER_REPORTED_UNSUPPORTED_LANGUAGE)); | 157 |
| 158 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
| 159 TranslateBrowserMetrics::UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION)); |
| 158 EXPECT_EQ(0, recorder.GetTotalCount()); | 160 EXPECT_EQ(0, recorder.GetTotalCount()); |
| 159 TranslateManagerMetrics::ReportUnsupportedLanguage(); | 161 TranslateBrowserMetrics::ReportUnsupportedLanguageAtInitiation("en"); |
| 160 EXPECT_EQ(1, recorder.GetTotalCount()); | 162 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); |
| 161 } | 163 } |
| 162 | 164 |
| 163 TEST(TranslateManagerMetricsTest, ReportedUnsupportedLanguageAtInitiation) { | 165 TEST(TranslateBrowserMetricsTest, ReportedUndisplayableLanguage) { |
| 164 const int ENGLISH = 25966; | 166 const int ENGLISH = 25966; |
| 165 | 167 |
| 166 MetricsRecorder recorder(TranslateManagerMetrics::GetMetricsName( | 168 MetricsRecorder recorder(TranslateBrowserMetrics::GetMetricsName( |
| 167 TranslateManagerMetrics::UMA_UNSUPPORTED_LANGUAGE_AT_INITIATION)); | 169 TranslateBrowserMetrics::UMA_UNDISPLAYABLE_LANGUAGE)); |
| 168 EXPECT_EQ(0, recorder.GetTotalCount()); | 170 EXPECT_EQ(0, recorder.GetTotalCount()); |
| 169 TranslateManagerMetrics::ReportUnsupportedLanguageAtInitiation("en"); | 171 TranslateBrowserMetrics::ReportUndisplayableLanguage("en"); |
| 170 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); | 172 EXPECT_EQ(1, recorder.GetCount(ENGLISH)); |
| 171 } | 173 } |
| OLD | NEW |