| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/renderer/translate/translate_helper.h" | 5 #include "chrome/renderer/translate/translate_helper.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/common/chrome_constants.h" | 8 #include "chrome/common/chrome_constants.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Tests that the language meta tag providing wrong information is ignored by | 82 // Tests that the language meta tag providing wrong information is ignored by |
| 83 // TranslateHelper due to disagreement between meta tag and CLD. | 83 // TranslateHelper due to disagreement between meta tag and CLD. |
| 84 TEST_F(TranslateHelperTest, CLDDisagreeWithWrongLanguageCode) { | 84 TEST_F(TranslateHelperTest, CLDDisagreeWithWrongLanguageCode) { |
| 85 string16 contents = ASCIIToUTF16( | 85 string16 contents = ASCIIToUTF16( |
| 86 "<html><head><meta http-equiv='Content-Language' content='ja'></head>" | 86 "<html><head><meta http-equiv='Content-Language' content='ja'></head>" |
| 87 "<body>This is a page apparently written in English. Even though " | 87 "<body>This is a page apparently written in English. Even though " |
| 88 "content-language is provided, the value will be ignored if the value " | 88 "content-language is provided, the value will be ignored if the value " |
| 89 "is suspicious.</body></html>"); | 89 "is suspicious.</body></html>"); |
| 90 std::string cld_language; |
| 91 bool is_cld_reliable; |
| 90 std::string language = | 92 std::string language = |
| 91 TranslateHelper::DeterminePageLanguage(std::string("ja"), contents); | 93 TranslateHelper::DeterminePageLanguage(std::string("ja"), contents, |
| 94 &cld_language, &is_cld_reliable); |
| 92 EXPECT_EQ(chrome::kUnknownLanguageCode, language); | 95 EXPECT_EQ(chrome::kUnknownLanguageCode, language); |
| 96 EXPECT_EQ("en", cld_language); |
| 97 EXPECT_TRUE(is_cld_reliable); |
| 93 } | 98 } |
| 94 | 99 |
| 95 // Tests that the language meta tag providing "en-US" style information is | 100 // Tests that the language meta tag providing "en-US" style information is |
| 96 // agreed by CLD. | 101 // agreed by CLD. |
| 97 TEST_F(TranslateHelperTest, CLDAgreeWithLanguageCodeHavingCountryCode) { | 102 TEST_F(TranslateHelperTest, CLDAgreeWithLanguageCodeHavingCountryCode) { |
| 98 string16 contents = ASCIIToUTF16( | 103 string16 contents = ASCIIToUTF16( |
| 99 "<html><head><meta http-equiv='Content-Language' content='en-US'></head>" | 104 "<html><head><meta http-equiv='Content-Language' content='en-US'></head>" |
| 100 "<body>This is a page apparently written in English. Even though " | 105 "<body>This is a page apparently written in English. Even though " |
| 101 "content-language is provided, the value will be ignored if the value " | 106 "content-language is provided, the value will be ignored if the value " |
| 102 "is suspicious.</body></html>"); | 107 "is suspicious.</body></html>"); |
| 108 std::string cld_language; |
| 109 bool is_cld_reliable; |
| 103 std::string language = | 110 std::string language = |
| 104 TranslateHelper::DeterminePageLanguage(std::string("en-US"), contents); | 111 TranslateHelper::DeterminePageLanguage(std::string("en-US"), contents, |
| 112 &cld_language, &is_cld_reliable); |
| 105 EXPECT_EQ("en-US", language); | 113 EXPECT_EQ("en-US", language); |
| 114 EXPECT_EQ("en", cld_language); |
| 115 EXPECT_TRUE(is_cld_reliable); |
| 106 } | 116 } |
| 107 | 117 |
| 108 // Tests that the language meta tag providing wrong information is ignored and | 118 // Tests that the language meta tag providing wrong information is ignored and |
| 109 // CLD's language will be adopted by TranslateHelper due to an invalid meta tag. | 119 // CLD's language will be adopted by TranslateHelper due to an invalid meta tag. |
| 110 TEST_F(TranslateHelperTest, InvalidLanguageMetaTagProviding) { | 120 TEST_F(TranslateHelperTest, InvalidLanguageMetaTagProviding) { |
| 111 string16 contents = ASCIIToUTF16( | 121 string16 contents = ASCIIToUTF16( |
| 112 "<html><head><meta http-equiv='Content-Language' content='utf-8'></head>" | 122 "<html><head><meta http-equiv='Content-Language' content='utf-8'></head>" |
| 113 "<body>This is a page apparently written in English. Even though " | 123 "<body>This is a page apparently written in English. Even though " |
| 114 "content-language is provided, the value will be ignored and CLD's" | 124 "content-language is provided, the value will be ignored and CLD's" |
| 115 " language will be adopted if the value is invalid.</body></html>"); | 125 " language will be adopted if the value is invalid.</body></html>"); |
| 126 std::string cld_language; |
| 127 bool is_cld_reliable; |
| 116 std::string language = | 128 std::string language = |
| 117 TranslateHelper::DeterminePageLanguage(std::string("utf-8"), contents); | 129 TranslateHelper::DeterminePageLanguage(std::string("utf-8"), contents, |
| 130 &cld_language, &is_cld_reliable); |
| 118 EXPECT_EQ("en", language); | 131 EXPECT_EQ("en", language); |
| 132 EXPECT_EQ("en", cld_language); |
| 133 EXPECT_TRUE(is_cld_reliable); |
| 119 } | 134 } |
| OLD | NEW |