diff options
-rw-r--r-- | net/base/host_resolver_unittest.h | 8 | ||||
-rw-r--r-- | net/base/run_all_unittests.cc | 16 |
2 files changed, 16 insertions, 8 deletions
diff --git a/net/base/host_resolver_unittest.h b/net/base/host_resolver_unittest.h index 5531bd0..e7a9c1a 100644 --- a/net/base/host_resolver_unittest.h +++ b/net/base/host_resolver_unittest.h @@ -125,12 +125,20 @@ class ScopedHostMapper { current_host_mapper_->set_previous_mapper(previous_host_mapper_.get()); } + ScopedHostMapper() {} + ~ScopedHostMapper() { HostMapper* old_mapper = SetHostMapper(previous_host_mapper_.get()); // The lifetimes of multiple instances must be nested. CHECK(old_mapper == current_host_mapper_.get()); } + void Init(HostMapper* mapper) { + current_host_mapper_ = mapper; + previous_host_mapper_ = SetHostMapper(current_host_mapper_.get()); + current_host_mapper_->set_previous_mapper(previous_host_mapper_.get()); + } + private: scoped_refptr<HostMapper> current_host_mapper_; scoped_refptr<HostMapper> previous_host_mapper_; diff --git a/net/base/run_all_unittests.cc b/net/base/run_all_unittests.cc index 15741e4..6c60e2d 100644 --- a/net/base/run_all_unittests.cc +++ b/net/base/run_all_unittests.cc @@ -34,19 +34,19 @@ class NetTestSuite : public TestSuite { public: - NetTestSuite(int argc, char** argv) - : TestSuite(argc, argv), - host_mapper_(new net::RuleBasedHostMapper()), - scoped_host_mapper_(host_mapper_.get()) { - // In case any attempts are made to resolve host names, force them all to - // be mapped to localhost. This prevents DNS queries from being sent in - // the process of running these unit tests. - host_mapper_->AddRule("*", "127.0.0.1"); + NetTestSuite(int argc, char** argv) : TestSuite(argc, argv) { } virtual void Initialize() { TestSuite::Initialize(); + host_mapper_ = new net::RuleBasedHostMapper(); + scoped_host_mapper_.Init(host_mapper_.get()); + // In case any attempts are made to resolve host names, force them all to + // be mapped to localhost. This prevents DNS queries from being sent in + // the process of running these unit tests. + host_mapper_->AddRule("*", "127.0.0.1"); + message_loop_.reset(new MessageLoopForIO()); } |