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

Side by Side Diff: chrome/renderer/translate/translate_helper_unittest.cc

Issue 15728002: Translate: adopt html lang attribute if valid value is provided (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix WindowOpenClose crash Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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"), contents, 93 TranslateHelper::DeterminePageLanguage(std::string("ja"), std::string(),
94 &cld_language, &is_cld_reliable); 94 contents, &cld_language,
95 &is_cld_reliable);
95 EXPECT_EQ(chrome::kUnknownLanguageCode, language); 96 EXPECT_EQ(chrome::kUnknownLanguageCode, language);
96 EXPECT_EQ("en", cld_language); 97 EXPECT_EQ("en", cld_language);
97 EXPECT_TRUE(is_cld_reliable); 98 EXPECT_TRUE(is_cld_reliable);
98 } 99 }
99 100
100 // Tests that the language meta tag providing "en-US" style information is 101 // Tests that the language meta tag providing "en-US" style information is
101 // agreed by CLD. 102 // agreed by CLD.
102 TEST_F(TranslateHelperTest, CLDAgreeWithLanguageCodeHavingCountryCode) { 103 TEST_F(TranslateHelperTest, CLDAgreeWithLanguageCodeHavingCountryCode) {
103 string16 contents = ASCIIToUTF16( 104 string16 contents = ASCIIToUTF16(
104 "<html><head><meta http-equiv='Content-Language' content='en-US'></head>" 105 "<html><head><meta http-equiv='Content-Language' content='en-US'></head>"
105 "<body>This is a page apparently written in English. Even though " 106 "<body>This is a page apparently written in English. Even though "
106 "content-language is provided, the value will be ignored if the value " 107 "content-language is provided, the value will be ignored if the value "
107 "is suspicious.</body></html>"); 108 "is suspicious.</body></html>");
108 std::string cld_language; 109 std::string cld_language;
109 bool is_cld_reliable; 110 bool is_cld_reliable;
110 std::string language = 111 std::string language =
111 TranslateHelper::DeterminePageLanguage(std::string("en-US"), contents, 112 TranslateHelper::DeterminePageLanguage(std::string("en-US"),
113 std::string(), contents,
112 &cld_language, &is_cld_reliable); 114 &cld_language, &is_cld_reliable);
113 EXPECT_EQ("en-US", language); 115 EXPECT_EQ("en-US", language);
114 EXPECT_EQ("en", cld_language); 116 EXPECT_EQ("en", cld_language);
115 EXPECT_TRUE(is_cld_reliable); 117 EXPECT_TRUE(is_cld_reliable);
116 } 118 }
117 119
118 // Tests that the language meta tag providing wrong information is ignored and 120 // Tests that the language meta tag providing wrong information is ignored and
119 // CLD's language will be adopted by TranslateHelper due to an invalid meta tag. 121 // CLD's language will be adopted by TranslateHelper due to an invalid meta tag.
120 TEST_F(TranslateHelperTest, InvalidLanguageMetaTagProviding) { 122 TEST_F(TranslateHelperTest, InvalidLanguageMetaTagProviding) {
121 string16 contents = ASCIIToUTF16( 123 string16 contents = ASCIIToUTF16(
122 "<html><head><meta http-equiv='Content-Language' content='utf-8'></head>" 124 "<html><head><meta http-equiv='Content-Language' content='utf-8'></head>"
123 "<body>This is a page apparently written in English. Even though " 125 "<body>This is a page apparently written in English. Even though "
124 "content-language is provided, the value will be ignored and CLD's" 126 "content-language is provided, the value will be ignored and CLD's"
125 " language will be adopted if the value is invalid.</body></html>"); 127 " language will be adopted if the value is invalid.</body></html>");
126 std::string cld_language; 128 std::string cld_language;
127 bool is_cld_reliable; 129 bool is_cld_reliable;
128 std::string language = 130 std::string language =
129 TranslateHelper::DeterminePageLanguage(std::string("utf-8"), contents, 131 TranslateHelper::DeterminePageLanguage(std::string("utf-8"),
132 std::string(), contents,
130 &cld_language, &is_cld_reliable); 133 &cld_language, &is_cld_reliable);
131 EXPECT_EQ("en", language); 134 EXPECT_EQ("en", language);
132 EXPECT_EQ("en", cld_language); 135 EXPECT_EQ("en", cld_language);
133 EXPECT_TRUE(is_cld_reliable); 136 EXPECT_TRUE(is_cld_reliable);
134 } 137 }
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 }
OLDNEW
« no previous file with comments | « chrome/renderer/translate/translate_helper_metrics_unittest.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698