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

Side by Side Diff: net/http/bidirectional_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/http/bidirectional_stream.h" 5 #include "net/http/bidirectional_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/timer/mock_timer.h" 16 #include "base/timer/mock_timer.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/http/bidirectional_stream_request_info.h" 18 #include "net/http/bidirectional_stream_request_info.h"
19 #include "net/http/http_network_session.h" 19 #include "net/http/http_network_session.h"
20 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
21 #include "net/http/http_server_properties.h" 21 #include "net/http/http_server_properties.h"
22 #include "net/log/net_log.h" 22 #include "net/log/net_log.h"
23 #include "net/log/test_net_log.h" 23 #include "net/log/test_net_log.h"
24 #include "net/log/test_net_log_util.h" 24 #include "net/log/test_net_log_util.h"
25 #include "net/socket/socket_test_util.h" 25 #include "net/socket/socket_test_util.h"
26 #include "net/spdy/spdy_session.h" 26 #include "net/spdy/spdy_session.h"
27 #include "net/spdy/spdy_test_util_common.h" 27 #include "net/spdy/spdy_test_util_common.h"
28 #include "net/test/cert_test_util.h" 28 #include "net/test/cert_test_util.h"
29 #include "net/test/gtest_util.h"
29 #include "net/test/test_data_directory.h" 30 #include "net/test/test_data_directory.h"
30 #include "net/url_request/url_request_test_util.h" 31 #include "net/url_request/url_request_test_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 const char kBodyData[] = "Body data"; 42 const char kBodyData[] = "Body data";
38 const size_t kBodyDataSize = arraysize(kBodyData); 43 const size_t kBodyDataSize = arraysize(kBodyData);
39 // Size of the buffer to be allocated for each read. 44 // Size of the buffer to be allocated for each read.
40 const size_t kReadBufferSize = 4096; 45 const size_t kReadBufferSize = 4096;
41 46
42 // Delegate that reads data but does not send any data. 47 // Delegate that reads data but does not send any data.
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 request_info->method = "GET"; 391 request_info->method = "GET";
387 request_info->url = GURL("http://www.example.org/"); 392 request_info->url = GURL("http://www.example.org/");
388 393
389 TestDelegateBase delegate(nullptr, 0); 394 TestDelegateBase delegate(nullptr, 0);
390 HttpNetworkSession::Params params = 395 HttpNetworkSession::Params params =
391 SpdySessionDependencies::CreateSessionParams(&session_deps_); 396 SpdySessionDependencies::CreateSessionParams(&session_deps_);
392 std::unique_ptr<HttpNetworkSession> session(new HttpNetworkSession(params)); 397 std::unique_ptr<HttpNetworkSession> session(new HttpNetworkSession(params));
393 delegate.SetRunUntilCompletion(true); 398 delegate.SetRunUntilCompletion(true);
394 delegate.Start(std::move(request_info), session.get()); 399 delegate.Start(std::move(request_info), session.get());
395 400
396 EXPECT_EQ(ERR_DISALLOWED_URL_SCHEME, delegate.error()); 401 EXPECT_THAT(delegate.error(), IsError(ERR_DISALLOWED_URL_SCHEME));
397 } 402 }
398 403
399 // Creates a BidirectionalStream with an insecure scheme. Destroy the stream 404 // Creates a BidirectionalStream with an insecure scheme. Destroy the stream
400 // without waiting for the OnFailed task to be executed. 405 // without waiting for the OnFailed task to be executed.
401 TEST_F(BidirectionalStreamTest, 406 TEST_F(BidirectionalStreamTest,
402 CreateInsecureStreamAndDestroyStreamRightAfter) { 407 CreateInsecureStreamAndDestroyStreamRightAfter) {
403 std::unique_ptr<BidirectionalStreamRequestInfo> request_info( 408 std::unique_ptr<BidirectionalStreamRequestInfo> request_info(
404 new BidirectionalStreamRequestInfo); 409 new BidirectionalStreamRequestInfo);
405 request_info->method = "GET"; 410 request_info->method = "GET";
406 request_info->url = GURL("http://www.example.org/"); 411 request_info->url = GURL("http://www.example.org/");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer))); 471 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer)));
467 delegate->set_do_not_start_read(true); 472 delegate->set_do_not_start_read(true);
468 473
469 delegate->Start(std::move(request_info), http_session_.get()); 474 delegate->Start(std::move(request_info), http_session_.get());
470 475
471 // Write request, and deliver response headers. 476 // Write request, and deliver response headers.
472 sequenced_data_->RunUntilPaused(); 477 sequenced_data_->RunUntilPaused();
473 EXPECT_FALSE(timer->IsRunning()); 478 EXPECT_FALSE(timer->IsRunning());
474 // ReadData returns asynchronously because no data is buffered. 479 // ReadData returns asynchronously because no data is buffered.
475 int rv = delegate->ReadData(); 480 int rv = delegate->ReadData();
476 EXPECT_EQ(ERR_IO_PENDING, rv); 481 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
477 // Deliver a DATA frame. 482 // Deliver a DATA frame.
478 sequenced_data_->Resume(); 483 sequenced_data_->Resume();
479 base::RunLoop().RunUntilIdle(); 484 base::RunLoop().RunUntilIdle();
480 timer->Fire(); 485 timer->Fire();
481 // Asynchronous completion callback is invoke. 486 // Asynchronous completion callback is invoke.
482 EXPECT_EQ(1, delegate->on_data_read_count()); 487 EXPECT_EQ(1, delegate->on_data_read_count());
483 EXPECT_EQ(kUploadDataSize * 1, 488 EXPECT_EQ(kUploadDataSize * 1,
484 static_cast<int>(delegate->data_received().size())); 489 static_cast<int>(delegate->data_received().size()));
485 490
486 // Deliver the rest. Note that user has not called a second ReadData. 491 // Deliver the rest. Note that user has not called a second ReadData.
487 sequenced_data_->Resume(); 492 sequenced_data_->Resume();
488 base::RunLoop().RunUntilIdle(); 493 base::RunLoop().RunUntilIdle();
489 // ReadData now. Read should complete synchronously. 494 // ReadData now. Read should complete synchronously.
490 rv = delegate->ReadData(); 495 rv = delegate->ReadData();
491 EXPECT_EQ(kUploadDataSize * 2, rv); 496 EXPECT_EQ(kUploadDataSize * 2, rv);
492 rv = delegate->ReadData(); 497 rv = delegate->ReadData();
493 EXPECT_EQ(OK, rv); // EOF. 498 EXPECT_THAT(rv, IsOk()); // EOF.
494 499
495 const SpdyHeaderBlock& response_headers = delegate->response_headers(); 500 const SpdyHeaderBlock& response_headers = delegate->response_headers();
496 EXPECT_EQ("200", response_headers.find(":status")->second); 501 EXPECT_EQ("200", response_headers.find(":status")->second);
497 EXPECT_EQ("header-value", response_headers.find("header-name")->second); 502 EXPECT_EQ("header-value", response_headers.find("header-name")->second);
498 EXPECT_EQ(1, delegate->on_data_read_count()); 503 EXPECT_EQ(1, delegate->on_data_read_count());
499 EXPECT_EQ(0, delegate->on_data_sent_count()); 504 EXPECT_EQ(0, delegate->on_data_sent_count());
500 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 505 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
501 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 506 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
502 delegate->GetTotalSentBytes()); 507 delegate->GetTotalSentBytes());
503 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 508 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // Send the request and receive response headers. 562 // Send the request and receive response headers.
558 sequenced_data_->RunUntilPaused(); 563 sequenced_data_->RunUntilPaused();
559 EXPECT_FALSE(timer->IsRunning()); 564 EXPECT_FALSE(timer->IsRunning());
560 565
561 scoped_refptr<StringIOBuffer> buf( 566 scoped_refptr<StringIOBuffer> buf(
562 new StringIOBuffer(std::string(kBodyData, kBodyDataSize))); 567 new StringIOBuffer(std::string(kBodyData, kBodyDataSize)));
563 // Send a DATA frame. 568 // Send a DATA frame.
564 delegate->SendData(buf, buf->size(), true); 569 delegate->SendData(buf, buf->size(), true);
565 // ReadData returns asynchronously because no data is buffered. 570 // ReadData returns asynchronously because no data is buffered.
566 int rv = delegate->ReadData(); 571 int rv = delegate->ReadData();
567 EXPECT_EQ(ERR_IO_PENDING, rv); 572 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
568 // Deliver the first DATA frame. 573 // Deliver the first DATA frame.
569 sequenced_data_->Resume(); 574 sequenced_data_->Resume();
570 sequenced_data_->RunUntilPaused(); 575 sequenced_data_->RunUntilPaused();
571 // |sequenced_data_| is now stopped after delivering first DATA frame but 576 // |sequenced_data_| is now stopped after delivering first DATA frame but
572 // before the second DATA frame. 577 // before the second DATA frame.
573 // Fire the timer to allow the first ReadData to complete asynchronously. 578 // Fire the timer to allow the first ReadData to complete asynchronously.
574 timer->Fire(); 579 timer->Fire();
575 base::RunLoop().RunUntilIdle(); 580 base::RunLoop().RunUntilIdle();
576 EXPECT_EQ(1, delegate->on_data_read_count()); 581 EXPECT_EQ(1, delegate->on_data_read_count());
577 582
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 EXPECT_FALSE(timer->IsRunning()); 696 EXPECT_FALSE(timer->IsRunning());
692 697
693 // Send a DATA frame. 698 // Send a DATA frame.
694 scoped_refptr<StringIOBuffer> buf( 699 scoped_refptr<StringIOBuffer> buf(
695 new StringIOBuffer(std::string(kBodyData, kBodyDataSize))); 700 new StringIOBuffer(std::string(kBodyData, kBodyDataSize)));
696 701
697 // Send a DATA frame. 702 // Send a DATA frame.
698 delegate->SendData(buf, buf->size(), false); 703 delegate->SendData(buf, buf->size(), false);
699 // ReadData and it should return asynchronously because no data is buffered. 704 // ReadData and it should return asynchronously because no data is buffered.
700 int rv = delegate->ReadData(); 705 int rv = delegate->ReadData();
701 EXPECT_EQ(ERR_IO_PENDING, rv); 706 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
702 // Deliver a DATA frame, and fire the timer. 707 // Deliver a DATA frame, and fire the timer.
703 sequenced_data_->Resume(); 708 sequenced_data_->Resume();
704 sequenced_data_->RunUntilPaused(); 709 sequenced_data_->RunUntilPaused();
705 timer->Fire(); 710 timer->Fire();
706 base::RunLoop().RunUntilIdle(); 711 base::RunLoop().RunUntilIdle();
707 EXPECT_EQ(1, delegate->on_data_sent_count()); 712 EXPECT_EQ(1, delegate->on_data_sent_count());
708 EXPECT_EQ(1, delegate->on_data_read_count()); 713 EXPECT_EQ(1, delegate->on_data_read_count());
709 714
710 // Send a DATA frame. 715 // Send a DATA frame.
711 delegate->SendData(buf, buf->size(), false); 716 delegate->SendData(buf, buf->size(), false);
712 // ReadData and it should return asynchronously because no data is buffered. 717 // ReadData and it should return asynchronously because no data is buffered.
713 rv = delegate->ReadData(); 718 rv = delegate->ReadData();
714 EXPECT_EQ(ERR_IO_PENDING, rv); 719 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
715 // Deliver a DATA frame, and fire the timer. 720 // Deliver a DATA frame, and fire the timer.
716 sequenced_data_->Resume(); 721 sequenced_data_->Resume();
717 sequenced_data_->RunUntilPaused(); 722 sequenced_data_->RunUntilPaused();
718 timer->Fire(); 723 timer->Fire();
719 base::RunLoop().RunUntilIdle(); 724 base::RunLoop().RunUntilIdle();
720 // Last DATA frame is read. Server half closes. 725 // Last DATA frame is read. Server half closes.
721 EXPECT_EQ(2, delegate->on_data_read_count()); 726 EXPECT_EQ(2, delegate->on_data_read_count());
722 EXPECT_EQ(2, delegate->on_data_sent_count()); 727 EXPECT_EQ(2, delegate->on_data_sent_count());
723 728
724 // Send the last body frame. Client half closes. 729 // Send the last body frame. Client half closes.
725 delegate->SendData(buf, buf->size(), true); 730 delegate->SendData(buf, buf->size(), true);
726 sequenced_data_->Resume(); 731 sequenced_data_->Resume();
727 base::RunLoop().RunUntilIdle(); 732 base::RunLoop().RunUntilIdle();
728 EXPECT_EQ(3, delegate->on_data_sent_count()); 733 EXPECT_EQ(3, delegate->on_data_sent_count());
729 734
730 // OnClose is invoked since both sides are closed. 735 // OnClose is invoked since both sides are closed.
731 rv = delegate->ReadData(); 736 rv = delegate->ReadData();
732 EXPECT_EQ(OK, rv); 737 EXPECT_THAT(rv, IsOk());
733 738
734 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 739 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
735 EXPECT_EQ(2, delegate->on_data_read_count()); 740 EXPECT_EQ(2, delegate->on_data_read_count());
736 EXPECT_EQ(3, delegate->on_data_sent_count()); 741 EXPECT_EQ(3, delegate->on_data_sent_count());
737 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 742 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
738 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 743 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
739 delegate->GetTotalSentBytes()); 744 delegate->GetTotalSentBytes());
740 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 745 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
741 delegate->GetTotalReceivedBytes()); 746 delegate->GetTotalReceivedBytes());
742 } 747 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 callback.callback()); 788 callback.callback());
784 // Wait until the stream is ready. 789 // Wait until the stream is ready.
785 callback.WaitForResult(); 790 callback.WaitForResult();
786 // Send a DATA frame. 791 // Send a DATA frame.
787 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5))); 792 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(body_data.substr(0, 5)));
788 scoped_refptr<StringIOBuffer> buf2( 793 scoped_refptr<StringIOBuffer> buf2(
789 new StringIOBuffer(body_data.substr(5, body_data.size() - 5))); 794 new StringIOBuffer(body_data.substr(5, body_data.size() - 5)));
790 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true); 795 delegate->SendvData({buf, buf2.get()}, {buf->size(), buf2->size()}, true);
791 sequenced_data_->RunUntilPaused(); // OnHeadersReceived. 796 sequenced_data_->RunUntilPaused(); // OnHeadersReceived.
792 // ReadData and it should return asynchronously because no data is buffered. 797 // ReadData and it should return asynchronously because no data is buffered.
793 EXPECT_EQ(ERR_IO_PENDING, delegate->ReadData()); 798 EXPECT_THAT(delegate->ReadData(), IsError(ERR_IO_PENDING));
794 sequenced_data_->Resume(); 799 sequenced_data_->Resume();
795 base::RunLoop().RunUntilIdle(); 800 base::RunLoop().RunUntilIdle();
796 EXPECT_EQ(1, delegate->on_data_sent_count()); 801 EXPECT_EQ(1, delegate->on_data_sent_count());
797 EXPECT_EQ(1, delegate->on_data_read_count()); 802 EXPECT_EQ(1, delegate->on_data_read_count());
798 803
799 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 804 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
800 EXPECT_EQ(1, delegate->on_data_read_count()); 805 EXPECT_EQ(1, delegate->on_data_read_count());
801 EXPECT_EQ(1, delegate->on_data_sent_count()); 806 EXPECT_EQ(1, delegate->on_data_sent_count());
802 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 807 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
803 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 808 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase( 879 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase(
875 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer))); 880 read_buffer.get(), kReadBufferSize, base::WrapUnique(timer)));
876 delegate->set_do_not_start_read(true); 881 delegate->set_do_not_start_read(true);
877 delegate->Start(std::move(request_info), http_session_.get()); 882 delegate->Start(std::move(request_info), http_session_.get());
878 // Write request, and deliver response headers. 883 // Write request, and deliver response headers.
879 sequenced_data_->RunUntilPaused(); 884 sequenced_data_->RunUntilPaused();
880 EXPECT_FALSE(timer->IsRunning()); 885 EXPECT_FALSE(timer->IsRunning());
881 886
882 // ReadData should return asynchronously because no data is buffered. 887 // ReadData should return asynchronously because no data is buffered.
883 int rv = delegate->ReadData(); 888 int rv = delegate->ReadData();
884 EXPECT_EQ(ERR_IO_PENDING, rv); 889 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
885 // Deliver END_STREAM. 890 // Deliver END_STREAM.
886 // OnClose should trigger completion of the remaining read. 891 // OnClose should trigger completion of the remaining read.
887 sequenced_data_->Resume(); 892 sequenced_data_->Resume();
888 base::RunLoop().RunUntilIdle(); 893 base::RunLoop().RunUntilIdle();
889 894
890 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 895 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
891 EXPECT_EQ(1, delegate->on_data_read_count()); 896 EXPECT_EQ(1, delegate->on_data_read_count());
892 EXPECT_EQ(0u, delegate->data_received().size()); 897 EXPECT_EQ(0u, delegate->data_received().size());
893 EXPECT_EQ(0, delegate->on_data_sent_count()); 898 EXPECT_EQ(0, delegate->on_data_sent_count());
894 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 899 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); 1171 new TestDelegateBase(read_buffer.get(), kReadBufferSize));
1167 delegate->set_do_not_start_read(true); 1172 delegate->set_do_not_start_read(true);
1168 delegate->Start(std::move(request_info), http_session_.get()); 1173 delegate->Start(std::move(request_info), http_session_.get());
1169 // Send the request and receive response headers. 1174 // Send the request and receive response headers.
1170 base::RunLoop().RunUntilIdle(); 1175 base::RunLoop().RunUntilIdle();
1171 1176
1172 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 1177 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
1173 // Cancel the stream after ReadData returns ERR_IO_PENDING. 1178 // Cancel the stream after ReadData returns ERR_IO_PENDING.
1174 int rv = delegate->ReadData(); 1179 int rv = delegate->ReadData();
1175 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 1180 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
1176 EXPECT_EQ(ERR_IO_PENDING, rv); 1181 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1177 delegate->CancelStream(); 1182 delegate->CancelStream();
1178 sequenced_data_->Resume(); 1183 sequenced_data_->Resume();
1179 base::RunLoop().RunUntilIdle(); 1184 base::RunLoop().RunUntilIdle();
1180 1185
1181 EXPECT_EQ(0, delegate->on_data_read_count()); 1186 EXPECT_EQ(0, delegate->on_data_read_count());
1182 EXPECT_EQ(0, delegate->on_data_sent_count()); 1187 EXPECT_EQ(0, delegate->on_data_sent_count());
1183 // Calling after stream is canceled gives kProtoUnknown. 1188 // Calling after stream is canceled gives kProtoUnknown.
1184 EXPECT_EQ(kProtoUnknown, delegate->GetProtocol()); 1189 EXPECT_EQ(kProtoUnknown, delegate->GetProtocol());
1185 EXPECT_EQ(0, delegate->GetTotalSentBytes()); 1190 EXPECT_EQ(0, delegate->GetTotalSentBytes());
1186 EXPECT_EQ(0, delegate->GetTotalReceivedBytes()); 1191 EXPECT_EQ(0, delegate->GetTotalReceivedBytes());
(...skipping 28 matching lines...) Expand all
1215 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength, 1220 request_info->extra_headers.SetHeader(net::HttpRequestHeaders::kContentLength,
1216 base::SizeTToString(kBodyDataSize * 3)); 1221 base::SizeTToString(kBodyDataSize * 3));
1217 1222
1218 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 1223 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
1219 std::unique_ptr<TestDelegateBase> delegate( 1224 std::unique_ptr<TestDelegateBase> delegate(
1220 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); 1225 new TestDelegateBase(read_buffer.get(), kReadBufferSize));
1221 delegate->SetRunUntilCompletion(true); 1226 delegate->SetRunUntilCompletion(true);
1222 delegate->Start(std::move(request_info), http_session_.get()); 1227 delegate->Start(std::move(request_info), http_session_.get());
1223 1228
1224 base::RunLoop().RunUntilIdle(); 1229 base::RunLoop().RunUntilIdle();
1225 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, delegate->error()); 1230 EXPECT_THAT(delegate->error(), IsError(ERR_SPDY_PROTOCOL_ERROR));
1226 EXPECT_EQ(delegate->response_headers().end(), 1231 EXPECT_EQ(delegate->response_headers().end(),
1227 delegate->response_headers().find(":status")); 1232 delegate->response_headers().find(":status"));
1228 EXPECT_EQ(0, delegate->on_data_read_count()); 1233 EXPECT_EQ(0, delegate->on_data_read_count());
1229 EXPECT_EQ(0, delegate->on_data_sent_count()); 1234 EXPECT_EQ(0, delegate->on_data_sent_count());
1230 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 1235 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
1231 // BidirectionalStreamSpdyStreamJob does not count the bytes sent for |rst| 1236 // BidirectionalStreamSpdyStreamJob does not count the bytes sent for |rst|
1232 // because it is sent after SpdyStream::Delegate::OnClose is called. 1237 // because it is sent after SpdyStream::Delegate::OnClose is called.
1233 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes()); 1238 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes());
1234 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 1239 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
1235 delegate->GetTotalReceivedBytes()); 1240 delegate->GetTotalReceivedBytes());
1236 1241
1237 TestNetLogEntry::List entries; 1242 TestNetLogEntry::List entries;
1238 net_log_.GetEntries(&entries); 1243 net_log_.GetEntries(&entries);
1239 1244
1240 size_t index = ExpectLogContainsSomewhere( 1245 size_t index = ExpectLogContainsSomewhere(
1241 entries, 0, NetLog::TYPE_BIDIRECTIONAL_STREAM_READY, NetLog::PHASE_NONE); 1246 entries, 0, NetLog::TYPE_BIDIRECTIONAL_STREAM_READY, NetLog::PHASE_NONE);
1242 TestNetLogEntry entry = entries[index]; 1247 TestNetLogEntry entry = entries[index];
1243 bool request_headers_sent = false; 1248 bool request_headers_sent = false;
1244 EXPECT_TRUE( 1249 EXPECT_TRUE(
1245 entry.params->GetBoolean("request_headers_sent", &request_headers_sent)); 1250 entry.params->GetBoolean("request_headers_sent", &request_headers_sent));
1246 EXPECT_TRUE(request_headers_sent); 1251 EXPECT_TRUE(request_headers_sent);
1247 1252
1248 index = ExpectLogContainsSomewhere(entries, index, 1253 index = ExpectLogContainsSomewhere(entries, index,
1249 NetLog::TYPE_BIDIRECTIONAL_STREAM_FAILED, 1254 NetLog::TYPE_BIDIRECTIONAL_STREAM_FAILED,
1250 NetLog::PHASE_NONE); 1255 NetLog::PHASE_NONE);
1251 entry = entries[index]; 1256 entry = entries[index];
1252 int net_error = OK; 1257 int net_error = OK;
1253 EXPECT_TRUE(entry.params->GetInteger("net_error", &net_error)); 1258 EXPECT_TRUE(entry.params->GetInteger("net_error", &net_error));
1254 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, net_error); 1259 EXPECT_THAT(net_error, IsError(ERR_SPDY_PROTOCOL_ERROR));
1255 } 1260 }
1256 1261
1257 INSTANTIATE_TEST_CASE_P(CancelOrDeleteTests, 1262 INSTANTIATE_TEST_CASE_P(CancelOrDeleteTests,
1258 BidirectionalStreamTest, 1263 BidirectionalStreamTest,
1259 ::testing::Values(true, false)); 1264 ::testing::Values(true, false));
1260 1265
1261 TEST_P(BidirectionalStreamTest, CancelOrDeleteStreamDuringOnHeadersReceived) { 1266 TEST_P(BidirectionalStreamTest, CancelOrDeleteStreamDuringOnHeadersReceived) {
1262 std::unique_ptr<SpdySerializedFrame> req( 1267 std::unique_ptr<SpdySerializedFrame> req(
1263 spdy_util_.ConstructSpdyGet(kDefaultUrl, 1, LOWEST)); 1268 spdy_util_.ConstructSpdyGet(kDefaultUrl, 1, LOWEST));
1264 1269
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 read_buffer.get(), kReadBufferSize, 1469 read_buffer.get(), kReadBufferSize,
1465 CancelOrDeleteStreamDelegate::Phase::ON_FAILED, GetParam())); 1470 CancelOrDeleteStreamDelegate::Phase::ON_FAILED, GetParam()));
1466 delegate->SetRunUntilCompletion(true); 1471 delegate->SetRunUntilCompletion(true);
1467 delegate->Start(std::move(request_info), http_session_.get()); 1472 delegate->Start(std::move(request_info), http_session_.get());
1468 // Makes sure delegate does not get called. 1473 // Makes sure delegate does not get called.
1469 base::RunLoop().RunUntilIdle(); 1474 base::RunLoop().RunUntilIdle();
1470 EXPECT_EQ(delegate->response_headers().end(), 1475 EXPECT_EQ(delegate->response_headers().end(),
1471 delegate->response_headers().find(":status")); 1476 delegate->response_headers().find(":status"));
1472 EXPECT_EQ(0, delegate->on_data_sent_count()); 1477 EXPECT_EQ(0, delegate->on_data_sent_count());
1473 EXPECT_EQ(0, delegate->on_data_read_count()); 1478 EXPECT_EQ(0, delegate->on_data_read_count());
1474 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, delegate->error()); 1479 EXPECT_THAT(delegate->error(), IsError(ERR_SPDY_PROTOCOL_ERROR));
1475 1480
1476 // If stream is destroyed, do not call into stream. 1481 // If stream is destroyed, do not call into stream.
1477 if (!GetParam()) 1482 if (!GetParam())
1478 return; 1483 return;
1479 EXPECT_EQ(0, delegate->GetTotalSentBytes()); 1484 EXPECT_EQ(0, delegate->GetTotalSentBytes());
1480 EXPECT_EQ(0, delegate->GetTotalReceivedBytes()); 1485 EXPECT_EQ(0, delegate->GetTotalReceivedBytes());
1481 EXPECT_EQ(kProtoUnknown, delegate->GetProtocol()); 1486 EXPECT_EQ(kProtoUnknown, delegate->GetProtocol());
1482 } 1487 }
1483 1488
1484 TEST_F(BidirectionalStreamTest, TestHonorAlternativeServiceHeader) { 1489 TEST_F(BidirectionalStreamTest, TestHonorAlternativeServiceHeader) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 http_session_->http_server_properties()->GetAlternativeServices( 1544 http_session_->http_server_properties()->GetAlternativeServices(
1540 url::SchemeHostPort(default_url_)); 1545 url::SchemeHostPort(default_url_));
1541 ASSERT_EQ(1u, alternative_service_vector.size()); 1546 ASSERT_EQ(1u, alternative_service_vector.size());
1542 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), 1547 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1543 alternative_service_vector[0].protocol); 1548 alternative_service_vector[0].protocol);
1544 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); 1549 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1545 EXPECT_EQ(443, alternative_service_vector[0].port); 1550 EXPECT_EQ(443, alternative_service_vector[0].port);
1546 } 1551 }
1547 1552
1548 } // namespace net 1553 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_network_transaction_unittest.cc ('k') | net/http/disk_cache_based_quic_server_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698