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/chromium/quic_http_stream.h" | 5 #include "net/quic/chromium/quic_http_stream.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 | 172 |
173 std::unique_ptr<QuicHttpStream> stream_; | 173 std::unique_ptr<QuicHttpStream> stream_; |
174 CompletionCallback callback_; | 174 CompletionCallback callback_; |
175 }; | 175 }; |
176 | 176 |
177 } // namespace | 177 } // namespace |
178 | 178 |
179 class QuicHttpStreamPeer { | 179 class QuicHttpStreamPeer { |
180 public: | 180 public: |
181 static QuicChromiumClientStream* GetQuicChromiumClientStream( | 181 static QuicChromiumClientStream::Handle* GetQuicChromiumClientStream( |
182 QuicHttpStream* stream) { | 182 QuicHttpStream* stream) { |
183 return stream->stream_; | 183 return stream->stream_.get(); |
184 } | 184 } |
185 }; | 185 }; |
186 | 186 |
187 class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { | 187 class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { |
188 protected: | 188 protected: |
189 static const bool kFin = true; | 189 static const bool kFin = true; |
190 static const bool kIncludeVersion = true; | 190 static const bool kIncludeVersion = true; |
191 static const bool kIncludeCongestionFeedback = true; | 191 static const bool kIncludeCongestionFeedback = true; |
192 | 192 |
193 // Holds a packet to be written to the wire, and the IO mode that should | 193 // Holds a packet to be written to the wire, and the IO mode that should |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 !kIncludeCongestionFeedback); | 529 !kIncludeCongestionFeedback); |
530 } | 530 } |
531 | 531 |
532 std::unique_ptr<QuicReceivedPacket> ConstructInitialSettingsPacket( | 532 std::unique_ptr<QuicReceivedPacket> ConstructInitialSettingsPacket( |
533 QuicStreamOffset* offset) { | 533 QuicStreamOffset* offset) { |
534 return client_maker_.MakeInitialSettingsPacket(1, offset); | 534 return client_maker_.MakeInitialSettingsPacket(1, offset); |
535 } | 535 } |
536 | 536 |
537 void ReceivePromise(QuicStreamId id) { | 537 void ReceivePromise(QuicStreamId id) { |
538 auto headers = AsHeaderList(push_promise_); | 538 auto headers = AsHeaderList(push_promise_); |
539 QuicChromiumClientStream* stream = | 539 QuicChromiumClientStream::Handle* stream = |
540 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); | 540 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
541 stream->OnPromiseHeaderList(id, headers.uncompressed_header_bytes(), | 541 stream->OnPromiseHeaderList(id, headers.uncompressed_header_bytes(), |
542 headers); | 542 headers); |
543 } | 543 } |
544 | 544 |
545 void ExpectLoadTimingValid(const LoadTimingInfo& load_timing_info, | 545 void ExpectLoadTimingValid(const LoadTimingInfo& load_timing_info, |
546 bool session_reused) { | 546 bool session_reused) { |
547 EXPECT_EQ(session_reused, load_timing_info.socket_reused); | 547 EXPECT_EQ(session_reused, load_timing_info.socket_reused); |
548 if (session_reused) { | 548 if (session_reused) { |
549 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 549 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 Initialize(); | 624 Initialize(); |
625 EXPECT_FALSE(stream_->CanReuseConnection()); | 625 EXPECT_FALSE(stream_->CanReuseConnection()); |
626 } | 626 } |
627 | 627 |
628 TEST_P(QuicHttpStreamTest, DisableConnectionMigrationForStream) { | 628 TEST_P(QuicHttpStreamTest, DisableConnectionMigrationForStream) { |
629 request_.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION; | 629 request_.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION; |
630 Initialize(); | 630 Initialize(); |
631 EXPECT_EQ(OK, | 631 EXPECT_EQ(OK, |
632 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 632 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
633 net_log_.bound(), callback_.callback())); | 633 net_log_.bound(), callback_.callback())); |
634 QuicChromiumClientStream* client_stream = | 634 QuicChromiumClientStream::Handle* client_stream = |
635 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); | 635 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
636 EXPECT_FALSE(client_stream->can_migrate()); | 636 EXPECT_FALSE(client_stream->can_migrate()); |
637 } | 637 } |
638 | 638 |
639 TEST_P(QuicHttpStreamTest, GetRequest) { | 639 TEST_P(QuicHttpStreamTest, GetRequest) { |
640 SetRequest("GET", "/", DEFAULT_PRIORITY); | 640 SetRequest("GET", "/", DEFAULT_PRIORITY); |
641 size_t spdy_request_header_frame_length; | 641 size_t spdy_request_header_frame_length; |
642 QuicStreamOffset header_stream_offset = 0; | 642 QuicStreamOffset header_stream_offset = 0; |
643 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 643 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
644 AddWrite(InnerConstructRequestHeadersPacket( | 644 AddWrite(InnerConstructRequestHeadersPacket( |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 use_closing_stream_ = true; | 1459 use_closing_stream_ = true; |
1460 Initialize(); | 1460 Initialize(); |
1461 | 1461 |
1462 request_.method = "GET"; | 1462 request_.method = "GET"; |
1463 request_.url = GURL("https://www.example.org/"); | 1463 request_.url = GURL("https://www.example.org/"); |
1464 | 1464 |
1465 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), | 1465 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), |
1466 callback_.callback())); | 1466 callback_.callback())); |
1467 | 1467 |
1468 // Check that priority is highest. | 1468 // Check that priority is highest. |
1469 QuicChromiumClientStream* reliable_stream = | 1469 QuicChromiumClientStream::Handle* reliable_stream = |
1470 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); | 1470 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
1471 DCHECK(reliable_stream); | 1471 DCHECK(reliable_stream); |
1472 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); | 1472 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); |
1473 | 1473 |
1474 EXPECT_EQ(OK, | 1474 EXPECT_EQ(OK, |
1475 stream_->SendRequest(headers_, &response_, callback_.callback())); | 1475 stream_->SendRequest(headers_, &response_, callback_.callback())); |
1476 | 1476 |
1477 // Check that priority has now dropped back to MEDIUM. | 1477 // Check that priority has now dropped back to MEDIUM. |
1478 DCHECK_EQ(MEDIUM, | 1478 DCHECK_EQ(MEDIUM, |
1479 ConvertQuicPriorityToRequestPriority(reliable_stream->priority())); | 1479 ConvertQuicPriorityToRequestPriority(reliable_stream->priority())); |
(...skipping 30 matching lines...) Expand all Loading... |
1510 | 1510 |
1511 Initialize(); | 1511 Initialize(); |
1512 | 1512 |
1513 request_.method = "GET"; | 1513 request_.method = "GET"; |
1514 request_.url = GURL("https://www.example.org/"); | 1514 request_.url = GURL("https://www.example.org/"); |
1515 | 1515 |
1516 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), | 1516 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), |
1517 callback_.callback())); | 1517 callback_.callback())); |
1518 | 1518 |
1519 // Check that priority is highest. | 1519 // Check that priority is highest. |
1520 QuicChromiumClientStream* reliable_stream = | 1520 QuicChromiumClientStream::Handle* reliable_stream = |
1521 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); | 1521 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
1522 DCHECK(reliable_stream); | 1522 DCHECK(reliable_stream); |
1523 QuicChromiumClientStream::Delegate* delegate = reliable_stream->GetDelegate(); | 1523 QuicChromiumClientStream::Delegate* delegate = reliable_stream->GetDelegate(); |
1524 DCHECK(delegate); | 1524 DCHECK(delegate); |
1525 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); | 1525 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); |
1526 | 1526 |
1527 // Set Delegate to nullptr and make sure Priority returns highest | 1527 // Set Delegate to nullptr and make sure Priority returns highest |
1528 // priority. | 1528 // priority. |
1529 reliable_stream->SetDelegate(nullptr); | 1529 reliable_stream->ClearDelegate(); |
1530 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); | 1530 DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); |
1531 reliable_stream->SetDelegate(delegate); | |
1532 | 1531 |
1533 EXPECT_EQ(0, stream_->GetTotalSentBytes()); | 1532 EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
1534 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); | 1533 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
1535 } | 1534 } |
1536 | 1535 |
1537 TEST_P(QuicHttpStreamTest, SessionClosedDuringDoLoop) { | 1536 TEST_P(QuicHttpStreamTest, SessionClosedDuringDoLoop) { |
1538 SetRequest("POST", "/", DEFAULT_PRIORITY); | 1537 SetRequest("POST", "/", DEFAULT_PRIORITY); |
1539 size_t spdy_request_headers_frame_length; | 1538 size_t spdy_request_headers_frame_length; |
1540 QuicStreamOffset header_stream_offset = 0; | 1539 QuicStreamOffset header_stream_offset = 0; |
1541 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 1540 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2172 EXPECT_TRUE(AtEof()); | 2171 EXPECT_TRUE(AtEof()); |
2173 | 2172 |
2174 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. | 2173 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
2175 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 2174 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
2176 stream_->GetTotalSentBytes()); | 2175 stream_->GetTotalSentBytes()); |
2177 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); | 2176 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
2178 } | 2177 } |
2179 | 2178 |
2180 } // namespace test | 2179 } // namespace test |
2181 } // namespace net | 2180 } // namespace net |
OLD | NEW |