Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: net/dns/dns_config_service_posix_unittest.cc

Issue 2136563002: Remove calls to MessageLoop::current() in base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/run_loop.h"
9 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
10 #include "base/test/test_timeouts.h" 11 #include "base/test/test_timeouts.h"
11 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
12 #include "net/base/ip_address.h" 13 #include "net/base/ip_address.h"
13 #include "net/dns/dns_config_service_posix.h" 14 #include "net/dns/dns_config_service_posix.h"
14 #include "net/dns/dns_protocol.h" 15 #include "net/dns/dns_protocol.h"
15 16
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 #if defined(OS_ANDROID) 19 #if defined(OS_ANDROID)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 #endif // !defined(OS_ANDROID) 201 #endif // !defined(OS_ANDROID)
201 202
202 class DnsConfigServicePosixTest : public testing::Test { 203 class DnsConfigServicePosixTest : public testing::Test {
203 public: 204 public:
204 DnsConfigServicePosixTest() : seen_config_(false) {} 205 DnsConfigServicePosixTest() : seen_config_(false) {}
205 ~DnsConfigServicePosixTest() override {} 206 ~DnsConfigServicePosixTest() override {}
206 207
207 void OnConfigChanged(const DnsConfig& config) { 208 void OnConfigChanged(const DnsConfig& config) {
208 EXPECT_TRUE(config.IsValid()); 209 EXPECT_TRUE(config.IsValid());
209 seen_config_ = true; 210 seen_config_ = true;
210 base::MessageLoop::current()->QuitWhenIdle(); 211 run_loop_.QuitWhenIdle();
211 } 212 }
212 213
213 void WriteMockHostsFile(const char* hosts_string) { 214 void WriteMockHostsFile(const char* hosts_string) {
214 ASSERT_EQ(base::WriteFile(temp_file_, hosts_string, strlen(hosts_string)), 215 ASSERT_EQ(base::WriteFile(temp_file_, hosts_string, strlen(hosts_string)),
215 static_cast<int>(strlen(hosts_string))); 216 static_cast<int>(strlen(hosts_string)));
216 } 217 }
217 218
218 void MockDNSConfig(const char* dns_server) { 219 void MockDNSConfig(const char* dns_server) {
219 IPAddress dns_address; 220 IPAddress dns_address;
220 ASSERT_TRUE(dns_address.AssignFromIPLiteral(dns_server)); 221 ASSERT_TRUE(dns_address.AssignFromIPLiteral(dns_server));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 MockHostsFilePath(temp_file_.value().c_str()); 260 MockHostsFilePath(temp_file_.value().c_str());
260 MockDNSConfig("8.8.8.8"); 261 MockDNSConfig("8.8.8.8");
261 seen_config_ = false; 262 seen_config_ = false;
262 service_->WatchConfig(base::Bind( 263 service_->WatchConfig(base::Bind(
263 &DnsConfigServicePosixTest::OnConfigChanged, base::Unretained(this))); 264 &DnsConfigServicePosixTest::OnConfigChanged, base::Unretained(this)));
264 ExpectChange(); 265 ExpectChange();
265 } 266 }
266 267
267 void ExpectChange() { 268 void ExpectChange() {
268 EXPECT_FALSE(seen_config_); 269 EXPECT_FALSE(seen_config_);
269 base::MessageLoop::current()->Run(); 270 run_loop_.Run();
270 EXPECT_TRUE(seen_config_); 271 EXPECT_TRUE(seen_config_);
271 seen_config_ = false; 272 seen_config_ = false;
272 } 273 }
273 274
274 bool seen_config_; 275 bool seen_config_;
275 base::Time creation_time_; 276 base::Time creation_time_;
276 base::FilePath temp_file_; 277 base::FilePath temp_file_;
277 std::unique_ptr<DnsConfigServicePosix> service_; 278 std::unique_ptr<DnsConfigServicePosix> service_;
278 DnsConfig test_config_; 279 DnsConfig test_config_;
280 base::RunLoop run_loop_;
279 }; 281 };
280 282
281 TEST_F(DnsConfigServicePosixTest, SeenChangeSinceNetworkChange) { 283 TEST_F(DnsConfigServicePosixTest, SeenChangeSinceNetworkChange) {
282 // Verify SeenChangeSince() returns false if no changes 284 // Verify SeenChangeSince() returns false if no changes
283 StartWatching(); 285 StartWatching();
284 EXPECT_FALSE(service_->SeenChangeSince(creation_time_)); 286 EXPECT_FALSE(service_->SeenChangeSince(creation_time_));
285 // Verify SeenChangeSince() returns true if network change 287 // Verify SeenChangeSince() returns true if network change
286 MockDNSConfig("8.8.4.4"); 288 MockDNSConfig("8.8.4.4");
287 service_->OnNetworkChanged(NetworkChangeNotifier::CONNECTION_WIFI); 289 service_->OnNetworkChanged(NetworkChangeNotifier::CONNECTION_WIFI);
288 EXPECT_TRUE(service_->SeenChangeSince(creation_time_)); 290 EXPECT_TRUE(service_->SeenChangeSince(creation_time_));
289 ExpectChange(); 291 ExpectChange();
290 } 292 }
291 293
292 } // namespace internal 294 } // namespace internal
293 295
294 #endif // OS_ANDROID 296 #endif // OS_ANDROID
295 297
296 } // namespace net 298 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698