| 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 namespace { |
| 12 |
| 13 const char kUTF16TextMimeType[] = "text/plain; charset=utf-16"; |
| 14 |
| 15 } // namespace |
| 16 |
| 17 TEST(TextResourceDecoderTest, BasicUTF16) |
| 18 { |
| 19 std::unique_ptr<TextResourceDecoder> decoder = TextResourceDecoder::create(k
UTF16TextMimeType); |
| 20 WTF::String decoded; |
| 21 |
| 22 const unsigned char fooLE[] = {0xff, 0xfe, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x0
0}; |
| 23 decoded = decoder->decode(reinterpret_cast<const char*>(fooLE), sizeof(fooLE
)); |
| 24 decoded = decoded + decoder->flush(); |
| 25 EXPECT_EQ("foo", decoded); |
| 26 |
| 27 decoder = TextResourceDecoder::create(kUTF16TextMimeType); |
| 28 const unsigned char fooBE[] = {0xfe, 0xff, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x6
f}; |
| 29 decoded = decoder->decode(reinterpret_cast<const char*>(fooBE), sizeof(fooBE
)); |
| 30 decoded = decoded + decoder->flush(); |
| 31 EXPECT_EQ("foo", decoded); |
| 32 } |
| 33 |
| 34 TEST(TextResourceDecoderTest, UTF16Pieces) |
| 35 { |
| 36 std::unique_ptr<TextResourceDecoder> decoder = TextResourceDecoder::create(k
UTF16TextMimeType); |
| 37 |
| 38 WTF::String decoded; |
| 39 const unsigned char foo[] = {0xff, 0xfe, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00}
; |
| 40 for (char c : foo) |
| 41 decoded = decoded + decoder->decode(reinterpret_cast<const char*>(&c), 1
); |
| 42 decoded = decoded + decoder->flush(); |
| 43 EXPECT_EQ("foo", decoded); |
| 44 } |
| 45 |
| 46 } // namespace blink |
| OLD | NEW |