| 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/glue/chrome_async_socket.h" | 5 #include "jingle/glue/chrome_async_socket.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/message_loop/message_pump_default.h" | 14 #include "base/message_loop/message_pump_default.h" |
| 15 #include "jingle/glue/resolving_client_socket_factory.h" | 15 #include "jingle/glue/resolving_client_socket_factory.h" |
| 16 #include "net/base/address_list.h" | 16 #include "net/base/address_list.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 #include "net/cert/mock_cert_verifier.h" | 19 #include "net/cert/mock_cert_verifier.h" |
| 20 #include "net/http/transport_security_state.h" | 20 #include "net/http/transport_security_state.h" |
| 21 #include "net/socket/socket_test_util.h" | 21 #include "net/socket/socket_test_util.h" |
| 22 #include "net/socket/ssl_client_socket.h" | 22 #include "net/socket/ssl_client_socket.h" |
| 23 #include "net/ssl/ssl_config_service.h" | 23 #include "net/ssl/ssl_config_service.h" |
| 24 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/libjingle/source/talk/base/ipaddress.h" | 26 #include "third_party/webrtc/base/ipaddress.h" |
| 27 #include "third_party/libjingle/source/talk/base/sigslot.h" | 27 #include "third_party/webrtc/base/sigslot.h" |
| 28 #include "third_party/libjingle/source/talk/base/socketaddress.h" | 28 #include "third_party/webrtc/base/socketaddress.h" |
| 29 | 29 |
| 30 namespace jingle_glue { | 30 namespace jingle_glue { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Data provider that handles reads/writes for ChromeAsyncSocket. | 34 // Data provider that handles reads/writes for ChromeAsyncSocket. |
| 35 class AsyncSocketDataProvider : public net::SocketDataProvider { | 35 class AsyncSocketDataProvider : public net::SocketDataProvider { |
| 36 public: | 36 public: |
| 37 AsyncSocketDataProvider() : has_pending_read_(false) {} | 37 AsyncSocketDataProvider() : has_pending_read_(false) {} |
| 38 | 38 |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 424 } |
| 425 | 425 |
| 426 // ChromeAsyncSocket expects a message loop. | 426 // ChromeAsyncSocket expects a message loop. |
| 427 scoped_ptr<base::MessageLoop> message_loop_; | 427 scoped_ptr<base::MessageLoop> message_loop_; |
| 428 | 428 |
| 429 AsyncSocketDataProvider async_socket_data_provider_; | 429 AsyncSocketDataProvider async_socket_data_provider_; |
| 430 net::SSLSocketDataProvider ssl_socket_data_provider_; | 430 net::SSLSocketDataProvider ssl_socket_data_provider_; |
| 431 | 431 |
| 432 scoped_ptr<ChromeAsyncSocket> chrome_async_socket_; | 432 scoped_ptr<ChromeAsyncSocket> chrome_async_socket_; |
| 433 std::deque<SignalSocketState> signal_socket_states_; | 433 std::deque<SignalSocketState> signal_socket_states_; |
| 434 const talk_base::SocketAddress addr_; | 434 const rtc::SocketAddress addr_; |
| 435 | 435 |
| 436 private: | 436 private: |
| 437 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocketTest); | 437 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocketTest); |
| 438 }; | 438 }; |
| 439 | 439 |
| 440 TEST_F(ChromeAsyncSocketTest, InitialState) { | 440 TEST_F(ChromeAsyncSocketTest, InitialState) { |
| 441 ExpectClosed(); | 441 ExpectClosed(); |
| 442 ExpectNoSignal(); | 442 ExpectNoSignal(); |
| 443 } | 443 } |
| 444 | 444 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 466 ExpectClosed(); | 466 ExpectClosed(); |
| 467 ExpectSignalSocketState( | 467 ExpectSignalSocketState( |
| 468 SignalSocketState::NoError( | 468 SignalSocketState::NoError( |
| 469 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 469 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
| 470 | 470 |
| 471 EXPECT_TRUE(chrome_async_socket_->Close()); | 471 EXPECT_TRUE(chrome_async_socket_->Close()); |
| 472 ExpectClosed(); | 472 ExpectClosed(); |
| 473 } | 473 } |
| 474 | 474 |
| 475 TEST_F(ChromeAsyncSocketTest, NoHostnameConnect) { | 475 TEST_F(ChromeAsyncSocketTest, NoHostnameConnect) { |
| 476 talk_base::IPAddress ip_address; | 476 rtc::IPAddress ip_address; |
| 477 EXPECT_TRUE(talk_base::IPFromString("127.0.0.1", &ip_address)); | 477 EXPECT_TRUE(rtc::IPFromString("127.0.0.1", &ip_address)); |
| 478 const talk_base::SocketAddress no_hostname_addr(ip_address, addr_.port()); | 478 const rtc::SocketAddress no_hostname_addr(ip_address, addr_.port()); |
| 479 EXPECT_FALSE(chrome_async_socket_->Connect(no_hostname_addr)); | 479 EXPECT_FALSE(chrome_async_socket_->Connect(no_hostname_addr)); |
| 480 ExpectErrorState(ChromeAsyncSocket::STATE_CLOSED, | 480 ExpectErrorState(ChromeAsyncSocket::STATE_CLOSED, |
| 481 ChromeAsyncSocket::ERROR_DNS); | 481 ChromeAsyncSocket::ERROR_DNS); |
| 482 | 482 |
| 483 EXPECT_TRUE(chrome_async_socket_->Close()); | 483 EXPECT_TRUE(chrome_async_socket_->Close()); |
| 484 ExpectClosed(); | 484 ExpectClosed(); |
| 485 } | 485 } |
| 486 | 486 |
| 487 TEST_F(ChromeAsyncSocketTest, ZeroPortConnect) { | 487 TEST_F(ChromeAsyncSocketTest, ZeroPortConnect) { |
| 488 const talk_base::SocketAddress zero_port_addr(addr_.hostname(), 0); | 488 const rtc::SocketAddress zero_port_addr(addr_.hostname(), 0); |
| 489 EXPECT_FALSE(chrome_async_socket_->Connect(zero_port_addr)); | 489 EXPECT_FALSE(chrome_async_socket_->Connect(zero_port_addr)); |
| 490 ExpectErrorState(ChromeAsyncSocket::STATE_CLOSED, | 490 ExpectErrorState(ChromeAsyncSocket::STATE_CLOSED, |
| 491 ChromeAsyncSocket::ERROR_DNS); | 491 ChromeAsyncSocket::ERROR_DNS); |
| 492 | 492 |
| 493 EXPECT_TRUE(chrome_async_socket_->Close()); | 493 EXPECT_TRUE(chrome_async_socket_->Close()); |
| 494 ExpectClosed(); | 494 ExpectClosed(); |
| 495 } | 495 } |
| 496 | 496 |
| 497 TEST_F(ChromeAsyncSocketTest, DoubleConnect) { | 497 TEST_F(ChromeAsyncSocketTest, DoubleConnect) { |
| 498 EXPECT_DEBUG_DEATH({ | 498 EXPECT_DEBUG_DEATH({ |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 message_loop_->RunUntilIdle(); | 1083 message_loop_->RunUntilIdle(); |
| 1084 | 1084 |
| 1085 ExpectNoSignal(); | 1085 ExpectNoSignal(); |
| 1086 | 1086 |
| 1087 DoSSLCloseOpenedNoError(); | 1087 DoSSLCloseOpenedNoError(); |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 } // namespace | 1090 } // namespace |
| 1091 | 1091 |
| 1092 } // namespace jingle_glue | 1092 } // namespace jingle_glue |
| OLD | NEW |