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

Unified Diff: third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp

Issue 2648703003: Pass more hints to encoding detector. (Closed)
Patch Set: _ Created 3 years, 11 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: third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp
diff --git a/third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp b/third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp
index f768df9b1d6bc5c85f1e5e1891fac1b7cec7c728..77d5e44b40410e24d81ee08f6e9fa750b06f8165 100644
--- a/third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp
+++ b/third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp
@@ -16,7 +16,7 @@ TEST(TextResourceDecoderTest, RespectIso2022Jp) {
"$BKL3$F;F|K\\%O%`%U%!%$%?!<%:$,%=%U%H%P%s%/$H$N%W%l!<%*%U$r@)$7!\"";
WTF::TextEncoding encoding;
bool result = detectTextEncoding(iso2022jp.c_str(), iso2022jp.length(),
- nullptr, &encoding);
+ nullptr, String(), nullptr, &encoding);
EXPECT_TRUE(result);
EXPECT_EQ(WTF::TextEncoding("ISO-2022-JP"), encoding);
}
@@ -28,9 +28,36 @@ TEST(TextResourceDecoderTest, Ignore7BitEncoding) {
" ~{\x54\x42\x31\x7D\x37\x22\x55\x39\x35\x3D\x3D\x71~} abc";
WTF::TextEncoding encoding;
bool result = detectTextEncoding(hzGb2312.c_str(), hzGb2312.length(), nullptr,
- &encoding);
+ String(), nullptr, &encoding);
EXPECT_TRUE(result);
EXPECT_EQ(WTF::TextEncoding("US-ASCII"), encoding);
}
+TEST(TextEncodingDetectorTest, UrlHintHelpsEUCJP) {
Jinsuk Kim 2017/01/20 21:50:47 Can you add another EXPECT to show that additional
tkent 2017/01/23 00:02:57 Done.
+ std::string eucjpBytes =
+ "<TITLE>"
+ "\xA5\xD1\xA5\xEF\xA1\xBC\xA5\xC1\xA5\xE3\xA1\xBC\xA5\xC8\xA1\xC3\xC5\xEA"
+ "\xBB\xF1\xBE\xF0\xCA\xF3\xA4\xCE\xA5\xD5\xA5\xA3\xA5\xB9\xA5\xB3</"
+ "TITLE>";
+ WTF::TextEncoding encoding;
+ bool result =
+ detectTextEncoding(eucjpBytes.c_str(), eucjpBytes.length(), nullptr,
+ "http://example.co.jp/", nullptr, &encoding);
+ EXPECT_TRUE(result);
+ EXPECT_EQ(WTF::TextEncoding("EUC-JP"), encoding);
+}
+
+TEST(TextEncodingDetectorTest, LanguageHintHelpsEUCJP) {
+ std::string eucjpBytes =
+ "<TITLE>"
+ "\xA5\xD1\xA5\xEF\xA1\xBC\xA5\xC1\xA5\xE3\xA1\xBC\xA5\xC8\xA1\xC3\xC5\xEA"
+ "\xBB\xF1\xBE\xF0\xCA\xF3\xA4\xCE\xA5\xD5\xA5\xA3\xA5\xB9\xA5\xB3</"
+ "TITLE>";
+ WTF::TextEncoding encoding;
+ bool result = detectTextEncoding(eucjpBytes.c_str(), eucjpBytes.length(),
+ nullptr, String(), "ja", &encoding);
+ EXPECT_TRUE(result);
+ EXPECT_EQ(WTF::TextEncoding("EUC-JP"), encoding);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698