OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/text/TextEncodingDetector.h" | 5 #include "platform/text/TextEncodingDetector.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "wtf/text/TextEncoding.h" | 8 #include "wtf/text/TextEncoding.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 EXPECT_EQ(WTF::TextEncoding("GBK"), encoding) | 66 EXPECT_EQ(WTF::TextEncoding("GBK"), encoding) |
67 << "Without language hint, it's detected as GBK"; | 67 << "Without language hint, it's detected as GBK"; |
68 | 68 |
69 result = detectTextEncoding(eucjpBytes.c_str(), eucjpBytes.length(), nullptr, | 69 result = detectTextEncoding(eucjpBytes.c_str(), eucjpBytes.length(), nullptr, |
70 nullptr, "ja", &encoding); | 70 nullptr, "ja", &encoding); |
71 EXPECT_TRUE(result); | 71 EXPECT_TRUE(result); |
72 EXPECT_EQ(WTF::TextEncoding("EUC-JP"), encoding) | 72 EXPECT_EQ(WTF::TextEncoding("EUC-JP"), encoding) |
73 << "With language hint 'ja', it's detected as EUC-JP"; | 73 << "With language hint 'ja', it's detected as EUC-JP"; |
74 } | 74 } |
75 | 75 |
| 76 TEST(TextEncodingDetectorTest, UTF8DetectionShouldFail) { |
| 77 std::string utf8Bytes = |
| 78 "tnegirjji gosa gii beare s\xC3\xA1htt\xC3\xA1 \xC4\x8D\xC3" |
| 79 "\xA1llit artihkkaliid. Maid don s\xC3\xA1ht\xC3\xA1t dievasmah"; |
| 80 WTF::TextEncoding encoding; |
| 81 bool result = detectTextEncoding(utf8Bytes.c_str(), utf8Bytes.length(), |
| 82 nullptr, nullptr, nullptr, &encoding); |
| 83 EXPECT_FALSE(result); |
| 84 } |
| 85 |
76 } // namespace blink | 86 } // namespace blink |
OLD | NEW |