| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 public: | 69 public: |
| 70 enum class FailureMode { SYNC, ASYNC }; | 70 enum class FailureMode { SYNC, ASYNC }; |
| 71 | 71 |
| 72 explicit ReadErrorUploadDataStream(FailureMode mode) | 72 explicit ReadErrorUploadDataStream(FailureMode mode) |
| 73 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} | 73 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } | 76 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } |
| 77 | 77 |
| 78 // UploadDataStream implementation: | 78 // UploadDataStream implementation: |
| 79 int InitInternal(const BoundNetLog& net_log) override { return OK; } | 79 int InitInternal(const NetLogWithSource& net_log) override { return OK; } |
| 80 | 80 |
| 81 int ReadInternal(IOBuffer* buf, int buf_len) override { | 81 int ReadInternal(IOBuffer* buf, int buf_len) override { |
| 82 if (async_ == FailureMode::ASYNC) { | 82 if (async_ == FailureMode::ASYNC) { |
| 83 base::ThreadTaskRunnerHandle::Get()->PostTask( | 83 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 84 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, | 84 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, |
| 85 weak_factory_.GetWeakPtr())); | 85 weak_factory_.GetWeakPtr())); |
| 86 return ERR_IO_PENDING; | 86 return ERR_IO_PENDING; |
| 87 } | 87 } |
| 88 return ERR_FAILED; | 88 return ERR_FAILED; |
| 89 } | 89 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 // Initializes the session using SequencedSocketData. | 140 // Initializes the session using SequencedSocketData. |
| 141 void InitSession(MockRead* reads, | 141 void InitSession(MockRead* reads, |
| 142 size_t reads_count, | 142 size_t reads_count, |
| 143 MockWrite* writes, | 143 MockWrite* writes, |
| 144 size_t writes_count) { | 144 size_t writes_count) { |
| 145 sequenced_data_.reset( | 145 sequenced_data_.reset( |
| 146 new SequencedSocketData(reads, reads_count, writes, writes_count)); | 146 new SequencedSocketData(reads, reads_count, writes, writes_count)); |
| 147 session_deps_.socket_factory->AddSocketDataProvider(sequenced_data_.get()); | 147 session_deps_.socket_factory->AddSocketDataProvider(sequenced_data_.get()); |
| 148 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 148 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 149 session_ = | 149 session_ = CreateInsecureSpdySession(http_session_.get(), key_, |
| 150 CreateInsecureSpdySession(http_session_.get(), key_, BoundNetLog()); | 150 NetLogWithSource()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void TestSendCredentials( | 153 void TestSendCredentials( |
| 154 ChannelIDService* channel_id_service, | 154 ChannelIDService* channel_id_service, |
| 155 const std::string& cert, | 155 const std::string& cert, |
| 156 const std::string& proof); | 156 const std::string& proof); |
| 157 | 157 |
| 158 SpdyTestUtil spdy_util_; | 158 SpdyTestUtil spdy_util_; |
| 159 TestNetLog net_log_; | 159 TestNetLog net_log_; |
| 160 SpdySessionDependencies session_deps_; | 160 SpdySessionDependencies session_deps_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 182 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 183 | 183 |
| 184 HttpRequestInfo request; | 184 HttpRequestInfo request; |
| 185 request.method = "GET"; | 185 request.method = "GET"; |
| 186 request.url = GURL("http://www.example.org/"); | 186 request.url = GURL("http://www.example.org/"); |
| 187 TestCompletionCallback callback; | 187 TestCompletionCallback callback; |
| 188 HttpResponseInfo response; | 188 HttpResponseInfo response; |
| 189 HttpRequestHeaders headers; | 189 HttpRequestHeaders headers; |
| 190 BoundNetLog net_log; | 190 NetLogWithSource net_log; |
| 191 std::unique_ptr<SpdyHttpStream> http_stream( | 191 std::unique_ptr<SpdyHttpStream> http_stream( |
| 192 new SpdyHttpStream(session_, true)); | 192 new SpdyHttpStream(session_, true)); |
| 193 // Make sure getting load timing information the stream early does not crash. | 193 // Make sure getting load timing information the stream early does not crash. |
| 194 LoadTimingInfo load_timing_info; | 194 LoadTimingInfo load_timing_info; |
| 195 EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); | 195 EXPECT_FALSE(http_stream->GetLoadTimingInfo(&load_timing_info)); |
| 196 | 196 |
| 197 ASSERT_EQ( | 197 ASSERT_EQ( |
| 198 OK, | 198 OK, |
| 199 http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 199 http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
| 200 net_log, CompletionCallback())); | 200 net_log, CompletionCallback())); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 HttpRequestInfo request2; | 257 HttpRequestInfo request2; |
| 258 request2.method = "GET"; | 258 request2.method = "GET"; |
| 259 request2.url = GURL("http://www.example.org/"); | 259 request2.url = GURL("http://www.example.org/"); |
| 260 TestCompletionCallback callback2; | 260 TestCompletionCallback callback2; |
| 261 HttpResponseInfo response2; | 261 HttpResponseInfo response2; |
| 262 HttpRequestHeaders headers2; | 262 HttpRequestHeaders headers2; |
| 263 std::unique_ptr<SpdyHttpStream> http_stream2( | 263 std::unique_ptr<SpdyHttpStream> http_stream2( |
| 264 new SpdyHttpStream(session_, true)); | 264 new SpdyHttpStream(session_, true)); |
| 265 | 265 |
| 266 // First write. | 266 // First write. |
| 267 ASSERT_EQ(OK, | 267 ASSERT_EQ(OK, http_stream1->InitializeStream(&request1, DEFAULT_PRIORITY, |
| 268 http_stream1->InitializeStream(&request1, DEFAULT_PRIORITY, | 268 NetLogWithSource(), |
| 269 BoundNetLog(), | 269 CompletionCallback())); |
| 270 CompletionCallback())); | |
| 271 EXPECT_EQ(ERR_IO_PENDING, http_stream1->SendRequest(headers1, &response1, | 270 EXPECT_EQ(ERR_IO_PENDING, http_stream1->SendRequest(headers1, &response1, |
| 272 callback1.callback())); | 271 callback1.callback())); |
| 273 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 272 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 274 | 273 |
| 275 EXPECT_LE(0, callback1.WaitForResult()); | 274 EXPECT_LE(0, callback1.WaitForResult()); |
| 276 | 275 |
| 277 TestLoadTimingNotReused(*http_stream1); | 276 TestLoadTimingNotReused(*http_stream1); |
| 278 LoadTimingInfo load_timing_info1; | 277 LoadTimingInfo load_timing_info1; |
| 279 LoadTimingInfo load_timing_info2; | 278 LoadTimingInfo load_timing_info2; |
| 280 EXPECT_TRUE(http_stream1->GetLoadTimingInfo(&load_timing_info1)); | 279 EXPECT_TRUE(http_stream1->GetLoadTimingInfo(&load_timing_info1)); |
| 281 EXPECT_FALSE(http_stream2->GetLoadTimingInfo(&load_timing_info2)); | 280 EXPECT_FALSE(http_stream2->GetLoadTimingInfo(&load_timing_info2)); |
| 282 | 281 |
| 283 // Second write. | 282 // Second write. |
| 284 ASSERT_EQ(OK, | 283 ASSERT_EQ(OK, http_stream2->InitializeStream(&request2, DEFAULT_PRIORITY, |
| 285 http_stream2->InitializeStream(&request2, DEFAULT_PRIORITY, | 284 NetLogWithSource(), |
| 286 BoundNetLog(), | 285 CompletionCallback())); |
| 287 CompletionCallback())); | |
| 288 EXPECT_EQ(ERR_IO_PENDING, http_stream2->SendRequest(headers2, &response2, | 286 EXPECT_EQ(ERR_IO_PENDING, http_stream2->SendRequest(headers2, &response2, |
| 289 callback2.callback())); | 287 callback2.callback())); |
| 290 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 288 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 291 | 289 |
| 292 EXPECT_LE(0, callback2.WaitForResult()); | 290 EXPECT_LE(0, callback2.WaitForResult()); |
| 293 TestLoadTimingReused(*http_stream2); | 291 TestLoadTimingReused(*http_stream2); |
| 294 EXPECT_TRUE(http_stream2->GetLoadTimingInfo(&load_timing_info2)); | 292 EXPECT_TRUE(http_stream2->GetLoadTimingInfo(&load_timing_info2)); |
| 295 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | 293 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 296 | 294 |
| 297 // Read stream 1 to completion, before making sure we can still read load | 295 // Read stream 1 to completion, before making sure we can still read load |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 const int kFirstChunkSize = kUploadDataSize/2; | 337 const int kFirstChunkSize = kUploadDataSize/2; |
| 340 upload_stream.AppendData(kUploadData, kFirstChunkSize, false); | 338 upload_stream.AppendData(kUploadData, kFirstChunkSize, false); |
| 341 upload_stream.AppendData(kUploadData + kFirstChunkSize, | 339 upload_stream.AppendData(kUploadData + kFirstChunkSize, |
| 342 kUploadDataSize - kFirstChunkSize, true); | 340 kUploadDataSize - kFirstChunkSize, true); |
| 343 | 341 |
| 344 HttpRequestInfo request; | 342 HttpRequestInfo request; |
| 345 request.method = "POST"; | 343 request.method = "POST"; |
| 346 request.url = GURL("http://www.example.org/"); | 344 request.url = GURL("http://www.example.org/"); |
| 347 request.upload_data_stream = &upload_stream; | 345 request.upload_data_stream = &upload_stream; |
| 348 | 346 |
| 349 ASSERT_THAT( | 347 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback(), |
| 350 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), | 348 NetLogWithSource()), |
| 351 IsOk()); | 349 IsOk()); |
| 352 | 350 |
| 353 TestCompletionCallback callback; | 351 TestCompletionCallback callback; |
| 354 HttpResponseInfo response; | 352 HttpResponseInfo response; |
| 355 HttpRequestHeaders headers; | 353 HttpRequestHeaders headers; |
| 356 BoundNetLog net_log; | 354 NetLogWithSource net_log; |
| 357 SpdyHttpStream http_stream(session_, true); | 355 SpdyHttpStream http_stream(session_, true); |
| 358 ASSERT_EQ( | 356 ASSERT_EQ( |
| 359 OK, | 357 OK, |
| 360 http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 358 http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 361 net_log, CompletionCallback())); | 359 net_log, CompletionCallback())); |
| 362 | 360 |
| 363 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( | 361 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( |
| 364 headers, &response, callback.callback())); | 362 headers, &response, callback.callback())); |
| 365 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 363 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 366 | 364 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 395 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 393 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 396 | 394 |
| 397 ChunkedUploadDataStream upload_stream(0); | 395 ChunkedUploadDataStream upload_stream(0); |
| 398 upload_stream.AppendData(nullptr, 0, true); | 396 upload_stream.AppendData(nullptr, 0, true); |
| 399 | 397 |
| 400 HttpRequestInfo request; | 398 HttpRequestInfo request; |
| 401 request.method = "POST"; | 399 request.method = "POST"; |
| 402 request.url = GURL("http://www.example.org/"); | 400 request.url = GURL("http://www.example.org/"); |
| 403 request.upload_data_stream = &upload_stream; | 401 request.upload_data_stream = &upload_stream; |
| 404 | 402 |
| 405 ASSERT_THAT( | 403 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback(), |
| 406 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), | 404 NetLogWithSource()), |
| 407 IsOk()); | 405 IsOk()); |
| 408 | 406 |
| 409 TestCompletionCallback callback; | 407 TestCompletionCallback callback; |
| 410 HttpResponseInfo response; | 408 HttpResponseInfo response; |
| 411 HttpRequestHeaders headers; | 409 HttpRequestHeaders headers; |
| 412 BoundNetLog net_log; | 410 NetLogWithSource net_log; |
| 413 SpdyHttpStream http_stream(session_, true); | 411 SpdyHttpStream http_stream(session_, true); |
| 414 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 412 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 415 net_log, CompletionCallback())); | 413 net_log, CompletionCallback())); |
| 416 EXPECT_EQ(ERR_IO_PENDING, | 414 EXPECT_EQ(ERR_IO_PENDING, |
| 417 http_stream.SendRequest(headers, &response, callback.callback())); | 415 http_stream.SendRequest(headers, &response, callback.callback())); |
| 418 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 416 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 419 | 417 |
| 420 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 418 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 421 | 419 |
| 422 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk.size()), | 420 EXPECT_EQ(static_cast<int64_t>(req.size() + chunk.size()), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 448 | 446 |
| 449 ChunkedUploadDataStream upload_stream(0); | 447 ChunkedUploadDataStream upload_stream(0); |
| 450 // Append first chunk. | 448 // Append first chunk. |
| 451 upload_stream.AppendData(kUploadData, kUploadDataSize, false); | 449 upload_stream.AppendData(kUploadData, kUploadDataSize, false); |
| 452 | 450 |
| 453 HttpRequestInfo request; | 451 HttpRequestInfo request; |
| 454 request.method = "POST"; | 452 request.method = "POST"; |
| 455 request.url = GURL("http://www.example.org/"); | 453 request.url = GURL("http://www.example.org/"); |
| 456 request.upload_data_stream = &upload_stream; | 454 request.upload_data_stream = &upload_stream; |
| 457 | 455 |
| 458 ASSERT_THAT( | 456 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback(), |
| 459 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), | 457 NetLogWithSource()), |
| 460 IsOk()); | 458 IsOk()); |
| 461 | 459 |
| 462 TestCompletionCallback callback; | 460 TestCompletionCallback callback; |
| 463 HttpResponseInfo response; | 461 HttpResponseInfo response; |
| 464 HttpRequestHeaders headers; | 462 HttpRequestHeaders headers; |
| 465 BoundNetLog net_log; | 463 NetLogWithSource net_log; |
| 466 SpdyHttpStream http_stream(session_, true); | 464 SpdyHttpStream http_stream(session_, true); |
| 467 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 465 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 468 net_log, CompletionCallback())); | 466 net_log, CompletionCallback())); |
| 469 | 467 |
| 470 EXPECT_EQ(ERR_IO_PENDING, | 468 EXPECT_EQ(ERR_IO_PENDING, |
| 471 http_stream.SendRequest(headers, &response, callback.callback())); | 469 http_stream.SendRequest(headers, &response, callback.callback())); |
| 472 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 470 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 473 | 471 |
| 474 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); | 472 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
| 475 | 473 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 515 |
| 518 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 516 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 519 | 517 |
| 520 ChunkedUploadDataStream upload_stream(0); | 518 ChunkedUploadDataStream upload_stream(0); |
| 521 | 519 |
| 522 HttpRequestInfo request; | 520 HttpRequestInfo request; |
| 523 request.method = "POST"; | 521 request.method = "POST"; |
| 524 request.url = GURL("http://www.example.org/"); | 522 request.url = GURL("http://www.example.org/"); |
| 525 request.upload_data_stream = &upload_stream; | 523 request.upload_data_stream = &upload_stream; |
| 526 | 524 |
| 527 ASSERT_THAT( | 525 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback(), |
| 528 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), | 526 NetLogWithSource()), |
| 529 IsOk()); | 527 IsOk()); |
| 530 upload_stream.AppendData(kUploadData, kUploadDataSize, false); | 528 upload_stream.AppendData(kUploadData, kUploadDataSize, false); |
| 531 | 529 |
| 532 BoundNetLog net_log; | 530 NetLogWithSource net_log; |
| 533 std::unique_ptr<SpdyHttpStream> http_stream( | 531 std::unique_ptr<SpdyHttpStream> http_stream( |
| 534 new SpdyHttpStream(session_, true)); | 532 new SpdyHttpStream(session_, true)); |
| 535 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 533 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
| 536 net_log, CompletionCallback())); | 534 net_log, CompletionCallback())); |
| 537 | 535 |
| 538 TestCompletionCallback callback; | 536 TestCompletionCallback callback; |
| 539 HttpRequestHeaders headers; | 537 HttpRequestHeaders headers; |
| 540 HttpResponseInfo response; | 538 HttpResponseInfo response; |
| 541 // This will attempt to Write() the initial request and headers, which will | 539 // This will attempt to Write() the initial request and headers, which will |
| 542 // complete asynchronously. | 540 // complete asynchronously. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 609 |
| 612 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 610 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 613 | 611 |
| 614 ChunkedUploadDataStream upload_stream(0); | 612 ChunkedUploadDataStream upload_stream(0); |
| 615 | 613 |
| 616 HttpRequestInfo request; | 614 HttpRequestInfo request; |
| 617 request.method = "POST"; | 615 request.method = "POST"; |
| 618 request.url = GURL("http://www.example.org/"); | 616 request.url = GURL("http://www.example.org/"); |
| 619 request.upload_data_stream = &upload_stream; | 617 request.upload_data_stream = &upload_stream; |
| 620 | 618 |
| 621 ASSERT_THAT( | 619 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback(), |
| 622 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), | 620 NetLogWithSource()), |
| 623 IsOk()); | 621 IsOk()); |
| 624 upload_stream.AppendData(kUploadData, kUploadDataSize, false); | 622 upload_stream.AppendData(kUploadData, kUploadDataSize, false); |
| 625 | 623 |
| 626 BoundNetLog net_log; | 624 NetLogWithSource net_log; |
| 627 std::unique_ptr<SpdyHttpStream> http_stream( | 625 std::unique_ptr<SpdyHttpStream> http_stream( |
| 628 new SpdyHttpStream(session_, true)); | 626 new SpdyHttpStream(session_, true)); |
| 629 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 627 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
| 630 net_log, CompletionCallback())); | 628 net_log, CompletionCallback())); |
| 631 | 629 |
| 632 TestCompletionCallback callback; | 630 TestCompletionCallback callback; |
| 633 HttpRequestHeaders headers; | 631 HttpRequestHeaders headers; |
| 634 HttpResponseInfo response; | 632 HttpResponseInfo response; |
| 635 // This will attempt to Write() the initial request and headers, which will | 633 // This will attempt to Write() the initial request and headers, which will |
| 636 // complete asynchronously. | 634 // complete asynchronously. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 692 |
| 695 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 693 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 696 | 694 |
| 697 ChunkedUploadDataStream upload_stream(0); | 695 ChunkedUploadDataStream upload_stream(0); |
| 698 | 696 |
| 699 HttpRequestInfo request; | 697 HttpRequestInfo request; |
| 700 request.method = "POST"; | 698 request.method = "POST"; |
| 701 request.url = GURL("http://www.example.org/"); | 699 request.url = GURL("http://www.example.org/"); |
| 702 request.upload_data_stream = &upload_stream; | 700 request.upload_data_stream = &upload_stream; |
| 703 | 701 |
| 704 ASSERT_THAT( | 702 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback(), |
| 705 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), | 703 NetLogWithSource()), |
| 706 IsOk()); | 704 IsOk()); |
| 707 upload_stream.AppendData("", 0, true); | 705 upload_stream.AppendData("", 0, true); |
| 708 | 706 |
| 709 BoundNetLog net_log; | 707 NetLogWithSource net_log; |
| 710 std::unique_ptr<SpdyHttpStream> http_stream( | 708 std::unique_ptr<SpdyHttpStream> http_stream( |
| 711 new SpdyHttpStream(session_, true)); | 709 new SpdyHttpStream(session_, true)); |
| 712 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 710 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
| 713 net_log, CompletionCallback())); | 711 net_log, CompletionCallback())); |
| 714 | 712 |
| 715 TestCompletionCallback callback; | 713 TestCompletionCallback callback; |
| 716 HttpRequestHeaders headers; | 714 HttpRequestHeaders headers; |
| 717 HttpResponseInfo response; | 715 HttpResponseInfo response; |
| 718 // This will attempt to Write() the initial request and headers, which will | 716 // This will attempt to Write() the initial request and headers, which will |
| 719 // complete asynchronously. | 717 // complete asynchronously. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 }; | 756 }; |
| 759 | 757 |
| 760 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 758 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 761 | 759 |
| 762 HttpRequestInfo request; | 760 HttpRequestInfo request; |
| 763 request.method = "GET"; | 761 request.method = "GET"; |
| 764 request.url = GURL(full_url); | 762 request.url = GURL(full_url); |
| 765 TestCompletionCallback callback; | 763 TestCompletionCallback callback; |
| 766 HttpResponseInfo response; | 764 HttpResponseInfo response; |
| 767 HttpRequestHeaders headers; | 765 HttpRequestHeaders headers; |
| 768 BoundNetLog net_log; | 766 NetLogWithSource net_log; |
| 769 std::unique_ptr<SpdyHttpStream> http_stream( | 767 std::unique_ptr<SpdyHttpStream> http_stream( |
| 770 new SpdyHttpStream(session_, true)); | 768 new SpdyHttpStream(session_, true)); |
| 771 ASSERT_EQ(OK, | 769 ASSERT_EQ(OK, |
| 772 http_stream->InitializeStream( | 770 http_stream->InitializeStream( |
| 773 &request, DEFAULT_PRIORITY, net_log, CompletionCallback())); | 771 &request, DEFAULT_PRIORITY, net_log, CompletionCallback())); |
| 774 | 772 |
| 775 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, | 773 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, |
| 776 callback.callback())); | 774 callback.callback())); |
| 777 | 775 |
| 778 EXPECT_EQ(base_url, http_stream->stream()->GetUrlFromHeaders().spec()); | 776 EXPECT_EQ(base_url, http_stream->stream()->GetUrlFromHeaders().spec()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 807 | 805 |
| 808 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 806 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 809 | 807 |
| 810 ChunkedUploadDataStream upload_stream(0); | 808 ChunkedUploadDataStream upload_stream(0); |
| 811 | 809 |
| 812 HttpRequestInfo request; | 810 HttpRequestInfo request; |
| 813 request.method = "POST"; | 811 request.method = "POST"; |
| 814 request.url = GURL("http://www.example.org/"); | 812 request.url = GURL("http://www.example.org/"); |
| 815 request.upload_data_stream = &upload_stream; | 813 request.upload_data_stream = &upload_stream; |
| 816 | 814 |
| 817 ASSERT_THAT( | 815 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback(), |
| 818 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), | 816 NetLogWithSource()), |
| 819 IsOk()); | 817 IsOk()); |
| 820 | 818 |
| 821 BoundNetLog net_log; | 819 NetLogWithSource net_log; |
| 822 std::unique_ptr<SpdyHttpStream> http_stream( | 820 std::unique_ptr<SpdyHttpStream> http_stream( |
| 823 new SpdyHttpStream(session_, true)); | 821 new SpdyHttpStream(session_, true)); |
| 824 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, | 822 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, |
| 825 net_log, CompletionCallback())); | 823 net_log, CompletionCallback())); |
| 826 | 824 |
| 827 HttpRequestHeaders headers; | 825 HttpRequestHeaders headers; |
| 828 HttpResponseInfo response; | 826 HttpResponseInfo response; |
| 829 // This will attempt to Write() the initial request and headers, which will | 827 // This will attempt to Write() the initial request and headers, which will |
| 830 // complete asynchronously. | 828 // complete asynchronously. |
| 831 TestCompletionCallback callback; | 829 TestCompletionCallback callback; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 | 902 |
| 905 MockRead reads[] = { | 903 MockRead reads[] = { |
| 906 CreateMockRead(resp, 2), MockRead(SYNCHRONOUS, 0, 3), | 904 CreateMockRead(resp, 2), MockRead(SYNCHRONOUS, 0, 3), |
| 907 }; | 905 }; |
| 908 | 906 |
| 909 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 907 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 910 | 908 |
| 911 ReadErrorUploadDataStream upload_data_stream( | 909 ReadErrorUploadDataStream upload_data_stream( |
| 912 ReadErrorUploadDataStream::FailureMode::SYNC); | 910 ReadErrorUploadDataStream::FailureMode::SYNC); |
| 913 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback(), | 911 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback(), |
| 914 BoundNetLog()), | 912 NetLogWithSource()), |
| 915 IsOk()); | 913 IsOk()); |
| 916 | 914 |
| 917 HttpRequestInfo request; | 915 HttpRequestInfo request; |
| 918 request.method = "POST"; | 916 request.method = "POST"; |
| 919 request.url = GURL("http://www.example.org/"); | 917 request.url = GURL("http://www.example.org/"); |
| 920 request.upload_data_stream = &upload_data_stream; | 918 request.upload_data_stream = &upload_data_stream; |
| 921 | 919 |
| 922 TestCompletionCallback callback; | 920 TestCompletionCallback callback; |
| 923 HttpResponseInfo response; | 921 HttpResponseInfo response; |
| 924 HttpRequestHeaders headers; | 922 HttpRequestHeaders headers; |
| 925 BoundNetLog net_log; | 923 NetLogWithSource net_log; |
| 926 SpdyHttpStream http_stream(session_, true); | 924 SpdyHttpStream http_stream(session_, true); |
| 927 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 925 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 928 net_log, CompletionCallback())); | 926 net_log, CompletionCallback())); |
| 929 | 927 |
| 930 int result = http_stream.SendRequest(headers, &response, callback.callback()); | 928 int result = http_stream.SendRequest(headers, &response, callback.callback()); |
| 931 EXPECT_THAT(callback.GetResult(result), IsError(ERR_FAILED)); | 929 EXPECT_THAT(callback.GetResult(result), IsError(ERR_FAILED)); |
| 932 | 930 |
| 933 // Because the server has not closed the connection yet, there shouldn't be | 931 // Because the server has not closed the connection yet, there shouldn't be |
| 934 // a stream but a session in the pool | 932 // a stream but a session in the pool |
| 935 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 933 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 953 | 951 |
| 954 MockRead reads[] = { | 952 MockRead reads[] = { |
| 955 MockRead(ASYNC, 0, 2), | 953 MockRead(ASYNC, 0, 2), |
| 956 }; | 954 }; |
| 957 | 955 |
| 958 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 956 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 959 | 957 |
| 960 ReadErrorUploadDataStream upload_data_stream( | 958 ReadErrorUploadDataStream upload_data_stream( |
| 961 ReadErrorUploadDataStream::FailureMode::ASYNC); | 959 ReadErrorUploadDataStream::FailureMode::ASYNC); |
| 962 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback(), | 960 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback(), |
| 963 BoundNetLog()), | 961 NetLogWithSource()), |
| 964 IsOk()); | 962 IsOk()); |
| 965 | 963 |
| 966 HttpRequestInfo request; | 964 HttpRequestInfo request; |
| 967 request.method = "POST"; | 965 request.method = "POST"; |
| 968 request.url = GURL("http://www.example.org/"); | 966 request.url = GURL("http://www.example.org/"); |
| 969 request.upload_data_stream = &upload_data_stream; | 967 request.upload_data_stream = &upload_data_stream; |
| 970 | 968 |
| 971 TestCompletionCallback callback; | 969 TestCompletionCallback callback; |
| 972 HttpResponseInfo response; | 970 HttpResponseInfo response; |
| 973 HttpRequestHeaders headers; | 971 HttpRequestHeaders headers; |
| 974 BoundNetLog net_log; | 972 NetLogWithSource net_log; |
| 975 SpdyHttpStream http_stream(session_, true); | 973 SpdyHttpStream http_stream(session_, true); |
| 976 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, | 974 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, |
| 977 net_log, CompletionCallback())); | 975 net_log, CompletionCallback())); |
| 978 | 976 |
| 979 int result = http_stream.SendRequest(headers, &response, callback.callback()); | 977 int result = http_stream.SendRequest(headers, &response, callback.callback()); |
| 980 EXPECT_THAT(result, IsError(ERR_IO_PENDING)); | 978 EXPECT_THAT(result, IsError(ERR_IO_PENDING)); |
| 981 EXPECT_THAT(callback.GetResult(result), IsError(ERR_FAILED)); | 979 EXPECT_THAT(callback.GetResult(result), IsError(ERR_FAILED)); |
| 982 | 980 |
| 983 // Because the server has closed the connection, there shouldn't be a session | 981 // Because the server has closed the connection, there shouldn't be a session |
| 984 // in the pool anymore. | 982 // in the pool anymore. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 997 MockRead reads[] = {MockRead(ASYNC, 0, 3)}; | 995 MockRead reads[] = {MockRead(ASYNC, 0, 3)}; |
| 998 InitSession(reads, arraysize(reads), writes, arraysize(writes)); | 996 InitSession(reads, arraysize(reads), writes, arraysize(writes)); |
| 999 | 997 |
| 1000 HttpRequestInfo request; | 998 HttpRequestInfo request; |
| 1001 request.method = "POST"; | 999 request.method = "POST"; |
| 1002 request.url = GURL("http://www.example.org/"); | 1000 request.url = GURL("http://www.example.org/"); |
| 1003 ChunkedUploadDataStream upload_stream(0); | 1001 ChunkedUploadDataStream upload_stream(0); |
| 1004 request.upload_data_stream = &upload_stream; | 1002 request.upload_data_stream = &upload_stream; |
| 1005 | 1003 |
| 1006 TestCompletionCallback upload_callback; | 1004 TestCompletionCallback upload_callback; |
| 1007 ASSERT_THAT(upload_stream.Init(upload_callback.callback(), BoundNetLog()), | 1005 ASSERT_THAT( |
| 1008 IsOk()); | 1006 upload_stream.Init(upload_callback.callback(), NetLogWithSource()), |
| 1007 IsOk()); |
| 1009 upload_stream.AppendData("", 0, true); | 1008 upload_stream.AppendData("", 0, true); |
| 1010 | 1009 |
| 1011 BoundNetLog net_log; | 1010 NetLogWithSource net_log; |
| 1012 SpdyHttpStream http_stream(session_, true); | 1011 SpdyHttpStream http_stream(session_, true); |
| 1013 ASSERT_THAT(http_stream.InitializeStream(&request, DEFAULT_PRIORITY, net_log, | 1012 ASSERT_THAT(http_stream.InitializeStream(&request, DEFAULT_PRIORITY, net_log, |
| 1014 CompletionCallback()), | 1013 CompletionCallback()), |
| 1015 IsOk()); | 1014 IsOk()); |
| 1016 | 1015 |
| 1017 CancelStreamCallback callback(&http_stream); | 1016 CancelStreamCallback callback(&http_stream); |
| 1018 HttpRequestHeaders headers; | 1017 HttpRequestHeaders headers; |
| 1019 HttpResponseInfo response; | 1018 HttpResponseInfo response; |
| 1020 // This will attempt to Write() the initial request and headers, which will | 1019 // This will attempt to Write() the initial request and headers, which will |
| 1021 // complete asynchronously. | 1020 // complete asynchronously. |
| 1022 EXPECT_EQ(ERR_IO_PENDING, | 1021 EXPECT_EQ(ERR_IO_PENDING, |
| 1023 http_stream.SendRequest(headers, &response, callback.callback())); | 1022 http_stream.SendRequest(headers, &response, callback.callback())); |
| 1024 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 1023 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 1025 | 1024 |
| 1026 // The callback cancels |http_stream|. | 1025 // The callback cancels |http_stream|. |
| 1027 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 1026 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 1028 | 1027 |
| 1029 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); | 1028 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); |
| 1030 } | 1029 } |
| 1031 | 1030 |
| 1032 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 1031 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
| 1033 // methods. | 1032 // methods. |
| 1034 | 1033 |
| 1035 } // namespace net | 1034 } // namespace net |
| OLD | NEW |