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