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_config_service.h" | 5 #include "net/dns/dns_config_service.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/cancelable_callback.h" | 9 #include "base/cancelable_callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 EXPECT_EQ(kPrivate, Classify("192.168.0.0 192.168.255.255")); | 88 EXPECT_EQ(kPrivate, Classify("192.168.0.0 192.168.255.255")); |
89 EXPECT_EQ(kPrivate, Classify("10.1.1.1 172.16.1.1 192.168.1.1")); | 89 EXPECT_EQ(kPrivate, Classify("10.1.1.1 172.16.1.1 192.168.1.1")); |
90 } | 90 } |
91 | 91 |
92 TEST_F(NameServerClassifierTest, PrivateIPv4LinkLocal) { | 92 TEST_F(NameServerClassifierTest, PrivateIPv4LinkLocal) { |
93 EXPECT_EQ(kPrivate, Classify("169.254.0.0 169.254.255.255")); | 93 EXPECT_EQ(kPrivate, Classify("169.254.0.0 169.254.255.255")); |
94 } | 94 } |
95 | 95 |
96 TEST_F(NameServerClassifierTest, PrivateIPv6LinkLocal) { | 96 TEST_F(NameServerClassifierTest, PrivateIPv6LinkLocal) { |
97 EXPECT_EQ(kPrivate, | 97 EXPECT_EQ(kPrivate, |
98 Classify("fe80:: fe80:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); | 98 Classify("fe80:: fe80:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); |
99 } | 99 } |
100 | 100 |
101 TEST_F(NameServerClassifierTest, Public) { | 101 TEST_F(NameServerClassifierTest, Public) { |
102 EXPECT_EQ(kPublic, Classify("4.2.2.1")); | 102 EXPECT_EQ(kPublic, Classify("4.2.2.1")); |
103 EXPECT_EQ(kPublic, Classify("4.2.2.1 4.2.2.2")); | 103 EXPECT_EQ(kPublic, Classify("4.2.2.1 4.2.2.2")); |
104 } | 104 } |
105 | 105 |
106 TEST_F(NameServerClassifierTest, Mixed) { | 106 TEST_F(NameServerClassifierTest, Mixed) { |
107 EXPECT_EQ(kMixed, Classify("8.8.8.8 192.168.1.1")); | 107 EXPECT_EQ(kMixed, Classify("8.8.8.8 192.168.1.1")); |
108 EXPECT_EQ(kMixed, Classify("8.8.8.8 4.2.2.1")); | 108 EXPECT_EQ(kMixed, Classify("8.8.8.8 4.2.2.1")); |
109 EXPECT_EQ(kMixed, Classify("192.168.1.1 4.2.2.1")); | 109 EXPECT_EQ(kMixed, Classify("192.168.1.1 4.2.2.1")); |
110 EXPECT_EQ(kMixed, Classify("8.8.8.8 192.168.1.1 4.2.2.1")); | 110 EXPECT_EQ(kMixed, Classify("8.8.8.8 192.168.1.1 4.2.2.1")); |
111 } | 111 } |
112 | 112 |
113 class DnsConfigServiceTest : public testing::Test { | 113 class DnsConfigServiceTest : public testing::Test { |
114 public: | 114 public: |
115 void OnConfigChanged(const DnsConfig& config) { | 115 void OnConfigChanged(const DnsConfig& config) { |
116 last_config_ = config; | 116 last_config_ = config; |
117 if (quit_on_config_) | 117 if (quit_on_config_) |
118 base::MessageLoop::current()->Quit(); | 118 base::MessageLoop::current()->Quit(); |
119 } | 119 } |
120 | 120 |
121 protected: | 121 protected: |
122 class TestDnsConfigService : public DnsConfigService { | 122 class TestDnsConfigService : public DnsConfigService { |
123 public: | 123 public: |
124 virtual void ReadNow() OVERRIDE {} | 124 virtual void ReadNow() OVERRIDE {} |
125 virtual bool StartWatching() OVERRIDE { return true; } | 125 virtual bool StartWatching() OVERRIDE { return true; } |
126 | 126 |
127 // Expose the protected methods to this test suite. | 127 // Expose the protected methods to this test suite. |
128 void InvalidateConfig() { | 128 void InvalidateConfig() { DnsConfigService::InvalidateConfig(); } |
129 DnsConfigService::InvalidateConfig(); | |
130 } | |
131 | 129 |
132 void InvalidateHosts() { | 130 void InvalidateHosts() { DnsConfigService::InvalidateHosts(); } |
133 DnsConfigService::InvalidateHosts(); | |
134 } | |
135 | 131 |
136 void OnConfigRead(const DnsConfig& config) { | 132 void OnConfigRead(const DnsConfig& config) { |
137 DnsConfigService::OnConfigRead(config); | 133 DnsConfigService::OnConfigRead(config); |
138 } | 134 } |
139 | 135 |
140 void OnHostsRead(const DnsHosts& hosts) { | 136 void OnHostsRead(const DnsHosts& hosts) { |
141 DnsConfigService::OnHostsRead(hosts); | 137 DnsConfigService::OnHostsRead(hosts); |
142 } | 138 } |
143 | 139 |
144 void set_watch_failed(bool value) { | 140 void set_watch_failed(bool value) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // TODO(szym): This is really an integration test and can time out if HOSTS is | 332 // TODO(szym): This is really an integration test and can time out if HOSTS is |
337 // huge. http://crbug.com/107810 | 333 // huge. http://crbug.com/107810 |
338 TEST_F(DnsConfigServiceTest, DISABLED_GetSystemConfig) { | 334 TEST_F(DnsConfigServiceTest, DISABLED_GetSystemConfig) { |
339 service_.reset(); | 335 service_.reset(); |
340 scoped_ptr<DnsConfigService> service(DnsConfigService::CreateSystemService()); | 336 scoped_ptr<DnsConfigService> service(DnsConfigService::CreateSystemService()); |
341 | 337 |
342 service->ReadConfig(base::Bind(&DnsConfigServiceTest::OnConfigChanged, | 338 service->ReadConfig(base::Bind(&DnsConfigServiceTest::OnConfigChanged, |
343 base::Unretained(this))); | 339 base::Unretained(this))); |
344 base::TimeDelta kTimeout = TestTimeouts::action_max_timeout(); | 340 base::TimeDelta kTimeout = TestTimeouts::action_max_timeout(); |
345 WaitForConfig(kTimeout); | 341 WaitForConfig(kTimeout); |
346 ASSERT_TRUE(last_config_.IsValid()) << "Did not receive DnsConfig in " << | 342 ASSERT_TRUE(last_config_.IsValid()) << "Did not receive DnsConfig in " |
347 kTimeout.InSecondsF() << "s"; | 343 << kTimeout.InSecondsF() << "s"; |
348 } | 344 } |
349 #endif // OS_POSIX || OS_WIN | 345 #endif // OS_POSIX || OS_WIN |
350 | 346 |
351 } // namespace net | 347 } // namespace net |
352 | |
OLD | NEW |