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 #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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "net/base/capturing_net_log.h" | |
10 #include "net/url_request/url_request_context_getter.h" | 9 #include "net/url_request/url_request_context_getter.h" |
11 #include "net/url_request/url_request_test_util.h" | 10 #include "net/url_request/url_request_test_util.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 | 13 |
15 namespace { | 14 namespace { |
16 // TODO(sanjeevr): Move this to net_test_support. | 15 // TODO(sanjeevr): Move this to net_test_support. |
17 // Used to return a dummy context. | 16 // Used to return a dummy context. |
18 class TestURLRequestContextGetter : public net::URLRequestContextGetter { | 17 class TestURLRequestContextGetter : public net::URLRequestContextGetter { |
19 public: | 18 public: |
(...skipping 17 matching lines...) Expand all Loading... |
37 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 36 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
38 }; | 37 }; |
39 } // namespace | 38 } // namespace |
40 | 39 |
41 namespace notifier { | 40 namespace notifier { |
42 | 41 |
43 class ProxyResolvingClientSocketTest : public testing::Test { | 42 class ProxyResolvingClientSocketTest : public testing::Test { |
44 protected: | 43 protected: |
45 ProxyResolvingClientSocketTest() | 44 ProxyResolvingClientSocketTest() |
46 : url_request_context_getter_(new TestURLRequestContextGetter()), | 45 : url_request_context_getter_(new TestURLRequestContextGetter()), |
47 capturing_net_log_(net::CapturingNetLog::kUnbounded), | |
48 connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 46 connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
49 &ProxyResolvingClientSocketTest::NetCallback) { } | 47 &ProxyResolvingClientSocketTest::NetCallback) { } |
50 | 48 |
51 virtual ~ProxyResolvingClientSocketTest() {} | 49 virtual ~ProxyResolvingClientSocketTest() {} |
52 | 50 |
53 virtual void TearDown() { | 51 virtual void TearDown() { |
54 // Clear out any messages posted by ProxyResolvingClientSocket's | 52 // Clear out any messages posted by ProxyResolvingClientSocket's |
55 // destructor. | 53 // destructor. |
56 message_loop_.RunAllPending(); | 54 message_loop_.RunAllPending(); |
57 } | 55 } |
58 | 56 |
59 MOCK_METHOD1(NetCallback, void(int status)); | 57 MOCK_METHOD1(NetCallback, void(int status)); |
60 | 58 |
61 // Needed by XmppConnection. | 59 // Needed by XmppConnection. |
62 MessageLoopForIO message_loop_; | 60 MessageLoopForIO message_loop_; |
63 scoped_refptr<TestURLRequestContextGetter> url_request_context_getter_; | 61 scoped_refptr<TestURLRequestContextGetter> url_request_context_getter_; |
64 net::CapturingNetLog capturing_net_log_; | |
65 net::CompletionCallbackImpl<ProxyResolvingClientSocketTest> connect_callback_; | 62 net::CompletionCallbackImpl<ProxyResolvingClientSocketTest> connect_callback_; |
66 }; | 63 }; |
67 | 64 |
68 // TODO(sanjeevr): Fix this test on Linux. | 65 // TODO(sanjeevr): Fix this test on Linux. |
69 TEST_F(ProxyResolvingClientSocketTest, DISABLED_ConnectError) { | 66 TEST_F(ProxyResolvingClientSocketTest, DISABLED_ConnectError) { |
70 net::HostPortPair dest("0.0.0.0", 0); | 67 net::HostPortPair dest("0.0.0.0", 0); |
71 ProxyResolvingClientSocket proxy_resolving_socket( | 68 ProxyResolvingClientSocket proxy_resolving_socket( |
72 url_request_context_getter_, | 69 url_request_context_getter_, |
73 net::SSLConfig(), | 70 net::SSLConfig(), |
74 dest, | 71 dest); |
75 &capturing_net_log_); | |
76 // ProxyResolvingClientSocket::Connect() will always return an error of | 72 // ProxyResolvingClientSocket::Connect() will always return an error of |
77 // ERR_ADDRESS_INVALID for a 0 IP address. | 73 // ERR_ADDRESS_INVALID for a 0 IP address. |
78 EXPECT_CALL(*this, NetCallback(net::ERR_ADDRESS_INVALID)).Times(1); | 74 EXPECT_CALL(*this, NetCallback(net::ERR_ADDRESS_INVALID)).Times(1); |
79 int status = proxy_resolving_socket.Connect(&connect_callback_); | 75 int status = proxy_resolving_socket.Connect(&connect_callback_); |
80 // Connect always returns ERR_IO_PENDING because it is always asynchronous. | 76 // Connect always returns ERR_IO_PENDING because it is always asynchronous. |
81 EXPECT_EQ(status, net::ERR_IO_PENDING); | 77 EXPECT_EQ(status, net::ERR_IO_PENDING); |
82 message_loop_.RunAllPending(); | 78 message_loop_.RunAllPending(); |
83 } | 79 } |
84 | 80 |
85 // TODO(sanjeevr): Add more unit-tests. | 81 // TODO(sanjeevr): Add more unit-tests. |
86 } // namespace notifier | 82 } // namespace notifier |
OLD | NEW |