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

Side by Side 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 unified diff | Download patch
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 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698