| 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" | |
| 15 #include "jingle/glue/resolving_client_socket_factory.h" | 14 #include "jingle/glue/resolving_client_socket_factory.h" |
| 16 #include "net/base/address_list.h" | 15 #include "net/base/address_list.h" |
| 17 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 19 #include "net/cert/mock_cert_verifier.h" | 18 #include "net/cert/mock_cert_verifier.h" |
| 20 #include "net/http/transport_security_state.h" | 19 #include "net/http/transport_security_state.h" |
| 21 #include "net/socket/socket_test_util.h" | 20 #include "net/socket/socket_test_util.h" |
| 22 #include "net/socket/ssl_client_socket.h" | 21 #include "net/socket/ssl_client_socket.h" |
| 23 #include "net/ssl/ssl_config_service.h" | 22 #include "net/ssl/ssl_config_service.h" |
| 24 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 scoped_ptr<net::CertVerifier> cert_verifier_; | 136 scoped_ptr<net::CertVerifier> cert_verifier_; |
| 138 scoped_ptr<net::TransportSecurityState> transport_security_state_; | 137 scoped_ptr<net::TransportSecurityState> transport_security_state_; |
| 139 }; | 138 }; |
| 140 | 139 |
| 141 class ChromeAsyncSocketTest | 140 class ChromeAsyncSocketTest |
| 142 : public testing::Test, | 141 : public testing::Test, |
| 143 public sigslot::has_slots<> { | 142 public sigslot::has_slots<> { |
| 144 protected: | 143 protected: |
| 145 ChromeAsyncSocketTest() | 144 ChromeAsyncSocketTest() |
| 146 : ssl_socket_data_provider_(net::ASYNC, net::OK), | 145 : ssl_socket_data_provider_(net::ASYNC, net::OK), |
| 147 addr_("localhost", 35) { | 146 addr_("localhost", 35) {} |
| 148 // GTest death tests execute in a fork()ed but not exec()ed process. | |
| 149 // On OS X a CoreFoundation-backed message loop will exit with a | |
| 150 // __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONA
LITY___YOU_MUST_EXEC__ | |
| 151 // when called. | |
| 152 // Explicitly create a MessagePumpDefault which can run in this enivronment. | |
| 153 scoped_ptr<base::MessagePump> pump(new base::MessagePumpDefault()); | |
| 154 message_loop_.reset(new base::MessageLoop(pump.Pass())); | |
| 155 } | |
| 156 | 147 |
| 157 virtual ~ChromeAsyncSocketTest() {} | 148 virtual ~ChromeAsyncSocketTest() {} |
| 158 | 149 |
| 159 virtual void SetUp() { | 150 virtual void SetUp() { |
| 160 scoped_ptr<net::MockClientSocketFactory> mock_client_socket_factory( | 151 scoped_ptr<net::MockClientSocketFactory> mock_client_socket_factory( |
| 161 new net::MockClientSocketFactory()); | 152 new net::MockClientSocketFactory()); |
| 162 mock_client_socket_factory->AddSocketDataProvider( | 153 mock_client_socket_factory->AddSocketDataProvider( |
| 163 &async_socket_data_provider_); | 154 &async_socket_data_provider_); |
| 164 mock_client_socket_factory->AddSSLSocketDataProvider( | 155 mock_client_socket_factory->AddSSLSocketDataProvider( |
| 165 &ssl_socket_data_provider_); | 156 &ssl_socket_data_provider_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 184 chrome_async_socket_->SignalClosed.connect( | 175 chrome_async_socket_->SignalClosed.connect( |
| 185 this, &ChromeAsyncSocketTest::OnClose); | 176 this, &ChromeAsyncSocketTest::OnClose); |
| 186 chrome_async_socket_->SignalRead.connect( | 177 chrome_async_socket_->SignalRead.connect( |
| 187 this, &ChromeAsyncSocketTest::OnRead); | 178 this, &ChromeAsyncSocketTest::OnRead); |
| 188 chrome_async_socket_->SignalError.connect( | 179 chrome_async_socket_->SignalError.connect( |
| 189 this, &ChromeAsyncSocketTest::OnError); | 180 this, &ChromeAsyncSocketTest::OnError); |
| 190 } | 181 } |
| 191 | 182 |
| 192 virtual void TearDown() { | 183 virtual void TearDown() { |
| 193 // Run any tasks that we forgot to pump. | 184 // Run any tasks that we forgot to pump. |
| 194 message_loop_->RunUntilIdle(); | 185 message_loop_.RunUntilIdle(); |
| 195 ExpectClosed(); | 186 ExpectClosed(); |
| 196 ExpectNoSignal(); | 187 ExpectNoSignal(); |
| 197 chrome_async_socket_.reset(); | 188 chrome_async_socket_.reset(); |
| 198 } | 189 } |
| 199 | 190 |
| 200 enum Signal { | 191 enum Signal { |
| 201 SIGNAL_CONNECT, | 192 SIGNAL_CONNECT, |
| 202 SIGNAL_SSL_CONNECT, | 193 SIGNAL_SSL_CONNECT, |
| 203 SIGNAL_CLOSE, | 194 SIGNAL_CLOSE, |
| 204 SIGNAL_READ, | 195 SIGNAL_READ, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 335 |
| 345 // Open/close utility functions. | 336 // Open/close utility functions. |
| 346 | 337 |
| 347 void DoOpenClosed() { | 338 void DoOpenClosed() { |
| 348 ExpectClosed(); | 339 ExpectClosed(); |
| 349 async_socket_data_provider_.set_connect_data( | 340 async_socket_data_provider_.set_connect_data( |
| 350 net::MockConnect(net::SYNCHRONOUS, net::OK)); | 341 net::MockConnect(net::SYNCHRONOUS, net::OK)); |
| 351 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 342 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 352 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 343 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
| 353 | 344 |
| 354 message_loop_->RunUntilIdle(); | 345 message_loop_.RunUntilIdle(); |
| 355 // We may not necessarily be open; may have been other events | 346 // We may not necessarily be open; may have been other events |
| 356 // queued up. | 347 // queued up. |
| 357 ExpectSignalSocketState( | 348 ExpectSignalSocketState( |
| 358 SignalSocketState::NoError( | 349 SignalSocketState::NoError( |
| 359 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 350 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
| 360 } | 351 } |
| 361 | 352 |
| 362 void DoCloseOpened(SignalSocketState expected_signal_socket_state) { | 353 void DoCloseOpened(SignalSocketState expected_signal_socket_state) { |
| 363 // We may be in an error state, so just compare state(). | 354 // We may be in an error state, so just compare state(). |
| 364 EXPECT_EQ(ChromeAsyncSocket::STATE_OPEN, chrome_async_socket_->state()); | 355 EXPECT_EQ(ChromeAsyncSocket::STATE_OPEN, chrome_async_socket_->state()); |
| 365 EXPECT_TRUE(chrome_async_socket_->Close()); | 356 EXPECT_TRUE(chrome_async_socket_->Close()); |
| 366 ExpectSignalSocketState(expected_signal_socket_state); | 357 ExpectSignalSocketState(expected_signal_socket_state); |
| 367 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); | 358 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); |
| 368 } | 359 } |
| 369 | 360 |
| 370 void DoCloseOpenedNoError() { | 361 void DoCloseOpenedNoError() { |
| 371 DoCloseOpened( | 362 DoCloseOpened( |
| 372 SignalSocketState::NoError( | 363 SignalSocketState::NoError( |
| 373 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 364 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
| 374 } | 365 } |
| 375 | 366 |
| 376 void DoSSLOpenClosed() { | 367 void DoSSLOpenClosed() { |
| 377 const char kDummyData[] = "dummy_data"; | 368 const char kDummyData[] = "dummy_data"; |
| 378 async_socket_data_provider_.AddRead(net::MockRead(kDummyData)); | 369 async_socket_data_provider_.AddRead(net::MockRead(kDummyData)); |
| 379 DoOpenClosed(); | 370 DoOpenClosed(); |
| 380 ExpectReadSignal(); | 371 ExpectReadSignal(); |
| 381 EXPECT_EQ(kDummyData, DrainRead(1)); | 372 EXPECT_EQ(kDummyData, DrainRead(1)); |
| 382 | 373 |
| 383 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 374 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 384 message_loop_->RunUntilIdle(); | 375 message_loop_.RunUntilIdle(); |
| 385 ExpectSSLConnectSignal(); | 376 ExpectSSLConnectSignal(); |
| 386 ExpectNoSignal(); | 377 ExpectNoSignal(); |
| 387 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 378 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
| 388 } | 379 } |
| 389 | 380 |
| 390 void DoSSLCloseOpened(SignalSocketState expected_signal_socket_state) { | 381 void DoSSLCloseOpened(SignalSocketState expected_signal_socket_state) { |
| 391 // We may be in an error state, so just compare state(). | 382 // We may be in an error state, so just compare state(). |
| 392 EXPECT_EQ(ChromeAsyncSocket::STATE_TLS_OPEN, | 383 EXPECT_EQ(ChromeAsyncSocket::STATE_TLS_OPEN, |
| 393 chrome_async_socket_->state()); | 384 chrome_async_socket_->state()); |
| 394 EXPECT_TRUE(chrome_async_socket_->Close()); | 385 EXPECT_TRUE(chrome_async_socket_->Close()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 417 } | 408 } |
| 418 if (len_read == 0U) { | 409 if (len_read == 0U) { |
| 419 break; | 410 break; |
| 420 } | 411 } |
| 421 read.append(buf.get(), len_read); | 412 read.append(buf.get(), len_read); |
| 422 } | 413 } |
| 423 return read; | 414 return read; |
| 424 } | 415 } |
| 425 | 416 |
| 426 // ChromeAsyncSocket expects a message loop. | 417 // ChromeAsyncSocket expects a message loop. |
| 427 scoped_ptr<base::MessageLoop> message_loop_; | 418 base::MessageLoop message_loop_; |
| 428 | 419 |
| 429 AsyncSocketDataProvider async_socket_data_provider_; | 420 AsyncSocketDataProvider async_socket_data_provider_; |
| 430 net::SSLSocketDataProvider ssl_socket_data_provider_; | 421 net::SSLSocketDataProvider ssl_socket_data_provider_; |
| 431 | 422 |
| 432 scoped_ptr<ChromeAsyncSocket> chrome_async_socket_; | 423 scoped_ptr<ChromeAsyncSocket> chrome_async_socket_; |
| 433 std::deque<SignalSocketState> signal_socket_states_; | 424 std::deque<SignalSocketState> signal_socket_states_; |
| 434 const talk_base::SocketAddress addr_; | 425 const talk_base::SocketAddress addr_; |
| 435 | 426 |
| 436 private: | 427 private: |
| 437 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocketTest); | 428 DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocketTest); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 503 |
| 513 TEST_F(ChromeAsyncSocketTest, ImmediateConnectCloseBeforeRead) { | 504 TEST_F(ChromeAsyncSocketTest, ImmediateConnectCloseBeforeRead) { |
| 514 DoOpenClosed(); | 505 DoOpenClosed(); |
| 515 | 506 |
| 516 EXPECT_TRUE(chrome_async_socket_->Close()); | 507 EXPECT_TRUE(chrome_async_socket_->Close()); |
| 517 ExpectClosed(); | 508 ExpectClosed(); |
| 518 ExpectSignalSocketState( | 509 ExpectSignalSocketState( |
| 519 SignalSocketState::NoError( | 510 SignalSocketState::NoError( |
| 520 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 511 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
| 521 | 512 |
| 522 message_loop_->RunUntilIdle(); | 513 message_loop_.RunUntilIdle(); |
| 523 } | 514 } |
| 524 | 515 |
| 525 TEST_F(ChromeAsyncSocketTest, HangingConnect) { | 516 TEST_F(ChromeAsyncSocketTest, HangingConnect) { |
| 526 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 517 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 527 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 518 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
| 528 ExpectNoSignal(); | 519 ExpectNoSignal(); |
| 529 | 520 |
| 530 EXPECT_TRUE(chrome_async_socket_->Close()); | 521 EXPECT_TRUE(chrome_async_socket_->Close()); |
| 531 ExpectClosed(); | 522 ExpectClosed(); |
| 532 ExpectSignalSocketState( | 523 ExpectSignalSocketState( |
| 533 SignalSocketState::NoError( | 524 SignalSocketState::NoError( |
| 534 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 525 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
| 535 } | 526 } |
| 536 | 527 |
| 537 TEST_F(ChromeAsyncSocketTest, PendingConnect) { | 528 TEST_F(ChromeAsyncSocketTest, PendingConnect) { |
| 538 async_socket_data_provider_.set_connect_data( | 529 async_socket_data_provider_.set_connect_data( |
| 539 net::MockConnect(net::ASYNC, net::OK)); | 530 net::MockConnect(net::ASYNC, net::OK)); |
| 540 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 531 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 541 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 532 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
| 542 ExpectNoSignal(); | 533 ExpectNoSignal(); |
| 543 | 534 |
| 544 message_loop_->RunUntilIdle(); | 535 message_loop_.RunUntilIdle(); |
| 545 ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); | 536 ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); |
| 546 ExpectSignalSocketState( | 537 ExpectSignalSocketState( |
| 547 SignalSocketState::NoError( | 538 SignalSocketState::NoError( |
| 548 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 539 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
| 549 ExpectNoSignal(); | 540 ExpectNoSignal(); |
| 550 | 541 |
| 551 message_loop_->RunUntilIdle(); | 542 message_loop_.RunUntilIdle(); |
| 552 | 543 |
| 553 DoCloseOpenedNoError(); | 544 DoCloseOpenedNoError(); |
| 554 } | 545 } |
| 555 | 546 |
| 556 // After this no need to test successful pending connect so | 547 // After this no need to test successful pending connect so |
| 557 // thoroughly. | 548 // thoroughly. |
| 558 | 549 |
| 559 TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { | 550 TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { |
| 560 async_socket_data_provider_.set_connect_data( | 551 async_socket_data_provider_.set_connect_data( |
| 561 net::MockConnect(net::ASYNC, net::OK)); | 552 net::MockConnect(net::ASYNC, net::OK)); |
| 562 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 553 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 563 | 554 |
| 564 message_loop_->RunUntilIdle(); | 555 message_loop_.RunUntilIdle(); |
| 565 ExpectSignalSocketState( | 556 ExpectSignalSocketState( |
| 566 SignalSocketState::NoError( | 557 SignalSocketState::NoError( |
| 567 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 558 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
| 568 | 559 |
| 569 DoCloseOpenedNoError(); | 560 DoCloseOpenedNoError(); |
| 570 | 561 |
| 571 message_loop_->RunUntilIdle(); | 562 message_loop_.RunUntilIdle(); |
| 572 } | 563 } |
| 573 | 564 |
| 574 TEST_F(ChromeAsyncSocketTest, PendingConnectError) { | 565 TEST_F(ChromeAsyncSocketTest, PendingConnectError) { |
| 575 async_socket_data_provider_.set_connect_data( | 566 async_socket_data_provider_.set_connect_data( |
| 576 net::MockConnect(net::ASYNC, net::ERR_TIMED_OUT)); | 567 net::MockConnect(net::ASYNC, net::ERR_TIMED_OUT)); |
| 577 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 568 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
| 578 | 569 |
| 579 message_loop_->RunUntilIdle(); | 570 message_loop_.RunUntilIdle(); |
| 580 | 571 |
| 581 ExpectSignalSocketState( | 572 ExpectSignalSocketState( |
| 582 SignalSocketState( | 573 SignalSocketState( |
| 583 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 574 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
| 584 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 575 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
| 585 } | 576 } |
| 586 | 577 |
| 587 // After this we can assume Connect() and Close() work as expected. | 578 // After this we can assume Connect() and Close() work as expected. |
| 588 | 579 |
| 589 TEST_F(ChromeAsyncSocketTest, EmptyRead) { | 580 TEST_F(ChromeAsyncSocketTest, EmptyRead) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 622 |
| 632 TEST_F(ChromeAsyncSocketTest, Read) { | 623 TEST_F(ChromeAsyncSocketTest, Read) { |
| 633 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 624 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 634 DoOpenClosed(); | 625 DoOpenClosed(); |
| 635 | 626 |
| 636 ExpectReadSignal(); | 627 ExpectReadSignal(); |
| 637 ExpectNoSignal(); | 628 ExpectNoSignal(); |
| 638 | 629 |
| 639 EXPECT_EQ(kReadData, DrainRead(1)); | 630 EXPECT_EQ(kReadData, DrainRead(1)); |
| 640 | 631 |
| 641 message_loop_->RunUntilIdle(); | 632 message_loop_.RunUntilIdle(); |
| 642 | 633 |
| 643 DoCloseOpenedNoError(); | 634 DoCloseOpenedNoError(); |
| 644 } | 635 } |
| 645 | 636 |
| 646 TEST_F(ChromeAsyncSocketTest, ReadTwice) { | 637 TEST_F(ChromeAsyncSocketTest, ReadTwice) { |
| 647 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 638 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 648 DoOpenClosed(); | 639 DoOpenClosed(); |
| 649 | 640 |
| 650 ExpectReadSignal(); | 641 ExpectReadSignal(); |
| 651 ExpectNoSignal(); | 642 ExpectNoSignal(); |
| 652 | 643 |
| 653 EXPECT_EQ(kReadData, DrainRead(1)); | 644 EXPECT_EQ(kReadData, DrainRead(1)); |
| 654 | 645 |
| 655 message_loop_->RunUntilIdle(); | 646 message_loop_.RunUntilIdle(); |
| 656 | 647 |
| 657 const char kReadData2[] = "mydatatoread2"; | 648 const char kReadData2[] = "mydatatoread2"; |
| 658 async_socket_data_provider_.AddRead(net::MockRead(kReadData2)); | 649 async_socket_data_provider_.AddRead(net::MockRead(kReadData2)); |
| 659 | 650 |
| 660 ExpectReadSignal(); | 651 ExpectReadSignal(); |
| 661 ExpectNoSignal(); | 652 ExpectNoSignal(); |
| 662 | 653 |
| 663 EXPECT_EQ(kReadData2, DrainRead(1)); | 654 EXPECT_EQ(kReadData2, DrainRead(1)); |
| 664 | 655 |
| 665 DoCloseOpenedNoError(); | 656 DoCloseOpenedNoError(); |
| 666 } | 657 } |
| 667 | 658 |
| 668 TEST_F(ChromeAsyncSocketTest, ReadError) { | 659 TEST_F(ChromeAsyncSocketTest, ReadError) { |
| 669 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 660 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 670 DoOpenClosed(); | 661 DoOpenClosed(); |
| 671 | 662 |
| 672 ExpectReadSignal(); | 663 ExpectReadSignal(); |
| 673 ExpectNoSignal(); | 664 ExpectNoSignal(); |
| 674 | 665 |
| 675 EXPECT_EQ(kReadData, DrainRead(1)); | 666 EXPECT_EQ(kReadData, DrainRead(1)); |
| 676 | 667 |
| 677 message_loop_->RunUntilIdle(); | 668 message_loop_.RunUntilIdle(); |
| 678 | 669 |
| 679 async_socket_data_provider_.AddRead( | 670 async_socket_data_provider_.AddRead( |
| 680 net::MockRead(net::SYNCHRONOUS, net::ERR_TIMED_OUT)); | 671 net::MockRead(net::SYNCHRONOUS, net::ERR_TIMED_OUT)); |
| 681 | 672 |
| 682 ExpectSignalSocketState( | 673 ExpectSignalSocketState( |
| 683 SignalSocketState( | 674 SignalSocketState( |
| 684 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 675 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
| 685 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 676 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
| 686 } | 677 } |
| 687 | 678 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 701 | 692 |
| 702 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 693 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 703 | 694 |
| 704 ExpectSignalSocketState( | 695 ExpectSignalSocketState( |
| 705 SignalSocketState::NoError( | 696 SignalSocketState::NoError( |
| 706 SIGNAL_READ, ChromeAsyncSocket::STATE_OPEN)); | 697 SIGNAL_READ, ChromeAsyncSocket::STATE_OPEN)); |
| 707 ExpectNoSignal(); | 698 ExpectNoSignal(); |
| 708 | 699 |
| 709 EXPECT_EQ(kReadData, DrainRead(1)); | 700 EXPECT_EQ(kReadData, DrainRead(1)); |
| 710 | 701 |
| 711 message_loop_->RunUntilIdle(); | 702 message_loop_.RunUntilIdle(); |
| 712 | 703 |
| 713 DoCloseOpenedNoError(); | 704 DoCloseOpenedNoError(); |
| 714 } | 705 } |
| 715 | 706 |
| 716 TEST_F(ChromeAsyncSocketTest, PendingEmptyRead) { | 707 TEST_F(ChromeAsyncSocketTest, PendingEmptyRead) { |
| 717 DoOpenClosed(); | 708 DoOpenClosed(); |
| 718 | 709 |
| 719 ExpectNoSignal(); | 710 ExpectNoSignal(); |
| 720 | 711 |
| 721 async_socket_data_provider_.AddRead(net::MockRead("")); | 712 async_socket_data_provider_.AddRead(net::MockRead("")); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 async_socket_data_provider_.AddWrite( | 748 async_socket_data_provider_.AddWrite( |
| 758 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); | 749 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); |
| 759 async_socket_data_provider_.AddWrite( | 750 async_socket_data_provider_.AddWrite( |
| 760 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); | 751 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); |
| 761 async_socket_data_provider_.AddWrite( | 752 async_socket_data_provider_.AddWrite( |
| 762 net::MockWrite(net::SYNCHRONOUS, | 753 net::MockWrite(net::SYNCHRONOUS, |
| 763 kWriteData + 8, arraysize(kWriteData) - 8)); | 754 kWriteData + 8, arraysize(kWriteData) - 8)); |
| 764 DoOpenClosed(); | 755 DoOpenClosed(); |
| 765 | 756 |
| 766 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 757 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
| 767 message_loop_->RunUntilIdle(); | 758 message_loop_.RunUntilIdle(); |
| 768 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 759 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
| 769 message_loop_->RunUntilIdle(); | 760 message_loop_.RunUntilIdle(); |
| 770 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 761 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
| 771 arraysize(kWriteData) - 8)); | 762 arraysize(kWriteData) - 8)); |
| 772 message_loop_->RunUntilIdle(); | 763 message_loop_.RunUntilIdle(); |
| 773 | 764 |
| 774 ExpectNoSignal(); | 765 ExpectNoSignal(); |
| 775 | 766 |
| 776 DoCloseOpenedNoError(); | 767 DoCloseOpenedNoError(); |
| 777 } | 768 } |
| 778 | 769 |
| 779 TEST_F(ChromeAsyncSocketTest, AsyncWrite) { | 770 TEST_F(ChromeAsyncSocketTest, AsyncWrite) { |
| 780 DoOpenClosed(); | 771 DoOpenClosed(); |
| 781 | 772 |
| 782 async_socket_data_provider_.AddWrite( | 773 async_socket_data_provider_.AddWrite( |
| 783 net::MockWrite(net::ASYNC, kWriteData, 3)); | 774 net::MockWrite(net::ASYNC, kWriteData, 3)); |
| 784 async_socket_data_provider_.AddWrite( | 775 async_socket_data_provider_.AddWrite( |
| 785 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 776 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
| 786 async_socket_data_provider_.AddWrite( | 777 async_socket_data_provider_.AddWrite( |
| 787 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); | 778 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); |
| 788 | 779 |
| 789 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 780 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
| 790 message_loop_->RunUntilIdle(); | 781 message_loop_.RunUntilIdle(); |
| 791 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 782 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
| 792 message_loop_->RunUntilIdle(); | 783 message_loop_.RunUntilIdle(); |
| 793 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 784 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
| 794 arraysize(kWriteData) - 8)); | 785 arraysize(kWriteData) - 8)); |
| 795 message_loop_->RunUntilIdle(); | 786 message_loop_.RunUntilIdle(); |
| 796 | 787 |
| 797 ExpectNoSignal(); | 788 ExpectNoSignal(); |
| 798 | 789 |
| 799 DoCloseOpenedNoError(); | 790 DoCloseOpenedNoError(); |
| 800 } | 791 } |
| 801 | 792 |
| 802 TEST_F(ChromeAsyncSocketTest, AsyncWriteError) { | 793 TEST_F(ChromeAsyncSocketTest, AsyncWriteError) { |
| 803 DoOpenClosed(); | 794 DoOpenClosed(); |
| 804 | 795 |
| 805 async_socket_data_provider_.AddWrite( | 796 async_socket_data_provider_.AddWrite( |
| 806 net::MockWrite(net::ASYNC, kWriteData, 3)); | 797 net::MockWrite(net::ASYNC, kWriteData, 3)); |
| 807 async_socket_data_provider_.AddWrite( | 798 async_socket_data_provider_.AddWrite( |
| 808 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 799 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
| 809 async_socket_data_provider_.AddWrite( | 800 async_socket_data_provider_.AddWrite( |
| 810 net::MockWrite(net::ASYNC, net::ERR_TIMED_OUT)); | 801 net::MockWrite(net::ASYNC, net::ERR_TIMED_OUT)); |
| 811 | 802 |
| 812 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 803 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
| 813 message_loop_->RunUntilIdle(); | 804 message_loop_.RunUntilIdle(); |
| 814 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 805 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
| 815 message_loop_->RunUntilIdle(); | 806 message_loop_.RunUntilIdle(); |
| 816 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 807 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
| 817 arraysize(kWriteData) - 8)); | 808 arraysize(kWriteData) - 8)); |
| 818 message_loop_->RunUntilIdle(); | 809 message_loop_.RunUntilIdle(); |
| 819 | 810 |
| 820 ExpectSignalSocketState( | 811 ExpectSignalSocketState( |
| 821 SignalSocketState( | 812 SignalSocketState( |
| 822 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 813 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
| 823 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 814 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
| 824 } | 815 } |
| 825 | 816 |
| 826 TEST_F(ChromeAsyncSocketTest, LargeWrite) { | 817 TEST_F(ChromeAsyncSocketTest, LargeWrite) { |
| 827 EXPECT_DEBUG_DEATH({ | 818 EXPECT_DEBUG_DEATH({ |
| 828 DoOpenClosed(); | 819 DoOpenClosed(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 ChromeAsyncSocket::STATE_CLOSED)); | 867 ChromeAsyncSocket::STATE_CLOSED)); |
| 877 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); | 868 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); |
| 878 } | 869 } |
| 879 | 870 |
| 880 TEST_F(ChromeAsyncSocketTest, ImmediateSSLConnect) { | 871 TEST_F(ChromeAsyncSocketTest, ImmediateSSLConnect) { |
| 881 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 872 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 882 DoOpenClosed(); | 873 DoOpenClosed(); |
| 883 ExpectReadSignal(); | 874 ExpectReadSignal(); |
| 884 | 875 |
| 885 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 876 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 886 message_loop_->RunUntilIdle(); | 877 message_loop_.RunUntilIdle(); |
| 887 ExpectSSLConnectSignal(); | 878 ExpectSSLConnectSignal(); |
| 888 ExpectNoSignal(); | 879 ExpectNoSignal(); |
| 889 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 880 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
| 890 | 881 |
| 891 DoSSLCloseOpenedNoError(); | 882 DoSSLCloseOpenedNoError(); |
| 892 } | 883 } |
| 893 | 884 |
| 894 TEST_F(ChromeAsyncSocketTest, DoubleSSLConnect) { | 885 TEST_F(ChromeAsyncSocketTest, DoubleSSLConnect) { |
| 895 EXPECT_DEBUG_DEATH({ | 886 EXPECT_DEBUG_DEATH({ |
| 896 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 887 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 897 DoOpenClosed(); | 888 DoOpenClosed(); |
| 898 ExpectReadSignal(); | 889 ExpectReadSignal(); |
| 899 | 890 |
| 900 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 891 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 901 message_loop_->RunUntilIdle(); | 892 message_loop_.RunUntilIdle(); |
| 902 ExpectSSLConnectSignal(); | 893 ExpectSSLConnectSignal(); |
| 903 ExpectNoSignal(); | 894 ExpectNoSignal(); |
| 904 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 895 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
| 905 | 896 |
| 906 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 897 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 907 | 898 |
| 908 DoSSLCloseOpened( | 899 DoSSLCloseOpened( |
| 909 SignalSocketState(SIGNAL_CLOSE, | 900 SignalSocketState(SIGNAL_CLOSE, |
| 910 ChromeAsyncSocket::STATE_CLOSED, | 901 ChromeAsyncSocket::STATE_CLOSED, |
| 911 ChromeAsyncSocket::ERROR_WRONGSTATE, | 902 ChromeAsyncSocket::ERROR_WRONGSTATE, |
| 912 net::OK)); | 903 net::OK)); |
| 913 }, "wrong state"); | 904 }, "wrong state"); |
| 914 } | 905 } |
| 915 | 906 |
| 916 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { | 907 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { |
| 917 ssl_socket_data_provider_.connect = | 908 ssl_socket_data_provider_.connect = |
| 918 net::MockConnect(net::ASYNC, net::ERR_CERT_COMMON_NAME_INVALID), | 909 net::MockConnect(net::ASYNC, net::ERR_CERT_COMMON_NAME_INVALID), |
| 919 | 910 |
| 920 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 911 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 921 DoOpenClosed(); | 912 DoOpenClosed(); |
| 922 ExpectReadSignal(); | 913 ExpectReadSignal(); |
| 923 | 914 |
| 924 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 915 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 925 message_loop_->RunUntilIdle(); | 916 message_loop_.RunUntilIdle(); |
| 926 ExpectSignalSocketState( | 917 ExpectSignalSocketState( |
| 927 SignalSocketState( | 918 SignalSocketState( |
| 928 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 919 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
| 929 ChromeAsyncSocket::ERROR_WINSOCK, | 920 ChromeAsyncSocket::ERROR_WINSOCK, |
| 930 net::ERR_CERT_COMMON_NAME_INVALID)); | 921 net::ERR_CERT_COMMON_NAME_INVALID)); |
| 931 | 922 |
| 932 EXPECT_TRUE(chrome_async_socket_->Close()); | 923 EXPECT_TRUE(chrome_async_socket_->Close()); |
| 933 ExpectClosed(); | 924 ExpectClosed(); |
| 934 } | 925 } |
| 935 | 926 |
| 936 TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) { | 927 TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) { |
| 937 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 928 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 938 DoOpenClosed(); | 929 DoOpenClosed(); |
| 939 ExpectReadSignal(); | 930 ExpectReadSignal(); |
| 940 EXPECT_EQ(kReadData, DrainRead(1)); | 931 EXPECT_EQ(kReadData, DrainRead(1)); |
| 941 | 932 |
| 942 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 933 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 943 ExpectNoSignal(); | 934 ExpectNoSignal(); |
| 944 | 935 |
| 945 // Shouldn't do anything. | 936 // Shouldn't do anything. |
| 946 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 937 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 947 | 938 |
| 948 char buf[4096]; | 939 char buf[4096]; |
| 949 size_t len_read = 10000U; | 940 size_t len_read = 10000U; |
| 950 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); | 941 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); |
| 951 EXPECT_EQ(0U, len_read); | 942 EXPECT_EQ(0U, len_read); |
| 952 | 943 |
| 953 message_loop_->RunUntilIdle(); | 944 message_loop_.RunUntilIdle(); |
| 954 ExpectSSLConnectSignal(); | 945 ExpectSSLConnectSignal(); |
| 955 ExpectSSLReadSignal(); | 946 ExpectSSLReadSignal(); |
| 956 ExpectNoSignal(); | 947 ExpectNoSignal(); |
| 957 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 948 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
| 958 | 949 |
| 959 len_read = 10000U; | 950 len_read = 10000U; |
| 960 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); | 951 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); |
| 961 EXPECT_EQ(kReadData, std::string(buf, len_read)); | 952 EXPECT_EQ(kReadData, std::string(buf, len_read)); |
| 962 | 953 |
| 963 DoSSLCloseOpenedNoError(); | 954 DoSSLCloseOpenedNoError(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 974 | 965 |
| 975 async_socket_data_provider_.AddWrite( | 966 async_socket_data_provider_.AddWrite( |
| 976 net::MockWrite(net::ASYNC, kWriteData, 3)); | 967 net::MockWrite(net::ASYNC, kWriteData, 3)); |
| 977 | 968 |
| 978 // Shouldn't do anything. | 969 // Shouldn't do anything. |
| 979 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 970 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
| 980 | 971 |
| 981 // TODO(akalin): Figure out how to test that the write happens | 972 // TODO(akalin): Figure out how to test that the write happens |
| 982 // *after* the SSL connect. | 973 // *after* the SSL connect. |
| 983 | 974 |
| 984 message_loop_->RunUntilIdle(); | 975 message_loop_.RunUntilIdle(); |
| 985 ExpectSSLConnectSignal(); | 976 ExpectSSLConnectSignal(); |
| 986 ExpectNoSignal(); | 977 ExpectNoSignal(); |
| 987 | 978 |
| 988 message_loop_->RunUntilIdle(); | 979 message_loop_.RunUntilIdle(); |
| 989 | 980 |
| 990 DoSSLCloseOpenedNoError(); | 981 DoSSLCloseOpenedNoError(); |
| 991 } | 982 } |
| 992 | 983 |
| 993 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPendingRead) { | 984 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPendingRead) { |
| 994 EXPECT_DEBUG_DEATH({ | 985 EXPECT_DEBUG_DEATH({ |
| 995 DoOpenClosed(); | 986 DoOpenClosed(); |
| 996 | 987 |
| 997 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 988 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 998 | 989 |
| 999 DoCloseOpened( | 990 DoCloseOpened( |
| 1000 SignalSocketState(SIGNAL_CLOSE, | 991 SignalSocketState(SIGNAL_CLOSE, |
| 1001 ChromeAsyncSocket::STATE_CLOSED, | 992 ChromeAsyncSocket::STATE_CLOSED, |
| 1002 ChromeAsyncSocket::ERROR_WRONGSTATE, | 993 ChromeAsyncSocket::ERROR_WRONGSTATE, |
| 1003 net::OK)); | 994 net::OK)); |
| 1004 }, "wrong state"); | 995 }, "wrong state"); |
| 1005 } | 996 } |
| 1006 | 997 |
| 1007 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPostedWrite) { | 998 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPostedWrite) { |
| 1008 EXPECT_DEBUG_DEATH({ | 999 EXPECT_DEBUG_DEATH({ |
| 1009 DoOpenClosed(); | 1000 DoOpenClosed(); |
| 1010 | 1001 |
| 1011 async_socket_data_provider_.AddWrite( | 1002 async_socket_data_provider_.AddWrite( |
| 1012 net::MockWrite(net::ASYNC, kWriteData, 3)); | 1003 net::MockWrite(net::ASYNC, kWriteData, 3)); |
| 1013 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1004 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
| 1014 | 1005 |
| 1015 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 1006 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
| 1016 | 1007 |
| 1017 message_loop_->RunUntilIdle(); | 1008 message_loop_.RunUntilIdle(); |
| 1018 | 1009 |
| 1019 DoCloseOpened( | 1010 DoCloseOpened( |
| 1020 SignalSocketState(SIGNAL_CLOSE, | 1011 SignalSocketState(SIGNAL_CLOSE, |
| 1021 ChromeAsyncSocket::STATE_CLOSED, | 1012 ChromeAsyncSocket::STATE_CLOSED, |
| 1022 ChromeAsyncSocket::ERROR_WRONGSTATE, | 1013 ChromeAsyncSocket::ERROR_WRONGSTATE, |
| 1023 net::OK)); | 1014 net::OK)); |
| 1024 }, "wrong state"); | 1015 }, "wrong state"); |
| 1025 } | 1016 } |
| 1026 | 1017 |
| 1027 // After this we can assume SSL connect works as expected. | 1018 // After this we can assume SSL connect works as expected. |
| 1028 | 1019 |
| 1029 TEST_F(ChromeAsyncSocketTest, SSLRead) { | 1020 TEST_F(ChromeAsyncSocketTest, SSLRead) { |
| 1030 DoSSLOpenClosed(); | 1021 DoSSLOpenClosed(); |
| 1031 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 1022 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
| 1032 message_loop_->RunUntilIdle(); | 1023 message_loop_.RunUntilIdle(); |
| 1033 | 1024 |
| 1034 ExpectSSLReadSignal(); | 1025 ExpectSSLReadSignal(); |
| 1035 ExpectNoSignal(); | 1026 ExpectNoSignal(); |
| 1036 | 1027 |
| 1037 EXPECT_EQ(kReadData, DrainRead(1)); | 1028 EXPECT_EQ(kReadData, DrainRead(1)); |
| 1038 | 1029 |
| 1039 message_loop_->RunUntilIdle(); | 1030 message_loop_.RunUntilIdle(); |
| 1040 | 1031 |
| 1041 DoSSLCloseOpenedNoError(); | 1032 DoSSLCloseOpenedNoError(); |
| 1042 } | 1033 } |
| 1043 | 1034 |
| 1044 TEST_F(ChromeAsyncSocketTest, SSLSyncWrite) { | 1035 TEST_F(ChromeAsyncSocketTest, SSLSyncWrite) { |
| 1045 async_socket_data_provider_.AddWrite( | 1036 async_socket_data_provider_.AddWrite( |
| 1046 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); | 1037 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); |
| 1047 async_socket_data_provider_.AddWrite( | 1038 async_socket_data_provider_.AddWrite( |
| 1048 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); | 1039 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); |
| 1049 async_socket_data_provider_.AddWrite( | 1040 async_socket_data_provider_.AddWrite( |
| 1050 net::MockWrite(net::SYNCHRONOUS, | 1041 net::MockWrite(net::SYNCHRONOUS, |
| 1051 kWriteData + 8, arraysize(kWriteData) - 8)); | 1042 kWriteData + 8, arraysize(kWriteData) - 8)); |
| 1052 DoSSLOpenClosed(); | 1043 DoSSLOpenClosed(); |
| 1053 | 1044 |
| 1054 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1045 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
| 1055 message_loop_->RunUntilIdle(); | 1046 message_loop_.RunUntilIdle(); |
| 1056 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 1047 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
| 1057 message_loop_->RunUntilIdle(); | 1048 message_loop_.RunUntilIdle(); |
| 1058 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 1049 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
| 1059 arraysize(kWriteData) - 8)); | 1050 arraysize(kWriteData) - 8)); |
| 1060 message_loop_->RunUntilIdle(); | 1051 message_loop_.RunUntilIdle(); |
| 1061 | 1052 |
| 1062 ExpectNoSignal(); | 1053 ExpectNoSignal(); |
| 1063 | 1054 |
| 1064 DoSSLCloseOpenedNoError(); | 1055 DoSSLCloseOpenedNoError(); |
| 1065 } | 1056 } |
| 1066 | 1057 |
| 1067 TEST_F(ChromeAsyncSocketTest, SSLAsyncWrite) { | 1058 TEST_F(ChromeAsyncSocketTest, SSLAsyncWrite) { |
| 1068 DoSSLOpenClosed(); | 1059 DoSSLOpenClosed(); |
| 1069 | 1060 |
| 1070 async_socket_data_provider_.AddWrite( | 1061 async_socket_data_provider_.AddWrite( |
| 1071 net::MockWrite(net::ASYNC, kWriteData, 3)); | 1062 net::MockWrite(net::ASYNC, kWriteData, 3)); |
| 1072 async_socket_data_provider_.AddWrite( | 1063 async_socket_data_provider_.AddWrite( |
| 1073 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 1064 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
| 1074 async_socket_data_provider_.AddWrite( | 1065 async_socket_data_provider_.AddWrite( |
| 1075 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); | 1066 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); |
| 1076 | 1067 |
| 1077 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1068 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
| 1078 message_loop_->RunUntilIdle(); | 1069 message_loop_.RunUntilIdle(); |
| 1079 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 1070 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
| 1080 message_loop_->RunUntilIdle(); | 1071 message_loop_.RunUntilIdle(); |
| 1081 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 1072 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
| 1082 arraysize(kWriteData) - 8)); | 1073 arraysize(kWriteData) - 8)); |
| 1083 message_loop_->RunUntilIdle(); | 1074 message_loop_.RunUntilIdle(); |
| 1084 | 1075 |
| 1085 ExpectNoSignal(); | 1076 ExpectNoSignal(); |
| 1086 | 1077 |
| 1087 DoSSLCloseOpenedNoError(); | 1078 DoSSLCloseOpenedNoError(); |
| 1088 } | 1079 } |
| 1089 | 1080 |
| 1090 } // namespace | 1081 } // namespace |
| 1091 | 1082 |
| 1092 } // namespace jingle_glue | 1083 } // namespace jingle_glue |
| OLD | NEW |