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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 service_->OnHostsRead(config.hosts); | 108 service_->OnHostsRead(config.hosts); |
109 // Empty hosts is acceptable. | 109 // Empty hosts is acceptable. |
110 EXPECT_TRUE(last_config_.IsValid()); | 110 EXPECT_TRUE(last_config_.IsValid()); |
111 EXPECT_TRUE(last_config_.Equals(config)); | 111 EXPECT_TRUE(last_config_.Equals(config)); |
112 } | 112 } |
113 | 113 |
114 TEST_F(DnsConfigServiceTest, Timeout) { | 114 TEST_F(DnsConfigServiceTest, Timeout) { |
115 DnsConfig config = MakeConfig(1); | 115 DnsConfig config = MakeConfig(1); |
116 config.hosts = MakeHosts(1); | 116 config.hosts = MakeHosts(1); |
| 117 ASSERT_TRUE(config.IsValid()); |
117 | 118 |
118 service_->OnConfigRead(config); | 119 service_->OnConfigRead(config); |
119 service_->OnHostsRead(config.hosts); | 120 service_->OnHostsRead(config.hosts); |
120 EXPECT_TRUE(last_config_.IsValid()); | 121 EXPECT_TRUE(last_config_.IsValid()); |
121 EXPECT_TRUE(last_config_.Equals(config)); | 122 EXPECT_TRUE(last_config_.Equals(config)); |
122 | 123 |
123 service_->InvalidateConfig(); | 124 service_->InvalidateConfig(); |
124 WaitForConfig(TestTimeouts::action_timeout()); | 125 WaitForConfig(TestTimeouts::action_timeout()); |
125 EXPECT_FALSE(last_config_.IsValid()); | 126 EXPECT_FALSE(last_config_.IsValid()); |
126 | 127 |
127 service_->OnConfigRead(config); | 128 service_->OnConfigRead(config); |
128 EXPECT_TRUE(last_config_.Equals(config)); | 129 EXPECT_TRUE(last_config_.Equals(config)); |
129 | 130 |
130 service_->InvalidateHosts(); | 131 service_->InvalidateHosts(); |
131 WaitForConfig(TestTimeouts::action_timeout()); | 132 WaitForConfig(TestTimeouts::action_timeout()); |
132 EXPECT_FALSE(last_config_.IsValid()); | 133 EXPECT_FALSE(last_config_.IsValid()); |
133 | 134 |
| 135 service_->InvalidateConfig(); |
| 136 // We don't expect an update. This should time out. If we get an update, |
| 137 // we'll detect unchanged config. |
| 138 WaitForConfig(base::TimeDelta::FromMilliseconds(100) + |
| 139 TestTimeouts::tiny_timeout()); |
| 140 EXPECT_FALSE(last_config_.IsValid()); |
| 141 |
| 142 service_->OnConfigRead(config); |
134 service_->OnHostsRead(config.hosts); | 143 service_->OnHostsRead(config.hosts); |
135 EXPECT_TRUE(last_config_.Equals(config)); | 144 EXPECT_TRUE(last_config_.Equals(config)); |
136 } | 145 } |
137 | 146 |
138 TEST_F(DnsConfigServiceTest, SameConfig) { | 147 TEST_F(DnsConfigServiceTest, SameConfig) { |
139 DnsConfig config = MakeConfig(1); | 148 DnsConfig config = MakeConfig(1); |
140 config.hosts = MakeHosts(1); | 149 config.hosts = MakeHosts(1); |
141 | 150 |
142 service_->OnConfigRead(config); | 151 service_->OnConfigRead(config); |
143 service_->OnHostsRead(config.hosts); | 152 service_->OnHostsRead(config.hosts); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 base::Unretained(this))); | 200 base::Unretained(this))); |
192 base::TimeDelta kTimeout = TestTimeouts::action_max_timeout(); | 201 base::TimeDelta kTimeout = TestTimeouts::action_max_timeout(); |
193 WaitForConfig(kTimeout); | 202 WaitForConfig(kTimeout); |
194 ASSERT_TRUE(last_config_.IsValid()) << "Did not receive DnsConfig in " << | 203 ASSERT_TRUE(last_config_.IsValid()) << "Did not receive DnsConfig in " << |
195 kTimeout.InSecondsF() << "s"; | 204 kTimeout.InSecondsF() << "s"; |
196 } | 205 } |
197 #endif // OS_POSIX || OS_WIN | 206 #endif // OS_POSIX || OS_WIN |
198 | 207 |
199 } // namespace net | 208 } // namespace net |
200 | 209 |
OLD | NEW |