| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/dns/dns_hosts.h" | 5 #include "net/dns/dns_hosts.h" |
| 6 | 6 |
| 7 #include "net/base/ip_address.h" | 7 #include "net/base/ip_address.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 "1.0.0.1\t CoMpANy # normalized to 'company' \n" | 41 "1.0.0.1\t CoMpANy # normalized to 'company' \n" |
| 42 "::1\tlocalhost ip6-localhost ip6-loopback # comment # within a comment\n" | 42 "::1\tlocalhost ip6-localhost ip6-loopback # comment # within a comment\n" |
| 43 "\t fe00::0 ip6-localnet\r\n" | 43 "\t fe00::0 ip6-localnet\r\n" |
| 44 "2048::2 example\n" | 44 "2048::2 example\n" |
| 45 "2048::1 company example # ignored for 'example' \n" | 45 "2048::1 company example # ignored for 'example' \n" |
| 46 "127.0.0.1 cache1\n" | 46 "127.0.0.1 cache1\n" |
| 47 "127.0.0.1 cache2 # should reuse parsed IP\n" | 47 "127.0.0.1 cache2 # should reuse parsed IP\n" |
| 48 "256.0.0.0 cache3 # bogus IP should not clear parsed IP cache\n" | 48 "256.0.0.0 cache3 # bogus IP should not clear parsed IP cache\n" |
| 49 "127.0.0.1 cache4 # should still be reused\n" | 49 "127.0.0.1 cache4 # should still be reused\n" |
| 50 "127.0.0.2 cache5\n" | 50 "127.0.0.2 cache5\n" |
| 51 "127.0.0.3 .foo # entries with leading dot are ignored\n" |
| 52 "127.0.0.3 . # just a dot is ignored\n" |
| 53 "127.0.0.4 bar. # trailing dot is allowed, for now\n" |
| 51 "gibberish"; | 54 "gibberish"; |
| 52 | 55 |
| 53 const ExpectedHostsEntry kEntries[] = { | 56 const ExpectedHostsEntry kEntries[] = { |
| 54 { "localhost", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, | 57 {"localhost", ADDRESS_FAMILY_IPV4, "127.0.0.1"}, |
| 55 { "localhost.localdomain", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, | 58 {"localhost.localdomain", ADDRESS_FAMILY_IPV4, "127.0.0.1"}, |
| 56 { "company", ADDRESS_FAMILY_IPV4, "1.0.0.1" }, | 59 {"company", ADDRESS_FAMILY_IPV4, "1.0.0.1"}, |
| 57 { "localhost", ADDRESS_FAMILY_IPV6, "::1" }, | 60 {"localhost", ADDRESS_FAMILY_IPV6, "::1"}, |
| 58 { "ip6-localhost", ADDRESS_FAMILY_IPV6, "::1" }, | 61 {"ip6-localhost", ADDRESS_FAMILY_IPV6, "::1"}, |
| 59 { "ip6-loopback", ADDRESS_FAMILY_IPV6, "::1" }, | 62 {"ip6-loopback", ADDRESS_FAMILY_IPV6, "::1"}, |
| 60 { "ip6-localnet", ADDRESS_FAMILY_IPV6, "fe00::0" }, | 63 {"ip6-localnet", ADDRESS_FAMILY_IPV6, "fe00::0"}, |
| 61 { "company", ADDRESS_FAMILY_IPV6, "2048::1" }, | 64 {"company", ADDRESS_FAMILY_IPV6, "2048::1"}, |
| 62 { "example", ADDRESS_FAMILY_IPV6, "2048::2" }, | 65 {"example", ADDRESS_FAMILY_IPV6, "2048::2"}, |
| 63 { "cache1", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, | 66 {"cache1", ADDRESS_FAMILY_IPV4, "127.0.0.1"}, |
| 64 { "cache2", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, | 67 {"cache2", ADDRESS_FAMILY_IPV4, "127.0.0.1"}, |
| 65 { "cache4", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, | 68 {"cache4", ADDRESS_FAMILY_IPV4, "127.0.0.1"}, |
| 66 { "cache5", ADDRESS_FAMILY_IPV4, "127.0.0.2" }, | 69 {"cache5", ADDRESS_FAMILY_IPV4, "127.0.0.2"}, |
| 70 {"bar.", ADDRESS_FAMILY_IPV4, "127.0.0.4"}, |
| 67 }; | 71 }; |
| 68 | 72 |
| 69 DnsHosts expected_hosts, actual_hosts; | 73 DnsHosts expected_hosts, actual_hosts; |
| 70 PopulateExpectedHosts(kEntries, arraysize(kEntries), &expected_hosts); | 74 PopulateExpectedHosts(kEntries, arraysize(kEntries), &expected_hosts); |
| 71 ParseHosts(kContents, &actual_hosts); | 75 ParseHosts(kContents, &actual_hosts); |
| 72 ASSERT_EQ(expected_hosts, actual_hosts); | 76 ASSERT_EQ(expected_hosts, actual_hosts); |
| 73 } | 77 } |
| 74 | 78 |
| 75 TEST(DnsHostsTest, ParseHosts_CommaIsToken) { | 79 TEST(DnsHostsTest, ParseHosts_CommaIsToken) { |
| 76 const std::string kContents = "127.0.0.1 comma1,comma2"; | 80 const std::string kContents = "127.0.0.1 comma1,comma2"; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 TEST(DnsHostsTest, HostsParser_EndsWithNewlineAndToken) { | 177 TEST(DnsHostsTest, HostsParser_EndsWithNewlineAndToken) { |
| 174 DnsHosts hosts; | 178 DnsHosts hosts; |
| 175 ParseHosts("127.0.0.1 localhost\ntoken", &hosts); | 179 ParseHosts("127.0.0.1 localhost\ntoken", &hosts); |
| 176 EXPECT_EQ(1u, hosts.size()); | 180 EXPECT_EQ(1u, hosts.size()); |
| 177 } | 181 } |
| 178 | 182 |
| 179 } // namespace | 183 } // namespace |
| 180 | 184 |
| 181 } // namespace net | 185 } // namespace net |
| 182 | 186 |
| OLD | NEW |