[email protected] | 5761ab9c | 2012-02-04 16:44:53 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 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 "net/dns/dns_config_service.h" |
| 6 | |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 7 | #include "base/basictypes.h" |
[email protected] | 76d7f72 | 2011-10-10 17:22:41 | [diff] [blame] | 8 | #include "base/bind.h" |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 9 | #include "base/cancelable_callback.h" |
[email protected] | 76d7f72 | 2011-10-10 17:22:41 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
[email protected] | 5ee2098 | 2013-07-17 21:51:18 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
[email protected] | e4e522d | 2014-03-12 05:08:06 | [diff] [blame^] | 12 | #include "base/strings/string_split.h" |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 13 | #include "base/test/test_timeouts.h" |
[email protected] | e4e522d | 2014-03-12 05:08:06 | [diff] [blame^] | 14 | #include "net/base/net_util.h" |
| 15 | #include "net/dns/dns_protocol.h" |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | |
| 18 | namespace net { |
| 19 | |
| 20 | namespace { |
| 21 | |
[email protected] | e4e522d | 2014-03-12 05:08:06 | [diff] [blame^] | 22 | const NameServerClassifier::NameServersType kNone = |
| 23 | NameServerClassifier::NAME_SERVERS_TYPE_NONE; |
| 24 | const NameServerClassifier::NameServersType kGoogle = |
| 25 | NameServerClassifier::NAME_SERVERS_TYPE_GOOGLE_PUBLIC_DNS; |
| 26 | const NameServerClassifier::NameServersType kPrivate = |
| 27 | NameServerClassifier::NAME_SERVERS_TYPE_PRIVATE; |
| 28 | const NameServerClassifier::NameServersType kPublic = |
| 29 | NameServerClassifier::NAME_SERVERS_TYPE_PUBLIC; |
| 30 | const NameServerClassifier::NameServersType kMixed = |
| 31 | NameServerClassifier::NAME_SERVERS_TYPE_MIXED; |
| 32 | |
| 33 | class NameServerClassifierTest : public testing::Test { |
| 34 | protected: |
| 35 | NameServerClassifier::NameServersType Classify( |
| 36 | const std::string& servers_string) { |
| 37 | std::vector<std::string> server_strings; |
| 38 | base::SplitString(servers_string, ' ', &server_strings); |
| 39 | |
| 40 | std::vector<IPEndPoint> servers; |
| 41 | for (std::vector<std::string>::const_iterator it = server_strings.begin(); |
| 42 | it != server_strings.end(); |
| 43 | ++it) { |
| 44 | if (*it == "") |
| 45 | continue; |
| 46 | |
| 47 | IPAddressNumber address; |
| 48 | bool parsed = ParseIPLiteralToNumber(*it, &address); |
| 49 | EXPECT_TRUE(parsed); |
| 50 | servers.push_back(IPEndPoint(address, dns_protocol::kDefaultPort)); |
| 51 | } |
| 52 | |
| 53 | return classifier_.GetNameServersType(servers); |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | NameServerClassifier classifier_; |
| 58 | }; |
| 59 | |
| 60 | TEST_F(NameServerClassifierTest, None) { |
| 61 | EXPECT_EQ(kNone, Classify("")); |
| 62 | } |
| 63 | |
| 64 | TEST_F(NameServerClassifierTest, Google) { |
| 65 | EXPECT_EQ(kGoogle, Classify("8.8.8.8")); |
| 66 | EXPECT_EQ(kGoogle, Classify("8.8.8.8 8.8.4.4")); |
| 67 | EXPECT_EQ(kGoogle, Classify("2001:4860:4860::8888")); |
| 68 | EXPECT_EQ(kGoogle, Classify("2001:4860:4860::8888 2001:4860:4860::8844")); |
| 69 | EXPECT_EQ(kGoogle, Classify("2001:4860:4860::8888 8.8.8.8")); |
| 70 | |
| 71 | // Make sure nobody took any shortcuts on the IP matching: |
| 72 | EXPECT_EQ(kPublic, Classify("8.8.8.4")); |
| 73 | EXPECT_EQ(kPublic, Classify("8.8.4.8")); |
| 74 | EXPECT_EQ(kPublic, Classify("2001:4860:4860::8884")); |
| 75 | EXPECT_EQ(kPublic, Classify("2001:4860:4860::8848")); |
| 76 | EXPECT_EQ(kPublic, Classify("2001:4860:4860::1:8888")); |
| 77 | EXPECT_EQ(kPublic, Classify("2001:4860:4860:1::8888")); |
| 78 | } |
| 79 | |
| 80 | TEST_F(NameServerClassifierTest, PrivateLocalhost) { |
| 81 | EXPECT_EQ(kPrivate, Classify("127.0.0.1")); |
| 82 | EXPECT_EQ(kPrivate, Classify("::1")); |
| 83 | } |
| 84 | |
| 85 | TEST_F(NameServerClassifierTest, PrivateRfc1918) { |
| 86 | EXPECT_EQ(kPrivate, Classify("10.0.0.0 10.255.255.255")); |
| 87 | EXPECT_EQ(kPrivate, Classify("172.16.0.0 172.31.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")); |
| 90 | } |
| 91 | |
| 92 | TEST_F(NameServerClassifierTest, PrivateIPv4LinkLocal) { |
| 93 | EXPECT_EQ(kPrivate, Classify("169.254.0.0 169.254.255.255")); |
| 94 | } |
| 95 | |
| 96 | TEST_F(NameServerClassifierTest, PrivateIPv6LinkLocal) { |
| 97 | EXPECT_EQ(kPrivate, |
| 98 | Classify("fe80:: fe80:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); |
| 99 | } |
| 100 | |
| 101 | TEST_F(NameServerClassifierTest, Public) { |
| 102 | EXPECT_EQ(kPublic, Classify("4.2.2.1")); |
| 103 | EXPECT_EQ(kPublic, Classify("4.2.2.1 4.2.2.2")); |
| 104 | } |
| 105 | |
| 106 | TEST_F(NameServerClassifierTest, Mixed) { |
| 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")); |
| 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")); |
| 111 | } |
| 112 | |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 113 | class DnsConfigServiceTest : public testing::Test { |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 114 | public: |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 115 | void OnConfigChanged(const DnsConfig& config) { |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 116 | last_config_ = config; |
| 117 | if (quit_on_config_) |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 118 | base::MessageLoop::current()->Quit(); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 119 | } |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 120 | |
| 121 | protected: |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 122 | class TestDnsConfigService : public DnsConfigService { |
| 123 | public: |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 124 | virtual void ReadNow() OVERRIDE {} |
| 125 | virtual bool StartWatching() OVERRIDE { return true; } |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 126 | |
| 127 | // Expose the protected methods to this test suite. |
| 128 | void InvalidateConfig() { |
| 129 | DnsConfigService::InvalidateConfig(); |
| 130 | } |
| 131 | |
| 132 | void InvalidateHosts() { |
| 133 | DnsConfigService::InvalidateHosts(); |
| 134 | } |
| 135 | |
| 136 | void OnConfigRead(const DnsConfig& config) { |
| 137 | DnsConfigService::OnConfigRead(config); |
| 138 | } |
| 139 | |
| 140 | void OnHostsRead(const DnsHosts& hosts) { |
| 141 | DnsConfigService::OnHostsRead(hosts); |
| 142 | } |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 143 | |
| 144 | void set_watch_failed(bool value) { |
| 145 | DnsConfigService::set_watch_failed(value); |
| 146 | } |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | void WaitForConfig(base::TimeDelta timeout) { |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 150 | base::CancelableClosure closure(base::MessageLoop::QuitClosure()); |
| 151 | base::MessageLoop::current()->PostDelayedTask( |
| 152 | FROM_HERE, closure.callback(), timeout); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 153 | quit_on_config_ = true; |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 154 | base::MessageLoop::current()->Run(); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 155 | quit_on_config_ = false; |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 156 | closure.Cancel(); |
| 157 | } |
| 158 | |
| 159 | // Generate a config using the given seed.. |
| 160 | DnsConfig MakeConfig(unsigned seed) { |
| 161 | DnsConfig config; |
| 162 | IPAddressNumber ip; |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 163 | CHECK(ParseIPLiteralToNumber("1.2.3.4", &ip)); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 164 | config.nameservers.push_back(IPEndPoint(ip, seed & 0xFFFF)); |
| 165 | EXPECT_TRUE(config.IsValid()); |
| 166 | return config; |
| 167 | } |
| 168 | |
| 169 | // Generate hosts using the given seed. |
| 170 | DnsHosts MakeHosts(unsigned seed) { |
| 171 | DnsHosts hosts; |
| 172 | std::string hosts_content = "127.0.0.1 localhost"; |
| 173 | hosts_content.append(seed, '1'); |
| 174 | ParseHosts(hosts_content, &hosts); |
| 175 | EXPECT_FALSE(hosts.empty()); |
| 176 | return hosts; |
| 177 | } |
| 178 | |
| 179 | virtual void SetUp() OVERRIDE { |
| 180 | quit_on_config_ = false; |
| 181 | |
| 182 | service_.reset(new TestDnsConfigService()); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 183 | service_->WatchConfig(base::Bind(&DnsConfigServiceTest::OnConfigChanged, |
| 184 | base::Unretained(this))); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 185 | EXPECT_FALSE(last_config_.IsValid()); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | DnsConfig last_config_; |
| 189 | bool quit_on_config_; |
| 190 | |
| 191 | // Service under test. |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 192 | scoped_ptr<TestDnsConfigService> service_; |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | } // namespace |
| 196 | |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 197 | TEST_F(DnsConfigServiceTest, FirstConfig) { |
| 198 | DnsConfig config = MakeConfig(1); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 199 | |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 200 | service_->OnConfigRead(config); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 201 | // No hosts yet, so no config. |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 202 | EXPECT_TRUE(last_config_.Equals(DnsConfig())); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 203 | |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 204 | service_->OnHostsRead(config.hosts); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 205 | EXPECT_TRUE(last_config_.Equals(config)); |
| 206 | } |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 207 | |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 208 | TEST_F(DnsConfigServiceTest, Timeout) { |
| 209 | DnsConfig config = MakeConfig(1); |
| 210 | config.hosts = MakeHosts(1); |
[email protected] | 163d9b2 | 2012-06-12 19:50:36 | [diff] [blame] | 211 | ASSERT_TRUE(config.IsValid()); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 212 | |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 213 | service_->OnConfigRead(config); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 214 | service_->OnHostsRead(config.hosts); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 215 | EXPECT_FALSE(last_config_.Equals(DnsConfig())); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 216 | EXPECT_TRUE(last_config_.Equals(config)); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 217 | |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 218 | service_->InvalidateConfig(); |
| 219 | WaitForConfig(TestTimeouts::action_timeout()); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 220 | EXPECT_FALSE(last_config_.Equals(config)); |
| 221 | EXPECT_TRUE(last_config_.Equals(DnsConfig())); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 222 | |
| 223 | service_->OnConfigRead(config); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 224 | EXPECT_FALSE(last_config_.Equals(DnsConfig())); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 225 | EXPECT_TRUE(last_config_.Equals(config)); |
| 226 | |
| 227 | service_->InvalidateHosts(); |
| 228 | WaitForConfig(TestTimeouts::action_timeout()); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 229 | EXPECT_FALSE(last_config_.Equals(config)); |
| 230 | EXPECT_TRUE(last_config_.Equals(DnsConfig())); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 231 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 232 | DnsConfig bad_config = last_config_ = MakeConfig(0xBAD); |
[email protected] | 163d9b2 | 2012-06-12 19:50:36 | [diff] [blame] | 233 | service_->InvalidateConfig(); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 234 | // We don't expect an update. This should time out. |
[email protected] | 163d9b2 | 2012-06-12 19:50:36 | [diff] [blame] | 235 | WaitForConfig(base::TimeDelta::FromMilliseconds(100) + |
| 236 | TestTimeouts::tiny_timeout()); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 237 | EXPECT_TRUE(last_config_.Equals(bad_config)) << "Unexpected change"; |
[email protected] | 163d9b2 | 2012-06-12 19:50:36 | [diff] [blame] | 238 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 239 | last_config_ = DnsConfig(); |
[email protected] | 163d9b2 | 2012-06-12 19:50:36 | [diff] [blame] | 240 | service_->OnConfigRead(config); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 241 | service_->OnHostsRead(config.hosts); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 242 | EXPECT_FALSE(last_config_.Equals(DnsConfig())); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 243 | EXPECT_TRUE(last_config_.Equals(config)); |
| 244 | } |
| 245 | |
| 246 | TEST_F(DnsConfigServiceTest, SameConfig) { |
| 247 | DnsConfig config = MakeConfig(1); |
| 248 | config.hosts = MakeHosts(1); |
| 249 | |
| 250 | service_->OnConfigRead(config); |
| 251 | service_->OnHostsRead(config.hosts); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 252 | EXPECT_FALSE(last_config_.Equals(DnsConfig())); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 253 | EXPECT_TRUE(last_config_.Equals(config)); |
| 254 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 255 | last_config_ = DnsConfig(); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 256 | service_->OnConfigRead(config); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 257 | EXPECT_TRUE(last_config_.Equals(DnsConfig())) << "Unexpected change"; |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 258 | |
| 259 | service_->OnHostsRead(config.hosts); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 260 | EXPECT_TRUE(last_config_.Equals(DnsConfig())) << "Unexpected change"; |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | TEST_F(DnsConfigServiceTest, DifferentConfig) { |
| 264 | DnsConfig config1 = MakeConfig(1); |
| 265 | DnsConfig config2 = MakeConfig(2); |
| 266 | DnsConfig config3 = MakeConfig(1); |
| 267 | config1.hosts = MakeHosts(1); |
| 268 | config2.hosts = MakeHosts(1); |
| 269 | config3.hosts = MakeHosts(2); |
| 270 | ASSERT_TRUE(config1.EqualsIgnoreHosts(config3)); |
| 271 | ASSERT_FALSE(config1.Equals(config2)); |
| 272 | ASSERT_FALSE(config1.Equals(config3)); |
| 273 | ASSERT_FALSE(config2.Equals(config3)); |
| 274 | |
| 275 | service_->OnConfigRead(config1); |
| 276 | service_->OnHostsRead(config1.hosts); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 277 | EXPECT_FALSE(last_config_.Equals(DnsConfig())); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 278 | EXPECT_TRUE(last_config_.Equals(config1)); |
| 279 | |
| 280 | // It doesn't matter for this tests, but increases coverage. |
| 281 | service_->InvalidateConfig(); |
| 282 | service_->InvalidateHosts(); |
| 283 | |
| 284 | service_->OnConfigRead(config2); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 285 | EXPECT_TRUE(last_config_.Equals(config1)) << "Unexpected change"; |
| 286 | service_->OnHostsRead(config2.hosts); // Not an actual change. |
| 287 | EXPECT_FALSE(last_config_.Equals(config1)); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 288 | EXPECT_TRUE(last_config_.Equals(config2)); |
| 289 | |
| 290 | service_->OnConfigRead(config3); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 291 | EXPECT_TRUE(last_config_.EqualsIgnoreHosts(config3)); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 292 | service_->OnHostsRead(config3.hosts); |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 293 | EXPECT_FALSE(last_config_.Equals(config2)); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 294 | EXPECT_TRUE(last_config_.Equals(config3)); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 297 | TEST_F(DnsConfigServiceTest, WatchFailure) { |
| 298 | DnsConfig config1 = MakeConfig(1); |
| 299 | DnsConfig config2 = MakeConfig(2); |
| 300 | config1.hosts = MakeHosts(1); |
| 301 | config2.hosts = MakeHosts(2); |
| 302 | |
| 303 | service_->OnConfigRead(config1); |
| 304 | service_->OnHostsRead(config1.hosts); |
| 305 | EXPECT_FALSE(last_config_.Equals(DnsConfig())); |
| 306 | EXPECT_TRUE(last_config_.Equals(config1)); |
| 307 | |
| 308 | // Simulate watch failure. |
| 309 | service_->set_watch_failed(true); |
| 310 | service_->InvalidateConfig(); |
| 311 | WaitForConfig(TestTimeouts::action_timeout()); |
| 312 | EXPECT_FALSE(last_config_.Equals(config1)); |
| 313 | EXPECT_TRUE(last_config_.Equals(DnsConfig())); |
| 314 | |
| 315 | DnsConfig bad_config = last_config_ = MakeConfig(0xBAD); |
| 316 | // Actual change in config, so expect an update, but it should be empty. |
| 317 | service_->OnConfigRead(config1); |
| 318 | EXPECT_FALSE(last_config_.Equals(bad_config)); |
| 319 | EXPECT_TRUE(last_config_.Equals(DnsConfig())); |
| 320 | |
| 321 | last_config_ = bad_config; |
| 322 | // Actual change in config, so expect an update, but it should be empty. |
| 323 | service_->InvalidateConfig(); |
| 324 | service_->OnConfigRead(config2); |
| 325 | EXPECT_FALSE(last_config_.Equals(bad_config)); |
| 326 | EXPECT_TRUE(last_config_.Equals(DnsConfig())); |
| 327 | |
| 328 | last_config_ = bad_config; |
| 329 | // No change, so no update. |
| 330 | service_->InvalidateConfig(); |
| 331 | service_->OnConfigRead(config2); |
| 332 | EXPECT_TRUE(last_config_.Equals(bad_config)); |
| 333 | } |
| 334 | |
[email protected] | 539df6c | 2012-06-19 21:21:29 | [diff] [blame] | 335 | #if (defined(OS_POSIX) && !defined(OS_ANDROID)) || defined(OS_WIN) |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 336 | // TODO(szym): This is really an integration test and can time out if HOSTS is |
| 337 | // huge. http://crbug.com/107810 |
[email protected] | 1e09ec8 | 2012-12-21 22:48:09 | [diff] [blame] | 338 | TEST_F(DnsConfigServiceTest, DISABLED_GetSystemConfig) { |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 339 | service_.reset(); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 340 | scoped_ptr<DnsConfigService> service(DnsConfigService::CreateSystemService()); |
| 341 | |
[email protected] | bb0e3454 | 2012-08-31 19:52:40 | [diff] [blame] | 342 | service->ReadConfig(base::Bind(&DnsConfigServiceTest::OnConfigChanged, |
| 343 | base::Unretained(this))); |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 344 | base::TimeDelta kTimeout = TestTimeouts::action_max_timeout(); |
| 345 | WaitForConfig(kTimeout); |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 346 | ASSERT_TRUE(last_config_.IsValid()) << "Did not receive DnsConfig in " << |
[email protected] | b4481b22 | 2012-03-16 17:13:11 | [diff] [blame] | 347 | kTimeout.InSecondsF() << "s"; |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 348 | } |
[email protected] | 76d7f72 | 2011-10-10 17:22:41 | [diff] [blame] | 349 | #endif // OS_POSIX || OS_WIN |
[email protected] | 6998a66 | 2011-09-03 00:17:29 | [diff] [blame] | 350 | |
| 351 | } // namespace net |
| 352 | |