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
3 // found in the LICENSE file.
5 #include "net/base/net_test_suite.h"
7 #include "base/message_loop.h"
8 #include "net/base/network_change_notifier.h"
9 #include "net/http/http_stream_factory.h"
10 #include "net/spdy/spdy_session.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 #if defined(USE_NSS) || defined(OS_IOS)
14 #include "net/ocsp/nss_ocsp.h"
17 class StaticReset
: public ::testing::EmptyTestEventListener
{
18 virtual void OnTestStart(const ::testing::TestInfo
& test_info
) OVERRIDE
{
19 net::HttpStreamFactory::ResetStaticSettingsToInit();
20 net::SpdySession::ResetStaticSettingsToInit();
24 NetTestSuite::NetTestSuite(int argc
, char** argv
)
25 : TestSuite(argc
, argv
) {
28 NetTestSuite::NetTestSuite(int argc
, char** argv
,
29 bool create_at_exit_manager
)
30 : TestSuite(argc
, argv
, create_at_exit_manager
) {
33 NetTestSuite::~NetTestSuite() {}
35 void NetTestSuite::Initialize() {
36 TestSuite::Initialize();
37 ::testing::UnitTest::GetInstance()->listeners().Append(new StaticReset());
38 InitializeTestThread();
41 void NetTestSuite::Shutdown() {
42 #if defined(USE_NSS) || defined(OS_IOS)
43 net::ShutdownNSSHttpIO();
46 // We want to destroy this here before the TestSuite continues to tear down
48 message_loop_
.reset();
50 TestSuite::Shutdown();
53 void NetTestSuite::InitializeTestThread() {
54 network_change_notifier_
.reset(net::NetworkChangeNotifier::CreateMock());
56 InitializeTestThreadNoNetworkChangeNotifier();
59 void NetTestSuite::InitializeTestThreadNoNetworkChangeNotifier() {
60 host_resolver_proc_
= new net::RuleBasedHostResolverProc(NULL
);
61 scoped_host_resolver_proc_
.Init(host_resolver_proc_
.get());
62 // In case any attempts are made to resolve host names, force them all to
63 // be mapped to localhost. This prevents DNS queries from being sent in
64 // the process of running these unit tests.
65 host_resolver_proc_
->AddRule("*", "127.0.0.1");
67 message_loop_
.reset(new MessageLoopForIO());