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