Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: net/base/net_test_suite.h

Issue 2802015: Massively simplify the NetworkChangeNotifier infrastructure:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 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 7
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/ref_counted.h" 9 #include "base/ref_counted.h"
10 #include "base/test/test_suite.h" 10 #include "base/test/test_suite.h"
11 #include "net/base/mock_host_resolver.h" 11 #include "net/base/mock_host_resolver.h"
12 12
13 class NetTestSuite : public TestSuite { 13 class NetTestSuite : public TestSuite {
14 public: 14 public:
15 NetTestSuite(int argc, char** argv) : TestSuite(argc, argv) { 15 NetTestSuite(int argc, char** argv) : TestSuite(argc, argv) {
16 } 16 }
17 17
18 virtual void Initialize() { 18 virtual void Initialize() {
19 TestSuite::Initialize(); 19 TestSuite::Initialize();
20 InitializeTestThread(); 20 InitializeTestThread();
21 } 21 }
22 22
23 // Called from within Initialize(), but separate so that derived classes 23 // Called from within Initialize(), but separate so that derived classes
24 // can initialize the NetTestSuite instance only and not 24 // can initialize the NetTestSuite instance only and not
25 // TestSuite::Initialize(). TestSuite::Initialize() performs some global 25 // TestSuite::Initialize(). TestSuite::Initialize() performs some global
26 // initialization that can only be done once. 26 // initialization that can only be done once.
27 void InitializeTestThread() { 27 void InitializeTestThread() {
28 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
29
28 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); 30 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL);
29 scoped_host_resolver_proc_.Init(host_resolver_proc_.get()); 31 scoped_host_resolver_proc_.Init(host_resolver_proc_.get());
30 // In case any attempts are made to resolve host names, force them all to 32 // In case any attempts are made to resolve host names, force them all to
31 // be mapped to localhost. This prevents DNS queries from being sent in 33 // be mapped to localhost. This prevents DNS queries from being sent in
32 // the process of running these unit tests. 34 // the process of running these unit tests.
33 host_resolver_proc_->AddRule("*", "127.0.0.1"); 35 host_resolver_proc_->AddRule("*", "127.0.0.1");
34 36
35 message_loop_.reset(new MessageLoopForIO()); 37 message_loop_.reset(new MessageLoopForIO());
36 } 38 }
37 39
38 virtual void Shutdown() { 40 virtual void Shutdown() {
39 // We want to destroy this here before the TestSuite continues to tear down 41 // We want to destroy this here before the TestSuite continues to tear down
40 // the environment. 42 // the environment.
41 message_loop_.reset(); 43 message_loop_.reset();
42 44
43 TestSuite::Shutdown(); 45 TestSuite::Shutdown();
44 } 46 }
45 47
46 private: 48 private:
49 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
47 scoped_ptr<MessageLoop> message_loop_; 50 scoped_ptr<MessageLoop> message_loop_;
48 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; 51 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_;
49 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; 52 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_;
50 }; 53 };
51 54
52 #endif // NET_BASE_NET_TEST_SUITE_H_ 55 #endif // NET_BASE_NET_TEST_SUITE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698