| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 SpdyHttpStream stream(session_, false); | 181 SpdyHttpStream stream(session_, false); |
| 182 UploadProgress progress = stream.GetUploadProgress(); | 182 UploadProgress progress = stream.GetUploadProgress(); |
| 183 EXPECT_EQ(0u, progress.size()); | 183 EXPECT_EQ(0u, progress.size()); |
| 184 EXPECT_EQ(0u, progress.position()); | 184 EXPECT_EQ(0u, progress.position()); |
| 185 | 185 |
| 186 // Pump the event loop so |reads| is consumed before the function returns. | 186 // Pump the event loop so |reads| is consumed before the function returns. |
| 187 base::RunLoop().RunUntilIdle(); | 187 base::RunLoop().RunUntilIdle(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST_P(SpdyHttpStreamTest, SendRequest) { | 190 TEST_P(SpdyHttpStreamTest, SendRequest) { |
| 191 std::unique_ptr<SpdySerializedFrame> req( | 191 SpdySerializedFrame req( |
| 192 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 192 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 193 MockWrite writes[] = { | 193 MockWrite writes[] = { |
| 194 CreateMockWrite(*req.get(), 0), | 194 CreateMockWrite(req, 0), |
| 195 }; | 195 }; |
| 196 std::unique_ptr<SpdySerializedFrame> resp( | 196 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 197 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); | |
| 198 MockRead reads[] = { | 197 MockRead reads[] = { |
| 199 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 198 CreateMockRead(resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
| 200 }; | 199 }; |
| 201 | 200 |
| 202 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 201 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 203 | 202 |
| 204 HttpRequestInfo request; | 203 HttpRequestInfo request; |
| 205 request.method = "GET"; | 204 request.method = "GET"; |
| 206 request.url = GURL("http://www.example.org/"); | 205 request.url = GURL("http://www.example.org/"); |
| 207 TestCompletionCallback callback; | 206 TestCompletionCallback callback; |
| 208 HttpResponseInfo response; | 207 HttpResponseInfo response; |
| 209 HttpRequestHeaders headers; | 208 HttpRequestHeaders headers; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 233 // Because we abandoned the stream, we don't expect to find a session in the | 232 // Because we abandoned the stream, we don't expect to find a session in the |
| 234 // pool anymore. | 233 // pool anymore. |
| 235 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 234 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 236 | 235 |
| 237 TestLoadTimingNotReused(*http_stream); | 236 TestLoadTimingNotReused(*http_stream); |
| 238 http_stream->Close(true); | 237 http_stream->Close(true); |
| 239 // Test that there's no crash when trying to get the load timing after the | 238 // Test that there's no crash when trying to get the load timing after the |
| 240 // stream has been closed. | 239 // stream has been closed. |
| 241 TestLoadTimingNotReused(*http_stream); | 240 TestLoadTimingNotReused(*http_stream); |
| 242 | 241 |
| 243 EXPECT_EQ(static_cast<int64_t>(req->size()), | 242 EXPECT_EQ(static_cast<int64_t>(req.size()), http_stream->GetTotalSentBytes()); |
| 244 http_stream->GetTotalSentBytes()); | 243 EXPECT_EQ(static_cast<int64_t>(resp.size()), |
| 245 EXPECT_EQ(static_cast<int64_t>(resp->size()), | |
| 246 http_stream->GetTotalReceivedBytes()); | 244 http_stream->GetTotalReceivedBytes()); |
| 247 } | 245 } |
| 248 | 246 |
| 249 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { | 247 TEST_P(SpdyHttpStreamTest, LoadTimingTwoRequests) { |
| 250 std::unique_ptr<SpdySerializedFrame> req1( | 248 SpdySerializedFrame req1( |
| 251 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 249 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 252 std::unique_ptr<SpdySerializedFrame> req2( | 250 SpdySerializedFrame req2( |
| 253 spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); | 251 spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
| 254 MockWrite writes[] = { | 252 MockWrite writes[] = { |
| 255 CreateMockWrite(*req1, 0), | 253 CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
| 256 CreateMockWrite(*req2, 1), | |
| 257 }; | 254 }; |
| 258 std::unique_ptr<SpdySerializedFrame> resp1( | 255 SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 259 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); | 256 SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "", 0, true)); |
| 260 std::unique_ptr<SpdySerializedFrame> body1( | 257 SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 3)); |
| 261 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | 258 SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, "", 0, true)); |
| 262 std::unique_ptr<SpdySerializedFrame> resp2( | |
| 263 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 3)); | |
| 264 std::unique_ptr<SpdySerializedFrame> body2( | |
| 265 spdy_util_.ConstructSpdyBodyFrame(3, "", 0, true)); | |
| 266 MockRead reads[] = { | 259 MockRead reads[] = { |
| 267 CreateMockRead(*resp1, 2), | 260 CreateMockRead(resp1, 2), CreateMockRead(body1, 3), |
| 268 CreateMockRead(*body1, 3), | 261 CreateMockRead(resp2, 4), CreateMockRead(body2, 5), |
| 269 CreateMockRead(*resp2, 4), | 262 MockRead(ASYNC, 0, 6) // EOF |
| 270 CreateMockRead(*body2, 5), | |
| 271 MockRead(ASYNC, 0, 6) // EOF | |
| 272 }; | 263 }; |
| 273 | 264 |
| 274 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 265 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 275 | 266 |
| 276 HttpRequestInfo request1; | 267 HttpRequestInfo request1; |
| 277 request1.method = "GET"; | 268 request1.method = "GET"; |
| 278 request1.url = GURL("http://www.example.org/"); | 269 request1.url = GURL("http://www.example.org/"); |
| 279 TestCompletionCallback callback1; | 270 TestCompletionCallback callback1; |
| 280 HttpResponseInfo response1; | 271 HttpResponseInfo response1; |
| 281 HttpRequestHeaders headers1; | 272 HttpRequestHeaders headers1; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 315 |
| 325 // Read stream 1 to completion, before making sure we can still read load | 316 // Read stream 1 to completion, before making sure we can still read load |
| 326 // timing from both streams. | 317 // timing from both streams. |
| 327 scoped_refptr<IOBuffer> buf1(new IOBuffer(1)); | 318 scoped_refptr<IOBuffer> buf1(new IOBuffer(1)); |
| 328 ASSERT_EQ( | 319 ASSERT_EQ( |
| 329 0, http_stream1->ReadResponseBody(buf1.get(), 1, callback1.callback())); | 320 0, http_stream1->ReadResponseBody(buf1.get(), 1, callback1.callback())); |
| 330 | 321 |
| 331 // Stream 1 has been read to completion. | 322 // Stream 1 has been read to completion. |
| 332 TestLoadTimingNotReused(*http_stream1); | 323 TestLoadTimingNotReused(*http_stream1); |
| 333 | 324 |
| 334 EXPECT_EQ(static_cast<int64_t>(req1->size()), | 325 EXPECT_EQ(static_cast<int64_t>(req1.size()), |
| 335 http_stream1->GetTotalSentBytes()); | 326 http_stream1->GetTotalSentBytes()); |
| 336 EXPECT_EQ(static_cast<int64_t>(resp1->size() + body1->size()), | 327 EXPECT_EQ(static_cast<int64_t>(resp1.size() + body1.size()), |
| 337 http_stream1->GetTotalReceivedBytes()); | 328 http_stream1->GetTotalReceivedBytes()); |
| 338 | 329 |
| 339 // Stream 2 still has queued body data. | 330 // Stream 2 still has queued body data. |
| 340 TestLoadTimingReused(*http_stream2); | 331 TestLoadTimingReused(*http_stream2); |
| 341 | 332 |
| 342 EXPECT_EQ(static_cast<int64_t>(req2->size()), | 333 EXPECT_EQ(static_cast<int64_t>(req2.size()), |
| 343 http_stream2->GetTotalSentBytes()); | 334 http_stream2->GetTotalSentBytes()); |
| 344 EXPECT_EQ(static_cast<int64_t>(resp2->size() + body2->size()), | 335 EXPECT_EQ(static_cast<int64_t>(resp2.size() + body2.size()), |
| 345 http_stream2->GetTotalReceivedBytes()); | 336 http_stream2->GetTotalReceivedBytes()); |
| 346 } | 337 } |
| 347 | 338 |
| 348 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { | 339 TEST_P(SpdyHttpStreamTest, SendChunkedPost) { |
| 349 BufferedSpdyFramer framer; | 340 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 350 | 341 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, kUploadData, |
| 351 std::unique_ptr<SpdySerializedFrame> req( | 342 kUploadDataSize, |
| 352 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 343 /*fin=*/true)); |
| 353 std::unique_ptr<SpdySerializedFrame> body( | |
| 354 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_FIN)); | |
| 355 MockWrite writes[] = { | 344 MockWrite writes[] = { |
| 356 CreateMockWrite(*req, 0), // request | 345 CreateMockWrite(req, 0), // request |
| 357 CreateMockWrite(*body, 1) // POST upload frame | 346 CreateMockWrite(body, 1) // POST upload frame |
| 358 }; | 347 }; |
| 359 | 348 |
| 360 std::unique_ptr<SpdySerializedFrame> resp( | 349 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 361 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
| 362 MockRead reads[] = { | 350 MockRead reads[] = { |
| 363 CreateMockRead(*resp, 2), | 351 CreateMockRead(resp, 2), CreateMockRead(body, 3), |
| 364 CreateMockRead(*body, 3), | |
| 365 MockRead(SYNCHRONOUS, 0, 4) // EOF | 352 MockRead(SYNCHRONOUS, 0, 4) // EOF |
| 366 }; | 353 }; |
| 367 | 354 |
| 368 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 355 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 369 | 356 |
| 370 ChunkedUploadDataStream upload_stream(0); | 357 ChunkedUploadDataStream upload_stream(0); |
| 371 const int kFirstChunkSize = kUploadDataSize/2; | 358 const int kFirstChunkSize = kUploadDataSize/2; |
| 372 upload_stream.AppendData(kUploadData, kFirstChunkSize, false); | 359 upload_stream.AppendData(kUploadData, kFirstChunkSize, false); |
| 373 upload_stream.AppendData(kUploadData + kFirstChunkSize, | 360 upload_stream.AppendData(kUploadData + kFirstChunkSize, |
| 374 kUploadDataSize - kFirstChunkSize, true); | 361 kUploadDataSize - kFirstChunkSize, true); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 389 OK, | 376 OK, |
| 390 http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 377 http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 391 net_log, CompletionCallback())); | 378 net_log, CompletionCallback())); |
| 392 | 379 |
| 393 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( | 380 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( |
| 394 headers, &response, callback.callback())); | 381 headers, &response, callback.callback())); |
| 395 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 382 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 396 | 383 |
| 397 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 384 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 398 | 385 |
| 399 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 386 EXPECT_EQ(static_cast<int64_t>(req.size() + body.size()), |
| 400 http_stream.GetTotalSentBytes()); | 387 http_stream.GetTotalSentBytes()); |
| 401 EXPECT_EQ(static_cast<int64_t>(resp->size() + body->size()), | 388 EXPECT_EQ(static_cast<int64_t>(resp.size() + body.size()), |
| 402 http_stream.GetTotalReceivedBytes()); | 389 http_stream.GetTotalReceivedBytes()); |
| 403 | 390 |
| 404 // Because the server closed the connection, we there shouldn't be a session | 391 // Because the server closed the connection, we there shouldn't be a session |
| 405 // in the pool anymore. | 392 // in the pool anymore. |
| 406 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 393 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 407 } | 394 } |
| 408 | 395 |
| 409 // This unittest tests the request callback is properly called and handled. | 396 // This unittest tests the request callback is properly called and handled. |
| 410 TEST_P(SpdyHttpStreamTest, SendChunkedPostLastEmpty) { | 397 TEST_P(SpdyHttpStreamTest, SendChunkedPostLastEmpty) { |
| 411 std::unique_ptr<SpdySerializedFrame> req( | 398 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 412 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 399 SpdySerializedFrame chunk( |
| 413 std::unique_ptr<SpdySerializedFrame> chunk( | 400 spdy_util_.ConstructSpdyDataFrame(1, nullptr, 0, true)); |
| 414 spdy_util_.ConstructSpdyBodyFrame(1, nullptr, 0, true)); | |
| 415 MockWrite writes[] = { | 401 MockWrite writes[] = { |
| 416 CreateMockWrite(*req, 0), // request | 402 CreateMockWrite(req, 0), // request |
| 417 CreateMockWrite(*chunk, 1), | 403 CreateMockWrite(chunk, 1), |
| 418 }; | 404 }; |
| 419 | 405 |
| 420 std::unique_ptr<SpdySerializedFrame> resp( | 406 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 421 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
| 422 MockRead reads[] = { | 407 MockRead reads[] = { |
| 423 CreateMockRead(*resp, 2), | 408 CreateMockRead(resp, 2), CreateMockRead(chunk, 3), |
| 424 CreateMockRead(*chunk, 3), | |
| 425 MockRead(SYNCHRONOUS, 0, 4) // EOF | 409 MockRead(SYNCHRONOUS, 0, 4) // EOF |
| 426 }; | 410 }; |
| 427 | 411 |
| 428 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 412 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 429 | 413 |
| 430 ChunkedUploadDataStream upload_stream(0); | 414 ChunkedUploadDataStream upload_stream(0); |
| 431 upload_stream.AppendData(nullptr, 0, true); | 415 upload_stream.AppendData(nullptr, 0, true); |
| 432 | 416 |
| 433 HttpRequestInfo request; | 417 HttpRequestInfo request; |
| 434 request.method = "POST"; | 418 request.method = "POST"; |
| 435 request.url = GURL("http://www.example.org/"); | 419 request.url = GURL("http://www.example.org/"); |
| 436 request.upload_data_stream = &upload_stream; | 420 request.upload_data_stream = &upload_stream; |
| 437 | 421 |
| 438 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk()); | 422 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk()); |
| 439 | 423 |
| 440 TestCompletionCallback callback; | 424 TestCompletionCallback callback; |
| 441 HttpResponseInfo response; | 425 HttpResponseInfo response; |
| 442 HttpRequestHeaders headers; | 426 HttpRequestHeaders headers; |
| 443 BoundNetLog net_log; | 427 BoundNetLog net_log; |
| 444 SpdyHttpStream http_stream(session_, true); | 428 SpdyHttpStream http_stream(session_, true); |
| 445 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 429 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 446 net_log, CompletionCallback())); | 430 net_log, CompletionCallback())); |
| 447 EXPECT_EQ(ERR_IO_PENDING, | 431 EXPECT_EQ(ERR_IO_PENDING, |
| 448 http_stream.SendRequest(headers, &response, callback.callback())); | 432 http_stream.SendRequest(headers, &response, callback.callback())); |
| 449 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 433 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 450 | 434 |
| 451 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 435 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 452 | 436 |
| 453 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()), | 437 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk.size()), |
| 454 http_stream.GetTotalSentBytes()); | 438 http_stream.GetTotalSentBytes()); |
| 455 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), | 439 EXPECT_EQ(static_cast<int64_t>(resp.size() + chunk.size()), |
| 456 http_stream.GetTotalReceivedBytes()); | 440 http_stream.GetTotalReceivedBytes()); |
| 457 | 441 |
| 458 // Because the server closed the connection, there shouldn't be a session | 442 // Because the server closed the connection, there shouldn't be a session |
| 459 // in the pool anymore. | 443 // in the pool anymore. |
| 460 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 444 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 461 } | 445 } |
| 462 | 446 |
| 463 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { | 447 TEST_P(SpdyHttpStreamTest, ConnectionClosedDuringChunkedPost) { |
| 464 BufferedSpdyFramer framer; | 448 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 465 | 449 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, kUploadData, |
| 466 std::unique_ptr<SpdySerializedFrame> req( | 450 kUploadDataSize, |
| 467 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 451 /*fin=*/false)); |
| 468 std::unique_ptr<SpdySerializedFrame> body( | |
| 469 framer.CreateDataFrame(1, kUploadData, kUploadDataSize, DATA_FLAG_NONE)); | |
| 470 MockWrite writes[] = { | 452 MockWrite writes[] = { |
| 471 CreateMockWrite(*req, 0), // Request | 453 CreateMockWrite(req, 0), // Request |
| 472 CreateMockWrite(*body, 1) // First POST upload frame | 454 CreateMockWrite(body, 1) // First POST upload frame |
| 473 }; | 455 }; |
| 474 | 456 |
| 475 std::unique_ptr<SpdySerializedFrame> resp( | 457 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 476 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
| 477 MockRead reads[] = { | 458 MockRead reads[] = { |
| 478 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. | 459 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2) // Server hangs up early. |
| 479 }; | 460 }; |
| 480 | 461 |
| 481 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 462 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 482 | 463 |
| 483 ChunkedUploadDataStream upload_stream(0); | 464 ChunkedUploadDataStream upload_stream(0); |
| 484 // Append first chunk. | 465 // Append first chunk. |
| 485 upload_stream.AppendData(kUploadData, kUploadDataSize, false); | 466 upload_stream.AppendData(kUploadData, kUploadDataSize, false); |
| 486 | 467 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 498 SpdyHttpStream http_stream(session_, true); | 479 SpdyHttpStream http_stream(session_, true); |
| 499 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 480 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 500 net_log, CompletionCallback())); | 481 net_log, CompletionCallback())); |
| 501 | 482 |
| 502 EXPECT_EQ(ERR_IO_PENDING, | 483 EXPECT_EQ(ERR_IO_PENDING, |
| 503 http_stream.SendRequest(headers, &response, callback.callback())); | 484 http_stream.SendRequest(headers, &response, callback.callback())); |
| 504 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 485 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 505 | 486 |
| 506 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); | 487 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
| 507 | 488 |
| 508 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 489 EXPECT_EQ(static_cast<int64_t>(req.size() + body.size()), |
| 509 http_stream.GetTotalSentBytes()); | 490 http_stream.GetTotalSentBytes()); |
| 510 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); | 491 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); |
| 511 | 492 |
| 512 // Because the server closed the connection, we there shouldn't be a session | 493 // Because the server closed the connection, we there shouldn't be a session |
| 513 // in the pool anymore. | 494 // in the pool anymore. |
| 514 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 495 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 515 | 496 |
| 516 // Appending a second chunk now should not result in a crash. | 497 // Appending a second chunk now should not result in a crash. |
| 517 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 498 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
| 518 // Appending data is currently done synchronously, but seems best to be | 499 // Appending data is currently done synchronously, but seems best to be |
| 519 // paranoid. | 500 // paranoid. |
| 520 base::RunLoop().RunUntilIdle(); | 501 base::RunLoop().RunUntilIdle(); |
| 521 | 502 |
| 522 // The total sent and received bytes should be unchanged. | 503 // The total sent and received bytes should be unchanged. |
| 523 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), | 504 EXPECT_EQ(static_cast<int64_t>(req.size() + body.size()), |
| 524 http_stream.GetTotalSentBytes()); | 505 http_stream.GetTotalSentBytes()); |
| 525 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); | 506 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); |
| 526 } | 507 } |
| 527 | 508 |
| 528 // Test to ensure the SpdyStream state machine does not get confused when a | 509 // Test to ensure the SpdyStream state machine does not get confused when a |
| 529 // chunk becomes available while a write is pending. | 510 // chunk becomes available while a write is pending. |
| 530 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { | 511 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPost) { |
| 531 const char kUploadData1[] = "12345678"; | 512 const char kUploadData1[] = "12345678"; |
| 532 const int kUploadData1Size = arraysize(kUploadData1)-1; | 513 const int kUploadData1Size = arraysize(kUploadData1)-1; |
| 533 std::unique_ptr<SpdySerializedFrame> req( | 514 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 534 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 515 SpdySerializedFrame chunk1(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 535 std::unique_ptr<SpdySerializedFrame> chunk1( | 516 SpdySerializedFrame chunk2(spdy_util_.ConstructSpdyDataFrame( |
| 536 spdy_util_.ConstructSpdyBodyFrame(1, false)); | |
| 537 std::unique_ptr<SpdySerializedFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame( | |
| 538 1, kUploadData1, kUploadData1Size, false)); | 517 1, kUploadData1, kUploadData1Size, false)); |
| 539 std::unique_ptr<SpdySerializedFrame> chunk3( | 518 SpdySerializedFrame chunk3(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 540 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 541 MockWrite writes[] = { | 519 MockWrite writes[] = { |
| 542 CreateMockWrite(*req.get(), 0), | 520 CreateMockWrite(req, 0), |
| 543 CreateMockWrite(*chunk1, 1), // POST upload frames | 521 CreateMockWrite(chunk1, 1), // POST upload frames |
| 544 CreateMockWrite(*chunk2, 2), | 522 CreateMockWrite(chunk2, 2), CreateMockWrite(chunk3, 3), |
| 545 CreateMockWrite(*chunk3, 3), | |
| 546 }; | 523 }; |
| 547 std::unique_ptr<SpdySerializedFrame> resp( | 524 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 548 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
| 549 MockRead reads[] = { | 525 MockRead reads[] = { |
| 550 CreateMockRead(*resp, 4), | 526 CreateMockRead(resp, 4), CreateMockRead(chunk1, 5), |
| 551 CreateMockRead(*chunk1, 5), | 527 CreateMockRead(chunk2, 6), CreateMockRead(chunk3, 7), |
| 552 CreateMockRead(*chunk2, 6), | 528 MockRead(ASYNC, 0, 8) // EOF |
| 553 CreateMockRead(*chunk3, 7), | |
| 554 MockRead(ASYNC, 0, 8) // EOF | |
| 555 }; | 529 }; |
| 556 | 530 |
| 557 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 531 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 558 | 532 |
| 559 ChunkedUploadDataStream upload_stream(0); | 533 ChunkedUploadDataStream upload_stream(0); |
| 560 | 534 |
| 561 HttpRequestInfo request; | 535 HttpRequestInfo request; |
| 562 request.method = "POST"; | 536 request.method = "POST"; |
| 563 request.url = GURL("http://www.example.org/"); | 537 request.url = GURL("http://www.example.org/"); |
| 564 request.upload_data_stream = &upload_stream; | 538 request.upload_data_stream = &upload_stream; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 587 | 561 |
| 588 // Now append the final two chunks which will enqueue two more writes. | 562 // Now append the final two chunks which will enqueue two more writes. |
| 589 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); | 563 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); |
| 590 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 564 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
| 591 | 565 |
| 592 // Finish writing all the chunks and do all reads. | 566 // Finish writing all the chunks and do all reads. |
| 593 base::RunLoop().RunUntilIdle(); | 567 base::RunLoop().RunUntilIdle(); |
| 594 ASSERT_TRUE(callback.have_result()); | 568 ASSERT_TRUE(callback.have_result()); |
| 595 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 569 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 596 | 570 |
| 597 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size() + | 571 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk1.size() + chunk2.size() + |
| 598 chunk3->size()), | 572 chunk3.size()), |
| 599 http_stream->GetTotalSentBytes()); | 573 http_stream->GetTotalSentBytes()); |
| 600 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size() + | 574 EXPECT_EQ(static_cast<int64_t>(resp.size() + chunk1.size() + chunk2.size() + |
| 601 chunk2->size() + chunk3->size()), | 575 chunk3.size()), |
| 602 http_stream->GetTotalReceivedBytes()); | 576 http_stream->GetTotalReceivedBytes()); |
| 603 | 577 |
| 604 // Check response headers. | 578 // Check response headers. |
| 605 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); | 579 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); |
| 606 | 580 |
| 607 // Check |chunk1| response. | 581 // Check |chunk1| response. |
| 608 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 582 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
| 609 ASSERT_EQ(kUploadDataSize, | 583 ASSERT_EQ(kUploadDataSize, |
| 610 http_stream->ReadResponseBody( | 584 http_stream->ReadResponseBody( |
| 611 buf1.get(), kUploadDataSize, callback.callback())); | 585 buf1.get(), kUploadDataSize, callback.callback())); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 625 buf3.get(), kUploadDataSize, callback.callback())); | 599 buf3.get(), kUploadDataSize, callback.callback())); |
| 626 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); | 600 EXPECT_EQ(kUploadData, std::string(buf3->data(), kUploadDataSize)); |
| 627 | 601 |
| 628 ASSERT_TRUE(response.headers.get()); | 602 ASSERT_TRUE(response.headers.get()); |
| 629 ASSERT_EQ(200, response.headers->response_code()); | 603 ASSERT_EQ(200, response.headers->response_code()); |
| 630 } | 604 } |
| 631 | 605 |
| 632 // Test that the SpdyStream state machine can handle sending a final empty data | 606 // Test that the SpdyStream state machine can handle sending a final empty data |
| 633 // frame when uploading a chunked data stream. | 607 // frame when uploading a chunked data stream. |
| 634 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { | 608 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithEmptyFinalDataFrame) { |
| 635 std::unique_ptr<SpdySerializedFrame> req( | 609 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 636 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 610 SpdySerializedFrame chunk1(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 637 std::unique_ptr<SpdySerializedFrame> chunk1( | 611 SpdySerializedFrame chunk2(spdy_util_.ConstructSpdyDataFrame(1, "", 0, true)); |
| 638 spdy_util_.ConstructSpdyBodyFrame(1, false)); | |
| 639 std::unique_ptr<SpdySerializedFrame> chunk2( | |
| 640 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | |
| 641 MockWrite writes[] = { | 612 MockWrite writes[] = { |
| 642 CreateMockWrite(*req.get(), 0), | 613 CreateMockWrite(req, 0), |
| 643 CreateMockWrite(*chunk1, 1), // POST upload frames | 614 CreateMockWrite(chunk1, 1), // POST upload frames |
| 644 CreateMockWrite(*chunk2, 2), | 615 CreateMockWrite(chunk2, 2), |
| 645 }; | 616 }; |
| 646 std::unique_ptr<SpdySerializedFrame> resp( | 617 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 647 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
| 648 MockRead reads[] = { | 618 MockRead reads[] = { |
| 649 CreateMockRead(*resp, 3), | 619 CreateMockRead(resp, 3), CreateMockRead(chunk1, 4), |
| 650 CreateMockRead(*chunk1, 4), | 620 CreateMockRead(chunk2, 5), MockRead(ASYNC, 0, 6) // EOF |
| 651 CreateMockRead(*chunk2, 5), | |
| 652 MockRead(ASYNC, 0, 6) // EOF | |
| 653 }; | 621 }; |
| 654 | 622 |
| 655 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 623 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 656 | 624 |
| 657 ChunkedUploadDataStream upload_stream(0); | 625 ChunkedUploadDataStream upload_stream(0); |
| 658 | 626 |
| 659 HttpRequestInfo request; | 627 HttpRequestInfo request; |
| 660 request.method = "POST"; | 628 request.method = "POST"; |
| 661 request.url = GURL("http://www.example.org/"); | 629 request.url = GURL("http://www.example.org/"); |
| 662 request.upload_data_stream = &upload_stream; | 630 request.upload_data_stream = &upload_stream; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 676 // This will attempt to Write() the initial request and headers, which will | 644 // This will attempt to Write() the initial request and headers, which will |
| 677 // complete asynchronously. | 645 // complete asynchronously. |
| 678 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 646 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
| 679 callback.callback())); | 647 callback.callback())); |
| 680 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 648 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 681 | 649 |
| 682 // Complete the initial request write and the first chunk. | 650 // Complete the initial request write and the first chunk. |
| 683 base::RunLoop().RunUntilIdle(); | 651 base::RunLoop().RunUntilIdle(); |
| 684 ASSERT_FALSE(callback.have_result()); | 652 ASSERT_FALSE(callback.have_result()); |
| 685 | 653 |
| 686 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 654 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk1.size()), |
| 687 http_stream->GetTotalSentBytes()); | 655 http_stream->GetTotalSentBytes()); |
| 688 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 656 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
| 689 | 657 |
| 690 // Now end the stream with an empty data frame and the FIN set. | 658 // Now end the stream with an empty data frame and the FIN set. |
| 691 upload_stream.AppendData(nullptr, 0, true); | 659 upload_stream.AppendData(nullptr, 0, true); |
| 692 | 660 |
| 693 // Finish writing the final frame, and perform all reads. | 661 // Finish writing the final frame, and perform all reads. |
| 694 base::RunLoop().RunUntilIdle(); | 662 base::RunLoop().RunUntilIdle(); |
| 695 ASSERT_TRUE(callback.have_result()); | 663 ASSERT_TRUE(callback.have_result()); |
| 696 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 664 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 697 | 665 |
| 698 // Check response headers. | 666 // Check response headers. |
| 699 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); | 667 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); |
| 700 | 668 |
| 701 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), | 669 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk1.size() + chunk2.size()), |
| 702 http_stream->GetTotalSentBytes()); | 670 http_stream->GetTotalSentBytes()); |
| 703 EXPECT_EQ( | 671 EXPECT_EQ(static_cast<int64_t>(resp.size() + chunk1.size() + chunk2.size()), |
| 704 static_cast<int64_t>(resp->size() + chunk1->size() + chunk2->size()), | 672 http_stream->GetTotalReceivedBytes()); |
| 705 http_stream->GetTotalReceivedBytes()); | |
| 706 | 673 |
| 707 // Check |chunk1| response. | 674 // Check |chunk1| response. |
| 708 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 675 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
| 709 ASSERT_EQ(kUploadDataSize, | 676 ASSERT_EQ(kUploadDataSize, |
| 710 http_stream->ReadResponseBody( | 677 http_stream->ReadResponseBody( |
| 711 buf1.get(), kUploadDataSize, callback.callback())); | 678 buf1.get(), kUploadDataSize, callback.callback())); |
| 712 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 679 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
| 713 | 680 |
| 714 // Check |chunk2| response. | 681 // Check |chunk2| response. |
| 715 ASSERT_EQ(0, | 682 ASSERT_EQ(0, |
| 716 http_stream->ReadResponseBody( | 683 http_stream->ReadResponseBody( |
| 717 buf1.get(), kUploadDataSize, callback.callback())); | 684 buf1.get(), kUploadDataSize, callback.callback())); |
| 718 | 685 |
| 719 ASSERT_TRUE(response.headers.get()); | 686 ASSERT_TRUE(response.headers.get()); |
| 720 ASSERT_EQ(200, response.headers->response_code()); | 687 ASSERT_EQ(200, response.headers->response_code()); |
| 721 } | 688 } |
| 722 | 689 |
| 723 // Test that the SpdyStream state machine handles a chunked upload with no | 690 // Test that the SpdyStream state machine handles a chunked upload with no |
| 724 // payload. Unclear if this is a case worth supporting. | 691 // payload. Unclear if this is a case worth supporting. |
| 725 TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) { | 692 TEST_P(SpdyHttpStreamTest, ChunkedPostWithEmptyPayload) { |
| 726 std::unique_ptr<SpdySerializedFrame> req( | 693 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 727 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 694 SpdySerializedFrame chunk(spdy_util_.ConstructSpdyDataFrame(1, "", 0, true)); |
| 728 std::unique_ptr<SpdySerializedFrame> chunk( | |
| 729 spdy_util_.ConstructSpdyBodyFrame(1, "", 0, true)); | |
| 730 MockWrite writes[] = { | 695 MockWrite writes[] = { |
| 731 CreateMockWrite(*req.get(), 0), | 696 CreateMockWrite(req, 0), CreateMockWrite(chunk, 1), |
| 732 CreateMockWrite(*chunk, 1), | |
| 733 }; | 697 }; |
| 734 std::unique_ptr<SpdySerializedFrame> resp( | 698 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 735 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
| 736 MockRead reads[] = { | 699 MockRead reads[] = { |
| 737 CreateMockRead(*resp, 2), | 700 CreateMockRead(resp, 2), CreateMockRead(chunk, 3), |
| 738 CreateMockRead(*chunk, 3), | 701 MockRead(ASYNC, 0, 4) // EOF |
| 739 MockRead(ASYNC, 0, 4) // EOF | |
| 740 }; | 702 }; |
| 741 | 703 |
| 742 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 704 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 743 | 705 |
| 744 ChunkedUploadDataStream upload_stream(0); | 706 ChunkedUploadDataStream upload_stream(0); |
| 745 | 707 |
| 746 HttpRequestInfo request; | 708 HttpRequestInfo request; |
| 747 request.method = "POST"; | 709 request.method = "POST"; |
| 748 request.url = GURL("http://www.example.org/"); | 710 request.url = GURL("http://www.example.org/"); |
| 749 request.upload_data_stream = &upload_stream; | 711 request.upload_data_stream = &upload_stream; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 764 // complete asynchronously. | 726 // complete asynchronously. |
| 765 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 727 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
| 766 callback.callback())); | 728 callback.callback())); |
| 767 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 729 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 768 | 730 |
| 769 // Complete writing request, followed by a FIN. | 731 // Complete writing request, followed by a FIN. |
| 770 base::RunLoop().RunUntilIdle(); | 732 base::RunLoop().RunUntilIdle(); |
| 771 ASSERT_TRUE(callback.have_result()); | 733 ASSERT_TRUE(callback.have_result()); |
| 772 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 734 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 773 | 735 |
| 774 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()), | 736 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk.size()), |
| 775 http_stream->GetTotalSentBytes()); | 737 http_stream->GetTotalSentBytes()); |
| 776 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), | 738 EXPECT_EQ(static_cast<int64_t>(resp.size() + chunk.size()), |
| 777 http_stream->GetTotalReceivedBytes()); | 739 http_stream->GetTotalReceivedBytes()); |
| 778 | 740 |
| 779 // Check response headers. | 741 // Check response headers. |
| 780 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); | 742 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); |
| 781 | 743 |
| 782 // Check |chunk| response. | 744 // Check |chunk| response. |
| 783 scoped_refptr<IOBuffer> buf(new IOBuffer(1)); | 745 scoped_refptr<IOBuffer> buf(new IOBuffer(1)); |
| 784 ASSERT_EQ(0, | 746 ASSERT_EQ(0, |
| 785 http_stream->ReadResponseBody( | 747 http_stream->ReadResponseBody( |
| 786 buf.get(), 1, callback.callback())); | 748 buf.get(), 1, callback.callback())); |
| 787 | 749 |
| 788 ASSERT_TRUE(response.headers.get()); | 750 ASSERT_TRUE(response.headers.get()); |
| 789 ASSERT_EQ(200, response.headers->response_code()); | 751 ASSERT_EQ(200, response.headers->response_code()); |
| 790 } | 752 } |
| 791 | 753 |
| 792 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 | 754 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 |
| 793 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { | 755 TEST_P(SpdyHttpStreamTest, SpdyURLTest) { |
| 794 const char* const full_url = "http://www.example.org/foo?query=what#anchor"; | 756 const char* const full_url = "http://www.example.org/foo?query=what#anchor"; |
| 795 const char* const base_url = "http://www.example.org/foo?query=what"; | 757 const char* const base_url = "http://www.example.org/foo?query=what"; |
| 796 std::unique_ptr<SpdySerializedFrame> req( | 758 SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(base_url, 1, LOWEST)); |
| 797 spdy_util_.ConstructSpdyGet(base_url, 1, LOWEST)); | |
| 798 MockWrite writes[] = { | 759 MockWrite writes[] = { |
| 799 CreateMockWrite(*req.get(), 0), | 760 CreateMockWrite(req, 0), |
| 800 }; | 761 }; |
| 801 std::unique_ptr<SpdySerializedFrame> resp( | 762 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 802 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); | |
| 803 MockRead reads[] = { | 763 MockRead reads[] = { |
| 804 CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF | 764 CreateMockRead(resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
| 805 }; | 765 }; |
| 806 | 766 |
| 807 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 767 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 808 | 768 |
| 809 HttpRequestInfo request; | 769 HttpRequestInfo request; |
| 810 request.method = "GET"; | 770 request.method = "GET"; |
| 811 request.url = GURL(full_url); | 771 request.url = GURL(full_url); |
| 812 TestCompletionCallback callback; | 772 TestCompletionCallback callback; |
| 813 HttpResponseInfo response; | 773 HttpResponseInfo response; |
| 814 HttpRequestHeaders headers; | 774 HttpRequestHeaders headers; |
| 815 BoundNetLog net_log; | 775 BoundNetLog net_log; |
| 816 std::unique_ptr<SpdyHttpStream> http_stream( | 776 std::unique_ptr<SpdyHttpStream> http_stream( |
| 817 new SpdyHttpStream(session_, true)); | 777 new SpdyHttpStream(session_, true)); |
| 818 ASSERT_EQ(OK, | 778 ASSERT_EQ(OK, |
| 819 http_stream->InitializeStream( | 779 http_stream->InitializeStream( |
| 820 &request, DEFAULT_PRIORITY, net_log, CompletionCallback())); | 780 &request, DEFAULT_PRIORITY, net_log, CompletionCallback())); |
| 821 | 781 |
| 822 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 782 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
| 823 callback.callback())); | 783 callback.callback())); |
| 824 | 784 |
| 825 EXPECT_EQ(base_url, http_stream->stream()->GetUrlFromHeaders().spec()); | 785 EXPECT_EQ(base_url, http_stream->stream()->GetUrlFromHeaders().spec()); |
| 826 | 786 |
| 827 callback.WaitForResult(); | 787 callback.WaitForResult(); |
| 828 | 788 |
| 829 EXPECT_EQ(static_cast<int64_t>(req->size()), | 789 EXPECT_EQ(static_cast<int64_t>(req.size()), http_stream->GetTotalSentBytes()); |
| 830 http_stream->GetTotalSentBytes()); | 790 EXPECT_EQ(static_cast<int64_t>(resp.size()), |
| 831 EXPECT_EQ(static_cast<int64_t>(resp->size()), | |
| 832 http_stream->GetTotalReceivedBytes()); | 791 http_stream->GetTotalReceivedBytes()); |
| 833 | 792 |
| 834 // Because we abandoned the stream, we don't expect to find a session in the | 793 // Because we abandoned the stream, we don't expect to find a session in the |
| 835 // pool anymore. | 794 // pool anymore. |
| 836 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 795 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 837 } | 796 } |
| 838 | 797 |
| 839 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be | 798 // Test the receipt of a WINDOW_UPDATE frame while waiting for a chunk to be |
| 840 // made available is handled correctly. | 799 // made available is handled correctly. |
| 841 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { | 800 TEST_P(SpdyHttpStreamTest, DelayedSendChunkedPostWithWindowUpdate) { |
| 842 std::unique_ptr<SpdySerializedFrame> req( | 801 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 843 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | 802 SpdySerializedFrame chunk1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 844 std::unique_ptr<SpdySerializedFrame> chunk1( | |
| 845 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 846 MockWrite writes[] = { | 803 MockWrite writes[] = { |
| 847 CreateMockWrite(*req.get(), 0), | 804 CreateMockWrite(req, 0), CreateMockWrite(chunk1, 1), |
| 848 CreateMockWrite(*chunk1, 1), | |
| 849 }; | 805 }; |
| 850 std::unique_ptr<SpdySerializedFrame> resp( | 806 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 851 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | 807 SpdySerializedFrame window_update( |
| 852 std::unique_ptr<SpdySerializedFrame> window_update( | |
| 853 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); | 808 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
| 854 MockRead reads[] = { | 809 MockRead reads[] = { |
| 855 CreateMockRead(*window_update, 2), | 810 CreateMockRead(window_update, 2), MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 856 MockRead(ASYNC, ERR_IO_PENDING, 3), | 811 CreateMockRead(resp, 4), CreateMockRead(chunk1, 5), |
| 857 CreateMockRead(*resp, 4), | |
| 858 CreateMockRead(*chunk1, 5), | |
| 859 MockRead(ASYNC, 0, 6) // EOF | 812 MockRead(ASYNC, 0, 6) // EOF |
| 860 }; | 813 }; |
| 861 | 814 |
| 862 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 815 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 863 | 816 |
| 864 ChunkedUploadDataStream upload_stream(0); | 817 ChunkedUploadDataStream upload_stream(0); |
| 865 | 818 |
| 866 HttpRequestInfo request; | 819 HttpRequestInfo request; |
| 867 request.method = "POST"; | 820 request.method = "POST"; |
| 868 request.url = GURL("http://www.example.org/"); | 821 request.url = GURL("http://www.example.org/"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 882 // complete asynchronously. | 835 // complete asynchronously. |
| 883 TestCompletionCallback callback; | 836 TestCompletionCallback callback; |
| 884 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 837 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
| 885 callback.callback())); | 838 callback.callback())); |
| 886 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 839 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 887 | 840 |
| 888 // Complete the initial request write and first chunk. | 841 // Complete the initial request write and first chunk. |
| 889 base::RunLoop().RunUntilIdle(); | 842 base::RunLoop().RunUntilIdle(); |
| 890 ASSERT_FALSE(callback.have_result()); | 843 ASSERT_FALSE(callback.have_result()); |
| 891 | 844 |
| 892 EXPECT_EQ(static_cast<int64_t>(req->size()), | 845 EXPECT_EQ(static_cast<int64_t>(req.size()), http_stream->GetTotalSentBytes()); |
| 893 http_stream->GetTotalSentBytes()); | |
| 894 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 846 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
| 895 | 847 |
| 896 upload_stream.AppendData(kUploadData, kUploadDataSize, true); | 848 upload_stream.AppendData(kUploadData, kUploadDataSize, true); |
| 897 | 849 |
| 898 ASSERT_TRUE(callback.have_result()); | 850 ASSERT_TRUE(callback.have_result()); |
| 899 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 851 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 900 | 852 |
| 901 // Verify that the window size has decreased. | 853 // Verify that the window size has decreased. |
| 902 ASSERT_TRUE(http_stream->stream() != nullptr); | 854 ASSERT_TRUE(http_stream->stream() != nullptr); |
| 903 EXPECT_NE(static_cast<int>(kDefaultInitialWindowSize), | 855 EXPECT_NE(static_cast<int>(kDefaultInitialWindowSize), |
| 904 http_stream->stream()->send_window_size()); | 856 http_stream->stream()->send_window_size()); |
| 905 | 857 |
| 906 // Read window update. | 858 // Read window update. |
| 907 base::RunLoop().RunUntilIdle(); | 859 base::RunLoop().RunUntilIdle(); |
| 908 | 860 |
| 909 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 861 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk1.size()), |
| 910 http_stream->GetTotalSentBytes()); | 862 http_stream->GetTotalSentBytes()); |
| 911 // The window update is not counted in the total received bytes. | 863 // The window update is not counted in the total received bytes. |
| 912 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); | 864 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); |
| 913 | 865 |
| 914 // Verify the window update. | 866 // Verify the window update. |
| 915 ASSERT_TRUE(http_stream->stream() != nullptr); | 867 ASSERT_TRUE(http_stream->stream() != nullptr); |
| 916 EXPECT_EQ(static_cast<int>(kDefaultInitialWindowSize), | 868 EXPECT_EQ(static_cast<int>(kDefaultInitialWindowSize), |
| 917 http_stream->stream()->send_window_size()); | 869 http_stream->stream()->send_window_size()); |
| 918 | 870 |
| 919 // Read rest of data. | 871 // Read rest of data. |
| 920 sequenced_data_->Resume(); | 872 sequenced_data_->Resume(); |
| 921 base::RunLoop().RunUntilIdle(); | 873 base::RunLoop().RunUntilIdle(); |
| 922 | 874 |
| 923 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), | 875 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk1.size()), |
| 924 http_stream->GetTotalSentBytes()); | 876 http_stream->GetTotalSentBytes()); |
| 925 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()), | 877 EXPECT_EQ(static_cast<int64_t>(resp.size() + chunk1.size()), |
| 926 http_stream->GetTotalReceivedBytes()); | 878 http_stream->GetTotalReceivedBytes()); |
| 927 | 879 |
| 928 // Check response headers. | 880 // Check response headers. |
| 929 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); | 881 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk()); |
| 930 | 882 |
| 931 // Check |chunk1| response. | 883 // Check |chunk1| response. |
| 932 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); | 884 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); |
| 933 ASSERT_EQ(kUploadDataSize, | 885 ASSERT_EQ(kUploadDataSize, |
| 934 http_stream->ReadResponseBody( | 886 http_stream->ReadResponseBody( |
| 935 buf1.get(), kUploadDataSize, callback.callback())); | 887 buf1.get(), kUploadDataSize, callback.callback())); |
| 936 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); | 888 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); |
| 937 | 889 |
| 938 ASSERT_TRUE(response.headers.get()); | 890 ASSERT_TRUE(response.headers.get()); |
| 939 ASSERT_EQ(200, response.headers->response_code()); | 891 ASSERT_EQ(200, response.headers->response_code()); |
| 940 } | 892 } |
| 941 | 893 |
| 942 TEST_P(SpdyHttpStreamTest, DataReadErrorSynchronous) { | 894 TEST_P(SpdyHttpStreamTest, DataReadErrorSynchronous) { |
| 943 std::unique_ptr<SpdySerializedFrame> req( | 895 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 944 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | |
| 945 | 896 |
| 946 // Server receives RST_STREAM_INTERNAL_ERROR on client's internal failure. | 897 // Server receives RST_STREAM_INTERNAL_ERROR on client's internal failure. |
| 947 // The failure is a reading error in this case caused by | 898 // The failure is a reading error in this case caused by |
| 948 // UploadDataStream::Read(). | 899 // UploadDataStream::Read(). |
| 949 std::unique_ptr<SpdySerializedFrame> rst_frame( | 900 SpdySerializedFrame rst_frame( |
| 950 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); | 901 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
| 951 | 902 |
| 952 MockWrite writes[] = { | 903 MockWrite writes[] = { |
| 953 CreateMockWrite(*req, 0, SYNCHRONOUS), // Request | 904 CreateMockWrite(req, 0, SYNCHRONOUS), // Request |
| 954 CreateMockWrite(*rst_frame, 1, SYNCHRONOUS) // Reset frame | 905 CreateMockWrite(rst_frame, 1, SYNCHRONOUS) // Reset frame |
| 955 }; | 906 }; |
| 956 | 907 |
| 957 std::unique_ptr<SpdySerializedFrame> resp( | 908 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 958 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
| 959 | 909 |
| 960 MockRead reads[] = { | 910 MockRead reads[] = { |
| 961 CreateMockRead(*resp, 2), MockRead(SYNCHRONOUS, 0, 3), | 911 CreateMockRead(resp, 2), MockRead(SYNCHRONOUS, 0, 3), |
| 962 }; | 912 }; |
| 963 | 913 |
| 964 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 914 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 965 | 915 |
| 966 ReadErrorUploadDataStream upload_data_stream( | 916 ReadErrorUploadDataStream upload_data_stream( |
| 967 ReadErrorUploadDataStream::FailureMode::SYNC); | 917 ReadErrorUploadDataStream::FailureMode::SYNC); |
| 968 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), | 918 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), |
| 969 IsOk()); | 919 IsOk()); |
| 970 | 920 |
| 971 HttpRequestInfo request; | 921 HttpRequestInfo request; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 983 | 933 |
| 984 int result = http_stream.SendRequest(headers, &response, callback.callback()); | 934 int result = http_stream.SendRequest(headers, &response, callback.callback()); |
| 985 EXPECT_THAT(callback.GetResult(result), IsError(ERR_FAILED)); | 935 EXPECT_THAT(callback.GetResult(result), IsError(ERR_FAILED)); |
| 986 | 936 |
| 987 // Because the server has not closed the connection yet, there shouldn't be | 937 // Because the server has not closed the connection yet, there shouldn't be |
| 988 // a stream but a session in the pool | 938 // a stream but a session in the pool |
| 989 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 939 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 990 } | 940 } |
| 991 | 941 |
| 992 TEST_P(SpdyHttpStreamTest, DataReadErrorAsynchronous) { | 942 TEST_P(SpdyHttpStreamTest, DataReadErrorAsynchronous) { |
| 993 std::unique_ptr<SpdySerializedFrame> req( | 943 SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); |
| 994 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); | |
| 995 | 944 |
| 996 // Server receives RST_STREAM_INTERNAL_ERROR on client's internal failure. | 945 // Server receives RST_STREAM_INTERNAL_ERROR on client's internal failure. |
| 997 // The failure is a reading error in this case caused by | 946 // The failure is a reading error in this case caused by |
| 998 // UploadDataStream::Read(). | 947 // UploadDataStream::Read(). |
| 999 std::unique_ptr<SpdySerializedFrame> rst_frame( | 948 SpdySerializedFrame rst_frame( |
| 1000 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); | 949 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
| 1001 | 950 |
| 1002 MockWrite writes[] = { | 951 MockWrite writes[] = { |
| 1003 CreateMockWrite(*req, 0), // Request | 952 CreateMockWrite(req, 0), // Request |
| 1004 CreateMockWrite(*rst_frame, 1) // Reset frame | 953 CreateMockWrite(rst_frame, 1) // Reset frame |
| 1005 }; | 954 }; |
| 1006 | 955 |
| 1007 std::unique_ptr<SpdySerializedFrame> resp( | 956 SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); |
| 1008 spdy_util_.ConstructSpdyPostSynReply(nullptr, 0)); | |
| 1009 | 957 |
| 1010 MockRead reads[] = { | 958 MockRead reads[] = { |
| 1011 MockRead(ASYNC, 0, 2), | 959 MockRead(ASYNC, 0, 2), |
| 1012 }; | 960 }; |
| 1013 | 961 |
| 1014 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 962 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 1015 | 963 |
| 1016 ReadErrorUploadDataStream upload_data_stream( | 964 ReadErrorUploadDataStream upload_data_stream( |
| 1017 ReadErrorUploadDataStream::FailureMode::ASYNC); | 965 ReadErrorUploadDataStream::FailureMode::ASYNC); |
| 1018 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), | 966 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1037 | 985 |
| 1038 // Because the server has closed the connection, there shouldn't be a session | 986 // Because the server has closed the connection, there shouldn't be a session |
| 1039 // in the pool anymore. | 987 // in the pool anymore. |
| 1040 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 988 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 1041 } | 989 } |
| 1042 | 990 |
| 1043 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 991 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
| 1044 // methods. | 992 // methods. |
| 1045 | 993 |
| 1046 } // namespace net | 994 } // namespace net |
| OLD | NEW |