| 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 11 matching lines...) Expand all Loading... |
| 22 EXPECT_FALSE(config.Equals(last_config_)) << | 22 EXPECT_FALSE(config.Equals(last_config_)) << |
| 23 "Config must be different from last call."; | 23 "Config must be different from last call."; |
| 24 last_config_ = config; | 24 last_config_ = config; |
| 25 if (quit_on_config_) | 25 if (quit_on_config_) |
| 26 MessageLoop::current()->Quit(); | 26 MessageLoop::current()->Quit(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 protected: | 29 protected: |
| 30 class TestDnsConfigService : public DnsConfigService { | 30 class TestDnsConfigService : public DnsConfigService { |
| 31 public: | 31 public: |
| 32 virtual void OnDNSChanged(unsigned detail) OVERRIDE {} | 32 virtual void ReadNow() OVERRIDE {} |
| 33 virtual bool StartWatching() OVERRIDE { return true; } |
| 33 | 34 |
| 34 // Expose the protected methods to this test suite. | 35 // Expose the protected methods to this test suite. |
| 35 void InvalidateConfig() { | 36 void InvalidateConfig() { |
| 36 DnsConfigService::InvalidateConfig(); | 37 DnsConfigService::InvalidateConfig(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void InvalidateHosts() { | 40 void InvalidateHosts() { |
| 40 DnsConfigService::InvalidateHosts(); | 41 DnsConfigService::InvalidateHosts(); |
| 41 } | 42 } |
| 42 | 43 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 hosts_content.append(seed, '1'); | 78 hosts_content.append(seed, '1'); |
| 78 ParseHosts(hosts_content, &hosts); | 79 ParseHosts(hosts_content, &hosts); |
| 79 EXPECT_FALSE(hosts.empty()); | 80 EXPECT_FALSE(hosts.empty()); |
| 80 return hosts; | 81 return hosts; |
| 81 } | 82 } |
| 82 | 83 |
| 83 virtual void SetUp() OVERRIDE { | 84 virtual void SetUp() OVERRIDE { |
| 84 quit_on_config_ = false; | 85 quit_on_config_ = false; |
| 85 | 86 |
| 86 service_.reset(new TestDnsConfigService()); | 87 service_.reset(new TestDnsConfigService()); |
| 87 service_->Watch(base::Bind(&DnsConfigServiceTest::OnConfigChanged, | 88 service_->WatchConfig(base::Bind(&DnsConfigServiceTest::OnConfigChanged, |
| 88 base::Unretained(this))); | 89 base::Unretained(this))); |
| 89 EXPECT_FALSE(last_config_.IsValid()); | 90 EXPECT_FALSE(last_config_.IsValid()); |
| 90 } | 91 } |
| 91 | 92 |
| 92 DnsConfig last_config_; | 93 DnsConfig last_config_; |
| 93 bool quit_on_config_; | 94 bool quit_on_config_; |
| 94 | 95 |
| 95 // Service under test. | 96 // Service under test. |
| 96 scoped_ptr<TestDnsConfigService> service_; | 97 scoped_ptr<TestDnsConfigService> service_; |
| 97 }; | 98 }; |
| 98 | 99 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 EXPECT_TRUE(last_config_.Equals(config3)); | 190 EXPECT_TRUE(last_config_.Equals(config3)); |
| 190 } | 191 } |
| 191 | 192 |
| 192 #if (defined(OS_POSIX) && !defined(OS_ANDROID)) || defined(OS_WIN) | 193 #if (defined(OS_POSIX) && !defined(OS_ANDROID)) || defined(OS_WIN) |
| 193 // TODO(szym): This is really an integration test and can time out if HOSTS is | 194 // TODO(szym): This is really an integration test and can time out if HOSTS is |
| 194 // huge. http://crbug.com/107810 | 195 // huge. http://crbug.com/107810 |
| 195 TEST_F(DnsConfigServiceTest, FLAKY_GetSystemConfig) { | 196 TEST_F(DnsConfigServiceTest, FLAKY_GetSystemConfig) { |
| 196 service_.reset(); | 197 service_.reset(); |
| 197 scoped_ptr<DnsConfigService> service(DnsConfigService::CreateSystemService()); | 198 scoped_ptr<DnsConfigService> service(DnsConfigService::CreateSystemService()); |
| 198 | 199 |
| 199 service->Read(base::Bind(&DnsConfigServiceTest::OnConfigChanged, | 200 service->ReadConfig(base::Bind(&DnsConfigServiceTest::OnConfigChanged, |
| 200 base::Unretained(this))); | 201 base::Unretained(this))); |
| 201 base::TimeDelta kTimeout = TestTimeouts::action_max_timeout(); | 202 base::TimeDelta kTimeout = TestTimeouts::action_max_timeout(); |
| 202 WaitForConfig(kTimeout); | 203 WaitForConfig(kTimeout); |
| 203 ASSERT_TRUE(last_config_.IsValid()) << "Did not receive DnsConfig in " << | 204 ASSERT_TRUE(last_config_.IsValid()) << "Did not receive DnsConfig in " << |
| 204 kTimeout.InSecondsF() << "s"; | 205 kTimeout.InSecondsF() << "s"; |
| 205 } | 206 } |
| 206 #endif // OS_POSIX || OS_WIN | 207 #endif // OS_POSIX || OS_WIN |
| 207 | 208 |
| 208 } // namespace net | 209 } // namespace net |
| 209 | 210 |
| OLD | NEW |