| 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/chrome_async_socket.h" | 5 #include "jingle/notifier/base/chrome_async_socket.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <winsock2.h> | 8 #include <winsock2.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <arpa/inet.h> | 10 #include <arpa/inet.h> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <deque> | 13 #include <deque> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "jingle/notifier/base/resolving_client_socket_factory.h" | 20 #include "jingle/notifier/base/resolving_client_socket_factory.h" |
| 21 #include "net/base/capturing_net_log.h" | |
| 22 #include "net/base/cert_verifier.h" | 21 #include "net/base/cert_verifier.h" |
| 23 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 24 #include "net/base/net_log.h" | |
| 25 #include "net/base/ssl_config_service.h" | 23 #include "net/base/ssl_config_service.h" |
| 26 #include "net/socket/socket_test_util.h" | 24 #include "net/socket/socket_test_util.h" |
| 27 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
| 28 #include "talk/base/sigslot.h" | 26 #include "talk/base/sigslot.h" |
| 29 #include "talk/base/socketaddress.h" | 27 #include "talk/base/socketaddress.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 29 |
| 32 namespace notifier { | 30 namespace notifier { |
| 33 | 31 |
| 34 namespace { | 32 namespace { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 public: | 122 public: |
| 125 MockXmppClientSocketFactory( | 123 MockXmppClientSocketFactory( |
| 126 net::ClientSocketFactory* mock_client_socket_factory, | 124 net::ClientSocketFactory* mock_client_socket_factory, |
| 127 const net::AddressList& address_list) | 125 const net::AddressList& address_list) |
| 128 : mock_client_socket_factory_(mock_client_socket_factory), | 126 : mock_client_socket_factory_(mock_client_socket_factory), |
| 129 address_list_(address_list) { | 127 address_list_(address_list) { |
| 130 } | 128 } |
| 131 | 129 |
| 132 // ResolvingClientSocketFactory implementation. | 130 // ResolvingClientSocketFactory implementation. |
| 133 virtual net::StreamSocket* CreateTransportClientSocket( | 131 virtual net::StreamSocket* CreateTransportClientSocket( |
| 134 const net::HostPortPair& host_and_port, net::NetLog* net_log) { | 132 const net::HostPortPair& host_and_port) { |
| 135 return mock_client_socket_factory_->CreateTransportClientSocket( | 133 return mock_client_socket_factory_->CreateTransportClientSocket( |
| 136 address_list_, net_log, net::NetLog::Source()); | 134 address_list_, NULL, net::NetLog::Source()); |
| 137 } | 135 } |
| 138 | 136 |
| 139 virtual net::SSLClientSocket* CreateSSLClientSocket( | 137 virtual net::SSLClientSocket* CreateSSLClientSocket( |
| 140 net::ClientSocketHandle* transport_socket, | 138 net::ClientSocketHandle* transport_socket, |
| 141 const net::HostPortPair& host_and_port) { | 139 const net::HostPortPair& host_and_port) { |
| 142 return mock_client_socket_factory_->CreateSSLClientSocket( | 140 return mock_client_socket_factory_->CreateSSLClientSocket( |
| 143 transport_socket, host_and_port, ssl_config_, NULL, &cert_verifier_, | 141 transport_socket, host_and_port, ssl_config_, NULL, &cert_verifier_, |
| 144 NULL); | 142 NULL); |
| 145 } | 143 } |
| 146 | 144 |
| 147 private: | 145 private: |
| 148 scoped_ptr<net::ClientSocketFactory> mock_client_socket_factory_; | 146 scoped_ptr<net::ClientSocketFactory> mock_client_socket_factory_; |
| 149 net::AddressList address_list_; | 147 net::AddressList address_list_; |
| 150 net::SSLConfig ssl_config_; | 148 net::SSLConfig ssl_config_; |
| 151 net::CertVerifier cert_verifier_; | 149 net::CertVerifier cert_verifier_; |
| 152 }; | 150 }; |
| 153 | 151 |
| 154 class ChromeAsyncSocketTest | 152 class ChromeAsyncSocketTest |
| 155 : public testing::Test, | 153 : public testing::Test, |
| 156 public sigslot::has_slots<> { | 154 public sigslot::has_slots<> { |
| 157 protected: | 155 protected: |
| 158 ChromeAsyncSocketTest() | 156 ChromeAsyncSocketTest() |
| 159 : ssl_socket_data_provider_(true, net::OK), | 157 : ssl_socket_data_provider_(true, net::OK), |
| 160 capturing_net_log_(net::CapturingNetLog::kUnbounded), | |
| 161 addr_(0xaabbccdd, 35) {} | 158 addr_(0xaabbccdd, 35) {} |
| 162 | 159 |
| 163 virtual ~ChromeAsyncSocketTest() {} | 160 virtual ~ChromeAsyncSocketTest() {} |
| 164 | 161 |
| 165 virtual void SetUp() { | 162 virtual void SetUp() { |
| 166 scoped_ptr<net::MockClientSocketFactory> mock_client_socket_factory( | 163 scoped_ptr<net::MockClientSocketFactory> mock_client_socket_factory( |
| 167 new net::MockClientSocketFactory()); | 164 new net::MockClientSocketFactory()); |
| 168 mock_client_socket_factory->AddSocketDataProvider( | 165 mock_client_socket_factory->AddSocketDataProvider( |
| 169 &async_socket_data_provider_); | 166 &async_socket_data_provider_); |
| 170 mock_client_socket_factory->AddSSLSocketDataProvider( | 167 mock_client_socket_factory->AddSSLSocketDataProvider( |
| 171 &ssl_socket_data_provider_); | 168 &ssl_socket_data_provider_); |
| 172 | 169 |
| 173 scoped_ptr<MockXmppClientSocketFactory> mock_xmpp_client_socket_factory( | 170 scoped_ptr<MockXmppClientSocketFactory> mock_xmpp_client_socket_factory( |
| 174 new MockXmppClientSocketFactory( | 171 new MockXmppClientSocketFactory( |
| 175 mock_client_socket_factory.release(), | 172 mock_client_socket_factory.release(), |
| 176 SocketAddressToAddressList(addr_))); | 173 SocketAddressToAddressList(addr_))); |
| 177 chrome_async_socket_.reset( | 174 chrome_async_socket_.reset( |
| 178 new ChromeAsyncSocket(mock_xmpp_client_socket_factory.release(), | 175 new ChromeAsyncSocket(mock_xmpp_client_socket_factory.release(), |
| 179 14, 20, | 176 14, 20)), |
| 180 &capturing_net_log_)), | |
| 181 | 177 |
| 182 chrome_async_socket_->SignalConnected.connect( | 178 chrome_async_socket_->SignalConnected.connect( |
| 183 this, &ChromeAsyncSocketTest::OnConnect); | 179 this, &ChromeAsyncSocketTest::OnConnect); |
| 184 chrome_async_socket_->SignalSSLConnected.connect( | 180 chrome_async_socket_->SignalSSLConnected.connect( |
| 185 this, &ChromeAsyncSocketTest::OnSSLConnect); | 181 this, &ChromeAsyncSocketTest::OnSSLConnect); |
| 186 chrome_async_socket_->SignalClosed.connect( | 182 chrome_async_socket_->SignalClosed.connect( |
| 187 this, &ChromeAsyncSocketTest::OnClose); | 183 this, &ChromeAsyncSocketTest::OnClose); |
| 188 chrome_async_socket_->SignalRead.connect( | 184 chrome_async_socket_->SignalRead.connect( |
| 189 this, &ChromeAsyncSocketTest::OnRead); | 185 this, &ChromeAsyncSocketTest::OnRead); |
| 190 chrome_async_socket_->SignalError.connect( | 186 chrome_async_socket_->SignalError.connect( |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 420 } |
| 425 return read; | 421 return read; |
| 426 } | 422 } |
| 427 | 423 |
| 428 // ChromeAsyncSocket expects a message loop. | 424 // ChromeAsyncSocket expects a message loop. |
| 429 MessageLoop message_loop_; | 425 MessageLoop message_loop_; |
| 430 | 426 |
| 431 AsyncSocketDataProvider async_socket_data_provider_; | 427 AsyncSocketDataProvider async_socket_data_provider_; |
| 432 net::SSLSocketDataProvider ssl_socket_data_provider_; | 428 net::SSLSocketDataProvider ssl_socket_data_provider_; |
| 433 | 429 |
| 434 net::CapturingNetLog capturing_net_log_; | |
| 435 scoped_ptr<ChromeAsyncSocket> chrome_async_socket_; | 430 scoped_ptr<ChromeAsyncSocket> chrome_async_socket_; |
| 436 std::deque<SignalSocketState> signal_socket_states_; | 431 std::deque<SignalSocketState> signal_socket_states_; |
| 437 const talk_base::SocketAddress addr_; | 432 const talk_base::SocketAddress addr_; |
| 438 | 433 |
| 439 private: | 434 private: |
| 440 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocketTest); | 435 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocketTest); |
| 441 }; | 436 }; |
| 442 | 437 |
| 443 TEST_F(ChromeAsyncSocketTest, InitialState) { | 438 TEST_F(ChromeAsyncSocketTest, InitialState) { |
| 444 ExpectClosed(); | 439 ExpectClosed(); |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 message_loop_.RunAllPending(); | 1067 message_loop_.RunAllPending(); |
| 1073 | 1068 |
| 1074 ExpectNoSignal(); | 1069 ExpectNoSignal(); |
| 1075 | 1070 |
| 1076 DoSSLCloseOpenedNoError(); | 1071 DoSSLCloseOpenedNoError(); |
| 1077 } | 1072 } |
| 1078 | 1073 |
| 1079 } // namespace | 1074 } // namespace |
| 1080 | 1075 |
| 1081 } // namespace notifier | 1076 } // namespace notifier |
| OLD | NEW |