Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: net/spdy/spdy_http_stream_unittest.cc

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "net/http/http_request_info.h" 21 #include "net/http/http_request_info.h"
22 #include "net/http/http_response_headers.h" 22 #include "net/http/http_response_headers.h"
23 #include "net/http/http_response_info.h" 23 #include "net/http/http_response_info.h"
24 #include "net/log/test_net_log.h" 24 #include "net/log/test_net_log.h"
25 #include "net/socket/next_proto.h" 25 #include "net/socket/next_proto.h"
26 #include "net/socket/socket_test_util.h" 26 #include "net/socket/socket_test_util.h"
27 #include "net/spdy/spdy_http_utils.h" 27 #include "net/spdy/spdy_http_utils.h"
28 #include "net/spdy/spdy_session.h" 28 #include "net/spdy/spdy_session.h"
29 #include "net/spdy/spdy_test_util_common.h" 29 #include "net/spdy/spdy_test_util_common.h"
30 #include "net/ssl/default_channel_id_store.h" 30 #include "net/ssl/default_channel_id_store.h"
31 #include "net/test/gtest_util.h"
32 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
32 34
35 using net::test::IsError;
36 using net::test::IsOk;
37
33 namespace net { 38 namespace net {
34 39
35 namespace { 40 namespace {
36 41
37 enum TestCase { 42 enum TestCase {
38 // Test using the SPDY/3.1 protocol. 43 // Test using the SPDY/3.1 protocol.
39 kTestCaseSPDY31, 44 kTestCaseSPDY31,
40 45
41 // Test using the HTTP/2 protocol, without specifying a stream 46 // Test using the HTTP/2 protocol, without specifying a stream
42 // dependency based on the RequestPriority. 47 // dependency based on the RequestPriority.
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 const int kFirstChunkSize = kUploadDataSize/2; 384 const int kFirstChunkSize = kUploadDataSize/2;
380 upload_stream.AppendData(kUploadData, kFirstChunkSize, false); 385 upload_stream.AppendData(kUploadData, kFirstChunkSize, false);
381 upload_stream.AppendData(kUploadData + kFirstChunkSize, 386 upload_stream.AppendData(kUploadData + kFirstChunkSize,
382 kUploadDataSize - kFirstChunkSize, true); 387 kUploadDataSize - kFirstChunkSize, true);
383 388
384 HttpRequestInfo request; 389 HttpRequestInfo request;
385 request.method = "POST"; 390 request.method = "POST";
386 request.url = GURL("http://www.example.org/"); 391 request.url = GURL("http://www.example.org/");
387 request.upload_data_stream = &upload_stream; 392 request.upload_data_stream = &upload_stream;
388 393
389 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); 394 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk());
390 395
391 TestCompletionCallback callback; 396 TestCompletionCallback callback;
392 HttpResponseInfo response; 397 HttpResponseInfo response;
393 HttpRequestHeaders headers; 398 HttpRequestHeaders headers;
394 BoundNetLog net_log; 399 BoundNetLog net_log;
395 SpdyHttpStream http_stream(session_, true); 400 SpdyHttpStream http_stream(session_, true);
396 ASSERT_EQ( 401 ASSERT_EQ(
397 OK, 402 OK,
398 http_stream.InitializeStream(&request, DEFAULT_PRIORITY, 403 http_stream.InitializeStream(&request, DEFAULT_PRIORITY,
399 net_log, CompletionCallback())); 404 net_log, CompletionCallback()));
400 405
401 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( 406 EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest(
402 headers, &response, callback.callback())); 407 headers, &response, callback.callback()));
403 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 408 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_));
404 409
405 EXPECT_EQ(OK, callback.WaitForResult()); 410 EXPECT_THAT(callback.WaitForResult(), IsOk());
406 411
407 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), 412 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()),
408 http_stream.GetTotalSentBytes()); 413 http_stream.GetTotalSentBytes());
409 EXPECT_EQ(static_cast<int64_t>(resp->size() + body->size()), 414 EXPECT_EQ(static_cast<int64_t>(resp->size() + body->size()),
410 http_stream.GetTotalReceivedBytes()); 415 http_stream.GetTotalReceivedBytes());
411 416
412 // Because the server closed the connection, we there shouldn't be a session 417 // Because the server closed the connection, we there shouldn't be a session
413 // in the pool anymore. 418 // in the pool anymore.
414 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 419 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_));
415 } 420 }
(...skipping 21 matching lines...) Expand all
437 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); 442 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion());
438 443
439 ChunkedUploadDataStream upload_stream(0); 444 ChunkedUploadDataStream upload_stream(0);
440 upload_stream.AppendData(nullptr, 0, true); 445 upload_stream.AppendData(nullptr, 0, true);
441 446
442 HttpRequestInfo request; 447 HttpRequestInfo request;
443 request.method = "POST"; 448 request.method = "POST";
444 request.url = GURL("http://www.example.org/"); 449 request.url = GURL("http://www.example.org/");
445 request.upload_data_stream = &upload_stream; 450 request.upload_data_stream = &upload_stream;
446 451
447 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); 452 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk());
448 453
449 TestCompletionCallback callback; 454 TestCompletionCallback callback;
450 HttpResponseInfo response; 455 HttpResponseInfo response;
451 HttpRequestHeaders headers; 456 HttpRequestHeaders headers;
452 BoundNetLog net_log; 457 BoundNetLog net_log;
453 SpdyHttpStream http_stream(session_, true); 458 SpdyHttpStream http_stream(session_, true);
454 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, 459 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY,
455 net_log, CompletionCallback())); 460 net_log, CompletionCallback()));
456 EXPECT_EQ(ERR_IO_PENDING, 461 EXPECT_EQ(ERR_IO_PENDING,
457 http_stream.SendRequest(headers, &response, callback.callback())); 462 http_stream.SendRequest(headers, &response, callback.callback()));
458 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 463 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_));
459 464
460 EXPECT_EQ(OK, callback.WaitForResult()); 465 EXPECT_THAT(callback.WaitForResult(), IsOk());
461 466
462 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()), 467 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()),
463 http_stream.GetTotalSentBytes()); 468 http_stream.GetTotalSentBytes());
464 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), 469 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()),
465 http_stream.GetTotalReceivedBytes()); 470 http_stream.GetTotalReceivedBytes());
466 471
467 // Because the server closed the connection, there shouldn't be a session 472 // Because the server closed the connection, there shouldn't be a session
468 // in the pool anymore. 473 // in the pool anymore.
469 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 474 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_));
470 } 475 }
(...skipping 21 matching lines...) Expand all
492 497
493 ChunkedUploadDataStream upload_stream(0); 498 ChunkedUploadDataStream upload_stream(0);
494 // Append first chunk. 499 // Append first chunk.
495 upload_stream.AppendData(kUploadData, kUploadDataSize, false); 500 upload_stream.AppendData(kUploadData, kUploadDataSize, false);
496 501
497 HttpRequestInfo request; 502 HttpRequestInfo request;
498 request.method = "POST"; 503 request.method = "POST";
499 request.url = GURL("http://www.example.org/"); 504 request.url = GURL("http://www.example.org/");
500 request.upload_data_stream = &upload_stream; 505 request.upload_data_stream = &upload_stream;
501 506
502 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); 507 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk());
503 508
504 TestCompletionCallback callback; 509 TestCompletionCallback callback;
505 HttpResponseInfo response; 510 HttpResponseInfo response;
506 HttpRequestHeaders headers; 511 HttpRequestHeaders headers;
507 BoundNetLog net_log; 512 BoundNetLog net_log;
508 SpdyHttpStream http_stream(session_, true); 513 SpdyHttpStream http_stream(session_, true);
509 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, 514 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY,
510 net_log, CompletionCallback())); 515 net_log, CompletionCallback()));
511 516
512 EXPECT_EQ(ERR_IO_PENDING, 517 EXPECT_EQ(ERR_IO_PENDING,
513 http_stream.SendRequest(headers, &response, callback.callback())); 518 http_stream.SendRequest(headers, &response, callback.callback()));
514 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 519 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_));
515 520
516 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); 521 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED));
517 522
518 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()), 523 EXPECT_EQ(static_cast<int64_t>(req->size() + body->size()),
519 http_stream.GetTotalSentBytes()); 524 http_stream.GetTotalSentBytes());
520 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes()); 525 EXPECT_EQ(0, http_stream.GetTotalReceivedBytes());
521 526
522 // Because the server closed the connection, we there shouldn't be a session 527 // Because the server closed the connection, we there shouldn't be a session
523 // in the pool anymore. 528 // in the pool anymore.
524 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 529 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_));
525 530
526 // Appending a second chunk now should not result in a crash. 531 // Appending a second chunk now should not result in a crash.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 571
567 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 572 InitSession(reads, arraysize(reads), writes, arraysize(writes));
568 573
569 ChunkedUploadDataStream upload_stream(0); 574 ChunkedUploadDataStream upload_stream(0);
570 575
571 HttpRequestInfo request; 576 HttpRequestInfo request;
572 request.method = "POST"; 577 request.method = "POST";
573 request.url = GURL("http://www.example.org/"); 578 request.url = GURL("http://www.example.org/");
574 request.upload_data_stream = &upload_stream; 579 request.upload_data_stream = &upload_stream;
575 580
576 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); 581 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk());
577 upload_stream.AppendData(kUploadData, kUploadDataSize, false); 582 upload_stream.AppendData(kUploadData, kUploadDataSize, false);
578 583
579 BoundNetLog net_log; 584 BoundNetLog net_log;
580 std::unique_ptr<SpdyHttpStream> http_stream( 585 std::unique_ptr<SpdyHttpStream> http_stream(
581 new SpdyHttpStream(session_, true)); 586 new SpdyHttpStream(session_, true));
582 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, 587 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY,
583 net_log, CompletionCallback())); 588 net_log, CompletionCallback()));
584 589
585 TestCompletionCallback callback; 590 TestCompletionCallback callback;
586 HttpRequestHeaders headers; 591 HttpRequestHeaders headers;
587 HttpResponseInfo response; 592 HttpResponseInfo response;
588 // This will attempt to Write() the initial request and headers, which will 593 // This will attempt to Write() the initial request and headers, which will
589 // complete asynchronously. 594 // complete asynchronously.
590 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, 595 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response,
591 callback.callback())); 596 callback.callback()));
592 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 597 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_));
593 598
594 // Complete the initial request write and the first chunk. 599 // Complete the initial request write and the first chunk.
595 base::RunLoop().RunUntilIdle(); 600 base::RunLoop().RunUntilIdle();
596 ASSERT_FALSE(callback.have_result()); 601 ASSERT_FALSE(callback.have_result());
597 602
598 // Now append the final two chunks which will enqueue two more writes. 603 // Now append the final two chunks which will enqueue two more writes.
599 upload_stream.AppendData(kUploadData1, kUploadData1Size, false); 604 upload_stream.AppendData(kUploadData1, kUploadData1Size, false);
600 upload_stream.AppendData(kUploadData, kUploadDataSize, true); 605 upload_stream.AppendData(kUploadData, kUploadDataSize, true);
601 606
602 // Finish writing all the chunks and do all reads. 607 // Finish writing all the chunks and do all reads.
603 base::RunLoop().RunUntilIdle(); 608 base::RunLoop().RunUntilIdle();
604 ASSERT_TRUE(callback.have_result()); 609 ASSERT_TRUE(callback.have_result());
605 EXPECT_EQ(OK, callback.WaitForResult()); 610 EXPECT_THAT(callback.WaitForResult(), IsOk());
606 611
607 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size() + 612 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size() +
608 chunk3->size()), 613 chunk3->size()),
609 http_stream->GetTotalSentBytes()); 614 http_stream->GetTotalSentBytes());
610 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size() + 615 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size() +
611 chunk2->size() + chunk3->size()), 616 chunk2->size() + chunk3->size()),
612 http_stream->GetTotalReceivedBytes()); 617 http_stream->GetTotalReceivedBytes());
613 618
614 // Check response headers. 619 // Check response headers.
615 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); 620 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk());
616 621
617 // Check |chunk1| response. 622 // Check |chunk1| response.
618 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); 623 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize));
619 ASSERT_EQ(kUploadDataSize, 624 ASSERT_EQ(kUploadDataSize,
620 http_stream->ReadResponseBody( 625 http_stream->ReadResponseBody(
621 buf1.get(), kUploadDataSize, callback.callback())); 626 buf1.get(), kUploadDataSize, callback.callback()));
622 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); 627 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize));
623 628
624 // Check |chunk2| response. 629 // Check |chunk2| response.
625 scoped_refptr<IOBuffer> buf2(new IOBuffer(kUploadData1Size)); 630 scoped_refptr<IOBuffer> buf2(new IOBuffer(kUploadData1Size));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 669
665 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 670 InitSession(reads, arraysize(reads), writes, arraysize(writes));
666 671
667 ChunkedUploadDataStream upload_stream(0); 672 ChunkedUploadDataStream upload_stream(0);
668 673
669 HttpRequestInfo request; 674 HttpRequestInfo request;
670 request.method = "POST"; 675 request.method = "POST";
671 request.url = GURL("http://www.example.org/"); 676 request.url = GURL("http://www.example.org/");
672 request.upload_data_stream = &upload_stream; 677 request.upload_data_stream = &upload_stream;
673 678
674 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); 679 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk());
675 upload_stream.AppendData(kUploadData, kUploadDataSize, false); 680 upload_stream.AppendData(kUploadData, kUploadDataSize, false);
676 681
677 BoundNetLog net_log; 682 BoundNetLog net_log;
678 std::unique_ptr<SpdyHttpStream> http_stream( 683 std::unique_ptr<SpdyHttpStream> http_stream(
679 new SpdyHttpStream(session_, true)); 684 new SpdyHttpStream(session_, true));
680 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, 685 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY,
681 net_log, CompletionCallback())); 686 net_log, CompletionCallback()));
682 687
683 TestCompletionCallback callback; 688 TestCompletionCallback callback;
684 HttpRequestHeaders headers; 689 HttpRequestHeaders headers;
(...skipping 11 matching lines...) Expand all
696 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), 701 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()),
697 http_stream->GetTotalSentBytes()); 702 http_stream->GetTotalSentBytes());
698 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); 703 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes());
699 704
700 // Now end the stream with an empty data frame and the FIN set. 705 // Now end the stream with an empty data frame and the FIN set.
701 upload_stream.AppendData(nullptr, 0, true); 706 upload_stream.AppendData(nullptr, 0, true);
702 707
703 // Finish writing the final frame, and perform all reads. 708 // Finish writing the final frame, and perform all reads.
704 base::RunLoop().RunUntilIdle(); 709 base::RunLoop().RunUntilIdle();
705 ASSERT_TRUE(callback.have_result()); 710 ASSERT_TRUE(callback.have_result());
706 EXPECT_EQ(OK, callback.WaitForResult()); 711 EXPECT_THAT(callback.WaitForResult(), IsOk());
707 712
708 // Check response headers. 713 // Check response headers.
709 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); 714 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk());
710 715
711 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()), 716 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size() + chunk2->size()),
712 http_stream->GetTotalSentBytes()); 717 http_stream->GetTotalSentBytes());
713 EXPECT_EQ( 718 EXPECT_EQ(
714 static_cast<int64_t>(resp->size() + chunk1->size() + chunk2->size()), 719 static_cast<int64_t>(resp->size() + chunk1->size() + chunk2->size()),
715 http_stream->GetTotalReceivedBytes()); 720 http_stream->GetTotalReceivedBytes());
716 721
717 // Check |chunk1| response. 722 // Check |chunk1| response.
718 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); 723 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize));
719 ASSERT_EQ(kUploadDataSize, 724 ASSERT_EQ(kUploadDataSize,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 756
752 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 757 InitSession(reads, arraysize(reads), writes, arraysize(writes));
753 758
754 ChunkedUploadDataStream upload_stream(0); 759 ChunkedUploadDataStream upload_stream(0);
755 760
756 HttpRequestInfo request; 761 HttpRequestInfo request;
757 request.method = "POST"; 762 request.method = "POST";
758 request.url = GURL("http://www.example.org/"); 763 request.url = GURL("http://www.example.org/");
759 request.upload_data_stream = &upload_stream; 764 request.upload_data_stream = &upload_stream;
760 765
761 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); 766 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk());
762 upload_stream.AppendData("", 0, true); 767 upload_stream.AppendData("", 0, true);
763 768
764 BoundNetLog net_log; 769 BoundNetLog net_log;
765 std::unique_ptr<SpdyHttpStream> http_stream( 770 std::unique_ptr<SpdyHttpStream> http_stream(
766 new SpdyHttpStream(session_, true)); 771 new SpdyHttpStream(session_, true));
767 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, 772 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY,
768 net_log, CompletionCallback())); 773 net_log, CompletionCallback()));
769 774
770 TestCompletionCallback callback; 775 TestCompletionCallback callback;
771 HttpRequestHeaders headers; 776 HttpRequestHeaders headers;
772 HttpResponseInfo response; 777 HttpResponseInfo response;
773 // This will attempt to Write() the initial request and headers, which will 778 // This will attempt to Write() the initial request and headers, which will
774 // complete asynchronously. 779 // complete asynchronously.
775 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, 780 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response,
776 callback.callback())); 781 callback.callback()));
777 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 782 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_));
778 783
779 // Complete writing request, followed by a FIN. 784 // Complete writing request, followed by a FIN.
780 base::RunLoop().RunUntilIdle(); 785 base::RunLoop().RunUntilIdle();
781 ASSERT_TRUE(callback.have_result()); 786 ASSERT_TRUE(callback.have_result());
782 EXPECT_EQ(OK, callback.WaitForResult()); 787 EXPECT_THAT(callback.WaitForResult(), IsOk());
783 788
784 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()), 789 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk->size()),
785 http_stream->GetTotalSentBytes()); 790 http_stream->GetTotalSentBytes());
786 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()), 791 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk->size()),
787 http_stream->GetTotalReceivedBytes()); 792 http_stream->GetTotalReceivedBytes());
788 793
789 // Check response headers. 794 // Check response headers.
790 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); 795 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk());
791 796
792 // Check |chunk| response. 797 // Check |chunk| response.
793 scoped_refptr<IOBuffer> buf(new IOBuffer(1)); 798 scoped_refptr<IOBuffer> buf(new IOBuffer(1));
794 ASSERT_EQ(0, 799 ASSERT_EQ(0,
795 http_stream->ReadResponseBody( 800 http_stream->ReadResponseBody(
796 buf.get(), 1, callback.callback())); 801 buf.get(), 1, callback.callback()));
797 802
798 ASSERT_TRUE(response.headers.get()); 803 ASSERT_TRUE(response.headers.get());
799 ASSERT_EQ(200, response.headers->response_code()); 804 ASSERT_EQ(200, response.headers->response_code());
800 } 805 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 876
872 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 877 InitSession(reads, arraysize(reads), writes, arraysize(writes));
873 878
874 ChunkedUploadDataStream upload_stream(0); 879 ChunkedUploadDataStream upload_stream(0);
875 880
876 HttpRequestInfo request; 881 HttpRequestInfo request;
877 request.method = "POST"; 882 request.method = "POST";
878 request.url = GURL("http://www.example.org/"); 883 request.url = GURL("http://www.example.org/");
879 request.upload_data_stream = &upload_stream; 884 request.upload_data_stream = &upload_stream;
880 885
881 ASSERT_EQ(OK, upload_stream.Init(TestCompletionCallback().callback())); 886 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk());
882 887
883 BoundNetLog net_log; 888 BoundNetLog net_log;
884 std::unique_ptr<SpdyHttpStream> http_stream( 889 std::unique_ptr<SpdyHttpStream> http_stream(
885 new SpdyHttpStream(session_, true)); 890 new SpdyHttpStream(session_, true));
886 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY, 891 ASSERT_EQ(OK, http_stream->InitializeStream(&request, DEFAULT_PRIORITY,
887 net_log, CompletionCallback())); 892 net_log, CompletionCallback()));
888 893
889 HttpRequestHeaders headers; 894 HttpRequestHeaders headers;
890 HttpResponseInfo response; 895 HttpResponseInfo response;
891 // This will attempt to Write() the initial request and headers, which will 896 // This will attempt to Write() the initial request and headers, which will
892 // complete asynchronously. 897 // complete asynchronously.
893 TestCompletionCallback callback; 898 TestCompletionCallback callback;
894 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response, 899 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, &response,
895 callback.callback())); 900 callback.callback()));
896 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 901 EXPECT_TRUE(HasSpdySession(http_session_->spdy_session_pool(), key_));
897 902
898 // Complete the initial request write and first chunk. 903 // Complete the initial request write and first chunk.
899 base::RunLoop().RunUntilIdle(); 904 base::RunLoop().RunUntilIdle();
900 ASSERT_FALSE(callback.have_result()); 905 ASSERT_FALSE(callback.have_result());
901 906
902 EXPECT_EQ(static_cast<int64_t>(req->size()), 907 EXPECT_EQ(static_cast<int64_t>(req->size()),
903 http_stream->GetTotalSentBytes()); 908 http_stream->GetTotalSentBytes());
904 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes()); 909 EXPECT_EQ(0, http_stream->GetTotalReceivedBytes());
905 910
906 upload_stream.AppendData(kUploadData, kUploadDataSize, true); 911 upload_stream.AppendData(kUploadData, kUploadDataSize, true);
907 912
908 ASSERT_TRUE(callback.have_result()); 913 ASSERT_TRUE(callback.have_result());
909 EXPECT_EQ(OK, callback.WaitForResult()); 914 EXPECT_THAT(callback.WaitForResult(), IsOk());
910 915
911 // Verify that the window size has decreased. 916 // Verify that the window size has decreased.
912 ASSERT_TRUE(http_stream->stream() != nullptr); 917 ASSERT_TRUE(http_stream->stream() != nullptr);
913 EXPECT_NE(static_cast<int>( 918 EXPECT_NE(static_cast<int>(
914 SpdySession::GetDefaultInitialWindowSize(session_->protocol())), 919 SpdySession::GetDefaultInitialWindowSize(session_->protocol())),
915 http_stream->stream()->send_window_size()); 920 http_stream->stream()->send_window_size());
916 921
917 // Read window update. 922 // Read window update.
918 base::RunLoop().RunUntilIdle(); 923 base::RunLoop().RunUntilIdle();
919 924
(...skipping 11 matching lines...) Expand all
931 // Read rest of data. 936 // Read rest of data.
932 sequenced_data_->Resume(); 937 sequenced_data_->Resume();
933 base::RunLoop().RunUntilIdle(); 938 base::RunLoop().RunUntilIdle();
934 939
935 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()), 940 EXPECT_EQ(static_cast<int64_t>(req->size() + chunk1->size()),
936 http_stream->GetTotalSentBytes()); 941 http_stream->GetTotalSentBytes());
937 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()), 942 EXPECT_EQ(static_cast<int64_t>(resp->size() + chunk1->size()),
938 http_stream->GetTotalReceivedBytes()); 943 http_stream->GetTotalReceivedBytes());
939 944
940 // Check response headers. 945 // Check response headers.
941 ASSERT_EQ(OK, http_stream->ReadResponseHeaders(callback.callback())); 946 ASSERT_THAT(http_stream->ReadResponseHeaders(callback.callback()), IsOk());
942 947
943 // Check |chunk1| response. 948 // Check |chunk1| response.
944 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize)); 949 scoped_refptr<IOBuffer> buf1(new IOBuffer(kUploadDataSize));
945 ASSERT_EQ(kUploadDataSize, 950 ASSERT_EQ(kUploadDataSize,
946 http_stream->ReadResponseBody( 951 http_stream->ReadResponseBody(
947 buf1.get(), kUploadDataSize, callback.callback())); 952 buf1.get(), kUploadDataSize, callback.callback()));
948 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize)); 953 EXPECT_EQ(kUploadData, std::string(buf1->data(), kUploadDataSize));
949 954
950 ASSERT_TRUE(response.headers.get()); 955 ASSERT_TRUE(response.headers.get());
951 ASSERT_EQ(200, response.headers->response_code()); 956 ASSERT_EQ(200, response.headers->response_code());
(...skipping 19 matching lines...) Expand all
971 976
972 MockRead reads[] = { 977 MockRead reads[] = {
973 CreateMockRead(*resp, 2), MockRead(SYNCHRONOUS, 0, 3), 978 CreateMockRead(*resp, 2), MockRead(SYNCHRONOUS, 0, 3),
974 }; 979 };
975 980
976 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 981 InitSession(reads, arraysize(reads), writes, arraysize(writes));
977 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); 982 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion());
978 983
979 ReadErrorUploadDataStream upload_data_stream( 984 ReadErrorUploadDataStream upload_data_stream(
980 ReadErrorUploadDataStream::FailureMode::SYNC); 985 ReadErrorUploadDataStream::FailureMode::SYNC);
981 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); 986 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()),
987 IsOk());
982 988
983 HttpRequestInfo request; 989 HttpRequestInfo request;
984 request.method = "POST"; 990 request.method = "POST";
985 request.url = GURL("http://www.example.org/"); 991 request.url = GURL("http://www.example.org/");
986 request.upload_data_stream = &upload_data_stream; 992 request.upload_data_stream = &upload_data_stream;
987 993
988 TestCompletionCallback callback; 994 TestCompletionCallback callback;
989 HttpResponseInfo response; 995 HttpResponseInfo response;
990 HttpRequestHeaders headers; 996 HttpRequestHeaders headers;
991 BoundNetLog net_log; 997 BoundNetLog net_log;
992 SpdyHttpStream http_stream(session_, true); 998 SpdyHttpStream http_stream(session_, true);
993 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, 999 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY,
994 net_log, CompletionCallback())); 1000 net_log, CompletionCallback()));
995 1001
996 int result = http_stream.SendRequest(headers, &response, callback.callback()); 1002 int result = http_stream.SendRequest(headers, &response, callback.callback());
997 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); 1003 EXPECT_THAT(callback.GetResult(result), IsError(ERR_FAILED));
998 1004
999 // Because the server has not closed the connection yet, there shouldn't be 1005 // Because the server has not closed the connection yet, there shouldn't be
1000 // a stream but a session in the pool 1006 // a stream but a session in the pool
1001 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 1007 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_));
1002 } 1008 }
1003 1009
1004 TEST_P(SpdyHttpStreamTest, DataReadErrorAsynchronous) { 1010 TEST_P(SpdyHttpStreamTest, DataReadErrorAsynchronous) {
1005 std::unique_ptr<SpdySerializedFrame> req( 1011 std::unique_ptr<SpdySerializedFrame> req(
1006 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0)); 1012 spdy_util_.ConstructChunkedSpdyPost(nullptr, 0));
1007 1013
(...skipping 13 matching lines...) Expand all
1021 1027
1022 MockRead reads[] = { 1028 MockRead reads[] = {
1023 MockRead(ASYNC, 0, 2), 1029 MockRead(ASYNC, 0, 2),
1024 }; 1030 };
1025 1031
1026 InitSession(reads, arraysize(reads), writes, arraysize(writes)); 1032 InitSession(reads, arraysize(reads), writes, arraysize(writes));
1027 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion()); 1033 EXPECT_EQ(spdy_util_.spdy_version(), session_->GetProtocolVersion());
1028 1034
1029 ReadErrorUploadDataStream upload_data_stream( 1035 ReadErrorUploadDataStream upload_data_stream(
1030 ReadErrorUploadDataStream::FailureMode::ASYNC); 1036 ReadErrorUploadDataStream::FailureMode::ASYNC);
1031 ASSERT_EQ(OK, upload_data_stream.Init(TestCompletionCallback().callback())); 1037 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()),
1038 IsOk());
1032 1039
1033 HttpRequestInfo request; 1040 HttpRequestInfo request;
1034 request.method = "POST"; 1041 request.method = "POST";
1035 request.url = GURL("http://www.example.org/"); 1042 request.url = GURL("http://www.example.org/");
1036 request.upload_data_stream = &upload_data_stream; 1043 request.upload_data_stream = &upload_data_stream;
1037 1044
1038 TestCompletionCallback callback; 1045 TestCompletionCallback callback;
1039 HttpResponseInfo response; 1046 HttpResponseInfo response;
1040 HttpRequestHeaders headers; 1047 HttpRequestHeaders headers;
1041 BoundNetLog net_log; 1048 BoundNetLog net_log;
1042 SpdyHttpStream http_stream(session_, true); 1049 SpdyHttpStream http_stream(session_, true);
1043 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY, 1050 ASSERT_EQ(OK, http_stream.InitializeStream(&request, DEFAULT_PRIORITY,
1044 net_log, CompletionCallback())); 1051 net_log, CompletionCallback()));
1045 1052
1046 int result = http_stream.SendRequest(headers, &response, callback.callback()); 1053 int result = http_stream.SendRequest(headers, &response, callback.callback());
1047 EXPECT_EQ(ERR_IO_PENDING, result); 1054 EXPECT_THAT(result, IsError(ERR_IO_PENDING));
1048 EXPECT_EQ(ERR_FAILED, callback.GetResult(result)); 1055 EXPECT_THAT(callback.GetResult(result), IsError(ERR_FAILED));
1049 1056
1050 // Because the server has closed the connection, there shouldn't be a session 1057 // Because the server has closed the connection, there shouldn't be a session
1051 // in the pool anymore. 1058 // in the pool anymore.
1052 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_)); 1059 EXPECT_FALSE(HasSpdySession(http_session_->spdy_session_pool(), key_));
1053 } 1060 }
1054 1061
1055 // TODO(willchan): Write a longer test for SpdyStream that exercises all 1062 // TODO(willchan): Write a longer test for SpdyStream that exercises all
1056 // methods. 1063 // methods.
1057 1064
1058 } // namespace net 1065 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/bidirectional_stream_spdy_impl_unittest.cc ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698