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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/parser/TextResourceDecoderTest.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/TextResourceDecoderTest.cpp b/third_party/WebKit/Source/core/html/parser/TextResourceDecoderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..636deecdffe2f48d514e5632d7073fad106c56ce
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoderTest.cpp
@@ -0,0 +1,46 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/html/parser/TextResourceDecoder.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+namespace {
+
+const char kUTF16TextMimeType[] = "text/plain; charset=utf-16";
+
+} // namespace
+
+TEST(TextResourceDecoderTest, BasicUTF16)
+{
+ std::unique_ptr<TextResourceDecoder> decoder = TextResourceDecoder::create(kUTF16TextMimeType);
+ WTF::String decoded;
+
+ const unsigned char fooLE[] = {0xff, 0xfe, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00};
+ decoded = decoder->decode(reinterpret_cast<const char*>(fooLE), sizeof(fooLE));
+ decoded = decoded + decoder->flush();
+ EXPECT_EQ("foo", decoded);
+
+ decoder = TextResourceDecoder::create(kUTF16TextMimeType);
+ const unsigned char fooBE[] = {0xfe, 0xff, 0x00, 0x66, 0x00, 0x6f, 0x00, 0x6f};
+ decoded = decoder->decode(reinterpret_cast<const char*>(fooBE), sizeof(fooBE));
+ decoded = decoded + decoder->flush();
+ EXPECT_EQ("foo", decoded);
+}
+
+TEST(TextResourceDecoderTest, UTF16Pieces)
+{
+ std::unique_ptr<TextResourceDecoder> decoder = TextResourceDecoder::create(kUTF16TextMimeType);
+
+ WTF::String decoded;
+ const unsigned char foo[] = {0xff, 0xfe, 0x66, 0x00, 0x6f, 0x00, 0x6f, 0x00};
+ for (char c : foo)
+ decoded = decoded + decoder->decode(reinterpret_cast<const char*>(&c), 1);
+ decoded = decoded + decoder->flush();
+ EXPECT_EQ("foo", decoded);
+}
+
+} // namespace blink
« 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