| 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/quic/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "net/base/chunked_upload_data_stream.h" | 10 #include "net/base/chunked_upload_data_stream.h" |
| 11 #include "net/base/elements_upload_data_stream.h" | 11 #include "net/base/elements_upload_data_stream.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "net/base/upload_bytes_element_reader.h" | 14 #include "net/base/upload_bytes_element_reader.h" |
| 15 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
| 16 #include "net/http/transport_security_state.h" | 16 #include "net/http/transport_security_state.h" |
| 17 #include "net/quic/congestion_control/send_algorithm_interface.h" | 17 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 18 #include "net/quic/crypto/crypto_protocol.h" | 18 #include "net/quic/crypto/crypto_protocol.h" |
| 19 #include "net/quic/crypto/quic_decrypter.h" | 19 #include "net/quic/crypto/quic_decrypter.h" |
| 20 #include "net/quic/crypto/quic_encrypter.h" | 20 #include "net/quic/crypto/quic_encrypter.h" |
| 21 #include "net/quic/crypto/quic_server_info.h" | 21 #include "net/quic/crypto/quic_server_info.h" |
| 22 #include "net/quic/quic_client_session.h" | 22 #include "net/quic/quic_client_session.h" |
| 23 #include "net/quic/quic_connection.h" | 23 #include "net/quic/quic_connection.h" |
| 24 #include "net/quic/quic_connection_helper.h" | 24 #include "net/quic/quic_connection_helper.h" |
| 25 #include "net/quic/quic_default_packet_writer.h" | 25 #include "net/quic/quic_default_packet_writer.h" |
| 26 #include "net/quic/quic_flags.h" |
| 26 #include "net/quic/quic_http_utils.h" | 27 #include "net/quic/quic_http_utils.h" |
| 27 #include "net/quic/quic_reliable_client_stream.h" | 28 #include "net/quic/quic_reliable_client_stream.h" |
| 28 #include "net/quic/quic_write_blocked_list.h" | 29 #include "net/quic/quic_write_blocked_list.h" |
| 29 #include "net/quic/spdy_utils.h" | 30 #include "net/quic/spdy_utils.h" |
| 30 #include "net/quic/test_tools/mock_clock.h" | 31 #include "net/quic/test_tools/mock_clock.h" |
| 31 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" | 32 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
| 32 #include "net/quic/test_tools/mock_random.h" | 33 #include "net/quic/test_tools/mock_random.h" |
| 33 #include "net/quic/test_tools/quic_connection_peer.h" | 34 #include "net/quic/test_tools/quic_connection_peer.h" |
| 34 #include "net/quic/test_tools/quic_test_packet_maker.h" | 35 #include "net/quic/test_tools/quic_test_packet_maker.h" |
| 35 #include "net/quic/test_tools/quic_test_utils.h" | 36 #include "net/quic/test_tools/quic_test_utils.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 sequence_number, stream_id_, !kIncludeVersion, fin, response_headers_); | 268 sequence_number, stream_id_, !kIncludeVersion, fin, response_headers_); |
| 268 } | 269 } |
| 269 | 270 |
| 270 scoped_ptr<QuicEncryptedPacket> ConstructRstStreamPacket( | 271 scoped_ptr<QuicEncryptedPacket> ConstructRstStreamPacket( |
| 271 QuicPacketSequenceNumber sequence_number) { | 272 QuicPacketSequenceNumber sequence_number) { |
| 272 return maker_.MakeRstPacket( | 273 return maker_.MakeRstPacket( |
| 273 sequence_number, true, stream_id_, | 274 sequence_number, true, stream_id_, |
| 274 AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam())); | 275 AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam())); |
| 275 } | 276 } |
| 276 | 277 |
| 278 scoped_ptr<QuicEncryptedPacket> ConstructRstStreamCancelledPacket( |
| 279 QuicPacketSequenceNumber sequence_number) { |
| 280 return maker_.MakeRstPacket(sequence_number, !kIncludeVersion, stream_id_, |
| 281 QUIC_STREAM_CANCELLED); |
| 282 } |
| 283 |
| 277 scoped_ptr<QuicEncryptedPacket> ConstructAckAndRstStreamPacket( | 284 scoped_ptr<QuicEncryptedPacket> ConstructAckAndRstStreamPacket( |
| 278 QuicPacketSequenceNumber sequence_number) { | 285 QuicPacketSequenceNumber sequence_number) { |
| 279 return maker_.MakeAckAndRstPacket( | 286 return maker_.MakeAckAndRstPacket( |
| 280 sequence_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, | 287 sequence_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, |
| 281 2, 1, !kIncludeCongestionFeedback); | 288 2, 1, !kIncludeCongestionFeedback); |
| 282 } | 289 } |
| 283 | 290 |
| 284 scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( | 291 scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( |
| 285 QuicPacketSequenceNumber sequence_number, | 292 QuicPacketSequenceNumber sequence_number, |
| 286 QuicPacketSequenceNumber largest_received, | 293 QuicPacketSequenceNumber largest_received, |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), | 663 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 657 callback_.callback())); | 664 callback_.callback())); |
| 658 | 665 |
| 659 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 666 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 660 EXPECT_TRUE(AtEof()); | 667 EXPECT_TRUE(AtEof()); |
| 661 } | 668 } |
| 662 | 669 |
| 663 TEST_P(QuicHttpStreamTest, DestroyedEarly) { | 670 TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
| 664 SetRequest("GET", "/", DEFAULT_PRIORITY); | 671 SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 665 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY)); | 672 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY)); |
| 666 AddWrite(ConstructAckAndRstStreamPacket(2)); | 673 if (FLAGS_quic_process_frames_inline) { |
| 674 AddWrite(ConstructRstStreamCancelledPacket(2)); |
| 675 } else { |
| 676 AddWrite(ConstructAckAndRstStreamPacket(2)); |
| 677 } |
| 667 use_closing_stream_ = true; | 678 use_closing_stream_ = true; |
| 668 Initialize(); | 679 Initialize(); |
| 669 | 680 |
| 670 request_.method = "GET"; | 681 request_.method = "GET"; |
| 671 request_.url = GURL("http://www.google.com/"); | 682 request_.url = GURL("http://www.google.com/"); |
| 672 | 683 |
| 673 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 684 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 674 net_log_, callback_.callback())); | 685 net_log_, callback_.callback())); |
| 675 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, | 686 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 676 callback_.callback())); | 687 callback_.callback())); |
| 677 | 688 |
| 678 // Ack the request. | 689 // Ack the request. |
| 679 ProcessPacket(ConstructAckPacket(1, 0, 0)); | 690 ProcessPacket(ConstructAckPacket(1, 0, 0)); |
| 680 EXPECT_EQ(ERR_IO_PENDING, | 691 EXPECT_EQ(ERR_IO_PENDING, |
| 681 stream_->ReadResponseHeaders(callback_.callback())); | 692 stream_->ReadResponseHeaders(callback_.callback())); |
| 682 | 693 |
| 683 // Send the response with a body. | 694 // Send the response with a body. |
| 684 SetResponse("404 OK", "hello world!"); | 695 SetResponse("404 OK", "hello world!"); |
| 685 // In the course of processing this packet, the QuicHttpStream close itself. | 696 // In the course of processing this packet, the QuicHttpStream close itself. |
| 686 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); | 697 ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); |
| 687 | 698 |
| 688 EXPECT_TRUE(AtEof()); | 699 EXPECT_TRUE(AtEof()); |
| 689 } | 700 } |
| 690 | 701 |
| 691 TEST_P(QuicHttpStreamTest, Priority) { | 702 TEST_P(QuicHttpStreamTest, Priority) { |
| 692 SetRequest("GET", "/", MEDIUM); | 703 SetRequest("GET", "/", MEDIUM); |
| 693 AddWrite(ConstructRequestHeadersPacket(1, kFin, MEDIUM)); | 704 AddWrite(ConstructRequestHeadersPacket(1, kFin, MEDIUM)); |
| 694 AddWrite(ConstructAckAndRstStreamPacket(2)); | 705 if (FLAGS_quic_process_frames_inline) { |
| 706 AddWrite(ConstructRstStreamCancelledPacket(2)); |
| 707 } else { |
| 708 AddWrite(ConstructAckAndRstStreamPacket(2)); |
| 709 } |
| 695 use_closing_stream_ = true; | 710 use_closing_stream_ = true; |
| 696 Initialize(); | 711 Initialize(); |
| 697 | 712 |
| 698 request_.method = "GET"; | 713 request_.method = "GET"; |
| 699 request_.url = GURL("http://www.google.com/"); | 714 request_.url = GURL("http://www.google.com/"); |
| 700 | 715 |
| 701 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, | 716 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, |
| 702 net_log_, callback_.callback())); | 717 net_log_, callback_.callback())); |
| 703 | 718 |
| 704 // Check that priority is highest. | 719 // Check that priority is highest. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 // Set Delegate to nullptr and make sure EffectivePriority returns highest | 770 // Set Delegate to nullptr and make sure EffectivePriority returns highest |
| 756 // priority. | 771 // priority. |
| 757 reliable_stream->SetDelegate(nullptr); | 772 reliable_stream->SetDelegate(nullptr); |
| 758 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, | 773 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
| 759 reliable_stream->EffectivePriority()); | 774 reliable_stream->EffectivePriority()); |
| 760 reliable_stream->SetDelegate(delegate); | 775 reliable_stream->SetDelegate(delegate); |
| 761 } | 776 } |
| 762 | 777 |
| 763 } // namespace test | 778 } // namespace test |
| 764 } // namespace net | 779 } // namespace net |
| OLD | NEW |