| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef NET_BASE_NET_TEST_SUITE_H_ | 5 #ifndef NET_BASE_NET_TEST_SUITE_H_ |
| 6 #define NET_BASE_NET_TEST_SUITE_H_ | 6 #define NET_BASE_NET_TEST_SUITE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/message_loop.h" | |
| 10 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 11 #include "base/test/test_suite.h" | 10 #include "base/test/test_suite.h" |
| 12 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 13 #include "net/base/mock_host_resolver.h" | 12 #include "net/base/mock_host_resolver.h" |
| 14 #if defined(USE_NSS) | 13 |
| 15 #include "net/ocsp/nss_ocsp.h" | 14 class MessageLoop; |
| 16 #endif | 15 |
| 16 namespace net { |
| 17 class NetworkChangeNotifier; |
| 18 } |
| 17 | 19 |
| 18 class NetTestSuite : public base::TestSuite { | 20 class NetTestSuite : public base::TestSuite { |
| 19 public: | 21 public: |
| 20 NetTestSuite(int argc, char** argv) : TestSuite(argc, argv) { | 22 NetTestSuite(int argc, char** argv); |
| 21 } | 23 virtual ~NetTestSuite(); |
| 22 | 24 |
| 23 virtual void Initialize() { | 25 virtual void Initialize(); |
| 24 TestSuite::Initialize(); | 26 |
| 25 InitializeTestThread(); | 27 virtual void Shutdown(); |
| 26 } | 28 |
| 29 protected: |
| 27 | 30 |
| 28 // Called from within Initialize(), but separate so that derived classes | 31 // Called from within Initialize(), but separate so that derived classes |
| 29 // can initialize the NetTestSuite instance only and not | 32 // can initialize the NetTestSuite instance only and not |
| 30 // TestSuite::Initialize(). TestSuite::Initialize() performs some global | 33 // TestSuite::Initialize(). TestSuite::Initialize() performs some global |
| 31 // initialization that can only be done once. | 34 // initialization that can only be done once. |
| 32 void InitializeTestThread() { | 35 void InitializeTestThread(); |
| 33 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | |
| 34 | |
| 35 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); | |
| 36 scoped_host_resolver_proc_.Init(host_resolver_proc_.get()); | |
| 37 // In case any attempts are made to resolve host names, force them all to | |
| 38 // be mapped to localhost. This prevents DNS queries from being sent in | |
| 39 // the process of running these unit tests. | |
| 40 host_resolver_proc_->AddRule("*", "127.0.0.1"); | |
| 41 | |
| 42 message_loop_.reset(new MessageLoopForIO()); | |
| 43 } | |
| 44 | |
| 45 virtual void Shutdown() { | |
| 46 #if defined(USE_NSS) | |
| 47 net::ShutdownOCSP(); | |
| 48 #endif | |
| 49 | |
| 50 // We want to destroy this here before the TestSuite continues to tear down | |
| 51 // the environment. | |
| 52 message_loop_.reset(); | |
| 53 | |
| 54 TestSuite::Shutdown(); | |
| 55 } | |
| 56 | 36 |
| 57 private: | 37 private: |
| 58 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 38 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 59 scoped_ptr<MessageLoop> message_loop_; | 39 scoped_ptr<MessageLoop> message_loop_; |
| 60 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; | 40 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; |
| 61 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; | 41 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; |
| 62 }; | 42 }; |
| 63 | 43 |
| 64 #endif // NET_BASE_NET_TEST_SUITE_H_ | 44 #endif // NET_BASE_NET_TEST_SUITE_H_ |
| OLD | NEW |