OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/loader/TextResourceDecoderBuilder.h" | 5 #include "core/loader/TextResourceDecoderBuilder.h" |
6 | 6 |
7 #include "core/testing/DummyPageHolder.h" | 7 #include "core/testing/DummyPageHolder.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include <memory> | |
10 | 9 |
11 namespace blink { | 10 namespace blink { |
12 | 11 |
13 static const WTF::TextEncoding defaultEncodingForURL(const char* url) | 12 static const WTF::TextEncoding defaultEncodingForURL(const char* url) |
14 { | 13 { |
15 std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(IntSiz
e(0, 0)); | 14 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(IntSize(0, 0)); |
16 Document& document = pageHolder->document(); | 15 Document& document = pageHolder->document(); |
17 document.setURL(KURL(KURL(), url)); | 16 document.setURL(KURL(KURL(), url)); |
18 TextResourceDecoderBuilder decoderBuilder("text/html", nullAtom); | 17 TextResourceDecoderBuilder decoderBuilder("text/html", nullAtom); |
19 return decoderBuilder.buildFor(&document)->encoding(); | 18 return decoderBuilder.buildFor(&document)->encoding(); |
20 } | 19 } |
21 | 20 |
22 TEST(TextResourceDecoderBuilderTest, defaultEncodingComesFromTopLevelDomain) | 21 TEST(TextResourceDecoderBuilderTest, defaultEncodingComesFromTopLevelDomain) |
23 { | 22 { |
24 EXPECT_EQ(WTF::TextEncoding("Shift_JIS"), defaultEncodingForURL("http://tsub
otaa.la.coocan.jp")); | 23 EXPECT_EQ(WTF::TextEncoding("Shift_JIS"), defaultEncodingForURL("http://tsub
otaa.la.coocan.jp")); |
25 EXPECT_EQ(WTF::TextEncoding("windows-1251"), defaultEncodingForURL("http://u
darenieru.ru/index.php")); | 24 EXPECT_EQ(WTF::TextEncoding("windows-1251"), defaultEncodingForURL("http://u
darenieru.ru/index.php")); |
26 } | 25 } |
27 | 26 |
28 TEST(TextResourceDecoderBuilderTest, NoCountryDomainURLDefaultsToLatin1Encoding) | 27 TEST(TextResourceDecoderBuilderTest, NoCountryDomainURLDefaultsToLatin1Encoding) |
29 { | 28 { |
30 // Latin1 encoding is set in |TextResourceDecoder::defaultEncoding()|. | 29 // Latin1 encoding is set in |TextResourceDecoder::defaultEncoding()|. |
31 EXPECT_EQ(WTF::Latin1Encoding(), defaultEncodingForURL("http://arstechnica.c
om/about-us")); | 30 EXPECT_EQ(WTF::Latin1Encoding(), defaultEncodingForURL("http://arstechnica.c
om/about-us")); |
32 } | 31 } |
33 | 32 |
34 } // namespace blink | 33 } // namespace blink |
OLD | NEW |