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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; | 90 std::string cld_language; |
91 bool is_cld_reliable; | 91 bool is_cld_reliable; |
92 std::string language = | 92 std::string language = |
93 TranslateHelper::DeterminePageLanguage(std::string("ja"), std::string(), | 93 TranslateHelper::DeterminePageLanguage(std::string("ja"), contents, |
94 contents, &cld_language, | 94 &cld_language, &is_cld_reliable); |
95 &is_cld_reliable); | |
96 EXPECT_EQ(chrome::kUnknownLanguageCode, language); | 95 EXPECT_EQ(chrome::kUnknownLanguageCode, language); |
97 EXPECT_EQ("en", cld_language); | 96 EXPECT_EQ("en", cld_language); |
98 EXPECT_TRUE(is_cld_reliable); | 97 EXPECT_TRUE(is_cld_reliable); |
99 } | 98 } |
100 | 99 |
101 // 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 |
102 // agreed by CLD. | 101 // agreed by CLD. |
103 TEST_F(TranslateHelperTest, CLDAgreeWithLanguageCodeHavingCountryCode) { | 102 TEST_F(TranslateHelperTest, CLDAgreeWithLanguageCodeHavingCountryCode) { |
104 string16 contents = ASCIIToUTF16( | 103 string16 contents = ASCIIToUTF16( |
105 "<html><head><meta http-equiv='Content-Language' content='en-US'></head>" | 104 "<html><head><meta http-equiv='Content-Language' content='en-US'></head>" |
106 "<body>This is a page apparently written in English. Even though " | 105 "<body>This is a page apparently written in English. Even though " |
107 "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 " |
108 "is suspicious.</body></html>"); | 107 "is suspicious.</body></html>"); |
109 std::string cld_language; | 108 std::string cld_language; |
110 bool is_cld_reliable; | 109 bool is_cld_reliable; |
111 std::string language = | 110 std::string language = |
112 TranslateHelper::DeterminePageLanguage(std::string("en-US"), | 111 TranslateHelper::DeterminePageLanguage(std::string("en-US"), contents, |
113 std::string(), contents, | |
114 &cld_language, &is_cld_reliable); | 112 &cld_language, &is_cld_reliable); |
115 EXPECT_EQ("en-US", language); | 113 EXPECT_EQ("en-US", language); |
116 EXPECT_EQ("en", cld_language); | 114 EXPECT_EQ("en", cld_language); |
117 EXPECT_TRUE(is_cld_reliable); | 115 EXPECT_TRUE(is_cld_reliable); |
118 } | 116 } |
119 | 117 |
120 // 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 |
121 // 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. |
122 TEST_F(TranslateHelperTest, InvalidLanguageMetaTagProviding) { | 120 TEST_F(TranslateHelperTest, InvalidLanguageMetaTagProviding) { |
123 string16 contents = ASCIIToUTF16( | 121 string16 contents = ASCIIToUTF16( |
124 "<html><head><meta http-equiv='Content-Language' content='utf-8'></head>" | 122 "<html><head><meta http-equiv='Content-Language' content='utf-8'></head>" |
125 "<body>This is a page apparently written in English. Even though " | 123 "<body>This is a page apparently written in English. Even though " |
126 "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" |
127 " language will be adopted if the value is invalid.</body></html>"); | 125 " language will be adopted if the value is invalid.</body></html>"); |
128 std::string cld_language; | 126 std::string cld_language; |
129 bool is_cld_reliable; | 127 bool is_cld_reliable; |
130 std::string language = | 128 std::string language = |
131 TranslateHelper::DeterminePageLanguage(std::string("utf-8"), | 129 TranslateHelper::DeterminePageLanguage(std::string("utf-8"), contents, |
132 std::string(), contents, | |
133 &cld_language, &is_cld_reliable); | 130 &cld_language, &is_cld_reliable); |
134 EXPECT_EQ("en", language); | 131 EXPECT_EQ("en", language); |
135 EXPECT_EQ("en", cld_language); | 132 EXPECT_EQ("en", cld_language); |
136 EXPECT_TRUE(is_cld_reliable); | 133 EXPECT_TRUE(is_cld_reliable); |
137 } | 134 } |
138 | |
139 // Tests that the language meta tag providing wrong information is ignored | |
140 // because of valid html lang attribute. | |
141 TEST_F(TranslateHelperTest, AdoptHtmlLang) { | |
142 string16 contents = ASCIIToUTF16( | |
143 "<html lang='en'><head><meta http-equiv='Content-Language' content='ja'>" | |
144 "</head><body>This is a page apparently written in English. Even though " | |
145 "content-language is provided, the value will be ignored if the value " | |
146 "is suspicious.</body></html>"); | |
147 std::string cld_language; | |
148 bool is_cld_reliable; | |
149 std::string language = | |
150 TranslateHelper::DeterminePageLanguage(std::string("ja"), | |
151 std::string("en"), | |
152 contents, &cld_language, | |
153 &is_cld_reliable); | |
154 EXPECT_EQ("en", language); | |
155 EXPECT_EQ("en", cld_language); | |
156 EXPECT_TRUE(is_cld_reliable); | |
157 } | |
OLD | NEW |