| 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 <resolv.h> | 5 #include <resolv.h> |
| 6 | 6 |
| 7 #include "base/cancelable_callback.h" | 7 #include "base/cancelable_callback.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1000)); | 186 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1000)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace | 189 } // namespace |
| 190 | 190 |
| 191 #else // OS_ANDROID | 191 #else // OS_ANDROID |
| 192 | 192 |
| 193 namespace internal { | 193 namespace internal { |
| 194 | 194 |
| 195 const char kTempHosts1[] = "127.0.0.1 localhost"; | 195 const char kTempHosts1[] = "127.0.0.1 localhost"; |
| 196 // kTempHosts2 is only used by SeenChangeSinceHostsChange, which doesn't run |
| 197 // on Android. |
| 198 #if !defined(OS_ANDROID) |
| 196 const char kTempHosts2[] = "127.0.0.2 localhost"; | 199 const char kTempHosts2[] = "127.0.0.2 localhost"; |
| 200 #endif // !defined(OS_ANDROID) |
| 197 | 201 |
| 198 class DnsConfigServicePosixTest : public testing::Test { | 202 class DnsConfigServicePosixTest : public testing::Test { |
| 199 public: | 203 public: |
| 200 DnsConfigServicePosixTest() : seen_config_(false) {} | 204 DnsConfigServicePosixTest() : seen_config_(false) {} |
| 201 ~DnsConfigServicePosixTest() override {} | 205 ~DnsConfigServicePosixTest() override {} |
| 202 | 206 |
| 203 void OnConfigChanged(const DnsConfig& config) { | 207 void OnConfigChanged(const DnsConfig& config) { |
| 204 EXPECT_TRUE(config.IsValid()); | 208 EXPECT_TRUE(config.IsValid()); |
| 205 seen_config_ = true; | 209 seen_config_ = true; |
| 206 base::MessageLoop::current()->QuitWhenIdle(); | 210 base::MessageLoop::current()->QuitWhenIdle(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 seen_config_ = false; | 271 seen_config_ = false; |
| 268 } | 272 } |
| 269 | 273 |
| 270 bool seen_config_; | 274 bool seen_config_; |
| 271 base::Time creation_time_; | 275 base::Time creation_time_; |
| 272 base::FilePath temp_file_; | 276 base::FilePath temp_file_; |
| 273 scoped_ptr<DnsConfigServicePosix> service_; | 277 scoped_ptr<DnsConfigServicePosix> service_; |
| 274 DnsConfig test_config_; | 278 DnsConfig test_config_; |
| 275 }; | 279 }; |
| 276 | 280 |
| 277 TEST_F(DnsConfigServicePosixTest, SeenChangeSince) { | 281 TEST_F(DnsConfigServicePosixTest, SeenChangeSinceNetworkChange) { |
| 278 // Verify SeenChangeSince() returns false if no changes | 282 // Verify SeenChangeSince() returns false if no changes |
| 279 StartWatching(); | 283 StartWatching(); |
| 280 EXPECT_FALSE(service_->SeenChangeSince(creation_time_)); | 284 EXPECT_FALSE(service_->SeenChangeSince(creation_time_)); |
| 281 // Verify SeenChangeSince() returns true if network change | 285 // Verify SeenChangeSince() returns true if network change |
| 282 MockDNSConfig("8.8.4.4"); | 286 MockDNSConfig("8.8.4.4"); |
| 283 service_->OnNetworkChanged(NetworkChangeNotifier::CONNECTION_WIFI); | 287 service_->OnNetworkChanged(NetworkChangeNotifier::CONNECTION_WIFI); |
| 284 EXPECT_TRUE(service_->SeenChangeSince(creation_time_)); | 288 EXPECT_TRUE(service_->SeenChangeSince(creation_time_)); |
| 285 ExpectChange(); | 289 ExpectChange(); |
| 286 // Verify SeenChangeSince() returns true if hosts file changes | |
| 287 StartWatching(); | |
| 288 EXPECT_FALSE(service_->SeenChangeSince(creation_time_)); | |
| 289 WriteMockHostsFile(kTempHosts2); | |
| 290 EXPECT_TRUE(service_->SeenChangeSince(creation_time_)); | |
| 291 ExpectChange(); | |
| 292 } | 290 } |
| 293 | 291 |
| 294 } // namespace internal | 292 } // namespace internal |
| 295 | 293 |
| 296 #endif // OS_ANDROID | 294 #endif // OS_ANDROID |
| 297 | 295 |
| 298 } // namespace net | 296 } // namespace net |
| OLD | NEW |