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

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

Issue 1890103002: Reland "UTF-8 detector for pages missing encoding info" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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..b2da4985ec6ef49e7587c46b8800aab9326462ce
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoderTest.cpp
@@ -0,0 +1,38 @@
+// 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 {
+
+TEST(TextResourceDecoderTest, KeepEncodingConsistent)
+{
+ bool useAutoEncodingDetector = true;
+ OwnPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/plain", WTF::TextEncoding(), useAutoEncodingDetector);
+
+ // First |decode()| call initializes the internal text codec with UTF-8
+ // which was inferred by the auto encoding detector.
+ decoder->decode("\xc2\xa7", 2);
+ ASSERT_EQ(UTF8Encoding(), decoder->encoding());
+
+ // Subsequent |decode()| is called with non-UTF-8 text (EUC-KR),
+ // but the codec remains fixed.
+ decoder->decode("\xc4\x22\xc4\x5c", 2);
+ EXPECT_EQ(UTF8Encoding(), decoder->encoding());
+
+ // |TextResourceDecoder| is created not to use auto encoding detector,
+ // which activates the light-weight UTF-8 encoding detector.
+ decoder = TextResourceDecoder::create("text/plain");
+
+ decoder->decode("abcde", 5);
+ ASSERT_EQ(Latin1Encoding(), decoder->encoding());
+
+ // Verify that the encoding(Latin1) used for the first |decode()| remains
+ // fixed even if the subsequent call is given UTF-8 text.
+ decoder->decode("\xc2\xa7", 2);
+ EXPECT_EQ(Latin1Encoding(), decoder->encoding());
+}
+}

Powered by Google App Engine
This is Rietveld 408576698