OLD | NEW |
---|---|
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/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "net/base/mock_host_resolver.h" | 10 #include "net/base/mock_host_resolver.h" |
10 #include "net/base/test_completion_callback.h" | 11 #include "net/base/test_completion_callback.h" |
11 #include "net/socket/socket_test_util.h" | 12 #include "net/socket/socket_test_util.h" |
12 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
13 #include "net/url_request/url_request_test_util.h" | 14 #include "net/url_request/url_request_test_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 // TODO(sanjeevr): Move this to net_test_support. | 18 |
18 // Used to return a dummy context. | 19 class ProxyTestURLRequestContextGetter : public TestURLRequestContextGetter { |
19 class TestURLRequestContextGetter : public net::URLRequestContextGetter { | |
20 public: | 20 public: |
21 TestURLRequestContextGetter() | 21 ProxyTestURLRequestContextGetter() |
22 : message_loop_proxy_(base::MessageLoopProxy::current()) { | 22 : TestURLRequestContextGetter(base::MessageLoopProxy::current()), |
23 } | 23 set_context_members_(false) {} |
24 virtual ~TestURLRequestContextGetter() { } | |
25 | 24 |
26 // net::URLRequestContextGetter: | 25 // TestURLRequestContextGetter overrides. |
27 virtual net::URLRequestContext* GetURLRequestContext() { | 26 virtual TestURLRequestContext* GetURLRequestContext() OVERRIDE { |
Nicolas Zea
2012/03/02 19:12:27
Comment about what this accomplishes.
akalin
2012/03/02 22:55:50
Done.
| |
28 if (!context_) | 27 TestURLRequestContext* context = |
29 CreateURLRequestContext(); | 28 TestURLRequestContextGetter::GetURLRequestContext(); |
30 return context_.get(); | 29 if (!set_context_members_) { |
31 } | 30 context->set_host_resolver(new net::MockHostResolver()); |
32 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | 31 context->set_proxy_service(net::ProxyService::CreateFixedFromPacResult( |
33 return message_loop_proxy_; | 32 "PROXY bad:99; PROXY maybe:80; DIRECT")); |
33 set_context_members_ = true; | |
34 } | |
35 return context; | |
34 } | 36 } |
35 | 37 |
38 protected: | |
39 virtual ~ProxyTestURLRequestContextGetter() {} | |
40 | |
36 private: | 41 private: |
37 void CreateURLRequestContext() { | 42 bool set_context_members_; |
38 context_ = new TestURLRequestContext(); | 43 }; |
39 context_->set_host_resolver(new net::MockHostResolver()); | |
40 context_->set_proxy_service(net::ProxyService::CreateFixedFromPacResult( | |
41 "PROXY bad:99; PROXY maybe:80; DIRECT")); | |
42 } | |
43 | 44 |
44 scoped_refptr<net::URLRequestContext> context_; | |
45 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
46 }; | |
47 } // namespace | 45 } // namespace |
48 | 46 |
49 namespace notifier { | 47 namespace notifier { |
50 | 48 |
51 class ProxyResolvingClientSocketTest : public testing::Test { | 49 class ProxyResolvingClientSocketTest : public testing::Test { |
52 protected: | 50 protected: |
53 ProxyResolvingClientSocketTest() | 51 ProxyResolvingClientSocketTest() |
54 : url_request_context_getter_(new TestURLRequestContextGetter()) {} | 52 : url_request_context_getter_(new ProxyTestURLRequestContextGetter()) {} |
55 | 53 |
56 virtual ~ProxyResolvingClientSocketTest() {} | 54 virtual ~ProxyResolvingClientSocketTest() {} |
57 | 55 |
58 virtual void TearDown() { | 56 virtual void TearDown() { |
59 // Clear out any messages posted by ProxyResolvingClientSocket's | 57 // Clear out any messages posted by ProxyResolvingClientSocket's |
60 // destructor. | 58 // destructor. |
61 message_loop_.RunAllPending(); | 59 message_loop_.RunAllPending(); |
62 } | 60 } |
63 | 61 |
64 // Needed by XmppConnection. | 62 MessageLoop message_loop_; |
65 MessageLoopForIO message_loop_; | 63 scoped_refptr<ProxyTestURLRequestContextGetter> url_request_context_getter_; |
66 scoped_refptr<TestURLRequestContextGetter> url_request_context_getter_; | |
67 }; | 64 }; |
68 | 65 |
69 // TODO(sanjeevr): Fix this test on Linux. | 66 // TODO(sanjeevr): Fix this test on Linux. |
70 TEST_F(ProxyResolvingClientSocketTest, DISABLED_ConnectError) { | 67 TEST_F(ProxyResolvingClientSocketTest, DISABLED_ConnectError) { |
71 net::HostPortPair dest("0.0.0.0", 0); | 68 net::HostPortPair dest("0.0.0.0", 0); |
72 ProxyResolvingClientSocket proxy_resolving_socket( | 69 ProxyResolvingClientSocket proxy_resolving_socket( |
73 NULL, | 70 NULL, |
74 url_request_context_getter_, | 71 url_request_context_getter_, |
75 net::SSLConfig(), | 72 net::SSLConfig(), |
76 dest); | 73 dest); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 const net::ProxyRetryInfoMap& retry_info = | 120 const net::ProxyRetryInfoMap& retry_info = |
124 context->proxy_service()->proxy_retry_info(); | 121 context->proxy_service()->proxy_retry_info(); |
125 | 122 |
126 EXPECT_EQ(1u, retry_info.size()); | 123 EXPECT_EQ(1u, retry_info.size()); |
127 net::ProxyRetryInfoMap::const_iterator iter = retry_info.find("bad:99"); | 124 net::ProxyRetryInfoMap::const_iterator iter = retry_info.find("bad:99"); |
128 EXPECT_TRUE(iter != retry_info.end()); | 125 EXPECT_TRUE(iter != retry_info.end()); |
129 } | 126 } |
130 | 127 |
131 // TODO(sanjeevr): Add more unit-tests. | 128 // TODO(sanjeevr): Add more unit-tests. |
132 } // namespace notifier | 129 } // namespace notifier |
OLD | NEW |