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

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

Issue 1126763002: Revert of Convert SpdyNetworkTransactionTest to SequencedSocketData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « no previous file | no next file » | 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) 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 void FinishDefaultTestWithoutVerification() { 261 void FinishDefaultTestWithoutVerification() {
262 output_.rv = callback_.WaitForResult(); 262 output_.rv = callback_.WaitForResult();
263 if (output_.rv != OK) 263 if (output_.rv != OK)
264 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); 264 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED);
265 } 265 }
266 266
267 // Most tests will want to call this function. In particular, the MockReads 267 // Most tests will want to call this function. In particular, the MockReads
268 // should end with an empty read, and that read needs to be processed to 268 // should end with an empty read, and that read needs to be processed to
269 // ensure proper deletion of the spdy_session_pool. 269 // ensure proper deletion of the spdy_session_pool.
270 void VerifyDataConsumed() { 270 void VerifyDataConsumed() {
271 for (const SocketDataProvider* provider : data_vector_) { 271 for (DataVector::iterator it = data_vector_.begin();
272 EXPECT_TRUE(provider->AllReadDataConsumed()); 272 it != data_vector_.end(); ++it) {
273 EXPECT_TRUE(provider->AllWriteDataConsumed()); 273 EXPECT_TRUE((*it)->AllReadDataConsumed())
274 << "Read count: " << (*it)->read_count()
275 << " Read index: " << (*it)->read_index();
276 EXPECT_TRUE((*it)->AllWriteDataConsumed())
277 << "Write count: " << (*it)->write_count()
278 << " Write index: " << (*it)->write_index();
274 } 279 }
275 } 280 }
276 281
277 // Occasionally a test will expect to error out before certain reads are 282 // Occasionally a test will expect to error out before certain reads are
278 // processed. In that case we want to explicitly ensure that the reads were 283 // processed. In that case we want to explicitly ensure that the reads were
279 // not processed. 284 // not processed.
280 void VerifyDataNotConsumed() { 285 void VerifyDataNotConsumed() {
281 for (const SocketDataProvider* provider : data_vector_) { 286 for (DataVector::iterator it = data_vector_.begin();
282 EXPECT_FALSE(provider->AllReadDataConsumed()); 287 it != data_vector_.end(); ++it) {
283 EXPECT_FALSE(provider->AllWriteDataConsumed()); 288 EXPECT_TRUE(!(*it)->AllReadDataConsumed())
289 << "Read count: " << (*it)->read_count()
290 << " Read index: " << (*it)->read_index();
291 EXPECT_TRUE(!(*it)->AllWriteDataConsumed())
292 << "Write count: " << (*it)->write_count()
293 << " Write index: " << (*it)->write_index();
284 } 294 }
285 } 295 }
286 296
287 void RunToCompletion(SocketDataProvider* data) { 297 void RunToCompletion(StaticSocketDataProvider* data) {
288 RunPreTestSetup(); 298 RunPreTestSetup();
289 AddData(data); 299 AddData(data);
290 RunDefaultTest(); 300 RunDefaultTest();
291 VerifyDataConsumed(); 301 VerifyDataConsumed();
292 } 302 }
293 303
294 void RunToCompletionWithSSLData( 304 void RunToCompletionWithSSLData(
295 SocketDataProvider* data, 305 StaticSocketDataProvider* data,
296 scoped_ptr<SSLSocketDataProvider> ssl_provider) { 306 scoped_ptr<SSLSocketDataProvider> ssl_provider) {
297 RunPreTestSetup(); 307 RunPreTestSetup();
298 AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass()); 308 AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass());
299 RunDefaultTest(); 309 RunDefaultTest();
300 VerifyDataConsumed(); 310 VerifyDataConsumed();
301 } 311 }
302 312
303 void AddData(SocketDataProvider* data) { 313 void AddData(StaticSocketDataProvider* data) {
304 scoped_ptr<SSLSocketDataProvider> ssl_provider( 314 scoped_ptr<SSLSocketDataProvider> ssl_provider(
305 new SSLSocketDataProvider(ASYNC, OK)); 315 new SSLSocketDataProvider(ASYNC, OK));
306 ssl_provider->cert = 316 ssl_provider->cert =
307 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); 317 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem");
308 AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass()); 318 AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass());
309 } 319 }
310 320
311 void AddDataWithSSLSocketDataProvider( 321 void AddDataWithSSLSocketDataProvider(
312 SocketDataProvider* data, 322 StaticSocketDataProvider* data,
313 scoped_ptr<SSLSocketDataProvider> ssl_provider) { 323 scoped_ptr<SSLSocketDataProvider> ssl_provider) {
314 DCHECK(!deterministic_); 324 DCHECK(!deterministic_);
315 data_vector_.push_back(data); 325 data_vector_.push_back(data);
316 if (ssl_provider->next_proto_status == 326 if (ssl_provider->next_proto_status ==
317 SSLClientSocket::kNextProtoUnsupported) { 327 SSLClientSocket::kNextProtoUnsupported) {
318 ssl_provider->SetNextProto(test_params_.protocol); 328 ssl_provider->SetNextProto(test_params_.protocol);
319 } 329 }
320 330
321 session_deps_->socket_factory->AddSSLSocketDataProvider( 331 session_deps_->socket_factory->AddSSLSocketDataProvider(
322 ssl_provider.get()); 332 ssl_provider.get());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 380 }
371 scoped_ptr<SpdySessionDependencies>& session_deps() { 381 scoped_ptr<SpdySessionDependencies>& session_deps() {
372 return session_deps_; 382 return session_deps_;
373 } 383 }
374 int port() const { return port_; } 384 int port() const { return port_; }
375 SpdyNetworkTransactionTestParams test_params() const { 385 SpdyNetworkTransactionTestParams test_params() const {
376 return test_params_; 386 return test_params_;
377 } 387 }
378 388
379 private: 389 private:
380 typedef std::vector<SocketDataProvider*> DataVector; 390 typedef std::vector<StaticSocketDataProvider*> DataVector;
381 typedef ScopedVector<SSLSocketDataProvider> SSLVector; 391 typedef ScopedVector<SSLSocketDataProvider> SSLVector;
382 typedef ScopedVector<SocketDataProvider> AlternateVector; 392 typedef ScopedVector<StaticSocketDataProvider> AlternateVector;
383 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector; 393 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector;
384 HttpRequestInfo request_; 394 HttpRequestInfo request_;
385 RequestPriority priority_; 395 RequestPriority priority_;
386 scoped_ptr<SpdySessionDependencies> session_deps_; 396 scoped_ptr<SpdySessionDependencies> session_deps_;
387 scoped_refptr<HttpNetworkSession> session_; 397 scoped_refptr<HttpNetworkSession> session_;
388 TransactionHelperResult output_; 398 TransactionHelperResult output_;
389 scoped_ptr<SocketDataProvider> first_transaction_; 399 scoped_ptr<StaticSocketDataProvider> first_transaction_;
390 SSLVector ssl_vector_; 400 SSLVector ssl_vector_;
391 TestCompletionCallback callback_; 401 TestCompletionCallback callback_;
392 scoped_ptr<HttpNetworkTransaction> trans_; 402 scoped_ptr<HttpNetworkTransaction> trans_;
393 scoped_ptr<HttpNetworkTransaction> trans_http_; 403 scoped_ptr<HttpNetworkTransaction> trans_http_;
394 DataVector data_vector_; 404 DataVector data_vector_;
395 AlternateVector alternate_vector_; 405 AlternateVector alternate_vector_;
396 AlternateDeterministicVector alternate_deterministic_vector_; 406 AlternateDeterministicVector alternate_deterministic_vector_;
397 const BoundNetLog log_; 407 const BoundNetLog log_;
398 SpdyNetworkTransactionTestParams test_params_; 408 SpdyNetworkTransactionTestParams test_params_;
399 int port_; 409 int port_;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 chunked_post_request_initialized_ = true; 556 chunked_post_request_initialized_ = true;
547 } 557 }
548 return chunked_post_request_; 558 return chunked_post_request_;
549 } 559 }
550 560
551 // Read the result of a particular transaction, knowing that we've got 561 // Read the result of a particular transaction, knowing that we've got
552 // multiple transactions in the read pipeline; so as we read, we may have 562 // multiple transactions in the read pipeline; so as we read, we may have
553 // to skip over data destined for other transactions while we consume 563 // to skip over data destined for other transactions while we consume
554 // the data for |trans|. 564 // the data for |trans|.
555 int ReadResult(HttpNetworkTransaction* trans, 565 int ReadResult(HttpNetworkTransaction* trans,
556 SocketDataProvider* data, 566 StaticSocketDataProvider* data,
557 std::string* result) { 567 std::string* result) {
558 const int kSize = 3000; 568 const int kSize = 3000;
559 569
560 int bytes_read = 0; 570 int bytes_read = 0;
561 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); 571 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize));
562 TestCompletionCallback callback; 572 TestCompletionCallback callback;
563 while (true) { 573 while (true) {
564 int rv = trans->Read(buf.get(), kSize, callback.callback()); 574 int rv = trans->Read(buf.get(), kSize, callback.callback());
565 if (rv == ERR_IO_PENDING) { 575 if (rv == ERR_IO_PENDING) {
576 // Multiple transactions may be in the data set. Keep pulling off
577 // reads until we complete our callback.
578 while (!callback.have_result()) {
579 data->CompleteRead();
580 base::RunLoop().RunUntilIdle();
581 }
566 rv = callback.WaitForResult(); 582 rv = callback.WaitForResult();
567 } else if (rv <= 0) { 583 } else if (rv <= 0) {
568 break; 584 break;
569 } 585 }
570 result->append(buf->data(), rv); 586 result->append(buf->data(), rv);
571 bytes_read += rv; 587 bytes_read += rv;
572 } 588 }
573 return bytes_read; 589 return bytes_read;
574 } 590 }
575 591
576 void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { 592 void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) {
577 // This lengthy block is reaching into the pool to dig out the active 593 // This lengthy block is reaching into the pool to dig out the active
578 // session. Once we have the session, we verify that the streams are 594 // session. Once we have the session, we verify that the streams are
579 // all closed and not leaked at this point. 595 // all closed and not leaked at this point.
580 const GURL& url = helper.request().url; 596 const GURL& url = helper.request().url;
581 HostPortPair host_port_pair(url.host(), 443); 597 HostPortPair host_port_pair(url.host(), 443);
582 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), 598 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
583 PRIVACY_MODE_DISABLED); 599 PRIVACY_MODE_DISABLED);
584 BoundNetLog log; 600 BoundNetLog log;
585 const scoped_refptr<HttpNetworkSession>& session = helper.session(); 601 const scoped_refptr<HttpNetworkSession>& session = helper.session();
586 base::WeakPtr<SpdySession> spdy_session = 602 base::WeakPtr<SpdySession> spdy_session =
587 session->spdy_session_pool()->FindAvailableSession(key, log); 603 session->spdy_session_pool()->FindAvailableSession(key, log);
588 ASSERT_TRUE(spdy_session != NULL); 604 ASSERT_TRUE(spdy_session != NULL);
589 EXPECT_EQ(0u, spdy_session->num_active_streams()); 605 EXPECT_EQ(0u, spdy_session->num_active_streams());
590 EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); 606 EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams());
591 } 607 }
592 608
593 void RunServerPushTest(SequencedSocketData* data, 609 void RunServerPushTest(OrderedSocketData* data,
594 HttpResponseInfo* response, 610 HttpResponseInfo* response,
595 HttpResponseInfo* push_response, 611 HttpResponseInfo* push_response,
596 const std::string& expected) { 612 const std::string& expected) {
597 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 613 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
598 BoundNetLog(), GetParam(), NULL); 614 BoundNetLog(), GetParam(), NULL);
599 helper.RunPreTestSetup(); 615 helper.RunPreTestSetup();
600 helper.AddData(data); 616 helper.AddData(data);
601 617
602 HttpNetworkTransaction* trans = helper.trans(); 618 HttpNetworkTransaction* trans = helper.trans();
603 619
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 scoped_refptr<HttpNetworkSession> session( 740 scoped_refptr<HttpNetworkSession> session(
725 SpdySessionDependencies::SpdyCreateSession(session_deps.get())); 741 SpdySessionDependencies::SpdyCreateSession(session_deps.get()));
726 scoped_ptr<HttpTransaction> trans( 742 scoped_ptr<HttpTransaction> trans(
727 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 743 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
728 } 744 }
729 745
730 TEST_P(SpdyNetworkTransactionTest, Get) { 746 TEST_P(SpdyNetworkTransactionTest, Get) {
731 // Construct the request. 747 // Construct the request.
732 scoped_ptr<SpdyFrame> req( 748 scoped_ptr<SpdyFrame> req(
733 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 749 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
734 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 750 MockWrite writes[] = { CreateMockWrite(*req) };
735 751
736 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 752 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
737 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 753 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
738 MockRead reads[] = { 754 MockRead reads[] = {
739 CreateMockRead(*resp, 1), 755 CreateMockRead(*resp),
740 CreateMockRead(*body, 2), 756 CreateMockRead(*body),
741 MockRead(ASYNC, 0, 3) // EOF 757 MockRead(ASYNC, 0, 0) // EOF
742 }; 758 };
743 759
744 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 760 DelayedSocketData data(1, reads, arraysize(reads),
761 writes, arraysize(writes));
745 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 762 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
746 BoundNetLog(), GetParam(), NULL); 763 BoundNetLog(), GetParam(), NULL);
747 helper.RunToCompletion(&data); 764 helper.RunToCompletion(&data);
748 TransactionHelperResult out = helper.output(); 765 TransactionHelperResult out = helper.output();
749 EXPECT_EQ(OK, out.rv); 766 EXPECT_EQ(OK, out.rv);
750 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 767 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
751 EXPECT_EQ("hello!", out.response_data); 768 EXPECT_EQ("hello!", out.response_data);
752 } 769 }
753 770
754 TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { 771 TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) {
755 for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; 772 for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY;
756 p = RequestPriority(p + 1)) { 773 p = RequestPriority(p + 1)) {
757 // Construct the request. 774 // Construct the request.
758 scoped_ptr<SpdyFrame> req( 775 scoped_ptr<SpdyFrame> req(
759 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, p, true)); 776 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, p, true));
760 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 777 MockWrite writes[] = { CreateMockWrite(*req) };
761 778
762 SpdyPriority spdy_prio = 0; 779 SpdyPriority spdy_prio = 0;
763 EXPECT_TRUE(GetSpdyPriority(spdy_util_.spdy_version(), *req, &spdy_prio)); 780 EXPECT_TRUE(GetSpdyPriority(spdy_util_.spdy_version(), *req, &spdy_prio));
764 // this repeats the RequestPriority-->SpdyPriority mapping from 781 // this repeats the RequestPriority-->SpdyPriority mapping from
765 // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make 782 // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make
766 // sure it's being done right. 783 // sure it's being done right.
767 if (spdy_util_.spdy_version() < SPDY3) { 784 if (spdy_util_.spdy_version() < SPDY3) {
768 switch (p) { 785 switch (p) {
769 case HIGHEST: 786 case HIGHEST:
770 EXPECT_EQ(0, spdy_prio); 787 EXPECT_EQ(0, spdy_prio);
(...skipping 29 matching lines...) Expand all
800 EXPECT_EQ(4, spdy_prio); 817 EXPECT_EQ(4, spdy_prio);
801 break; 818 break;
802 default: 819 default:
803 FAIL(); 820 FAIL();
804 } 821 }
805 } 822 }
806 823
807 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 824 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
808 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 825 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
809 MockRead reads[] = { 826 MockRead reads[] = {
810 CreateMockRead(*resp, 1), 827 CreateMockRead(*resp),
811 CreateMockRead(*body, 2), 828 CreateMockRead(*body),
812 MockRead(ASYNC, 0, 3) // EOF 829 MockRead(ASYNC, 0, 0) // EOF
813 }; 830 };
814 831
815 SequencedSocketData data(reads, arraysize(reads), writes, 832 DelayedSocketData data(1, reads, arraysize(reads),
816 arraysize(writes)); 833 writes, arraysize(writes));
817 HttpRequestInfo http_req = CreateGetRequest(); 834 HttpRequestInfo http_req = CreateGetRequest();
818 835
819 NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(), 836 NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(),
820 GetParam(), NULL); 837 GetParam(), NULL);
821 helper.RunToCompletion(&data); 838 helper.RunToCompletion(&data);
822 TransactionHelperResult out = helper.output(); 839 TransactionHelperResult out = helper.output();
823 EXPECT_EQ(OK, out.rv); 840 EXPECT_EQ(OK, out.rv);
824 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 841 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
825 EXPECT_EQ("hello!", out.response_data); 842 EXPECT_EQ("hello!", out.response_data);
826 } 843 }
(...skipping 22 matching lines...) Expand all
849 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); 866 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false));
850 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); 867 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true));
851 868
852 scoped_ptr<SpdyFrame> req3( 869 scoped_ptr<SpdyFrame> req3(
853 spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); 870 spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true));
854 scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); 871 scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5));
855 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); 872 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false));
856 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); 873 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true));
857 874
858 MockWrite writes[] = { 875 MockWrite writes[] = {
859 CreateMockWrite(*req, 0), 876 CreateMockWrite(*req),
860 CreateMockWrite(*req2, 3), 877 CreateMockWrite(*req2),
861 CreateMockWrite(*req3, 6), 878 CreateMockWrite(*req3),
862 }; 879 };
863 MockRead reads[] = { 880 MockRead reads[] = {
864 CreateMockRead(*resp, 1), 881 CreateMockRead(*resp, 1),
865 CreateMockRead(*body, 2), 882 CreateMockRead(*body),
866 CreateMockRead(*resp2, 4), 883 CreateMockRead(*resp2, 4),
867 CreateMockRead(*body2, 5), 884 CreateMockRead(*body2),
868 CreateMockRead(*resp3, 7), 885 CreateMockRead(*resp3, 7),
869 CreateMockRead(*body3, 8), 886 CreateMockRead(*body3),
870 887
871 CreateMockRead(*fbody, 9), 888 CreateMockRead(*fbody),
872 CreateMockRead(*fbody2, 10), 889 CreateMockRead(*fbody2),
873 CreateMockRead(*fbody3, 11), 890 CreateMockRead(*fbody3),
874 891
875 MockRead(ASYNC, 0, 12), // EOF 892 MockRead(ASYNC, 0, 0), // EOF
876 }; 893 };
877 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 894 OrderedSocketData data(reads, arraysize(reads),
878 SequencedSocketData data_placeholder(NULL, 0, NULL, 0); 895 writes, arraysize(writes));
896 OrderedSocketData data_placeholder(NULL, 0, NULL, 0);
879 897
880 BoundNetLog log; 898 BoundNetLog log;
881 TransactionHelperResult out; 899 TransactionHelperResult out;
882 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 900 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
883 BoundNetLog(), GetParam(), NULL); 901 BoundNetLog(), GetParam(), NULL);
884 helper.RunPreTestSetup(); 902 helper.RunPreTestSetup();
885 helper.AddData(&data); 903 helper.AddData(&data);
886 // We require placeholder data because three get requests are sent out at 904 // We require placeholder data because three get requests are sent out at
887 // the same time which results in three sockets being connected. The first 905 // the same time which results in three sockets being connected. The first
888 // on will negotiate SPDY and will be used for all requests. 906 // on will negotiate SPDY and will be used for all requests.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); 957 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false));
940 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); 958 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true));
941 959
942 scoped_ptr<SpdyFrame> req2( 960 scoped_ptr<SpdyFrame> req2(
943 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); 961 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true));
944 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); 962 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
945 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); 963 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false));
946 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); 964 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true));
947 965
948 MockWrite writes[] = { 966 MockWrite writes[] = {
949 CreateMockWrite(*req, 0), CreateMockWrite(*req2, 3), 967 CreateMockWrite(*req),
968 CreateMockWrite(*req2),
950 }; 969 };
951 MockRead reads[] = { 970 MockRead reads[] = {
952 CreateMockRead(*resp, 1), 971 CreateMockRead(*resp, 1),
953 CreateMockRead(*body, 2), 972 CreateMockRead(*body),
954 CreateMockRead(*resp2, 4), 973 CreateMockRead(*resp2, 4),
955 CreateMockRead(*body2, 5), 974 CreateMockRead(*body2),
956 CreateMockRead(*fbody, 6), 975 CreateMockRead(*fbody),
957 CreateMockRead(*fbody2, 7), 976 CreateMockRead(*fbody2),
958 MockRead(ASYNC, 0, 8), // EOF 977 MockRead(ASYNC, 0, 0), // EOF
959 }; 978 };
960 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 979 OrderedSocketData data(reads, arraysize(reads),
980 writes, arraysize(writes));
961 981
962 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); 982 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
963 SequencedSocketData data_placeholder(NULL, 0, NULL, 0); 983 OrderedSocketData data_placeholder(NULL, 0, NULL, 0);
964 data_placeholder.set_connect_data(never_finishing_connect); 984 data_placeholder.set_connect_data(never_finishing_connect);
965 985
966 BoundNetLog log; 986 BoundNetLog log;
967 TransactionHelperResult out; 987 TransactionHelperResult out;
968 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 988 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
969 BoundNetLog(), GetParam(), NULL); 989 BoundNetLog(), GetParam(), NULL);
970 helper.RunPreTestSetup(); 990 helper.RunPreTestSetup();
971 helper.AddData(&data); 991 helper.AddData(&data);
972 // We require placeholder data because two requests are sent out at 992 // We require placeholder data because two requests are sent out at
973 // the same time which results in two sockets being connected. The first 993 // the same time which results in two sockets being connected. The first
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); 1044 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false));
1025 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1045 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true));
1026 1046
1027 scoped_ptr<SpdyFrame> req2( 1047 scoped_ptr<SpdyFrame> req2(
1028 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); 1048 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true));
1029 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); 1049 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
1030 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); 1050 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false));
1031 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); 1051 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true));
1032 1052
1033 MockWrite writes[] = { 1053 MockWrite writes[] = {
1034 CreateMockWrite(*req, 0), CreateMockWrite(*req2, 3), 1054 CreateMockWrite(*req),
1055 CreateMockWrite(*req2),
1035 }; 1056 };
1036 MockRead reads[] = { 1057 MockRead reads[] = {
1037 CreateMockRead(*resp, 1), 1058 CreateMockRead(*resp, 1),
1038 CreateMockRead(*body, 2), 1059 CreateMockRead(*body),
1039 CreateMockRead(*resp2, 4), 1060 CreateMockRead(*resp2, 4),
1040 CreateMockRead(*body2, 5), 1061 CreateMockRead(*body2),
1041 CreateMockRead(*fbody, 6), 1062 CreateMockRead(*fbody),
1042 CreateMockRead(*fbody2, 7), 1063 CreateMockRead(*fbody2),
1043 MockRead(ASYNC, 0, 8), // EOF 1064 MockRead(ASYNC, 0, 0), // EOF
1044 }; 1065 };
1045 SequencedSocketData preconnect_data(reads, arraysize(reads), writes, 1066 OrderedSocketData preconnect_data(reads, arraysize(reads),
1046 arraysize(writes)); 1067 writes, arraysize(writes));
1047 1068
1048 MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); 1069 MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING);
1049 1070
1050 SequencedSocketData data_placeholder(NULL, 0, NULL, 0); 1071 OrderedSocketData data_placeholder(NULL, 0, NULL, 0);
1051 data_placeholder.set_connect_data(never_finishing_connect); 1072 data_placeholder.set_connect_data(never_finishing_connect);
1052 1073
1053 BoundNetLog log; 1074 BoundNetLog log;
1054 TransactionHelperResult out; 1075 TransactionHelperResult out;
1055 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 1076 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
1056 BoundNetLog(), GetParam(), NULL); 1077 BoundNetLog(), GetParam(), NULL);
1057 helper.RunPreTestSetup(); 1078 helper.RunPreTestSetup();
1058 helper.AddData(&preconnect_data); 1079 helper.AddData(&preconnect_data);
1059 // We require placeholder data because 3 connections are attempted (first is 1080 // We require placeholder data because 3 connections are attempted (first is
1060 // the preconnect, 2nd and 3rd are the never finished connections. 1081 // the preconnect, 2nd and 3rd are the never finished connections.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 1163
1143 SettingsMap settings; 1164 SettingsMap settings;
1144 const uint32 max_concurrent_streams = 1; 1165 const uint32 max_concurrent_streams = 1;
1145 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = 1166 settings[SETTINGS_MAX_CONCURRENT_STREAMS] =
1146 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); 1167 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams);
1147 scoped_ptr<SpdyFrame> settings_frame( 1168 scoped_ptr<SpdyFrame> settings_frame(
1148 spdy_util_.ConstructSpdySettings(settings)); 1169 spdy_util_.ConstructSpdySettings(settings));
1149 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); 1170 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck());
1150 1171
1151 MockWrite writes[] = { 1172 MockWrite writes[] = {
1152 CreateMockWrite(*req, 0), 1173 CreateMockWrite(*req),
1153 CreateMockWrite(*settings_ack, 5), 1174 CreateMockWrite(*settings_ack, 2),
1154 CreateMockWrite(*req2, 6), 1175 CreateMockWrite(*req2),
1155 CreateMockWrite(*req3, 10), 1176 CreateMockWrite(*req3),
1156 }; 1177 };
1157 1178
1158 MockRead reads[] = { 1179 MockRead reads[] = {
1159 CreateMockRead(*settings_frame, 1), 1180 CreateMockRead(*settings_frame, 1),
1160 CreateMockRead(*resp, 2), 1181 CreateMockRead(*resp),
1161 CreateMockRead(*body, 3), 1182 CreateMockRead(*body),
1162 CreateMockRead(*fbody, 4), 1183 CreateMockRead(*fbody),
1163 CreateMockRead(*resp2, 7), 1184 CreateMockRead(*resp2, 8),
1164 CreateMockRead(*body2, 8), 1185 CreateMockRead(*body2),
1165 CreateMockRead(*fbody2, 9), 1186 CreateMockRead(*fbody2),
1166 CreateMockRead(*resp3, 11), 1187 CreateMockRead(*resp3, 13),
1167 CreateMockRead(*body3, 12), 1188 CreateMockRead(*body3),
1168 CreateMockRead(*fbody3, 13), 1189 CreateMockRead(*fbody3),
1169 1190
1170 MockRead(ASYNC, 0, 14), // EOF 1191 MockRead(ASYNC, 0, 0), // EOF
1171 }; 1192 };
1172 1193
1173 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1194 OrderedSocketData data(reads, arraysize(reads),
1195 writes, arraysize(writes));
1174 1196
1175 BoundNetLog log; 1197 BoundNetLog log;
1176 TransactionHelperResult out; 1198 TransactionHelperResult out;
1177 { 1199 {
1178 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 1200 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
1179 BoundNetLog(), GetParam(), NULL); 1201 BoundNetLog(), GetParam(), NULL);
1180 helper.RunPreTestSetup(); 1202 helper.RunPreTestSetup();
1181 helper.AddData(&data); 1203 helper.AddData(&data);
1182 scoped_ptr<HttpNetworkTransaction> trans1( 1204 scoped_ptr<HttpNetworkTransaction> trans1(
1183 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 1205 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
(...skipping 16 matching lines...) Expand all
1200 // frame. 1222 // frame.
1201 out.rv = callback1.WaitForResult(); 1223 out.rv = callback1.WaitForResult();
1202 ASSERT_EQ(OK, out.rv); 1224 ASSERT_EQ(OK, out.rv);
1203 1225
1204 out.rv = trans2->Start(&httpreq2, callback2.callback(), log); 1226 out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
1205 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1227 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1206 out.rv = trans3->Start(&httpreq3, callback3.callback(), log); 1228 out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
1207 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1229 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1208 out.rv = callback2.WaitForResult(); 1230 out.rv = callback2.WaitForResult();
1209 ASSERT_EQ(OK, out.rv); 1231 ASSERT_EQ(OK, out.rv);
1232 EXPECT_EQ(7U, data.read_index()); // i.e. the third trans was queued
1210 1233
1211 out.rv = callback3.WaitForResult(); 1234 out.rv = callback3.WaitForResult();
1212 ASSERT_EQ(OK, out.rv); 1235 ASSERT_EQ(OK, out.rv);
1213 1236
1214 const HttpResponseInfo* response1 = trans1->GetResponseInfo(); 1237 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
1215 ASSERT_TRUE(response1 != NULL); 1238 ASSERT_TRUE(response1 != NULL);
1216 EXPECT_TRUE(response1->headers.get() != NULL); 1239 EXPECT_TRUE(response1->headers.get() != NULL);
1217 EXPECT_TRUE(response1->was_fetched_via_spdy); 1240 EXPECT_TRUE(response1->was_fetched_via_spdy);
1218 out.status_line = response1->headers->GetStatusLine(); 1241 out.status_line = response1->headers->GetStatusLine();
1219 out.response_info = *response1; 1242 out.response_info = *response1;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(7, false)); 1296 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(7, false));
1274 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(7, true)); 1297 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(7, true));
1275 1298
1276 SettingsMap settings; 1299 SettingsMap settings;
1277 const uint32 max_concurrent_streams = 1; 1300 const uint32 max_concurrent_streams = 1;
1278 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = 1301 settings[SETTINGS_MAX_CONCURRENT_STREAMS] =
1279 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); 1302 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams);
1280 scoped_ptr<SpdyFrame> settings_frame( 1303 scoped_ptr<SpdyFrame> settings_frame(
1281 spdy_util_.ConstructSpdySettings(settings)); 1304 spdy_util_.ConstructSpdySettings(settings));
1282 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); 1305 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck());
1283 MockWrite writes[] = {
1284 CreateMockWrite(*req, 0),
1285 CreateMockWrite(*settings_ack, 5),
1286 // By making these synchronous, it guarantees that they are not *started*
1287 // before their sequence number, which in turn verifies that only a single
1288 // request is in-flight at a time.
1289 CreateMockWrite(*req2, 6, SYNCHRONOUS),
1290 CreateMockWrite(*req4, 10, SYNCHRONOUS),
1291 CreateMockWrite(*req3, 13, SYNCHRONOUS),
1292 };
1293 MockRead reads[] = {
1294 CreateMockRead(*settings_frame, 1),
1295 CreateMockRead(*resp, 2),
1296 CreateMockRead(*body, 3),
1297 CreateMockRead(*fbody, 4),
1298 CreateMockRead(*resp2, 7),
1299 CreateMockRead(*body2, 8),
1300 CreateMockRead(*fbody2, 9),
1301 CreateMockRead(*resp4, 11),
1302 CreateMockRead(*fbody4, 12),
1303 CreateMockRead(*resp3, 14),
1304 CreateMockRead(*body3, 15),
1305 CreateMockRead(*fbody3, 16),
1306
1307 MockRead(ASYNC, 0, 17), // EOF
1308 };
1309 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1310 BoundNetLog log;
1311 TransactionHelperResult out;
1312 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
1313 BoundNetLog(), GetParam(), NULL);
1314 helper.RunPreTestSetup();
1315 helper.AddData(&data);
1316
1317 scoped_ptr<HttpNetworkTransaction> trans1(
1318 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1319 scoped_ptr<HttpNetworkTransaction> trans2(
1320 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1321 scoped_ptr<HttpNetworkTransaction> trans3(
1322 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1323 scoped_ptr<HttpNetworkTransaction> trans4(
1324 new HttpNetworkTransaction(HIGHEST, helper.session().get()));
1325
1326 TestCompletionCallback callback1;
1327 TestCompletionCallback callback2;
1328 TestCompletionCallback callback3;
1329 TestCompletionCallback callback4;
1330
1331 HttpRequestInfo httpreq1 = CreateGetRequest();
1332 HttpRequestInfo httpreq2 = CreateGetRequest();
1333 HttpRequestInfo httpreq3 = CreateGetRequest();
1334 HttpRequestInfo httpreq4 = CreateGetRequest();
1335
1336 out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
1337 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1338 // Run transaction 1 through quickly to force a read of our SETTINGS frame.
1339 out.rv = callback1.WaitForResult();
1340 ASSERT_EQ(OK, out.rv);
1341
1342 out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
1343 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1344 out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
1345 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1346 out.rv = trans4->Start(&httpreq4, callback4.callback(), log);
1347 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1348
1349 out.rv = callback2.WaitForResult();
1350 ASSERT_EQ(OK, out.rv);
1351
1352 out.rv = callback3.WaitForResult();
1353 ASSERT_EQ(OK, out.rv);
1354
1355 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
1356 EXPECT_TRUE(response1->headers.get() != NULL);
1357 EXPECT_TRUE(response1->was_fetched_via_spdy);
1358 out.status_line = response1->headers->GetStatusLine();
1359 out.response_info = *response1;
1360 out.rv = ReadTransaction(trans1.get(), &out.response_data);
1361 EXPECT_EQ(OK, out.rv);
1362 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1363 EXPECT_EQ("hello!hello!", out.response_data);
1364
1365 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
1366 out.status_line = response2->headers->GetStatusLine();
1367 out.response_info = *response2;
1368 out.rv = ReadTransaction(trans2.get(), &out.response_data);
1369 EXPECT_EQ(OK, out.rv);
1370 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1371 EXPECT_EQ("hello!hello!", out.response_data);
1372
1373 // notice: response3 gets two hellos, response4 gets one
1374 // hello, so we know dequeuing priority was respected.
1375 const HttpResponseInfo* response3 = trans3->GetResponseInfo();
1376 out.status_line = response3->headers->GetStatusLine();
1377 out.response_info = *response3;
1378 out.rv = ReadTransaction(trans3.get(), &out.response_data);
1379 EXPECT_EQ(OK, out.rv);
1380 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1381 EXPECT_EQ("hello!hello!", out.response_data);
1382
1383 out.rv = callback4.WaitForResult();
1384 EXPECT_EQ(OK, out.rv);
1385 const HttpResponseInfo* response4 = trans4->GetResponseInfo();
1386 out.status_line = response4->headers->GetStatusLine();
1387 out.response_info = *response4;
1388 out.rv = ReadTransaction(trans4.get(), &out.response_data);
1389 EXPECT_EQ(OK, out.rv);
1390 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1391 EXPECT_EQ("hello!", out.response_data);
1392 helper.VerifyDataConsumed();
1393 EXPECT_EQ(OK, out.rv);
1394 }
1395
1396 // Similar to ThreeGetsMaxConcurrrent above, however, this test
1397 // deletes a session in the middle of the transaction to ensure
1398 // that we properly remove pendingcreatestream objects from
1399 // the spdy_session
1400 TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) {
1401 // Construct the request.
1402 scoped_ptr<SpdyFrame> req(
1403 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
1404 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
1405 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false));
1406 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true));
1407
1408 scoped_ptr<SpdyFrame> req2(
1409 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true));
1410 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
1411 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false));
1412 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true));
1413
1414 SettingsMap settings;
1415 const uint32 max_concurrent_streams = 1;
1416 settings[SETTINGS_MAX_CONCURRENT_STREAMS] =
1417 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams);
1418 scoped_ptr<SpdyFrame> settings_frame(
1419 spdy_util_.ConstructSpdySettings(settings));
1420 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck());
1421 1306
1422 MockWrite writes[] = { 1307 MockWrite writes[] = { CreateMockWrite(*req),
1423 CreateMockWrite(*req, 0), 1308 CreateMockWrite(*settings_ack, 2),
1424 CreateMockWrite(*settings_ack, 5), 1309 CreateMockWrite(*req2),
1425 CreateMockWrite(*req2, 6), 1310 CreateMockWrite(*req4),
1311 CreateMockWrite(*req3),
1426 }; 1312 };
1427 MockRead reads[] = { 1313 MockRead reads[] = {
1428 CreateMockRead(*settings_frame, 1), 1314 CreateMockRead(*settings_frame, 1),
1429 CreateMockRead(*resp, 2), 1315 CreateMockRead(*resp),
1430 CreateMockRead(*body, 3), 1316 CreateMockRead(*body),
1431 CreateMockRead(*fbody, 4), 1317 CreateMockRead(*fbody),
1432 CreateMockRead(*resp2, 7), 1318 CreateMockRead(*resp2, 8),
1433 CreateMockRead(*body2, 8), 1319 CreateMockRead(*body2),
1434 CreateMockRead(*fbody2, 9), 1320 CreateMockRead(*fbody2),
1435 MockRead(ASYNC, 0, 10), // EOF 1321 CreateMockRead(*resp4, 14),
1322 CreateMockRead(*fbody4),
1323 CreateMockRead(*resp3, 17),
1324 CreateMockRead(*body3),
1325 CreateMockRead(*fbody3),
1326
1327 MockRead(ASYNC, 0, 0), // EOF
1436 }; 1328 };
1437 1329
1438 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1330 OrderedSocketData data(reads, arraysize(reads),
1331 writes, arraysize(writes));
1439 1332
1440 BoundNetLog log; 1333 BoundNetLog log;
1441 TransactionHelperResult out; 1334 TransactionHelperResult out;
1442 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 1335 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
1443 BoundNetLog(), GetParam(), NULL); 1336 BoundNetLog(), GetParam(), NULL);
1444 helper.RunPreTestSetup(); 1337 helper.RunPreTestSetup();
1445 helper.AddData(&data); 1338 helper.AddData(&data);
1446 scoped_ptr<HttpNetworkTransaction> trans1( 1339 scoped_ptr<HttpNetworkTransaction> trans1(
1447 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 1340 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1448 scoped_ptr<HttpNetworkTransaction> trans2( 1341 scoped_ptr<HttpNetworkTransaction> trans2(
1449 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 1342 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1450 scoped_ptr<HttpNetworkTransaction> trans3( 1343 scoped_ptr<HttpNetworkTransaction> trans3(
1451 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); 1344 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1345 scoped_ptr<HttpNetworkTransaction> trans4(
1346 new HttpNetworkTransaction(HIGHEST, helper.session().get()));
1347
1348 TestCompletionCallback callback1;
1349 TestCompletionCallback callback2;
1350 TestCompletionCallback callback3;
1351 TestCompletionCallback callback4;
1352
1353 HttpRequestInfo httpreq1 = CreateGetRequest();
1354 HttpRequestInfo httpreq2 = CreateGetRequest();
1355 HttpRequestInfo httpreq3 = CreateGetRequest();
1356 HttpRequestInfo httpreq4 = CreateGetRequest();
1357
1358 out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
1359 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1360 // Run transaction 1 through quickly to force a read of our SETTINGS frame.
1361 out.rv = callback1.WaitForResult();
1362 ASSERT_EQ(OK, out.rv);
1363
1364 out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
1365 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1366 out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
1367 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1368 out.rv = trans4->Start(&httpreq4, callback4.callback(), log);
1369 ASSERT_EQ(ERR_IO_PENDING, out.rv);
1370
1371 out.rv = callback2.WaitForResult();
1372 ASSERT_EQ(OK, out.rv);
1373 EXPECT_EQ(data.read_index(), 7U); // i.e. the third & fourth trans queued
1374
1375 out.rv = callback3.WaitForResult();
1376 ASSERT_EQ(OK, out.rv);
1377
1378 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
1379 EXPECT_TRUE(response1->headers.get() != NULL);
1380 EXPECT_TRUE(response1->was_fetched_via_spdy);
1381 out.status_line = response1->headers->GetStatusLine();
1382 out.response_info = *response1;
1383 out.rv = ReadTransaction(trans1.get(), &out.response_data);
1384 EXPECT_EQ(OK, out.rv);
1385 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1386 EXPECT_EQ("hello!hello!", out.response_data);
1387
1388 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
1389 out.status_line = response2->headers->GetStatusLine();
1390 out.response_info = *response2;
1391 out.rv = ReadTransaction(trans2.get(), &out.response_data);
1392 EXPECT_EQ(OK, out.rv);
1393 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1394 EXPECT_EQ("hello!hello!", out.response_data);
1395
1396 // notice: response3 gets two hellos, response4 gets one
1397 // hello, so we know dequeuing priority was respected.
1398 const HttpResponseInfo* response3 = trans3->GetResponseInfo();
1399 out.status_line = response3->headers->GetStatusLine();
1400 out.response_info = *response3;
1401 out.rv = ReadTransaction(trans3.get(), &out.response_data);
1402 EXPECT_EQ(OK, out.rv);
1403 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1404 EXPECT_EQ("hello!hello!", out.response_data);
1405
1406 out.rv = callback4.WaitForResult();
1407 EXPECT_EQ(OK, out.rv);
1408 const HttpResponseInfo* response4 = trans4->GetResponseInfo();
1409 out.status_line = response4->headers->GetStatusLine();
1410 out.response_info = *response4;
1411 out.rv = ReadTransaction(trans4.get(), &out.response_data);
1412 EXPECT_EQ(OK, out.rv);
1413 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1414 EXPECT_EQ("hello!", out.response_data);
1415 helper.VerifyDataConsumed();
1416 EXPECT_EQ(OK, out.rv);
1417 }
1418
1419 // Similar to ThreeGetsMaxConcurrrent above, however, this test
1420 // deletes a session in the middle of the transaction to insure
1421 // that we properly remove pendingcreatestream objects from
1422 // the spdy_session
1423 TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) {
1424 // Construct the request.
1425 scoped_ptr<SpdyFrame> req(
1426 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
1427 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
1428 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false));
1429 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true));
1430
1431 scoped_ptr<SpdyFrame> req2(
1432 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true));
1433 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
1434 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false));
1435 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true));
1436
1437 SettingsMap settings;
1438 const uint32 max_concurrent_streams = 1;
1439 settings[SETTINGS_MAX_CONCURRENT_STREAMS] =
1440 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams);
1441 scoped_ptr<SpdyFrame> settings_frame(
1442 spdy_util_.ConstructSpdySettings(settings));
1443 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck());
1444
1445 MockWrite writes[] = {
1446 CreateMockWrite(*req),
1447 CreateMockWrite(*settings_ack, 2),
1448 CreateMockWrite(*req2),
1449 };
1450 MockRead reads[] = {
1451 CreateMockRead(*settings_frame, 1),
1452 CreateMockRead(*resp),
1453 CreateMockRead(*body),
1454 CreateMockRead(*fbody),
1455 CreateMockRead(*resp2, 8),
1456 CreateMockRead(*body2),
1457 CreateMockRead(*fbody2),
1458 MockRead(ASYNC, 0, 0), // EOF
1459 };
1460
1461 OrderedSocketData data(reads, arraysize(reads),
1462 writes, arraysize(writes));
1463
1464 BoundNetLog log;
1465 TransactionHelperResult out;
1466 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
1467 BoundNetLog(), GetParam(), NULL);
1468 helper.RunPreTestSetup();
1469 helper.AddData(&data);
1470 scoped_ptr<HttpNetworkTransaction> trans1(
1471 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1472 scoped_ptr<HttpNetworkTransaction> trans2(
1473 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1474 scoped_ptr<HttpNetworkTransaction> trans3(
1475 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get()));
1452 1476
1453 TestCompletionCallback callback1; 1477 TestCompletionCallback callback1;
1454 TestCompletionCallback callback2; 1478 TestCompletionCallback callback2;
1455 TestCompletionCallback callback3; 1479 TestCompletionCallback callback3;
1456 1480
1457 HttpRequestInfo httpreq1 = CreateGetRequest(); 1481 HttpRequestInfo httpreq1 = CreateGetRequest();
1458 HttpRequestInfo httpreq2 = CreateGetRequest(); 1482 HttpRequestInfo httpreq2 = CreateGetRequest();
1459 HttpRequestInfo httpreq3 = CreateGetRequest(); 1483 HttpRequestInfo httpreq3 = CreateGetRequest();
1460 1484
1461 out.rv = trans1->Start(&httpreq1, callback1.callback(), log); 1485 out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
1462 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1486 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1463 // Run transaction 1 through quickly to force a read of our SETTINGS frame. 1487 // Run transaction 1 through quickly to force a read of our SETTINGS frame.
1464 out.rv = callback1.WaitForResult(); 1488 out.rv = callback1.WaitForResult();
1465 ASSERT_EQ(OK, out.rv); 1489 ASSERT_EQ(OK, out.rv);
1466 1490
1467 out.rv = trans2->Start(&httpreq2, callback2.callback(), log); 1491 out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
1468 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1492 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1469 out.rv = trans3->Start(&httpreq3, callback3.callback(), log); 1493 out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
1470 delete trans3.release(); 1494 delete trans3.release();
1471 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1495 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1472 out.rv = callback2.WaitForResult(); 1496 out.rv = callback2.WaitForResult();
1473 ASSERT_EQ(OK, out.rv); 1497 ASSERT_EQ(OK, out.rv);
1474 1498
1499 EXPECT_EQ(8U, data.read_index());
1500
1475 const HttpResponseInfo* response1 = trans1->GetResponseInfo(); 1501 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
1476 ASSERT_TRUE(response1 != NULL); 1502 ASSERT_TRUE(response1 != NULL);
1477 EXPECT_TRUE(response1->headers.get() != NULL); 1503 EXPECT_TRUE(response1->headers.get() != NULL);
1478 EXPECT_TRUE(response1->was_fetched_via_spdy); 1504 EXPECT_TRUE(response1->was_fetched_via_spdy);
1479 out.status_line = response1->headers->GetStatusLine(); 1505 out.status_line = response1->headers->GetStatusLine();
1480 out.response_info = *response1; 1506 out.response_info = *response1;
1481 out.rv = ReadTransaction(trans1.get(), &out.response_data); 1507 out.rv = ReadTransaction(trans1.get(), &out.response_data);
1482 EXPECT_EQ(OK, out.rv); 1508 EXPECT_EQ(OK, out.rv);
1483 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1509 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1484 EXPECT_EQ("hello!hello!", out.response_data); 1510 EXPECT_EQ("hello!hello!", out.response_data);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 1568
1543 SettingsMap settings; 1569 SettingsMap settings;
1544 const uint32 max_concurrent_streams = 1; 1570 const uint32 max_concurrent_streams = 1;
1545 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = 1571 settings[SETTINGS_MAX_CONCURRENT_STREAMS] =
1546 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); 1572 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams);
1547 scoped_ptr<SpdyFrame> settings_frame( 1573 scoped_ptr<SpdyFrame> settings_frame(
1548 spdy_util_.ConstructSpdySettings(settings)); 1574 spdy_util_.ConstructSpdySettings(settings));
1549 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); 1575 scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck());
1550 1576
1551 MockWrite writes[] = { 1577 MockWrite writes[] = {
1552 CreateMockWrite(*req, 0), 1578 CreateMockWrite(*req),
1553 CreateMockWrite(*settings_ack, 5), 1579 CreateMockWrite(*settings_ack, 2),
1554 CreateMockWrite(*req2, 6), 1580 CreateMockWrite(*req2),
1555 }; 1581 };
1556 MockRead reads[] = { 1582 MockRead reads[] = {
1557 CreateMockRead(*settings_frame, 1), 1583 CreateMockRead(*settings_frame, 1),
1558 CreateMockRead(*resp, 2), 1584 CreateMockRead(*resp),
1559 CreateMockRead(*body, 3), 1585 CreateMockRead(*body),
1560 CreateMockRead(*fin_body, 4), 1586 CreateMockRead(*fin_body),
1561 CreateMockRead(*resp2, 7), 1587 CreateMockRead(*resp2, 8),
1562 MockRead(ASYNC, ERR_CONNECTION_RESET, 8), // Abort! 1588 MockRead(ASYNC, ERR_CONNECTION_RESET, 0), // Abort!
1563 }; 1589 };
1564 1590
1565 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1591 OrderedSocketData data(reads, arraysize(reads),
1566 SequencedSocketData data_placeholder(NULL, 0, NULL, 0); 1592 writes, arraysize(writes));
1593 OrderedSocketData data_placeholder(NULL, 0, NULL, 0);
1567 1594
1568 BoundNetLog log; 1595 BoundNetLog log;
1569 TransactionHelperResult out; 1596 TransactionHelperResult out;
1570 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 1597 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
1571 BoundNetLog(), GetParam(), NULL); 1598 BoundNetLog(), GetParam(), NULL);
1572 helper.RunPreTestSetup(); 1599 helper.RunPreTestSetup();
1573 helper.AddData(&data); 1600 helper.AddData(&data);
1574 // We require placeholder data because three get requests are sent out, so 1601 // We require placeholder data because three get requests are sent out, so
1575 // there needs to be three sets of SSL connection data. 1602 // there needs to be three sets of SSL connection data.
1576 helper.AddData(&data_placeholder); 1603 helper.AddData(&data_placeholder);
(...skipping 17 matching lines...) Expand all
1594 out.rv = callback1.WaitForResult(); 1621 out.rv = callback1.WaitForResult();
1595 ASSERT_EQ(OK, out.rv); 1622 ASSERT_EQ(OK, out.rv);
1596 1623
1597 out.rv = trans2.Start(&httpreq2, callback2.callback(), log); 1624 out.rv = trans2.Start(&httpreq2, callback2.callback(), log);
1598 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1625 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1599 out.rv = trans3->Start(&httpreq3, callback3.callback(), log); 1626 out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
1600 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1627 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1601 out.rv = callback3.WaitForResult(); 1628 out.rv = callback3.WaitForResult();
1602 ASSERT_EQ(ERR_ABORTED, out.rv); 1629 ASSERT_EQ(ERR_ABORTED, out.rv);
1603 1630
1631 EXPECT_EQ(6U, data.read_index());
1632
1604 const HttpResponseInfo* response1 = trans1.GetResponseInfo(); 1633 const HttpResponseInfo* response1 = trans1.GetResponseInfo();
1605 ASSERT_TRUE(response1 != NULL); 1634 ASSERT_TRUE(response1 != NULL);
1606 EXPECT_TRUE(response1->headers.get() != NULL); 1635 EXPECT_TRUE(response1->headers.get() != NULL);
1607 EXPECT_TRUE(response1->was_fetched_via_spdy); 1636 EXPECT_TRUE(response1->was_fetched_via_spdy);
1608 out.status_line = response1->headers->GetStatusLine(); 1637 out.status_line = response1->headers->GetStatusLine();
1609 out.response_info = *response1; 1638 out.response_info = *response1;
1610 out.rv = ReadTransaction(&trans1, &out.response_data); 1639 out.rv = ReadTransaction(&trans1, &out.response_data);
1611 EXPECT_EQ(OK, out.rv); 1640 EXPECT_EQ(OK, out.rv);
1612 1641
1613 const HttpResponseInfo* response2 = trans2.GetResponseInfo(); 1642 const HttpResponseInfo* response2 = trans2.GetResponseInfo();
(...skipping 11 matching lines...) Expand all
1625 // Setup the request 1654 // Setup the request
1626 HttpRequestInfo request; 1655 HttpRequestInfo request;
1627 request.method = "PUT"; 1656 request.method = "PUT";
1628 request.url = GURL(GetDefaultUrl()); 1657 request.url = GURL(GetDefaultUrl());
1629 1658
1630 scoped_ptr<SpdyHeaderBlock> put_headers( 1659 scoped_ptr<SpdyHeaderBlock> put_headers(
1631 spdy_util_.ConstructPutHeaderBlock(GetDefaultUrl(), 0)); 1660 spdy_util_.ConstructPutHeaderBlock(GetDefaultUrl(), 0));
1632 scoped_ptr<SpdyFrame> req( 1661 scoped_ptr<SpdyFrame> req(
1633 spdy_util_.ConstructSpdySyn(1, *put_headers, LOWEST, false, true)); 1662 spdy_util_.ConstructSpdySyn(1, *put_headers, LOWEST, false, true));
1634 MockWrite writes[] = { 1663 MockWrite writes[] = {
1635 CreateMockWrite(*req, 0), 1664 CreateMockWrite(*req),
1636 }; 1665 };
1637 1666
1638 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 1667 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
1639 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1668 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1640 MockRead reads[] = { 1669 MockRead reads[] = {
1641 CreateMockRead(*resp, 1), 1670 CreateMockRead(*resp),
1642 CreateMockRead(*body, 2), 1671 CreateMockRead(*body),
1643 MockRead(ASYNC, 0, 3) // EOF 1672 MockRead(ASYNC, 0, 0) // EOF
1644 }; 1673 };
1645 1674
1646 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1675 DelayedSocketData data(1, reads, arraysize(reads),
1676 writes, arraysize(writes));
1647 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 1677 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
1648 BoundNetLog(), GetParam(), NULL); 1678 BoundNetLog(), GetParam(), NULL);
1649 helper.RunToCompletion(&data); 1679 helper.RunToCompletion(&data);
1650 TransactionHelperResult out = helper.output(); 1680 TransactionHelperResult out = helper.output();
1651 1681
1652 EXPECT_EQ(OK, out.rv); 1682 EXPECT_EQ(OK, out.rv);
1653 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1683 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1654 } 1684 }
1655 1685
1656 // Test that a simple HEAD request works. 1686 // Test that a simple HEAD request works.
1657 TEST_P(SpdyNetworkTransactionTest, Head) { 1687 TEST_P(SpdyNetworkTransactionTest, Head) {
1658 // Setup the request 1688 // Setup the request
1659 HttpRequestInfo request; 1689 HttpRequestInfo request;
1660 request.method = "HEAD"; 1690 request.method = "HEAD";
1661 request.url = GURL(GetDefaultUrl()); 1691 request.url = GURL(GetDefaultUrl());
1662 1692
1663 scoped_ptr<SpdyHeaderBlock> head_headers( 1693 scoped_ptr<SpdyHeaderBlock> head_headers(
1664 spdy_util_.ConstructHeadHeaderBlock(GetDefaultUrl(), 0)); 1694 spdy_util_.ConstructHeadHeaderBlock(GetDefaultUrl(), 0));
1665 scoped_ptr<SpdyFrame> req( 1695 scoped_ptr<SpdyFrame> req(
1666 spdy_util_.ConstructSpdySyn(1, *head_headers, LOWEST, false, true)); 1696 spdy_util_.ConstructSpdySyn(1, *head_headers, LOWEST, false, true));
1667 MockWrite writes[] = { 1697 MockWrite writes[] = {
1668 CreateMockWrite(*req, 0), 1698 CreateMockWrite(*req),
1669 }; 1699 };
1670 1700
1671 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 1701 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
1672 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1702 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1673 MockRead reads[] = { 1703 MockRead reads[] = {
1674 CreateMockRead(*resp, 1), 1704 CreateMockRead(*resp),
1675 CreateMockRead(*body, 2), 1705 CreateMockRead(*body),
1676 MockRead(ASYNC, 0, 3) // EOF 1706 MockRead(ASYNC, 0, 0) // EOF
1677 }; 1707 };
1678 1708
1679 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1709 DelayedSocketData data(1, reads, arraysize(reads),
1710 writes, arraysize(writes));
1680 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 1711 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
1681 BoundNetLog(), GetParam(), NULL); 1712 BoundNetLog(), GetParam(), NULL);
1682 helper.RunToCompletion(&data); 1713 helper.RunToCompletion(&data);
1683 TransactionHelperResult out = helper.output(); 1714 TransactionHelperResult out = helper.output();
1684 1715
1685 EXPECT_EQ(OK, out.rv); 1716 EXPECT_EQ(OK, out.rv);
1686 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1717 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1687 } 1718 }
1688 1719
1689 // Test that a simple POST works. 1720 // Test that a simple POST works.
1690 TEST_P(SpdyNetworkTransactionTest, Post) { 1721 TEST_P(SpdyNetworkTransactionTest, Post) {
1691 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( 1722 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost(
1692 GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); 1723 GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0));
1693 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1724 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1694 MockWrite writes[] = { 1725 MockWrite writes[] = {
1695 CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame 1726 CreateMockWrite(*req),
1727 CreateMockWrite(*body), // POST upload frame
1696 }; 1728 };
1697 1729
1698 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); 1730 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0));
1699 MockRead reads[] = { 1731 MockRead reads[] = {
1700 CreateMockRead(*resp, 2), 1732 CreateMockRead(*resp),
1701 CreateMockRead(*body, 3), 1733 CreateMockRead(*body),
1702 MockRead(ASYNC, 0, 4) // EOF 1734 MockRead(ASYNC, 0, 0) // EOF
1703 }; 1735 };
1704 1736
1705 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1737 DelayedSocketData data(2, reads, arraysize(reads),
1738 writes, arraysize(writes));
1706 NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, 1739 NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY,
1707 BoundNetLog(), GetParam(), NULL); 1740 BoundNetLog(), GetParam(), NULL);
1708 helper.RunToCompletion(&data); 1741 helper.RunToCompletion(&data);
1709 TransactionHelperResult out = helper.output(); 1742 TransactionHelperResult out = helper.output();
1710 EXPECT_EQ(OK, out.rv); 1743 EXPECT_EQ(OK, out.rv);
1711 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1744 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1712 EXPECT_EQ("hello!", out.response_data); 1745 EXPECT_EQ("hello!", out.response_data);
1713 } 1746 }
1714 1747
1715 // Test that a POST with a file works. 1748 // Test that a POST with a file works.
1716 TEST_P(SpdyNetworkTransactionTest, FilePost) { 1749 TEST_P(SpdyNetworkTransactionTest, FilePost) {
1717 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( 1750 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost(
1718 GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); 1751 GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0));
1719 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1752 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1720 MockWrite writes[] = { 1753 MockWrite writes[] = {
1721 CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame 1754 CreateMockWrite(*req),
1755 CreateMockWrite(*body), // POST upload frame
1722 }; 1756 };
1723 1757
1724 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); 1758 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0));
1725 MockRead reads[] = { 1759 MockRead reads[] = {
1726 CreateMockRead(*resp, 2), 1760 CreateMockRead(*resp),
1727 CreateMockRead(*body, 3), 1761 CreateMockRead(*body),
1728 MockRead(ASYNC, 0, 4) // EOF 1762 MockRead(ASYNC, 0, 0) // EOF
1729 }; 1763 };
1730 1764
1731 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1765 DelayedSocketData data(2, reads, arraysize(reads),
1766 writes, arraysize(writes));
1732 NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, 1767 NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY,
1733 BoundNetLog(), GetParam(), NULL); 1768 BoundNetLog(), GetParam(), NULL);
1734 helper.RunToCompletion(&data); 1769 helper.RunToCompletion(&data);
1735 TransactionHelperResult out = helper.output(); 1770 TransactionHelperResult out = helper.output();
1736 EXPECT_EQ(OK, out.rv); 1771 EXPECT_EQ(OK, out.rv);
1737 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1772 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1738 EXPECT_EQ("hello!", out.response_data); 1773 EXPECT_EQ("hello!", out.response_data);
1739 } 1774 }
1740 1775
1741 // Test that a POST with a unreadable file fails. 1776 // Test that a POST with a unreadable file fails.
1742 TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) { 1777 TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) {
1743 MockWrite writes[] = { 1778 MockWrite writes[] = {
1744 MockWrite(ASYNC, 0, 0) // EOF 1779 MockWrite(ASYNC, 0, 0) // EOF
1745 }; 1780 };
1746 MockRead reads[] = { 1781 MockRead reads[] = {
1747 MockRead(ASYNC, 0, 1) // EOF 1782 MockRead(ASYNC, 0, 0) // EOF
1748 }; 1783 };
1749 1784
1750 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1785 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes));
1751 NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), 1786 NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(),
1752 DEFAULT_PRIORITY, 1787 DEFAULT_PRIORITY,
1753 BoundNetLog(), GetParam(), NULL); 1788 BoundNetLog(), GetParam(), NULL);
1754 helper.RunPreTestSetup(); 1789 helper.RunPreTestSetup();
1755 helper.AddData(&data); 1790 helper.AddData(&data);
1756 helper.RunDefaultTest(); 1791 helper.RunDefaultTest();
1757 1792
1758 base::RunLoop().RunUntilIdle(); 1793 base::RunLoop().RunUntilIdle();
1759 helper.VerifyDataNotConsumed(); 1794 helper.VerifyDataNotConsumed();
1760 EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv); 1795 EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv);
1761 } 1796 }
1762 1797
1763 // Test that a complex POST works. 1798 // Test that a complex POST works.
1764 TEST_P(SpdyNetworkTransactionTest, ComplexPost) { 1799 TEST_P(SpdyNetworkTransactionTest, ComplexPost) {
1765 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( 1800 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost(
1766 GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); 1801 GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0));
1767 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1802 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1768 MockWrite writes[] = { 1803 MockWrite writes[] = {
1769 CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame 1804 CreateMockWrite(*req),
1805 CreateMockWrite(*body), // POST upload frame
1770 }; 1806 };
1771 1807
1772 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); 1808 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0));
1773 MockRead reads[] = { 1809 MockRead reads[] = {
1774 CreateMockRead(*resp, 2), 1810 CreateMockRead(*resp),
1775 CreateMockRead(*body, 3), 1811 CreateMockRead(*body),
1776 MockRead(ASYNC, 0, 4) // EOF 1812 MockRead(ASYNC, 0, 0) // EOF
1777 }; 1813 };
1778 1814
1779 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1815 DelayedSocketData data(2, reads, arraysize(reads),
1816 writes, arraysize(writes));
1780 NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), 1817 NormalSpdyTransactionHelper helper(CreateComplexPostRequest(),
1781 DEFAULT_PRIORITY, 1818 DEFAULT_PRIORITY,
1782 BoundNetLog(), GetParam(), NULL); 1819 BoundNetLog(), GetParam(), NULL);
1783 helper.RunToCompletion(&data); 1820 helper.RunToCompletion(&data);
1784 TransactionHelperResult out = helper.output(); 1821 TransactionHelperResult out = helper.output();
1785 EXPECT_EQ(OK, out.rv); 1822 EXPECT_EQ(OK, out.rv);
1786 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1823 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1787 EXPECT_EQ("hello!", out.response_data); 1824 EXPECT_EQ("hello!", out.response_data);
1788 } 1825 }
1789 1826
1790 // Test that a chunked POST works. 1827 // Test that a chunked POST works.
1791 TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { 1828 TEST_P(SpdyNetworkTransactionTest, ChunkedPost) {
1792 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); 1829 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0));
1793 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1830 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1794 MockWrite writes[] = { 1831 MockWrite writes[] = {
1795 CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), 1832 CreateMockWrite(*req),
1833 CreateMockWrite(*body),
1796 }; 1834 };
1797 1835
1798 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); 1836 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0));
1799 MockRead reads[] = { 1837 MockRead reads[] = {
1800 CreateMockRead(*resp, 2), 1838 CreateMockRead(*resp),
1801 CreateMockRead(*body, 3), 1839 CreateMockRead(*body),
1802 MockRead(ASYNC, 0, 4) // EOF 1840 MockRead(ASYNC, 0, 0) // EOF
1803 }; 1841 };
1804 1842
1805 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1843 DelayedSocketData data(2, reads, arraysize(reads),
1844 writes, arraysize(writes));
1806 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), 1845 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(),
1807 DEFAULT_PRIORITY, 1846 DEFAULT_PRIORITY,
1808 BoundNetLog(), GetParam(), NULL); 1847 BoundNetLog(), GetParam(), NULL);
1809 1848
1810 // These chunks get merged into a single frame when being sent. 1849 // These chunks get merged into a single frame when being sent.
1811 const int kFirstChunkSize = kUploadDataSize/2; 1850 const int kFirstChunkSize = kUploadDataSize/2;
1812 upload_chunked_data_stream()->AppendData(kUploadData, kFirstChunkSize, false); 1851 upload_chunked_data_stream()->AppendData(kUploadData, kFirstChunkSize, false);
1813 upload_chunked_data_stream()->AppendData( 1852 upload_chunked_data_stream()->AppendData(
1814 kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); 1853 kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true);
1815 1854
1816 helper.RunToCompletion(&data); 1855 helper.RunToCompletion(&data);
1817 TransactionHelperResult out = helper.output(); 1856 TransactionHelperResult out = helper.output();
1818 EXPECT_EQ(OK, out.rv); 1857 EXPECT_EQ(OK, out.rv);
1819 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1858 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1820 EXPECT_EQ(kUploadData, out.response_data); 1859 EXPECT_EQ(kUploadData, out.response_data);
1821 } 1860 }
1822 1861
1823 // Test that a chunked POST works with chunks appended after transaction starts. 1862 // Test that a chunked POST works with chunks appended after transaction starts.
1824 TEST_P(SpdyNetworkTransactionTest, DelayedChunkedPost) { 1863 TEST_P(SpdyNetworkTransactionTest, DelayedChunkedPost) {
1825 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); 1864 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0));
1826 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); 1865 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false));
1827 scoped_ptr<SpdyFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame(1, false)); 1866 scoped_ptr<SpdyFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame(1, false));
1828 scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1867 scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true));
1829 MockWrite writes[] = { 1868 MockWrite writes[] = {
1830 CreateMockWrite(*req, 0), 1869 CreateMockWrite(*req),
1831 CreateMockWrite(*chunk1, 1), 1870 CreateMockWrite(*chunk1),
1832 CreateMockWrite(*chunk2, 2), 1871 CreateMockWrite(*chunk2),
1833 CreateMockWrite(*chunk3, 3), 1872 CreateMockWrite(*chunk3),
1834 }; 1873 };
1835 1874
1836 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); 1875 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0));
1837 MockRead reads[] = { 1876 MockRead reads[] = {
1838 CreateMockRead(*resp, 4), 1877 CreateMockRead(*resp),
1839 CreateMockRead(*chunk1, 5), 1878 CreateMockRead(*chunk1),
1840 CreateMockRead(*chunk2, 6), 1879 CreateMockRead(*chunk2),
1841 CreateMockRead(*chunk3, 7), 1880 CreateMockRead(*chunk3),
1842 MockRead(ASYNC, 0, 8) // EOF 1881 MockRead(ASYNC, 0, 0) // EOF
1843 }; 1882 };
1844 1883
1845 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1884 DelayedSocketData data(4, reads, arraysize(reads),
1885 writes, arraysize(writes));
1846 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), 1886 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(),
1847 DEFAULT_PRIORITY, 1887 DEFAULT_PRIORITY,
1848 BoundNetLog(), GetParam(), NULL); 1888 BoundNetLog(), GetParam(), NULL);
1849 1889
1850 upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); 1890 upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false);
1851 1891
1852 helper.RunPreTestSetup(); 1892 helper.RunPreTestSetup();
1853 helper.AddData(&data); 1893 helper.AddData(&data);
1854 ASSERT_TRUE(helper.StartDefaultTest()); 1894 ASSERT_TRUE(helper.StartDefaultTest());
1855 1895
(...skipping 27 matching lines...) Expand all
1883 request.upload_data_stream = NULL; 1923 request.upload_data_stream = NULL;
1884 1924
1885 // When request.upload_data_stream is NULL for post, content-length is 1925 // When request.upload_data_stream is NULL for post, content-length is
1886 // expected to be 0. 1926 // expected to be 0.
1887 scoped_ptr<SpdyHeaderBlock> req_block( 1927 scoped_ptr<SpdyHeaderBlock> req_block(
1888 spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), 0)); 1928 spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), 0));
1889 scoped_ptr<SpdyFrame> req( 1929 scoped_ptr<SpdyFrame> req(
1890 spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true)); 1930 spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true));
1891 1931
1892 MockWrite writes[] = { 1932 MockWrite writes[] = {
1893 CreateMockWrite(*req, 0), 1933 CreateMockWrite(*req),
1894 }; 1934 };
1895 1935
1896 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); 1936 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0));
1897 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1937 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1898 MockRead reads[] = { 1938 MockRead reads[] = {
1899 CreateMockRead(*resp, 1), 1939 CreateMockRead(*resp),
1900 CreateMockRead(*body, 2), 1940 CreateMockRead(*body),
1901 MockRead(ASYNC, 0, 3) // EOF 1941 MockRead(ASYNC, 0, 0) // EOF
1902 }; 1942 };
1903 1943
1904 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1944 DelayedSocketData data(1, reads, arraysize(reads),
1945 writes, arraysize(writes));
1905 1946
1906 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 1947 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
1907 BoundNetLog(), GetParam(), NULL); 1948 BoundNetLog(), GetParam(), NULL);
1908 helper.RunToCompletion(&data); 1949 helper.RunToCompletion(&data);
1909 TransactionHelperResult out = helper.output(); 1950 TransactionHelperResult out = helper.output();
1910 EXPECT_EQ(OK, out.rv); 1951 EXPECT_EQ(OK, out.rv);
1911 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1952 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1912 EXPECT_EQ("hello!", out.response_data); 1953 EXPECT_EQ("hello!", out.response_data);
1913 } 1954 }
1914 1955
(...skipping 11 matching lines...) Expand all
1926 request.upload_data_stream = &stream; 1967 request.upload_data_stream = &stream;
1927 1968
1928 const uint64 kContentLength = 0; 1969 const uint64 kContentLength = 0;
1929 1970
1930 scoped_ptr<SpdyHeaderBlock> req_block( 1971 scoped_ptr<SpdyHeaderBlock> req_block(
1931 spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), kContentLength)); 1972 spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), kContentLength));
1932 scoped_ptr<SpdyFrame> req( 1973 scoped_ptr<SpdyFrame> req(
1933 spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true)); 1974 spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true));
1934 1975
1935 MockWrite writes[] = { 1976 MockWrite writes[] = {
1936 CreateMockWrite(*req, 0), 1977 CreateMockWrite(*req),
1937 }; 1978 };
1938 1979
1939 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); 1980 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0));
1940 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 1981 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
1941 MockRead reads[] = { 1982 MockRead reads[] = {
1942 CreateMockRead(*resp, 1), 1983 CreateMockRead(*resp),
1943 CreateMockRead(*body, 2), 1984 CreateMockRead(*body),
1944 MockRead(ASYNC, 0, 3) // EOF 1985 MockRead(ASYNC, 0, 0) // EOF
1945 }; 1986 };
1946 1987
1947 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1988 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes));
1948 1989
1949 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 1990 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
1950 BoundNetLog(), GetParam(), NULL); 1991 BoundNetLog(), GetParam(), NULL);
1951 helper.RunToCompletion(&data); 1992 helper.RunToCompletion(&data);
1952 TransactionHelperResult out = helper.output(); 1993 TransactionHelperResult out = helper.output();
1953 EXPECT_EQ(OK, out.rv); 1994 EXPECT_EQ(OK, out.rv);
1954 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 1995 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
1955 EXPECT_EQ("hello!", out.response_data); 1996 EXPECT_EQ("hello!", out.response_data);
1956 } 1997 }
1957 1998
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 data.SetStop(20); 2081 data.SetStop(20);
2041 data.Run(); 2082 data.Run();
2042 2083
2043 helper.VerifyDataConsumed(); 2084 helper.VerifyDataConsumed();
2044 } 2085 }
2045 2086
2046 // Test that the transaction doesn't crash when we don't have a reply. 2087 // Test that the transaction doesn't crash when we don't have a reply.
2047 TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { 2088 TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) {
2048 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 2089 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
2049 MockRead reads[] = { 2090 MockRead reads[] = {
2050 CreateMockRead(*body, 1), MockRead(ASYNC, 0, 3) // EOF 2091 CreateMockRead(*body),
2092 MockRead(ASYNC, 0, 0) // EOF
2051 }; 2093 };
2052 2094
2053 scoped_ptr<SpdyFrame> req( 2095 DelayedSocketData data(1, reads, arraysize(reads), NULL, 0);
2054 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2055 scoped_ptr<SpdyFrame> rst(
2056 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR));
2057 MockWrite writes[] = {
2058 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2),
2059 };
2060 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
2061 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 2096 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
2062 BoundNetLog(), GetParam(), NULL); 2097 BoundNetLog(), GetParam(), NULL);
2063 helper.RunToCompletion(&data); 2098 helper.RunToCompletion(&data);
2064 TransactionHelperResult out = helper.output(); 2099 TransactionHelperResult out = helper.output();
2065 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 2100 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
2066 } 2101 }
2067 2102
2068 // Test that the transaction doesn't crash when we get two replies on the same 2103 // Test that the transaction doesn't crash when we get two replies on the same
2069 // stream ID. See http://crbug.com/45639. 2104 // stream ID. See http://crbug.com/45639.
2070 TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { 2105 TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) {
2071 scoped_ptr<SpdyFrame> req( 2106 scoped_ptr<SpdyFrame> req(
2072 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2107 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2073 scoped_ptr<SpdyFrame> rst( 2108 scoped_ptr<SpdyFrame> rst(
2074 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); 2109 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR));
2075 MockWrite writes[] = { 2110 MockWrite writes[] = {
2076 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), 2111 CreateMockWrite(*req),
2112 CreateMockWrite(*rst),
2077 }; 2113 };
2078 2114
2079 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2115 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2080 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 2116 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
2081 MockRead reads[] = { 2117 MockRead reads[] = {
2082 CreateMockRead(*resp, 1), 2118 CreateMockRead(*resp),
2083 CreateMockRead(*resp, 2), 2119 CreateMockRead(*resp),
2084 CreateMockRead(*body, 3), 2120 CreateMockRead(*body),
2085 MockRead(ASYNC, 0, 5) // EOF 2121 MockRead(ASYNC, 0, 0) // EOF
2086 }; 2122 };
2087 2123
2088 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2124 DelayedSocketData data(1, reads, arraysize(reads),
2125 writes, arraysize(writes));
2089 2126
2090 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 2127 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
2091 BoundNetLog(), GetParam(), NULL); 2128 BoundNetLog(), GetParam(), NULL);
2092 helper.RunPreTestSetup(); 2129 helper.RunPreTestSetup();
2093 helper.AddData(&data); 2130 helper.AddData(&data);
2094 2131
2095 HttpNetworkTransaction* trans = helper.trans(); 2132 HttpNetworkTransaction* trans = helper.trans();
2096 2133
2097 TestCompletionCallback callback; 2134 TestCompletionCallback callback;
2098 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); 2135 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
(...skipping 12 matching lines...) Expand all
2111 helper.VerifyDataConsumed(); 2148 helper.VerifyDataConsumed();
2112 } 2149 }
2113 2150
2114 TEST_P(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { 2151 TEST_P(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) {
2115 // Construct the request. 2152 // Construct the request.
2116 scoped_ptr<SpdyFrame> req( 2153 scoped_ptr<SpdyFrame> req(
2117 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2154 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2118 scoped_ptr<SpdyFrame> rst( 2155 scoped_ptr<SpdyFrame> rst(
2119 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); 2156 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR));
2120 MockWrite writes[] = { 2157 MockWrite writes[] = {
2121 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), 2158 CreateMockWrite(*req),
2159 CreateMockWrite(*rst),
2122 }; 2160 };
2123 2161
2124 const char* const headers[] = { 2162 const char* const headers[] = {
2125 "transfer-encoding", "chunked" 2163 "transfer-encoding", "chunked"
2126 }; 2164 };
2127 scoped_ptr<SpdyFrame> resp( 2165 scoped_ptr<SpdyFrame> resp(
2128 spdy_util_.ConstructSpdyGetSynReply(headers, 1, 1)); 2166 spdy_util_.ConstructSpdyGetSynReply(headers, 1, 1));
2129 scoped_ptr<SpdyFrame> body( 2167 scoped_ptr<SpdyFrame> body(
2130 spdy_util_.ConstructSpdyBodyFrame(1, true)); 2168 spdy_util_.ConstructSpdyBodyFrame(1, true));
2131 MockRead reads[] = { 2169 MockRead reads[] = {
2132 CreateMockRead(*resp, 1), 2170 CreateMockRead(*resp),
2133 CreateMockRead(*body, 3), 2171 CreateMockRead(*body),
2134 MockRead(ASYNC, 0, 4) // EOF 2172 MockRead(ASYNC, 0, 0) // EOF
2135 }; 2173 };
2136 2174
2137 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2175 DelayedSocketData data(1, reads, arraysize(reads),
2176 writes, arraysize(writes));
2138 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 2177 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
2139 BoundNetLog(), GetParam(), NULL); 2178 BoundNetLog(), GetParam(), NULL);
2140 helper.RunToCompletion(&data); 2179 helper.RunToCompletion(&data);
2141 TransactionHelperResult out = helper.output(); 2180 TransactionHelperResult out = helper.output();
2142 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 2181 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
2143 2182
2144 helper.session()->spdy_session_pool()->CloseAllSessions(); 2183 helper.session()->spdy_session_pool()->CloseAllSessions();
2145 helper.VerifyDataConsumed(); 2184 helper.VerifyDataConsumed();
2146 } 2185 }
2147 2186
2148 TEST_P(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { 2187 TEST_P(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) {
2149 // Construct the request. 2188 // Construct the request.
2150 scoped_ptr<SpdyFrame> req( 2189 scoped_ptr<SpdyFrame> req(
2151 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2190 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2152 scoped_ptr<SpdyFrame> rst( 2191 scoped_ptr<SpdyFrame> rst(
2153 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); 2192 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR));
2154 MockWrite writes[] = { 2193 MockWrite writes[] = {
2155 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), 2194 CreateMockWrite(*req),
2195 CreateMockWrite(*rst),
2156 }; 2196 };
2157 2197
2158 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2198 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2159 const char* const headers[] = { 2199 const char* const headers[] = {
2160 "transfer-encoding", "chunked" 2200 "transfer-encoding", "chunked"
2161 }; 2201 };
2162 scoped_ptr<SpdyFrame> push( 2202 scoped_ptr<SpdyFrame> push(
2163 spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, 2, 1, 2203 spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, 2, 1,
2164 GetDefaultUrlWithPath("/1").c_str())); 2204 GetDefaultUrlWithPath("/1").c_str()));
2165 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 2205 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
2166 MockRead reads[] = { 2206 MockRead reads[] = {
2167 CreateMockRead(*resp, 1), 2207 CreateMockRead(*resp),
2168 CreateMockRead(*push, 2), 2208 CreateMockRead(*push),
2169 CreateMockRead(*body, 3), 2209 CreateMockRead(*body),
2170 MockRead(ASYNC, 0, 5) // EOF 2210 MockRead(ASYNC, 0, 0) // EOF
2171 }; 2211 };
2172 2212
2173 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2213 DelayedSocketData data(1, reads, arraysize(reads),
2214 writes, arraysize(writes));
2174 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 2215 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
2175 BoundNetLog(), GetParam(), NULL); 2216 BoundNetLog(), GetParam(), NULL);
2176 helper.RunToCompletion(&data); 2217 helper.RunToCompletion(&data);
2177 TransactionHelperResult out = helper.output(); 2218 TransactionHelperResult out = helper.output();
2178 EXPECT_EQ(OK, out.rv); 2219 EXPECT_EQ(OK, out.rv);
2179 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 2220 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
2180 EXPECT_EQ("hello!", out.response_data); 2221 EXPECT_EQ("hello!", out.response_data);
2181 2222
2182 helper.session()->spdy_session_pool()->CloseAllSessions(); 2223 helper.session()->spdy_session_pool()->CloseAllSessions();
2183 helper.VerifyDataConsumed(); 2224 helper.VerifyDataConsumed();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 2305
2265 helper.VerifyDataConsumed(); 2306 helper.VerifyDataConsumed();
2266 } 2307 }
2267 2308
2268 // Verify that the client can correctly deal with the user callback attempting 2309 // Verify that the client can correctly deal with the user callback attempting
2269 // to start another transaction on a session that is closing down. See 2310 // to start another transaction on a session that is closing down. See
2270 // http://crbug.com/47455 2311 // http://crbug.com/47455
2271 TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { 2312 TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) {
2272 scoped_ptr<SpdyFrame> req( 2313 scoped_ptr<SpdyFrame> req(
2273 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2314 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2274 MockWrite writes[] = {CreateMockWrite(*req)}; 2315 MockWrite writes[] = { CreateMockWrite(*req) };
2275 MockWrite writes2[] = {CreateMockWrite(*req, 0)}; 2316 MockWrite writes2[] = { CreateMockWrite(*req) };
2276 2317
2277 // The indicated length of this frame is longer than its actual length. When 2318 // The indicated length of this frame is longer than its actual length. When
2278 // the session receives an empty frame after this one, it shuts down the 2319 // the session receives an empty frame after this one, it shuts down the
2279 // session, and calls the read callback with the incomplete data. 2320 // session, and calls the read callback with the incomplete data.
2280 const uint8 kGetBodyFrame2[] = { 2321 const uint8 kGetBodyFrame2[] = {
2281 0x00, 0x00, 0x00, 0x01, 2322 0x00, 0x00, 0x00, 0x01,
2282 0x01, 0x00, 0x00, 0x07, 2323 0x01, 0x00, 0x00, 0x07,
2283 'h', 'e', 'l', 'l', 'o', '!', 2324 'h', 'e', 'l', 'l', 'o', '!',
2284 }; 2325 };
2285 2326
2286 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2327 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2287 MockRead reads[] = { 2328 MockRead reads[] = {
2288 CreateMockRead(*resp, 2), 2329 CreateMockRead(*resp, 2),
2289 MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause 2330 MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause
2290 MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2), 2331 MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2),
2291 arraysize(kGetBodyFrame2), 4), 2332 arraysize(kGetBodyFrame2), 4),
2292 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause 2333 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause
2293 MockRead(ASYNC, 0, 0, 6), // EOF 2334 MockRead(ASYNC, 0, 0, 6), // EOF
2294 }; 2335 };
2295 MockRead reads2[] = { 2336 MockRead reads2[] = {
2296 CreateMockRead(*resp, 1), MockRead(ASYNC, 0, 0, 2), // EOF 2337 CreateMockRead(*resp, 2),
2338 MockRead(ASYNC, 0, 0, 3), // EOF
2297 }; 2339 };
2298 2340
2299 OrderedSocketData data(reads, arraysize(reads), 2341 OrderedSocketData data(reads, arraysize(reads),
2300 writes, arraysize(writes)); 2342 writes, arraysize(writes));
2301 SequencedSocketData data2(reads2, arraysize(reads2), writes2, 2343 DelayedSocketData data2(1, reads2, arraysize(reads2),
2302 arraysize(writes2)); 2344 writes2, arraysize(writes2));
2303 2345
2304 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 2346 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
2305 BoundNetLog(), GetParam(), NULL); 2347 BoundNetLog(), GetParam(), NULL);
2306 helper.RunPreTestSetup(); 2348 helper.RunPreTestSetup();
2307 helper.AddData(&data); 2349 helper.AddData(&data);
2308 helper.AddData(&data2); 2350 helper.AddData(&data2);
2309 HttpNetworkTransaction* trans = helper.trans(); 2351 HttpNetworkTransaction* trans = helper.trans();
2310 2352
2311 // Start the transaction with basic parameters. 2353 // Start the transaction with basic parameters.
2312 TestCompletionCallback callback; 2354 TestCompletionCallback callback;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2447 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2406 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); 2448 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true));
2407 MockWrite writes2[] = { 2449 MockWrite writes2[] = {
2408 CreateMockWrite(*req2, 1), 2450 CreateMockWrite(*req2, 1),
2409 }; 2451 };
2410 MockRead reads2[] = { 2452 MockRead reads2[] = {
2411 CreateMockRead(*resp2, 2), 2453 CreateMockRead(*resp2, 2),
2412 CreateMockRead(*body2, 3), 2454 CreateMockRead(*body2, 3),
2413 MockRead(ASYNC, 0, 0, 4) // EOF 2455 MockRead(ASYNC, 0, 0, 4) // EOF
2414 }; 2456 };
2415 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2457 OrderedSocketData data(reads, arraysize(reads),
2416 SequencedSocketData data2(reads2, arraysize(reads2), writes2, 2458 writes, arraysize(writes));
2417 arraysize(writes2)); 2459 OrderedSocketData data2(reads2, arraysize(reads2),
2460 writes2, arraysize(writes2));
2418 2461
2419 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN 2462 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN
2420 TestDelegate d; 2463 TestDelegate d;
2421 { 2464 {
2422 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); 2465 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol);
2423 scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( 2466 scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest(
2424 GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d)); 2467 GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d));
2425 spdy_url_request_context.socket_factory(). 2468 spdy_url_request_context.socket_factory().
2426 AddSocketDataProvider(&data); 2469 AddSocketDataProvider(&data);
2427 spdy_url_request_context.socket_factory(). 2470 spdy_url_request_context.socket_factory().
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2530 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2488 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); 2531 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true));
2489 MockWrite writes2[] = { 2532 MockWrite writes2[] = {
2490 CreateMockWrite(*req2, 1), 2533 CreateMockWrite(*req2, 1),
2491 }; 2534 };
2492 MockRead reads2[] = { 2535 MockRead reads2[] = {
2493 CreateMockRead(*resp2, 2), 2536 CreateMockRead(*resp2, 2),
2494 CreateMockRead(*body2, 3), 2537 CreateMockRead(*body2, 3),
2495 MockRead(ASYNC, 0, 0, 5) // EOF 2538 MockRead(ASYNC, 0, 0, 5) // EOF
2496 }; 2539 };
2497 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2540 OrderedSocketData data(reads, arraysize(reads),
2498 SequencedSocketData data2(reads2, arraysize(reads2), writes2, 2541 writes, arraysize(writes));
2499 arraysize(writes2)); 2542 OrderedSocketData data2(reads2, arraysize(reads2),
2543 writes2, arraysize(writes2));
2500 2544
2501 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN 2545 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN
2502 TestDelegate d; 2546 TestDelegate d;
2503 TestDelegate d2; 2547 TestDelegate d2;
2504 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); 2548 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol);
2505 { 2549 {
2506 scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( 2550 scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest(
2507 GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d)); 2551 GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d));
2508 spdy_url_request_context.socket_factory(). 2552 spdy_url_request_context.socket_factory().
2509 AddSocketDataProvider(&data); 2553 AddSocketDataProvider(&data);
(...skipping 16 matching lines...) Expand all
2526 EXPECT_EQ(1, d2.received_redirect_count()); 2570 EXPECT_EQ(1, d2.received_redirect_count());
2527 2571
2528 r2->FollowDeferredRedirect(); 2572 r2->FollowDeferredRedirect();
2529 base::RunLoop().Run(); 2573 base::RunLoop().Run();
2530 EXPECT_EQ(1, d2.response_started_count()); 2574 EXPECT_EQ(1, d2.response_started_count());
2531 EXPECT_FALSE(d2.received_data_before_response()); 2575 EXPECT_FALSE(d2.received_data_before_response());
2532 EXPECT_EQ(URLRequestStatus::SUCCESS, r2->status().status()); 2576 EXPECT_EQ(URLRequestStatus::SUCCESS, r2->status().status());
2533 std::string contents2("hello!"); 2577 std::string contents2("hello!");
2534 EXPECT_EQ(contents2, d2.data_received()); 2578 EXPECT_EQ(contents2, d2.data_received());
2535 } 2579 }
2580 data.CompleteRead();
2581 data2.CompleteRead();
2536 EXPECT_TRUE(data.AllReadDataConsumed()); 2582 EXPECT_TRUE(data.AllReadDataConsumed());
2537 EXPECT_TRUE(data.AllWriteDataConsumed()); 2583 EXPECT_TRUE(data.AllWriteDataConsumed());
2538 EXPECT_TRUE(data2.AllReadDataConsumed()); 2584 EXPECT_TRUE(data2.AllReadDataConsumed());
2539 EXPECT_TRUE(data2.AllWriteDataConsumed()); 2585 EXPECT_TRUE(data2.AllWriteDataConsumed());
2540 } 2586 }
2541 2587
2542 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { 2588 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) {
2543 scoped_ptr<SpdyFrame> stream1_syn( 2589 scoped_ptr<SpdyFrame> stream1_syn(
2544 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2590 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2545 scoped_ptr<SpdyFrame> stream1_body( 2591 scoped_ptr<SpdyFrame> stream1_body(
2546 spdy_util_.ConstructSpdyBodyFrame(1, true)); 2592 spdy_util_.ConstructSpdyBodyFrame(1, true));
2547 MockWrite writes[] = { 2593 MockWrite writes[] = {
2548 CreateMockWrite(*stream1_syn, 0), 2594 CreateMockWrite(*stream1_syn, 1),
2549 }; 2595 };
2550 2596
2551 scoped_ptr<SpdyFrame> 2597 scoped_ptr<SpdyFrame>
2552 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2598 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2553 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 2599 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2554 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); 2600 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str()));
2555 const char kPushedData[] = "pushed"; 2601 const char kPushedData[] = "pushed";
2556 scoped_ptr<SpdyFrame> stream2_body( 2602 scoped_ptr<SpdyFrame> stream2_body(
2557 spdy_util_.ConstructSpdyBodyFrame( 2603 spdy_util_.ConstructSpdyBodyFrame(
2558 2, kPushedData, strlen(kPushedData), true)); 2604 2, kPushedData, strlen(kPushedData), true));
2559 MockRead reads[] = { 2605 MockRead reads[] = {
2560 CreateMockRead(*stream1_reply, 1), 2606 CreateMockRead(*stream1_reply, 2),
2561 CreateMockRead(*stream2_syn, 2), 2607 CreateMockRead(*stream2_syn, 3),
2562 CreateMockRead(*stream1_body, 3, SYNCHRONOUS), 2608 CreateMockRead(*stream1_body, 4, SYNCHRONOUS),
2563 CreateMockRead(*stream2_body, 4), 2609 CreateMockRead(*stream2_body, 5),
2564 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause 2610 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
2565 }; 2611 };
2566 2612
2567 HttpResponseInfo response; 2613 HttpResponseInfo response;
2568 HttpResponseInfo response2; 2614 HttpResponseInfo response2;
2569 std::string expected_push_result("pushed"); 2615 std::string expected_push_result("pushed");
2570 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2616 OrderedSocketData data(reads, arraysize(reads),
2617 writes, arraysize(writes));
2571 RunServerPushTest(&data, 2618 RunServerPushTest(&data,
2572 &response, 2619 &response,
2573 &response2, 2620 &response2,
2574 expected_push_result); 2621 expected_push_result);
2575 2622
2576 // Verify the SYN_REPLY. 2623 // Verify the SYN_REPLY.
2577 EXPECT_TRUE(response.headers.get() != NULL); 2624 EXPECT_TRUE(response.headers.get() != NULL);
2578 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 2625 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2579 2626
2580 // Verify the pushed stream. 2627 // Verify the pushed stream.
2581 EXPECT_TRUE(response2.headers.get() != NULL); 2628 EXPECT_TRUE(response2.headers.get() != NULL);
2582 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); 2629 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine());
2583 } 2630 }
2584 2631
2585 TEST_P(SpdyNetworkTransactionTest, ServerPushBeforeSynReply) { 2632 TEST_P(SpdyNetworkTransactionTest, ServerPushBeforeSynReply) {
2586 scoped_ptr<SpdyFrame> stream1_syn( 2633 scoped_ptr<SpdyFrame> stream1_syn(
2587 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2634 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2588 scoped_ptr<SpdyFrame> stream1_body( 2635 scoped_ptr<SpdyFrame> stream1_body(
2589 spdy_util_.ConstructSpdyBodyFrame(1, true)); 2636 spdy_util_.ConstructSpdyBodyFrame(1, true));
2590 MockWrite writes[] = { 2637 MockWrite writes[] = {
2591 CreateMockWrite(*stream1_syn, 0), 2638 CreateMockWrite(*stream1_syn, 1),
2592 }; 2639 };
2593 2640
2594 scoped_ptr<SpdyFrame> 2641 scoped_ptr<SpdyFrame>
2595 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2642 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2596 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 2643 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2597 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); 2644 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str()));
2598 const char kPushedData[] = "pushed"; 2645 const char kPushedData[] = "pushed";
2599 scoped_ptr<SpdyFrame> stream2_body( 2646 scoped_ptr<SpdyFrame> stream2_body(
2600 spdy_util_.ConstructSpdyBodyFrame( 2647 spdy_util_.ConstructSpdyBodyFrame(
2601 2, kPushedData, strlen(kPushedData), true)); 2648 2, kPushedData, strlen(kPushedData), true));
2602 MockRead reads[] = { 2649 MockRead reads[] = {
2603 CreateMockRead(*stream2_syn, 1), 2650 CreateMockRead(*stream2_syn, 2),
2604 CreateMockRead(*stream1_reply, 2), 2651 CreateMockRead(*stream1_reply, 3),
2605 CreateMockRead(*stream1_body, 3, SYNCHRONOUS), 2652 CreateMockRead(*stream1_body, 4, SYNCHRONOUS),
2606 CreateMockRead(*stream2_body, 4), 2653 CreateMockRead(*stream2_body, 5),
2607 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause 2654 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
2608 }; 2655 };
2609 2656
2610 HttpResponseInfo response; 2657 HttpResponseInfo response;
2611 HttpResponseInfo response2; 2658 HttpResponseInfo response2;
2612 std::string expected_push_result("pushed"); 2659 std::string expected_push_result("pushed");
2613 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2660 OrderedSocketData data(reads, arraysize(reads),
2661 writes, arraysize(writes));
2614 RunServerPushTest(&data, 2662 RunServerPushTest(&data,
2615 &response, 2663 &response,
2616 &response2, 2664 &response2,
2617 expected_push_result); 2665 expected_push_result);
2618 2666
2619 // Verify the SYN_REPLY. 2667 // Verify the SYN_REPLY.
2620 EXPECT_TRUE(response.headers.get() != NULL); 2668 EXPECT_TRUE(response.headers.get() != NULL);
2621 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 2669 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2622 2670
2623 // Verify the pushed stream. 2671 // Verify the pushed stream.
2624 EXPECT_TRUE(response2.headers.get() != NULL); 2672 EXPECT_TRUE(response2.headers.get() != NULL);
2625 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); 2673 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine());
2626 } 2674 }
2627 2675
2628 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { 2676 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) {
2629 scoped_ptr<SpdyFrame> stream1_syn( 2677 scoped_ptr<SpdyFrame> stream1_syn(
2630 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2678 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2631 MockWrite writes[] = { 2679 MockWrite writes[] = { CreateMockWrite(*stream1_syn, 1), };
2632 CreateMockWrite(*stream1_syn, 0),
2633 };
2634 2680
2635 scoped_ptr<SpdyFrame> 2681 scoped_ptr<SpdyFrame>
2636 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2682 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2637 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 2683 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2638 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); 2684 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str()));
2639 const char kPushedData[] = "pushed"; 2685 const char kPushedData[] = "pushed";
2640 scoped_ptr<SpdyFrame> stream2_body( 2686 scoped_ptr<SpdyFrame> stream2_body(
2641 spdy_util_.ConstructSpdyBodyFrame( 2687 spdy_util_.ConstructSpdyBodyFrame(
2642 2, kPushedData, strlen(kPushedData), true)); 2688 2, kPushedData, strlen(kPushedData), true));
2643 scoped_ptr<SpdyFrame> 2689 scoped_ptr<SpdyFrame>
2644 stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 2690 stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true));
2645 MockRead reads[] = { 2691 MockRead reads[] = {
2646 CreateMockRead(*stream1_reply, 1), 2692 CreateMockRead(*stream1_reply, 2),
2647 CreateMockRead(*stream2_syn, 2), 2693 CreateMockRead(*stream2_syn, 3),
2648 CreateMockRead(*stream2_body, 3), 2694 CreateMockRead(*stream2_body, 4),
2649 CreateMockRead(*stream1_body, 4, SYNCHRONOUS), 2695 CreateMockRead(*stream1_body, 5, SYNCHRONOUS),
2650 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause 2696 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
2651 }; 2697 };
2652 2698
2653 HttpResponseInfo response; 2699 HttpResponseInfo response;
2654 HttpResponseInfo response2; 2700 HttpResponseInfo response2;
2655 std::string expected_push_result("pushed"); 2701 std::string expected_push_result("pushed");
2656 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2702 OrderedSocketData data(reads, arraysize(reads),
2703 writes, arraysize(writes));
2657 RunServerPushTest(&data, 2704 RunServerPushTest(&data,
2658 &response, 2705 &response,
2659 &response2, 2706 &response2,
2660 expected_push_result); 2707 expected_push_result);
2661 2708
2662 // Verify the SYN_REPLY. 2709 // Verify the SYN_REPLY.
2663 EXPECT_TRUE(response.headers.get() != NULL); 2710 EXPECT_TRUE(response.headers.get() != NULL);
2664 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 2711 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2665 2712
2666 // Verify the pushed stream. 2713 // Verify the pushed stream.
2667 EXPECT_TRUE(response2.headers.get() != NULL); 2714 EXPECT_TRUE(response2.headers.get() != NULL);
2668 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); 2715 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine());
2669 } 2716 }
2670 2717
2671 TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { 2718 TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) {
2672 scoped_ptr<SpdyFrame> stream1_syn( 2719 scoped_ptr<SpdyFrame> stream1_syn(
2673 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2720 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2674 scoped_ptr<SpdyFrame> stream1_body( 2721 scoped_ptr<SpdyFrame> stream1_body(
2675 spdy_util_.ConstructSpdyBodyFrame(1, true)); 2722 spdy_util_.ConstructSpdyBodyFrame(1, true));
2676 MockWrite writes[] = { 2723 MockWrite writes[] = {
2677 CreateMockWrite(*stream1_syn, 0), 2724 CreateMockWrite(*stream1_syn, 1),
2678 }; 2725 };
2679 2726
2680 scoped_ptr<SpdyFrame> 2727 scoped_ptr<SpdyFrame>
2681 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2728 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2682 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 2729 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2683 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); 2730 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str()));
2684 scoped_ptr<SpdyFrame> stream2_rst( 2731 scoped_ptr<SpdyFrame> stream2_rst(
2685 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); 2732 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR));
2686 MockRead reads[] = { 2733 MockRead reads[] = {
2687 CreateMockRead(*stream1_reply, 1), 2734 CreateMockRead(*stream1_reply, 2),
2688 CreateMockRead(*stream2_syn, 2), 2735 CreateMockRead(*stream2_syn, 3),
2689 CreateMockRead(*stream2_rst, 3), 2736 CreateMockRead(*stream2_rst, 4),
2690 CreateMockRead(*stream1_body, 4, SYNCHRONOUS), 2737 CreateMockRead(*stream1_body, 5, SYNCHRONOUS),
2691 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause 2738 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
2692 }; 2739 };
2693 2740
2694 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2741 OrderedSocketData data(reads, arraysize(reads),
2742 writes, arraysize(writes));
2695 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 2743 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
2696 BoundNetLog(), GetParam(), NULL); 2744 BoundNetLog(), GetParam(), NULL);
2697 2745
2698 helper.RunPreTestSetup(); 2746 helper.RunPreTestSetup();
2699 helper.AddData(&data); 2747 helper.AddData(&data);
2700 2748
2701 HttpNetworkTransaction* trans = helper.trans(); 2749 HttpNetworkTransaction* trans = helper.trans();
2702 2750
2703 // Start the transaction with basic parameters. 2751 // Start the transaction with basic parameters.
2704 TestCompletionCallback callback; 2752 TestCompletionCallback callback;
2705 int rv = trans->Start( 2753 int rv = trans->Start(
2706 &CreateGetRequest(), callback.callback(), BoundNetLog()); 2754 &CreateGetRequest(), callback.callback(), BoundNetLog());
2707 EXPECT_EQ(ERR_IO_PENDING, rv); 2755 EXPECT_EQ(ERR_IO_PENDING, rv);
2708 rv = callback.WaitForResult(); 2756 rv = callback.WaitForResult();
2709 EXPECT_EQ(OK, rv); 2757 EXPECT_EQ(OK, rv);
2710 2758
2711 // Verify that we consumed all test data. 2759 // Verify that we consumed all test data.
2712 EXPECT_TRUE(data.AllReadDataConsumed()); 2760 EXPECT_TRUE(data.AllReadDataConsumed())
2713 EXPECT_TRUE(data.AllWriteDataConsumed()); 2761 << "Read count: " << data.read_count()
2762 << " Read index: " << data.read_index();
2763 EXPECT_TRUE(data.AllWriteDataConsumed())
2764 << "Write count: " << data.write_count()
2765 << " Write index: " << data.write_index();
2714 2766
2715 // Verify the SYN_REPLY. 2767 // Verify the SYN_REPLY.
2716 HttpResponseInfo response = *trans->GetResponseInfo(); 2768 HttpResponseInfo response = *trans->GetResponseInfo();
2717 EXPECT_TRUE(response.headers.get() != NULL); 2769 EXPECT_TRUE(response.headers.get() != NULL);
2718 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 2770 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2719 } 2771 }
2720 2772
2721 // Verify that we don't leak streams and that we properly send a reset 2773 // Verify that we don't leak streams and that we properly send a reset
2722 // if the server pushes the same stream twice. 2774 // if the server pushes the same stream twice.
2723 TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) { 2775 TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) {
2724 scoped_ptr<SpdyFrame> stream1_syn( 2776 scoped_ptr<SpdyFrame> stream1_syn(
2725 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2777 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2726 scoped_ptr<SpdyFrame> stream1_body( 2778 scoped_ptr<SpdyFrame> stream1_body(
2727 spdy_util_.ConstructSpdyBodyFrame(1, true)); 2779 spdy_util_.ConstructSpdyBodyFrame(1, true));
2728 scoped_ptr<SpdyFrame> stream3_rst( 2780 scoped_ptr<SpdyFrame> stream3_rst(
2729 spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); 2781 spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR));
2730 MockWrite writes[] = { 2782 MockWrite writes[] = {
2731 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream3_rst, 4), 2783 CreateMockWrite(*stream1_syn, 1),
2784 CreateMockWrite(*stream3_rst, 5),
2732 }; 2785 };
2733 2786
2734 scoped_ptr<SpdyFrame> 2787 scoped_ptr<SpdyFrame>
2735 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2788 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2736 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 2789 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2737 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); 2790 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str()));
2738 const char kPushedData[] = "pushed"; 2791 const char kPushedData[] = "pushed";
2739 scoped_ptr<SpdyFrame> stream2_body( 2792 scoped_ptr<SpdyFrame> stream2_body(
2740 spdy_util_.ConstructSpdyBodyFrame( 2793 spdy_util_.ConstructSpdyBodyFrame(
2741 2, kPushedData, strlen(kPushedData), true)); 2794 2, kPushedData, strlen(kPushedData), true));
2742 scoped_ptr<SpdyFrame> stream3_syn(spdy_util_.ConstructSpdyPush( 2795 scoped_ptr<SpdyFrame> stream3_syn(spdy_util_.ConstructSpdyPush(
2743 NULL, 0, 4, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); 2796 NULL, 0, 4, 1, GetDefaultUrlWithPath("/foo.dat").c_str()));
2744 MockRead reads[] = { 2797 MockRead reads[] = {
2745 CreateMockRead(*stream1_reply, 1), 2798 CreateMockRead(*stream1_reply, 2),
2746 CreateMockRead(*stream2_syn, 2), 2799 CreateMockRead(*stream2_syn, 3),
2747 CreateMockRead(*stream3_syn, 3), 2800 CreateMockRead(*stream3_syn, 4),
2748 CreateMockRead(*stream1_body, 5), 2801 CreateMockRead(*stream1_body, 6, SYNCHRONOUS),
2749 CreateMockRead(*stream2_body, 6), 2802 CreateMockRead(*stream2_body, 7),
2750 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), // Force a pause 2803 MockRead(ASYNC, ERR_IO_PENDING, 8), // Force a pause
2751 }; 2804 };
2752 2805
2753 HttpResponseInfo response; 2806 HttpResponseInfo response;
2754 HttpResponseInfo response2; 2807 HttpResponseInfo response2;
2755 std::string expected_push_result("pushed"); 2808 std::string expected_push_result("pushed");
2756 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2809 OrderedSocketData data(reads, arraysize(reads),
2810 writes, arraysize(writes));
2757 RunServerPushTest(&data, 2811 RunServerPushTest(&data,
2758 &response, 2812 &response,
2759 &response2, 2813 &response2,
2760 expected_push_result); 2814 expected_push_result);
2761 2815
2762 // Verify the SYN_REPLY. 2816 // Verify the SYN_REPLY.
2763 EXPECT_TRUE(response.headers.get() != NULL); 2817 EXPECT_TRUE(response.headers.get() != NULL);
2764 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 2818 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2765 2819
2766 // Verify the pushed stream. 2820 // Verify the pushed stream.
2767 EXPECT_TRUE(response2.headers.get() != NULL); 2821 EXPECT_TRUE(response2.headers.get() != NULL);
2768 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); 2822 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine());
2769 } 2823 }
2770 2824
2771 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { 2825 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) {
2772 scoped_ptr<SpdyFrame> stream1_syn( 2826 scoped_ptr<SpdyFrame> stream1_syn(
2773 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2827 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2774 scoped_ptr<SpdyFrame> stream1_body( 2828 scoped_ptr<SpdyFrame> stream1_body(
2775 spdy_util_.ConstructSpdyBodyFrame(1, true)); 2829 spdy_util_.ConstructSpdyBodyFrame(1, true));
2776 MockWrite writes[] = { 2830 MockWrite writes[] = {
2777 CreateMockWrite(*stream1_syn, 0), 2831 CreateMockWrite(*stream1_syn, 1),
2778 }; 2832 };
2779 2833
2780 scoped_ptr<SpdyFrame> 2834 scoped_ptr<SpdyFrame>
2781 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2835 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2782 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 2836 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2783 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); 2837 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str()));
2784 static const char kPushedData[] = "pushed my darling hello my baby"; 2838 static const char kPushedData[] = "pushed my darling hello my baby";
2785 scoped_ptr<SpdyFrame> stream2_body_base( 2839 scoped_ptr<SpdyFrame> stream2_body_base(
2786 spdy_util_.ConstructSpdyBodyFrame( 2840 spdy_util_.ConstructSpdyBodyFrame(
2787 2, kPushedData, strlen(kPushedData), true)); 2841 2, kPushedData, strlen(kPushedData), true));
2788 const size_t kChunkSize = strlen(kPushedData) / 4; 2842 const size_t kChunkSize = strlen(kPushedData) / 4;
2789 scoped_ptr<SpdyFrame> stream2_body1( 2843 scoped_ptr<SpdyFrame> stream2_body1(
2790 new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); 2844 new SpdyFrame(stream2_body_base->data(), kChunkSize, false));
2791 scoped_ptr<SpdyFrame> stream2_body2( 2845 scoped_ptr<SpdyFrame> stream2_body2(
2792 new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); 2846 new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false));
2793 scoped_ptr<SpdyFrame> stream2_body3( 2847 scoped_ptr<SpdyFrame> stream2_body3(
2794 new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, 2848 new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize,
2795 kChunkSize, false)); 2849 kChunkSize, false));
2796 scoped_ptr<SpdyFrame> stream2_body4( 2850 scoped_ptr<SpdyFrame> stream2_body4(
2797 new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, 2851 new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize,
2798 stream2_body_base->size() - 3 * kChunkSize, false)); 2852 stream2_body_base->size() - 3 * kChunkSize, false));
2799 MockRead reads[] = { 2853 MockRead reads[] = {
2800 CreateMockRead(*stream1_reply, 1), 2854 CreateMockRead(*stream1_reply, 2),
2801 CreateMockRead(*stream2_syn, 2), 2855 CreateMockRead(*stream2_syn, 3),
2802 CreateMockRead(*stream2_body1, 3), 2856 CreateMockRead(*stream2_body1, 4),
2803 CreateMockRead(*stream2_body2, 4), 2857 CreateMockRead(*stream2_body2, 5),
2804 CreateMockRead(*stream2_body3, 5), 2858 CreateMockRead(*stream2_body3, 6),
2805 CreateMockRead(*stream2_body4, 6), 2859 CreateMockRead(*stream2_body4, 7),
2806 CreateMockRead(*stream1_body, 7, SYNCHRONOUS), 2860 CreateMockRead(*stream1_body, 8, SYNCHRONOUS),
2807 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), // Force a pause 2861 MockRead(ASYNC, ERR_IO_PENDING, 9), // Force a pause
2808 }; 2862 };
2809 2863
2810 HttpResponseInfo response; 2864 HttpResponseInfo response;
2811 HttpResponseInfo response2; 2865 HttpResponseInfo response2;
2812 std::string expected_push_result("pushed my darling hello my baby"); 2866 std::string expected_push_result("pushed my darling hello my baby");
2813 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2867 OrderedSocketData data(reads, arraysize(reads),
2868 writes, arraysize(writes));
2814 RunServerPushTest(&data, &response, &response2, kPushedData); 2869 RunServerPushTest(&data, &response, &response2, kPushedData);
2815 2870
2816 // Verify the SYN_REPLY. 2871 // Verify the SYN_REPLY.
2817 EXPECT_TRUE(response.headers.get() != NULL); 2872 EXPECT_TRUE(response.headers.get() != NULL);
2818 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 2873 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2819 2874
2820 // Verify the pushed stream. 2875 // Verify the pushed stream.
2821 EXPECT_TRUE(response2.headers.get() != NULL); 2876 EXPECT_TRUE(response2.headers.get() != NULL);
2822 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); 2877 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine());
2823 } 2878 }
2824 2879
2825 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { 2880 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) {
2826 scoped_ptr<SpdyFrame> stream1_syn( 2881 scoped_ptr<SpdyFrame> stream1_syn(
2827 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2882 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2828 scoped_ptr<SpdyFrame> stream1_body( 2883 scoped_ptr<SpdyFrame> stream1_body(
2829 spdy_util_.ConstructSpdyBodyFrame(1, true)); 2884 spdy_util_.ConstructSpdyBodyFrame(1, true));
2830 MockWrite writes[] = { 2885 MockWrite writes[] = {
2831 CreateMockWrite(*stream1_syn, 0), 2886 CreateMockWrite(*stream1_syn, 1),
2832 }; 2887 };
2833 2888
2834 scoped_ptr<SpdyFrame> 2889 scoped_ptr<SpdyFrame>
2835 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2890 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2836 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 2891 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2837 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); 2892 NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str()));
2838 static const char kPushedData[] = "pushed my darling hello my baby"; 2893 static const char kPushedData[] = "pushed my darling hello my baby";
2839 scoped_ptr<SpdyFrame> stream2_body_base( 2894 scoped_ptr<SpdyFrame> stream2_body_base(
2840 spdy_util_.ConstructSpdyBodyFrame( 2895 spdy_util_.ConstructSpdyBodyFrame(
2841 2, kPushedData, strlen(kPushedData), true)); 2896 2, kPushedData, strlen(kPushedData), true));
2842 const size_t kChunkSize = strlen(kPushedData) / 4; 2897 const size_t kChunkSize = strlen(kPushedData) / 4;
2843 scoped_ptr<SpdyFrame> stream2_body1( 2898 scoped_ptr<SpdyFrame> stream2_body1(
2844 new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); 2899 new SpdyFrame(stream2_body_base->data(), kChunkSize, false));
2845 scoped_ptr<SpdyFrame> stream2_body2( 2900 scoped_ptr<SpdyFrame> stream2_body2(
2846 new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); 2901 new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false));
2847 scoped_ptr<SpdyFrame> stream2_body3( 2902 scoped_ptr<SpdyFrame> stream2_body3(
2848 new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, 2903 new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize,
2849 kChunkSize, false)); 2904 kChunkSize, false));
2850 scoped_ptr<SpdyFrame> stream2_body4( 2905 scoped_ptr<SpdyFrame> stream2_body4(
2851 new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, 2906 new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize,
2852 stream2_body_base->size() - 3 * kChunkSize, false)); 2907 stream2_body_base->size() - 3 * kChunkSize, false));
2853 MockRead reads[] = { 2908 MockRead reads[] = {
2854 CreateMockRead(*stream1_reply, 1), 2909 CreateMockRead(*stream1_reply, 2),
2855 CreateMockRead(*stream2_syn, 2), 2910 CreateMockRead(*stream2_syn, 3),
2856 CreateMockRead(*stream2_body1, 3), 2911 CreateMockRead(*stream2_body1, 4),
2857 CreateMockRead(*stream2_body2, 4), 2912 CreateMockRead(*stream2_body2, 5),
2858 CreateMockRead(*stream2_body3, 5), 2913 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
2859 CreateMockRead(*stream2_body4, 6), 2914 CreateMockRead(*stream2_body3, 7),
2860 CreateMockRead(*stream1_body.get(), 7, SYNCHRONOUS), 2915 CreateMockRead(*stream2_body4, 8),
2861 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8) // Force a pause. 2916 CreateMockRead(*stream1_body.get(), 9, SYNCHRONOUS),
2917 MockRead(ASYNC, ERR_IO_PENDING, 10) // Force a pause.
2862 }; 2918 };
2863 2919
2864 HttpResponseInfo response; 2920 HttpResponseInfo response;
2865 HttpResponseInfo response2; 2921 HttpResponseInfo response2;
2866 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2922 OrderedSocketData data(reads, arraysize(reads),
2923 writes, arraysize(writes));
2867 RunServerPushTest(&data, &response, &response2, kPushedData); 2924 RunServerPushTest(&data, &response, &response2, kPushedData);
2868 2925
2869 // Verify the SYN_REPLY. 2926 // Verify the SYN_REPLY.
2870 EXPECT_TRUE(response.headers.get() != NULL); 2927 EXPECT_TRUE(response.headers.get() != NULL);
2871 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 2928 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2872 2929
2873 // Verify the pushed stream. 2930 // Verify the pushed stream.
2874 EXPECT_TRUE(response2.headers.get() != NULL); 2931 EXPECT_TRUE(response2.headers.get() != NULL);
2875 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); 2932 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine());
2876 } 2933 }
2877 2934
2878 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { 2935 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) {
2879 if (spdy_util_.spdy_version() == SPDY4) { 2936 if (spdy_util_.spdy_version() == SPDY4) {
2880 // PUSH_PROMISE with stream id 0 is connection-level error. 2937 // PUSH_PROMISE with stream id 0 is connection-level error.
2881 // TODO(baranovich): Test session going away. 2938 // TODO(baranovich): Test session going away.
2882 return; 2939 return;
2883 } 2940 }
2884 2941
2885 scoped_ptr<SpdyFrame> stream1_syn( 2942 scoped_ptr<SpdyFrame> stream1_syn(
2886 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2943 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2887 scoped_ptr<SpdyFrame> stream1_body( 2944 scoped_ptr<SpdyFrame> stream1_body(
2888 spdy_util_.ConstructSpdyBodyFrame(1, true)); 2945 spdy_util_.ConstructSpdyBodyFrame(1, true));
2889 scoped_ptr<SpdyFrame> stream2_rst( 2946 scoped_ptr<SpdyFrame> stream2_rst(
2890 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); 2947 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
2891 MockWrite writes[] = { 2948 MockWrite writes[] = {
2892 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), 2949 CreateMockWrite(*stream1_syn, 1),
2950 CreateMockWrite(*stream2_rst, 4),
2893 }; 2951 };
2894 2952
2895 scoped_ptr<SpdyFrame> 2953 scoped_ptr<SpdyFrame>
2896 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 2954 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2897 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 2955 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2898 NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str())); 2956 NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str()));
2899 MockRead reads[] = { 2957 MockRead reads[] = {
2900 CreateMockRead(*stream1_reply, 1), 2958 CreateMockRead(*stream1_reply, 2),
2901 CreateMockRead(*stream2_syn, 2), 2959 CreateMockRead(*stream2_syn, 3),
2902 CreateMockRead(*stream1_body, 4), 2960 CreateMockRead(*stream1_body, 4),
2903 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause 2961 MockRead(ASYNC, ERR_IO_PENDING, 5) // Force a pause
2904 }; 2962 };
2905 2963
2906 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 2964 OrderedSocketData data(reads, arraysize(reads),
2965 writes, arraysize(writes));
2907 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 2966 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
2908 BoundNetLog(), GetParam(), NULL); 2967 BoundNetLog(), GetParam(), NULL);
2909 2968
2910 helper.RunPreTestSetup(); 2969 helper.RunPreTestSetup();
2911 helper.AddData(&data); 2970 helper.AddData(&data);
2912 2971
2913 HttpNetworkTransaction* trans = helper.trans(); 2972 HttpNetworkTransaction* trans = helper.trans();
2914 2973
2915 // Start the transaction with basic parameters. 2974 // Start the transaction with basic parameters.
2916 TestCompletionCallback callback; 2975 TestCompletionCallback callback;
2917 int rv = trans->Start( 2976 int rv = trans->Start(
2918 &CreateGetRequest(), callback.callback(), BoundNetLog()); 2977 &CreateGetRequest(), callback.callback(), BoundNetLog());
2919 EXPECT_EQ(ERR_IO_PENDING, rv); 2978 EXPECT_EQ(ERR_IO_PENDING, rv);
2920 rv = callback.WaitForResult(); 2979 rv = callback.WaitForResult();
2921 EXPECT_EQ(OK, rv); 2980 EXPECT_EQ(OK, rv);
2922 2981
2923 // Verify that we consumed all test data. 2982 // Verify that we consumed all test data.
2924 EXPECT_TRUE(data.AllReadDataConsumed()); 2983 EXPECT_TRUE(data.AllReadDataConsumed())
2925 EXPECT_TRUE(data.AllWriteDataConsumed()); 2984 << "Read count: " << data.read_count()
2985 << " Read index: " << data.read_index();
2986 EXPECT_TRUE(data.AllWriteDataConsumed())
2987 << "Write count: " << data.write_count()
2988 << " Write index: " << data.write_index();
2926 2989
2927 // Verify the SYN_REPLY. 2990 // Verify the SYN_REPLY.
2928 HttpResponseInfo response = *trans->GetResponseInfo(); 2991 HttpResponseInfo response = *trans->GetResponseInfo();
2929 EXPECT_TRUE(response.headers.get() != NULL); 2992 EXPECT_TRUE(response.headers.get() != NULL);
2930 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 2993 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2931 } 2994 }
2932 2995
2933 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { 2996 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) {
2934 scoped_ptr<SpdyFrame> stream1_syn( 2997 scoped_ptr<SpdyFrame> stream1_syn(
2935 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 2998 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2936 scoped_ptr<SpdyFrame> stream1_body( 2999 scoped_ptr<SpdyFrame> stream1_body(
2937 spdy_util_.ConstructSpdyBodyFrame(1, true)); 3000 spdy_util_.ConstructSpdyBodyFrame(1, true));
2938 scoped_ptr<SpdyFrame> stream2_rst( 3001 scoped_ptr<SpdyFrame> stream2_rst(
2939 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); 3002 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM));
2940 MockWrite writes[] = { 3003 MockWrite writes[] = {
2941 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), 3004 CreateMockWrite(*stream1_syn, 1),
3005 CreateMockWrite(*stream2_rst, 4),
2942 }; 3006 };
2943 3007
2944 scoped_ptr<SpdyFrame> 3008 scoped_ptr<SpdyFrame>
2945 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3009 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2946 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( 3010 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush(
2947 NULL, 0, 2, 9, GetDefaultUrlWithPath("/foo.dat").c_str())); 3011 NULL, 0, 2, 9, GetDefaultUrlWithPath("/foo.dat").c_str()));
2948 MockRead reads[] = { 3012 MockRead reads[] = {
2949 CreateMockRead(*stream1_reply, 1), 3013 CreateMockRead(*stream1_reply, 2),
2950 CreateMockRead(*stream2_syn, 2), 3014 CreateMockRead(*stream2_syn, 3),
2951 CreateMockRead(*stream1_body, 4), 3015 CreateMockRead(*stream1_body, 4),
2952 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause 3016 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause
2953 }; 3017 };
2954 3018
2955 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 3019 OrderedSocketData data(reads, arraysize(reads),
3020 writes, arraysize(writes));
2956 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3021 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
2957 BoundNetLog(), GetParam(), NULL); 3022 BoundNetLog(), GetParam(), NULL);
2958 3023
2959 helper.RunPreTestSetup(); 3024 helper.RunPreTestSetup();
2960 helper.AddData(&data); 3025 helper.AddData(&data);
2961 3026
2962 HttpNetworkTransaction* trans = helper.trans(); 3027 HttpNetworkTransaction* trans = helper.trans();
2963 3028
2964 // Start the transaction with basic parameters. 3029 // Start the transaction with basic parameters.
2965 TestCompletionCallback callback; 3030 TestCompletionCallback callback;
2966 int rv = trans->Start( 3031 int rv = trans->Start(
2967 &CreateGetRequest(), callback.callback(), BoundNetLog()); 3032 &CreateGetRequest(), callback.callback(), BoundNetLog());
2968 EXPECT_EQ(ERR_IO_PENDING, rv); 3033 EXPECT_EQ(ERR_IO_PENDING, rv);
2969 rv = callback.WaitForResult(); 3034 rv = callback.WaitForResult();
2970 EXPECT_EQ(OK, rv); 3035 EXPECT_EQ(OK, rv);
2971 3036
2972 // Verify that we consumed all test data. 3037 // Verify that we consumed all test data.
2973 EXPECT_TRUE(data.AllReadDataConsumed()); 3038 EXPECT_TRUE(data.AllReadDataConsumed())
2974 EXPECT_TRUE(data.AllWriteDataConsumed()); 3039 << "Read count: " << data.read_count()
3040 << " Read index: " << data.read_index();
3041 EXPECT_TRUE(data.AllWriteDataConsumed())
3042 << "Write count: " << data.write_count()
3043 << " Write index: " << data.write_index();
2975 3044
2976 // Verify the SYN_REPLY. 3045 // Verify the SYN_REPLY.
2977 HttpResponseInfo response = *trans->GetResponseInfo(); 3046 HttpResponseInfo response = *trans->GetResponseInfo();
2978 EXPECT_TRUE(response.headers.get() != NULL); 3047 EXPECT_TRUE(response.headers.get() != NULL);
2979 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 3048 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
2980 } 3049 }
2981 3050
2982 TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { 3051 TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) {
2983 scoped_ptr<SpdyFrame> stream1_syn( 3052 scoped_ptr<SpdyFrame> stream1_syn(
2984 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3053 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
2985 scoped_ptr<SpdyFrame> stream1_body( 3054 scoped_ptr<SpdyFrame> stream1_body(
2986 spdy_util_.ConstructSpdyBodyFrame(1, true)); 3055 spdy_util_.ConstructSpdyBodyFrame(1, true));
2987 scoped_ptr<SpdyFrame> stream2_rst( 3056 scoped_ptr<SpdyFrame> stream2_rst(
2988 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); 3057 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR));
2989 MockWrite writes[] = { 3058 MockWrite writes[] = {
2990 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), 3059 CreateMockWrite(*stream1_syn, 1),
3060 CreateMockWrite(*stream2_rst, 4),
2991 }; 3061 };
2992 3062
2993 scoped_ptr<SpdyFrame> 3063 scoped_ptr<SpdyFrame>
2994 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3064 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
2995 scoped_ptr<SpdyHeaderBlock> incomplete_headers(new SpdyHeaderBlock()); 3065 scoped_ptr<SpdyHeaderBlock> incomplete_headers(new SpdyHeaderBlock());
2996 (*incomplete_headers)["hello"] = "bye"; 3066 (*incomplete_headers)["hello"] = "bye";
2997 (*incomplete_headers)[spdy_util_.GetStatusKey()] = "200 OK"; 3067 (*incomplete_headers)[spdy_util_.GetStatusKey()] = "200 OK";
2998 (*incomplete_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; 3068 (*incomplete_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1";
2999 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( 3069 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame(
3000 incomplete_headers.Pass(), 2, 1)); 3070 incomplete_headers.Pass(), 2, 1));
3001 MockRead reads[] = { 3071 MockRead reads[] = {
3002 CreateMockRead(*stream1_reply, 1), 3072 CreateMockRead(*stream1_reply, 2),
3003 CreateMockRead(*stream2_syn, 2), 3073 CreateMockRead(*stream2_syn, 3),
3004 CreateMockRead(*stream1_body, 4), 3074 CreateMockRead(*stream1_body, 4),
3005 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause 3075 MockRead(ASYNC, ERR_IO_PENDING, 5) // Force a pause
3006 }; 3076 };
3007 3077
3008 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 3078 OrderedSocketData data(reads, arraysize(reads),
3079 writes, arraysize(writes));
3009 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3080 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
3010 BoundNetLog(), GetParam(), NULL); 3081 BoundNetLog(), GetParam(), NULL);
3011 3082
3012 helper.RunPreTestSetup(); 3083 helper.RunPreTestSetup();
3013 helper.AddData(&data); 3084 helper.AddData(&data);
3014 3085
3015 HttpNetworkTransaction* trans = helper.trans(); 3086 HttpNetworkTransaction* trans = helper.trans();
3016 3087
3017 // Start the transaction with basic parameters. 3088 // Start the transaction with basic parameters.
3018 TestCompletionCallback callback; 3089 TestCompletionCallback callback;
3019 int rv = trans->Start( 3090 int rv = trans->Start(
3020 &CreateGetRequest(), callback.callback(), BoundNetLog()); 3091 &CreateGetRequest(), callback.callback(), BoundNetLog());
3021 EXPECT_EQ(ERR_IO_PENDING, rv); 3092 EXPECT_EQ(ERR_IO_PENDING, rv);
3022 rv = callback.WaitForResult(); 3093 rv = callback.WaitForResult();
3023 EXPECT_EQ(OK, rv); 3094 EXPECT_EQ(OK, rv);
3024
3025 // Verify that we consumed all test data. 3095 // Verify that we consumed all test data.
3026 EXPECT_TRUE(data.AllReadDataConsumed()); 3096 EXPECT_TRUE(data.AllReadDataConsumed())
3027 EXPECT_TRUE(data.AllWriteDataConsumed()); 3097 << "Read count: " << data.read_count()
3098 << " Read index: " << data.read_index();
3099 EXPECT_TRUE(data.AllWriteDataConsumed())
3100 << "Write count: " << data.write_count()
3101 << " Write index: " << data.write_index();
3028 3102
3029 // Verify the SYN_REPLY. 3103 // Verify the SYN_REPLY.
3030 HttpResponseInfo response = *trans->GetResponseInfo(); 3104 HttpResponseInfo response = *trans->GetResponseInfo();
3031 EXPECT_TRUE(response.headers.get() != NULL); 3105 EXPECT_TRUE(response.headers.get() != NULL);
3032 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 3106 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
3033 } 3107 }
3034 3108
3035 // Verify that various SynReply headers parse correctly through the 3109 // Verify that various SynReply headers parse correctly through the
3036 // HTTP layer. 3110 // HTTP layer.
3037 TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { 3111 TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3075 if (spdy_util_.spdy_version() < SPDY4) { 3149 if (spdy_util_.spdy_version() < SPDY4) {
3076 // SPDY4/HTTP2 eliminates use of the :version header. 3150 // SPDY4/HTTP2 eliminates use of the :version header.
3077 test_cases[0].expected_headers["version"] = "HTTP/1.1"; 3151 test_cases[0].expected_headers["version"] = "HTTP/1.1";
3078 test_cases[1].expected_headers["version"] = "HTTP/1.1"; 3152 test_cases[1].expected_headers["version"] = "HTTP/1.1";
3079 test_cases[2].expected_headers["version"] = "HTTP/1.1"; 3153 test_cases[2].expected_headers["version"] = "HTTP/1.1";
3080 } 3154 }
3081 3155
3082 for (size_t i = 0; i < arraysize(test_cases); ++i) { 3156 for (size_t i = 0; i < arraysize(test_cases); ++i) {
3083 scoped_ptr<SpdyFrame> req( 3157 scoped_ptr<SpdyFrame> req(
3084 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3158 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3085 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 3159 MockWrite writes[] = { CreateMockWrite(*req) };
3086 3160
3087 scoped_ptr<SpdyFrame> resp( 3161 scoped_ptr<SpdyFrame> resp(
3088 spdy_util_.ConstructSpdyGetSynReply(test_cases[i].extra_headers, 3162 spdy_util_.ConstructSpdyGetSynReply(test_cases[i].extra_headers,
3089 test_cases[i].num_headers, 3163 test_cases[i].num_headers,
3090 1)); 3164 1));
3091 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 3165 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3092 MockRead reads[] = { 3166 MockRead reads[] = {
3093 CreateMockRead(*resp, 1), 3167 CreateMockRead(*resp),
3094 CreateMockRead(*body, 2), 3168 CreateMockRead(*body),
3095 MockRead(ASYNC, 0, 3) // EOF 3169 MockRead(ASYNC, 0, 0) // EOF
3096 }; 3170 };
3097 3171
3098 SequencedSocketData data(reads, arraysize(reads), writes, 3172 DelayedSocketData data(1, reads, arraysize(reads),
3099 arraysize(writes)); 3173 writes, arraysize(writes));
3100 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3174 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
3101 BoundNetLog(), GetParam(), NULL); 3175 BoundNetLog(), GetParam(), NULL);
3102 helper.RunToCompletion(&data); 3176 helper.RunToCompletion(&data);
3103 TransactionHelperResult out = helper.output(); 3177 TransactionHelperResult out = helper.output();
3104 3178
3105 EXPECT_EQ(OK, out.rv); 3179 EXPECT_EQ(OK, out.rv);
3106 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 3180 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
3107 EXPECT_EQ("hello!", out.response_data); 3181 EXPECT_EQ("hello!", out.response_data);
3108 3182
3109 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; 3183 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 }; 3267 };
3194 3268
3195 for (size_t i = 0; i < arraysize(test_cases); ++i) { 3269 for (size_t i = 0; i < arraysize(test_cases); ++i) {
3196 // Construct the request. 3270 // Construct the request.
3197 scoped_ptr<SpdyFrame> frame_req( 3271 scoped_ptr<SpdyFrame> frame_req(
3198 spdy_util_.ConstructSpdyGet(test_cases[i].extra_headers[0], 3272 spdy_util_.ConstructSpdyGet(test_cases[i].extra_headers[0],
3199 test_cases[i].num_headers[0], 3273 test_cases[i].num_headers[0],
3200 false, 1, LOWEST, true)); 3274 false, 1, LOWEST, true));
3201 3275
3202 MockWrite writes[] = { 3276 MockWrite writes[] = {
3203 CreateMockWrite(*frame_req, 0), 3277 CreateMockWrite(*frame_req),
3204 }; 3278 };
3205 3279
3206 // Construct the reply. 3280 // Construct the reply.
3207 SpdyHeaderBlock reply_headers; 3281 SpdyHeaderBlock reply_headers;
3208 AppendToHeaderBlock(test_cases[i].extra_headers[1], 3282 AppendToHeaderBlock(test_cases[i].extra_headers[1],
3209 test_cases[i].num_headers[1], 3283 test_cases[i].num_headers[1],
3210 &reply_headers); 3284 &reply_headers);
3211 scoped_ptr<SpdyFrame> frame_reply( 3285 scoped_ptr<SpdyFrame> frame_reply(
3212 spdy_util_.ConstructSpdyReply(1, reply_headers)); 3286 spdy_util_.ConstructSpdyReply(1, reply_headers));
3213 3287
3214 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 3288 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3215 MockRead reads[] = { 3289 MockRead reads[] = {
3216 CreateMockRead(*frame_reply, 1), 3290 CreateMockRead(*frame_reply),
3217 CreateMockRead(*body, 2), 3291 CreateMockRead(*body),
3218 MockRead(ASYNC, 0, 3) // EOF 3292 MockRead(ASYNC, 0, 0) // EOF
3219 }; 3293 };
3220 3294
3221 // Attach the headers to the request. 3295 // Attach the headers to the request.
3222 int header_count = test_cases[i].num_headers[0]; 3296 int header_count = test_cases[i].num_headers[0];
3223 3297
3224 HttpRequestInfo request = CreateGetRequest(); 3298 HttpRequestInfo request = CreateGetRequest();
3225 for (int ct = 0; ct < header_count; ct++) { 3299 for (int ct = 0; ct < header_count; ct++) {
3226 const char* header_key = test_cases[i].extra_headers[0][ct * 2]; 3300 const char* header_key = test_cases[i].extra_headers[0][ct * 2];
3227 const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; 3301 const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1];
3228 request.extra_headers.SetHeader(header_key, header_value); 3302 request.extra_headers.SetHeader(header_key, header_value);
3229 } 3303 }
3230 3304
3231 SequencedSocketData data(reads, arraysize(reads), writes, 3305 DelayedSocketData data(1, reads, arraysize(reads),
3232 arraysize(writes)); 3306 writes, arraysize(writes));
3233 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 3307 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
3234 BoundNetLog(), GetParam(), NULL); 3308 BoundNetLog(), GetParam(), NULL);
3235 helper.RunToCompletion(&data); 3309 helper.RunToCompletion(&data);
3236 TransactionHelperResult out = helper.output(); 3310 TransactionHelperResult out = helper.output();
3237 3311
3238 EXPECT_EQ(OK, out.rv) << i; 3312 EXPECT_EQ(OK, out.rv) << i;
3239 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line) << i; 3313 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line) << i;
3240 EXPECT_EQ("hello!", out.response_data) << i; 3314 EXPECT_EQ("hello!", out.response_data) << i;
3241 3315
3242 // Test the response information. 3316 // Test the response information.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 // SYN_REPLY with no headers 3369 // SYN_REPLY with no headers
3296 { 0, { NULL }, }, 3370 { 0, { NULL }, },
3297 }; 3371 };
3298 3372
3299 for (size_t i = 0; i < arraysize(test_cases); ++i) { 3373 for (size_t i = 0; i < arraysize(test_cases); ++i) {
3300 scoped_ptr<SpdyFrame> req( 3374 scoped_ptr<SpdyFrame> req(
3301 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3375 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3302 scoped_ptr<SpdyFrame> rst( 3376 scoped_ptr<SpdyFrame> rst(
3303 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); 3377 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR));
3304 MockWrite writes[] = { 3378 MockWrite writes[] = {
3305 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), 3379 CreateMockWrite(*req),
3380 CreateMockWrite(*rst),
3306 }; 3381 };
3307 3382
3308 // Construct the reply. 3383 // Construct the reply.
3309 SpdyHeaderBlock reply_headers; 3384 SpdyHeaderBlock reply_headers;
3310 AppendToHeaderBlock( 3385 AppendToHeaderBlock(
3311 test_cases[i].headers, test_cases[i].num_headers, &reply_headers); 3386 test_cases[i].headers, test_cases[i].num_headers, &reply_headers);
3312 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyReply(1, reply_headers)); 3387 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyReply(1, reply_headers));
3313 MockRead reads[] = { 3388 MockRead reads[] = {
3314 CreateMockRead(*resp, 1), MockRead(ASYNC, 0, 3) // EOF 3389 CreateMockRead(*resp),
3390 MockRead(ASYNC, 0, 0) // EOF
3315 }; 3391 };
3316 3392
3317 SequencedSocketData data(reads, arraysize(reads), writes, 3393 DelayedSocketData data(1, reads, arraysize(reads),
3318 arraysize(writes)); 3394 writes, arraysize(writes));
3319 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3395 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
3320 BoundNetLog(), GetParam(), NULL); 3396 BoundNetLog(), GetParam(), NULL);
3321 helper.RunToCompletion(&data); 3397 helper.RunToCompletion(&data);
3322 TransactionHelperResult out = helper.output(); 3398 TransactionHelperResult out = helper.output();
3323 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 3399 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
3324 } 3400 }
3325 } 3401 }
3326 3402
3327 // Verify that we don't crash on some corrupt frames. 3403 // Verify that we don't crash on some corrupt frames.
3328 // TODO(jgraettinger): SPDY4 and up treats a header decompression failure as a 3404 // TODO(jgraettinger): SPDY4 and up treats a header decompression failure as a
(...skipping 20 matching lines...) Expand all
3349 } test_cases[] = { 3425 } test_cases[] = {
3350 { syn_reply_wrong_length.get(), }, 3426 { syn_reply_wrong_length.get(), },
3351 }; 3427 };
3352 3428
3353 for (size_t i = 0; i < arraysize(test_cases); ++i) { 3429 for (size_t i = 0; i < arraysize(test_cases); ++i) {
3354 scoped_ptr<SpdyFrame> req( 3430 scoped_ptr<SpdyFrame> req(
3355 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3431 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3356 scoped_ptr<SpdyFrame> rst( 3432 scoped_ptr<SpdyFrame> rst(
3357 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); 3433 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR));
3358 MockWrite writes[] = { 3434 MockWrite writes[] = {
3359 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 3), 3435 CreateMockWrite(*req),
3436 CreateMockWrite(*rst),
3360 }; 3437 };
3361 3438
3362 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 3439 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3363 MockRead reads[] = { 3440 MockRead reads[] = {
3364 MockRead(ASYNC, test_cases[i].syn_reply->data(), wrong_size, 1), 3441 MockRead(ASYNC, test_cases[i].syn_reply->data(), wrong_size),
3365 CreateMockRead(*body, 2), 3442 CreateMockRead(*body),
3366 MockRead(ASYNC, 0, 4) // EOF 3443 MockRead(ASYNC, 0, 0) // EOF
3367 }; 3444 };
3368 3445
3369 SequencedSocketData data(reads, arraysize(reads), writes, 3446 DelayedSocketData data(1, reads, arraysize(reads),
3370 arraysize(writes)); 3447 writes, arraysize(writes));
3371 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3448 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
3372 BoundNetLog(), GetParam(), NULL); 3449 BoundNetLog(), GetParam(), NULL);
3373 helper.RunToCompletion(&data); 3450 helper.RunToCompletion(&data);
3374 TransactionHelperResult out = helper.output(); 3451 TransactionHelperResult out = helper.output();
3375 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 3452 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
3376 } 3453 }
3377 } 3454 }
3378 3455
3379 // SPDY4 treats a header decompression failure as a connection-level error. 3456 // SPDY4 treats a header decompression failure as a connection-level error.
3380 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) { 3457 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) {
3381 if (spdy_util_.spdy_version() < SPDY4) { 3458 if (spdy_util_.spdy_version() < SPDY4) {
3382 return; 3459 return;
3383 } 3460 }
3384 // This is the length field that's too short. 3461 // This is the length field that's too short.
3385 scoped_ptr<SpdyFrame> syn_reply_wrong_length( 3462 scoped_ptr<SpdyFrame> syn_reply_wrong_length(
3386 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3463 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3387 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); 3464 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false);
3388 size_t right_size = 3465 size_t right_size =
3389 syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize(); 3466 syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize();
3390 size_t wrong_size = right_size - 4; 3467 size_t wrong_size = right_size - 4;
3391 test::SetFrameLength(syn_reply_wrong_length.get(), 3468 test::SetFrameLength(syn_reply_wrong_length.get(),
3392 wrong_size, 3469 wrong_size,
3393 spdy_util_.spdy_version()); 3470 spdy_util_.spdy_version());
3394 3471
3395 scoped_ptr<SpdyFrame> req( 3472 scoped_ptr<SpdyFrame> req(
3396 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3473 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3397 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( 3474 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(
3398 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); 3475 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE)."));
3399 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; 3476 MockWrite writes[] = {CreateMockWrite(*req), CreateMockWrite(*goaway)};
3400 3477
3401 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 3478 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3402 MockRead reads[] = { 3479 MockRead reads[] = {
3403 MockRead(ASYNC, syn_reply_wrong_length->data(), 3480 MockRead(ASYNC, syn_reply_wrong_length->data(),
3404 syn_reply_wrong_length->size() - 4, 1), 3481 syn_reply_wrong_length->size() - 4),
3405 }; 3482 };
3406 3483
3407 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 3484 DelayedSocketData data(1, reads, arraysize(reads),
3485 writes, arraysize(writes));
3408 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3486 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
3409 BoundNetLog(), GetParam(), NULL); 3487 BoundNetLog(), GetParam(), NULL);
3410 helper.RunToCompletion(&data); 3488 helper.RunToCompletion(&data);
3411 TransactionHelperResult out = helper.output(); 3489 TransactionHelperResult out = helper.output();
3412 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); 3490 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv);
3413 } 3491 }
3414 3492
3415 TEST_P(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) { 3493 TEST_P(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) {
3416 if (GetParam().protocol < kProtoSPDY4MinimumVersion) { 3494 if (GetParam().protocol < kProtoSPDY4MinimumVersion) {
3417 // Decompression failures are a stream error in SPDY3 and above. 3495 // Decompression failures are a stream error in SPDY3 and above.
3418 return; 3496 return;
3419 } 3497 }
3420 scoped_ptr<SpdyFrame> req( 3498 scoped_ptr<SpdyFrame> req(
3421 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3499 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3422 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( 3500 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(
3423 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); 3501 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE)."));
3424 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; 3502 MockWrite writes[] = {CreateMockWrite(*req), CreateMockWrite(*goaway)};
3425 3503
3426 // Read HEADERS with corrupted payload. 3504 // Read HEADERS with corrupted payload.
3427 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3505 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3428 memset(resp->data() + 12, 0xff, resp->size() - 12); 3506 memset(resp->data() + 12, 0xff, resp->size() - 12);
3429 MockRead reads[] = {CreateMockRead(*resp, 1)}; 3507 MockRead reads[] = {CreateMockRead(*resp)};
3430 3508
3431 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 3509 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes));
3432 NormalSpdyTransactionHelper helper( 3510 NormalSpdyTransactionHelper helper(
3433 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); 3511 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL);
3434 helper.RunToCompletion(&data); 3512 helper.RunToCompletion(&data);
3435 TransactionHelperResult out = helper.output(); 3513 TransactionHelperResult out = helper.output();
3436 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); 3514 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv);
3437 } 3515 }
3438 3516
3439 TEST_P(SpdyNetworkTransactionTest, GoAwayOnFrameSizeError) { 3517 TEST_P(SpdyNetworkTransactionTest, GoAwayOnFrameSizeError) {
3440 scoped_ptr<SpdyFrame> req( 3518 scoped_ptr<SpdyFrame> req(
3441 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3519 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3442 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( 3520 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(
3443 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_CONTROL_FRAME).")); 3521 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_CONTROL_FRAME)."));
3444 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; 3522 MockWrite writes[] = {CreateMockWrite(*req), CreateMockWrite(*goaway)};
3445 3523
3446 // Read WINDOW_UPDATE with incorrectly-sized payload. 3524 // Read WINDOW_UPDATE with incorrectly-sized payload.
3447 // TODO(jgraettinger): SpdyFramer signals this as an INVALID_CONTROL_FRAME, 3525 // TODO(jgraettinger): SpdyFramer signals this as an INVALID_CONTROL_FRAME,
3448 // which is mapped to a protocol error, and not a frame size error. 3526 // which is mapped to a protocol error, and not a frame size error.
3449 scoped_ptr<SpdyFrame> bad_window_update( 3527 scoped_ptr<SpdyFrame> bad_window_update(
3450 spdy_util_.ConstructSpdyWindowUpdate(1, 1)); 3528 spdy_util_.ConstructSpdyWindowUpdate(1, 1));
3451 test::SetFrameLength(bad_window_update.get(), 3529 test::SetFrameLength(bad_window_update.get(),
3452 bad_window_update->size() - 1, 3530 bad_window_update->size() - 1,
3453 spdy_util_.spdy_version()); 3531 spdy_util_.spdy_version());
3454 MockRead reads[] = {CreateMockRead(*bad_window_update, 1)}; 3532 MockRead reads[] = {CreateMockRead(*bad_window_update)};
3455 3533
3456 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 3534 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes));
3457 NormalSpdyTransactionHelper helper( 3535 NormalSpdyTransactionHelper helper(
3458 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); 3536 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL);
3459 helper.RunToCompletion(&data); 3537 helper.RunToCompletion(&data);
3460 TransactionHelperResult out = helper.output(); 3538 TransactionHelperResult out = helper.output();
3461 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 3539 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
3462 } 3540 }
3463 3541
3464 // Test that we shutdown correctly on write errors. 3542 // Test that we shutdown correctly on write errors.
3465 TEST_P(SpdyNetworkTransactionTest, WriteError) { 3543 TEST_P(SpdyNetworkTransactionTest, WriteError) {
3466 scoped_ptr<SpdyFrame> req( 3544 scoped_ptr<SpdyFrame> req(
(...skipping 28 matching lines...) Expand all
3495 EXPECT_EQ(ERR_FAILED, out.rv); 3573 EXPECT_EQ(ERR_FAILED, out.rv);
3496 } 3574 }
3497 3575
3498 // Test that partial writes work. 3576 // Test that partial writes work.
3499 TEST_P(SpdyNetworkTransactionTest, PartialWrite) { 3577 TEST_P(SpdyNetworkTransactionTest, PartialWrite) {
3500 // Chop the SYN_STREAM frame into 5 chunks. 3578 // Chop the SYN_STREAM frame into 5 chunks.
3501 scoped_ptr<SpdyFrame> req( 3579 scoped_ptr<SpdyFrame> req(
3502 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3580 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3503 const int kChunks = 5; 3581 const int kChunks = 5;
3504 scoped_ptr<MockWrite[]> writes(ChopWriteFrame(*req.get(), kChunks)); 3582 scoped_ptr<MockWrite[]> writes(ChopWriteFrame(*req.get(), kChunks));
3505 for (int i = 0; i < kChunks; ++i) {
3506 writes[i].sequence_number = i;
3507 }
3508 3583
3509 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3584 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3510 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 3585 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3511 MockRead reads[] = { 3586 MockRead reads[] = {
3512 CreateMockRead(*resp, kChunks), 3587 CreateMockRead(*resp),
3513 CreateMockRead(*body, kChunks + 1), 3588 CreateMockRead(*body),
3514 MockRead(ASYNC, 0, kChunks + 2) // EOF 3589 MockRead(ASYNC, 0, 0) // EOF
3515 }; 3590 };
3516 3591
3517 SequencedSocketData data(reads, arraysize(reads), writes.get(), kChunks); 3592 DelayedSocketData data(kChunks, reads, arraysize(reads),
3593 writes.get(), kChunks);
3518 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3594 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
3519 BoundNetLog(), GetParam(), NULL); 3595 BoundNetLog(), GetParam(), NULL);
3520 helper.RunToCompletion(&data); 3596 helper.RunToCompletion(&data);
3521 TransactionHelperResult out = helper.output(); 3597 TransactionHelperResult out = helper.output();
3522 EXPECT_EQ(OK, out.rv); 3598 EXPECT_EQ(OK, out.rv);
3523 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 3599 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
3524 EXPECT_EQ("hello!", out.response_data); 3600 EXPECT_EQ("hello!", out.response_data);
3525 } 3601 }
3526 3602
3527 // In this test, we enable compression, but get a uncompressed SynReply from 3603 // In this test, we enable compression, but get a uncompressed SynReply from
3528 // the server. Verify that teardown is all clean. 3604 // the server. Verify that teardown is all clean.
3529 TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { 3605 TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) {
3530 if (spdy_util_.spdy_version() >= SPDY4) { 3606 if (spdy_util_.spdy_version() >= SPDY4) {
3531 // HPACK doesn't use deflate compression. 3607 // HPACK doesn't use deflate compression.
3532 return; 3608 return;
3533 } 3609 }
3534 scoped_ptr<SpdyFrame> compressed( 3610 scoped_ptr<SpdyFrame> compressed(
3535 spdy_util_.ConstructSpdyGet(NULL, 0, true, 1, LOWEST, true)); 3611 spdy_util_.ConstructSpdyGet(NULL, 0, true, 1, LOWEST, true));
3536 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( 3612 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(
3537 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); 3613 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE)."));
3538 MockWrite writes[] = {CreateMockWrite(*compressed, 0), 3614 MockWrite writes[] = {CreateMockWrite(*compressed), CreateMockWrite(*goaway)};
3539 CreateMockWrite(*goaway, 2)};
3540 3615
3541 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3616 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3542 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 3617 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3543 MockRead reads[] = { 3618 MockRead reads[] = {
3544 CreateMockRead(*resp, 1), 3619 CreateMockRead(*resp),
3545 }; 3620 };
3546 3621
3547 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 3622 DelayedSocketData data(1, reads, arraysize(reads),
3623 writes, arraysize(writes));
3548 SpdySessionDependencies* session_deps = 3624 SpdySessionDependencies* session_deps =
3549 CreateSpdySessionDependencies(GetParam()); 3625 CreateSpdySessionDependencies(GetParam());
3550 session_deps->enable_compression = true; 3626 session_deps->enable_compression = true;
3551 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3627 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
3552 BoundNetLog(), GetParam(), session_deps); 3628 BoundNetLog(), GetParam(), session_deps);
3553 helper.RunToCompletion(&data); 3629 helper.RunToCompletion(&data);
3554 TransactionHelperResult out = helper.output(); 3630 TransactionHelperResult out = helper.output();
3555 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); 3631 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv);
3556 data.Reset(); 3632 data.Reset();
3557 } 3633 }
3558 3634
3559 // Test that the NetLog contains good data for a simple GET request. 3635 // Test that the NetLog contains good data for a simple GET request.
3560 TEST_P(SpdyNetworkTransactionTest, NetLog) { 3636 TEST_P(SpdyNetworkTransactionTest, NetLog) {
3561 static const char* const kExtraHeaders[] = { 3637 static const char* const kExtraHeaders[] = {
3562 "user-agent", "Chrome", 3638 "user-agent", "Chrome",
3563 }; 3639 };
3564 scoped_ptr<SpdyFrame> req( 3640 scoped_ptr<SpdyFrame> req(
3565 spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, false, 1, LOWEST, true)); 3641 spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, false, 1, LOWEST, true));
3566 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 3642 MockWrite writes[] = { CreateMockWrite(*req) };
3567 3643
3568 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3644 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3569 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 3645 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3570 MockRead reads[] = { 3646 MockRead reads[] = {
3571 CreateMockRead(*resp, 1), 3647 CreateMockRead(*resp),
3572 CreateMockRead(*body, 2), 3648 CreateMockRead(*body),
3573 MockRead(ASYNC, 0, 3) // EOF 3649 MockRead(ASYNC, 0, 0) // EOF
3574 }; 3650 };
3575 3651
3576 BoundTestNetLog log; 3652 BoundTestNetLog log;
3577 3653
3578 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 3654 DelayedSocketData data(1, reads, arraysize(reads),
3655 writes, arraysize(writes));
3579 NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), 3656 NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(),
3580 DEFAULT_PRIORITY, 3657 DEFAULT_PRIORITY,
3581 log.bound(), GetParam(), NULL); 3658 log.bound(), GetParam(), NULL);
3582 helper.RunToCompletion(&data); 3659 helper.RunToCompletion(&data);
3583 TransactionHelperResult out = helper.output(); 3660 TransactionHelperResult out = helper.output();
3584 EXPECT_EQ(OK, out.rv); 3661 EXPECT_EQ(OK, out.rv);
3585 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 3662 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
3586 EXPECT_EQ("hello!", out.response_data); 3663 EXPECT_EQ("hello!", out.response_data);
3587 3664
3588 // Check that the NetLog was filled reasonably. 3665 // Check that the NetLog was filled reasonably.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3647 3724
3648 // Since we buffer the IO from the stream to the renderer, this test verifies 3725 // Since we buffer the IO from the stream to the renderer, this test verifies
3649 // that when we read out the maximum amount of data (e.g. we received 50 bytes 3726 // that when we read out the maximum amount of data (e.g. we received 50 bytes
3650 // on the network, but issued a Read for only 5 of those bytes) that the data 3727 // on the network, but issued a Read for only 5 of those bytes) that the data
3651 // flow still works correctly. 3728 // flow still works correctly.
3652 TEST_P(SpdyNetworkTransactionTest, BufferFull) { 3729 TEST_P(SpdyNetworkTransactionTest, BufferFull) {
3653 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); 3730 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false);
3654 3731
3655 scoped_ptr<SpdyFrame> req( 3732 scoped_ptr<SpdyFrame> req(
3656 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3733 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3657 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 3734 MockWrite writes[] = { CreateMockWrite(*req) };
3658 3735
3659 // 2 data frames in a single read. 3736 // 2 data frames in a single read.
3660 scoped_ptr<SpdyFrame> data_frame_1( 3737 scoped_ptr<SpdyFrame> data_frame_1(
3661 framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); 3738 framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE));
3662 scoped_ptr<SpdyFrame> data_frame_2( 3739 scoped_ptr<SpdyFrame> data_frame_2(
3663 framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); 3740 framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE));
3664 const SpdyFrame* data_frames[2] = { 3741 const SpdyFrame* data_frames[2] = {
3665 data_frame_1.get(), 3742 data_frame_1.get(),
3666 data_frame_2.get(), 3743 data_frame_2.get(),
3667 }; 3744 };
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 3913 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
3837 EXPECT_EQ("messagemessagemessagemessage", out.response_data); 3914 EXPECT_EQ("messagemessagemessagemessage", out.response_data);
3838 } 3915 }
3839 3916
3840 // Verify the case where we buffer data but read it after it has been buffered. 3917 // Verify the case where we buffer data but read it after it has been buffered.
3841 TEST_P(SpdyNetworkTransactionTest, BufferedAll) { 3918 TEST_P(SpdyNetworkTransactionTest, BufferedAll) {
3842 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); 3919 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false);
3843 3920
3844 scoped_ptr<SpdyFrame> req( 3921 scoped_ptr<SpdyFrame> req(
3845 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 3922 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
3846 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 3923 MockWrite writes[] = { CreateMockWrite(*req) };
3847 3924
3848 // 5 data frames in a single read. 3925 // 5 data frames in a single read.
3849 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 3926 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3850 scoped_ptr<SpdyFrame> data_frame( 3927 scoped_ptr<SpdyFrame> data_frame(
3851 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); 3928 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE));
3852 scoped_ptr<SpdyFrame> data_frame_fin( 3929 scoped_ptr<SpdyFrame> data_frame_fin(
3853 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); 3930 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN));
3854 const SpdyFrame* frames[5] = {reply.get(), data_frame.get(), data_frame.get(), 3931 const SpdyFrame* frames[5] = {reply.get(), data_frame.get(), data_frame.get(),
3855 data_frame.get(), data_frame_fin.get()}; 3932 data_frame.get(), data_frame_fin.get()};
3856 char combined_frames[200]; 3933 char combined_frames[200];
3857 int combined_frames_len = 3934 int combined_frames_len =
3858 CombineFrames(frames, arraysize(frames), 3935 CombineFrames(frames, arraysize(frames),
3859 combined_frames, arraysize(combined_frames)); 3936 combined_frames, arraysize(combined_frames));
3860 3937
3861 MockRead reads[] = { 3938 MockRead reads[] = {
3862 MockRead(ASYNC, combined_frames, combined_frames_len, 1), 3939 MockRead(ASYNC, combined_frames, combined_frames_len),
3863 MockRead(ASYNC, 0, 2) // EOF 3940 MockRead(ASYNC, 0, 0) // EOF
3864 }; 3941 };
3865 3942
3866 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 3943 DelayedSocketData data(1, reads, arraysize(reads),
3944 writes, arraysize(writes));
3867 3945
3868 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 3946 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
3869 BoundNetLog(), GetParam(), NULL); 3947 BoundNetLog(), GetParam(), NULL);
3870 helper.RunPreTestSetup(); 3948 helper.RunPreTestSetup();
3871 helper.AddData(&data); 3949 helper.AddData(&data);
3872 HttpNetworkTransaction* trans = helper.trans(); 3950 HttpNetworkTransaction* trans = helper.trans();
3873 3951
3874 TestCompletionCallback callback; 3952 TestCompletionCallback callback;
3875 int rv = trans->Start( 3953 int rv = trans->Start(
3876 &CreateGetRequest(), callback.callback(), BoundNetLog()); 3954 &CreateGetRequest(), callback.callback(), BoundNetLog());
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
4109 4187
4110 // Verify that no settings exist initially. 4188 // Verify that no settings exist initially.
4111 HostPortPair host_port_pair("www.example.org", helper.port()); 4189 HostPortPair host_port_pair("www.example.org", helper.port());
4112 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); 4190 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool();
4113 EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( 4191 EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings(
4114 host_port_pair).empty()); 4192 host_port_pair).empty());
4115 4193
4116 // Construct the request. 4194 // Construct the request.
4117 scoped_ptr<SpdyFrame> req( 4195 scoped_ptr<SpdyFrame> req(
4118 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 4196 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
4119 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 4197 MockWrite writes[] = { CreateMockWrite(*req) };
4120 4198
4121 // Construct the reply. 4199 // Construct the reply.
4122 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); 4200 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock());
4123 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; 4201 (*reply_headers)[spdy_util_.GetStatusKey()] = "200";
4124 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; 4202 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1";
4125 scoped_ptr<SpdyFrame> reply( 4203 scoped_ptr<SpdyFrame> reply(
4126 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); 4204 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass()));
4127 4205
4128 const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH; 4206 const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH;
4129 unsigned int kSampleValue1 = 0x0a0a0a0a; 4207 unsigned int kSampleValue1 = 0x0a0a0a0a;
(...skipping 12 matching lines...) Expand all
4142 settings[kSampleId2] = 4220 settings[kSampleId2] =
4143 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2); 4221 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2);
4144 // Next add another persisted setting. 4222 // Next add another persisted setting.
4145 settings[kSampleId3] = 4223 settings[kSampleId3] =
4146 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3); 4224 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3);
4147 settings_frame.reset(spdy_util_.ConstructSpdySettings(settings)); 4225 settings_frame.reset(spdy_util_.ConstructSpdySettings(settings));
4148 } 4226 }
4149 4227
4150 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 4228 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
4151 MockRead reads[] = { 4229 MockRead reads[] = {
4152 CreateMockRead(*reply, 1), 4230 CreateMockRead(*reply),
4153 CreateMockRead(*body, 2), 4231 CreateMockRead(*body),
4154 CreateMockRead(*settings_frame, 3), 4232 CreateMockRead(*settings_frame),
4155 MockRead(ASYNC, 0, 4) // EOF 4233 MockRead(ASYNC, 0, 0) // EOF
4156 }; 4234 };
4157 4235
4158 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 4236 DelayedSocketData data(1, reads, arraysize(reads),
4237 writes, arraysize(writes));
4159 helper.AddData(&data); 4238 helper.AddData(&data);
4160 helper.RunDefaultTest(); 4239 helper.RunDefaultTest();
4161 helper.VerifyDataConsumed(); 4240 helper.VerifyDataConsumed();
4162 TransactionHelperResult out = helper.output(); 4241 TransactionHelperResult out = helper.output();
4163 EXPECT_EQ(OK, out.rv); 4242 EXPECT_EQ(OK, out.rv);
4164 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 4243 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
4165 EXPECT_EQ("hello!", out.response_data); 4244 EXPECT_EQ("hello!", out.response_data);
4166 4245
4167 { 4246 {
4168 // Verify we had two persisted settings. 4247 // Verify we had two persisted settings.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
4319 EXPECT_TRUE(it2 != settings_map.end()); 4398 EXPECT_TRUE(it2 != settings_map.end());
4320 SettingsFlagsAndValue flags_and_value2 = it2->second; 4399 SettingsFlagsAndValue flags_and_value2 = it2->second;
4321 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first); 4400 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first);
4322 EXPECT_EQ(kSampleValue2, flags_and_value2.second); 4401 EXPECT_EQ(kSampleValue2, flags_and_value2.second);
4323 } 4402 }
4324 } 4403 }
4325 4404
4326 TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { 4405 TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) {
4327 scoped_ptr<SpdyFrame> req( 4406 scoped_ptr<SpdyFrame> req(
4328 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 4407 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
4329 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 4408 MockWrite writes[] = { CreateMockWrite(*req) };
4330 4409
4331 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway()); 4410 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway());
4332 MockRead reads[] = { 4411 MockRead reads[] = {
4333 CreateMockRead(*go_away, 1), 4412 CreateMockRead(*go_away),
4334 }; 4413 };
4335 4414
4336 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 4415 DelayedSocketData data(1, reads, arraysize(reads),
4416 writes, arraysize(writes));
4337 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 4417 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
4338 BoundNetLog(), GetParam(), NULL); 4418 BoundNetLog(), GetParam(), NULL);
4339 helper.AddData(&data); 4419 helper.AddData(&data);
4340 helper.RunToCompletion(&data); 4420 helper.RunToCompletion(&data);
4341 TransactionHelperResult out = helper.output(); 4421 TransactionHelperResult out = helper.output();
4342 EXPECT_EQ(ERR_ABORTED, out.rv); 4422 EXPECT_EQ(ERR_ABORTED, out.rv);
4343 } 4423 }
4344 4424
4345 TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { 4425 TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) {
4346 scoped_ptr<SpdyFrame> req( 4426 scoped_ptr<SpdyFrame> req(
4347 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 4427 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
4348 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 4428 MockWrite writes[] = { CreateMockWrite(*req) };
4349 4429
4350 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 4430 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
4351 MockRead reads[] = { 4431 MockRead reads[] = {
4352 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF 4432 CreateMockRead(*resp),
4433 MockRead(SYNCHRONOUS, 0, 0) // EOF
4353 }; 4434 };
4354 4435
4355 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 4436 DelayedSocketData data(1, reads, arraysize(reads),
4437 writes, arraysize(writes));
4356 BoundNetLog log; 4438 BoundNetLog log;
4357 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 4439 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
4358 log, GetParam(), NULL); 4440 log, GetParam(), NULL);
4359 helper.RunPreTestSetup(); 4441 helper.RunPreTestSetup();
4360 helper.AddData(&data); 4442 helper.AddData(&data);
4361 HttpNetworkTransaction* trans = helper.trans(); 4443 HttpNetworkTransaction* trans = helper.trans();
4362 4444
4363 TestCompletionCallback callback; 4445 TestCompletionCallback callback;
4364 TransactionHelperResult out; 4446 TransactionHelperResult out;
4365 out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); 4447 out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log);
(...skipping 17 matching lines...) Expand all
4383 // HTTP_1_1_REQUIRED is only supported by SPDY4. 4465 // HTTP_1_1_REQUIRED is only supported by SPDY4.
4384 if (spdy_util_.spdy_version() < SPDY4) 4466 if (spdy_util_.spdy_version() < SPDY4)
4385 return; 4467 return;
4386 4468
4387 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 4469 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
4388 BoundNetLog(), GetParam(), nullptr); 4470 BoundNetLog(), GetParam(), nullptr);
4389 4471
4390 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( 4472 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway(
4391 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); 4473 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please."));
4392 MockRead reads[] = { 4474 MockRead reads[] = {
4393 CreateMockRead(*go_away, 0), 4475 CreateMockRead(*go_away),
4394 }; 4476 };
4395 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); 4477 DelayedSocketData data(0, reads, arraysize(reads), nullptr, 0);
4396 4478
4397 helper.RunToCompletion(&data); 4479 helper.RunToCompletion(&data);
4398 TransactionHelperResult out = helper.output(); 4480 TransactionHelperResult out = helper.output();
4399 EXPECT_EQ(ERR_HTTP_1_1_REQUIRED, out.rv); 4481 EXPECT_EQ(ERR_HTTP_1_1_REQUIRED, out.rv);
4400 } 4482 }
4401 4483
4402 // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual 4484 // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual
4403 // protocol negotiation happens, instead this test forces protocols for both 4485 // protocol negotiation happens, instead this test forces protocols for both
4404 // sockets. 4486 // sockets.
4405 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { 4487 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredRetry) {
(...skipping 13 matching lines...) Expand all
4419 // Do not force SPDY so that second socket can negotiate HTTP/1.1. 4501 // Do not force SPDY so that second socket can negotiate HTTP/1.1.
4420 session_deps->next_protos = SpdyNextProtos(); 4502 session_deps->next_protos = SpdyNextProtos();
4421 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), 4503 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(),
4422 GetParam(), session_deps.release()); 4504 GetParam(), session_deps.release());
4423 4505
4424 // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. 4506 // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED.
4425 const char* url = request.url.spec().c_str(); 4507 const char* url = request.url.spec().c_str();
4426 scoped_ptr<SpdyHeaderBlock> headers(spdy_util_.ConstructGetHeaderBlock(url)); 4508 scoped_ptr<SpdyHeaderBlock> headers(spdy_util_.ConstructGetHeaderBlock(url));
4427 scoped_ptr<SpdyFrame> req( 4509 scoped_ptr<SpdyFrame> req(
4428 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); 4510 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true));
4429 MockWrite writes0[] = {CreateMockWrite(*req, 0)}; 4511 MockWrite writes0[] = {CreateMockWrite(*req)};
4430 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( 4512 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway(
4431 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); 4513 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please."));
4432 MockRead reads0[] = {CreateMockRead(*go_away, 1)}; 4514 MockRead reads0[] = {CreateMockRead(*go_away)};
4433 SequencedSocketData data0(reads0, arraysize(reads0), writes0, 4515 DelayedSocketData data0(1, reads0, arraysize(reads0), writes0,
4434 arraysize(writes0)); 4516 arraysize(writes0));
4435 4517
4436 scoped_ptr<SSLSocketDataProvider> ssl_provider0( 4518 scoped_ptr<SSLSocketDataProvider> ssl_provider0(
4437 new SSLSocketDataProvider(ASYNC, OK)); 4519 new SSLSocketDataProvider(ASYNC, OK));
4438 // Expect HTTP/2 protocols too in SSLConfig. 4520 // Expect HTTP/2 protocols too in SSLConfig.
4439 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); 4521 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11);
4440 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); 4522 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31);
4441 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_14); 4523 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_14);
4442 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4); 4524 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4);
4443 // Force SPDY. 4525 // Force SPDY.
4444 ssl_provider0->SetNextProto(GetParam().protocol); 4526 ssl_provider0->SetNextProto(GetParam().protocol);
4445 helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass()); 4527 helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass());
4446 4528
4447 // Second socket: falling back to HTTP/1.1. 4529 // Second socket: falling back to HTTP/1.1.
4448 MockWrite writes1[] = {MockWrite(ASYNC, 0, 4530 MockWrite writes1[] = {MockWrite(
4449 "GET / HTTP/1.1\r\n" 4531 "GET / HTTP/1.1\r\n"
4450 "Host: www.example.org\r\n" 4532 "Host: www.example.org\r\n"
4451 "Connection: keep-alive\r\n\r\n")}; 4533 "Connection: keep-alive\r\n\r\n")};
4452 MockRead reads1[] = {MockRead(ASYNC, 1, 4534 MockRead reads1[] = {MockRead(
4453 "HTTP/1.1 200 OK\r\n" 4535 "HTTP/1.1 200 OK\r\n"
4454 "Content-Length: 5\r\n\r\n" 4536 "Content-Length: 5\r\n\r\n"
4455 "hello")}; 4537 "hello")};
4456 SequencedSocketData data1(reads1, arraysize(reads1), writes1, 4538 DelayedSocketData data1(1, reads1, arraysize(reads1), writes1,
4457 arraysize(writes1)); 4539 arraysize(writes1));
4458 4540
4459 scoped_ptr<SSLSocketDataProvider> ssl_provider1( 4541 scoped_ptr<SSLSocketDataProvider> ssl_provider1(
4460 new SSLSocketDataProvider(ASYNC, OK)); 4542 new SSLSocketDataProvider(ASYNC, OK));
4461 // Expect only HTTP/1.1 protocol in SSLConfig. 4543 // Expect only HTTP/1.1 protocol in SSLConfig.
4462 ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); 4544 ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11);
4463 // Force HTTP/1.1. 4545 // Force HTTP/1.1.
4464 ssl_provider1->SetNextProto(kProtoHTTP11); 4546 ssl_provider1->SetNextProto(kProtoHTTP11);
4465 helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass()); 4547 helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass());
4466 4548
4467 base::WeakPtr<HttpServerProperties> http_server_properties = 4549 base::WeakPtr<HttpServerProperties> http_server_properties =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
4510 GetParam(), 4592 GetParam(),
4511 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"))); 4593 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")));
4512 // Do not force SPDY so that second socket can negotiate HTTP/1.1. 4594 // Do not force SPDY so that second socket can negotiate HTTP/1.1.
4513 session_deps->next_protos = SpdyNextProtos(); 4595 session_deps->next_protos = SpdyNextProtos();
4514 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), 4596 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(),
4515 GetParam(), session_deps.release()); 4597 GetParam(), session_deps.release());
4516 4598
4517 // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. 4599 // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED.
4518 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( 4600 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect(
4519 nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); 4601 nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443)));
4520 MockWrite writes0[] = {CreateMockWrite(*req, 0)}; 4602 MockWrite writes0[] = {CreateMockWrite(*req)};
4521 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( 4603 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway(
4522 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); 4604 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please."));
4523 MockRead reads0[] = {CreateMockRead(*go_away, 1)}; 4605 MockRead reads0[] = {CreateMockRead(*go_away)};
4524 SequencedSocketData data0(reads0, arraysize(reads0), writes0, 4606 DelayedSocketData data0(1, reads0, arraysize(reads0), writes0,
4525 arraysize(writes0)); 4607 arraysize(writes0));
4526 4608
4527 scoped_ptr<SSLSocketDataProvider> ssl_provider0( 4609 scoped_ptr<SSLSocketDataProvider> ssl_provider0(
4528 new SSLSocketDataProvider(ASYNC, OK)); 4610 new SSLSocketDataProvider(ASYNC, OK));
4529 // Expect HTTP/2 protocols too in SSLConfig. 4611 // Expect HTTP/2 protocols too in SSLConfig.
4530 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); 4612 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11);
4531 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); 4613 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31);
4532 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_14); 4614 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_14);
4533 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4); 4615 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4);
4534 // Force SPDY. 4616 // Force SPDY.
4535 ssl_provider0->SetNextProto(GetParam().protocol); 4617 ssl_provider0->SetNextProto(GetParam().protocol);
4536 helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass()); 4618 helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass());
4537 4619
4538 // Second socket: retry using HTTP/1.1. 4620 // Second socket: retry using HTTP/1.1.
4539 MockWrite writes1[] = { 4621 MockWrite writes1[] = {
4540 MockWrite(ASYNC, 0, 4622 MockWrite(ASYNC, 1,
4541 "CONNECT www.example.org:443 HTTP/1.1\r\n" 4623 "CONNECT www.example.org:443 HTTP/1.1\r\n"
4542 "Host: www.example.org\r\n" 4624 "Host: www.example.org\r\n"
4543 "Proxy-Connection: keep-alive\r\n\r\n"), 4625 "Proxy-Connection: keep-alive\r\n\r\n"),
4544 MockWrite(ASYNC, 2, 4626 MockWrite(ASYNC, 3,
4545 "GET / HTTP/1.1\r\n" 4627 "GET / HTTP/1.1\r\n"
4546 "Host: www.example.org\r\n" 4628 "Host: www.example.org\r\n"
4547 "Connection: keep-alive\r\n\r\n"), 4629 "Connection: keep-alive\r\n\r\n"),
4548 }; 4630 };
4549 4631
4550 MockRead reads1[] = { 4632 MockRead reads1[] = {
4551 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), 4633 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n\r\n"),
4552 MockRead(ASYNC, 3, 4634 MockRead(ASYNC, 4,
4553 "HTTP/1.1 200 OK\r\n" 4635 "HTTP/1.1 200 OK\r\n"
4554 "Content-Length: 5\r\n\r\n" 4636 "Content-Length: 5\r\n\r\n"
4555 "hello"), 4637 "hello"),
4556 }; 4638 };
4557 SequencedSocketData data1(reads1, arraysize(reads1), writes1, 4639 DelayedSocketData data1(1, reads1, arraysize(reads1), writes1,
4558 arraysize(writes1)); 4640 arraysize(writes1));
4559 4641
4560 scoped_ptr<SSLSocketDataProvider> ssl_provider1( 4642 scoped_ptr<SSLSocketDataProvider> ssl_provider1(
4561 new SSLSocketDataProvider(ASYNC, OK)); 4643 new SSLSocketDataProvider(ASYNC, OK));
4562 // Expect only HTTP/1.1 protocol in SSLConfig. 4644 // Expect only HTTP/1.1 protocol in SSLConfig.
4563 ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); 4645 ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11);
4564 // Force HTTP/1.1. 4646 // Force HTTP/1.1.
4565 ssl_provider1->SetNextProto(kProtoHTTP11); 4647 ssl_provider1->SetNextProto(kProtoHTTP11);
4566 helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass()); 4648 helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass());
4567 4649
4568 // A third socket is needed for the tunnelled connection. 4650 // A third socket is needed for the tunnelled connection.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4622 MockWrite writes[] = { 4704 MockWrite writes[] = {
4623 MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), 4705 MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0),
4624 CreateMockWrite(*req, 2), 4706 CreateMockWrite(*req, 2),
4625 }; 4707 };
4626 MockRead reads[] = { 4708 MockRead reads[] = {
4627 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), 4709 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1),
4628 CreateMockRead(*resp, 3), 4710 CreateMockRead(*resp, 3),
4629 CreateMockRead(*body.get(), 4), 4711 CreateMockRead(*body.get(), 4),
4630 MockRead(ASYNC, 0, 0, 5), 4712 MockRead(ASYNC, 0, 0, 5),
4631 }; 4713 };
4632 scoped_ptr<SequencedSocketData> data(new SequencedSocketData( 4714 scoped_ptr<OrderedSocketData> data(new OrderedSocketData(
4633 reads, arraysize(reads), writes, arraysize(writes))); 4715 reads, arraysize(reads), writes, arraysize(writes)));
4634 4716
4635 helper.AddData(data.get()); 4717 helper.AddData(data.get());
4636 TestCompletionCallback callback; 4718 TestCompletionCallback callback;
4637 4719
4638 int rv = trans->Start( 4720 int rv = trans->Start(
4639 &CreateGetRequest(), callback.callback(), BoundNetLog()); 4721 &CreateGetRequest(), callback.callback(), BoundNetLog());
4640 EXPECT_EQ(ERR_IO_PENDING, rv); 4722 EXPECT_EQ(ERR_IO_PENDING, rv);
4641 4723
4642 rv = callback.WaitForResult(); 4724 rv = callback.WaitForResult();
(...skipping 29 matching lines...) Expand all
4672 helper.SetSession(make_scoped_refptr( 4754 helper.SetSession(make_scoped_refptr(
4673 SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); 4755 SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get())));
4674 4756
4675 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); 4757 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool();
4676 helper.RunPreTestSetup(); 4758 helper.RunPreTestSetup();
4677 4759
4678 // Construct and send a simple GET request. 4760 // Construct and send a simple GET request.
4679 scoped_ptr<SpdyFrame> req( 4761 scoped_ptr<SpdyFrame> req(
4680 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 4762 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
4681 MockWrite writes[] = { 4763 MockWrite writes[] = {
4682 CreateMockWrite(*req, 0), 4764 CreateMockWrite(*req, 1),
4683 }; 4765 };
4684 4766
4685 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 4767 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
4686 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 4768 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
4687 MockRead reads[] = { 4769 MockRead reads[] = {
4688 CreateMockRead(*resp, 1), 4770 CreateMockRead(*resp, 2),
4689 CreateMockRead(*body, 2), 4771 CreateMockRead(*body, 3),
4690 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), // Force a pause 4772 MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause
4773 MockRead(ASYNC, 0, 5) // EOF
4691 }; 4774 };
4692 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 4775 OrderedSocketData data(reads, arraysize(reads),
4776 writes, arraysize(writes));
4693 helper.AddData(&data); 4777 helper.AddData(&data);
4694 HttpNetworkTransaction* trans = helper.trans(); 4778 HttpNetworkTransaction* trans = helper.trans();
4695 4779
4696 TestCompletionCallback callback; 4780 TestCompletionCallback callback;
4697 TransactionHelperResult out; 4781 TransactionHelperResult out;
4698 out.rv = trans->Start( 4782 out.rv = trans->Start(
4699 &CreateGetRequest(), callback.callback(), BoundNetLog()); 4783 &CreateGetRequest(), callback.callback(), BoundNetLog());
4700 4784
4701 EXPECT_EQ(out.rv, ERR_IO_PENDING); 4785 EXPECT_EQ(out.rv, ERR_IO_PENDING);
4702 out.rv = callback.WaitForResult(); 4786 out.rv = callback.WaitForResult();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4737 MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), 4821 MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0),
4738 CreateMockWrite(*req2, 2), 4822 CreateMockWrite(*req2, 2),
4739 }; 4823 };
4740 MockRead reads2[] = { 4824 MockRead reads2[] = {
4741 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), 4825 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1),
4742 CreateMockRead(*resp2, 3), 4826 CreateMockRead(*resp2, 3),
4743 CreateMockRead(*body2, 4), 4827 CreateMockRead(*body2, 4),
4744 MockRead(ASYNC, 0, 5) // EOF 4828 MockRead(ASYNC, 0, 5) // EOF
4745 }; 4829 };
4746 4830
4747 scoped_ptr<SequencedSocketData> data_proxy(new SequencedSocketData( 4831 scoped_ptr<OrderedSocketData> data_proxy(new OrderedSocketData(
4748 reads2, arraysize(reads2), writes2, arraysize(writes2))); 4832 reads2, arraysize(reads2), writes2, arraysize(writes2)));
4749 4833
4750 // Create another request to www.example.org, but this time through a proxy. 4834 // Create another request to www.example.org, but this time through a proxy.
4751 HttpRequestInfo request_proxy; 4835 HttpRequestInfo request_proxy;
4752 request_proxy.method = "GET"; 4836 request_proxy.method = "GET";
4753 request_proxy.url = GURL(GetDefaultUrlWithPath("/foo.dat")); 4837 request_proxy.url = GURL(GetDefaultUrlWithPath("/foo.dat"));
4754 request_proxy.load_flags = 0; 4838 request_proxy.load_flags = 0;
4755 scoped_ptr<SpdySessionDependencies> ssd_proxy( 4839 scoped_ptr<SpdySessionDependencies> ssd_proxy(
4756 CreateSpdySessionDependencies(GetParam())); 4840 CreateSpdySessionDependencies(GetParam()));
4757 // Ensure that this transaction uses the same SpdySessionPool. 4841 // Ensure that this transaction uses the same SpdySessionPool.
(...skipping 19 matching lines...) Expand all
4777 EXPECT_EQ(0, rv); 4861 EXPECT_EQ(0, rv);
4778 4862
4779 HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo(); 4863 HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo();
4780 EXPECT_TRUE(response_proxy.headers.get() != NULL); 4864 EXPECT_TRUE(response_proxy.headers.get() != NULL);
4781 EXPECT_EQ("HTTP/1.1 200 OK", response_proxy.headers->GetStatusLine()); 4865 EXPECT_EQ("HTTP/1.1 200 OK", response_proxy.headers->GetStatusLine());
4782 4866
4783 std::string response_data; 4867 std::string response_data;
4784 ASSERT_EQ(OK, ReadTransaction(trans_proxy, &response_data)); 4868 ASSERT_EQ(OK, ReadTransaction(trans_proxy, &response_data));
4785 EXPECT_EQ("hello!", response_data); 4869 EXPECT_EQ("hello!", response_data);
4786 4870
4871 data.CompleteRead();
4787 helper_proxy.VerifyDataConsumed(); 4872 helper_proxy.VerifyDataConsumed();
4788 } 4873 }
4789 4874
4790 // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction 4875 // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction
4791 // on a new connection, if the connection was previously known to be good. 4876 // on a new connection, if the connection was previously known to be good.
4792 // This can happen when a server reboots without saying goodbye, or when 4877 // This can happen when a server reboots without saying goodbye, or when
4793 // we're behind a NAT that masked the RST. 4878 // we're behind a NAT that masked the RST.
4794 TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { 4879 TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) {
4795 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 4880 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
4796 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 4881 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
4797 MockRead reads[] = { 4882 MockRead reads[] = {
4798 CreateMockRead(*resp, 0), 4883 CreateMockRead(*resp),
4799 CreateMockRead(*body, 1), 4884 CreateMockRead(*body),
4800 MockRead(ASYNC, ERR_IO_PENDING, 2), 4885 MockRead(ASYNC, ERR_IO_PENDING),
4801 MockRead(ASYNC, ERR_CONNECTION_RESET, 3), 4886 MockRead(ASYNC, ERR_CONNECTION_RESET),
4802 }; 4887 };
4803 4888
4804 MockRead reads2[] = { 4889 MockRead reads2[] = {
4805 CreateMockRead(*resp, 0), 4890 CreateMockRead(*resp),
4806 CreateMockRead(*body, 1), 4891 CreateMockRead(*body),
4807 MockRead(ASYNC, 0, 2) // EOF 4892 MockRead(ASYNC, 0, 0) // EOF
4808 }; 4893 };
4809 4894
4810 // This test has a couple of variants. 4895 // This test has a couple of variants.
4811 enum { 4896 enum {
4812 // Induce the RST while waiting for our transaction to send. 4897 // Induce the RST while waiting for our transaction to send.
4813 VARIANT_RST_DURING_SEND_COMPLETION, 4898 VARIANT_RST_DURING_SEND_COMPLETION,
4814 // Induce the RST while waiting for our transaction to read. 4899 // Induce the RST while waiting for our transaction to read.
4815 // In this case, the send completed - everything copied into the SNDBUF. 4900 // In this case, the send completed - everything copied into the SNDBUF.
4816 VARIANT_RST_DURING_READ_COMPLETION 4901 VARIANT_RST_DURING_READ_COMPLETION
4817 }; 4902 };
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4866 4951
4867 helper.VerifyDataConsumed(); 4952 helper.VerifyDataConsumed();
4868 } 4953 }
4869 } 4954 }
4870 4955
4871 // Test that turning SPDY on and off works properly. 4956 // Test that turning SPDY on and off works properly.
4872 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { 4957 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) {
4873 HttpStreamFactory::set_spdy_enabled(true); 4958 HttpStreamFactory::set_spdy_enabled(true);
4874 scoped_ptr<SpdyFrame> req( 4959 scoped_ptr<SpdyFrame> req(
4875 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 4960 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
4876 MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; 4961 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
4877 4962
4878 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 4963 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
4879 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 4964 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
4880 MockRead spdy_reads[] = { 4965 MockRead spdy_reads[] = {
4881 CreateMockRead(*resp, 1), 4966 CreateMockRead(*resp),
4882 CreateMockRead(*body, 2), 4967 CreateMockRead(*body),
4883 MockRead(ASYNC, 0, 3) // EOF 4968 MockRead(ASYNC, 0, 0) // EOF
4884 }; 4969 };
4885 4970
4886 SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, 4971 DelayedSocketData data(1, spdy_reads, arraysize(spdy_reads),
4887 arraysize(spdy_writes)); 4972 spdy_writes, arraysize(spdy_writes));
4888 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 4973 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
4889 BoundNetLog(), GetParam(), NULL); 4974 BoundNetLog(), GetParam(), NULL);
4890 helper.RunToCompletion(&data); 4975 helper.RunToCompletion(&data);
4891 TransactionHelperResult out = helper.output(); 4976 TransactionHelperResult out = helper.output();
4892 EXPECT_EQ(OK, out.rv); 4977 EXPECT_EQ(OK, out.rv);
4893 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 4978 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
4894 EXPECT_EQ("hello!", out.response_data); 4979 EXPECT_EQ("hello!", out.response_data);
4895 4980
4896 HttpStreamFactory::set_spdy_enabled(false); 4981 HttpStreamFactory::set_spdy_enabled(false);
4897 MockWrite http_writes[] = { 4982 MockRead http_reads[] = {
4898 MockWrite(SYNCHRONOUS, 0, 4983 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
4899 "GET / HTTP/1.1\r\n" 4984 MockRead("hello from http"),
4900 "Host: www.example.org\r\n" 4985 MockRead(SYNCHRONOUS, OK),
4901 "Connection: keep-alive\r\n\r\n"),
4902 }; 4986 };
4903 4987 DelayedSocketData data2(1, http_reads, arraysize(http_reads), NULL, 0);
4904 MockRead http_reads[] = {
4905 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"),
4906 MockRead(SYNCHRONOUS, 2, "hello from http"),
4907 MockRead(SYNCHRONOUS, OK, 3),
4908 };
4909 SequencedSocketData data2(http_reads, arraysize(http_reads), http_writes,
4910 arraysize(http_writes));
4911 NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, 4988 NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY,
4912 BoundNetLog(), GetParam(), NULL); 4989 BoundNetLog(), GetParam(), NULL);
4913 helper2.SetSpdyDisabled(); 4990 helper2.SetSpdyDisabled();
4914 helper2.RunToCompletion(&data2); 4991 helper2.RunToCompletion(&data2);
4915 TransactionHelperResult out2 = helper2.output(); 4992 TransactionHelperResult out2 = helper2.output();
4916 EXPECT_EQ(OK, out2.rv); 4993 EXPECT_EQ(OK, out2.rv);
4917 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); 4994 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line);
4918 EXPECT_EQ("hello from http", out2.response_data); 4995 EXPECT_EQ("hello from http", out2.response_data);
4919 4996
4920 HttpStreamFactory::set_spdy_enabled(true); 4997 HttpStreamFactory::set_spdy_enabled(true);
4921 } 4998 }
4922 4999
4923 // Tests that Basic authentication works over SPDY 5000 // Tests that Basic authentication works over SPDY
4924 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { 5001 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) {
4925 HttpStreamFactory::set_spdy_enabled(true); 5002 HttpStreamFactory::set_spdy_enabled(true);
4926 5003
4927 // The first request will be a bare GET, the second request will be a 5004 // The first request will be a bare GET, the second request will be a
4928 // GET with an Authorization header. 5005 // GET with an Authorization header.
4929 scoped_ptr<SpdyFrame> req_get( 5006 scoped_ptr<SpdyFrame> req_get(
4930 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 5007 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
4931 const char* const kExtraAuthorizationHeaders[] = { 5008 const char* const kExtraAuthorizationHeaders[] = {
4932 "authorization", "Basic Zm9vOmJhcg==" 5009 "authorization", "Basic Zm9vOmJhcg=="
4933 }; 5010 };
4934 scoped_ptr<SpdyFrame> req_get_authorization( 5011 scoped_ptr<SpdyFrame> req_get_authorization(
4935 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, 5012 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders,
4936 arraysize(kExtraAuthorizationHeaders) / 2, 5013 arraysize(kExtraAuthorizationHeaders) / 2,
4937 false, 3, LOWEST, true)); 5014 false, 3, LOWEST, true));
4938 MockWrite spdy_writes[] = { 5015 MockWrite spdy_writes[] = {
4939 CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), 5016 CreateMockWrite(*req_get, 1),
5017 CreateMockWrite(*req_get_authorization, 4),
4940 }; 5018 };
4941 5019
4942 // The first response is a 401 authentication challenge, and the second 5020 // The first response is a 401 authentication challenge, and the second
4943 // response will be a 200 response since the second request includes a valid 5021 // response will be a 200 response since the second request includes a valid
4944 // Authorization header. 5022 // Authorization header.
4945 const char* const kExtraAuthenticationHeaders[] = { 5023 const char* const kExtraAuthenticationHeaders[] = {
4946 "www-authenticate", 5024 "www-authenticate",
4947 "Basic realm=\"MyRealm\"" 5025 "Basic realm=\"MyRealm\""
4948 }; 5026 };
4949 scoped_ptr<SpdyFrame> resp_authentication( 5027 scoped_ptr<SpdyFrame> resp_authentication(
4950 spdy_util_.ConstructSpdySynReplyError( 5028 spdy_util_.ConstructSpdySynReplyError(
4951 "401 Authentication Required", 5029 "401 Authentication Required",
4952 kExtraAuthenticationHeaders, 5030 kExtraAuthenticationHeaders,
4953 arraysize(kExtraAuthenticationHeaders) / 2, 5031 arraysize(kExtraAuthenticationHeaders) / 2,
4954 1)); 5032 1));
4955 scoped_ptr<SpdyFrame> body_authentication( 5033 scoped_ptr<SpdyFrame> body_authentication(
4956 spdy_util_.ConstructSpdyBodyFrame(1, true)); 5034 spdy_util_.ConstructSpdyBodyFrame(1, true));
4957 scoped_ptr<SpdyFrame> resp_data( 5035 scoped_ptr<SpdyFrame> resp_data(
4958 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); 5036 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
4959 scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); 5037 scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true));
4960 MockRead spdy_reads[] = { 5038 MockRead spdy_reads[] = {
4961 CreateMockRead(*resp_authentication, 1), 5039 CreateMockRead(*resp_authentication, 2),
4962 CreateMockRead(*body_authentication, 2), 5040 CreateMockRead(*body_authentication, 3),
4963 CreateMockRead(*resp_data, 4), 5041 CreateMockRead(*resp_data, 5),
4964 CreateMockRead(*body_data, 5), 5042 CreateMockRead(*body_data, 6),
4965 MockRead(ASYNC, 0, 6), 5043 MockRead(ASYNC, 0, 7),
4966 }; 5044 };
4967 5045
4968 SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, 5046 OrderedSocketData data(spdy_reads, arraysize(spdy_reads),
4969 arraysize(spdy_writes)); 5047 spdy_writes, arraysize(spdy_writes));
4970 HttpRequestInfo request(CreateGetRequest()); 5048 HttpRequestInfo request(CreateGetRequest());
4971 BoundNetLog net_log; 5049 BoundNetLog net_log;
4972 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, 5050 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY,
4973 net_log, GetParam(), NULL); 5051 net_log, GetParam(), NULL);
4974 5052
4975 helper.RunPreTestSetup(); 5053 helper.RunPreTestSetup();
4976 helper.AddData(&data); 5054 helper.AddData(&data);
4977 HttpNetworkTransaction* trans = helper.trans(); 5055 HttpNetworkTransaction* trans = helper.trans();
4978 TestCompletionCallback callback; 5056 TestCompletionCallback callback;
4979 const int rv_start = trans->Start(&request, callback.callback(), net_log); 5057 const int rv_start = trans->Start(&request, callback.callback(), net_log);
(...skipping 30 matching lines...) Expand all
5010 EXPECT_EQ(200, response_restart->headers->response_code()); 5088 EXPECT_EQ(200, response_restart->headers->response_code());
5011 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); 5089 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL);
5012 } 5090 }
5013 5091
5014 TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) { 5092 TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) {
5015 scoped_ptr<SpdyFrame> stream1_syn( 5093 scoped_ptr<SpdyFrame> stream1_syn(
5016 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 5094 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
5017 scoped_ptr<SpdyFrame> stream1_body( 5095 scoped_ptr<SpdyFrame> stream1_body(
5018 spdy_util_.ConstructSpdyBodyFrame(1, true)); 5096 spdy_util_.ConstructSpdyBodyFrame(1, true));
5019 MockWrite writes[] = { 5097 MockWrite writes[] = {
5020 CreateMockWrite(*stream1_syn, 0), 5098 CreateMockWrite(*stream1_syn, 1),
5021 }; 5099 };
5022 5100
5023 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); 5101 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock());
5024 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), 5102 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"),
5025 initial_headers.get()); 5103 initial_headers.get());
5026 scoped_ptr<SpdyFrame> stream2_syn( 5104 scoped_ptr<SpdyFrame> stream2_syn(
5027 spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); 5105 spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1));
5028 5106
5029 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); 5107 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock());
5030 (*late_headers)["hello"] = "bye"; 5108 (*late_headers)["hello"] = "bye";
5031 (*late_headers)[spdy_util_.GetStatusKey()] = "200"; 5109 (*late_headers)[spdy_util_.GetStatusKey()] = "200";
5032 (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; 5110 (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1";
5033 scoped_ptr<SpdyFrame> stream2_headers( 5111 scoped_ptr<SpdyFrame> stream2_headers(
5034 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), 5112 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(),
5035 false, 5113 false,
5036 2, 5114 2,
5037 LOWEST, 5115 LOWEST,
5038 HEADERS, 5116 HEADERS,
5039 CONTROL_FLAG_NONE, 5117 CONTROL_FLAG_NONE,
5040 0)); 5118 0));
5041 5119
5042 scoped_ptr<SpdyFrame> 5120 scoped_ptr<SpdyFrame>
5043 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 5121 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
5044 const char kPushedData[] = "pushed"; 5122 const char kPushedData[] = "pushed";
5045 scoped_ptr<SpdyFrame> stream2_body( 5123 scoped_ptr<SpdyFrame> stream2_body(
5046 spdy_util_.ConstructSpdyBodyFrame( 5124 spdy_util_.ConstructSpdyBodyFrame(
5047 2, kPushedData, strlen(kPushedData), true)); 5125 2, kPushedData, strlen(kPushedData), true));
5048 MockRead reads[] = { 5126 MockRead reads[] = {
5049 CreateMockRead(*stream1_reply, 1), 5127 CreateMockRead(*stream1_reply, 2),
5050 CreateMockRead(*stream2_syn, 2), 5128 CreateMockRead(*stream2_syn, 3),
5051 CreateMockRead(*stream2_headers, 3), 5129 CreateMockRead(*stream2_headers, 4),
5052 CreateMockRead(*stream1_body, 4, SYNCHRONOUS), 5130 CreateMockRead(*stream1_body, 5, SYNCHRONOUS),
5053 CreateMockRead(*stream2_body, 5), 5131 CreateMockRead(*stream2_body, 5),
5054 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause 5132 MockRead(ASYNC, ERR_IO_PENDING, 7), // Force a pause
5055 }; 5133 };
5056 5134
5057 HttpResponseInfo response; 5135 HttpResponseInfo response;
5058 HttpResponseInfo response2; 5136 HttpResponseInfo response2;
5059 std::string expected_push_result("pushed"); 5137 std::string expected_push_result("pushed");
5060 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 5138 OrderedSocketData data(reads, arraysize(reads),
5139 writes, arraysize(writes));
5061 RunServerPushTest(&data, 5140 RunServerPushTest(&data,
5062 &response, 5141 &response,
5063 &response2, 5142 &response2,
5064 expected_push_result); 5143 expected_push_result);
5065 5144
5066 // Verify the SYN_REPLY. 5145 // Verify the SYN_REPLY.
5067 EXPECT_TRUE(response.headers.get() != NULL); 5146 EXPECT_TRUE(response.headers.get() != NULL);
5068 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 5147 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
5069 5148
5070 // Verify the pushed stream. 5149 // Verify the pushed stream.
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
5437 EXPECT_TRUE(data.AllReadDataConsumed()); 5516 EXPECT_TRUE(data.AllReadDataConsumed());
5438 EXPECT_TRUE(data.AllWriteDataConsumed()); 5517 EXPECT_TRUE(data.AllWriteDataConsumed());
5439 } 5518 }
5440 5519
5441 TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) { 5520 TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) {
5442 scoped_ptr<SpdyFrame> req( 5521 scoped_ptr<SpdyFrame> req(
5443 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 5522 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
5444 scoped_ptr<SpdyFrame> rst( 5523 scoped_ptr<SpdyFrame> rst(
5445 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); 5524 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR));
5446 MockWrite writes[] = { 5525 MockWrite writes[] = {
5447 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), 5526 CreateMockWrite(*req), CreateMockWrite(*rst),
5448 }; 5527 };
5449 5528
5450 scoped_ptr<SpdyFrame> stream1_reply( 5529 scoped_ptr<SpdyFrame> stream1_reply(
5451 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 5530 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
5452 5531
5453 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); 5532 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock());
5454 (*late_headers)["hello"] = "bye"; 5533 (*late_headers)["hello"] = "bye";
5455 scoped_ptr<SpdyFrame> stream1_headers( 5534 scoped_ptr<SpdyFrame> stream1_headers(
5456 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), 5535 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(),
5457 false, 5536 false,
5458 1, 5537 1,
5459 LOWEST, 5538 LOWEST,
5460 HEADERS, 5539 HEADERS,
5461 CONTROL_FLAG_NONE, 5540 CONTROL_FLAG_NONE,
5462 0)); 5541 0));
5463 scoped_ptr<SpdyFrame> stream1_body( 5542 scoped_ptr<SpdyFrame> stream1_body(
5464 spdy_util_.ConstructSpdyBodyFrame(1, true)); 5543 spdy_util_.ConstructSpdyBodyFrame(1, true));
5465 MockRead reads[] = { 5544 MockRead reads[] = {
5466 CreateMockRead(*stream1_reply, 1), 5545 CreateMockRead(*stream1_reply),
5467 CreateMockRead(*stream1_headers, 2), 5546 CreateMockRead(*stream1_headers),
5468 CreateMockRead(*stream1_body, 3), 5547 CreateMockRead(*stream1_body),
5469 MockRead(ASYNC, 0, 5) // EOF 5548 MockRead(ASYNC, 0, 0) // EOF
5470 }; 5549 };
5471 5550
5472 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 5551 DelayedSocketData data(1, reads, arraysize(reads),
5552 writes, arraysize(writes));
5473 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 5553 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
5474 BoundNetLog(), GetParam(), NULL); 5554 BoundNetLog(), GetParam(), NULL);
5475 helper.RunToCompletion(&data); 5555 helper.RunToCompletion(&data);
5476 TransactionHelperResult out = helper.output(); 5556 TransactionHelperResult out = helper.output();
5477 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 5557 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
5478 } 5558 }
5479 5559
5480 TEST_P(SpdyNetworkTransactionTest, SynReplyWithLateHeaders) { 5560 TEST_P(SpdyNetworkTransactionTest, SynReplyWithLateHeaders) {
5481 scoped_ptr<SpdyFrame> req( 5561 scoped_ptr<SpdyFrame> req(
5482 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 5562 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
5483 scoped_ptr<SpdyFrame> rst( 5563 scoped_ptr<SpdyFrame> rst(
5484 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); 5564 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR));
5485 MockWrite writes[] = { 5565 MockWrite writes[] = {
5486 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), 5566 CreateMockWrite(*req),
5567 CreateMockWrite(*rst),
5487 }; 5568 };
5488 5569
5489 scoped_ptr<SpdyFrame> stream1_reply( 5570 scoped_ptr<SpdyFrame> stream1_reply(
5490 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 5571 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
5491 5572
5492 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); 5573 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock());
5493 (*late_headers)["hello"] = "bye"; 5574 (*late_headers)["hello"] = "bye";
5494 scoped_ptr<SpdyFrame> stream1_headers( 5575 scoped_ptr<SpdyFrame> stream1_headers(
5495 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), 5576 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(),
5496 false, 5577 false,
5497 1, 5578 1,
5498 LOWEST, 5579 LOWEST,
5499 HEADERS, 5580 HEADERS,
5500 CONTROL_FLAG_NONE, 5581 CONTROL_FLAG_NONE,
5501 0)); 5582 0));
5502 scoped_ptr<SpdyFrame> stream1_body( 5583 scoped_ptr<SpdyFrame> stream1_body(
5503 spdy_util_.ConstructSpdyBodyFrame(1, false)); 5584 spdy_util_.ConstructSpdyBodyFrame(1, false));
5504 scoped_ptr<SpdyFrame> stream1_body2( 5585 scoped_ptr<SpdyFrame> stream1_body2(
5505 spdy_util_.ConstructSpdyBodyFrame(1, true)); 5586 spdy_util_.ConstructSpdyBodyFrame(1, true));
5506 MockRead reads[] = { 5587 MockRead reads[] = {
5507 CreateMockRead(*stream1_reply, 1), 5588 CreateMockRead(*stream1_reply),
5508 CreateMockRead(*stream1_body, 2), 5589 CreateMockRead(*stream1_body),
5509 CreateMockRead(*stream1_headers, 3), 5590 CreateMockRead(*stream1_headers),
5510 CreateMockRead(*stream1_body2, 5), 5591 CreateMockRead(*stream1_body2),
5511 MockRead(ASYNC, 0, 6) // EOF 5592 MockRead(ASYNC, 0, 0) // EOF
5512 }; 5593 };
5513 5594
5514 DelayedSocketData data(1, reads, arraysize(reads), 5595 DelayedSocketData data(1, reads, arraysize(reads),
5515 writes, arraysize(writes)); 5596 writes, arraysize(writes));
5516 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 5597 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
5517 BoundNetLog(), GetParam(), NULL); 5598 BoundNetLog(), GetParam(), NULL);
5518 helper.RunToCompletion(&data); 5599 helper.RunToCompletion(&data);
5519 TransactionHelperResult out = helper.output(); 5600 TransactionHelperResult out = helper.output();
5520 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 5601 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
5521 } 5602 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5553 const char* url_to_fetch = kTestCases[index]; 5634 const char* url_to_fetch = kTestCases[index];
5554 const char* url_to_push = kTestCases[index + 1]; 5635 const char* url_to_push = kTestCases[index + 1];
5555 5636
5556 scoped_ptr<SpdyFrame> stream1_syn( 5637 scoped_ptr<SpdyFrame> stream1_syn(
5557 spdy_util_.ConstructSpdyGet(url_to_fetch, false, 1, LOWEST)); 5638 spdy_util_.ConstructSpdyGet(url_to_fetch, false, 1, LOWEST));
5558 scoped_ptr<SpdyFrame> stream1_body( 5639 scoped_ptr<SpdyFrame> stream1_body(
5559 spdy_util_.ConstructSpdyBodyFrame(1, true)); 5640 spdy_util_.ConstructSpdyBodyFrame(1, true));
5560 scoped_ptr<SpdyFrame> push_rst( 5641 scoped_ptr<SpdyFrame> push_rst(
5561 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); 5642 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
5562 MockWrite writes[] = { 5643 MockWrite writes[] = {
5563 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*push_rst, 3), 5644 CreateMockWrite(*stream1_syn, 1),
5645 CreateMockWrite(*push_rst, 4),
5564 }; 5646 };
5565 5647
5566 scoped_ptr<SpdyFrame> 5648 scoped_ptr<SpdyFrame>
5567 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 5649 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
5568 scoped_ptr<SpdyFrame> 5650 scoped_ptr<SpdyFrame>
5569 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, 5651 stream2_syn(spdy_util_.ConstructSpdyPush(NULL,
5570 0, 5652 0,
5571 2, 5653 2,
5572 1, 5654 1,
5573 url_to_push)); 5655 url_to_push));
5574 const char kPushedData[] = "pushed"; 5656 const char kPushedData[] = "pushed";
5575 scoped_ptr<SpdyFrame> stream2_body( 5657 scoped_ptr<SpdyFrame> stream2_body(
5576 spdy_util_.ConstructSpdyBodyFrame( 5658 spdy_util_.ConstructSpdyBodyFrame(
5577 2, kPushedData, strlen(kPushedData), true)); 5659 2, kPushedData, strlen(kPushedData), true));
5578 scoped_ptr<SpdyFrame> rst( 5660 scoped_ptr<SpdyFrame> rst(
5579 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); 5661 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL));
5580 5662
5581 MockRead reads[] = { 5663 MockRead reads[] = {
5582 CreateMockRead(*stream1_reply, 1), 5664 CreateMockRead(*stream1_reply, 2),
5583 CreateMockRead(*stream2_syn, 2), 5665 CreateMockRead(*stream2_syn, 3),
5584 CreateMockRead(*stream1_body, 4), 5666 CreateMockRead(*stream1_body, 5, SYNCHRONOUS),
5585 CreateMockRead(*stream2_body, 5), 5667 CreateMockRead(*stream2_body, 6),
5586 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause 5668 MockRead(ASYNC, ERR_IO_PENDING, 7), // Force a pause
5587 }; 5669 };
5588 5670
5589 HttpResponseInfo response; 5671 HttpResponseInfo response;
5590 SequencedSocketData data(reads, arraysize(reads), writes, 5672 OrderedSocketData data(reads, arraysize(reads),
5591 arraysize(writes)); 5673 writes, arraysize(writes));
5592 5674
5593 HttpRequestInfo request; 5675 HttpRequestInfo request;
5594 request.method = "GET"; 5676 request.method = "GET";
5595 request.url = GURL(url_to_fetch); 5677 request.url = GURL(url_to_fetch);
5596 request.load_flags = 0; 5678 request.load_flags = 0;
5597 5679
5598 // Enable cross-origin push. Since we are not using a proxy, this should 5680 // Enable cross-origin push. Since we are not using a proxy, this should
5599 // not actually enable cross-origin SPDY push. 5681 // not actually enable cross-origin SPDY push.
5600 scoped_ptr<SpdySessionDependencies> session_deps( 5682 scoped_ptr<SpdySessionDependencies> session_deps(
5601 CreateSpdySessionDependencies(GetParam())); 5683 CreateSpdySessionDependencies(GetParam()));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5635 } 5717 }
5636 } 5718 }
5637 5719
5638 TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { 5720 TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) {
5639 // Construct the request. 5721 // Construct the request.
5640 scoped_ptr<SpdyFrame> req( 5722 scoped_ptr<SpdyFrame> req(
5641 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 5723 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
5642 scoped_ptr<SpdyFrame> req2( 5724 scoped_ptr<SpdyFrame> req2(
5643 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); 5725 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true));
5644 MockWrite writes[] = { 5726 MockWrite writes[] = {
5645 CreateMockWrite(*req, 0), CreateMockWrite(*req2, 2), 5727 CreateMockWrite(*req, 1),
5728 CreateMockWrite(*req2, 3),
5646 }; 5729 };
5647 5730
5648 scoped_ptr<SpdyFrame> refused( 5731 scoped_ptr<SpdyFrame> refused(
5649 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); 5732 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM));
5650 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); 5733 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
5651 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(3, true)); 5734 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(3, true));
5652 MockRead reads[] = { 5735 MockRead reads[] = {
5653 CreateMockRead(*refused, 1), 5736 CreateMockRead(*refused, 2),
5654 CreateMockRead(*resp, 3), 5737 CreateMockRead(*resp, 4),
5655 CreateMockRead(*body, 4), 5738 CreateMockRead(*body, 5),
5656 MockRead(ASYNC, 0, 5) // EOF 5739 MockRead(ASYNC, 0, 6) // EOF
5657 }; 5740 };
5658 5741
5659 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 5742 OrderedSocketData data(reads, arraysize(reads),
5743 writes, arraysize(writes));
5660 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 5744 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
5661 BoundNetLog(), GetParam(), NULL); 5745 BoundNetLog(), GetParam(), NULL);
5662 5746
5663 helper.RunPreTestSetup(); 5747 helper.RunPreTestSetup();
5664 helper.AddData(&data); 5748 helper.AddData(&data);
5665 5749
5666 HttpNetworkTransaction* trans = helper.trans(); 5750 HttpNetworkTransaction* trans = helper.trans();
5667 5751
5668 // Start the transaction with basic parameters. 5752 // Start the transaction with basic parameters.
5669 TestCompletionCallback callback; 5753 TestCompletionCallback callback;
5670 int rv = trans->Start( 5754 int rv = trans->Start(
5671 &CreateGetRequest(), callback.callback(), BoundNetLog()); 5755 &CreateGetRequest(), callback.callback(), BoundNetLog());
5672 EXPECT_EQ(ERR_IO_PENDING, rv); 5756 EXPECT_EQ(ERR_IO_PENDING, rv);
5673 rv = callback.WaitForResult(); 5757 rv = callback.WaitForResult();
5674 EXPECT_EQ(OK, rv); 5758 EXPECT_EQ(OK, rv);
5675 5759
5676 // Verify that we consumed all test data. 5760 // Verify that we consumed all test data.
5677 EXPECT_TRUE(data.AllReadDataConsumed()); 5761 EXPECT_TRUE(data.AllReadDataConsumed())
5678 EXPECT_TRUE(data.AllWriteDataConsumed()); 5762 << "Read count: " << data.read_count()
5763 << " Read index: " << data.read_index();
5764 EXPECT_TRUE(data.AllWriteDataConsumed())
5765 << "Write count: " << data.write_count()
5766 << " Write index: " << data.write_index();
5679 5767
5680 // Verify the SYN_REPLY. 5768 // Verify the SYN_REPLY.
5681 HttpResponseInfo response = *trans->GetResponseInfo(); 5769 HttpResponseInfo response = *trans->GetResponseInfo();
5682 EXPECT_TRUE(response.headers.get() != NULL); 5770 EXPECT_TRUE(response.headers.get() != NULL);
5683 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 5771 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
5684 } 5772 }
5685 5773
5686 TEST_P(SpdyNetworkTransactionTest, OutOfOrderSynStream) { 5774 TEST_P(SpdyNetworkTransactionTest, OutOfOrderSynStream) {
5687 // This first request will start to establish the SpdySession. 5775 // This first request will start to establish the SpdySession.
5688 // Then we will start the second (MEDIUM priority) and then third 5776 // Then we will start the second (MEDIUM priority) and then third
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
6451 MockRead reads[] = {CreateMockRead(*push, 1)}; 6539 MockRead reads[] = {CreateMockRead(*push, 1)};
6452 6540
6453 scoped_ptr<SpdyFrame> req( 6541 scoped_ptr<SpdyFrame> req(
6454 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 6542 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
6455 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( 6543 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(
6456 0, GOAWAY_PROTOCOL_ERROR, "Odd push stream id.")); 6544 0, GOAWAY_PROTOCOL_ERROR, "Odd push stream id."));
6457 MockWrite writes[] = { 6545 MockWrite writes[] = {
6458 CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2), 6546 CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2),
6459 }; 6547 };
6460 6548
6461 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 6549 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes));
6462 NormalSpdyTransactionHelper helper( 6550 NormalSpdyTransactionHelper helper(
6463 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); 6551 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL);
6464 helper.RunToCompletion(&data); 6552 helper.RunToCompletion(&data);
6465 TransactionHelperResult out = helper.output(); 6553 TransactionHelperResult out = helper.output();
6466 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 6554 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
6467 } 6555 }
6468 6556
6469 TEST_P(SpdyNetworkTransactionTest, 6557 TEST_P(SpdyNetworkTransactionTest,
6470 GoAwayOnPushStreamIdLesserOrEqualThanLastAccepted) { 6558 GoAwayOnPushStreamIdLesserOrEqualThanLastAccepted) {
6471 if (spdy_util_.spdy_version() < SPDY3) 6559 if (spdy_util_.spdy_version() < SPDY3)
(...skipping 13 matching lines...) Expand all
6485 scoped_ptr<SpdyFrame> req( 6573 scoped_ptr<SpdyFrame> req(
6486 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 6574 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
6487 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( 6575 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(
6488 4, 6576 4,
6489 GOAWAY_PROTOCOL_ERROR, 6577 GOAWAY_PROTOCOL_ERROR,
6490 "New push stream id must be greater than the last accepted.")); 6578 "New push stream id must be greater than the last accepted."));
6491 MockWrite writes[] = { 6579 MockWrite writes[] = {
6492 CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 3), 6580 CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 3),
6493 }; 6581 };
6494 6582
6495 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 6583 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes));
6496 NormalSpdyTransactionHelper helper( 6584 NormalSpdyTransactionHelper helper(
6497 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); 6585 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL);
6498 helper.RunToCompletion(&data); 6586 helper.RunToCompletion(&data);
6499 TransactionHelperResult out = helper.output(); 6587 TransactionHelperResult out = helper.output();
6500 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 6588 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
6501 } 6589 }
6502 6590
6503 class SpdyNetworkTransactionNoTLSUsageCheckTest 6591 class SpdyNetworkTransactionNoTLSUsageCheckTest
6504 : public SpdyNetworkTransactionTest { 6592 : public SpdyNetworkTransactionTest {
6505 protected: 6593 protected:
6506 void RunNoTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) { 6594 void RunNoTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) {
6507 // Construct the request. 6595 // Construct the request.
6508 scoped_ptr<SpdyFrame> req( 6596 scoped_ptr<SpdyFrame> req(
6509 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 6597 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
6510 MockWrite writes[] = {CreateMockWrite(*req, 0)}; 6598 MockWrite writes[] = {CreateMockWrite(*req)};
6511 6599
6512 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 6600 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
6513 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); 6601 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
6514 MockRead reads[] = { 6602 MockRead reads[] = {
6515 CreateMockRead(*resp, 1), 6603 CreateMockRead(*resp), CreateMockRead(*body),
6516 CreateMockRead(*body, 2), 6604 MockRead(ASYNC, 0, 0) // EOF
6517 MockRead(ASYNC, 0, 3) // EOF
6518 }; 6605 };
6519 6606
6520 SequencedSocketData data(reads, arraysize(reads), writes, 6607 DelayedSocketData data(
6521 arraysize(writes)); 6608 1, reads, arraysize(reads), writes, arraysize(writes));
6522 HttpRequestInfo request; 6609 HttpRequestInfo request;
6523 request.method = "GET"; 6610 request.method = "GET";
6524 request.url = GURL("https://www.example.org/"); 6611 request.url = GURL("https://www.example.org/");
6525 NormalSpdyTransactionHelper helper( 6612 NormalSpdyTransactionHelper helper(
6526 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); 6613 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL);
6527 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); 6614 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass());
6528 TransactionHelperResult out = helper.output(); 6615 TransactionHelperResult out = helper.output();
6529 EXPECT_EQ(OK, out.rv); 6616 EXPECT_EQ(OK, out.rv);
6530 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 6617 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
6531 EXPECT_EQ("hello!", out.response_data); 6618 EXPECT_EQ("hello!", out.response_data);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
6563 } 6650 }
6564 6651
6565 class SpdyNetworkTransactionTLSUsageCheckTest 6652 class SpdyNetworkTransactionTLSUsageCheckTest
6566 : public SpdyNetworkTransactionTest { 6653 : public SpdyNetworkTransactionTest {
6567 protected: 6654 protected:
6568 void RunTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) { 6655 void RunTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) {
6569 scoped_ptr<SpdyFrame> goaway( 6656 scoped_ptr<SpdyFrame> goaway(
6570 spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, "")); 6657 spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, ""));
6571 MockWrite writes[] = {CreateMockWrite(*goaway)}; 6658 MockWrite writes[] = {CreateMockWrite(*goaway)};
6572 6659
6573 StaticSocketDataProvider data(NULL, 0, writes, arraysize(writes)); 6660 DelayedSocketData data(1, NULL, 0, writes, arraysize(writes));
6574 HttpRequestInfo request; 6661 HttpRequestInfo request;
6575 request.method = "GET"; 6662 request.method = "GET";
6576 request.url = GURL("https://www.example.org/"); 6663 request.url = GURL("https://www.example.org/");
6577 NormalSpdyTransactionHelper helper( 6664 NormalSpdyTransactionHelper helper(
6578 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); 6665 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL);
6579 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); 6666 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass());
6580 TransactionHelperResult out = helper.output(); 6667 TransactionHelperResult out = helper.output();
6581 EXPECT_EQ(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, out.rv); 6668 EXPECT_EQ(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, out.rv);
6582 } 6669 }
6583 }; 6670 };
(...skipping 17 matching lines...) Expand all
6601 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { 6688 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) {
6602 scoped_ptr<SSLSocketDataProvider> ssl_provider( 6689 scoped_ptr<SSLSocketDataProvider> ssl_provider(
6603 new SSLSocketDataProvider(ASYNC, OK)); 6690 new SSLSocketDataProvider(ASYNC, OK));
6604 // Set to TLS_RSA_WITH_NULL_MD5 6691 // Set to TLS_RSA_WITH_NULL_MD5
6605 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); 6692 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status);
6606 6693
6607 RunTLSUsageCheckTest(ssl_provider.Pass()); 6694 RunTLSUsageCheckTest(ssl_provider.Pass());
6608 } 6695 }
6609 6696
6610 } // namespace net 6697 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698