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

Unified Diff: chrome/common/translate/language_detection_util_unittest.cc

Issue 18911002: Move language detection to chrome/common/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 5 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
Index: chrome/common/translate/language_detection_util_unittest.cc
diff --git a/chrome/renderer/translate/translate_helper_unittest.cc b/chrome/common/translate/language_detection_util_unittest.cc
similarity index 48%
rename from chrome/renderer/translate/translate_helper_unittest.cc
rename to chrome/common/translate/language_detection_util_unittest.cc
index f1d21610544c76b64b64623a5a7a26ae83405046..4f8dbf3fbdb80f41cd279283f620890af7d7d3c3 100644
--- a/chrome/renderer/translate/translate_helper_unittest.cc
+++ b/chrome/common/translate/language_detection_util_unittest.cc
@@ -1,98 +1,102 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/renderer/translate/translate_helper.h"
+#include "chrome/common/translate/language_detection_util.h"
+#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/chrome_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
-typedef testing::Test TranslateHelperTest;
+typedef testing::Test LanguageDetectionUtilTest;
// Tests that well-known language code typos are fixed.
-TEST_F(TranslateHelperTest, LanguageCodeTypoCorrection) {
+TEST_F(LanguageDetectionUtilTest, LanguageCodeTypoCorrection) {
std::string language;
// Strip the second and later codes.
language = std::string("ja,en");
- TranslateHelper::CorrectLanguageCodeTypo(&language);
+ LanguageDetectionUtil::CorrectLanguageCodeTypo(&language);
EXPECT_EQ("ja", language);
// Replace dash with hyphen.
language = std::string("ja_JP");
- TranslateHelper::CorrectLanguageCodeTypo(&language);
+ LanguageDetectionUtil::CorrectLanguageCodeTypo(&language);
EXPECT_EQ("ja-JP", language);
// Correct wrong cases.
language = std::string("JA-jp");
- TranslateHelper::CorrectLanguageCodeTypo(&language);
+ LanguageDetectionUtil::CorrectLanguageCodeTypo(&language);
EXPECT_EQ("ja-JP", language);
}
// Tests if the language codes' format is invalid.
-TEST_F(TranslateHelperTest, IsValidLanguageCode) {
+TEST_F(LanguageDetectionUtilTest, IsValidLanguageCode) {
std::string language;
language = std::string("ja");
- EXPECT_TRUE(TranslateHelper::IsValidLanguageCode(language));
+ EXPECT_TRUE(LanguageDetectionUtil::IsValidLanguageCode(language));
language = std::string("ja-JP");
- EXPECT_TRUE(TranslateHelper::IsValidLanguageCode(language));
+ EXPECT_TRUE(LanguageDetectionUtil::IsValidLanguageCode(language));
language = std::string("ceb");
- EXPECT_TRUE(TranslateHelper::IsValidLanguageCode(language));
+ EXPECT_TRUE(LanguageDetectionUtil::IsValidLanguageCode(language));
language = std::string("ceb-XX");
- EXPECT_TRUE(TranslateHelper::IsValidLanguageCode(language));
+ EXPECT_TRUE(LanguageDetectionUtil::IsValidLanguageCode(language));
// Invalid because the sub code consists of a number.
language = std::string("utf-8");
- EXPECT_FALSE(TranslateHelper::IsValidLanguageCode(language));
+ EXPECT_FALSE(LanguageDetectionUtil::IsValidLanguageCode(language));
// Invalid because of six characters after hyphen.
language = std::string("ja-YUKARI");
- EXPECT_FALSE(TranslateHelper::IsValidLanguageCode(language));
+ EXPECT_FALSE(LanguageDetectionUtil::IsValidLanguageCode(language));
// Invalid because of four characters.
language = std::string("DHMO");
- EXPECT_FALSE(TranslateHelper::IsValidLanguageCode(language));
+ EXPECT_FALSE(LanguageDetectionUtil::IsValidLanguageCode(language));
}
// Tests that similar language table works.
-TEST_F(TranslateHelperTest, SimilarLanguageCode) {
- EXPECT_TRUE(TranslateHelper::IsSameOrSimilarLanguages("en", "en"));
- EXPECT_FALSE(TranslateHelper::IsSameOrSimilarLanguages("en", "ja"));
- EXPECT_TRUE(TranslateHelper::IsSameOrSimilarLanguages("bs", "hr"));
- EXPECT_TRUE(TranslateHelper::IsSameOrSimilarLanguages("sr-ME", "sr"));
- EXPECT_TRUE(TranslateHelper::IsSameOrSimilarLanguages("ne", "hi"));
- EXPECT_FALSE(TranslateHelper::IsSameOrSimilarLanguages("bs", "hi"));
+TEST_F(LanguageDetectionUtilTest, SimilarLanguageCode) {
+ EXPECT_TRUE(LanguageDetectionUtil::IsSameOrSimilarLanguages("en", "en"));
+ EXPECT_FALSE(LanguageDetectionUtil::IsSameOrSimilarLanguages("en", "ja"));
+ EXPECT_TRUE(LanguageDetectionUtil::IsSameOrSimilarLanguages("bs", "hr"));
+ EXPECT_TRUE(LanguageDetectionUtil::IsSameOrSimilarLanguages("sr-ME", "sr"));
+ EXPECT_TRUE(LanguageDetectionUtil::IsSameOrSimilarLanguages("ne", "hi"));
+ EXPECT_FALSE(LanguageDetectionUtil::IsSameOrSimilarLanguages("bs", "hi"));
}
// Tests that well-known languages which often have wrong server configuration
// are handles.
-TEST_F(TranslateHelperTest, WellKnownWrongConfiguration) {
- EXPECT_TRUE(TranslateHelper::MaybeServerWrongConfiguration("en", "ja"));
- EXPECT_TRUE(TranslateHelper::MaybeServerWrongConfiguration("en-US", "ja"));
- EXPECT_TRUE(TranslateHelper::MaybeServerWrongConfiguration("en", "zh-CN"));
- EXPECT_FALSE(TranslateHelper::MaybeServerWrongConfiguration("ja", "en"));
- EXPECT_FALSE(TranslateHelper::MaybeServerWrongConfiguration("en", "he"));
+TEST_F(LanguageDetectionUtilTest, WellKnownWrongConfiguration) {
+ EXPECT_TRUE(LanguageDetectionUtil::MaybeServerWrongConfiguration("en", "ja"));
+ EXPECT_TRUE(LanguageDetectionUtil::MaybeServerWrongConfiguration("en-US",
+ "ja"));
+ EXPECT_TRUE(LanguageDetectionUtil::MaybeServerWrongConfiguration("en",
+ "zh-CN"));
+ EXPECT_FALSE(LanguageDetectionUtil::MaybeServerWrongConfiguration("ja",
+ "en"));
+ EXPECT_FALSE(LanguageDetectionUtil::MaybeServerWrongConfiguration("en",
+ "he"));
}
// Tests that the language meta tag providing wrong information is ignored by
-// TranslateHelper due to disagreement between meta tag and CLD.
-TEST_F(TranslateHelperTest, CLDDisagreeWithWrongLanguageCode) {
- string16 contents = ASCIIToUTF16(
+// LanguageDetectionUtil due to disagreement between meta tag and CLD.
+TEST_F(LanguageDetectionUtilTest, CLDDisagreeWithWrongLanguageCode) {
+ base::string16 contents = ASCIIToUTF16(
"<html><head><meta http-equiv='Content-Language' content='ja'></head>"
"<body>This is a page apparently written in English. Even though "
"content-language is provided, the value will be ignored if the value "
"is suspicious.</body></html>");
std::string cld_language;
bool is_cld_reliable;
- std::string language =
- TranslateHelper::DeterminePageLanguage(std::string("ja"), std::string(),
- contents, &cld_language,
- &is_cld_reliable);
+ std::string language = LanguageDetectionUtil::DeterminePageLanguage(
+ std::string("ja"), std::string(), contents, &cld_language,
+ &is_cld_reliable);
EXPECT_EQ(chrome::kUnknownLanguageCode, language);
EXPECT_EQ("en", cld_language);
EXPECT_TRUE(is_cld_reliable);
@@ -100,37 +104,36 @@ TEST_F(TranslateHelperTest, CLDDisagreeWithWrongLanguageCode) {
// Tests that the language meta tag providing "en-US" style information is
// agreed by CLD.
-TEST_F(TranslateHelperTest, CLDAgreeWithLanguageCodeHavingCountryCode) {
- string16 contents = ASCIIToUTF16(
+TEST_F(LanguageDetectionUtilTest, CLDAgreeWithLanguageCodeHavingCountryCode) {
+ base::string16 contents = ASCIIToUTF16(
"<html><head><meta http-equiv='Content-Language' content='en-US'></head>"
"<body>This is a page apparently written in English. Even though "
"content-language is provided, the value will be ignored if the value "
"is suspicious.</body></html>");
std::string cld_language;
bool is_cld_reliable;
- std::string language =
- TranslateHelper::DeterminePageLanguage(std::string("en-US"),
- std::string(), contents,
- &cld_language, &is_cld_reliable);
+ std::string language = LanguageDetectionUtil::DeterminePageLanguage(
+ std::string("en-US"), std::string(), contents, &cld_language,
+ &is_cld_reliable);
EXPECT_EQ("en-US", language);
EXPECT_EQ("en", cld_language);
EXPECT_TRUE(is_cld_reliable);
}
// Tests that the language meta tag providing wrong information is ignored and
-// CLD's language will be adopted by TranslateHelper due to an invalid meta tag.
-TEST_F(TranslateHelperTest, InvalidLanguageMetaTagProviding) {
- string16 contents = ASCIIToUTF16(
+// CLD's language will be adopted by LanguageDetectionUtil due to an invalid
+// meta tag.
+TEST_F(LanguageDetectionUtilTest, InvalidLanguageMetaTagProviding) {
+ base::string16 contents = ASCIIToUTF16(
"<html><head><meta http-equiv='Content-Language' content='utf-8'></head>"
"<body>This is a page apparently written in English. Even though "
"content-language is provided, the value will be ignored and CLD's"
" language will be adopted if the value is invalid.</body></html>");
std::string cld_language;
bool is_cld_reliable;
- std::string language =
- TranslateHelper::DeterminePageLanguage(std::string("utf-8"),
- std::string(), contents,
- &cld_language, &is_cld_reliable);
+ std::string language = LanguageDetectionUtil::DeterminePageLanguage(
+ std::string("utf-8"), std::string(), contents, &cld_language,
+ &is_cld_reliable);
EXPECT_EQ("en", language);
EXPECT_EQ("en", cld_language);
EXPECT_TRUE(is_cld_reliable);
@@ -138,19 +141,17 @@ TEST_F(TranslateHelperTest, InvalidLanguageMetaTagProviding) {
// Tests that the language meta tag providing wrong information is ignored
// because of valid html lang attribute.
-TEST_F(TranslateHelperTest, AdoptHtmlLang) {
- string16 contents = ASCIIToUTF16(
+TEST_F(LanguageDetectionUtilTest, AdoptHtmlLang) {
+ base::string16 contents = ASCIIToUTF16(
"<html lang='en'><head><meta http-equiv='Content-Language' content='ja'>"
"</head><body>This is a page apparently written in English. Even though "
"content-language is provided, the value will be ignored if the value "
"is suspicious.</body></html>");
std::string cld_language;
bool is_cld_reliable;
- std::string language =
- TranslateHelper::DeterminePageLanguage(std::string("ja"),
- std::string("en"),
- contents, &cld_language,
- &is_cld_reliable);
+ std::string language = LanguageDetectionUtil::DeterminePageLanguage(
+ std::string("ja"), std::string("en"), contents, &cld_language,
+ &is_cld_reliable);
EXPECT_EQ("en", language);
EXPECT_EQ("en", cld_language);
EXPECT_TRUE(is_cld_reliable);
« no previous file with comments | « chrome/common/translate/language_detection_util.cc ('k') | chrome/common/translate/translate_common_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698