OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 deterministic_data()->RunFor(3); | 182 deterministic_data()->RunFor(3); |
183 | 183 |
184 callback.WaitForResult(); | 184 callback.WaitForResult(); |
185 | 185 |
186 // Can get timing information once the stream connects. | 186 // Can get timing information once the stream connects. |
187 TestLoadTimingNotReused(*http_stream); | 187 TestLoadTimingNotReused(*http_stream); |
188 | 188 |
189 // Because we abandoned the stream, we don't expect to find a session in the | 189 // Because we abandoned the stream, we don't expect to find a session in the |
190 // pool anymore. | 190 // pool anymore. |
191 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 191 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
192 EXPECT_TRUE(deterministic_data()->AllReadDataConsumed()); | 192 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
193 EXPECT_TRUE(deterministic_data()->AllWriteDataConsumed()); | 193 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
194 | 194 |
195 TestLoadTimingNotReused(*http_stream); | 195 TestLoadTimingNotReused(*http_stream); |
196 http_stream->Close(true); | 196 http_stream->Close(true); |
197 // Test that there's no crash when trying to get the load timing after the | 197 // Test that there's no crash when trying to get the load timing after the |
198 // stream has been closed. | 198 // stream has been closed. |
199 TestLoadTimingNotReused(*http_stream); | 199 TestLoadTimingNotReused(*http_stream); |
200 } | 200 } |
201 | 201 |
202 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { | 202 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { |
203 scoped_ptr<SpdyFrame> req1( | 203 scoped_ptr<SpdyFrame> req1( |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( | 344 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( |
345 headers, &response, callback.callback())); | 345 headers, &response, callback.callback())); |
346 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 346 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
347 | 347 |
348 deterministic_data()->RunFor(seq); | 348 deterministic_data()->RunFor(seq); |
349 callback.WaitForResult(); | 349 callback.WaitForResult(); |
350 | 350 |
351 // Because we abandoned the stream, we don't expect to find a session in the | 351 // Because we abandoned the stream, we don't expect to find a session in the |
352 // pool anymore. | 352 // pool anymore. |
353 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 353 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
354 EXPECT_TRUE(deterministic_data()->AllReadDataConsumed()); | 354 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
355 EXPECT_TRUE(deterministic_data()->AllWriteDataConsumed()); | 355 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
356 } | 356 } |
357 | 357 |
358 // Test to ensure the SpdyStream state machine does not get confused when a | 358 // Test to ensure the SpdyStream state machine does not get confused when a |
359 // chunk becomes available while a write is pending. | 359 // chunk becomes available while a write is pending. |
360 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { | 360 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { |
361 const char kUploadData1[] = "12345678"; | 361 const char kUploadData1[] = "12345678"; |
362 const int kUploadData1Size = arraysize(kUploadData1)-1; | 362 const int kUploadData1Size = arraysize(kUploadData1)-1; |
363 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 363 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
364 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 364 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
365 scoped_ptr<SpdyFrame> chunk2( | 365 scoped_ptr<SpdyFrame> chunk2( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 scoped_refptr<IOBuffer> buf3(new IOBuffer(kUploadDataSize)); | 447 scoped_refptr<IOBuffer> buf3(new IOBuffer(kUploadDataSize)); |
448 ASSERT_EQ(kUploadDataSize, | 448 ASSERT_EQ(kUploadDataSize, |
449 http_stream->ReadResponseBody( | 449 http_stream->ReadResponseBody( |
450 buf3.get(), kUploadDataSize, callback.callback())); | 450 buf3.get(), kUploadDataSize, callback.callback())); |
451 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); | 451 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); |
452 | 452 |
453 // Finish reading the |EOF|. | 453 // Finish reading the |EOF|. |
454 deterministic_data()->RunFor(1); | 454 deterministic_data()->RunFor(1); |
455 ASSERT_TRUE(response.headers.get()); | 455 ASSERT_TRUE(response.headers.get()); |
456 ASSERT_EQ(200, response.headers->response_code()); | 456 ASSERT_EQ(200, response.headers->response_code()); |
457 EXPECT_TRUE(deterministic_data()->AllReadDataConsumed()); | 457 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
458 EXPECT_TRUE(deterministic_data()->AllWriteDataConsumed()); | 458 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
459 } | 459 } |
460 | 460 |
461 // Test that the SpdyStream state machine can handle sending a final empty data | 461 // Test that the SpdyStream state machine can handle sending a final empty data |
462 // frame when uploading a chunked data stream. | 462 // frame when uploading a chunked data stream. |
463 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { | 463 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { |
464 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 464 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
465 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 465 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
466 scoped_ptr<SpdyFrame> chunk2( | 466 scoped_ptr<SpdyFrame> chunk2( |
467 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 467 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); |
468 MockWrite writes[] = { | 468 MockWrite writes[] = { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 // Read and check |chunk2| response. | 533 // Read and check |chunk2| response. |
534 deterministic_data()->RunFor(1); | 534 deterministic_data()->RunFor(1); |
535 ASSERT_EQ(0, | 535 ASSERT_EQ(0, |
536 http_stream->ReadResponseBody( | 536 http_stream->ReadResponseBody( |
537 buf1.get(), kUploadDataSize, callback.callback())); | 537 buf1.get(), kUploadDataSize, callback.callback())); |
538 | 538 |
539 // Finish reading the |EOF|. | 539 // Finish reading the |EOF|. |
540 deterministic_data()->RunFor(1); | 540 deterministic_data()->RunFor(1); |
541 ASSERT_TRUE(response.headers.get()); | 541 ASSERT_TRUE(response.headers.get()); |
542 ASSERT_EQ(200, response.headers->response_code()); | 542 ASSERT_EQ(200, response.headers->response_code()); |
543 EXPECT_TRUE(deterministic_data()->AllReadDataConsumed()); | 543 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
544 EXPECT_TRUE(deterministic_data()->AllWriteDataConsumed()); | 544 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
545 } | 545 } |
546 | 546 |
547 // Test that the SpdyStream state machine handles a chunked upload with no | 547 // Test that the SpdyStream state machine handles a chunked upload with no |
548 // payload. Unclear if this is a case worth supporting. | 548 // payload. Unclear if this is a case worth supporting. |
549 TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) { | 549 TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) { |
550 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 550 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
551 scoped_ptr<SpdyFrame> chunk( | 551 scoped_ptr<SpdyFrame> chunk( |
552 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 552 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); |
553 MockWrite writes[] = { | 553 MockWrite writes[] = { |
554 CreateMockWrite(*req.get(), 0), | 554 CreateMockWrite(*req.get(), 0), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 deterministic_data()->RunFor(1); | 603 deterministic_data()->RunFor(1); |
604 scoped_refptr<IOBuffer> buf(new IOBuffer(1)); | 604 scoped_refptr<IOBuffer> buf(new IOBuffer(1)); |
605 ASSERT_EQ(0, | 605 ASSERT_EQ(0, |
606 http_stream->ReadResponseBody( | 606 http_stream->ReadResponseBody( |
607 buf.get(), 1, callback.callback())); | 607 buf.get(), 1, callback.callback())); |
608 | 608 |
609 // Finish reading the |EOF|. | 609 // Finish reading the |EOF|. |
610 deterministic_data()->RunFor(1); | 610 deterministic_data()->RunFor(1); |
611 ASSERT_TRUE(response.headers.get()); | 611 ASSERT_TRUE(response.headers.get()); |
612 ASSERT_EQ(200, response.headers->response_code()); | 612 ASSERT_EQ(200, response.headers->response_code()); |
613 EXPECT_TRUE(deterministic_data()->AllReadDataConsumed()); | 613 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
614 EXPECT_TRUE(deterministic_data()->AllWriteDataConsumed()); | 614 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
615 } | 615 } |
616 | 616 |
617 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 617 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
618 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { | 618 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { |
619 const char* const full_url = "http://www.example.org/foo?query=what#anchor"; | 619 const char* const full_url = "http://www.example.org/foo?query=what#anchor"; |
620 const char* const base_url = "http://www.example.org/foo?query=what"; | 620 const char* const base_url = "http://www.example.org/foo?query=what"; |
621 scoped_ptr<SpdyFrame> req( | 621 scoped_ptr<SpdyFrame> req( |
622 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); | 622 spdy_util_.ConstructSpdyGet(base_url, false, 1, LOWEST)); |
623 MockWrite writes[] = { | 623 MockWrite writes[] = { |
624 CreateMockWrite(*req.get(), 0), | 624 CreateMockWrite(*req.get(), 0), |
(...skipping 24 matching lines...) Expand all Loading... |
649 callback.callback())); | 649 callback.callback())); |
650 | 650 |
651 EXPECT_EQ(base_url, http_stream->stream()->GetUrlFromHeaders().spec()); | 651 EXPECT_EQ(base_url, http_stream->stream()->GetUrlFromHeaders().spec()); |
652 | 652 |
653 deterministic_data()->RunFor(3); | 653 deterministic_data()->RunFor(3); |
654 callback.WaitForResult(); | 654 callback.WaitForResult(); |
655 | 655 |
656 // Because we abandoned the stream, we don't expect to find a session in the | 656 // Because we abandoned the stream, we don't expect to find a session in the |
657 // pool anymore. | 657 // pool anymore. |
658 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 658 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); |
659 EXPECT_TRUE(deterministic_data()->AllReadDataConsumed()); | 659 EXPECT_TRUE(deterministic_data()->at_read_eof()); |
660 EXPECT_TRUE(deterministic_data()->AllWriteDataConsumed()); | 660 EXPECT_TRUE(deterministic_data()->at_write_eof()); |
661 } | 661 } |
662 | 662 |
663 // The tests below are only for SPDY/3 and above. | 663 // The tests below are only for SPDY/3 and above. |
664 | 664 |
665 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | 665 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be |
666 // made available is handled correctly. | 666 // made available is handled correctly. |
667 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { | 667 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { |
668 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 668 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
669 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 669 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
670 MockWrite writes[] = { | 670 MockWrite writes[] = { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 740 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
741 ASSERT_EQ(kUploadDataSize, | 741 ASSERT_EQ(kUploadDataSize, |
742 http_stream->ReadResponseBody( | 742 http_stream->ReadResponseBody( |
743 buf1.get(), kUploadDataSize, callback.callback())); | 743 buf1.get(), kUploadDataSize, callback.callback())); |
744 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 744 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
745 | 745 |
746 // Finish reading the |EOF|. | 746 // Finish reading the |EOF|. |
747 deterministic_data_->RunFor(1); | 747 deterministic_data_->RunFor(1); |
748 ASSERT_TRUE(response.headers.get()); | 748 ASSERT_TRUE(response.headers.get()); |
749 ASSERT_EQ(200, response.headers->response_code()); | 749 ASSERT_EQ(200, response.headers->response_code()); |
750 EXPECT_TRUE(deterministic_data_->AllReadDataConsumed()); | 750 EXPECT_TRUE(deterministic_data_->at_read_eof()); |
751 EXPECT_TRUE(deterministic_data_->AllWriteDataConsumed()); | 751 EXPECT_TRUE(deterministic_data_->at_write_eof()); |
752 } | 752 } |
753 | 753 |
754 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 754 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
755 // methods. | 755 // methods. |
756 | 756 |
757 } // namespace net | 757 } // namespace net |
OLD | NEW |