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

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

Issue 2265873002: Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: rebased 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
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 socket_factory_.AddSocketDataProvider(&socket_data); 155 socket_factory_.AddSocketDataProvider(&socket_data);
156 156
157 TestDelegate delegate; 157 TestDelegate delegate;
158 std::unique_ptr<URLRequest> request = context_->CreateRequest( 158 std::unique_ptr<URLRequest> request = context_->CreateRequest(
159 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 159 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
160 160
161 request->Start(); 161 request->Start();
162 ASSERT_TRUE(request->is_pending()); 162 ASSERT_TRUE(request->is_pending());
163 base::RunLoop().Run(); 163 base::RunLoop().Run();
164 164
165 EXPECT_TRUE(request->status().is_success()); 165 EXPECT_EQ(OK, delegate.request_status());
166 EXPECT_EQ(12, request->received_response_content_length()); 166 EXPECT_EQ(12, request->received_response_content_length());
167 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 167 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
168 request->GetTotalSentBytes()); 168 request->GetTotalSentBytes());
169 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 169 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
170 request->GetTotalReceivedBytes()); 170 request->GetTotalReceivedBytes());
171 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 171 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
172 network_delegate_.total_network_bytes_sent()); 172 network_delegate_.total_network_bytes_sent());
173 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 173 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
174 network_delegate_.total_network_bytes_received()); 174 network_delegate_.total_network_bytes_received());
175 } 175 }
176 176
177 TEST_F(URLRequestHttpJobWithMockSocketsTest, 177 TEST_F(URLRequestHttpJobWithMockSocketsTest,
178 TestContentLengthSuccessfulHttp09Request) { 178 TestContentLengthSuccessfulHttp09Request) {
179 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; 179 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
180 MockRead reads[] = {MockRead("Test Content"), 180 MockRead reads[] = {MockRead("Test Content"),
181 MockRead(net::SYNCHRONOUS, net::OK)}; 181 MockRead(net::SYNCHRONOUS, net::OK)};
182 182
183 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); 183 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0);
184 socket_factory_.AddSocketDataProvider(&socket_data); 184 socket_factory_.AddSocketDataProvider(&socket_data);
185 185
186 TestDelegate delegate; 186 TestDelegate delegate;
187 std::unique_ptr<URLRequest> request = context_->CreateRequest( 187 std::unique_ptr<URLRequest> request = context_->CreateRequest(
188 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 188 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
189 189
190 request->Start(); 190 request->Start();
191 ASSERT_TRUE(request->is_pending()); 191 ASSERT_TRUE(request->is_pending());
192 base::RunLoop().Run(); 192 base::RunLoop().Run();
193 193
194 EXPECT_TRUE(request->status().is_success()); 194 EXPECT_EQ(OK, delegate.request_status());
195 EXPECT_EQ(12, request->received_response_content_length()); 195 EXPECT_EQ(12, request->received_response_content_length());
196 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 196 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
197 request->GetTotalSentBytes()); 197 request->GetTotalSentBytes());
198 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 198 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
199 request->GetTotalReceivedBytes()); 199 request->GetTotalReceivedBytes());
200 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 200 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
201 network_delegate_.total_network_bytes_sent()); 201 network_delegate_.total_network_bytes_sent());
202 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 202 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
203 network_delegate_.total_network_bytes_received()); 203 network_delegate_.total_network_bytes_received());
204 } 204 }
(...skipping 10 matching lines...) Expand all
215 socket_factory_.AddSocketDataProvider(&socket_data); 215 socket_factory_.AddSocketDataProvider(&socket_data);
216 216
217 TestDelegate delegate; 217 TestDelegate delegate;
218 std::unique_ptr<URLRequest> request = context_->CreateRequest( 218 std::unique_ptr<URLRequest> request = context_->CreateRequest(
219 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 219 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
220 220
221 request->Start(); 221 request->Start();
222 ASSERT_TRUE(request->is_pending()); 222 ASSERT_TRUE(request->is_pending());
223 base::RunLoop().Run(); 223 base::RunLoop().Run();
224 224
225 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); 225 EXPECT_EQ(ERR_FAILED, delegate.request_status());
226 EXPECT_EQ(12, request->received_response_content_length()); 226 EXPECT_EQ(12, request->received_response_content_length());
227 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 227 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
228 request->GetTotalSentBytes()); 228 request->GetTotalSentBytes());
229 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 229 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
230 request->GetTotalReceivedBytes()); 230 request->GetTotalReceivedBytes());
231 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 231 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
232 network_delegate_.total_network_bytes_sent()); 232 network_delegate_.total_network_bytes_sent());
233 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 233 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
234 network_delegate_.total_network_bytes_received()); 234 network_delegate_.total_network_bytes_received());
235 } 235 }
(...skipping 11 matching lines...) Expand all
247 socket_factory_.AddSocketDataProvider(&socket_data); 247 socket_factory_.AddSocketDataProvider(&socket_data);
248 248
249 TestDelegate delegate; 249 TestDelegate delegate;
250 std::unique_ptr<URLRequest> request = context_->CreateRequest( 250 std::unique_ptr<URLRequest> request = context_->CreateRequest(
251 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 251 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
252 252
253 delegate.set_cancel_in_received_data(true); 253 delegate.set_cancel_in_received_data(true);
254 request->Start(); 254 request->Start();
255 base::RunLoop().RunUntilIdle(); 255 base::RunLoop().RunUntilIdle();
256 256
257 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 257 EXPECT_EQ(ERR_ABORTED, delegate.request_status());
258 EXPECT_EQ(12, request->received_response_content_length()); 258 EXPECT_EQ(12, request->received_response_content_length());
259 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 259 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
260 request->GetTotalSentBytes()); 260 request->GetTotalSentBytes());
261 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 261 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
262 request->GetTotalReceivedBytes()); 262 request->GetTotalReceivedBytes());
263 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 263 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
264 network_delegate_.total_network_bytes_sent()); 264 network_delegate_.total_network_bytes_sent());
265 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 265 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
266 network_delegate_.total_network_bytes_received()); 266 network_delegate_.total_network_bytes_received());
267 } 267 }
(...skipping 27 matching lines...) Expand all
295 socket_factory_.AddSocketDataProvider(&final_socket_data); 295 socket_factory_.AddSocketDataProvider(&final_socket_data);
296 296
297 TestDelegate delegate; 297 TestDelegate delegate;
298 std::unique_ptr<URLRequest> request = context_->CreateRequest( 298 std::unique_ptr<URLRequest> request = context_->CreateRequest(
299 GURL("http://www.redirect.com"), DEFAULT_PRIORITY, &delegate); 299 GURL("http://www.redirect.com"), DEFAULT_PRIORITY, &delegate);
300 300
301 request->Start(); 301 request->Start();
302 ASSERT_TRUE(request->is_pending()); 302 ASSERT_TRUE(request->is_pending());
303 base::RunLoop().RunUntilIdle(); 303 base::RunLoop().RunUntilIdle();
304 304
305 EXPECT_TRUE(request->status().is_success()); 305 EXPECT_EQ(OK, delegate.request_status());
306 EXPECT_EQ(12, request->received_response_content_length()); 306 EXPECT_EQ(12, request->received_response_content_length());
307 // Should not include the redirect. 307 // Should not include the redirect.
308 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)), 308 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)),
309 request->GetTotalSentBytes()); 309 request->GetTotalSentBytes());
310 EXPECT_EQ(CountReadBytes(final_reads, arraysize(final_reads)), 310 EXPECT_EQ(CountReadBytes(final_reads, arraysize(final_reads)),
311 request->GetTotalReceivedBytes()); 311 request->GetTotalReceivedBytes());
312 // Should include the redirect as well as the final response. 312 // Should include the redirect as well as the final response.
313 EXPECT_EQ(CountWriteBytes(redirect_writes, arraysize(redirect_writes)) + 313 EXPECT_EQ(CountWriteBytes(redirect_writes, arraysize(redirect_writes)) +
314 CountWriteBytes(final_writes, arraysize(final_writes)), 314 CountWriteBytes(final_writes, arraysize(final_writes)),
315 network_delegate_.total_network_bytes_sent()); 315 network_delegate_.total_network_bytes_sent());
(...skipping 11 matching lines...) Expand all
327 socket_factory_.AddSocketDataProvider(&socket_data); 327 socket_factory_.AddSocketDataProvider(&socket_data);
328 328
329 TestDelegate delegate; 329 TestDelegate delegate;
330 std::unique_ptr<URLRequest> request = context_->CreateRequest( 330 std::unique_ptr<URLRequest> request = context_->CreateRequest(
331 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 331 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
332 332
333 delegate.set_cancel_in_response_started(true); 333 delegate.set_cancel_in_response_started(true);
334 request->Start(); 334 request->Start();
335 base::RunLoop().RunUntilIdle(); 335 base::RunLoop().RunUntilIdle();
336 336
337 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 337 EXPECT_EQ(ERR_ABORTED, delegate.request_status());
338 EXPECT_EQ(0, request->received_response_content_length()); 338 EXPECT_EQ(0, request->received_response_content_length());
339 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 339 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
340 request->GetTotalSentBytes()); 340 request->GetTotalSentBytes());
341 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 341 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
342 request->GetTotalReceivedBytes()); 342 request->GetTotalReceivedBytes());
343 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 343 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
344 network_delegate_.total_network_bytes_sent()); 344 network_delegate_.total_network_bytes_sent());
345 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 345 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
346 network_delegate_.total_network_bytes_received()); 346 network_delegate_.total_network_bytes_received());
347 } 347 }
348 348
349 TEST_F(URLRequestHttpJobWithMockSocketsTest, 349 TEST_F(URLRequestHttpJobWithMockSocketsTest,
350 TestNetworkBytesCancelledImmediately) { 350 TestNetworkBytesCancelledImmediately) {
351 StaticSocketDataProvider socket_data(nullptr, 0, nullptr, 0); 351 StaticSocketDataProvider socket_data(nullptr, 0, nullptr, 0);
352 socket_factory_.AddSocketDataProvider(&socket_data); 352 socket_factory_.AddSocketDataProvider(&socket_data);
353 353
354 TestDelegate delegate; 354 TestDelegate delegate;
355 std::unique_ptr<URLRequest> request = context_->CreateRequest( 355 std::unique_ptr<URLRequest> request = context_->CreateRequest(
356 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 356 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
357 357
358 request->Start(); 358 request->Start();
359 request->Cancel(); 359 request->Cancel();
360 base::RunLoop().RunUntilIdle(); 360 base::RunLoop().RunUntilIdle();
361 361
362 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 362 EXPECT_EQ(ERR_ABORTED, delegate.request_status());
363 EXPECT_EQ(0, request->received_response_content_length()); 363 EXPECT_EQ(0, request->received_response_content_length());
364 EXPECT_EQ(0, request->GetTotalSentBytes()); 364 EXPECT_EQ(0, request->GetTotalSentBytes());
365 EXPECT_EQ(0, request->GetTotalReceivedBytes()); 365 EXPECT_EQ(0, request->GetTotalReceivedBytes());
366 EXPECT_EQ(0, network_delegate_.total_network_bytes_received()); 366 EXPECT_EQ(0, network_delegate_.total_network_bytes_received());
367 } 367 }
368 368
369 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) { 369 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) {
370 DelayedCookieMonster cookie_monster; 370 DelayedCookieMonster cookie_monster;
371 TestURLRequestContext context(true); 371 TestURLRequestContext context(true);
372 context.set_cookie_store(&cookie_monster); 372 context.set_cookie_store(&cookie_monster);
373 context.Init(); 373 context.Init();
374 374
375 TestDelegate delegate; 375 TestDelegate delegate;
376 std::unique_ptr<URLRequest> request = context.CreateRequest( 376 std::unique_ptr<URLRequest> request = context.CreateRequest(
377 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 377 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
378 378
379 request->Start(); 379 request->Start();
380 request->Cancel(); 380 request->Cancel();
381 base::RunLoop().Run(); 381 base::RunLoop().Run();
382 382
383 EXPECT_EQ(URLRequestStatus::CANCELED, request->status().status()); 383 EXPECT_EQ(ERR_ABORTED, delegate.request_status());
384 } 384 }
385 385
386 // Make sure that SetPriority actually sets the URLRequestHttpJob's 386 // Make sure that SetPriority actually sets the URLRequestHttpJob's
387 // priority, before start. Other tests handle the after start case. 387 // priority, before start. Other tests handle the after start case.
388 TEST_F(URLRequestHttpJobTest, SetPriorityBasic) { 388 TEST_F(URLRequestHttpJobTest, SetPriorityBasic) {
389 std::unique_ptr<TestURLRequestHttpJob> job( 389 std::unique_ptr<TestURLRequestHttpJob> job(
390 new TestURLRequestHttpJob(req_.get())); 390 new TestURLRequestHttpJob(req_.get()));
391 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 391 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
392 392
393 job->SetPriority(LOWEST); 393 job->SetPriority(LOWEST);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // invoked. 560 // invoked.
561 GURL url("http://example.com"); 561 GURL url("http://example.com");
562 EXPECT_CALL(sdch_observer, 562 EXPECT_CALL(sdch_observer,
563 OnGetDictionary(url, GURL("http://example.com/sdch.dict"))); 563 OnGetDictionary(url, GURL("http://example.com/sdch.dict")));
564 TestDelegate delegate; 564 TestDelegate delegate;
565 std::unique_ptr<URLRequest> request = 565 std::unique_ptr<URLRequest> request =
566 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate); 566 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate);
567 request->Start(); 567 request->Start();
568 base::RunLoop().RunUntilIdle(); 568 base::RunLoop().RunUntilIdle();
569 569
570 EXPECT_TRUE(request->status().is_success()); 570 EXPECT_EQ(OK, delegate.request_status());
571 571
572 // Second response should be from cache without notification of SdchObserver 572 // Second response should be from cache without notification of SdchObserver
573 TestDelegate delegate2; 573 TestDelegate delegate2;
574 std::unique_ptr<URLRequest> request2 = 574 std::unique_ptr<URLRequest> request2 =
575 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate2); 575 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate2);
576 request2->Start(); 576 request2->Start();
577 base::RunLoop().RunUntilIdle(); 577 base::RunLoop().RunUntilIdle();
578 578
579 EXPECT_TRUE(request->status().is_success()); 579 EXPECT_EQ(OK, delegate2.request_status());
580 580
581 // Cleanup manager. 581 // Cleanup manager.
582 sdch_manager.RemoveObserver(&sdch_observer); 582 sdch_manager.RemoveObserver(&sdch_observer);
583 } 583 }
584 584
585 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test { 585 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test {
586 protected: 586 protected:
587 URLRequestHttpJobWithBrotliSupportTest() 587 URLRequestHttpJobWithBrotliSupportTest()
588 : context_(new TestURLRequestContext(true)) { 588 : context_(new TestURLRequestContext(true)) {
589 std::unique_ptr<HttpNetworkSession::Params> params( 589 std::unique_ptr<HttpNetworkSession::Params> params(
(...skipping 16 matching lines...) Expand all
606 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 606 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
607 arraysize(writes)); 607 arraysize(writes));
608 socket_factory_.AddSocketDataProvider(&socket_data); 608 socket_factory_.AddSocketDataProvider(&socket_data);
609 609
610 TestDelegate delegate; 610 TestDelegate delegate;
611 std::unique_ptr<URLRequest> request = context_->CreateRequest( 611 std::unique_ptr<URLRequest> request = context_->CreateRequest(
612 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); 612 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
613 request->Start(); 613 request->Start();
614 base::RunLoop().RunUntilIdle(); 614 base::RunLoop().RunUntilIdle();
615 615
616 EXPECT_TRUE(request->status().is_success()); 616 EXPECT_EQ(OK, delegate.request_status());
617 EXPECT_EQ(12, request->received_response_content_length()); 617 EXPECT_EQ(12, request->received_response_content_length());
618 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 618 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
619 request->GetTotalSentBytes()); 619 request->GetTotalSentBytes());
620 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 620 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
621 request->GetTotalReceivedBytes()); 621 request->GetTotalReceivedBytes());
622 } 622 }
623 623
624 TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) { 624 TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) {
625 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK); 625 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK);
626 ssl_socket_data_provider.next_proto = kProtoHTTP11; 626 ssl_socket_data_provider.next_proto = kProtoHTTP11;
(...skipping 14 matching lines...) Expand all
641 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 641 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
642 arraysize(writes)); 642 arraysize(writes));
643 socket_factory_.AddSocketDataProvider(&socket_data); 643 socket_factory_.AddSocketDataProvider(&socket_data);
644 644
645 TestDelegate delegate; 645 TestDelegate delegate;
646 std::unique_ptr<URLRequest> request = context_->CreateRequest( 646 std::unique_ptr<URLRequest> request = context_->CreateRequest(
647 GURL("https://www.example.com"), DEFAULT_PRIORITY, &delegate); 647 GURL("https://www.example.com"), DEFAULT_PRIORITY, &delegate);
648 request->Start(); 648 request->Start();
649 base::RunLoop().RunUntilIdle(); 649 base::RunLoop().RunUntilIdle();
650 650
651 EXPECT_TRUE(request->status().is_success()); 651 EXPECT_EQ(OK, delegate.request_status());
652 EXPECT_EQ(12, request->received_response_content_length()); 652 EXPECT_EQ(12, request->received_response_content_length());
653 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 653 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
654 request->GetTotalSentBytes()); 654 request->GetTotalSentBytes());
655 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 655 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
656 request->GetTotalReceivedBytes()); 656 request->GetTotalReceivedBytes());
657 } 657 }
658 658
659 // This base class just serves to set up some things before the TestURLRequest 659 // This base class just serves to set up some things before the TestURLRequest
660 // constructor is called. 660 // constructor is called.
661 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { 661 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 return std::unique_ptr<WebSocketStream>(); 791 return std::unique_ptr<WebSocketStream>();
792 } 792 }
793 793
794 private: 794 private:
795 bool initialize_stream_was_called_; 795 bool initialize_stream_was_called_;
796 }; 796 };
797 797
798 TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) { 798 TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) {
799 req_->Start(); 799 req_->Start();
800 base::RunLoop().RunUntilIdle(); 800 base::RunLoop().RunUntilIdle();
801 EXPECT_EQ(URLRequestStatus::FAILED, req_->status().status()); 801 EXPECT_EQ(ERR_DISALLOWED_URL_SCHEME, delegate_.request_status());
802 EXPECT_THAT(req_->status().error(), IsError(ERR_DISALLOWED_URL_SCHEME));
803 } 802 }
804 803
805 TEST_F(URLRequestHttpJobWebSocketTest, CreateHelperPassedThrough) { 804 TEST_F(URLRequestHttpJobWebSocketTest, CreateHelperPassedThrough) {
806 std::unique_ptr<MockCreateHelper> create_helper( 805 std::unique_ptr<MockCreateHelper> create_helper(
807 new ::testing::StrictMock<MockCreateHelper>()); 806 new ::testing::StrictMock<MockCreateHelper>());
808 FakeWebSocketHandshakeStream* fake_handshake_stream( 807 FakeWebSocketHandshakeStream* fake_handshake_stream(
809 new FakeWebSocketHandshakeStream); 808 new FakeWebSocketHandshakeStream);
810 // Ownership of fake_handshake_stream is transferred when CreateBasicStream() 809 // Ownership of fake_handshake_stream is transferred when CreateBasicStream()
811 // is called. 810 // is called.
812 EXPECT_CALL(*create_helper, CreateBasicStreamMock()) 811 EXPECT_CALL(*create_helper, CreateBasicStreamMock())
813 .WillOnce(Return(fake_handshake_stream)); 812 .WillOnce(Return(fake_handshake_stream));
814 req_->SetUserData(WebSocketHandshakeStreamBase::CreateHelper::DataKey(), 813 req_->SetUserData(WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
815 create_helper.release()); 814 create_helper.release());
816 req_->SetLoadFlags(LOAD_DISABLE_CACHE); 815 req_->SetLoadFlags(LOAD_DISABLE_CACHE);
817 req_->Start(); 816 req_->Start();
818 base::RunLoop().RunUntilIdle(); 817 base::RunLoop().RunUntilIdle();
819 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status());
820 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 818 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
821 } 819 }
822 820
823 #endif // defined(ENABLE_WEBSOCKETS) 821 #endif // defined(ENABLE_WEBSOCKETS)
824 822
825 } // namespace 823 } // namespace
826 824
827 } // namespace net 825 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698