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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/message_loop/message_pump_default.h" | 17 #include "base/message_loop/message_pump_default.h" |
| 18 #include "base/run_loop.h" |
18 #include "jingle/glue/resolving_client_socket_factory.h" | 19 #include "jingle/glue/resolving_client_socket_factory.h" |
19 #include "net/base/address_list.h" | 20 #include "net/base/address_list.h" |
20 #include "net/base/ip_address.h" | 21 #include "net/base/ip_address.h" |
21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
22 #include "net/cert/mock_cert_verifier.h" | 23 #include "net/cert/mock_cert_verifier.h" |
23 #include "net/http/transport_security_state.h" | 24 #include "net/http/transport_security_state.h" |
24 #include "net/socket/socket_test_util.h" | 25 #include "net/socket/socket_test_util.h" |
25 #include "net/socket/ssl_client_socket.h" | 26 #include "net/socket/ssl_client_socket.h" |
26 #include "net/ssl/ssl_config_service.h" | 27 #include "net/ssl/ssl_config_service.h" |
27 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 chrome_async_socket_->SignalClosed.connect( | 193 chrome_async_socket_->SignalClosed.connect( |
193 this, &ChromeAsyncSocketTest::OnClose); | 194 this, &ChromeAsyncSocketTest::OnClose); |
194 chrome_async_socket_->SignalRead.connect( | 195 chrome_async_socket_->SignalRead.connect( |
195 this, &ChromeAsyncSocketTest::OnRead); | 196 this, &ChromeAsyncSocketTest::OnRead); |
196 chrome_async_socket_->SignalError.connect( | 197 chrome_async_socket_->SignalError.connect( |
197 this, &ChromeAsyncSocketTest::OnError); | 198 this, &ChromeAsyncSocketTest::OnError); |
198 } | 199 } |
199 | 200 |
200 void TearDown() override { | 201 void TearDown() override { |
201 // Run any tasks that we forgot to pump. | 202 // Run any tasks that we forgot to pump. |
202 message_loop_->RunUntilIdle(); | 203 base::RunLoop().RunUntilIdle(); |
203 ExpectClosed(); | 204 ExpectClosed(); |
204 ExpectNoSignal(); | 205 ExpectNoSignal(); |
205 chrome_async_socket_.reset(); | 206 chrome_async_socket_.reset(); |
206 } | 207 } |
207 | 208 |
208 enum Signal { | 209 enum Signal { |
209 SIGNAL_CONNECT, | 210 SIGNAL_CONNECT, |
210 SIGNAL_SSL_CONNECT, | 211 SIGNAL_SSL_CONNECT, |
211 SIGNAL_CLOSE, | 212 SIGNAL_CLOSE, |
212 SIGNAL_READ, | 213 SIGNAL_READ, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 353 |
353 // Open/close utility functions. | 354 // Open/close utility functions. |
354 | 355 |
355 void DoOpenClosed() { | 356 void DoOpenClosed() { |
356 ExpectClosed(); | 357 ExpectClosed(); |
357 async_socket_data_provider_.set_connect_data( | 358 async_socket_data_provider_.set_connect_data( |
358 net::MockConnect(net::SYNCHRONOUS, net::OK)); | 359 net::MockConnect(net::SYNCHRONOUS, net::OK)); |
359 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 360 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
360 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 361 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
361 | 362 |
362 message_loop_->RunUntilIdle(); | 363 base::RunLoop().RunUntilIdle(); |
363 // We may not necessarily be open; may have been other events | 364 // We may not necessarily be open; may have been other events |
364 // queued up. | 365 // queued up. |
365 ExpectSignalSocketState( | 366 ExpectSignalSocketState( |
366 SignalSocketState::NoError( | 367 SignalSocketState::NoError( |
367 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 368 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
368 } | 369 } |
369 | 370 |
370 void DoCloseOpened(SignalSocketState expected_signal_socket_state) { | 371 void DoCloseOpened(SignalSocketState expected_signal_socket_state) { |
371 // We may be in an error state, so just compare state(). | 372 // We may be in an error state, so just compare state(). |
372 EXPECT_EQ(ChromeAsyncSocket::STATE_OPEN, chrome_async_socket_->state()); | 373 EXPECT_EQ(ChromeAsyncSocket::STATE_OPEN, chrome_async_socket_->state()); |
373 EXPECT_TRUE(chrome_async_socket_->Close()); | 374 EXPECT_TRUE(chrome_async_socket_->Close()); |
374 ExpectSignalSocketState(expected_signal_socket_state); | 375 ExpectSignalSocketState(expected_signal_socket_state); |
375 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); | 376 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); |
376 } | 377 } |
377 | 378 |
378 void DoCloseOpenedNoError() { | 379 void DoCloseOpenedNoError() { |
379 DoCloseOpened( | 380 DoCloseOpened( |
380 SignalSocketState::NoError( | 381 SignalSocketState::NoError( |
381 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 382 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
382 } | 383 } |
383 | 384 |
384 void DoSSLOpenClosed() { | 385 void DoSSLOpenClosed() { |
385 const char kDummyData[] = "dummy_data"; | 386 const char kDummyData[] = "dummy_data"; |
386 async_socket_data_provider_.AddRead(net::MockRead(kDummyData)); | 387 async_socket_data_provider_.AddRead(net::MockRead(kDummyData)); |
387 DoOpenClosed(); | 388 DoOpenClosed(); |
388 ExpectReadSignal(); | 389 ExpectReadSignal(); |
389 EXPECT_EQ(kDummyData, DrainRead(1)); | 390 EXPECT_EQ(kDummyData, DrainRead(1)); |
390 | 391 |
391 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 392 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
392 message_loop_->RunUntilIdle(); | 393 base::RunLoop().RunUntilIdle(); |
393 ExpectSSLConnectSignal(); | 394 ExpectSSLConnectSignal(); |
394 ExpectNoSignal(); | 395 ExpectNoSignal(); |
395 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 396 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
396 } | 397 } |
397 | 398 |
398 void DoSSLCloseOpened(SignalSocketState expected_signal_socket_state) { | 399 void DoSSLCloseOpened(SignalSocketState expected_signal_socket_state) { |
399 // We may be in an error state, so just compare state(). | 400 // We may be in an error state, so just compare state(). |
400 EXPECT_EQ(ChromeAsyncSocket::STATE_TLS_OPEN, | 401 EXPECT_EQ(ChromeAsyncSocket::STATE_TLS_OPEN, |
401 chrome_async_socket_->state()); | 402 chrome_async_socket_->state()); |
402 EXPECT_TRUE(chrome_async_socket_->Close()); | 403 EXPECT_TRUE(chrome_async_socket_->Close()); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 521 |
521 TEST_F(ChromeAsyncSocketTest, ImmediateConnectCloseBeforeRead) { | 522 TEST_F(ChromeAsyncSocketTest, ImmediateConnectCloseBeforeRead) { |
522 DoOpenClosed(); | 523 DoOpenClosed(); |
523 | 524 |
524 EXPECT_TRUE(chrome_async_socket_->Close()); | 525 EXPECT_TRUE(chrome_async_socket_->Close()); |
525 ExpectClosed(); | 526 ExpectClosed(); |
526 ExpectSignalSocketState( | 527 ExpectSignalSocketState( |
527 SignalSocketState::NoError( | 528 SignalSocketState::NoError( |
528 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 529 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
529 | 530 |
530 message_loop_->RunUntilIdle(); | 531 base::RunLoop().RunUntilIdle(); |
531 } | 532 } |
532 | 533 |
533 TEST_F(ChromeAsyncSocketTest, HangingConnect) { | 534 TEST_F(ChromeAsyncSocketTest, HangingConnect) { |
534 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 535 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
535 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 536 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
536 ExpectNoSignal(); | 537 ExpectNoSignal(); |
537 | 538 |
538 EXPECT_TRUE(chrome_async_socket_->Close()); | 539 EXPECT_TRUE(chrome_async_socket_->Close()); |
539 ExpectClosed(); | 540 ExpectClosed(); |
540 ExpectSignalSocketState( | 541 ExpectSignalSocketState( |
541 SignalSocketState::NoError( | 542 SignalSocketState::NoError( |
542 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 543 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
543 } | 544 } |
544 | 545 |
545 TEST_F(ChromeAsyncSocketTest, PendingConnect) { | 546 TEST_F(ChromeAsyncSocketTest, PendingConnect) { |
546 async_socket_data_provider_.set_connect_data( | 547 async_socket_data_provider_.set_connect_data( |
547 net::MockConnect(net::ASYNC, net::OK)); | 548 net::MockConnect(net::ASYNC, net::OK)); |
548 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 549 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
549 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 550 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
550 ExpectNoSignal(); | 551 ExpectNoSignal(); |
551 | 552 |
552 message_loop_->RunUntilIdle(); | 553 base::RunLoop().RunUntilIdle(); |
553 ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); | 554 ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); |
554 ExpectSignalSocketState( | 555 ExpectSignalSocketState( |
555 SignalSocketState::NoError( | 556 SignalSocketState::NoError( |
556 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 557 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
557 ExpectNoSignal(); | 558 ExpectNoSignal(); |
558 | 559 |
559 message_loop_->RunUntilIdle(); | 560 base::RunLoop().RunUntilIdle(); |
560 | 561 |
561 DoCloseOpenedNoError(); | 562 DoCloseOpenedNoError(); |
562 } | 563 } |
563 | 564 |
564 // After this no need to test successful pending connect so | 565 // After this no need to test successful pending connect so |
565 // thoroughly. | 566 // thoroughly. |
566 | 567 |
567 TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { | 568 TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { |
568 async_socket_data_provider_.set_connect_data( | 569 async_socket_data_provider_.set_connect_data( |
569 net::MockConnect(net::ASYNC, net::OK)); | 570 net::MockConnect(net::ASYNC, net::OK)); |
570 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 571 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
571 | 572 |
572 message_loop_->RunUntilIdle(); | 573 base::RunLoop().RunUntilIdle(); |
573 ExpectSignalSocketState( | 574 ExpectSignalSocketState( |
574 SignalSocketState::NoError( | 575 SignalSocketState::NoError( |
575 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 576 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
576 | 577 |
577 DoCloseOpenedNoError(); | 578 DoCloseOpenedNoError(); |
578 | 579 |
579 message_loop_->RunUntilIdle(); | 580 base::RunLoop().RunUntilIdle(); |
580 } | 581 } |
581 | 582 |
582 TEST_F(ChromeAsyncSocketTest, PendingConnectError) { | 583 TEST_F(ChromeAsyncSocketTest, PendingConnectError) { |
583 async_socket_data_provider_.set_connect_data( | 584 async_socket_data_provider_.set_connect_data( |
584 net::MockConnect(net::ASYNC, net::ERR_TIMED_OUT)); | 585 net::MockConnect(net::ASYNC, net::ERR_TIMED_OUT)); |
585 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 586 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
586 | 587 |
587 message_loop_->RunUntilIdle(); | 588 base::RunLoop().RunUntilIdle(); |
588 | 589 |
589 ExpectSignalSocketState( | 590 ExpectSignalSocketState( |
590 SignalSocketState( | 591 SignalSocketState( |
591 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 592 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
592 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 593 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
593 } | 594 } |
594 | 595 |
595 // After this we can assume Connect() and Close() work as expected. | 596 // After this we can assume Connect() and Close() work as expected. |
596 | 597 |
597 TEST_F(ChromeAsyncSocketTest, EmptyRead) { | 598 TEST_F(ChromeAsyncSocketTest, EmptyRead) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 | 640 |
640 TEST_F(ChromeAsyncSocketTest, Read) { | 641 TEST_F(ChromeAsyncSocketTest, Read) { |
641 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 642 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
642 DoOpenClosed(); | 643 DoOpenClosed(); |
643 | 644 |
644 ExpectReadSignal(); | 645 ExpectReadSignal(); |
645 ExpectNoSignal(); | 646 ExpectNoSignal(); |
646 | 647 |
647 EXPECT_EQ(kReadData, DrainRead(1)); | 648 EXPECT_EQ(kReadData, DrainRead(1)); |
648 | 649 |
649 message_loop_->RunUntilIdle(); | 650 base::RunLoop().RunUntilIdle(); |
650 | 651 |
651 DoCloseOpenedNoError(); | 652 DoCloseOpenedNoError(); |
652 } | 653 } |
653 | 654 |
654 TEST_F(ChromeAsyncSocketTest, ReadTwice) { | 655 TEST_F(ChromeAsyncSocketTest, ReadTwice) { |
655 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 656 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
656 DoOpenClosed(); | 657 DoOpenClosed(); |
657 | 658 |
658 ExpectReadSignal(); | 659 ExpectReadSignal(); |
659 ExpectNoSignal(); | 660 ExpectNoSignal(); |
660 | 661 |
661 EXPECT_EQ(kReadData, DrainRead(1)); | 662 EXPECT_EQ(kReadData, DrainRead(1)); |
662 | 663 |
663 message_loop_->RunUntilIdle(); | 664 base::RunLoop().RunUntilIdle(); |
664 | 665 |
665 const char kReadData2[] = "mydatatoread2"; | 666 const char kReadData2[] = "mydatatoread2"; |
666 async_socket_data_provider_.AddRead(net::MockRead(kReadData2)); | 667 async_socket_data_provider_.AddRead(net::MockRead(kReadData2)); |
667 | 668 |
668 ExpectReadSignal(); | 669 ExpectReadSignal(); |
669 ExpectNoSignal(); | 670 ExpectNoSignal(); |
670 | 671 |
671 EXPECT_EQ(kReadData2, DrainRead(1)); | 672 EXPECT_EQ(kReadData2, DrainRead(1)); |
672 | 673 |
673 DoCloseOpenedNoError(); | 674 DoCloseOpenedNoError(); |
674 } | 675 } |
675 | 676 |
676 TEST_F(ChromeAsyncSocketTest, ReadError) { | 677 TEST_F(ChromeAsyncSocketTest, ReadError) { |
677 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 678 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
678 DoOpenClosed(); | 679 DoOpenClosed(); |
679 | 680 |
680 ExpectReadSignal(); | 681 ExpectReadSignal(); |
681 ExpectNoSignal(); | 682 ExpectNoSignal(); |
682 | 683 |
683 EXPECT_EQ(kReadData, DrainRead(1)); | 684 EXPECT_EQ(kReadData, DrainRead(1)); |
684 | 685 |
685 message_loop_->RunUntilIdle(); | 686 base::RunLoop().RunUntilIdle(); |
686 | 687 |
687 async_socket_data_provider_.AddRead( | 688 async_socket_data_provider_.AddRead( |
688 net::MockRead(net::SYNCHRONOUS, net::ERR_TIMED_OUT)); | 689 net::MockRead(net::SYNCHRONOUS, net::ERR_TIMED_OUT)); |
689 | 690 |
690 ExpectSignalSocketState( | 691 ExpectSignalSocketState( |
691 SignalSocketState( | 692 SignalSocketState( |
692 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 693 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
693 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 694 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
694 } | 695 } |
695 | 696 |
(...skipping 13 matching lines...) Expand all Loading... |
709 | 710 |
710 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 711 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
711 | 712 |
712 ExpectSignalSocketState( | 713 ExpectSignalSocketState( |
713 SignalSocketState::NoError( | 714 SignalSocketState::NoError( |
714 SIGNAL_READ, ChromeAsyncSocket::STATE_OPEN)); | 715 SIGNAL_READ, ChromeAsyncSocket::STATE_OPEN)); |
715 ExpectNoSignal(); | 716 ExpectNoSignal(); |
716 | 717 |
717 EXPECT_EQ(kReadData, DrainRead(1)); | 718 EXPECT_EQ(kReadData, DrainRead(1)); |
718 | 719 |
719 message_loop_->RunUntilIdle(); | 720 base::RunLoop().RunUntilIdle(); |
720 | 721 |
721 DoCloseOpenedNoError(); | 722 DoCloseOpenedNoError(); |
722 } | 723 } |
723 | 724 |
724 TEST_F(ChromeAsyncSocketTest, PendingEmptyRead) { | 725 TEST_F(ChromeAsyncSocketTest, PendingEmptyRead) { |
725 DoOpenClosed(); | 726 DoOpenClosed(); |
726 | 727 |
727 ExpectNoSignal(); | 728 ExpectNoSignal(); |
728 | 729 |
729 async_socket_data_provider_.AddRead(net::MockRead("")); | 730 async_socket_data_provider_.AddRead(net::MockRead("")); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 async_socket_data_provider_.AddWrite( | 766 async_socket_data_provider_.AddWrite( |
766 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); | 767 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); |
767 async_socket_data_provider_.AddWrite( | 768 async_socket_data_provider_.AddWrite( |
768 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); | 769 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); |
769 async_socket_data_provider_.AddWrite( | 770 async_socket_data_provider_.AddWrite( |
770 net::MockWrite(net::SYNCHRONOUS, | 771 net::MockWrite(net::SYNCHRONOUS, |
771 kWriteData + 8, arraysize(kWriteData) - 8)); | 772 kWriteData + 8, arraysize(kWriteData) - 8)); |
772 DoOpenClosed(); | 773 DoOpenClosed(); |
773 | 774 |
774 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 775 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
775 message_loop_->RunUntilIdle(); | 776 base::RunLoop().RunUntilIdle(); |
776 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 777 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
777 message_loop_->RunUntilIdle(); | 778 base::RunLoop().RunUntilIdle(); |
778 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 779 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
779 arraysize(kWriteData) - 8)); | 780 arraysize(kWriteData) - 8)); |
780 message_loop_->RunUntilIdle(); | 781 base::RunLoop().RunUntilIdle(); |
781 | 782 |
782 ExpectNoSignal(); | 783 ExpectNoSignal(); |
783 | 784 |
784 DoCloseOpenedNoError(); | 785 DoCloseOpenedNoError(); |
785 } | 786 } |
786 | 787 |
787 TEST_F(ChromeAsyncSocketTest, AsyncWrite) { | 788 TEST_F(ChromeAsyncSocketTest, AsyncWrite) { |
788 DoOpenClosed(); | 789 DoOpenClosed(); |
789 | 790 |
790 async_socket_data_provider_.AddWrite( | 791 async_socket_data_provider_.AddWrite( |
791 net::MockWrite(net::ASYNC, kWriteData, 3)); | 792 net::MockWrite(net::ASYNC, kWriteData, 3)); |
792 async_socket_data_provider_.AddWrite( | 793 async_socket_data_provider_.AddWrite( |
793 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 794 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
794 async_socket_data_provider_.AddWrite( | 795 async_socket_data_provider_.AddWrite( |
795 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); | 796 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); |
796 | 797 |
797 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 798 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
798 message_loop_->RunUntilIdle(); | 799 base::RunLoop().RunUntilIdle(); |
799 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 800 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
800 message_loop_->RunUntilIdle(); | 801 base::RunLoop().RunUntilIdle(); |
801 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 802 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
802 arraysize(kWriteData) - 8)); | 803 arraysize(kWriteData) - 8)); |
803 message_loop_->RunUntilIdle(); | 804 base::RunLoop().RunUntilIdle(); |
804 | 805 |
805 ExpectNoSignal(); | 806 ExpectNoSignal(); |
806 | 807 |
807 DoCloseOpenedNoError(); | 808 DoCloseOpenedNoError(); |
808 } | 809 } |
809 | 810 |
810 TEST_F(ChromeAsyncSocketTest, AsyncWriteError) { | 811 TEST_F(ChromeAsyncSocketTest, AsyncWriteError) { |
811 DoOpenClosed(); | 812 DoOpenClosed(); |
812 | 813 |
813 async_socket_data_provider_.AddWrite( | 814 async_socket_data_provider_.AddWrite( |
814 net::MockWrite(net::ASYNC, kWriteData, 3)); | 815 net::MockWrite(net::ASYNC, kWriteData, 3)); |
815 async_socket_data_provider_.AddWrite( | 816 async_socket_data_provider_.AddWrite( |
816 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 817 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
817 async_socket_data_provider_.AddWrite( | 818 async_socket_data_provider_.AddWrite( |
818 net::MockWrite(net::ASYNC, net::ERR_TIMED_OUT)); | 819 net::MockWrite(net::ASYNC, net::ERR_TIMED_OUT)); |
819 | 820 |
820 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 821 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
821 message_loop_->RunUntilIdle(); | 822 base::RunLoop().RunUntilIdle(); |
822 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 823 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
823 message_loop_->RunUntilIdle(); | 824 base::RunLoop().RunUntilIdle(); |
824 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 825 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
825 arraysize(kWriteData) - 8)); | 826 arraysize(kWriteData) - 8)); |
826 message_loop_->RunUntilIdle(); | 827 base::RunLoop().RunUntilIdle(); |
827 | 828 |
828 ExpectSignalSocketState( | 829 ExpectSignalSocketState( |
829 SignalSocketState( | 830 SignalSocketState( |
830 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 831 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
831 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 832 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
832 } | 833 } |
833 | 834 |
834 TEST_F(ChromeAsyncSocketTest, LargeWrite) { | 835 TEST_F(ChromeAsyncSocketTest, LargeWrite) { |
835 EXPECT_DEBUG_DEATH({ | 836 EXPECT_DEBUG_DEATH({ |
836 DoOpenClosed(); | 837 DoOpenClosed(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 ChromeAsyncSocket::STATE_CLOSED)); | 885 ChromeAsyncSocket::STATE_CLOSED)); |
885 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); | 886 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); |
886 } | 887 } |
887 | 888 |
888 TEST_F(ChromeAsyncSocketTest, ImmediateSSLConnect) { | 889 TEST_F(ChromeAsyncSocketTest, ImmediateSSLConnect) { |
889 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 890 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
890 DoOpenClosed(); | 891 DoOpenClosed(); |
891 ExpectReadSignal(); | 892 ExpectReadSignal(); |
892 | 893 |
893 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 894 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
894 message_loop_->RunUntilIdle(); | 895 base::RunLoop().RunUntilIdle(); |
895 ExpectSSLConnectSignal(); | 896 ExpectSSLConnectSignal(); |
896 ExpectNoSignal(); | 897 ExpectNoSignal(); |
897 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 898 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
898 | 899 |
899 DoSSLCloseOpenedNoError(); | 900 DoSSLCloseOpenedNoError(); |
900 } | 901 } |
901 | 902 |
902 TEST_F(ChromeAsyncSocketTest, DoubleSSLConnect) { | 903 TEST_F(ChromeAsyncSocketTest, DoubleSSLConnect) { |
903 EXPECT_DEBUG_DEATH({ | 904 EXPECT_DEBUG_DEATH({ |
904 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 905 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
905 DoOpenClosed(); | 906 DoOpenClosed(); |
906 ExpectReadSignal(); | 907 ExpectReadSignal(); |
907 | 908 |
908 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 909 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
909 message_loop_->RunUntilIdle(); | 910 base::RunLoop().RunUntilIdle(); |
910 ExpectSSLConnectSignal(); | 911 ExpectSSLConnectSignal(); |
911 ExpectNoSignal(); | 912 ExpectNoSignal(); |
912 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 913 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
913 | 914 |
914 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 915 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
915 | 916 |
916 DoSSLCloseOpened( | 917 DoSSLCloseOpened( |
917 SignalSocketState(SIGNAL_CLOSE, | 918 SignalSocketState(SIGNAL_CLOSE, |
918 ChromeAsyncSocket::STATE_CLOSED, | 919 ChromeAsyncSocket::STATE_CLOSED, |
919 ChromeAsyncSocket::ERROR_WRONGSTATE, | 920 ChromeAsyncSocket::ERROR_WRONGSTATE, |
920 net::OK)); | 921 net::OK)); |
921 }, "wrong state"); | 922 }, "wrong state"); |
922 } | 923 } |
923 | 924 |
924 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { | 925 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { |
925 ssl_socket_data_provider_.connect = | 926 ssl_socket_data_provider_.connect = |
926 net::MockConnect(net::ASYNC, net::ERR_CERT_COMMON_NAME_INVALID), | 927 net::MockConnect(net::ASYNC, net::ERR_CERT_COMMON_NAME_INVALID), |
927 | 928 |
928 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 929 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
929 DoOpenClosed(); | 930 DoOpenClosed(); |
930 ExpectReadSignal(); | 931 ExpectReadSignal(); |
931 | 932 |
932 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 933 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
933 message_loop_->RunUntilIdle(); | 934 base::RunLoop().RunUntilIdle(); |
934 ExpectSignalSocketState( | 935 ExpectSignalSocketState( |
935 SignalSocketState( | 936 SignalSocketState( |
936 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 937 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
937 ChromeAsyncSocket::ERROR_WINSOCK, | 938 ChromeAsyncSocket::ERROR_WINSOCK, |
938 net::ERR_CERT_COMMON_NAME_INVALID)); | 939 net::ERR_CERT_COMMON_NAME_INVALID)); |
939 | 940 |
940 EXPECT_TRUE(chrome_async_socket_->Close()); | 941 EXPECT_TRUE(chrome_async_socket_->Close()); |
941 ExpectClosed(); | 942 ExpectClosed(); |
942 } | 943 } |
943 | 944 |
944 TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) { | 945 TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) { |
945 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 946 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
946 DoOpenClosed(); | 947 DoOpenClosed(); |
947 ExpectReadSignal(); | 948 ExpectReadSignal(); |
948 EXPECT_EQ(kReadData, DrainRead(1)); | 949 EXPECT_EQ(kReadData, DrainRead(1)); |
949 | 950 |
950 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 951 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
951 ExpectNoSignal(); | 952 ExpectNoSignal(); |
952 | 953 |
953 // Shouldn't do anything. | 954 // Shouldn't do anything. |
954 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 955 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
955 | 956 |
956 char buf[4096]; | 957 char buf[4096]; |
957 size_t len_read = 10000U; | 958 size_t len_read = 10000U; |
958 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); | 959 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); |
959 EXPECT_EQ(0U, len_read); | 960 EXPECT_EQ(0U, len_read); |
960 | 961 |
961 message_loop_->RunUntilIdle(); | 962 base::RunLoop().RunUntilIdle(); |
962 ExpectSSLConnectSignal(); | 963 ExpectSSLConnectSignal(); |
963 ExpectSSLReadSignal(); | 964 ExpectSSLReadSignal(); |
964 ExpectNoSignal(); | 965 ExpectNoSignal(); |
965 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 966 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
966 | 967 |
967 len_read = 10000U; | 968 len_read = 10000U; |
968 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); | 969 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); |
969 EXPECT_EQ(kReadData, std::string(buf, len_read)); | 970 EXPECT_EQ(kReadData, std::string(buf, len_read)); |
970 | 971 |
971 DoSSLCloseOpenedNoError(); | 972 DoSSLCloseOpenedNoError(); |
(...skipping 10 matching lines...) Expand all Loading... |
982 | 983 |
983 async_socket_data_provider_.AddWrite( | 984 async_socket_data_provider_.AddWrite( |
984 net::MockWrite(net::ASYNC, kWriteData, 3)); | 985 net::MockWrite(net::ASYNC, kWriteData, 3)); |
985 | 986 |
986 // Shouldn't do anything. | 987 // Shouldn't do anything. |
987 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 988 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
988 | 989 |
989 // TODO(akalin): Figure out how to test that the write happens | 990 // TODO(akalin): Figure out how to test that the write happens |
990 // *after* the SSL connect. | 991 // *after* the SSL connect. |
991 | 992 |
992 message_loop_->RunUntilIdle(); | 993 base::RunLoop().RunUntilIdle(); |
993 ExpectSSLConnectSignal(); | 994 ExpectSSLConnectSignal(); |
994 ExpectNoSignal(); | 995 ExpectNoSignal(); |
995 | 996 |
996 message_loop_->RunUntilIdle(); | 997 base::RunLoop().RunUntilIdle(); |
997 | 998 |
998 DoSSLCloseOpenedNoError(); | 999 DoSSLCloseOpenedNoError(); |
999 } | 1000 } |
1000 | 1001 |
1001 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPendingRead) { | 1002 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPendingRead) { |
1002 EXPECT_DEBUG_DEATH({ | 1003 EXPECT_DEBUG_DEATH({ |
1003 DoOpenClosed(); | 1004 DoOpenClosed(); |
1004 | 1005 |
1005 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 1006 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
1006 | 1007 |
1007 DoCloseOpened( | 1008 DoCloseOpened( |
1008 SignalSocketState(SIGNAL_CLOSE, | 1009 SignalSocketState(SIGNAL_CLOSE, |
1009 ChromeAsyncSocket::STATE_CLOSED, | 1010 ChromeAsyncSocket::STATE_CLOSED, |
1010 ChromeAsyncSocket::ERROR_WRONGSTATE, | 1011 ChromeAsyncSocket::ERROR_WRONGSTATE, |
1011 net::OK)); | 1012 net::OK)); |
1012 }, "wrong state"); | 1013 }, "wrong state"); |
1013 } | 1014 } |
1014 | 1015 |
1015 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPostedWrite) { | 1016 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPostedWrite) { |
1016 EXPECT_DEBUG_DEATH({ | 1017 EXPECT_DEBUG_DEATH({ |
1017 DoOpenClosed(); | 1018 DoOpenClosed(); |
1018 | 1019 |
1019 async_socket_data_provider_.AddWrite( | 1020 async_socket_data_provider_.AddWrite( |
1020 net::MockWrite(net::ASYNC, kWriteData, 3)); | 1021 net::MockWrite(net::ASYNC, kWriteData, 3)); |
1021 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1022 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
1022 | 1023 |
1023 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 1024 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
1024 | 1025 |
1025 message_loop_->RunUntilIdle(); | 1026 base::RunLoop().RunUntilIdle(); |
1026 | 1027 |
1027 DoCloseOpened( | 1028 DoCloseOpened( |
1028 SignalSocketState(SIGNAL_CLOSE, | 1029 SignalSocketState(SIGNAL_CLOSE, |
1029 ChromeAsyncSocket::STATE_CLOSED, | 1030 ChromeAsyncSocket::STATE_CLOSED, |
1030 ChromeAsyncSocket::ERROR_WRONGSTATE, | 1031 ChromeAsyncSocket::ERROR_WRONGSTATE, |
1031 net::OK)); | 1032 net::OK)); |
1032 }, "wrong state"); | 1033 }, "wrong state"); |
1033 } | 1034 } |
1034 | 1035 |
1035 // After this we can assume SSL connect works as expected. | 1036 // After this we can assume SSL connect works as expected. |
1036 | 1037 |
1037 TEST_F(ChromeAsyncSocketTest, SSLRead) { | 1038 TEST_F(ChromeAsyncSocketTest, SSLRead) { |
1038 DoSSLOpenClosed(); | 1039 DoSSLOpenClosed(); |
1039 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 1040 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
1040 message_loop_->RunUntilIdle(); | 1041 base::RunLoop().RunUntilIdle(); |
1041 | 1042 |
1042 ExpectSSLReadSignal(); | 1043 ExpectSSLReadSignal(); |
1043 ExpectNoSignal(); | 1044 ExpectNoSignal(); |
1044 | 1045 |
1045 EXPECT_EQ(kReadData, DrainRead(1)); | 1046 EXPECT_EQ(kReadData, DrainRead(1)); |
1046 | 1047 |
1047 message_loop_->RunUntilIdle(); | 1048 base::RunLoop().RunUntilIdle(); |
1048 | 1049 |
1049 DoSSLCloseOpenedNoError(); | 1050 DoSSLCloseOpenedNoError(); |
1050 } | 1051 } |
1051 | 1052 |
1052 TEST_F(ChromeAsyncSocketTest, SSLSyncWrite) { | 1053 TEST_F(ChromeAsyncSocketTest, SSLSyncWrite) { |
1053 async_socket_data_provider_.AddWrite( | 1054 async_socket_data_provider_.AddWrite( |
1054 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); | 1055 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); |
1055 async_socket_data_provider_.AddWrite( | 1056 async_socket_data_provider_.AddWrite( |
1056 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); | 1057 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); |
1057 async_socket_data_provider_.AddWrite( | 1058 async_socket_data_provider_.AddWrite( |
1058 net::MockWrite(net::SYNCHRONOUS, | 1059 net::MockWrite(net::SYNCHRONOUS, |
1059 kWriteData + 8, arraysize(kWriteData) - 8)); | 1060 kWriteData + 8, arraysize(kWriteData) - 8)); |
1060 DoSSLOpenClosed(); | 1061 DoSSLOpenClosed(); |
1061 | 1062 |
1062 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1063 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
1063 message_loop_->RunUntilIdle(); | 1064 base::RunLoop().RunUntilIdle(); |
1064 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 1065 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
1065 message_loop_->RunUntilIdle(); | 1066 base::RunLoop().RunUntilIdle(); |
1066 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 1067 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
1067 arraysize(kWriteData) - 8)); | 1068 arraysize(kWriteData) - 8)); |
1068 message_loop_->RunUntilIdle(); | 1069 base::RunLoop().RunUntilIdle(); |
1069 | 1070 |
1070 ExpectNoSignal(); | 1071 ExpectNoSignal(); |
1071 | 1072 |
1072 DoSSLCloseOpenedNoError(); | 1073 DoSSLCloseOpenedNoError(); |
1073 } | 1074 } |
1074 | 1075 |
1075 TEST_F(ChromeAsyncSocketTest, SSLAsyncWrite) { | 1076 TEST_F(ChromeAsyncSocketTest, SSLAsyncWrite) { |
1076 DoSSLOpenClosed(); | 1077 DoSSLOpenClosed(); |
1077 | 1078 |
1078 async_socket_data_provider_.AddWrite( | 1079 async_socket_data_provider_.AddWrite( |
1079 net::MockWrite(net::ASYNC, kWriteData, 3)); | 1080 net::MockWrite(net::ASYNC, kWriteData, 3)); |
1080 async_socket_data_provider_.AddWrite( | 1081 async_socket_data_provider_.AddWrite( |
1081 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 1082 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
1082 async_socket_data_provider_.AddWrite( | 1083 async_socket_data_provider_.AddWrite( |
1083 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); | 1084 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); |
1084 | 1085 |
1085 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1086 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
1086 message_loop_->RunUntilIdle(); | 1087 base::RunLoop().RunUntilIdle(); |
1087 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 1088 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
1088 message_loop_->RunUntilIdle(); | 1089 base::RunLoop().RunUntilIdle(); |
1089 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 1090 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
1090 arraysize(kWriteData) - 8)); | 1091 arraysize(kWriteData) - 8)); |
1091 message_loop_->RunUntilIdle(); | 1092 base::RunLoop().RunUntilIdle(); |
1092 | 1093 |
1093 ExpectNoSignal(); | 1094 ExpectNoSignal(); |
1094 | 1095 |
1095 DoSSLCloseOpenedNoError(); | 1096 DoSSLCloseOpenedNoError(); |
1096 } | 1097 } |
1097 | 1098 |
1098 } // namespace | 1099 } // namespace |
1099 | 1100 |
1100 } // namespace jingle_glue | 1101 } // namespace jingle_glue |
OLD | NEW |