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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/TextResourceDecoderTest.cpp

Issue 2212393003: Fix BOM handling in TextResourceDecoder on partial data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698