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

Side by Side Diff: jingle/notifier/base/proxy_resolving_client_socket_unittest.cc

Issue 10408067: [net] Switch TestURLRequestContext to use MockCachingHostResolver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to trunk. Created 8 years, 7 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) 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 "jingle/notifier/base/proxy_resolving_client_socket.h" 5 #include "jingle/notifier/base/proxy_resolving_client_socket.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "net/base/mock_host_resolver.h" 10 #include "net/base/mock_host_resolver.h"
11 #include "net/base/test_completion_callback.h" 11 #include "net/base/test_completion_callback.h"
12 #include "net/proxy/proxy_service.h"
12 #include "net/socket/socket_test_util.h" 13 #include "net/socket/socket_test_util.h"
13 #include "net/url_request/url_request_context_getter.h" 14 #include "net/url_request/url_request_context_getter.h"
14 #include "net/url_request/url_request_test_util.h" 15 #include "net/url_request/url_request_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace { 18 namespace {
18 19
19 class ProxyTestURLRequestContextGetter : public TestURLRequestContextGetter { 20 class MyTestURLRequestContext : public TestURLRequestContext {
20 public: 21 public:
21 ProxyTestURLRequestContextGetter() 22 MyTestURLRequestContext() : TestURLRequestContext(true) {
22 : TestURLRequestContextGetter(base::MessageLoopProxy::current()), 23 context_storage_.set_proxy_service(
23 set_context_members_(false) {} 24 net::ProxyService::CreateFixedFromPacResult(
24 25 "PROXY bad:99; PROXY maybe:80; DIRECT"));
25 // Override GetURLRequestContext to set the host resolver and proxy 26 Init();
26 // service (used by the unit tests).
27 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE {
28 TestURLRequestContext* context =
29 TestURLRequestContextGetter::GetURLRequestContext();
30 if (!set_context_members_) {
31 context->set_host_resolver(new net::MockHostResolver());
32 context->set_proxy_service(net::ProxyService::CreateFixedFromPacResult(
33 "PROXY bad:99; PROXY maybe:80; DIRECT"));
34 set_context_members_ = true;
35 }
36 return context;
37 } 27 }
38 28 virtual ~MyTestURLRequestContext() {}
39 protected:
40 virtual ~ProxyTestURLRequestContextGetter() {}
41
42 private:
43 bool set_context_members_;
44 }; 29 };
45 30
46 } // namespace 31 } // namespace
47 32
48 namespace notifier { 33 namespace notifier {
49 34
50 class ProxyResolvingClientSocketTest : public testing::Test { 35 class ProxyResolvingClientSocketTest : public testing::Test {
51 protected: 36 protected:
52 ProxyResolvingClientSocketTest() 37 ProxyResolvingClientSocketTest()
53 : url_request_context_getter_(new ProxyTestURLRequestContextGetter()) {} 38 : url_request_context_getter_(new TestURLRequestContextGetter(
39 base::MessageLoopProxy::current(),
40 scoped_ptr<TestURLRequestContext>(new MyTestURLRequestContext))) {}
54 41
55 virtual ~ProxyResolvingClientSocketTest() {} 42 virtual ~ProxyResolvingClientSocketTest() {}
56 43
57 virtual void TearDown() { 44 virtual void TearDown() {
58 // Clear out any messages posted by ProxyResolvingClientSocket's 45 // Clear out any messages posted by ProxyResolvingClientSocket's
59 // destructor. 46 // destructor.
60 message_loop_.RunAllPending(); 47 message_loop_.RunAllPending();
61 } 48 }
62 49
63 MessageLoop message_loop_; 50 MessageLoop message_loop_;
64 scoped_refptr<ProxyTestURLRequestContextGetter> url_request_context_getter_; 51 scoped_refptr<TestURLRequestContextGetter> url_request_context_getter_;
65 }; 52 };
66 53
67 // TODO(sanjeevr): Fix this test on Linux. 54 // TODO(sanjeevr): Fix this test on Linux.
68 TEST_F(ProxyResolvingClientSocketTest, DISABLED_ConnectError) { 55 TEST_F(ProxyResolvingClientSocketTest, DISABLED_ConnectError) {
69 net::HostPortPair dest("0.0.0.0", 0); 56 net::HostPortPair dest("0.0.0.0", 0);
70 ProxyResolvingClientSocket proxy_resolving_socket( 57 ProxyResolvingClientSocket proxy_resolving_socket(
71 NULL, 58 NULL,
72 url_request_context_getter_, 59 url_request_context_getter_,
73 net::SSLConfig(), 60 net::SSLConfig(),
74 dest); 61 dest);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const net::ProxyRetryInfoMap& retry_info = 108 const net::ProxyRetryInfoMap& retry_info =
122 context->proxy_service()->proxy_retry_info(); 109 context->proxy_service()->proxy_retry_info();
123 110
124 EXPECT_EQ(1u, retry_info.size()); 111 EXPECT_EQ(1u, retry_info.size());
125 net::ProxyRetryInfoMap::const_iterator iter = retry_info.find("bad:99"); 112 net::ProxyRetryInfoMap::const_iterator iter = retry_info.find("bad:99");
126 EXPECT_TRUE(iter != retry_info.end()); 113 EXPECT_TRUE(iter != retry_info.end());
127 } 114 }
128 115
129 // TODO(sanjeevr): Add more unit-tests. 116 // TODO(sanjeevr): Add more unit-tests.
130 } // namespace notifier 117 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698