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> |
9 | 10 |
10 namespace blink { | 11 namespace blink { |
11 | 12 |
12 static const WTF::TextEncoding defaultEncodingForURL(const char* url) | 13 static const WTF::TextEncoding defaultEncodingForURL(const char* url) |
13 { | 14 { |
14 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(IntSize(0, 0)); | 15 std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(IntSiz
e(0, 0)); |
15 Document& document = pageHolder->document(); | 16 Document& document = pageHolder->document(); |
16 document.setURL(KURL(KURL(), url)); | 17 document.setURL(KURL(KURL(), url)); |
17 TextResourceDecoderBuilder decoderBuilder("text/html", nullAtom); | 18 TextResourceDecoderBuilder decoderBuilder("text/html", nullAtom); |
18 return decoderBuilder.buildFor(&document)->encoding(); | 19 return decoderBuilder.buildFor(&document)->encoding(); |
19 } | 20 } |
20 | 21 |
21 TEST(TextResourceDecoderBuilderTest, defaultEncodingComesFromTopLevelDomain) | 22 TEST(TextResourceDecoderBuilderTest, defaultEncodingComesFromTopLevelDomain) |
22 { | 23 { |
23 EXPECT_EQ(WTF::TextEncoding("Shift_JIS"), defaultEncodingForURL("http://tsub
otaa.la.coocan.jp")); | 24 EXPECT_EQ(WTF::TextEncoding("Shift_JIS"), defaultEncodingForURL("http://tsub
otaa.la.coocan.jp")); |
24 EXPECT_EQ(WTF::TextEncoding("windows-1251"), defaultEncodingForURL("http://u
darenieru.ru/index.php")); | 25 EXPECT_EQ(WTF::TextEncoding("windows-1251"), defaultEncodingForURL("http://u
darenieru.ru/index.php")); |
25 } | 26 } |
26 | 27 |
27 TEST(TextResourceDecoderBuilderTest, NoCountryDomainURLDefaultsToLatin1Encoding) | 28 TEST(TextResourceDecoderBuilderTest, NoCountryDomainURLDefaultsToLatin1Encoding) |
28 { | 29 { |
29 // Latin1 encoding is set in |TextResourceDecoder::defaultEncoding()|. | 30 // Latin1 encoding is set in |TextResourceDecoder::defaultEncoding()|. |
30 EXPECT_EQ(WTF::Latin1Encoding(), defaultEncodingForURL("http://arstechnica.c
om/about-us")); | 31 EXPECT_EQ(WTF::Latin1Encoding(), defaultEncodingForURL("http://arstechnica.c
om/about-us")); |
31 } | 32 } |
32 | 33 |
33 } // namespace blink | 34 } // namespace blink |
OLD | NEW |