Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: net/spdy/spdy_network_transaction_unittest.cc

Issue 2852029: Revert "Streams send a Rst frame upon being closed by client. Some minor editorial fixes." (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_network_transaction.h ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "net/spdy/spdy_network_transaction.h" 5 #include "net/spdy/spdy_network_transaction.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/ref_counted.h" 8 #include "base/ref_counted.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/completion_callback.h" 10 #include "net/base/completion_callback.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 const HttpRequestInfo& CreateGetRequest() { 500 const HttpRequestInfo& CreateGetRequest() {
501 if (!google_get_request_initialized_) { 501 if (!google_get_request_initialized_) {
502 google_get_request_.method = "GET"; 502 google_get_request_.method = "GET";
503 google_get_request_.url = GURL("http://www.google.com/"); 503 google_get_request_.url = GURL("http://www.google.com/");
504 google_get_request_.load_flags = 0; 504 google_get_request_.load_flags = 0;
505 google_get_request_initialized_ = true; 505 google_get_request_initialized_ = true;
506 } 506 }
507 return google_get_request_; 507 return google_get_request_;
508 } 508 }
509 509
510 SpdyStream* GetSpdyStream(SpdyNetworkTransaction* trans) {
511 return trans->stream_->stream();
512 }
513
514 private: 510 private:
515 bool google_get_request_initialized_; 511 bool google_get_request_initialized_;
516 HttpRequestInfo google_get_request_; 512 HttpRequestInfo google_get_request_;
517 }; 513 };
518 514
519 //----------------------------------------------------------------------------- 515 //-----------------------------------------------------------------------------
520 516
521 // Verify SpdyNetworkTransaction constructor. 517 // Verify SpdyNetworkTransaction constructor.
522 TEST_F(SpdyNetworkTransactionTest, Constructor) { 518 TEST_F(SpdyNetworkTransactionTest, Constructor) {
523 SessionDependencies session_deps; 519 SessionDependencies session_deps;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 }; 674 };
679 675
680 scoped_refptr<DelayedSocketData> data( 676 scoped_refptr<DelayedSocketData> data(
681 new DelayedSocketData(1, reads, arraysize(reads), NULL, 0)); 677 new DelayedSocketData(1, reads, arraysize(reads), NULL, 0));
682 TransactionHelperResult out = TransactionHelper(CreateGetRequest(), 678 TransactionHelperResult out = TransactionHelper(CreateGetRequest(),
683 data.get(), 679 data.get(),
684 BoundNetLog()); 680 BoundNetLog());
685 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); 681 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv);
686 } 682 }
687 683
688 class CloseStreamCallback : public CallbackRunner< Tuple1<int> > {
689 public:
690 explicit CloseStreamCallback(SpdyStream* stream)
691 : stream_(stream) {}
692
693 // This callback should occur immediately after the SpdyStream has been
694 // closed. We check that the stream has been marked half closed from the
695 // client side.
696 virtual void RunWithParams(const Tuple1<int>& params) {
697 EXPECT_TRUE(stream_->half_closed_client_side());
698 }
699
700 private:
701 const SpdyStream* stream_;
702 };
703
704 // Test that spdy_session marks a stream as half closed immediately upon closing
705 // the stream.
706 TEST_F(SpdyNetworkTransactionTest, StreamHalfClosedClientSide) {
707 MockWrite writes[] = {
708 MockWrite(true, reinterpret_cast<const char*>(kGetSyn),
709 arraysize(kGetSyn), 1),
710 };
711
712 MockRead reads[] = {
713 MockRead(true, reinterpret_cast<const char*>(kGetSynReply),
714 arraysize(kGetSynReply), 2),
715 MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame),
716 arraysize(kGetBodyFrame), 3),
717 MockRead(true, 0, 0, 4), // EOF
718 };
719
720 HttpRequestInfo request;
721 request.method = "GET";
722 request.url = GURL("http://www.google.com/");
723 request.load_flags = 0;
724
725 // We disable SSL for this test.
726 SpdySession::SetSSLMode(false);
727
728 SessionDependencies session_deps;
729 scoped_ptr<SpdyNetworkTransaction> trans(
730 new SpdyNetworkTransaction(CreateSession(&session_deps)));
731 scoped_refptr<OrderedSocketData> data(
732 new OrderedSocketData(reads, arraysize(reads),
733 writes, arraysize(writes)));
734 session_deps.socket_factory.AddSocketDataProvider(data);
735
736 // Start the transaction with basic parameters.
737 TestCompletionCallback callback;
738 int rv = trans->Start(&request, &callback, BoundNetLog());
739 EXPECT_EQ(ERR_IO_PENDING, rv);
740 rv = callback.WaitForResult();
741
742 SpdyStream* stream = GetSpdyStream(trans.get());
743
744 // Setup a user callback which will check that the half closed flag is marked
745 // immediately after the stream is closed.
746 CloseStreamCallback callback2(stream);
747 const int kSize = 3000;
748 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
749 rv = trans->Read(buf, kSize, &callback2);
750
751 // Finish running rest of tasks.
752 MessageLoop::current()->RunAllPending();
753 }
754
755 // Test that the transaction doesn't crash when we get two replies on the same 684 // Test that the transaction doesn't crash when we get two replies on the same
756 // stream ID. See http://crbug.com/45639. 685 // stream ID. See http://crbug.com/45639.
757 TEST_F(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { 686 TEST_F(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) {
758 SessionDependencies session_deps; 687 SessionDependencies session_deps;
759 HttpNetworkSession* session = CreateSession(&session_deps); 688 HttpNetworkSession* session = CreateSession(&session_deps);
760 689
761 // We disable SSL for this test. 690 // We disable SSL for this test.
762 SpdySession::SetSSLMode(false); 691 SpdySession::SetSSLMode(false);
763 692
764 MockWrite writes[] = { 693 MockWrite writes[] = {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 TestCompletionCallback callback; 762 TestCompletionCallback callback;
834 763
835 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); 764 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog());
836 EXPECT_EQ(ERR_IO_PENDING, rv); 765 EXPECT_EQ(ERR_IO_PENDING, rv);
837 trans.reset(); // Cancel the transaction. 766 trans.reset(); // Cancel the transaction.
838 767
839 // Flush the MessageLoop while the SessionDependencies (in particular, the 768 // Flush the MessageLoop while the SessionDependencies (in particular, the
840 // MockClientSocketFactory) are still alive. 769 // MockClientSocketFactory) are still alive.
841 MessageLoop::current()->RunAllPending(); 770 MessageLoop::current()->RunAllPending();
842 } 771 }
843 // The client upon cancellation tries to send a RST_STREAM frame. The mock
844 // socket causes the TCP write to return zero. This test checks that the client
845 // tries to queue up the RST_STREAM frame again.
846 TEST_F(SpdyNetworkTransactionTest, SocketWriteReturnsZero) {
847 MockWrite writes[] = {
848 MockWrite(true, reinterpret_cast<const char*>(kGetSyn),
849 arraysize(kGetSyn), 1),
850 MockWrite(true, 0, 0, 3),
851 MockWrite(true, reinterpret_cast<const char*>(kGetRst),
852 arraysize(kGetRst), 4),
853 };
854
855 MockRead reads[] = {
856 MockRead(true, reinterpret_cast<const char*>(kGetSynReply),
857 arraysize(kGetSynReply), 2),
858 MockRead(true, 0, 0, 5) // EOF
859 };
860
861 HttpRequestInfo request;
862 request.method = "GET";
863 request.url = GURL("http://www.google.com/");
864 request.load_flags = 0;
865
866 // We disable SSL for this test.
867 SpdySession::SetSSLMode(false);
868
869 SessionDependencies session_deps;
870 scoped_ptr<SpdyNetworkTransaction> trans(
871 new SpdyNetworkTransaction(CreateSession(&session_deps)));
872 scoped_refptr<OrderedSocketData> data(
873 new OrderedSocketData(reads, arraysize(reads),
874 writes, arraysize(writes)));
875 session_deps.socket_factory.AddSocketDataProvider(data);
876
877 TestCompletionCallback callback;
878
879 int rv = trans->Start(&request, &callback, BoundNetLog());
880 EXPECT_EQ(ERR_IO_PENDING, rv);
881 rv = callback.WaitForResult();
882 trans.reset(); // Cancel the transaction.
883
884 // Finish running rest of tasks.
885 MessageLoop::current()->RunAllPending();
886 EXPECT_TRUE(data->at_write_eof()) << "Write count: " << data->write_count()
887 << ". Write index: " << data->write_index() << ".";
888 }
889
890
891 // Verify that the client sends a Rst Frame upon cancelling the stream.
892 TEST_F(SpdyNetworkTransactionTest, CancelledTransactionSendRst) {
893 MockWrite writes[] = {
894 MockWrite(true, reinterpret_cast<const char*>(kGetSyn),
895 arraysize(kGetSyn), 1),
896 MockWrite(true, reinterpret_cast<const char*>(kGetRst),
897 arraysize(kGetRst), 3),
898 };
899
900 MockRead reads[] = {
901 MockRead(true, reinterpret_cast<const char*>(kGetSynReply),
902 arraysize(kGetSynReply), 2),
903 MockRead(true, 0, 0, 4) // EOF
904 };
905
906 HttpRequestInfo request;
907 request.method = "GET";
908 request.url = GURL("http://www.google.com/");
909 request.load_flags = 0;
910
911 // We disable SSL for this test.
912 SpdySession::SetSSLMode(false);
913
914 SessionDependencies session_deps;
915 scoped_ptr<SpdyNetworkTransaction> trans(
916 new SpdyNetworkTransaction(CreateSession(&session_deps)));
917 scoped_refptr<OrderedSocketData> data(
918 new OrderedSocketData(reads, arraysize(reads),
919 writes, arraysize(writes)));
920 session_deps.socket_factory.AddSocketDataProvider(data);
921
922 TestCompletionCallback callback;
923
924 int rv = trans->Start(&request, &callback, BoundNetLog());
925 EXPECT_EQ(ERR_IO_PENDING, rv);
926 rv = callback.WaitForResult();
927 trans.reset(); // Cancel the transaction.
928
929 // Finish running rest of tasks.
930 MessageLoop::current()->RunAllPending();
931 EXPECT_TRUE(data->at_write_eof()) << "Write count: " << data->write_count()
932 << ". Write index: " << data->write_index() << ".";
933 }
934 772
935 class DeleteSessionCallback : public CallbackRunner< Tuple1<int> > { 773 class DeleteSessionCallback : public CallbackRunner< Tuple1<int> > {
936 public: 774 public:
937 explicit DeleteSessionCallback(SpdyNetworkTransaction* trans1) : 775 explicit DeleteSessionCallback(SpdyNetworkTransaction* trans1) :
938 trans(trans1) {} 776 trans(trans1) {}
939 777
940 // We kill the transaction, which deletes the session and stream. However, the 778 // We kill the transaction, which deletes the session and stream. However, the
941 // memory is still accessible, so we also have to zero out the memory of the 779 // memory is still accessible, so we also have to zero out the memory of the
942 // stream. This is not a well defined operation, and can cause failures. 780 // stream. This is not a well defined operation, and can cause failures.
943 virtual void RunWithParams(const Tuple1<int>& params) { 781 virtual void RunWithParams(const Tuple1<int>& params) {
(...skipping 24 matching lines...) Expand all
968 806
969 HttpRequestInfo request; 807 HttpRequestInfo request;
970 request.method = "GET"; 808 request.method = "GET";
971 request.url = GURL("http://www.google.com/"); 809 request.url = GURL("http://www.google.com/");
972 request.load_flags = 0; 810 request.load_flags = 0;
973 811
974 // We disable SSL for this test. 812 // We disable SSL for this test.
975 SpdySession::SetSSLMode(false); 813 SpdySession::SetSSLMode(false);
976 814
977 SessionDependencies session_deps; 815 SessionDependencies session_deps;
978 SpdyNetworkTransaction* trans = 816 SpdyNetworkTransaction * trans =
979 new SpdyNetworkTransaction(CreateSession(&session_deps)); 817 new SpdyNetworkTransaction(CreateSession(&session_deps));
980 scoped_refptr<OrderedSocketData> data( 818 scoped_refptr<OrderedSocketData> data(
981 new OrderedSocketData(reads, arraysize(reads), 819 new OrderedSocketData(reads, arraysize(reads),
982 writes, arraysize(writes))); 820 writes, arraysize(writes)));
983 session_deps.socket_factory.AddSocketDataProvider(data); 821 session_deps.socket_factory.AddSocketDataProvider(data);
984 822
985 // Start the transaction with basic parameters. 823 // Start the transaction with basic parameters.
986 TestCompletionCallback callback; 824 TestCompletionCallback callback;
987 int rv = trans->Start(&request, &callback, BoundNetLog()); 825 int rv = trans->Start(&request, &callback, BoundNetLog());
988 EXPECT_EQ(ERR_IO_PENDING, rv); 826 EXPECT_EQ(ERR_IO_PENDING, rv);
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 EXPECT_TRUE(response->was_fetched_via_spdy); 2508 EXPECT_TRUE(response->was_fetched_via_spdy);
2671 out.rv = ReadTransaction(trans.get(), &out.response_data); 2509 out.rv = ReadTransaction(trans.get(), &out.response_data);
2672 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); 2510 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv);
2673 2511
2674 // Verify that we consumed all test data. 2512 // Verify that we consumed all test data.
2675 EXPECT_TRUE(data->at_read_eof()); 2513 EXPECT_TRUE(data->at_read_eof());
2676 EXPECT_TRUE(data->at_write_eof()); 2514 EXPECT_TRUE(data->at_write_eof());
2677 } 2515 }
2678 2516
2679 } // namespace net 2517 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction.h ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698