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

Side by Side Diff: net/url_request/url_request_http_job_unittest.cc

Issue 2332643002: Change net/nqe and some url_request tests to use new URLRequest API (Closed)
Patch Set: add ftp job unittests and http job files Created 4 years, 3 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
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <memory> 10 #include <memory>
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 socket_factory_.AddSocketDataProvider(&socket_data); 156 socket_factory_.AddSocketDataProvider(&socket_data);
157 157
158 TestDelegate delegate; 158 TestDelegate delegate;
159 std::unique_ptr<URLRequest> request = context_->CreateRequest( 159 std::unique_ptr<URLRequest> request = context_->CreateRequest(
160 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 160 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
161 161
162 request->Start(); 162 request->Start();
163 ASSERT_TRUE(request->is_pending()); 163 ASSERT_TRUE(request->is_pending());
164 base::RunLoop().Run(); 164 base::RunLoop().Run();
165 165
166 EXPECT_TRUE(request->status().is_success()); 166 EXPECT_THAT(delegate.request_status(), IsOk());
167 EXPECT_EQ(12, request->received_response_content_length()); 167 EXPECT_EQ(12, request->received_response_content_length());
168 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 168 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
169 request->GetTotalSentBytes()); 169 request->GetTotalSentBytes());
170 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 170 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
171 request->GetTotalReceivedBytes()); 171 request->GetTotalReceivedBytes());
172 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 172 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
173 network_delegate_.total_network_bytes_sent()); 173 network_delegate_.total_network_bytes_sent());
174 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 174 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
175 network_delegate_.total_network_bytes_received()); 175 network_delegate_.total_network_bytes_received());
176 } 176 }
177 177
178 TEST_F(URLRequestHttpJobWithMockSocketsTest, 178 TEST_F(URLRequestHttpJobWithMockSocketsTest,
179 TestContentLengthSuccessfulHttp09Request) { 179 TestContentLengthSuccessfulHttp09Request) {
180 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; 180 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
181 MockRead reads[] = {MockRead("Test Content"), 181 MockRead reads[] = {MockRead("Test Content"),
182 MockRead(net::SYNCHRONOUS, net::OK)}; 182 MockRead(net::SYNCHRONOUS, net::OK)};
183 183
184 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); 184 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0);
185 socket_factory_.AddSocketDataProvider(&socket_data); 185 socket_factory_.AddSocketDataProvider(&socket_data);
186 186
187 TestDelegate delegate; 187 TestDelegate delegate;
188 std::unique_ptr<URLRequest> request = context_->CreateRequest( 188 std::unique_ptr<URLRequest> request = context_->CreateRequest(
189 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 189 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
190 190
191 request->Start(); 191 request->Start();
192 ASSERT_TRUE(request->is_pending()); 192 ASSERT_TRUE(request->is_pending());
193 base::RunLoop().Run(); 193 base::RunLoop().Run();
194 194
195 EXPECT_TRUE(request->status().is_success()); 195 EXPECT_THAT(delegate.request_status(), IsOk());
196 EXPECT_EQ(12, request->received_response_content_length()); 196 EXPECT_EQ(12, request->received_response_content_length());
197 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 197 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
198 request->GetTotalSentBytes()); 198 request->GetTotalSentBytes());
199 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 199 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
200 request->GetTotalReceivedBytes()); 200 request->GetTotalReceivedBytes());
201 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 201 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
202 network_delegate_.total_network_bytes_sent()); 202 network_delegate_.total_network_bytes_sent());
203 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 203 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
204 network_delegate_.total_network_bytes_received()); 204 network_delegate_.total_network_bytes_received());
205 } 205 }
(...skipping 10 matching lines...) Expand all
216 socket_factory_.AddSocketDataProvider(&socket_data); 216 socket_factory_.AddSocketDataProvider(&socket_data);
217 217
218 TestDelegate delegate; 218 TestDelegate delegate;
219 std::unique_ptr<URLRequest> request = context_->CreateRequest( 219 std::unique_ptr<URLRequest> request = context_->CreateRequest(
220 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 220 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
221 221
222 request->Start(); 222 request->Start();
223 ASSERT_TRUE(request->is_pending()); 223 ASSERT_TRUE(request->is_pending());
224 base::RunLoop().Run(); 224 base::RunLoop().Run();
225 225
226 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); 226 EXPECT_THAT(delegate.request_status(), IsError(ERR_FAILED));
227 EXPECT_EQ(12, request->received_response_content_length()); 227 EXPECT_EQ(12, request->received_response_content_length());
228 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 228 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
229 request->GetTotalSentBytes()); 229 request->GetTotalSentBytes());
230 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 230 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
231 request->GetTotalReceivedBytes()); 231 request->GetTotalReceivedBytes());
232 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 232 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
233 network_delegate_.total_network_bytes_sent()); 233 network_delegate_.total_network_bytes_sent());
234 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 234 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
235 network_delegate_.total_network_bytes_received()); 235 network_delegate_.total_network_bytes_received());
236 } 236 }
(...skipping 11 matching lines...) Expand all
248 socket_factory_.AddSocketDataProvider(&socket_data); 248 socket_factory_.AddSocketDataProvider(&socket_data);
249 249
250 TestDelegate delegate; 250 TestDelegate delegate;
251 std::unique_ptr<URLRequest> request = context_->CreateRequest( 251 std::unique_ptr<URLRequest> request = context_->CreateRequest(
252 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 252 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
253 253
254 delegate.set_cancel_in_received_data(true); 254 delegate.set_cancel_in_received_data(true);
255 request->Start(); 255 request->Start();
256 base::RunLoop().RunUntilIdle(); 256 base::RunLoop().RunUntilIdle();
257 257
258 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 258 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED));
259 EXPECT_EQ(12, request->received_response_content_length()); 259 EXPECT_EQ(12, request->received_response_content_length());
260 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 260 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
261 request->GetTotalSentBytes()); 261 request->GetTotalSentBytes());
262 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 262 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
263 request->GetTotalReceivedBytes()); 263 request->GetTotalReceivedBytes());
264 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 264 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
265 network_delegate_.total_network_bytes_sent()); 265 network_delegate_.total_network_bytes_sent());
266 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 266 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
267 network_delegate_.total_network_bytes_received()); 267 network_delegate_.total_network_bytes_received());
268 } 268 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 socket_factory_.AddSocketDataProvider(&final_socket_data); 421 socket_factory_.AddSocketDataProvider(&final_socket_data);
422 422
423 TestDelegate delegate; 423 TestDelegate delegate;
424 std::unique_ptr<URLRequest> request = context_->CreateRequest( 424 std::unique_ptr<URLRequest> request = context_->CreateRequest(
425 GURL("http://www.redirect.com"), DEFAULT_PRIORITY, &delegate); 425 GURL("http://www.redirect.com"), DEFAULT_PRIORITY, &delegate);
426 426
427 request->Start(); 427 request->Start();
428 ASSERT_TRUE(request->is_pending()); 428 ASSERT_TRUE(request->is_pending());
429 base::RunLoop().RunUntilIdle(); 429 base::RunLoop().RunUntilIdle();
430 430
431 EXPECT_EQ(OK, request->status().error()); 431 EXPECT_THAT(delegate.request_status(), IsOk());
432 EXPECT_EQ(12, request->received_response_content_length()); 432 EXPECT_EQ(12, request->received_response_content_length());
433 // Should not include the redirect. 433 // Should not include the redirect.
434 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)), 434 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)),
435 request->GetTotalSentBytes()); 435 request->GetTotalSentBytes());
436 EXPECT_EQ(CountReadBytes(final_reads, arraysize(final_reads)), 436 EXPECT_EQ(CountReadBytes(final_reads, arraysize(final_reads)),
437 request->GetTotalReceivedBytes()); 437 request->GetTotalReceivedBytes());
438 // Should include the redirect as well as the final response. 438 // Should include the redirect as well as the final response.
439 EXPECT_EQ(CountWriteBytes(redirect_writes, arraysize(redirect_writes)) + 439 EXPECT_EQ(CountWriteBytes(redirect_writes, arraysize(redirect_writes)) +
440 CountWriteBytes(final_writes, arraysize(final_writes)), 440 CountWriteBytes(final_writes, arraysize(final_writes)),
441 network_delegate_.total_network_bytes_sent()); 441 network_delegate_.total_network_bytes_sent());
(...skipping 11 matching lines...) Expand all
453 socket_factory_.AddSocketDataProvider(&socket_data); 453 socket_factory_.AddSocketDataProvider(&socket_data);
454 454
455 TestDelegate delegate; 455 TestDelegate delegate;
456 std::unique_ptr<URLRequest> request = context_->CreateRequest( 456 std::unique_ptr<URLRequest> request = context_->CreateRequest(
457 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 457 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
458 458
459 delegate.set_cancel_in_response_started(true); 459 delegate.set_cancel_in_response_started(true);
460 request->Start(); 460 request->Start();
461 base::RunLoop().RunUntilIdle(); 461 base::RunLoop().RunUntilIdle();
462 462
463 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 463 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED));
464 EXPECT_EQ(0, request->received_response_content_length()); 464 EXPECT_EQ(0, request->received_response_content_length());
465 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 465 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
466 request->GetTotalSentBytes()); 466 request->GetTotalSentBytes());
467 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 467 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
468 request->GetTotalReceivedBytes()); 468 request->GetTotalReceivedBytes());
469 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 469 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
470 network_delegate_.total_network_bytes_sent()); 470 network_delegate_.total_network_bytes_sent());
471 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 471 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
472 network_delegate_.total_network_bytes_received()); 472 network_delegate_.total_network_bytes_received());
473 } 473 }
474 474
475 TEST_F(URLRequestHttpJobWithMockSocketsTest, 475 TEST_F(URLRequestHttpJobWithMockSocketsTest,
476 TestNetworkBytesCancelledImmediately) { 476 TestNetworkBytesCancelledImmediately) {
477 StaticSocketDataProvider socket_data(nullptr, 0, nullptr, 0); 477 StaticSocketDataProvider socket_data(nullptr, 0, nullptr, 0);
478 socket_factory_.AddSocketDataProvider(&socket_data); 478 socket_factory_.AddSocketDataProvider(&socket_data);
479 479
480 TestDelegate delegate; 480 TestDelegate delegate;
481 std::unique_ptr<URLRequest> request = context_->CreateRequest( 481 std::unique_ptr<URLRequest> request = context_->CreateRequest(
482 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 482 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
483 483
484 request->Start(); 484 request->Start();
485 request->Cancel(); 485 request->Cancel();
486 base::RunLoop().RunUntilIdle(); 486 base::RunLoop().RunUntilIdle();
487 487
488 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 488 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED));
489 EXPECT_EQ(0, request->received_response_content_length()); 489 EXPECT_EQ(0, request->received_response_content_length());
490 EXPECT_EQ(0, request->GetTotalSentBytes()); 490 EXPECT_EQ(0, request->GetTotalSentBytes());
491 EXPECT_EQ(0, request->GetTotalReceivedBytes()); 491 EXPECT_EQ(0, request->GetTotalReceivedBytes());
492 EXPECT_EQ(0, network_delegate_.total_network_bytes_received()); 492 EXPECT_EQ(0, network_delegate_.total_network_bytes_received());
493 } 493 }
494 494
495 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) { 495 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) {
496 DelayedCookieMonster cookie_monster; 496 DelayedCookieMonster cookie_monster;
497 TestURLRequestContext context(true); 497 TestURLRequestContext context(true);
498 context.set_cookie_store(&cookie_monster); 498 context.set_cookie_store(&cookie_monster);
499 context.Init(); 499 context.Init();
500 500
501 TestDelegate delegate; 501 TestDelegate delegate;
502 std::unique_ptr<URLRequest> request = context.CreateRequest( 502 std::unique_ptr<URLRequest> request = context.CreateRequest(
503 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 503 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
504 504
505 request->Start(); 505 request->Start();
506 request->Cancel(); 506 request->Cancel();
507 base::RunLoop().Run(); 507 base::RunLoop().Run();
508 508
509 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 509 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED));
510 } 510 }
511 511
512 // Make sure that SetPriority actually sets the URLRequestHttpJob's 512 // Make sure that SetPriority actually sets the URLRequestHttpJob's
513 // priority, before start. Other tests handle the after start case. 513 // priority, before start. Other tests handle the after start case.
514 TEST_F(URLRequestHttpJobTest, SetPriorityBasic) { 514 TEST_F(URLRequestHttpJobTest, SetPriorityBasic) {
515 std::unique_ptr<TestURLRequestHttpJob> job( 515 std::unique_ptr<TestURLRequestHttpJob> job(
516 new TestURLRequestHttpJob(req_.get())); 516 new TestURLRequestHttpJob(req_.get()));
517 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 517 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
518 518
519 job->SetPriority(LOWEST); 519 job->SetPriority(LOWEST);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // invoked. 686 // invoked.
687 GURL url("http://example.com"); 687 GURL url("http://example.com");
688 EXPECT_CALL(sdch_observer, 688 EXPECT_CALL(sdch_observer,
689 OnGetDictionary(url, GURL("http://example.com/sdch.dict"))); 689 OnGetDictionary(url, GURL("http://example.com/sdch.dict")));
690 TestDelegate delegate; 690 TestDelegate delegate;
691 std::unique_ptr<URLRequest> request = 691 std::unique_ptr<URLRequest> request =
692 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate); 692 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate);
693 request->Start(); 693 request->Start();
694 base::RunLoop().RunUntilIdle(); 694 base::RunLoop().RunUntilIdle();
695 695
696 EXPECT_TRUE(request->status().is_success()); 696 EXPECT_THAT(delegate.request_status(), IsOk());
697 697
698 // Second response should be from cache without notification of SdchObserver 698 // Second response should be from cache without notification of SdchObserver
699 TestDelegate delegate2; 699 TestDelegate delegate2;
700 std::unique_ptr<URLRequest> request2 = 700 std::unique_ptr<URLRequest> request2 =
701 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate2); 701 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate2);
702 request2->Start(); 702 request2->Start();
703 base::RunLoop().RunUntilIdle(); 703 base::RunLoop().RunUntilIdle();
704 704
705 EXPECT_TRUE(request->status().is_success()); 705 EXPECT_THAT(delegate2.request_status(), IsOk());
706 706
707 // Cleanup manager. 707 // Cleanup manager.
708 sdch_manager.RemoveObserver(&sdch_observer); 708 sdch_manager.RemoveObserver(&sdch_observer);
709 } 709 }
710 710
711 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test { 711 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test {
712 protected: 712 protected:
713 URLRequestHttpJobWithBrotliSupportTest() 713 URLRequestHttpJobWithBrotliSupportTest()
714 : context_(new TestURLRequestContext(true)) { 714 : context_(new TestURLRequestContext(true)) {
715 std::unique_ptr<HttpNetworkSession::Params> params( 715 std::unique_ptr<HttpNetworkSession::Params> params(
(...skipping 16 matching lines...) Expand all
732 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 732 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
733 arraysize(writes)); 733 arraysize(writes));
734 socket_factory_.AddSocketDataProvider(&socket_data); 734 socket_factory_.AddSocketDataProvider(&socket_data);
735 735
736 TestDelegate delegate; 736 TestDelegate delegate;
737 std::unique_ptr<URLRequest> request = context_->CreateRequest( 737 std::unique_ptr<URLRequest> request = context_->CreateRequest(
738 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 738 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
739 request->Start(); 739 request->Start();
740 base::RunLoop().RunUntilIdle(); 740 base::RunLoop().RunUntilIdle();
741 741
742 EXPECT_TRUE(request->status().is_success()); 742 EXPECT_THAT(delegate.request_status(), IsOk());
743 EXPECT_EQ(12, request->received_response_content_length()); 743 EXPECT_EQ(12, request->received_response_content_length());
744 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 744 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
745 request->GetTotalSentBytes()); 745 request->GetTotalSentBytes());
746 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 746 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
747 request->GetTotalReceivedBytes()); 747 request->GetTotalReceivedBytes());
748 } 748 }
749 749
750 TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) { 750 TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) {
751 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK); 751 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK);
752 ssl_socket_data_provider.next_proto = kProtoHTTP11; 752 ssl_socket_data_provider.next_proto = kProtoHTTP11;
(...skipping 14 matching lines...) Expand all
767 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 767 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
768 arraysize(writes)); 768 arraysize(writes));
769 socket_factory_.AddSocketDataProvider(&socket_data); 769 socket_factory_.AddSocketDataProvider(&socket_data);
770 770
771 TestDelegate delegate; 771 TestDelegate delegate;
772 std::unique_ptr<URLRequest> request = context_->CreateRequest( 772 std::unique_ptr<URLRequest> request = context_->CreateRequest(
773 GURL("https://www.example.com"), DEFAULT_PRIORITY, &delegate); 773 GURL("https://www.example.com"), DEFAULT_PRIORITY, &delegate);
774 request->Start(); 774 request->Start();
775 base::RunLoop().RunUntilIdle(); 775 base::RunLoop().RunUntilIdle();
776 776
777 EXPECT_TRUE(request->status().is_success()); 777 EXPECT_THAT(delegate.request_status(), IsOk());
778 EXPECT_EQ(12, request->received_response_content_length()); 778 EXPECT_EQ(12, request->received_response_content_length());
779 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 779 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
780 request->GetTotalSentBytes()); 780 request->GetTotalSentBytes());
781 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 781 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
782 request->GetTotalReceivedBytes()); 782 request->GetTotalReceivedBytes());
783 } 783 }
784 784
785 // This base class just serves to set up some things before the TestURLRequest 785 // This base class just serves to set up some things before the TestURLRequest
786 // constructor is called. 786 // constructor is called.
787 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { 787 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 return std::unique_ptr<WebSocketStream>(); 917 return std::unique_ptr<WebSocketStream>();
918 } 918 }
919 919
920 private: 920 private:
921 bool initialize_stream_was_called_; 921 bool initialize_stream_was_called_;
922 }; 922 };
923 923
924 TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) { 924 TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) {
925 req_->Start(); 925 req_->Start();
926 base::RunLoop().RunUntilIdle(); 926 base::RunLoop().RunUntilIdle();
927 EXPECT_EQ(URLRequestStatus::FAILED, req_->status().status()); 927 EXPECT_THAT(delegate_.request_status(), IsError(ERR_DISALLOWED_URL_SCHEME));
928 EXPECT_THAT(req_->status().error(), IsError(ERR_DISALLOWED_URL_SCHEME));
929 } 928 }
930 929
931 TEST_F(URLRequestHttpJobWebSocketTest, CreateHelperPassedThrough) { 930 TEST_F(URLRequestHttpJobWebSocketTest, CreateHelperPassedThrough) {
932 std::unique_ptr<MockCreateHelper> create_helper( 931 std::unique_ptr<MockCreateHelper> create_helper(
933 new ::testing::StrictMock<MockCreateHelper>()); 932 new ::testing::StrictMock<MockCreateHelper>());
934 FakeWebSocketHandshakeStream* fake_handshake_stream( 933 FakeWebSocketHandshakeStream* fake_handshake_stream(
935 new FakeWebSocketHandshakeStream); 934 new FakeWebSocketHandshakeStream);
936 // Ownership of fake_handshake_stream is transferred when CreateBasicStream() 935 // Ownership of fake_handshake_stream is transferred when CreateBasicStream()
937 // is called. 936 // is called.
938 EXPECT_CALL(*create_helper, CreateBasicStreamMock()) 937 EXPECT_CALL(*create_helper, CreateBasicStreamMock())
939 .WillOnce(Return(fake_handshake_stream)); 938 .WillOnce(Return(fake_handshake_stream));
940 req_->SetUserData(WebSocketHandshakeStreamBase::CreateHelper::DataKey(), 939 req_->SetUserData(WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
941 create_helper.release()); 940 create_helper.release());
942 req_->SetLoadFlags(LOAD_DISABLE_CACHE); 941 req_->SetLoadFlags(LOAD_DISABLE_CACHE);
943 req_->Start(); 942 req_->Start();
944 base::RunLoop().RunUntilIdle(); 943 base::RunLoop().RunUntilIdle();
945 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); 944 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING));
946 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 945 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
947 } 946 }
948 947
949 #endif // defined(ENABLE_WEBSOCKETS) 948 #endif // defined(ENABLE_WEBSOCKETS)
950 949
951 } // namespace 950 } // namespace
952 951
953 } // namespace net 952 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698