OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_TEST_NET_TEST_SUITE_H_ | 5 #ifndef NET_TEST_NET_TEST_SUITE_H_ |
6 #define NET_TEST_NET_TEST_SUITE_H_ | 6 #define NET_TEST_NET_TEST_SUITE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/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/dns/mock_host_resolver.h" | 13 #include "net/dns/mock_host_resolver.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class MessageLoop; | 16 namespace test { |
| 17 class ScopedTaskEnvironment; |
| 18 } |
17 } | 19 } |
18 | 20 |
19 namespace net { | 21 namespace net { |
20 class NetworkChangeNotifier; | 22 class NetworkChangeNotifier; |
21 } | 23 } |
22 | 24 |
23 class NetTestSuite : public base::TestSuite { | 25 class NetTestSuite : public base::TestSuite { |
24 public: | 26 public: |
25 NetTestSuite(int argc, char** argv); | 27 NetTestSuite(int argc, char** argv); |
26 ~NetTestSuite() override; | 28 ~NetTestSuite() override; |
27 | 29 |
28 void Initialize() override; | 30 void Initialize() override; |
29 | 31 |
30 void Shutdown() override; | 32 void Shutdown() override; |
31 | 33 |
| 34 // Returns the base::test::ScopedTaskEnvironment initialized by the current |
| 35 // NetTestSuite. |
| 36 static base::test::ScopedTaskEnvironment* GetScopedTaskEnvironment(); |
| 37 |
32 protected: | 38 protected: |
33 // Called from within Initialize(), but separate so that derived classes | 39 // Called from within Initialize(), but separate so that derived classes |
34 // can initialize the NetTestSuite instance only and not | 40 // can initialize the NetTestSuite instance only and not |
35 // TestSuite::Initialize(). TestSuite::Initialize() performs some global | 41 // TestSuite::Initialize(). TestSuite::Initialize() performs some global |
36 // initialization that can only be done once. | 42 // initialization that can only be done once. |
37 void InitializeTestThread(); | 43 void InitializeTestThread(); |
38 | 44 |
39 // Same as above, except it does not create a mock | 45 // Same as above, except it does not create a mock |
40 // NetworkChangeNotifier. Use this if your test needs to create and | 46 // NetworkChangeNotifier. Use this if your test needs to create and |
41 // manage its own mock NetworkChangeNotifier, or if your test uses | 47 // manage its own mock NetworkChangeNotifier, or if your test uses |
42 // the production NetworkChangeNotifier. | 48 // the production NetworkChangeNotifier. |
43 void InitializeTestThreadNoNetworkChangeNotifier(); | 49 void InitializeTestThreadNoNetworkChangeNotifier(); |
44 | 50 |
45 private: | 51 private: |
46 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 52 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
47 std::unique_ptr<base::MessageLoop> message_loop_; | 53 std::unique_ptr<base::test::ScopedTaskEnvironment> scoped_task_environment_; |
48 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; | 54 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; |
49 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; | 55 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; |
50 }; | 56 }; |
51 | 57 |
52 #endif // NET_TEST_NET_TEST_SUITE_H_ | 58 #endif // NET_TEST_NET_TEST_SUITE_H_ |
OLD | NEW |