| 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 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 ExpectSignalSocketState( | 335 ExpectSignalSocketState( |
| 336 SignalSocketState::NoError( | 336 SignalSocketState::NoError( |
| 337 SIGNAL_READ, ChromeAsyncSocket::STATE_TLS_OPEN)); | 337 SIGNAL_READ, ChromeAsyncSocket::STATE_TLS_OPEN)); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // Open/close utility functions. | 340 // Open/close utility functions. |
| 341 | 341 |
| 342 void DoOpenClosed() { | 342 void DoOpenClosed() { |
| 343 ExpectClosed(); | 343 ExpectClosed(); |
| 344 async_socket_data_provider_.set_connect_data( | 344 async_socket_data_provider_.set_connect_data( |
| 345 net::MockConnect(false, net::OK)); | 345 net::MockConnect(net::SYNCHRONOUS, net::OK)); |
| 346 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 346 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 347 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 347 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
| 348 | 348 |
| 349 message_loop_.RunAllPending(); | 349 message_loop_.RunAllPending(); |
| 350 // We may not necessarily be open; may have been other events | 350 // We may not necessarily be open; may have been other events |
| 351 // queued up. | 351 // queued up. |
| 352 ExpectSignalSocketState( | 352 ExpectSignalSocketState( |
| 353 SignalSocketState::NoError( | 353 SignalSocketState::NoError( |
| 354 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 354 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
| 355 } | 355 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 512 |
| 513 EXPECT_TRUE(chrome_async_socket_->Close()); | 513 EXPECT_TRUE(chrome_async_socket_->Close()); |
| 514 ExpectClosed(); | 514 ExpectClosed(); |
| 515 ExpectSignalSocketState( | 515 ExpectSignalSocketState( |
| 516 SignalSocketState::NoError( | 516 SignalSocketState::NoError( |
| 517 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 517 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
| 518 } | 518 } |
| 519 | 519 |
| 520 TEST_F(ChromeAsyncSocketTest, PendingConnect) { | 520 TEST_F(ChromeAsyncSocketTest, PendingConnect) { |
| 521 async_socket_data_provider_.set_connect_data( | 521 async_socket_data_provider_.set_connect_data( |
| 522 net::MockConnect(true, net::OK)); | 522 net::MockConnect(net::ASYNC, net::OK)); |
| 523 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 523 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 524 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 524 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
| 525 ExpectNoSignal(); | 525 ExpectNoSignal(); |
| 526 | 526 |
| 527 message_loop_.RunAllPending(); | 527 message_loop_.RunAllPending(); |
| 528 ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); | 528 ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); |
| 529 ExpectSignalSocketState( | 529 ExpectSignalSocketState( |
| 530 SignalSocketState::NoError( | 530 SignalSocketState::NoError( |
| 531 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 531 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
| 532 ExpectNoSignal(); | 532 ExpectNoSignal(); |
| 533 | 533 |
| 534 message_loop_.RunAllPending(); | 534 message_loop_.RunAllPending(); |
| 535 | 535 |
| 536 DoCloseOpenedNoError(); | 536 DoCloseOpenedNoError(); |
| 537 } | 537 } |
| 538 | 538 |
| 539 // After this no need to test successful pending connect so | 539 // After this no need to test successful pending connect so |
| 540 // thoroughly. | 540 // thoroughly. |
| 541 | 541 |
| 542 TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { | 542 TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { |
| 543 async_socket_data_provider_.set_connect_data( | 543 async_socket_data_provider_.set_connect_data( |
| 544 net::MockConnect(true, net::OK)); | 544 net::MockConnect(net::ASYNC, net::OK)); |
| 545 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 545 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 546 | 546 |
| 547 message_loop_.RunAllPending(); | 547 message_loop_.RunAllPending(); |
| 548 ExpectSignalSocketState( | 548 ExpectSignalSocketState( |
| 549 SignalSocketState::NoError( | 549 SignalSocketState::NoError( |
| 550 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 550 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
| 551 | 551 |
| 552 DoCloseOpenedNoError(); | 552 DoCloseOpenedNoError(); |
| 553 | 553 |
| 554 message_loop_.RunAllPending(); | 554 message_loop_.RunAllPending(); |
| 555 } | 555 } |
| 556 | 556 |
| 557 TEST_F(ChromeAsyncSocketTest, PendingConnectError) { | 557 TEST_F(ChromeAsyncSocketTest, PendingConnectError) { |
| 558 async_socket_data_provider_.set_connect_data( | 558 async_socket_data_provider_.set_connect_data( |
| 559 net::MockConnect(true, net::ERR_TIMED_OUT)); | 559 net::MockConnect(net::ASYNC, net::ERR_TIMED_OUT)); |
| 560 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 560 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 561 | 561 |
| 562 message_loop_.RunAllPending(); | 562 message_loop_.RunAllPending(); |
| 563 | 563 |
| 564 ExpectSignalSocketState( | 564 ExpectSignalSocketState( |
| 565 SignalSocketState( | 565 SignalSocketState( |
| 566 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 566 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
| 567 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 567 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
| 568 } | 568 } |
| 569 | 569 |
| 570 // After this we can assume Connect() and Close() work as expected. | 570 // After this we can assume Connect() and Close() work as expected. |
| 571 | 571 |
| 572 TEST_F(ChromeAsyncSocketTest, EmptyRead) { | 572 TEST_F(ChromeAsyncSocketTest, EmptyRead) { |
| 573 DoOpenClosed(); | 573 DoOpenClosed(); |
| 574 | 574 |
| 575 char buf[4096]; | 575 char buf[4096]; |
| 576 size_t len_read = 10000U; | 576 size_t len_read = 10000U; |
| 577 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); | 577 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); |
| 578 EXPECT_EQ(0U, len_read); | 578 EXPECT_EQ(0U, len_read); |
| 579 | 579 |
| 580 DoCloseOpenedNoError(); | 580 DoCloseOpenedNoError(); |
| 581 } | 581 } |
| 582 | 582 |
| 583 TEST_F(ChromeAsyncSocketTest, WrongRead) { | 583 TEST_F(ChromeAsyncSocketTest, WrongRead) { |
| 584 EXPECT_DEBUG_DEATH({ | 584 EXPECT_DEBUG_DEATH({ |
| 585 async_socket_data_provider_.set_connect_data( | 585 async_socket_data_provider_.set_connect_data( |
| 586 net::MockConnect(true, net::OK)); | 586 net::MockConnect(net::ASYNC, net::OK)); |
| 587 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 587 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 588 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 588 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
| 589 ExpectNoSignal(); | 589 ExpectNoSignal(); |
| 590 | 590 |
| 591 char buf[4096]; | 591 char buf[4096]; |
| 592 size_t len_read; | 592 size_t len_read; |
| 593 EXPECT_FALSE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); | 593 EXPECT_FALSE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); |
| 594 ExpectErrorState(ChromeAsyncSocket::STATE_CONNECTING, | 594 ExpectErrorState(ChromeAsyncSocket::STATE_CONNECTING, |
| 595 ChromeAsyncSocket::ERROR_WRONGSTATE); | 595 ChromeAsyncSocket::ERROR_WRONGSTATE); |
| 596 EXPECT_TRUE(chrome_async_socket_->Close()); | 596 EXPECT_TRUE(chrome_async_socket_->Close()); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 DoSSLCloseOpened( | 890 DoSSLCloseOpened( |
| 891 SignalSocketState(SIGNAL_CLOSE, | 891 SignalSocketState(SIGNAL_CLOSE, |
| 892 ChromeAsyncSocket::STATE_CLOSED, | 892 ChromeAsyncSocket::STATE_CLOSED, |
| 893 ChromeAsyncSocket::ERROR_WRONGSTATE, | 893 ChromeAsyncSocket::ERROR_WRONGSTATE, |
| 894 net::OK)); | 894 net::OK)); |
| 895 }, "wrong state"); | 895 }, "wrong state"); |
| 896 } | 896 } |
| 897 | 897 |
| 898 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { | 898 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { |
| 899 ssl_socket_data_provider_.connect = | 899 ssl_socket_data_provider_.connect = |
| 900 net::MockConnect(true, net::ERR_CERT_COMMON_NAME_INVALID), | 900 net::MockConnect(net::ASYNC, net::ERR_CERT_COMMON_NAME_INVALID), |
| 901 | 901 |
| 902 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 902 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 903 DoOpenClosed(); | 903 DoOpenClosed(); |
| 904 ExpectReadSignal(); | 904 ExpectReadSignal(); |
| 905 | 905 |
| 906 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 906 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 907 message_loop_.RunAllPending(); | 907 message_loop_.RunAllPending(); |
| 908 ExpectSignalSocketState( | 908 ExpectSignalSocketState( |
| 909 SignalSocketState( | 909 SignalSocketState( |
| 910 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 910 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 message_loop_.RunAllPending(); | 1064 message_loop_.RunAllPending(); |
| 1065 | 1065 |
| 1066 ExpectNoSignal(); | 1066 ExpectNoSignal(); |
| 1067 | 1067 |
| 1068 DoSSLCloseOpenedNoError(); | 1068 DoSSLCloseOpenedNoError(); |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 } // namespace | 1071 } // namespace |
| 1072 | 1072 |
| 1073 } // namespace notifier | 1073 } // namespace notifier |
| OLD | NEW |