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" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 chrome_async_socket_->SignalClosed.connect( | 171 chrome_async_socket_->SignalClosed.connect( |
172 this, &ChromeAsyncSocketTest::OnClose); | 172 this, &ChromeAsyncSocketTest::OnClose); |
173 chrome_async_socket_->SignalRead.connect( | 173 chrome_async_socket_->SignalRead.connect( |
174 this, &ChromeAsyncSocketTest::OnRead); | 174 this, &ChromeAsyncSocketTest::OnRead); |
175 chrome_async_socket_->SignalError.connect( | 175 chrome_async_socket_->SignalError.connect( |
176 this, &ChromeAsyncSocketTest::OnError); | 176 this, &ChromeAsyncSocketTest::OnError); |
177 } | 177 } |
178 | 178 |
179 virtual void TearDown() { | 179 virtual void TearDown() { |
180 // Run any tasks that we forgot to pump. | 180 // Run any tasks that we forgot to pump. |
181 message_loop_.RunAllPending(); | 181 message_loop_.RunUntilIdle(); |
182 ExpectClosed(); | 182 ExpectClosed(); |
183 ExpectNoSignal(); | 183 ExpectNoSignal(); |
184 chrome_async_socket_.reset(); | 184 chrome_async_socket_.reset(); |
185 } | 185 } |
186 | 186 |
187 enum Signal { | 187 enum Signal { |
188 SIGNAL_CONNECT, | 188 SIGNAL_CONNECT, |
189 SIGNAL_SSL_CONNECT, | 189 SIGNAL_SSL_CONNECT, |
190 SIGNAL_CLOSE, | 190 SIGNAL_CLOSE, |
191 SIGNAL_READ, | 191 SIGNAL_READ, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 // Open/close utility functions. | 332 // Open/close utility functions. |
333 | 333 |
334 void DoOpenClosed() { | 334 void DoOpenClosed() { |
335 ExpectClosed(); | 335 ExpectClosed(); |
336 async_socket_data_provider_.set_connect_data( | 336 async_socket_data_provider_.set_connect_data( |
337 net::MockConnect(net::SYNCHRONOUS, net::OK)); | 337 net::MockConnect(net::SYNCHRONOUS, net::OK)); |
338 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 338 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
339 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 339 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
340 | 340 |
341 message_loop_.RunAllPending(); | 341 message_loop_.RunUntilIdle(); |
342 // We may not necessarily be open; may have been other events | 342 // We may not necessarily be open; may have been other events |
343 // queued up. | 343 // queued up. |
344 ExpectSignalSocketState( | 344 ExpectSignalSocketState( |
345 SignalSocketState::NoError( | 345 SignalSocketState::NoError( |
346 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 346 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
347 } | 347 } |
348 | 348 |
349 void DoCloseOpened(SignalSocketState expected_signal_socket_state) { | 349 void DoCloseOpened(SignalSocketState expected_signal_socket_state) { |
350 // We may be in an error state, so just compare state(). | 350 // We may be in an error state, so just compare state(). |
351 EXPECT_EQ(ChromeAsyncSocket::STATE_OPEN, chrome_async_socket_->state()); | 351 EXPECT_EQ(ChromeAsyncSocket::STATE_OPEN, chrome_async_socket_->state()); |
352 EXPECT_TRUE(chrome_async_socket_->Close()); | 352 EXPECT_TRUE(chrome_async_socket_->Close()); |
353 ExpectSignalSocketState(expected_signal_socket_state); | 353 ExpectSignalSocketState(expected_signal_socket_state); |
354 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); | 354 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); |
355 } | 355 } |
356 | 356 |
357 void DoCloseOpenedNoError() { | 357 void DoCloseOpenedNoError() { |
358 DoCloseOpened( | 358 DoCloseOpened( |
359 SignalSocketState::NoError( | 359 SignalSocketState::NoError( |
360 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 360 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
361 } | 361 } |
362 | 362 |
363 void DoSSLOpenClosed() { | 363 void DoSSLOpenClosed() { |
364 const char kDummyData[] = "dummy_data"; | 364 const char kDummyData[] = "dummy_data"; |
365 async_socket_data_provider_.AddRead(net::MockRead(kDummyData)); | 365 async_socket_data_provider_.AddRead(net::MockRead(kDummyData)); |
366 DoOpenClosed(); | 366 DoOpenClosed(); |
367 ExpectReadSignal(); | 367 ExpectReadSignal(); |
368 EXPECT_EQ(kDummyData, DrainRead(1)); | 368 EXPECT_EQ(kDummyData, DrainRead(1)); |
369 | 369 |
370 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 370 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
371 message_loop_.RunAllPending(); | 371 message_loop_.RunUntilIdle(); |
372 ExpectSSLConnectSignal(); | 372 ExpectSSLConnectSignal(); |
373 ExpectNoSignal(); | 373 ExpectNoSignal(); |
374 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 374 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
375 } | 375 } |
376 | 376 |
377 void DoSSLCloseOpened(SignalSocketState expected_signal_socket_state) { | 377 void DoSSLCloseOpened(SignalSocketState expected_signal_socket_state) { |
378 // We may be in an error state, so just compare state(). | 378 // We may be in an error state, so just compare state(). |
379 EXPECT_EQ(ChromeAsyncSocket::STATE_TLS_OPEN, | 379 EXPECT_EQ(ChromeAsyncSocket::STATE_TLS_OPEN, |
380 chrome_async_socket_->state()); | 380 chrome_async_socket_->state()); |
381 EXPECT_TRUE(chrome_async_socket_->Close()); | 381 EXPECT_TRUE(chrome_async_socket_->Close()); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 499 |
500 TEST_F(ChromeAsyncSocketTest, ImmediateConnectCloseBeforeRead) { | 500 TEST_F(ChromeAsyncSocketTest, ImmediateConnectCloseBeforeRead) { |
501 DoOpenClosed(); | 501 DoOpenClosed(); |
502 | 502 |
503 EXPECT_TRUE(chrome_async_socket_->Close()); | 503 EXPECT_TRUE(chrome_async_socket_->Close()); |
504 ExpectClosed(); | 504 ExpectClosed(); |
505 ExpectSignalSocketState( | 505 ExpectSignalSocketState( |
506 SignalSocketState::NoError( | 506 SignalSocketState::NoError( |
507 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 507 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
508 | 508 |
509 message_loop_.RunAllPending(); | 509 message_loop_.RunUntilIdle(); |
510 } | 510 } |
511 | 511 |
512 TEST_F(ChromeAsyncSocketTest, HangingConnect) { | 512 TEST_F(ChromeAsyncSocketTest, HangingConnect) { |
513 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 513 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
514 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 514 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
515 ExpectNoSignal(); | 515 ExpectNoSignal(); |
516 | 516 |
517 EXPECT_TRUE(chrome_async_socket_->Close()); | 517 EXPECT_TRUE(chrome_async_socket_->Close()); |
518 ExpectClosed(); | 518 ExpectClosed(); |
519 ExpectSignalSocketState( | 519 ExpectSignalSocketState( |
520 SignalSocketState::NoError( | 520 SignalSocketState::NoError( |
521 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); | 521 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED)); |
522 } | 522 } |
523 | 523 |
524 TEST_F(ChromeAsyncSocketTest, PendingConnect) { | 524 TEST_F(ChromeAsyncSocketTest, PendingConnect) { |
525 async_socket_data_provider_.set_connect_data( | 525 async_socket_data_provider_.set_connect_data( |
526 net::MockConnect(net::ASYNC, net::OK)); | 526 net::MockConnect(net::ASYNC, net::OK)); |
527 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 527 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
528 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); | 528 ExpectNonErrorState(ChromeAsyncSocket::STATE_CONNECTING); |
529 ExpectNoSignal(); | 529 ExpectNoSignal(); |
530 | 530 |
531 message_loop_.RunAllPending(); | 531 message_loop_.RunUntilIdle(); |
532 ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); | 532 ExpectNonErrorState(ChromeAsyncSocket::STATE_OPEN); |
533 ExpectSignalSocketState( | 533 ExpectSignalSocketState( |
534 SignalSocketState::NoError( | 534 SignalSocketState::NoError( |
535 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 535 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
536 ExpectNoSignal(); | 536 ExpectNoSignal(); |
537 | 537 |
538 message_loop_.RunAllPending(); | 538 message_loop_.RunUntilIdle(); |
539 | 539 |
540 DoCloseOpenedNoError(); | 540 DoCloseOpenedNoError(); |
541 } | 541 } |
542 | 542 |
543 // After this no need to test successful pending connect so | 543 // After this no need to test successful pending connect so |
544 // thoroughly. | 544 // thoroughly. |
545 | 545 |
546 TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { | 546 TEST_F(ChromeAsyncSocketTest, PendingConnectCloseBeforeRead) { |
547 async_socket_data_provider_.set_connect_data( | 547 async_socket_data_provider_.set_connect_data( |
548 net::MockConnect(net::ASYNC, net::OK)); | 548 net::MockConnect(net::ASYNC, net::OK)); |
549 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 549 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
550 | 550 |
551 message_loop_.RunAllPending(); | 551 message_loop_.RunUntilIdle(); |
552 ExpectSignalSocketState( | 552 ExpectSignalSocketState( |
553 SignalSocketState::NoError( | 553 SignalSocketState::NoError( |
554 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); | 554 SIGNAL_CONNECT, ChromeAsyncSocket::STATE_OPEN)); |
555 | 555 |
556 DoCloseOpenedNoError(); | 556 DoCloseOpenedNoError(); |
557 | 557 |
558 message_loop_.RunAllPending(); | 558 message_loop_.RunUntilIdle(); |
559 } | 559 } |
560 | 560 |
561 TEST_F(ChromeAsyncSocketTest, PendingConnectError) { | 561 TEST_F(ChromeAsyncSocketTest, PendingConnectError) { |
562 async_socket_data_provider_.set_connect_data( | 562 async_socket_data_provider_.set_connect_data( |
563 net::MockConnect(net::ASYNC, net::ERR_TIMED_OUT)); | 563 net::MockConnect(net::ASYNC, net::ERR_TIMED_OUT)); |
564 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); | 564 EXPECT_TRUE(chrome_async_socket_->Connect(addr_)); |
565 | 565 |
566 message_loop_.RunAllPending(); | 566 message_loop_.RunUntilIdle(); |
567 | 567 |
568 ExpectSignalSocketState( | 568 ExpectSignalSocketState( |
569 SignalSocketState( | 569 SignalSocketState( |
570 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 570 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
571 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 571 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
572 } | 572 } |
573 | 573 |
574 // After this we can assume Connect() and Close() work as expected. | 574 // After this we can assume Connect() and Close() work as expected. |
575 | 575 |
576 TEST_F(ChromeAsyncSocketTest, EmptyRead) { | 576 TEST_F(ChromeAsyncSocketTest, EmptyRead) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 618 |
619 TEST_F(ChromeAsyncSocketTest, Read) { | 619 TEST_F(ChromeAsyncSocketTest, Read) { |
620 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 620 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
621 DoOpenClosed(); | 621 DoOpenClosed(); |
622 | 622 |
623 ExpectReadSignal(); | 623 ExpectReadSignal(); |
624 ExpectNoSignal(); | 624 ExpectNoSignal(); |
625 | 625 |
626 EXPECT_EQ(kReadData, DrainRead(1)); | 626 EXPECT_EQ(kReadData, DrainRead(1)); |
627 | 627 |
628 message_loop_.RunAllPending(); | 628 message_loop_.RunUntilIdle(); |
629 | 629 |
630 DoCloseOpenedNoError(); | 630 DoCloseOpenedNoError(); |
631 } | 631 } |
632 | 632 |
633 TEST_F(ChromeAsyncSocketTest, ReadTwice) { | 633 TEST_F(ChromeAsyncSocketTest, ReadTwice) { |
634 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 634 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
635 DoOpenClosed(); | 635 DoOpenClosed(); |
636 | 636 |
637 ExpectReadSignal(); | 637 ExpectReadSignal(); |
638 ExpectNoSignal(); | 638 ExpectNoSignal(); |
639 | 639 |
640 EXPECT_EQ(kReadData, DrainRead(1)); | 640 EXPECT_EQ(kReadData, DrainRead(1)); |
641 | 641 |
642 message_loop_.RunAllPending(); | 642 message_loop_.RunUntilIdle(); |
643 | 643 |
644 const char kReadData2[] = "mydatatoread2"; | 644 const char kReadData2[] = "mydatatoread2"; |
645 async_socket_data_provider_.AddRead(net::MockRead(kReadData2)); | 645 async_socket_data_provider_.AddRead(net::MockRead(kReadData2)); |
646 | 646 |
647 ExpectReadSignal(); | 647 ExpectReadSignal(); |
648 ExpectNoSignal(); | 648 ExpectNoSignal(); |
649 | 649 |
650 EXPECT_EQ(kReadData2, DrainRead(1)); | 650 EXPECT_EQ(kReadData2, DrainRead(1)); |
651 | 651 |
652 DoCloseOpenedNoError(); | 652 DoCloseOpenedNoError(); |
653 } | 653 } |
654 | 654 |
655 TEST_F(ChromeAsyncSocketTest, ReadError) { | 655 TEST_F(ChromeAsyncSocketTest, ReadError) { |
656 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 656 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
657 DoOpenClosed(); | 657 DoOpenClosed(); |
658 | 658 |
659 ExpectReadSignal(); | 659 ExpectReadSignal(); |
660 ExpectNoSignal(); | 660 ExpectNoSignal(); |
661 | 661 |
662 EXPECT_EQ(kReadData, DrainRead(1)); | 662 EXPECT_EQ(kReadData, DrainRead(1)); |
663 | 663 |
664 message_loop_.RunAllPending(); | 664 message_loop_.RunUntilIdle(); |
665 | 665 |
666 async_socket_data_provider_.AddRead( | 666 async_socket_data_provider_.AddRead( |
667 net::MockRead(net::SYNCHRONOUS, net::ERR_TIMED_OUT)); | 667 net::MockRead(net::SYNCHRONOUS, net::ERR_TIMED_OUT)); |
668 | 668 |
669 ExpectSignalSocketState( | 669 ExpectSignalSocketState( |
670 SignalSocketState( | 670 SignalSocketState( |
671 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 671 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
672 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 672 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
673 } | 673 } |
674 | 674 |
(...skipping 13 matching lines...) Expand all Loading... |
688 | 688 |
689 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 689 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
690 | 690 |
691 ExpectSignalSocketState( | 691 ExpectSignalSocketState( |
692 SignalSocketState::NoError( | 692 SignalSocketState::NoError( |
693 SIGNAL_READ, ChromeAsyncSocket::STATE_OPEN)); | 693 SIGNAL_READ, ChromeAsyncSocket::STATE_OPEN)); |
694 ExpectNoSignal(); | 694 ExpectNoSignal(); |
695 | 695 |
696 EXPECT_EQ(kReadData, DrainRead(1)); | 696 EXPECT_EQ(kReadData, DrainRead(1)); |
697 | 697 |
698 message_loop_.RunAllPending(); | 698 message_loop_.RunUntilIdle(); |
699 | 699 |
700 DoCloseOpenedNoError(); | 700 DoCloseOpenedNoError(); |
701 } | 701 } |
702 | 702 |
703 TEST_F(ChromeAsyncSocketTest, PendingEmptyRead) { | 703 TEST_F(ChromeAsyncSocketTest, PendingEmptyRead) { |
704 DoOpenClosed(); | 704 DoOpenClosed(); |
705 | 705 |
706 ExpectNoSignal(); | 706 ExpectNoSignal(); |
707 | 707 |
708 async_socket_data_provider_.AddRead(net::MockRead("")); | 708 async_socket_data_provider_.AddRead(net::MockRead("")); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 async_socket_data_provider_.AddWrite( | 744 async_socket_data_provider_.AddWrite( |
745 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); | 745 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); |
746 async_socket_data_provider_.AddWrite( | 746 async_socket_data_provider_.AddWrite( |
747 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); | 747 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); |
748 async_socket_data_provider_.AddWrite( | 748 async_socket_data_provider_.AddWrite( |
749 net::MockWrite(net::SYNCHRONOUS, | 749 net::MockWrite(net::SYNCHRONOUS, |
750 kWriteData + 8, arraysize(kWriteData) - 8)); | 750 kWriteData + 8, arraysize(kWriteData) - 8)); |
751 DoOpenClosed(); | 751 DoOpenClosed(); |
752 | 752 |
753 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 753 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
754 message_loop_.RunAllPending(); | 754 message_loop_.RunUntilIdle(); |
755 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 755 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
756 message_loop_.RunAllPending(); | 756 message_loop_.RunUntilIdle(); |
757 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 757 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
758 arraysize(kWriteData) - 8)); | 758 arraysize(kWriteData) - 8)); |
759 message_loop_.RunAllPending(); | 759 message_loop_.RunUntilIdle(); |
760 | 760 |
761 ExpectNoSignal(); | 761 ExpectNoSignal(); |
762 | 762 |
763 DoCloseOpenedNoError(); | 763 DoCloseOpenedNoError(); |
764 } | 764 } |
765 | 765 |
766 TEST_F(ChromeAsyncSocketTest, AsyncWrite) { | 766 TEST_F(ChromeAsyncSocketTest, AsyncWrite) { |
767 DoOpenClosed(); | 767 DoOpenClosed(); |
768 | 768 |
769 async_socket_data_provider_.AddWrite( | 769 async_socket_data_provider_.AddWrite( |
770 net::MockWrite(net::ASYNC, kWriteData, 3)); | 770 net::MockWrite(net::ASYNC, kWriteData, 3)); |
771 async_socket_data_provider_.AddWrite( | 771 async_socket_data_provider_.AddWrite( |
772 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 772 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
773 async_socket_data_provider_.AddWrite( | 773 async_socket_data_provider_.AddWrite( |
774 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); | 774 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); |
775 | 775 |
776 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 776 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
777 message_loop_.RunAllPending(); | 777 message_loop_.RunUntilIdle(); |
778 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 778 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
779 message_loop_.RunAllPending(); | 779 message_loop_.RunUntilIdle(); |
780 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 780 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
781 arraysize(kWriteData) - 8)); | 781 arraysize(kWriteData) - 8)); |
782 message_loop_.RunAllPending(); | 782 message_loop_.RunUntilIdle(); |
783 | 783 |
784 ExpectNoSignal(); | 784 ExpectNoSignal(); |
785 | 785 |
786 DoCloseOpenedNoError(); | 786 DoCloseOpenedNoError(); |
787 } | 787 } |
788 | 788 |
789 TEST_F(ChromeAsyncSocketTest, AsyncWriteError) { | 789 TEST_F(ChromeAsyncSocketTest, AsyncWriteError) { |
790 DoOpenClosed(); | 790 DoOpenClosed(); |
791 | 791 |
792 async_socket_data_provider_.AddWrite( | 792 async_socket_data_provider_.AddWrite( |
793 net::MockWrite(net::ASYNC, kWriteData, 3)); | 793 net::MockWrite(net::ASYNC, kWriteData, 3)); |
794 async_socket_data_provider_.AddWrite( | 794 async_socket_data_provider_.AddWrite( |
795 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 795 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
796 async_socket_data_provider_.AddWrite( | 796 async_socket_data_provider_.AddWrite( |
797 net::MockWrite(net::ASYNC, net::ERR_TIMED_OUT)); | 797 net::MockWrite(net::ASYNC, net::ERR_TIMED_OUT)); |
798 | 798 |
799 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 799 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
800 message_loop_.RunAllPending(); | 800 message_loop_.RunUntilIdle(); |
801 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 801 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
802 message_loop_.RunAllPending(); | 802 message_loop_.RunUntilIdle(); |
803 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 803 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
804 arraysize(kWriteData) - 8)); | 804 arraysize(kWriteData) - 8)); |
805 message_loop_.RunAllPending(); | 805 message_loop_.RunUntilIdle(); |
806 | 806 |
807 ExpectSignalSocketState( | 807 ExpectSignalSocketState( |
808 SignalSocketState( | 808 SignalSocketState( |
809 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 809 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
810 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); | 810 ChromeAsyncSocket::ERROR_WINSOCK, net::ERR_TIMED_OUT)); |
811 } | 811 } |
812 | 812 |
813 TEST_F(ChromeAsyncSocketTest, LargeWrite) { | 813 TEST_F(ChromeAsyncSocketTest, LargeWrite) { |
814 EXPECT_DEBUG_DEATH({ | 814 EXPECT_DEBUG_DEATH({ |
815 DoOpenClosed(); | 815 DoOpenClosed(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 ChromeAsyncSocket::STATE_CLOSED)); | 863 ChromeAsyncSocket::STATE_CLOSED)); |
864 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); | 864 ExpectNonErrorState(ChromeAsyncSocket::STATE_CLOSED); |
865 } | 865 } |
866 | 866 |
867 TEST_F(ChromeAsyncSocketTest, ImmediateSSLConnect) { | 867 TEST_F(ChromeAsyncSocketTest, ImmediateSSLConnect) { |
868 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 868 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
869 DoOpenClosed(); | 869 DoOpenClosed(); |
870 ExpectReadSignal(); | 870 ExpectReadSignal(); |
871 | 871 |
872 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 872 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
873 message_loop_.RunAllPending(); | 873 message_loop_.RunUntilIdle(); |
874 ExpectSSLConnectSignal(); | 874 ExpectSSLConnectSignal(); |
875 ExpectNoSignal(); | 875 ExpectNoSignal(); |
876 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 876 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
877 | 877 |
878 DoSSLCloseOpenedNoError(); | 878 DoSSLCloseOpenedNoError(); |
879 } | 879 } |
880 | 880 |
881 TEST_F(ChromeAsyncSocketTest, DoubleSSLConnect) { | 881 TEST_F(ChromeAsyncSocketTest, DoubleSSLConnect) { |
882 EXPECT_DEBUG_DEATH({ | 882 EXPECT_DEBUG_DEATH({ |
883 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 883 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
884 DoOpenClosed(); | 884 DoOpenClosed(); |
885 ExpectReadSignal(); | 885 ExpectReadSignal(); |
886 | 886 |
887 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 887 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
888 message_loop_.RunAllPending(); | 888 message_loop_.RunUntilIdle(); |
889 ExpectSSLConnectSignal(); | 889 ExpectSSLConnectSignal(); |
890 ExpectNoSignal(); | 890 ExpectNoSignal(); |
891 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 891 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
892 | 892 |
893 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 893 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
894 | 894 |
895 DoSSLCloseOpened( | 895 DoSSLCloseOpened( |
896 SignalSocketState(SIGNAL_CLOSE, | 896 SignalSocketState(SIGNAL_CLOSE, |
897 ChromeAsyncSocket::STATE_CLOSED, | 897 ChromeAsyncSocket::STATE_CLOSED, |
898 ChromeAsyncSocket::ERROR_WRONGSTATE, | 898 ChromeAsyncSocket::ERROR_WRONGSTATE, |
899 net::OK)); | 899 net::OK)); |
900 }, "wrong state"); | 900 }, "wrong state"); |
901 } | 901 } |
902 | 902 |
903 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { | 903 TEST_F(ChromeAsyncSocketTest, FailedSSLConnect) { |
904 ssl_socket_data_provider_.connect = | 904 ssl_socket_data_provider_.connect = |
905 net::MockConnect(net::ASYNC, net::ERR_CERT_COMMON_NAME_INVALID), | 905 net::MockConnect(net::ASYNC, net::ERR_CERT_COMMON_NAME_INVALID), |
906 | 906 |
907 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 907 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
908 DoOpenClosed(); | 908 DoOpenClosed(); |
909 ExpectReadSignal(); | 909 ExpectReadSignal(); |
910 | 910 |
911 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 911 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
912 message_loop_.RunAllPending(); | 912 message_loop_.RunUntilIdle(); |
913 ExpectSignalSocketState( | 913 ExpectSignalSocketState( |
914 SignalSocketState( | 914 SignalSocketState( |
915 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, | 915 SIGNAL_CLOSE, ChromeAsyncSocket::STATE_CLOSED, |
916 ChromeAsyncSocket::ERROR_WINSOCK, | 916 ChromeAsyncSocket::ERROR_WINSOCK, |
917 net::ERR_CERT_COMMON_NAME_INVALID)); | 917 net::ERR_CERT_COMMON_NAME_INVALID)); |
918 | 918 |
919 EXPECT_TRUE(chrome_async_socket_->Close()); | 919 EXPECT_TRUE(chrome_async_socket_->Close()); |
920 ExpectClosed(); | 920 ExpectClosed(); |
921 } | 921 } |
922 | 922 |
923 TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) { | 923 TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) { |
924 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 924 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
925 DoOpenClosed(); | 925 DoOpenClosed(); |
926 ExpectReadSignal(); | 926 ExpectReadSignal(); |
927 EXPECT_EQ(kReadData, DrainRead(1)); | 927 EXPECT_EQ(kReadData, DrainRead(1)); |
928 | 928 |
929 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); | 929 EXPECT_TRUE(chrome_async_socket_->StartTls("fakedomain.com")); |
930 ExpectNoSignal(); | 930 ExpectNoSignal(); |
931 | 931 |
932 // Shouldn't do anything. | 932 // Shouldn't do anything. |
933 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 933 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
934 | 934 |
935 char buf[4096]; | 935 char buf[4096]; |
936 size_t len_read = 10000U; | 936 size_t len_read = 10000U; |
937 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); | 937 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); |
938 EXPECT_EQ(0U, len_read); | 938 EXPECT_EQ(0U, len_read); |
939 | 939 |
940 message_loop_.RunAllPending(); | 940 message_loop_.RunUntilIdle(); |
941 ExpectSSLConnectSignal(); | 941 ExpectSSLConnectSignal(); |
942 ExpectSSLReadSignal(); | 942 ExpectSSLReadSignal(); |
943 ExpectNoSignal(); | 943 ExpectNoSignal(); |
944 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); | 944 ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN); |
945 | 945 |
946 len_read = 10000U; | 946 len_read = 10000U; |
947 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); | 947 EXPECT_TRUE(chrome_async_socket_->Read(buf, sizeof(buf), &len_read)); |
948 EXPECT_EQ(kReadData, std::string(buf, len_read)); | 948 EXPECT_EQ(kReadData, std::string(buf, len_read)); |
949 | 949 |
950 DoSSLCloseOpenedNoError(); | 950 DoSSLCloseOpenedNoError(); |
(...skipping 10 matching lines...) Expand all Loading... |
961 | 961 |
962 async_socket_data_provider_.AddWrite( | 962 async_socket_data_provider_.AddWrite( |
963 net::MockWrite(net::ASYNC, kWriteData, 3)); | 963 net::MockWrite(net::ASYNC, kWriteData, 3)); |
964 | 964 |
965 // Shouldn't do anything. | 965 // Shouldn't do anything. |
966 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 966 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
967 | 967 |
968 // TODO(akalin): Figure out how to test that the write happens | 968 // TODO(akalin): Figure out how to test that the write happens |
969 // *after* the SSL connect. | 969 // *after* the SSL connect. |
970 | 970 |
971 message_loop_.RunAllPending(); | 971 message_loop_.RunUntilIdle(); |
972 ExpectSSLConnectSignal(); | 972 ExpectSSLConnectSignal(); |
973 ExpectNoSignal(); | 973 ExpectNoSignal(); |
974 | 974 |
975 message_loop_.RunAllPending(); | 975 message_loop_.RunUntilIdle(); |
976 | 976 |
977 DoSSLCloseOpenedNoError(); | 977 DoSSLCloseOpenedNoError(); |
978 } | 978 } |
979 | 979 |
980 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPendingRead) { | 980 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPendingRead) { |
981 EXPECT_DEBUG_DEATH({ | 981 EXPECT_DEBUG_DEATH({ |
982 DoOpenClosed(); | 982 DoOpenClosed(); |
983 | 983 |
984 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 984 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
985 | 985 |
986 DoCloseOpened( | 986 DoCloseOpened( |
987 SignalSocketState(SIGNAL_CLOSE, | 987 SignalSocketState(SIGNAL_CLOSE, |
988 ChromeAsyncSocket::STATE_CLOSED, | 988 ChromeAsyncSocket::STATE_CLOSED, |
989 ChromeAsyncSocket::ERROR_WRONGSTATE, | 989 ChromeAsyncSocket::ERROR_WRONGSTATE, |
990 net::OK)); | 990 net::OK)); |
991 }, "wrong state"); | 991 }, "wrong state"); |
992 } | 992 } |
993 | 993 |
994 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPostedWrite) { | 994 TEST_F(ChromeAsyncSocketTest, SSLConnectDuringPostedWrite) { |
995 EXPECT_DEBUG_DEATH({ | 995 EXPECT_DEBUG_DEATH({ |
996 DoOpenClosed(); | 996 DoOpenClosed(); |
997 | 997 |
998 async_socket_data_provider_.AddWrite( | 998 async_socket_data_provider_.AddWrite( |
999 net::MockWrite(net::ASYNC, kWriteData, 3)); | 999 net::MockWrite(net::ASYNC, kWriteData, 3)); |
1000 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1000 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
1001 | 1001 |
1002 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); | 1002 EXPECT_FALSE(chrome_async_socket_->StartTls("fakedomain.com")); |
1003 | 1003 |
1004 message_loop_.RunAllPending(); | 1004 message_loop_.RunUntilIdle(); |
1005 | 1005 |
1006 DoCloseOpened( | 1006 DoCloseOpened( |
1007 SignalSocketState(SIGNAL_CLOSE, | 1007 SignalSocketState(SIGNAL_CLOSE, |
1008 ChromeAsyncSocket::STATE_CLOSED, | 1008 ChromeAsyncSocket::STATE_CLOSED, |
1009 ChromeAsyncSocket::ERROR_WRONGSTATE, | 1009 ChromeAsyncSocket::ERROR_WRONGSTATE, |
1010 net::OK)); | 1010 net::OK)); |
1011 }, "wrong state"); | 1011 }, "wrong state"); |
1012 } | 1012 } |
1013 | 1013 |
1014 // After this we can assume SSL connect works as expected. | 1014 // After this we can assume SSL connect works as expected. |
1015 | 1015 |
1016 TEST_F(ChromeAsyncSocketTest, SSLRead) { | 1016 TEST_F(ChromeAsyncSocketTest, SSLRead) { |
1017 DoSSLOpenClosed(); | 1017 DoSSLOpenClosed(); |
1018 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); | 1018 async_socket_data_provider_.AddRead(net::MockRead(kReadData)); |
1019 message_loop_.RunAllPending(); | 1019 message_loop_.RunUntilIdle(); |
1020 | 1020 |
1021 ExpectSSLReadSignal(); | 1021 ExpectSSLReadSignal(); |
1022 ExpectNoSignal(); | 1022 ExpectNoSignal(); |
1023 | 1023 |
1024 EXPECT_EQ(kReadData, DrainRead(1)); | 1024 EXPECT_EQ(kReadData, DrainRead(1)); |
1025 | 1025 |
1026 message_loop_.RunAllPending(); | 1026 message_loop_.RunUntilIdle(); |
1027 | 1027 |
1028 DoSSLCloseOpenedNoError(); | 1028 DoSSLCloseOpenedNoError(); |
1029 } | 1029 } |
1030 | 1030 |
1031 TEST_F(ChromeAsyncSocketTest, SSLSyncWrite) { | 1031 TEST_F(ChromeAsyncSocketTest, SSLSyncWrite) { |
1032 async_socket_data_provider_.AddWrite( | 1032 async_socket_data_provider_.AddWrite( |
1033 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); | 1033 net::MockWrite(net::SYNCHRONOUS, kWriteData, 3)); |
1034 async_socket_data_provider_.AddWrite( | 1034 async_socket_data_provider_.AddWrite( |
1035 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); | 1035 net::MockWrite(net::SYNCHRONOUS, kWriteData + 3, 5)); |
1036 async_socket_data_provider_.AddWrite( | 1036 async_socket_data_provider_.AddWrite( |
1037 net::MockWrite(net::SYNCHRONOUS, | 1037 net::MockWrite(net::SYNCHRONOUS, |
1038 kWriteData + 8, arraysize(kWriteData) - 8)); | 1038 kWriteData + 8, arraysize(kWriteData) - 8)); |
1039 DoSSLOpenClosed(); | 1039 DoSSLOpenClosed(); |
1040 | 1040 |
1041 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1041 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
1042 message_loop_.RunAllPending(); | 1042 message_loop_.RunUntilIdle(); |
1043 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 1043 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
1044 message_loop_.RunAllPending(); | 1044 message_loop_.RunUntilIdle(); |
1045 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 1045 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
1046 arraysize(kWriteData) - 8)); | 1046 arraysize(kWriteData) - 8)); |
1047 message_loop_.RunAllPending(); | 1047 message_loop_.RunUntilIdle(); |
1048 | 1048 |
1049 ExpectNoSignal(); | 1049 ExpectNoSignal(); |
1050 | 1050 |
1051 DoSSLCloseOpenedNoError(); | 1051 DoSSLCloseOpenedNoError(); |
1052 } | 1052 } |
1053 | 1053 |
1054 TEST_F(ChromeAsyncSocketTest, SSLAsyncWrite) { | 1054 TEST_F(ChromeAsyncSocketTest, SSLAsyncWrite) { |
1055 DoSSLOpenClosed(); | 1055 DoSSLOpenClosed(); |
1056 | 1056 |
1057 async_socket_data_provider_.AddWrite( | 1057 async_socket_data_provider_.AddWrite( |
1058 net::MockWrite(net::ASYNC, kWriteData, 3)); | 1058 net::MockWrite(net::ASYNC, kWriteData, 3)); |
1059 async_socket_data_provider_.AddWrite( | 1059 async_socket_data_provider_.AddWrite( |
1060 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); | 1060 net::MockWrite(net::ASYNC, kWriteData + 3, 5)); |
1061 async_socket_data_provider_.AddWrite( | 1061 async_socket_data_provider_.AddWrite( |
1062 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); | 1062 net::MockWrite(net::ASYNC, kWriteData + 8, arraysize(kWriteData) - 8)); |
1063 | 1063 |
1064 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); | 1064 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData, 3)); |
1065 message_loop_.RunAllPending(); | 1065 message_loop_.RunUntilIdle(); |
1066 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); | 1066 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 3, 5)); |
1067 message_loop_.RunAllPending(); | 1067 message_loop_.RunUntilIdle(); |
1068 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, | 1068 EXPECT_TRUE(chrome_async_socket_->Write(kWriteData + 8, |
1069 arraysize(kWriteData) - 8)); | 1069 arraysize(kWriteData) - 8)); |
1070 message_loop_.RunAllPending(); | 1070 message_loop_.RunUntilIdle(); |
1071 | 1071 |
1072 ExpectNoSignal(); | 1072 ExpectNoSignal(); |
1073 | 1073 |
1074 DoSSLCloseOpenedNoError(); | 1074 DoSSLCloseOpenedNoError(); |
1075 } | 1075 } |
1076 | 1076 |
1077 } // namespace | 1077 } // namespace |
1078 | 1078 |
1079 } // namespace jingle_glue | 1079 } // namespace jingle_glue |
OLD | NEW |