| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/html/parser/TextResourceDecoder.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace blink { | |
| 10 | |
| 11 TEST(TextResourceDecoderTest, KeepEncodingConsistent) | |
| 12 { | |
| 13 bool useAutoEncodingDetector = true; | |
| 14 OwnPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/plai
n", WTF::TextEncoding(), useAutoEncodingDetector); | |
| 15 | |
| 16 // First |decode()| call initializes the internal text codec with UTF-8 | |
| 17 // which was inferred by the auto encoding detector. | |
| 18 decoder->decode("\xc2\xa7", 2); | |
| 19 ASSERT_EQ(UTF8Encoding(), decoder->encoding()); | |
| 20 | |
| 21 // Subsequent |decode()| is called with non-UTF-8 text (EUC-KR), | |
| 22 // but the codec remains fixed. | |
| 23 decoder->decode("\xc4\x22\xc4\x5c", 2); | |
| 24 EXPECT_EQ(UTF8Encoding(), decoder->encoding()); | |
| 25 | |
| 26 // |TextResourceDecoder| is created not to use auto encoding detector, | |
| 27 // which activates the light-weight UTF-8 encoding detector. | |
| 28 decoder = TextResourceDecoder::create("text/plain"); | |
| 29 | |
| 30 decoder->decode("abcde", 5); | |
| 31 ASSERT_EQ(Latin1Encoding(), decoder->encoding()); | |
| 32 | |
| 33 // Verify that the encoding(Latin1) used for the first |decode()| remains | |
| 34 // fixed even if the subsequent call is given UTF-8 text. | |
| 35 decoder->decode("\xc2\xa7", 2); | |
| 36 EXPECT_EQ(Latin1Encoding(), decoder->encoding()); | |
| 37 } | |
| 38 } | |
| OLD | NEW |