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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 using testing::AnyNumber; | 67 using testing::AnyNumber; |
68 using testing::Return; | 68 using testing::Return; |
69 | 69 |
70 namespace net { | 70 namespace net { |
71 namespace test { | 71 namespace test { |
72 namespace { | 72 namespace { |
73 | 73 |
74 const char kUploadData[] = "Really nifty data!"; | 74 const char kUploadData[] = "Really nifty data!"; |
75 const char kDefaultServerHostName[] = "www.example.org"; | 75 const char kDefaultServerHostName[] = "www.example.org"; |
76 const uint16_t kDefaultServerPort = 80; | 76 const uint16_t kDefaultServerPort = 80; |
| 77 const bool kMarkQuicBrokenWhenNetworkSuspected = true; |
77 | 78 |
78 class TestQuicConnection : public QuicConnection { | 79 class TestQuicConnection : public QuicConnection { |
79 public: | 80 public: |
80 TestQuicConnection(const QuicVersionVector& versions, | 81 TestQuicConnection(const QuicVersionVector& versions, |
81 QuicConnectionId connection_id, | 82 QuicConnectionId connection_id, |
82 IPEndPoint address, | 83 IPEndPoint address, |
83 QuicChromiumConnectionHelper* helper, | 84 QuicChromiumConnectionHelper* helper, |
84 QuicChromiumAlarmFactory* alarm_factory, | 85 QuicChromiumAlarmFactory* alarm_factory, |
85 QuicPacketWriter* writer) | 86 QuicPacketWriter* writer) |
86 : QuicConnection(connection_id, | 87 : QuicConnection(connection_id, |
87 QuicSocketAddress(QuicSocketAddressImpl(address)), | 88 QuicSocketAddress(QuicSocketAddressImpl(address)), |
88 helper, | 89 helper, |
89 alarm_factory, | 90 alarm_factory, |
90 writer, | 91 writer, |
91 true /* owns_writer */, | 92 true /* owns_writer */, |
92 Perspective::IS_CLIENT, | 93 Perspective::IS_CLIENT, |
93 versions) {} | 94 versions) {} |
94 | 95 |
95 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 96 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
96 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 97 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
97 } | 98 } |
98 }; | 99 }; |
99 | 100 |
100 // Subclass of QuicHttpStream that closes itself when the first piece of data | 101 // Subclass of QuicHttpStream that closes itself when the first piece of data |
101 // is received. | 102 // is received. |
102 class AutoClosingStream : public QuicHttpStream { | 103 class AutoClosingStream : public QuicHttpStream { |
103 public: | 104 public: |
104 explicit AutoClosingStream( | 105 explicit AutoClosingStream( |
105 const base::WeakPtr<QuicChromiumClientSession>& session, | 106 const base::WeakPtr<QuicChromiumClientSession>& session, |
106 HttpServerProperties* http_server_properties) | 107 HttpServerProperties* http_server_properties, |
107 : QuicHttpStream(session, http_server_properties) {} | 108 bool mark_quic_broken_when_network_suspected) |
| 109 : QuicHttpStream(session, |
| 110 http_server_properties, |
| 111 mark_quic_broken_when_network_suspected) {} |
108 | 112 |
109 void OnHeadersAvailable(const SpdyHeaderBlock& headers, | 113 void OnHeadersAvailable(const SpdyHeaderBlock& headers, |
110 size_t frame_len) override { | 114 size_t frame_len) override { |
111 Close(false); | 115 Close(false); |
112 } | 116 } |
113 | 117 |
114 void OnDataAvailable() override { Close(false); } | 118 void OnDataAvailable() override { Close(false); } |
115 }; | 119 }; |
116 | 120 |
117 // UploadDataStream that always returns errors on data read. | 121 // UploadDataStream that always returns errors on data read. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), | 329 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), |
326 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, | 330 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, |
327 "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, | 331 "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, |
328 base::ThreadTaskRunnerHandle::Get().get(), | 332 base::ThreadTaskRunnerHandle::Get().get(), |
329 /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); | 333 /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); |
330 session_->Initialize(); | 334 session_->Initialize(); |
331 TestCompletionCallback callback; | 335 TestCompletionCallback callback; |
332 session_->CryptoConnect(callback.callback()); | 336 session_->CryptoConnect(callback.callback()); |
333 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); | 337 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); |
334 stream_.reset(use_closing_stream_ | 338 stream_.reset(use_closing_stream_ |
335 ? new AutoClosingStream(session_->GetWeakPtr(), | 339 ? new AutoClosingStream( |
336 &http_server_properties_) | 340 session_->GetWeakPtr(), &http_server_properties_, |
337 : new QuicHttpStream(session_->GetWeakPtr(), | 341 !kMarkQuicBrokenWhenNetworkSuspected) |
338 &http_server_properties_)); | 342 : new QuicHttpStream( |
| 343 session_->GetWeakPtr(), &http_server_properties_, |
| 344 !kMarkQuicBrokenWhenNetworkSuspected)); |
339 | 345 |
340 promised_stream_.reset(use_closing_stream_ | 346 promised_stream_.reset( |
341 ? new AutoClosingStream(session_->GetWeakPtr(), | 347 use_closing_stream_ |
342 &http_server_properties_) | 348 ? new AutoClosingStream(session_->GetWeakPtr(), |
343 : new QuicHttpStream(session_->GetWeakPtr(), | 349 &http_server_properties_, |
344 &http_server_properties_)); | 350 !kMarkQuicBrokenWhenNetworkSuspected) |
| 351 : new QuicHttpStream(session_->GetWeakPtr(), |
| 352 &http_server_properties_, |
| 353 !kMarkQuicBrokenWhenNetworkSuspected)); |
345 | 354 |
346 push_promise_[":path"] = "/bar"; | 355 push_promise_[":path"] = "/bar"; |
347 push_promise_[":authority"] = "www.example.org"; | 356 push_promise_[":authority"] = "www.example.org"; |
348 push_promise_[":version"] = "HTTP/1.1"; | 357 push_promise_[":version"] = "HTTP/1.1"; |
349 push_promise_[":method"] = "GET"; | 358 push_promise_[":method"] = "GET"; |
350 push_promise_[":scheme"] = "https"; | 359 push_promise_[":scheme"] = "https"; |
351 | 360 |
352 promised_response_[":status"] = "200 OK"; | 361 promised_response_[":status"] = "200 OK"; |
353 promised_response_[":version"] = "HTTP/1.1"; | 362 promised_response_[":version"] = "HTTP/1.1"; |
354 promised_response_["content-type"] = "text/plain"; | 363 promised_response_["content-type"] = "text/plain"; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 request_.method = "GET"; | 727 request_.method = "GET"; |
719 request_.url = GURL("http://www.example.org/"); | 728 request_.url = GURL("http://www.example.org/"); |
720 // Start first request. | 729 // Start first request. |
721 EXPECT_EQ(OK, | 730 EXPECT_EQ(OK, |
722 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 731 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
723 net_log_.bound(), callback_.callback())); | 732 net_log_.bound(), callback_.callback())); |
724 EXPECT_EQ(OK, | 733 EXPECT_EQ(OK, |
725 stream_->SendRequest(headers_, &response_, callback_.callback())); | 734 stream_->SendRequest(headers_, &response_, callback_.callback())); |
726 | 735 |
727 // Start a second request. | 736 // Start a second request. |
728 QuicHttpStream stream2(session_->GetWeakPtr(), &http_server_properties_); | 737 QuicHttpStream stream2(session_->GetWeakPtr(), &http_server_properties_, |
| 738 !kMarkQuicBrokenWhenNetworkSuspected); |
729 TestCompletionCallback callback2; | 739 TestCompletionCallback callback2; |
730 EXPECT_EQ(OK, | 740 EXPECT_EQ(OK, |
731 stream2.InitializeStream(&request_, DEFAULT_PRIORITY, | 741 stream2.InitializeStream(&request_, DEFAULT_PRIORITY, |
732 net_log_.bound(), callback2.callback())); | 742 net_log_.bound(), callback2.callback())); |
733 EXPECT_EQ(OK, | 743 EXPECT_EQ(OK, |
734 stream2.SendRequest(headers_, &response_, callback2.callback())); | 744 stream2.SendRequest(headers_, &response_, callback2.callback())); |
735 | 745 |
736 // Ack both requests. | 746 // Ack both requests. |
737 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); | 747 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
738 | 748 |
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2169 EXPECT_TRUE(AtEof()); | 2179 EXPECT_TRUE(AtEof()); |
2170 | 2180 |
2171 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. | 2181 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
2172 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 2182 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
2173 stream_->GetTotalSentBytes()); | 2183 stream_->GetTotalSentBytes()); |
2174 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); | 2184 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
2175 } | 2185 } |
2176 | 2186 |
2177 } // namespace test | 2187 } // namespace test |
2178 } // namespace net | 2188 } // namespace net |
OLD | NEW |