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

Unified Diff: components/translate/common/translate_metrics_unittest.cc

Issue 25531002: Move language detection to a component (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Run translate unittests on iOS Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/translate/common/translate_metrics.cc ('k') | components/translate/common/translate_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/translate/common/translate_metrics_unittest.cc
diff --git a/chrome/common/translate/translate_common_metrics_unittest.cc b/components/translate/common/translate_metrics_unittest.cc
similarity index 46%
rename from chrome/common/translate/translate_common_metrics_unittest.cc
rename to components/translate/common/translate_metrics_unittest.cc
index cd0753eb8b3ca956276ebf1dd1df4165c798c759..dac4b09162d88f9c72dbd2f33a2ec03d20804fe4 100644
--- a/chrome/common/translate/translate_common_metrics_unittest.cc
+++ b/components/translate/common/translate_metrics_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/common/translate/translate_common_metrics.h"
+#include "components/translate/common/translate_metrics.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
@@ -33,23 +33,20 @@ class MetricsRecorder {
base_samples_ = histogram->SnapshotSamples();
}
- void CheckLanguage(TranslateCommonMetrics::MetricsNameIndex index,
+ void CheckLanguage(translate::MetricsNameIndex index,
int expected_not_provided,
int expected_valid,
int expected_invalid) {
- ASSERT_EQ(TranslateCommonMetrics::GetMetricsName(index), key_);
+ ASSERT_EQ(translate::GetMetricsName(index), key_);
Snapshot();
EXPECT_EQ(expected_not_provided,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_NOT_PROVIDED));
+ GetCountWithoutSnapshot(translate::LANGUAGE_NOT_PROVIDED));
EXPECT_EQ(expected_valid,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_VALID));
+ GetCountWithoutSnapshot(translate::LANGUAGE_VALID));
EXPECT_EQ(expected_invalid,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_INVALID));
+ GetCountWithoutSnapshot(translate::LANGUAGE_INVALID));
}
void CheckLanguageVerification(int expected_cld_disabled,
@@ -59,54 +56,43 @@ class MetricsRecorder {
int expected_cld_disagree,
int expected_trust_cld,
int expected_cld_complement_sub_code) {
- ASSERT_EQ(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_LANGUAGE_VERIFICATION), key_);
+ ASSERT_EQ(translate::GetMetricsName(translate::UMA_LANGUAGE_VERIFICATION),
+ key_);
Snapshot();
EXPECT_EQ(
expected_cld_disabled,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_DISABLED));
+ GetCountWithoutSnapshot(translate::LANGUAGE_VERIFICATION_CLD_DISABLED));
EXPECT_EQ(
expected_cld_only,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_ONLY));
+ GetCountWithoutSnapshot(translate::LANGUAGE_VERIFICATION_CLD_ONLY));
EXPECT_EQ(
expected_unknown,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_UNKNOWN));
+ GetCountWithoutSnapshot(translate::LANGUAGE_VERIFICATION_UNKNOWN));
EXPECT_EQ(
expected_cld_agree,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_AGREE));
+ GetCountWithoutSnapshot(translate::LANGUAGE_VERIFICATION_CLD_AGREE));
EXPECT_EQ(
expected_cld_disagree,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_DISAGREE));
+ GetCountWithoutSnapshot(translate::LANGUAGE_VERIFICATION_CLD_DISAGREE));
EXPECT_EQ(
expected_trust_cld,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_TRUST_CLD));
- EXPECT_EQ(
- expected_cld_complement_sub_code,
- GetCountWithoutSnapshot(
- TranslateCommonMetrics::
- LANGUAGE_VERIFICATION_CLD_COMPLEMENT_SUB_CODE));
+ GetCountWithoutSnapshot(translate::LANGUAGE_VERIFICATION_TRUST_CLD));
+ EXPECT_EQ(expected_cld_complement_sub_code,
+ GetCountWithoutSnapshot(
+ translate::LANGUAGE_VERIFICATION_CLD_COMPLEMENT_SUB_CODE));
}
void CheckScheme(int expected_http, int expected_https, int expected_others) {
- ASSERT_EQ(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_PAGE_SCHEME), key_);
+ ASSERT_EQ(translate::GetMetricsName(translate::UMA_PAGE_SCHEME), key_);
Snapshot();
- EXPECT_EQ(expected_http,
- GetCountWithoutSnapshot(TranslateCommonMetrics::SCHEME_HTTP));
- EXPECT_EQ(expected_https,
- GetCountWithoutSnapshot(TranslateCommonMetrics::SCHEME_HTTPS));
+ EXPECT_EQ(expected_http, GetCountWithoutSnapshot(translate::SCHEME_HTTP));
+ EXPECT_EQ(expected_https, GetCountWithoutSnapshot(translate::SCHEME_HTTPS));
EXPECT_EQ(expected_others,
- GetCountWithoutSnapshot(TranslateCommonMetrics::SCHEME_OTHERS));
+ GetCountWithoutSnapshot(translate::SCHEME_OTHERS));
}
void CheckTotalCount(int count) {
@@ -117,8 +103,7 @@ class MetricsRecorder {
void CheckValueInLogs(double value) {
Snapshot();
ASSERT_TRUE(samples_.get());
- for (scoped_ptr<SampleCountIterator> i = samples_->Iterator();
- !i->Done();
+ for (scoped_ptr<SampleCountIterator> i = samples_->Iterator(); !i->Done();
i->Next()) {
HistogramBase::Sample min;
HistogramBase::Sample max;
@@ -170,131 +155,130 @@ class MetricsRecorder {
} // namespace
-TEST(TranslateCommonMetricsTest, ReportContentLanguage) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_CONTENT_LANGUAGE));
-
- recorder.CheckLanguage(TranslateCommonMetrics::UMA_CONTENT_LANGUAGE, 0, 0, 0);
- TranslateCommonMetrics::ReportContentLanguage(std::string(), std::string());
- recorder.CheckLanguage(TranslateCommonMetrics::UMA_CONTENT_LANGUAGE, 1, 0, 0);
- TranslateCommonMetrics::ReportContentLanguage("ja_JP", "ja-JP");
- recorder.CheckLanguage(TranslateCommonMetrics::UMA_CONTENT_LANGUAGE, 1, 0, 1);
- TranslateCommonMetrics::ReportContentLanguage("en", "en");
- recorder.CheckLanguage(TranslateCommonMetrics::UMA_CONTENT_LANGUAGE, 1, 1, 1);
+TEST(TranslateMetricsTest, ReportContentLanguage) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_CONTENT_LANGUAGE));
+
+ recorder.CheckLanguage(translate::UMA_CONTENT_LANGUAGE, 0, 0, 0);
+ translate::ReportContentLanguage(std::string(), std::string());
+ recorder.CheckLanguage(translate::UMA_CONTENT_LANGUAGE, 1, 0, 0);
+ translate::ReportContentLanguage("ja_JP", "ja-JP");
+ recorder.CheckLanguage(translate::UMA_CONTENT_LANGUAGE, 1, 0, 1);
+ translate::ReportContentLanguage("en", "en");
+ recorder.CheckLanguage(translate::UMA_CONTENT_LANGUAGE, 1, 1, 1);
}
-TEST(TranslateCommonMetricsTest, ReportHtmlLang) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_HTML_LANG));
-
- recorder.CheckLanguage(TranslateCommonMetrics::UMA_HTML_LANG, 0, 0, 0);
- TranslateCommonMetrics::ReportHtmlLang(std::string(), std::string());
- recorder.CheckLanguage(TranslateCommonMetrics::UMA_HTML_LANG, 1, 0, 0);
- TranslateCommonMetrics::ReportHtmlLang("ja_JP", "ja-JP");
- recorder.CheckLanguage(TranslateCommonMetrics::UMA_HTML_LANG, 1, 0, 1);
- TranslateCommonMetrics::ReportHtmlLang("en", "en");
- recorder.CheckLanguage(TranslateCommonMetrics::UMA_HTML_LANG, 1, 1, 1);
+TEST(TranslateMetricsTest, ReportHtmlLang) {
+ MetricsRecorder recorder(translate::GetMetricsName(translate::UMA_HTML_LANG));
+
+ recorder.CheckLanguage(translate::UMA_HTML_LANG, 0, 0, 0);
+ translate::ReportHtmlLang(std::string(), std::string());
+ recorder.CheckLanguage(translate::UMA_HTML_LANG, 1, 0, 0);
+ translate::ReportHtmlLang("ja_JP", "ja-JP");
+ recorder.CheckLanguage(translate::UMA_HTML_LANG, 1, 0, 1);
+ translate::ReportHtmlLang("en", "en");
+ recorder.CheckLanguage(translate::UMA_HTML_LANG, 1, 1, 1);
}
-TEST(TranslateCommonMetricsTest, ReportLanguageVerification) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_LANGUAGE_VERIFICATION));
+TEST(TranslateMetricsTest, ReportLanguageVerification) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_LANGUAGE_VERIFICATION));
recorder.CheckLanguageVerification(0, 0, 0, 0, 0, 0, 0);
- TranslateCommonMetrics::ReportLanguageVerification(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_DISABLED);
+ translate::ReportLanguageVerification(
+ translate::LANGUAGE_VERIFICATION_CLD_DISABLED);
recorder.CheckLanguageVerification(1, 0, 0, 0, 0, 0, 0);
- TranslateCommonMetrics::ReportLanguageVerification(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_ONLY);
+ translate::ReportLanguageVerification(
+ translate::LANGUAGE_VERIFICATION_CLD_ONLY);
recorder.CheckLanguageVerification(1, 1, 0, 0, 0, 0, 0);
- TranslateCommonMetrics::ReportLanguageVerification(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_UNKNOWN);
+ translate::ReportLanguageVerification(
+ translate::LANGUAGE_VERIFICATION_UNKNOWN);
recorder.CheckLanguageVerification(1, 1, 1, 0, 0, 0, 0);
- TranslateCommonMetrics::ReportLanguageVerification(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_AGREE);
+ translate::ReportLanguageVerification(
+ translate::LANGUAGE_VERIFICATION_CLD_AGREE);
recorder.CheckLanguageVerification(1, 1, 1, 1, 0, 0, 0);
- TranslateCommonMetrics::ReportLanguageVerification(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_DISAGREE);
+ translate::ReportLanguageVerification(
+ translate::LANGUAGE_VERIFICATION_CLD_DISAGREE);
recorder.CheckLanguageVerification(1, 1, 1, 1, 1, 0, 0);
- TranslateCommonMetrics::ReportLanguageVerification(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_TRUST_CLD);
+ translate::ReportLanguageVerification(
+ translate::LANGUAGE_VERIFICATION_TRUST_CLD);
recorder.CheckLanguageVerification(1, 1, 1, 1, 1, 1, 0);
- TranslateCommonMetrics::ReportLanguageVerification(
- TranslateCommonMetrics::LANGUAGE_VERIFICATION_CLD_COMPLEMENT_SUB_CODE);
+ translate::ReportLanguageVerification(
+ translate::LANGUAGE_VERIFICATION_CLD_COMPLEMENT_SUB_CODE);
recorder.CheckLanguageVerification(1, 1, 1, 1, 1, 1, 1);
}
-TEST(TranslateCommonMetricsTest, ReportTimeToBeReady) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_TIME_TO_BE_READY));
+TEST(TranslateMetricsTest, ReportTimeToBeReady) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_TIME_TO_BE_READY));
recorder.CheckTotalCount(0);
- TranslateCommonMetrics::ReportTimeToBeReady(3.14);
+ translate::ReportTimeToBeReady(3.14);
recorder.CheckValueInLogs(3.14);
recorder.CheckTotalCount(1);
}
-TEST(TranslateCommonMetricsTest, ReportTimeToLoad) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_TIME_TO_LOAD));
+TEST(TranslateMetricsTest, ReportTimeToLoad) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_TIME_TO_LOAD));
recorder.CheckTotalCount(0);
- TranslateCommonMetrics::ReportTimeToLoad(573.0);
+ translate::ReportTimeToLoad(573.0);
recorder.CheckValueInLogs(573.0);
recorder.CheckTotalCount(1);
}
-TEST(TranslateCommonMetricsTest, ReportTimeToTranslate) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_TIME_TO_TRANSLATE));
+TEST(TranslateMetricsTest, ReportTimeToTranslate) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_TIME_TO_TRANSLATE));
recorder.CheckTotalCount(0);
- TranslateCommonMetrics::ReportTimeToTranslate(4649.0);
+ translate::ReportTimeToTranslate(4649.0);
recorder.CheckValueInLogs(4649.0);
recorder.CheckTotalCount(1);
}
-TEST(TranslateCommonMetricsTest, ReportUserActionDuration) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_USER_ACTION_DURATION));
+TEST(TranslateMetricsTest, ReportUserActionDuration) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_USER_ACTION_DURATION));
recorder.CheckTotalCount(0);
TimeTicks begin = TimeTicks::Now();
TimeTicks end = begin + base::TimeDelta::FromSeconds(3776);
- TranslateCommonMetrics::ReportUserActionDuration(begin, end);
+ translate::ReportUserActionDuration(begin, end);
recorder.CheckValueInLogs(3776000.0);
recorder.CheckTotalCount(1);
}
-TEST(TranslateCommonMetricsTest, ReportPageScheme) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_PAGE_SCHEME));
+TEST(TranslateMetricsTest, ReportPageScheme) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_PAGE_SCHEME));
recorder.CheckScheme(0, 0, 0);
- TranslateCommonMetrics::ReportPageScheme("http");
+ translate::ReportPageScheme("http");
recorder.CheckScheme(1, 0, 0);
- TranslateCommonMetrics::ReportPageScheme("https");
+ translate::ReportPageScheme("https");
recorder.CheckScheme(1, 1, 0);
- TranslateCommonMetrics::ReportPageScheme("ftp");
+ translate::ReportPageScheme("ftp");
recorder.CheckScheme(1, 1, 1);
}
-TEST(TranslateCommonMetricsTest, ReportSimilarLanguageMatch) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_SIMILAR_LANGUAGE_MATCH));
+TEST(TranslateMetricsTest, ReportSimilarLanguageMatch) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_SIMILAR_LANGUAGE_MATCH));
recorder.CheckTotalCount(0);
EXPECT_EQ(0, recorder.GetCount(kTrue));
EXPECT_EQ(0, recorder.GetCount(kFalse));
- TranslateCommonMetrics::ReportSimilarLanguageMatch(true);
+ translate::ReportSimilarLanguageMatch(true);
EXPECT_EQ(1, recorder.GetCount(kTrue));
EXPECT_EQ(0, recorder.GetCount(kFalse));
- TranslateCommonMetrics::ReportSimilarLanguageMatch(false);
+ translate::ReportSimilarLanguageMatch(false);
EXPECT_EQ(1, recorder.GetCount(kTrue));
EXPECT_EQ(1, recorder.GetCount(kFalse));
}
-TEST(TranslateCommonMetricsTest, ReportLanguageDetectionTime) {
- MetricsRecorder recorder(TranslateCommonMetrics::GetMetricsName(
- TranslateCommonMetrics::UMA_LANGUAGE_DETECTION));
+TEST(TranslateMetricsTest, ReportLanguageDetectionTime) {
+ MetricsRecorder recorder(
+ translate::GetMetricsName(translate::UMA_LANGUAGE_DETECTION));
recorder.CheckTotalCount(0);
TimeTicks begin = TimeTicks::Now();
TimeTicks end = begin + base::TimeDelta::FromMicroseconds(9009);
- TranslateCommonMetrics::ReportLanguageDetectionTime(begin, end);
+ translate::ReportLanguageDetectionTime(begin, end);
recorder.CheckValueInLogs(9.009);
recorder.CheckTotalCount(1);
}
« no previous file with comments | « components/translate/common/translate_metrics.cc ('k') | components/translate/common/translate_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698