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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); | 106 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); |
107 }; | 107 }; |
108 | 108 |
109 } // namespace | 109 } // namespace |
110 | 110 |
111 class SpdyHttpStreamTest : public testing::Test, | 111 class SpdyHttpStreamTest : public testing::Test, |
112 public testing::WithParamInterface<TestCase> { | 112 public testing::WithParamInterface<TestCase> { |
113 public: | 113 public: |
114 SpdyHttpStreamTest() | 114 SpdyHttpStreamTest() |
115 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), | 115 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
116 session_deps_(GetProtocol()) { | 116 session_deps_(GetProtocol()), |
| 117 host_port_pair_(HostPortPair::FromURL(GURL(kDefaultUrl))), |
| 118 key_(host_port_pair_, ProxyServer::Direct(), PRIVACY_MODE_DISABLED) { |
117 session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); | 119 session_deps_.enable_priority_dependencies = GetDependenciesFromPriority(); |
118 session_deps_.net_log = &net_log_; | 120 session_deps_.net_log = &net_log_; |
119 spdy_util_.set_default_url(GURL("http://www.example.org/")); | 121 spdy_util_.set_default_url(GURL("http://www.example.org/")); |
120 } | 122 } |
121 | 123 |
122 ~SpdyHttpStreamTest() {} | 124 ~SpdyHttpStreamTest() {} |
123 | 125 |
124 protected: | 126 protected: |
125 NextProto GetProtocol() const { | 127 NextProto GetProtocol() const { |
126 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; | 128 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
127 } | 129 } |
128 | 130 |
129 bool GetDependenciesFromPriority() const { | 131 bool GetDependenciesFromPriority() const { |
130 return GetParam() == kTestCaseHTTP2PriorityDependencies; | 132 return GetParam() == kTestCaseHTTP2PriorityDependencies; |
131 } | 133 } |
132 | 134 |
133 void TearDown() override { | 135 void TearDown() override { |
134 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr); | 136 crypto::ECSignatureCreator::SetFactoryForTesting(nullptr); |
135 base::RunLoop().RunUntilIdle(); | 137 base::RunLoop().RunUntilIdle(); |
136 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed()); | 138 EXPECT_TRUE(sequenced_data_->AllReadDataConsumed()); |
137 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed()); | 139 EXPECT_TRUE(sequenced_data_->AllWriteDataConsumed()); |
138 } | 140 } |
139 | 141 |
140 // Initializes the session using SequencedSocketData. | 142 // Initializes the session using SequencedSocketData. |
141 void InitSession(MockRead* reads, | 143 void InitSession(MockRead* reads, |
142 size_t reads_count, | 144 size_t reads_count, |
143 MockWrite* writes, | 145 MockWrite* writes, |
144 size_t writes_count, | 146 size_t writes_count) { |
145 const SpdySessionKey& key) { | |
146 sequenced_data_.reset( | 147 sequenced_data_.reset( |
147 new SequencedSocketData(reads, reads_count, writes, writes_count)); | 148 new SequencedSocketData(reads, reads_count, writes, writes_count)); |
148 session_deps_.socket_factory->AddSocketDataProvider(sequenced_data_.get()); | 149 session_deps_.socket_factory->AddSocketDataProvider(sequenced_data_.get()); |
149 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 150 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
150 session_ = | 151 session_ = |
151 CreateInsecureSpdySession(http_session_.get(), key, BoundNetLog()); | 152 CreateInsecureSpdySession(http_session_.get(), key_, BoundNetLog()); |
152 } | 153 } |
153 | 154 |
154 void TestSendCredentials( | 155 void TestSendCredentials( |
155 ChannelIDService* channel_id_service, | 156 ChannelIDService* channel_id_service, |
156 const std::string& cert, | 157 const std::string& cert, |
157 const std::string& proof); | 158 const std::string& proof); |
158 | 159 |
159 SpdyTestUtil spdy_util_; | 160 SpdyTestUtil spdy_util_; |
160 TestNetLog net_log_; | 161 TestNetLog net_log_; |
161 SpdySessionDependencies session_deps_; | 162 SpdySessionDependencies session_deps_; |
| 163 const HostPortPair host_port_pair_; |
| 164 const SpdySessionKey key_; |
162 std::unique_ptr<SequencedSocketData> sequenced_data_; | 165 std::unique_ptr<SequencedSocketData> sequenced_data_; |
163 std::unique_ptr<HttpNetworkSession> http_session_; | 166 std::unique_ptr<HttpNetworkSession> http_session_; |
164 base::WeakPtr<SpdySession> session_; | 167 base::WeakPtr<SpdySession> session_; |
165 | 168 |
166 private: | 169 private: |
167 MockECSignatureCreatorFactory ec_signature_creator_factory_; | 170 MockECSignatureCreatorFactory ec_signature_creator_factory_; |
168 }; | 171 }; |
169 | 172 |
170 INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, | 173 INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
171 SpdyHttpStreamTest, | 174 SpdyHttpStreamTest, |
172 testing::Values(kTestCaseSPDY31, | 175 testing::Values(kTestCaseSPDY31, |
173 kTestCaseHTTP2NoPriorityDependencies, | 176 kTestCaseHTTP2NoPriorityDependencies, |
174 kTestCaseHTTP2PriorityDependencies)); | 177 kTestCaseHTTP2PriorityDependencies)); |
175 | 178 |
176 // SpdyHttpStream::GetUploadProgress() should still work even before the | 179 // SpdyHttpStream::GetUploadProgress() should still work even before the |
177 // stream is initialized. | 180 // stream is initialized. |
178 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { | 181 TEST_P(SpdyHttpStreamTest, GetUploadProgressBeforeInitialization) { |
179 MockRead reads[] = { | 182 MockRead reads[] = { |
180 MockRead(ASYNC, 0, 0) // EOF | 183 MockRead(ASYNC, 0, 0) // EOF |
181 }; | 184 }; |
182 | 185 |
183 HostPortPair host_port_pair("www.example.org", 80); | 186 InitSession(reads, arraysize(reads), nullptr, 0); |
184 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
185 PRIVACY_MODE_DISABLED); | |
186 InitSession(reads, arraysize(reads), nullptr, 0, key); | |
187 | 187 |
188 SpdyHttpStream stream(session_, false); | 188 SpdyHttpStream stream(session_, false); |
189 UploadProgress progress = stream.GetUploadProgress(); | 189 UploadProgress progress = stream.GetUploadProgress(); |
190 EXPECT_EQ(0u, progress.size()); | 190 EXPECT_EQ(0u, progress.size()); |
191 EXPECT_EQ(0u, progress.position()); | 191 EXPECT_EQ(0u, progress.position()); |
192 | 192 |
193 // Pump the event loop so |reads| is consumed before the function returns. | 193 // Pump the event loop so |reads| is consumed before the function returns. |
194 base::RunLoop().RunUntilIdle(); | 194 base::RunLoop().RunUntilIdle(); |
195 } | 195 } |
196 | 196 |
197 TEST_P(SpdyHttpStreamTest, SendRequest) { | 197 TEST_P(SpdyHttpStreamTest, SendRequest) { |
198 std::unique_ptr<SpdySerializedFrame> req( | 198 std::unique_ptr<SpdySerializedFrame> req( |
199 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 199 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
200 MockWrite writes[] = { | 200 MockWrite writes[] = { |
201 CreateMockWrite(*req.get(), 0), | 201 CreateMockWrite(*req.get(), 0), |
202 }; | 202 }; |
203 std::unique_ptr<SpdySerializedFrame> resp( | 203 std::unique_ptr<SpdySerializedFrame> resp( |
204 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); | 204 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
205 MockRead reads[] = { | 205 MockRead reads[] = { |
206 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 206 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
207 }; | 207 }; |
208 | 208 |
209 HostPortPair host_port_pair("www.example.org", 80); | 209 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
210 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
211 PRIVACY_MODE_DISABLED); | |
212 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
213 | 210 |
214 HttpRequestInfo request; | 211 HttpRequestInfo request; |
215 request.method = "GET"; | 212 request.method = "GET"; |
216 request.url = GURL("http://www.example.org/"); | 213 request.url = GURL("http://www.example.org/"); |
217 TestCompletionCallback callback; | 214 TestCompletionCallback callback; |
218 HttpResponseInfo response; | 215 HttpResponseInfo response; |
219 HttpRequestHeaders headers; | 216 HttpRequestHeaders headers; |
220 BoundNetLog net_log; | 217 BoundNetLog net_log; |
221 std::unique_ptr<SpdyHttpStream> http_stream( | 218 std::unique_ptr<SpdyHttpStream> http_stream( |
222 new SpdyHttpStream(session_, true)); | 219 new SpdyHttpStream(session_, true)); |
223 // Make sure getting load timing information the stream early does not crash. | 220 // Make sure getting load timing information the stream early does not crash. |
224 LoadTimingInfo load_timing_info; | 221 LoadTimingInfo load_timing_info; |
225 EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); | 222 EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); |
226 | 223 |
227 ASSERT_EQ( | 224 ASSERT_EQ( |
228 OK, | 225 OK, |
229 http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 226 http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
230 net_log, CompletionCallback())); | 227 net_log, CompletionCallback())); |
231 EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); | 228 EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); |
232 | 229 |
233 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 230 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
234 callback.callback())); | 231 callback.callback())); |
235 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 232 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
236 EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); | 233 EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); |
237 | 234 |
238 callback.WaitForResult(); | 235 callback.WaitForResult(); |
239 | 236 |
240 // Can get timing information once the stream connects. | 237 // Can get timing information once the stream connects. |
241 TestLoadTimingNotReused(*http_stream); | 238 TestLoadTimingNotReused(*http_stream); |
242 | 239 |
243 // Because we abandoned the stream, we don't expect to find a session in the | 240 // Because we abandoned the stream, we don't expect to find a session in the |
244 // pool anymore. | 241 // pool anymore. |
245 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 242 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
246 | 243 |
247 TestLoadTimingNotReused(*http_stream); | 244 TestLoadTimingNotReused(*http_stream); |
248 http_stream->Close(true); | 245 http_stream->Close(true); |
249 // Test that there's no crash when trying to get the load timing after the | 246 // Test that there's no crash when trying to get the load timing after the |
250 // stream has been closed. | 247 // stream has been closed. |
251 TestLoadTimingNotReused(*http_stream); | 248 TestLoadTimingNotReused(*http_stream); |
252 | 249 |
253 EXPECT_EQ(static_cast<int64_t>(req->size()), | 250 EXPECT_EQ(static_cast<int64_t>(req->size()), |
254 http_stream->GetTotalSentBytes()); | 251 http_stream->GetTotalSentBytes()); |
255 EXPECT_EQ(static_cast<int64_t>(resp->size()), | 252 EXPECT_EQ(static_cast<int64_t>(resp->size()), |
(...skipping 18 matching lines...) Expand all Loading... |
274 std::unique_ptr<SpdySerializedFrame> body2( | 271 std::unique_ptr<SpdySerializedFrame> body2( |
275 spdy_util_.ConstructSpdyBodyFrame(3, "", 0, true)); | 272 spdy_util_.ConstructSpdyBodyFrame(3, "", 0, true)); |
276 MockRead reads[] = { | 273 MockRead reads[] = { |
277 CreateMockRead(*resp1, 2), | 274 CreateMockRead(*resp1, 2), |
278 CreateMockRead(*body1, 3), | 275 CreateMockRead(*body1, 3), |
279 CreateMockRead(*resp2, 4), | 276 CreateMockRead(*resp2, 4), |
280 CreateMockRead(*body2, 5), | 277 CreateMockRead(*body2, 5), |
281 MockRead(ASYNC, 0, 6) // EOF | 278 MockRead(ASYNC, 0, 6) // EOF |
282 }; | 279 }; |
283 | 280 |
284 HostPortPair host_port_pair("www.example.org", 80); | 281 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
285 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
286 PRIVACY_MODE_DISABLED); | |
287 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
288 | 282 |
289 HttpRequestInfo request1; | 283 HttpRequestInfo request1; |
290 request1.method = "GET"; | 284 request1.method = "GET"; |
291 request1.url = GURL("http://www.example.org/"); | 285 request1.url = GURL("http://www.example.org/"); |
292 TestCompletionCallback callback1; | 286 TestCompletionCallback callback1; |
293 HttpResponseInfo response1; | 287 HttpResponseInfo response1; |
294 HttpRequestHeaders headers1; | 288 HttpRequestHeaders headers1; |
295 std::unique_ptr<SpdyHttpStream> http_stream1( | 289 std::unique_ptr<SpdyHttpStream> http_stream1( |
296 new SpdyHttpStream(session_, true)); | 290 new SpdyHttpStream(session_, true)); |
297 | 291 |
298 HttpRequestInfo request2; | 292 HttpRequestInfo request2; |
299 request2.method = "GET"; | 293 request2.method = "GET"; |
300 request2.url = GURL("http://www.example.org/"); | 294 request2.url = GURL("http://www.example.org/"); |
301 TestCompletionCallback callback2; | 295 TestCompletionCallback callback2; |
302 HttpResponseInfo response2; | 296 HttpResponseInfo response2; |
303 HttpRequestHeaders headers2; | 297 HttpRequestHeaders headers2; |
304 std::unique_ptr<SpdyHttpStream> http_stream2( | 298 std::unique_ptr<SpdyHttpStream> http_stream2( |
305 new SpdyHttpStream(session_, true)); | 299 new SpdyHttpStream(session_, true)); |
306 | 300 |
307 // First write. | 301 // First write. |
308 ASSERT_EQ(OK, | 302 ASSERT_EQ(OK, |
309 http_stream1->InitializeStream(&request1, DEFAULT_PRIORITY, | 303 http_stream1->InitializeStream(&request1, DEFAULT_PRIORITY, |
310 BoundNetLog(), | 304 BoundNetLog(), |
311 CompletionCallback())); | 305 CompletionCallback())); |
312 EXPECT_EQ(ERR_IO_PENDING, http_stream1->SendRequest(headers1, &response1, | 306 EXPECT_EQ(ERR_IO_PENDING, http_stream1->SendRequest(headers1, &response1, |
313 callback1.callback())); | 307 callback1.callback())); |
314 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 308 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
315 | 309 |
316 EXPECT_LE(0, callback1.WaitForResult()); | 310 EXPECT_LE(0, callback1.WaitForResult()); |
317 | 311 |
318 TestLoadTimingNotReused(*http_stream1); | 312 TestLoadTimingNotReused(*http_stream1); |
319 LoadTimingInfo load_timing_info1; | 313 LoadTimingInfo load_timing_info1; |
320 LoadTimingInfo load_timing_info2; | 314 LoadTimingInfo load_timing_info2; |
321 EXPECT_TRUE(http_stream1->GetLoadTimingInfo(&load_timing_info1)); | 315 EXPECT_TRUE(http_stream1->GetLoadTimingInfo(&load_timing_info1)); |
322 EXPECT_FALSE(http_stream2->GetLoadTimingInfo(&load_timing_info2)); | 316 EXPECT_FALSE(http_stream2->GetLoadTimingInfo(&load_timing_info2)); |
323 | 317 |
324 // Second write. | 318 // Second write. |
325 ASSERT_EQ(OK, | 319 ASSERT_EQ(OK, |
326 http_stream2->InitializeStream(&request2, DEFAULT_PRIORITY, | 320 http_stream2->InitializeStream(&request2, DEFAULT_PRIORITY, |
327 BoundNetLog(), | 321 BoundNetLog(), |
328 CompletionCallback())); | 322 CompletionCallback())); |
329 EXPECT_EQ(ERR_IO_PENDING, http_stream2->SendRequest(headers2, &response2, | 323 EXPECT_EQ(ERR_IO_PENDING, http_stream2->SendRequest(headers2, &response2, |
330 callback2.callback())); | 324 callback2.callback())); |
331 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 325 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
332 | 326 |
333 EXPECT_LE(0, callback2.WaitForResult()); | 327 EXPECT_LE(0, callback2.WaitForResult()); |
334 TestLoadTimingReused(*http_stream2); | 328 TestLoadTimingReused(*http_stream2); |
335 EXPECT_TRUE(http_stream2->GetLoadTimingInfo(&load_timing_info2)); | 329 EXPECT_TRUE(http_stream2->GetLoadTimingInfo(&load_timing_info2)); |
336 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | 330 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
337 | 331 |
338 // Read stream 1 to completion, before making sure we can still read load | 332 // Read stream 1 to completion, before making sure we can still read load |
339 // timing from both streams. | 333 // timing from both streams. |
340 scoped_refptr<IOBuffer> buf1(new IOBuffer(1)); | 334 scoped_refptr<IOBuffer> buf1(new IOBuffer(1)); |
341 ASSERT_EQ( | 335 ASSERT_EQ( |
(...skipping 29 matching lines...) Expand all Loading... |
371 }; | 365 }; |
372 | 366 |
373 std::unique_ptr<SpdySerializedFrame> resp( | 367 std::unique_ptr<SpdySerializedFrame> resp( |
374 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 368 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
375 MockRead reads[] = { | 369 MockRead reads[] = { |
376 CreateMockRead(*resp, 2), | 370 CreateMockRead(*resp, 2), |
377 CreateMockRead(*body, 3), | 371 CreateMockRead(*body, 3), |
378 MockRead(SYNCHRONOUS, 0, 4) // EOF | 372 MockRead(SYNCHRONOUS, 0, 4) // EOF |
379 }; | 373 }; |
380 | 374 |
381 HostPortPair host_port_pair("www.example.org", 80); | 375 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
382 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
383 PRIVACY_MODE_DISABLED); | |
384 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
385 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | 376 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
386 | 377 |
387 ChunkedUploadDataStream upload_stream(0); | 378 ChunkedUploadDataStream upload_stream(0); |
388 const int kFirstChunkSize = kUploadDataSize/2; | 379 const int kFirstChunkSize = kUploadDataSize/2; |
389 upload_stream.AppendData(kUploadData, kFirstChunkSize, false); | 380 upload_stream.AppendData(kUploadData, kFirstChunkSize, false); |
390 upload_stream.AppendData(kUploadData + kFirstChunkSize, | 381 upload_stream.AppendData(kUploadData + kFirstChunkSize, |
391 kUploadDataSize - kFirstChunkSize, true); | 382 kUploadDataSize - kFirstChunkSize, true); |
392 | 383 |
393 HttpRequestInfo request; | 384 HttpRequestInfo request; |
394 request.method = "POST"; | 385 request.method = "POST"; |
395 request.url = GURL("http://www.example.org/"); | 386 request.url = GURL("http://www.example.org/"); |
396 request.upload_data_stream = &upload_stream; | 387 request.upload_data_stream = &upload_stream; |
397 | 388 |
398 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); | 389 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); |
399 | 390 |
400 TestCompletionCallback callback; | 391 TestCompletionCallback callback; |
401 HttpResponseInfo response; | 392 HttpResponseInfo response; |
402 HttpRequestHeaders headers; | 393 HttpRequestHeaders headers; |
403 BoundNetLog net_log; | 394 BoundNetLog net_log; |
404 SpdyHttpStream http_stream(session_, true); | 395 SpdyHttpStream http_stream(session_, true); |
405 ASSERT_EQ( | 396 ASSERT_EQ( |
406 OK, | 397 OK, |
407 http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 398 http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
408 net_log, CompletionCallback())); | 399 net_log, CompletionCallback())); |
409 | 400 |
410 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( | 401 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( |
411 headers, &response, callback.callback())); | 402 headers, &response, callback.callback())); |
412 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 403 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
413 | 404 |
414 EXPECT_EQ(OK, callback.WaitForResult()); | 405 EXPECT_EQ(OK, callback.WaitForResult()); |
415 | 406 |
416 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 407 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), |
417 http_stream.GetTotalSentBytes()); | 408 http_stream.GetTotalSentBytes()); |
418 EXPECT_EQ(static_cast<int64_t>(resp->size() + body->size()), | 409 EXPECT_EQ(static_cast<int64_t>(resp->size() + body->size()), |
419 http_stream.GetTotalReceivedBytes()); | 410 http_stream.GetTotalReceivedBytes()); |
420 | 411 |
421 // Because the server closed the connection, we there shouldn't be a session | 412 // Because the server closed the connection, we there shouldn't be a session |
422 // in the pool anymore. | 413 // in the pool anymore. |
423 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 414 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
424 } | 415 } |
425 | 416 |
426 // This unittest tests the request callback is properly called and handled. | 417 // This unittest tests the request callback is properly called and handled. |
427 TEST_P(SpdyHttpStreamTest, SendChunkedPostLastEmpty) { | 418 TEST_P(SpdyHttpStreamTest, SendChunkedPostLastEmpty) { |
428 std::unique_ptr<SpdySerializedFrame> req( | 419 std::unique_ptr<SpdySerializedFrame> req( |
429 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 420 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
430 std::unique_ptr<SpdySerializedFrame> chunk( | 421 std::unique_ptr<SpdySerializedFrame> chunk( |
431 spdy_util_.ConstructSpdyBodyFrame(1, nullptr, 0, true)); | 422 spdy_util_.ConstructSpdyBodyFrame(1, nullptr, 0, true)); |
432 MockWrite writes[] = { | 423 MockWrite writes[] = { |
433 CreateMockWrite(*req, 0), // request | 424 CreateMockWrite(*req, 0), // request |
434 CreateMockWrite(*chunk, 1), | 425 CreateMockWrite(*chunk, 1), |
435 }; | 426 }; |
436 | 427 |
437 std::unique_ptr<SpdySerializedFrame> resp( | 428 std::unique_ptr<SpdySerializedFrame> resp( |
438 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 429 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
439 MockRead reads[] = { | 430 MockRead reads[] = { |
440 CreateMockRead(*resp, 2), | 431 CreateMockRead(*resp, 2), |
441 CreateMockRead(*chunk, 3), | 432 CreateMockRead(*chunk, 3), |
442 MockRead(SYNCHRONOUS, 0, 4) // EOF | 433 MockRead(SYNCHRONOUS, 0, 4) // EOF |
443 }; | 434 }; |
444 | 435 |
445 HostPortPair host_port_pair("www.example.org", 80); | 436 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
446 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
447 PRIVACY_MODE_DISABLED); | |
448 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
449 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | 437 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
450 | 438 |
451 ChunkedUploadDataStream upload_stream(0); | 439 ChunkedUploadDataStream upload_stream(0); |
452 upload_stream.AppendData(nullptr, 0, true); | 440 upload_stream.AppendData(nullptr, 0, true); |
453 | 441 |
454 HttpRequestInfo request; | 442 HttpRequestInfo request; |
455 request.method = "POST"; | 443 request.method = "POST"; |
456 request.url = GURL("http://www.example.org/"); | 444 request.url = GURL("http://www.example.org/"); |
457 request.upload_data_stream = &upload_stream; | 445 request.upload_data_stream = &upload_stream; |
458 | 446 |
459 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); | 447 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); |
460 | 448 |
461 TestCompletionCallback callback; | 449 TestCompletionCallback callback; |
462 HttpResponseInfo response; | 450 HttpResponseInfo response; |
463 HttpRequestHeaders headers; | 451 HttpRequestHeaders headers; |
464 BoundNetLog net_log; | 452 BoundNetLog net_log; |
465 SpdyHttpStream http_stream(session_, true); | 453 SpdyHttpStream http_stream(session_, true); |
466 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 454 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
467 net_log, CompletionCallback())); | 455 net_log, CompletionCallback())); |
468 EXPECT_EQ(ERR_IO_PENDING, | 456 EXPECT_EQ(ERR_IO_PENDING, |
469 http_stream.SendRequest(headers, &response, callback.callback())); | 457 http_stream.SendRequest(headers, &response, callback.callback())); |
470 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 458 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
471 | 459 |
472 EXPECT_EQ(OK, callback.WaitForResult()); | 460 EXPECT_EQ(OK, callback.WaitForResult()); |
473 | 461 |
474 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()), | 462 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()), |
475 http_stream.GetTotalSentBytes()); | 463 http_stream.GetTotalSentBytes()); |
476 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), | 464 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), |
477 http_stream.GetTotalReceivedBytes()); | 465 http_stream.GetTotalReceivedBytes()); |
478 | 466 |
479 // Because the server closed the connection, there shouldn't be a session | 467 // Because the server closed the connection, there shouldn't be a session |
480 // in the pool anymore. | 468 // in the pool anymore. |
481 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 469 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
482 } | 470 } |
483 | 471 |
484 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { | 472 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { |
485 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 473 BufferedSpdyFramer framer(spdy_util_.spdy_version()); |
486 | 474 |
487 std::unique_ptr<SpdySerializedFrame> req( | 475 std::unique_ptr<SpdySerializedFrame> req( |
488 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 476 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
489 std::unique_ptr<SpdySerializedFrame> body( | 477 std::unique_ptr<SpdySerializedFrame> body( |
490 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); | 478 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); |
491 MockWrite writes[] = { | 479 MockWrite writes[] = { |
492 CreateMockWrite(*req, 0), // Request | 480 CreateMockWrite(*req, 0), // Request |
493 CreateMockWrite(*body, 1) // First POST upload frame | 481 CreateMockWrite(*body, 1) // First POST upload frame |
494 }; | 482 }; |
495 | 483 |
496 std::unique_ptr<SpdySerializedFrame> resp( | 484 std::unique_ptr<SpdySerializedFrame> resp( |
497 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 485 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
498 MockRead reads[] = { | 486 MockRead reads[] = { |
499 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. | 487 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. |
500 }; | 488 }; |
501 | 489 |
502 HostPortPair host_port_pair("www.example.org", 80); | 490 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
503 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
504 PRIVACY_MODE_DISABLED); | |
505 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
506 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | 491 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
507 | 492 |
508 ChunkedUploadDataStream upload_stream(0); | 493 ChunkedUploadDataStream upload_stream(0); |
509 // Append first chunk. | 494 // Append first chunk. |
510 upload_stream.AppendData(kUploadData, kUploadDataSize, false); | 495 upload_stream.AppendData(kUploadData, kUploadDataSize, false); |
511 | 496 |
512 HttpRequestInfo request; | 497 HttpRequestInfo request; |
513 request.method = "POST"; | 498 request.method = "POST"; |
514 request.url = GURL("http://www.example.org/"); | 499 request.url = GURL("http://www.example.org/"); |
515 request.upload_data_stream = &upload_stream; | 500 request.upload_data_stream = &upload_stream; |
516 | 501 |
517 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); | 502 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); |
518 | 503 |
519 TestCompletionCallback callback; | 504 TestCompletionCallback callback; |
520 HttpResponseInfo response; | 505 HttpResponseInfo response; |
521 HttpRequestHeaders headers; | 506 HttpRequestHeaders headers; |
522 BoundNetLog net_log; | 507 BoundNetLog net_log; |
523 SpdyHttpStream http_stream(session_, true); | 508 SpdyHttpStream http_stream(session_, true); |
524 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 509 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
525 net_log, CompletionCallback())); | 510 net_log, CompletionCallback())); |
526 | 511 |
527 EXPECT_EQ(ERR_IO_PENDING, | 512 EXPECT_EQ(ERR_IO_PENDING, |
528 http_stream.SendRequest(headers, &response, callback.callback())); | 513 http_stream.SendRequest(headers, &response, callback.callback())); |
529 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 514 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
530 | 515 |
531 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); | 516 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
532 | 517 |
533 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 518 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), |
534 http_stream.GetTotalSentBytes()); | 519 http_stream.GetTotalSentBytes()); |
535 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); | 520 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); |
536 | 521 |
537 // Because the server closed the connection, we there shouldn't be a session | 522 // Because the server closed the connection, we there shouldn't be a session |
538 // in the pool anymore. | 523 // in the pool anymore. |
539 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 524 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
540 | 525 |
541 // Appending a second chunk now should not result in a crash. | 526 // Appending a second chunk now should not result in a crash. |
542 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 527 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
543 // Appending data is currently done synchronously, but seems best to be | 528 // Appending data is currently done synchronously, but seems best to be |
544 // paranoid. | 529 // paranoid. |
545 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
546 | 531 |
547 // The total sent and received bytes should be unchanged. | 532 // The total sent and received bytes should be unchanged. |
548 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 533 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), |
549 http_stream.GetTotalSentBytes()); | 534 http_stream.GetTotalSentBytes()); |
(...skipping 22 matching lines...) Expand all Loading... |
572 std::unique_ptr<SpdySerializedFrame> resp( | 557 std::unique_ptr<SpdySerializedFrame> resp( |
573 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 558 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
574 MockRead reads[] = { | 559 MockRead reads[] = { |
575 CreateMockRead(*resp, 4), | 560 CreateMockRead(*resp, 4), |
576 CreateMockRead(*chunk1, 5), | 561 CreateMockRead(*chunk1, 5), |
577 CreateMockRead(*chunk2, 6), | 562 CreateMockRead(*chunk2, 6), |
578 CreateMockRead(*chunk3, 7), | 563 CreateMockRead(*chunk3, 7), |
579 MockRead(ASYNC, 0, 8) // EOF | 564 MockRead(ASYNC, 0, 8) // EOF |
580 }; | 565 }; |
581 | 566 |
582 HostPortPair host_port_pair("www.example.org", 80); | 567 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
583 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
584 PRIVACY_MODE_DISABLED); | |
585 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
586 | 568 |
587 ChunkedUploadDataStream upload_stream(0); | 569 ChunkedUploadDataStream upload_stream(0); |
588 | 570 |
589 HttpRequestInfo request; | 571 HttpRequestInfo request; |
590 request.method = "POST"; | 572 request.method = "POST"; |
591 request.url = GURL("http://www.example.org/"); | 573 request.url = GURL("http://www.example.org/"); |
592 request.upload_data_stream = &upload_stream; | 574 request.upload_data_stream = &upload_stream; |
593 | 575 |
594 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); | 576 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); |
595 upload_stream.AppendData(kUploadData, kUploadDataSize, false); | 577 upload_stream.AppendData(kUploadData, kUploadDataSize, false); |
596 | 578 |
597 BoundNetLog net_log; | 579 BoundNetLog net_log; |
598 std::unique_ptr<SpdyHttpStream> http_stream( | 580 std::unique_ptr<SpdyHttpStream> http_stream( |
599 new SpdyHttpStream(session_, true)); | 581 new SpdyHttpStream(session_, true)); |
600 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 582 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
601 net_log, CompletionCallback())); | 583 net_log, CompletionCallback())); |
602 | 584 |
603 TestCompletionCallback callback; | 585 TestCompletionCallback callback; |
604 HttpRequestHeaders headers; | 586 HttpRequestHeaders headers; |
605 HttpResponseInfo response; | 587 HttpResponseInfo response; |
606 // This will attempt to Write() the initial request and headers, which will | 588 // This will attempt to Write() the initial request and headers, which will |
607 // complete asynchronously. | 589 // complete asynchronously. |
608 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 590 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
609 callback.callback())); | 591 callback.callback())); |
610 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 592 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
611 | 593 |
612 // Complete the initial request write and the first chunk. | 594 // Complete the initial request write and the first chunk. |
613 base::RunLoop().RunUntilIdle(); | 595 base::RunLoop().RunUntilIdle(); |
614 ASSERT_FALSE(callback.have_result()); | 596 ASSERT_FALSE(callback.have_result()); |
615 | 597 |
616 // Now append the final two chunks which will enqueue two more writes. | 598 // Now append the final two chunks which will enqueue two more writes. |
617 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); | 599 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); |
618 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 600 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
619 | 601 |
620 // Finish writing all the chunks and do all reads. | 602 // Finish writing all the chunks and do all reads. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 }; | 655 }; |
674 std::unique_ptr<SpdySerializedFrame> resp( | 656 std::unique_ptr<SpdySerializedFrame> resp( |
675 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 657 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
676 MockRead reads[] = { | 658 MockRead reads[] = { |
677 CreateMockRead(*resp, 3), | 659 CreateMockRead(*resp, 3), |
678 CreateMockRead(*chunk1, 4), | 660 CreateMockRead(*chunk1, 4), |
679 CreateMockRead(*chunk2, 5), | 661 CreateMockRead(*chunk2, 5), |
680 MockRead(ASYNC, 0, 6) // EOF | 662 MockRead(ASYNC, 0, 6) // EOF |
681 }; | 663 }; |
682 | 664 |
683 HostPortPair host_port_pair("www.example.org", 80); | 665 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
684 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
685 PRIVACY_MODE_DISABLED); | |
686 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
687 | 666 |
688 ChunkedUploadDataStream upload_stream(0); | 667 ChunkedUploadDataStream upload_stream(0); |
689 | 668 |
690 HttpRequestInfo request; | 669 HttpRequestInfo request; |
691 request.method = "POST"; | 670 request.method = "POST"; |
692 request.url = GURL("http://www.example.org/"); | 671 request.url = GURL("http://www.example.org/"); |
693 request.upload_data_stream = &upload_stream; | 672 request.upload_data_stream = &upload_stream; |
694 | 673 |
695 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); | 674 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); |
696 upload_stream.AppendData(kUploadData, kUploadDataSize, false); | 675 upload_stream.AppendData(kUploadData, kUploadDataSize, false); |
697 | 676 |
698 BoundNetLog net_log; | 677 BoundNetLog net_log; |
699 std::unique_ptr<SpdyHttpStream> http_stream( | 678 std::unique_ptr<SpdyHttpStream> http_stream( |
700 new SpdyHttpStream(session_, true)); | 679 new SpdyHttpStream(session_, true)); |
701 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 680 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
702 net_log, CompletionCallback())); | 681 net_log, CompletionCallback())); |
703 | 682 |
704 TestCompletionCallback callback; | 683 TestCompletionCallback callback; |
705 HttpRequestHeaders headers; | 684 HttpRequestHeaders headers; |
706 HttpResponseInfo response; | 685 HttpResponseInfo response; |
707 // This will attempt to Write() the initial request and headers, which will | 686 // This will attempt to Write() the initial request and headers, which will |
708 // complete asynchronously. | 687 // complete asynchronously. |
709 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 688 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
710 callback.callback())); | 689 callback.callback())); |
711 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 690 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
712 | 691 |
713 // Complete the initial request write and the first chunk. | 692 // Complete the initial request write and the first chunk. |
714 base::RunLoop().RunUntilIdle(); | 693 base::RunLoop().RunUntilIdle(); |
715 ASSERT_FALSE(callback.have_result()); | 694 ASSERT_FALSE(callback.have_result()); |
716 | 695 |
717 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 696 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), |
718 http_stream->GetTotalSentBytes()); | 697 http_stream->GetTotalSentBytes()); |
719 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 698 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
720 | 699 |
721 // Now end the stream with an empty data frame and the FIN set. | 700 // Now end the stream with an empty data frame and the FIN set. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 CreateMockWrite(*chunk, 1), | 742 CreateMockWrite(*chunk, 1), |
764 }; | 743 }; |
765 std::unique_ptr<SpdySerializedFrame> resp( | 744 std::unique_ptr<SpdySerializedFrame> resp( |
766 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 745 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
767 MockRead reads[] = { | 746 MockRead reads[] = { |
768 CreateMockRead(*resp, 2), | 747 CreateMockRead(*resp, 2), |
769 CreateMockRead(*chunk, 3), | 748 CreateMockRead(*chunk, 3), |
770 MockRead(ASYNC, 0, 4) // EOF | 749 MockRead(ASYNC, 0, 4) // EOF |
771 }; | 750 }; |
772 | 751 |
773 HostPortPair host_port_pair("www.example.org", 80); | 752 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
774 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
775 PRIVACY_MODE_DISABLED); | |
776 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
777 | 753 |
778 ChunkedUploadDataStream upload_stream(0); | 754 ChunkedUploadDataStream upload_stream(0); |
779 | 755 |
780 HttpRequestInfo request; | 756 HttpRequestInfo request; |
781 request.method = "POST"; | 757 request.method = "POST"; |
782 request.url = GURL("http://www.example.org/"); | 758 request.url = GURL("http://www.example.org/"); |
783 request.upload_data_stream = &upload_stream; | 759 request.upload_data_stream = &upload_stream; |
784 | 760 |
785 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); | 761 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); |
786 upload_stream.AppendData("", 0, true); | 762 upload_stream.AppendData("", 0, true); |
787 | 763 |
788 BoundNetLog net_log; | 764 BoundNetLog net_log; |
789 std::unique_ptr<SpdyHttpStream> http_stream( | 765 std::unique_ptr<SpdyHttpStream> http_stream( |
790 new SpdyHttpStream(session_, true)); | 766 new SpdyHttpStream(session_, true)); |
791 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 767 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
792 net_log, CompletionCallback())); | 768 net_log, CompletionCallback())); |
793 | 769 |
794 TestCompletionCallback callback; | 770 TestCompletionCallback callback; |
795 HttpRequestHeaders headers; | 771 HttpRequestHeaders headers; |
796 HttpResponseInfo response; | 772 HttpResponseInfo response; |
797 // This will attempt to Write() the initial request and headers, which will | 773 // This will attempt to Write() the initial request and headers, which will |
798 // complete asynchronously. | 774 // complete asynchronously. |
799 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 775 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
800 callback.callback())); | 776 callback.callback())); |
801 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 777 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
802 | 778 |
803 // Complete writing request, followed by a FIN. | 779 // Complete writing request, followed by a FIN. |
804 base::RunLoop().RunUntilIdle(); | 780 base::RunLoop().RunUntilIdle(); |
805 ASSERT_TRUE(callback.have_result()); | 781 ASSERT_TRUE(callback.have_result()); |
806 EXPECT_EQ(OK, callback.WaitForResult()); | 782 EXPECT_EQ(OK, callback.WaitForResult()); |
807 | 783 |
808 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()), | 784 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()), |
809 http_stream->GetTotalSentBytes()); | 785 http_stream->GetTotalSentBytes()); |
810 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), | 786 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), |
811 http_stream->GetTotalReceivedBytes()); | 787 http_stream->GetTotalReceivedBytes()); |
(...skipping 19 matching lines...) Expand all Loading... |
831 spdy_util_.ConstructSpdyGet(base_url, 1, LOWEST)); | 807 spdy_util_.ConstructSpdyGet(base_url, 1, LOWEST)); |
832 MockWrite writes[] = { | 808 MockWrite writes[] = { |
833 CreateMockWrite(*req.get(), 0), | 809 CreateMockWrite(*req.get(), 0), |
834 }; | 810 }; |
835 std::unique_ptr<SpdySerializedFrame> resp( | 811 std::unique_ptr<SpdySerializedFrame> resp( |
836 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); | 812 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
837 MockRead reads[] = { | 813 MockRead reads[] = { |
838 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 814 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
839 }; | 815 }; |
840 | 816 |
841 HostPortPair host_port_pair("www.example.org", 80); | 817 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
842 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
843 PRIVACY_MODE_DISABLED); | |
844 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
845 | 818 |
846 HttpRequestInfo request; | 819 HttpRequestInfo request; |
847 request.method = "GET"; | 820 request.method = "GET"; |
848 request.url = GURL(full_url); | 821 request.url = GURL(full_url); |
849 TestCompletionCallback callback; | 822 TestCompletionCallback callback; |
850 HttpResponseInfo response; | 823 HttpResponseInfo response; |
851 HttpRequestHeaders headers; | 824 HttpRequestHeaders headers; |
852 BoundNetLog net_log; | 825 BoundNetLog net_log; |
853 std::unique_ptr<SpdyHttpStream> http_stream( | 826 std::unique_ptr<SpdyHttpStream> http_stream( |
854 new SpdyHttpStream(session_, true)); | 827 new SpdyHttpStream(session_, true)); |
855 ASSERT_EQ(OK, | 828 ASSERT_EQ(OK, |
856 http_stream->InitializeStream( | 829 http_stream->InitializeStream( |
857 &request, DEFAULT_PRIORITY, net_log, CompletionCallback())); | 830 &request, DEFAULT_PRIORITY, net_log, CompletionCallback())); |
858 | 831 |
859 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 832 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
860 callback.callback())); | 833 callback.callback())); |
861 | 834 |
862 EXPECT_EQ(base_url, http_stream->stream()->GetUrlFromHeaders().spec()); | 835 EXPECT_EQ(base_url, http_stream->stream()->GetUrlFromHeaders().spec()); |
863 | 836 |
864 callback.WaitForResult(); | 837 callback.WaitForResult(); |
865 | 838 |
866 EXPECT_EQ(static_cast<int64_t>(req->size()), | 839 EXPECT_EQ(static_cast<int64_t>(req->size()), |
867 http_stream->GetTotalSentBytes()); | 840 http_stream->GetTotalSentBytes()); |
868 EXPECT_EQ(static_cast<int64_t>(resp->size()), | 841 EXPECT_EQ(static_cast<int64_t>(resp->size()), |
869 http_stream->GetTotalReceivedBytes()); | 842 http_stream->GetTotalReceivedBytes()); |
870 | 843 |
871 // Because we abandoned the stream, we don't expect to find a session in the | 844 // Because we abandoned the stream, we don't expect to find a session in the |
872 // pool anymore. | 845 // pool anymore. |
873 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 846 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
874 } | 847 } |
875 | 848 |
876 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | 849 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be |
877 // made available is handled correctly. | 850 // made available is handled correctly. |
878 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { | 851 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { |
879 std::unique_ptr<SpdySerializedFrame> req( | 852 std::unique_ptr<SpdySerializedFrame> req( |
880 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 853 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
881 std::unique_ptr<SpdySerializedFrame> chunk1( | 854 std::unique_ptr<SpdySerializedFrame> chunk1( |
882 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 855 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
883 MockWrite writes[] = { | 856 MockWrite writes[] = { |
884 CreateMockWrite(*req.get(), 0), | 857 CreateMockWrite(*req.get(), 0), |
885 CreateMockWrite(*chunk1, 1), | 858 CreateMockWrite(*chunk1, 1), |
886 }; | 859 }; |
887 std::unique_ptr<SpdySerializedFrame> resp( | 860 std::unique_ptr<SpdySerializedFrame> resp( |
888 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 861 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
889 std::unique_ptr<SpdySerializedFrame> window_update( | 862 std::unique_ptr<SpdySerializedFrame> window_update( |
890 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); | 863 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
891 MockRead reads[] = { | 864 MockRead reads[] = { |
892 CreateMockRead(*window_update, 2), | 865 CreateMockRead(*window_update, 2), |
893 MockRead(ASYNC, ERR_IO_PENDING, 3), | 866 MockRead(ASYNC, ERR_IO_PENDING, 3), |
894 CreateMockRead(*resp, 4), | 867 CreateMockRead(*resp, 4), |
895 CreateMockRead(*chunk1, 5), | 868 CreateMockRead(*chunk1, 5), |
896 MockRead(ASYNC, 0, 6) // EOF | 869 MockRead(ASYNC, 0, 6) // EOF |
897 }; | 870 }; |
898 | 871 |
899 HostPortPair host_port_pair("www.example.org", 80); | 872 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
900 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
901 PRIVACY_MODE_DISABLED); | |
902 | |
903 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
904 | 873 |
905 ChunkedUploadDataStream upload_stream(0); | 874 ChunkedUploadDataStream upload_stream(0); |
906 | 875 |
907 HttpRequestInfo request; | 876 HttpRequestInfo request; |
908 request.method = "POST"; | 877 request.method = "POST"; |
909 request.url = GURL("http://www.example.org/"); | 878 request.url = GURL("http://www.example.org/"); |
910 request.upload_data_stream = &upload_stream; | 879 request.upload_data_stream = &upload_stream; |
911 | 880 |
912 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); | 881 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); |
913 | 882 |
914 BoundNetLog net_log; | 883 BoundNetLog net_log; |
915 std::unique_ptr<SpdyHttpStream> http_stream( | 884 std::unique_ptr<SpdyHttpStream> http_stream( |
916 new SpdyHttpStream(session_, true)); | 885 new SpdyHttpStream(session_, true)); |
917 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 886 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
918 net_log, CompletionCallback())); | 887 net_log, CompletionCallback())); |
919 | 888 |
920 HttpRequestHeaders headers; | 889 HttpRequestHeaders headers; |
921 HttpResponseInfo response; | 890 HttpResponseInfo response; |
922 // This will attempt to Write() the initial request and headers, which will | 891 // This will attempt to Write() the initial request and headers, which will |
923 // complete asynchronously. | 892 // complete asynchronously. |
924 TestCompletionCallback callback; | 893 TestCompletionCallback callback; |
925 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 894 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
926 callback.callback())); | 895 callback.callback())); |
927 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 896 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
928 | 897 |
929 // Complete the initial request write and first chunk. | 898 // Complete the initial request write and first chunk. |
930 base::RunLoop().RunUntilIdle(); | 899 base::RunLoop().RunUntilIdle(); |
931 ASSERT_FALSE(callback.have_result()); | 900 ASSERT_FALSE(callback.have_result()); |
932 | 901 |
933 EXPECT_EQ(static_cast<int64_t>(req->size()), | 902 EXPECT_EQ(static_cast<int64_t>(req->size()), |
934 http_stream->GetTotalSentBytes()); | 903 http_stream->GetTotalSentBytes()); |
935 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 904 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
936 | 905 |
937 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 906 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 CreateMockWrite(*rst_frame, 1, SYNCHRONOUS) // Reset frame | 966 CreateMockWrite(*rst_frame, 1, SYNCHRONOUS) // Reset frame |
998 }; | 967 }; |
999 | 968 |
1000 std::unique_ptr<SpdySerializedFrame> resp( | 969 std::unique_ptr<SpdySerializedFrame> resp( |
1001 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 970 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
1002 | 971 |
1003 MockRead reads[] = { | 972 MockRead reads[] = { |
1004 CreateMockRead(*resp, 2), MockRead(SYNCHRONOUS, 0, 3), | 973 CreateMockRead(*resp, 2), MockRead(SYNCHRONOUS, 0, 3), |
1005 }; | 974 }; |
1006 | 975 |
1007 HostPortPair host_port_pair("www.example.org", 80); | 976 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
1008 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
1009 PRIVACY_MODE_DISABLED); | |
1010 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
1011 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | 977 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
1012 | 978 |
1013 ReadErrorUploadDataStream upload_data_stream( | 979 ReadErrorUploadDataStream upload_data_stream( |
1014 ReadErrorUploadDataStream::FailureMode::SYNC); | 980 ReadErrorUploadDataStream::FailureMode::SYNC); |
1015 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); | 981 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); |
1016 | 982 |
1017 HttpRequestInfo request; | 983 HttpRequestInfo request; |
1018 request.method = "POST"; | 984 request.method = "POST"; |
1019 request.url = GURL("http://www.example.org/"); | 985 request.url = GURL("http://www.example.org/"); |
1020 request.upload_data_stream = &upload_data_stream; | 986 request.upload_data_stream = &upload_data_stream; |
1021 | 987 |
1022 TestCompletionCallback callback; | 988 TestCompletionCallback callback; |
1023 HttpResponseInfo response; | 989 HttpResponseInfo response; |
1024 HttpRequestHeaders headers; | 990 HttpRequestHeaders headers; |
1025 BoundNetLog net_log; | 991 BoundNetLog net_log; |
1026 SpdyHttpStream http_stream(session_, true); | 992 SpdyHttpStream http_stream(session_, true); |
1027 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 993 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
1028 net_log, CompletionCallback())); | 994 net_log, CompletionCallback())); |
1029 | 995 |
1030 int result = http_stream.SendRequest(headers, &response, callback.callback()); | 996 int result = http_stream.SendRequest(headers, &response, callback.callback()); |
1031 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); | 997 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); |
1032 | 998 |
1033 // Because the server has not closed the connection yet, there shouldn't be | 999 // Because the server has not closed the connection yet, there shouldn't be |
1034 // a stream but a session in the pool | 1000 // a stream but a session in the pool |
1035 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 1001 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
1036 } | 1002 } |
1037 | 1003 |
1038 TEST_P(SpdyHttpStreamTest, DataReadErrorAsynchronous) { | 1004 TEST_P(SpdyHttpStreamTest, DataReadErrorAsynchronous) { |
1039 std::unique_ptr<SpdySerializedFrame> req( | 1005 std::unique_ptr<SpdySerializedFrame> req( |
1040 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 1006 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
1041 | 1007 |
1042 // Server receives RST_STREAM_INTERNAL_ERROR on client's internal failure. | 1008 // Server receives RST_STREAM_INTERNAL_ERROR on client's internal failure. |
1043 // The failure is a reading error in this case caused by | 1009 // The failure is a reading error in this case caused by |
1044 // UploadDataStream::Read(). | 1010 // UploadDataStream::Read(). |
1045 std::unique_ptr<SpdySerializedFrame> rst_frame( | 1011 std::unique_ptr<SpdySerializedFrame> rst_frame( |
1046 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); | 1012 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
1047 | 1013 |
1048 MockWrite writes[] = { | 1014 MockWrite writes[] = { |
1049 CreateMockWrite(*req, 0), // Request | 1015 CreateMockWrite(*req, 0), // Request |
1050 CreateMockWrite(*rst_frame, 1) // Reset frame | 1016 CreateMockWrite(*rst_frame, 1) // Reset frame |
1051 }; | 1017 }; |
1052 | 1018 |
1053 std::unique_ptr<SpdySerializedFrame> resp( | 1019 std::unique_ptr<SpdySerializedFrame> resp( |
1054 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 1020 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
1055 | 1021 |
1056 MockRead reads[] = { | 1022 MockRead reads[] = { |
1057 MockRead(ASYNC, 0, 2), | 1023 MockRead(ASYNC, 0, 2), |
1058 }; | 1024 }; |
1059 | 1025 |
1060 HostPortPair host_port_pair("www.example.org", 80); | 1026 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
1061 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | |
1062 PRIVACY_MODE_DISABLED); | |
1063 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); | |
1064 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); | 1027 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); |
1065 | 1028 |
1066 ReadErrorUploadDataStream upload_data_stream( | 1029 ReadErrorUploadDataStream upload_data_stream( |
1067 ReadErrorUploadDataStream::FailureMode::ASYNC); | 1030 ReadErrorUploadDataStream::FailureMode::ASYNC); |
1068 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); | 1031 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); |
1069 | 1032 |
1070 HttpRequestInfo request; | 1033 HttpRequestInfo request; |
1071 request.method = "POST"; | 1034 request.method = "POST"; |
1072 request.url = GURL("http://www.example.org/"); | 1035 request.url = GURL("http://www.example.org/"); |
1073 request.upload_data_stream = &upload_data_stream; | 1036 request.upload_data_stream = &upload_data_stream; |
1074 | 1037 |
1075 TestCompletionCallback callback; | 1038 TestCompletionCallback callback; |
1076 HttpResponseInfo response; | 1039 HttpResponseInfo response; |
1077 HttpRequestHeaders headers; | 1040 HttpRequestHeaders headers; |
1078 BoundNetLog net_log; | 1041 BoundNetLog net_log; |
1079 SpdyHttpStream http_stream(session_, true); | 1042 SpdyHttpStream http_stream(session_, true); |
1080 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 1043 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
1081 net_log, CompletionCallback())); | 1044 net_log, CompletionCallback())); |
1082 | 1045 |
1083 int result = http_stream.SendRequest(headers, &response, callback.callback()); | 1046 int result = http_stream.SendRequest(headers, &response, callback.callback()); |
1084 EXPECT_EQ(ERR_IO_PENDING, result); | 1047 EXPECT_EQ(ERR_IO_PENDING, result); |
1085 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); | 1048 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); |
1086 | 1049 |
1087 // Because the server has closed the connection, there shouldn't be a session | 1050 // Because the server has closed the connection, there shouldn't be a session |
1088 // in the pool anymore. | 1051 // in the pool anymore. |
1089 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key)); | 1052 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
1090 } | 1053 } |
1091 | 1054 |
1092 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1055 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
1093 // methods. | 1056 // methods. |
1094 | 1057 |
1095 } // namespace net | 1058 } // namespace net |
OLD | NEW |