| 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/test/net_test_suite.h" | 5 #include "net/test/net_test_suite.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/test/scoped_task_environment.h" |
| 8 #include "net/base/network_change_notifier.h" | 9 #include "net/base/network_change_notifier.h" |
| 9 #include "net/http/http_stream_factory.h" | 10 #include "net/http/http_stream_factory.h" |
| 10 #include "net/spdy/chromium/spdy_session.h" | 11 #include "net/spdy/chromium/spdy_session.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 #if defined(USE_NSS_CERTS) | 14 #if defined(USE_NSS_CERTS) |
| 14 #include "net/cert_net/nss_ocsp.h" | 15 #include "net/cert_net/nss_ocsp.h" |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 NetTestSuite::NetTestSuite(int argc, char** argv) | 18 NetTestSuite::NetTestSuite(int argc, char** argv) |
| 18 : TestSuite(argc, argv) { | 19 : TestSuite(argc, argv) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 NetTestSuite::~NetTestSuite() {} | 22 NetTestSuite::~NetTestSuite() {} |
| 22 | 23 |
| 23 void NetTestSuite::Initialize() { | 24 void NetTestSuite::Initialize() { |
| 24 TestSuite::Initialize(); | 25 TestSuite::Initialize(); |
| 25 InitializeTestThread(); | 26 InitializeTestThread(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 void NetTestSuite::Shutdown() { | 29 void NetTestSuite::Shutdown() { |
| 29 #if defined(USE_NSS_CERTS) | 30 #if defined(USE_NSS_CERTS) |
| 30 net::ShutdownNSSHttpIO(); | 31 net::ShutdownNSSHttpIO(); |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 // We want to destroy this here before the TestSuite continues to tear down | 34 // We want to destroy this here before the TestSuite continues to tear down |
| 34 // the environment. | 35 // the environment. |
| 35 message_loop_.reset(); | 36 scoped_task_environment_.reset(); |
| 36 | 37 |
| 37 TestSuite::Shutdown(); | 38 TestSuite::Shutdown(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void NetTestSuite::InitializeTestThread() { | 41 void NetTestSuite::InitializeTestThread() { |
| 41 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 42 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
| 42 | 43 |
| 43 InitializeTestThreadNoNetworkChangeNotifier(); | 44 InitializeTestThreadNoNetworkChangeNotifier(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 void NetTestSuite::InitializeTestThreadNoNetworkChangeNotifier() { | 47 void NetTestSuite::InitializeTestThreadNoNetworkChangeNotifier() { |
| 47 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); | 48 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); |
| 48 scoped_host_resolver_proc_.Init(host_resolver_proc_.get()); | 49 scoped_host_resolver_proc_.Init(host_resolver_proc_.get()); |
| 49 // In case any attempts are made to resolve host names, force them all to | 50 // In case any attempts are made to resolve host names, force them all to |
| 50 // be mapped to localhost. This prevents DNS queries from being sent in | 51 // be mapped to localhost. This prevents DNS queries from being sent in |
| 51 // the process of running these unit tests. | 52 // the process of running these unit tests. |
| 52 host_resolver_proc_->AddRule("*", "127.0.0.1"); | 53 host_resolver_proc_->AddRule("*", "127.0.0.1"); |
| 53 | 54 |
| 54 message_loop_.reset(new base::MessageLoopForIO()); | 55 scoped_task_environment_ = |
| 56 base::MakeUnique<base::test::ScopedTaskEnvironment>( |
| 57 base::test::ScopedTaskEnvironment::MainThreadType::IO); |
| 55 } | 58 } |
| OLD | NEW |