| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/url_request/url_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
| 15 #include "net/base/load_states.h" | 15 #include "net/base/load_states.h" |
| 16 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
| 17 #include "net/ftp/ftp_auth_cache.h" | 17 #include "net/ftp/ftp_auth_cache.h" |
| 18 #include "net/http/http_transaction_test_util.h" | 18 #include "net/http/http_transaction_test_util.h" |
| 19 #include "net/proxy/mock_proxy_resolver.h" | 19 #include "net/proxy/mock_proxy_resolver.h" |
| 20 #include "net/proxy/proxy_config_service.h" | 20 #include "net/proxy/proxy_config_service.h" |
| 21 #include "net/proxy/proxy_config_service_fixed.h" | 21 #include "net/proxy/proxy_config_service_fixed.h" |
| 22 #include "net/proxy/proxy_server.h" | 22 #include "net/proxy/proxy_server.h" |
| 23 #include "net/socket/socket_test_util.h" | 23 #include "net/socket/socket_test_util.h" |
| 24 #include "net/test/gtest_util.h" | 24 #include "net/test/gtest_util.h" |
| 25 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 25 #include "net/url_request/ftp_protocol_handler.h" | 26 #include "net/url_request/ftp_protocol_handler.h" |
| 26 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
| 27 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 28 #include "net/url_request/url_request_job_factory_impl.h" | 29 #include "net/url_request/url_request_job_factory_impl.h" |
| 29 #include "net/url_request/url_request_status.h" | 30 #include "net/url_request/url_request_status.h" |
| 30 #include "net/url_request/url_request_test_util.h" | 31 #include "net/url_request/url_request_test_util.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // Fixture for priority-related tests. Priority matters when there is | 160 // Fixture for priority-related tests. Priority matters when there is |
| 160 // an HTTP proxy. | 161 // an HTTP proxy. |
| 161 class URLRequestFtpJobPriorityTest : public testing::Test { | 162 class URLRequestFtpJobPriorityTest : public testing::Test { |
| 162 protected: | 163 protected: |
| 163 URLRequestFtpJobPriorityTest() | 164 URLRequestFtpJobPriorityTest() |
| 164 : proxy_service_(base::WrapUnique(new SimpleProxyConfigService), | 165 : proxy_service_(base::WrapUnique(new SimpleProxyConfigService), |
| 165 NULL, | 166 NULL, |
| 166 NULL), | 167 NULL), |
| 167 req_(context_.CreateRequest(GURL("ftp://ftp.example.com"), | 168 req_(context_.CreateRequest(GURL("ftp://ftp.example.com"), |
| 168 DEFAULT_PRIORITY, | 169 DEFAULT_PRIORITY, |
| 169 &delegate_)) { | 170 &delegate_, |
| 171 TRAFFIC_ANNOTATION_FOR_TESTS)) { |
| 170 context_.set_proxy_service(&proxy_service_); | 172 context_.set_proxy_service(&proxy_service_); |
| 171 context_.set_http_transaction_factory(&network_layer_); | 173 context_.set_http_transaction_factory(&network_layer_); |
| 172 } | 174 } |
| 173 | 175 |
| 174 ProxyService proxy_service_; | 176 ProxyService proxy_service_; |
| 175 MockNetworkLayer network_layer_; | 177 MockNetworkLayer network_layer_; |
| 176 MockFtpTransactionFactory ftp_factory_; | 178 MockFtpTransactionFactory ftp_factory_; |
| 177 FtpAuthCache ftp_auth_cache_; | 179 FtpAuthCache ftp_auth_cache_; |
| 178 TestURLRequestContext context_; | 180 TestURLRequestContext context_; |
| 179 TestDelegate delegate_; | 181 TestDelegate delegate_; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 MockRead reads[] = { | 297 MockRead reads[] = { |
| 296 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 298 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
| 297 MockRead(ASYNC, 2, "Content-Length: 9\r\n\r\n"), | 299 MockRead(ASYNC, 2, "Content-Length: 9\r\n\r\n"), |
| 298 MockRead(ASYNC, 3, "test.html"), | 300 MockRead(ASYNC, 3, "test.html"), |
| 299 }; | 301 }; |
| 300 | 302 |
| 301 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 303 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
| 302 | 304 |
| 303 TestDelegate request_delegate; | 305 TestDelegate request_delegate; |
| 304 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 306 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 305 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 307 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 308 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 306 url_request->Start(); | 309 url_request->Start(); |
| 307 ASSERT_TRUE(url_request->is_pending()); | 310 ASSERT_TRUE(url_request->is_pending()); |
| 308 | 311 |
| 309 // The TestDelegate will by default quit the message loop on completion. | 312 // The TestDelegate will by default quit the message loop on completion. |
| 310 base::RunLoop().Run(); | 313 base::RunLoop().Run(); |
| 311 | 314 |
| 312 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 315 EXPECT_THAT(request_delegate.request_status(), IsOk()); |
| 313 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, | 316 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 314 HostPortPair::FromString("localhost:80")), | 317 HostPortPair::FromString("localhost:80")), |
| 315 url_request->proxy_server()); | 318 url_request->proxy_server()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 326 MockProxyResolverFactory* resolver_factory = owned_resolver_factory.get(); | 329 MockProxyResolverFactory* resolver_factory = owned_resolver_factory.get(); |
| 327 | 330 |
| 328 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. | 331 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. |
| 329 request_context()->set_proxy_service(base::WrapUnique(new ProxyService( | 332 request_context()->set_proxy_service(base::WrapUnique(new ProxyService( |
| 330 base::WrapUnique(new ProxyConfigServiceFixed( | 333 base::WrapUnique(new ProxyConfigServiceFixed( |
| 331 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo")))), | 334 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo")))), |
| 332 std::move(owned_resolver_factory), nullptr))); | 335 std::move(owned_resolver_factory), nullptr))); |
| 333 | 336 |
| 334 TestDelegate request_delegate; | 337 TestDelegate request_delegate; |
| 335 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 338 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 336 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 339 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 340 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 337 url_request->Start(); | 341 url_request->Start(); |
| 338 | 342 |
| 339 // Verify PAC request is in progress. | 343 // Verify PAC request is in progress. |
| 340 EXPECT_EQ(net::LoadState::LOAD_STATE_RESOLVING_PROXY_FOR_URL, | 344 EXPECT_EQ(net::LoadState::LOAD_STATE_RESOLVING_PROXY_FOR_URL, |
| 341 url_request->GetLoadState().state); | 345 url_request->GetLoadState().state); |
| 342 EXPECT_EQ(1u, resolver_factory->resolver()->pending_jobs().size()); | 346 EXPECT_EQ(1u, resolver_factory->resolver()->pending_jobs().size()); |
| 343 EXPECT_EQ(0u, resolver_factory->resolver()->cancelled_jobs().size()); | 347 EXPECT_EQ(0u, resolver_factory->resolver()->cancelled_jobs().size()); |
| 344 | 348 |
| 345 // Destroying the request should cancel the PAC request. | 349 // Destroying the request should cancel the PAC request. |
| 346 url_request.reset(); | 350 url_request.reset(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 357 MockProxyResolverFactory* resolver_factory = owned_resolver_factory.get(); | 361 MockProxyResolverFactory* resolver_factory = owned_resolver_factory.get(); |
| 358 | 362 |
| 359 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. | 363 // Use a PAC URL so that URLRequestFtpJob's |pac_request_| field is non-NULL. |
| 360 request_context()->set_proxy_service(base::WrapUnique(new ProxyService( | 364 request_context()->set_proxy_service(base::WrapUnique(new ProxyService( |
| 361 base::WrapUnique(new ProxyConfigServiceFixed( | 365 base::WrapUnique(new ProxyConfigServiceFixed( |
| 362 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo")))), | 366 ProxyConfig::CreateFromCustomPacURL(GURL("http://foo")))), |
| 363 std::move(owned_resolver_factory), nullptr))); | 367 std::move(owned_resolver_factory), nullptr))); |
| 364 | 368 |
| 365 TestDelegate request_delegate; | 369 TestDelegate request_delegate; |
| 366 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 370 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 367 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 371 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 372 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 368 | 373 |
| 369 // Verify PAC request is in progress. | 374 // Verify PAC request is in progress. |
| 370 url_request->Start(); | 375 url_request->Start(); |
| 371 EXPECT_EQ(net::LoadState::LOAD_STATE_RESOLVING_PROXY_FOR_URL, | 376 EXPECT_EQ(net::LoadState::LOAD_STATE_RESOLVING_PROXY_FOR_URL, |
| 372 url_request->GetLoadState().state); | 377 url_request->GetLoadState().state); |
| 373 EXPECT_EQ(1u, resolver_factory->resolver()->pending_jobs().size()); | 378 EXPECT_EQ(1u, resolver_factory->resolver()->pending_jobs().size()); |
| 374 EXPECT_EQ(0u, resolver_factory->resolver()->cancelled_jobs().size()); | 379 EXPECT_EQ(0u, resolver_factory->resolver()->cancelled_jobs().size()); |
| 375 | 380 |
| 376 // Cancelling the request should cancel the PAC request. | 381 // Cancelling the request should cancel the PAC request. |
| 377 url_request->Cancel(); | 382 url_request->Cancel(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 392 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " | 397 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic " |
| 393 "realm=\"MyRealm1\"\r\n"), | 398 "realm=\"MyRealm1\"\r\n"), |
| 394 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | 399 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), |
| 395 MockRead(ASYNC, 4, "test.html"), | 400 MockRead(ASYNC, 4, "test.html"), |
| 396 }; | 401 }; |
| 397 | 402 |
| 398 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 403 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
| 399 | 404 |
| 400 TestDelegate request_delegate; | 405 TestDelegate request_delegate; |
| 401 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 406 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 402 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 407 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 408 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 403 url_request->Start(); | 409 url_request->Start(); |
| 404 ASSERT_TRUE(url_request->is_pending()); | 410 ASSERT_TRUE(url_request->is_pending()); |
| 405 | 411 |
| 406 // The TestDelegate will by default quit the message loop on completion. | 412 // The TestDelegate will by default quit the message loop on completion. |
| 407 base::RunLoop().Run(); | 413 base::RunLoop().Run(); |
| 408 | 414 |
| 409 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 415 EXPECT_THAT(request_delegate.request_status(), IsOk()); |
| 410 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, | 416 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 411 HostPortPair::FromString("localhost:80")), | 417 HostPortPair::FromString("localhost:80")), |
| 412 url_request->proxy_server()); | 418 url_request->proxy_server()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 439 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), | 445 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), |
| 440 MockRead(ASYNC, 8, "test2.html"), | 446 MockRead(ASYNC, 8, "test2.html"), |
| 441 }; | 447 }; |
| 442 | 448 |
| 443 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 449 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
| 444 | 450 |
| 445 TestDelegate request_delegate; | 451 TestDelegate request_delegate; |
| 446 request_delegate.set_credentials( | 452 request_delegate.set_credentials( |
| 447 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | 453 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); |
| 448 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 454 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 449 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 455 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 456 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 450 url_request->Start(); | 457 url_request->Start(); |
| 451 ASSERT_TRUE(url_request->is_pending()); | 458 ASSERT_TRUE(url_request->is_pending()); |
| 452 | 459 |
| 453 // The TestDelegate will by default quit the message loop on completion. | 460 // The TestDelegate will by default quit the message loop on completion. |
| 454 base::RunLoop().Run(); | 461 base::RunLoop().Run(); |
| 455 | 462 |
| 456 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 463 EXPECT_THAT(request_delegate.request_status(), IsOk()); |
| 457 EXPECT_EQ(1, network_delegate()->completed_requests()); | 464 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 458 EXPECT_EQ(0, network_delegate()->error_count()); | 465 EXPECT_EQ(0, network_delegate()->error_count()); |
| 459 EXPECT_TRUE(request_delegate.auth_required_called()); | 466 EXPECT_TRUE(request_delegate.auth_required_called()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 472 MockRead(ASYNC, 2, "WWW-Authenticate: Basic " | 479 MockRead(ASYNC, 2, "WWW-Authenticate: Basic " |
| 473 "realm=\"MyRealm1\"\r\n"), | 480 "realm=\"MyRealm1\"\r\n"), |
| 474 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), | 481 MockRead(ASYNC, 3, "Content-Length: 9\r\n\r\n"), |
| 475 MockRead(ASYNC, 4, "test.html"), | 482 MockRead(ASYNC, 4, "test.html"), |
| 476 }; | 483 }; |
| 477 | 484 |
| 478 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 485 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
| 479 | 486 |
| 480 TestDelegate request_delegate; | 487 TestDelegate request_delegate; |
| 481 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 488 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 482 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 489 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 490 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 483 url_request->Start(); | 491 url_request->Start(); |
| 484 ASSERT_TRUE(url_request->is_pending()); | 492 ASSERT_TRUE(url_request->is_pending()); |
| 485 | 493 |
| 486 // The TestDelegate will by default quit the message loop on completion. | 494 // The TestDelegate will by default quit the message loop on completion. |
| 487 base::RunLoop().Run(); | 495 base::RunLoop().Run(); |
| 488 | 496 |
| 489 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 497 EXPECT_THAT(request_delegate.request_status(), IsOk()); |
| 490 EXPECT_EQ(1, network_delegate()->completed_requests()); | 498 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 491 EXPECT_EQ(0, network_delegate()->error_count()); | 499 EXPECT_EQ(0, network_delegate()->error_count()); |
| 492 EXPECT_TRUE(request_delegate.auth_required_called()); | 500 EXPECT_TRUE(request_delegate.auth_required_called()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 516 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), | 524 MockRead(ASYNC, 7, "Content-Length: 10\r\n\r\n"), |
| 517 MockRead(ASYNC, 8, "test2.html"), | 525 MockRead(ASYNC, 8, "test2.html"), |
| 518 }; | 526 }; |
| 519 | 527 |
| 520 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 528 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
| 521 | 529 |
| 522 TestDelegate request_delegate; | 530 TestDelegate request_delegate; |
| 523 request_delegate.set_credentials( | 531 request_delegate.set_credentials( |
| 524 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | 532 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); |
| 525 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 533 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 526 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 534 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 535 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 527 url_request->Start(); | 536 url_request->Start(); |
| 528 ASSERT_TRUE(url_request->is_pending()); | 537 ASSERT_TRUE(url_request->is_pending()); |
| 529 | 538 |
| 530 // The TestDelegate will by default quit the message loop on completion. | 539 // The TestDelegate will by default quit the message loop on completion. |
| 531 base::RunLoop().Run(); | 540 base::RunLoop().Run(); |
| 532 | 541 |
| 533 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 542 EXPECT_THAT(request_delegate.request_status(), IsOk()); |
| 534 EXPECT_EQ(1, network_delegate()->completed_requests()); | 543 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 535 EXPECT_EQ(0, network_delegate()->error_count()); | 544 EXPECT_EQ(0, network_delegate()->error_count()); |
| 536 EXPECT_TRUE(request_delegate.auth_required_called()); | 545 EXPECT_TRUE(request_delegate.auth_required_called()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 590 |
| 582 // Make sure cached FTP credentials are not used for proxy authentication. | 591 // Make sure cached FTP credentials are not used for proxy authentication. |
| 583 request_context()->GetFtpAuthCache()->Add( | 592 request_context()->GetFtpAuthCache()->Add( |
| 584 url.GetOrigin(), | 593 url.GetOrigin(), |
| 585 AuthCredentials(ASCIIToUTF16("userdonotuse"), | 594 AuthCredentials(ASCIIToUTF16("userdonotuse"), |
| 586 ASCIIToUTF16("passworddonotuse"))); | 595 ASCIIToUTF16("passworddonotuse"))); |
| 587 | 596 |
| 588 TestDelegate request_delegate; | 597 TestDelegate request_delegate; |
| 589 request_delegate.set_quit_on_auth_required(true); | 598 request_delegate.set_quit_on_auth_required(true); |
| 590 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 599 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 591 url, DEFAULT_PRIORITY, &request_delegate)); | 600 url, DEFAULT_PRIORITY, &request_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 592 url_request->Start(); | 601 url_request->Start(); |
| 593 ASSERT_TRUE(url_request->is_pending()); | 602 ASSERT_TRUE(url_request->is_pending()); |
| 594 | 603 |
| 595 // Run until proxy auth is requested. | 604 // Run until proxy auth is requested. |
| 596 base::RunLoop().Run(); | 605 base::RunLoop().Run(); |
| 597 | 606 |
| 598 ASSERT_TRUE(request_delegate.auth_required_called()); | 607 ASSERT_TRUE(request_delegate.auth_required_called()); |
| 599 EXPECT_EQ(0, network_delegate()->completed_requests()); | 608 EXPECT_EQ(0, network_delegate()->completed_requests()); |
| 600 EXPECT_EQ(0, network_delegate()->error_count()); | 609 EXPECT_EQ(0, network_delegate()->error_count()); |
| 601 url_request->SetAuth( | 610 url_request->SetAuth( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 629 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 638 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
| 630 MockRead(ASYNC, 2, "Content-Length: 9\r\n"), | 639 MockRead(ASYNC, 2, "Content-Length: 9\r\n"), |
| 631 MockRead(ASYNC, 3, "Set-Cookie: name=value\r\n\r\n"), | 640 MockRead(ASYNC, 3, "Set-Cookie: name=value\r\n\r\n"), |
| 632 MockRead(ASYNC, 4, "test.html"), | 641 MockRead(ASYNC, 4, "test.html"), |
| 633 }; | 642 }; |
| 634 | 643 |
| 635 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 644 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
| 636 | 645 |
| 637 TestDelegate request_delegate; | 646 TestDelegate request_delegate; |
| 638 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 647 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 639 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 648 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 649 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 640 url_request->Start(); | 650 url_request->Start(); |
| 641 ASSERT_TRUE(url_request->is_pending()); | 651 ASSERT_TRUE(url_request->is_pending()); |
| 642 | 652 |
| 643 // The TestDelegate will by default quit the message loop on completion. | 653 // The TestDelegate will by default quit the message loop on completion. |
| 644 base::RunLoop().Run(); | 654 base::RunLoop().Run(); |
| 645 | 655 |
| 646 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 656 EXPECT_THAT(request_delegate.request_status(), IsOk()); |
| 647 EXPECT_EQ(1, network_delegate()->completed_requests()); | 657 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 648 EXPECT_EQ(0, network_delegate()->error_count()); | 658 EXPECT_EQ(0, network_delegate()->error_count()); |
| 649 | 659 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 662 }; | 672 }; |
| 663 MockRead reads[] = { | 673 MockRead reads[] = { |
| 664 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 302 Found\r\n"), | 674 MockRead(SYNCHRONOUS, 1, "HTTP/1.1 302 Found\r\n"), |
| 665 MockRead(ASYNC, 2, "Location: http://other.example.com/\r\n\r\n"), | 675 MockRead(ASYNC, 2, "Location: http://other.example.com/\r\n\r\n"), |
| 666 }; | 676 }; |
| 667 | 677 |
| 668 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 678 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
| 669 | 679 |
| 670 TestDelegate request_delegate; | 680 TestDelegate request_delegate; |
| 671 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 681 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
| 672 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 682 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate, |
| 683 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 673 url_request->Start(); | 684 url_request->Start(); |
| 674 EXPECT_TRUE(url_request->is_pending()); | 685 EXPECT_TRUE(url_request->is_pending()); |
| 675 | 686 |
| 676 // The TestDelegate will by default quit the message loop on completion. | 687 // The TestDelegate will by default quit the message loop on completion. |
| 677 base::RunLoop().Run(); | 688 base::RunLoop().Run(); |
| 678 | 689 |
| 679 EXPECT_EQ(1, network_delegate()->completed_requests()); | 690 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 680 EXPECT_EQ(1, network_delegate()->error_count()); | 691 EXPECT_EQ(1, network_delegate()->error_count()); |
| 681 EXPECT_FALSE(url_request->status().is_success()); | 692 EXPECT_FALSE(url_request->status().is_success()); |
| 682 EXPECT_THAT(url_request->status().error(), IsError(ERR_UNSAFE_REDIRECT)); | 693 EXPECT_THAT(url_request->status().error(), IsError(ERR_UNSAFE_REDIRECT)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 698 MockRead(ASYNC, 3, "test1.html"), | 709 MockRead(ASYNC, 3, "test1.html"), |
| 699 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), | 710 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), |
| 700 MockRead(ASYNC, 6, "Content-Length: 10\r\n\r\n"), | 711 MockRead(ASYNC, 6, "Content-Length: 10\r\n\r\n"), |
| 701 MockRead(ASYNC, 7, "test2.html"), | 712 MockRead(ASYNC, 7, "test2.html"), |
| 702 }; | 713 }; |
| 703 | 714 |
| 704 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); | 715 AddSocket(reads, arraysize(reads), writes, arraysize(writes)); |
| 705 | 716 |
| 706 TestDelegate request_delegate1; | 717 TestDelegate request_delegate1; |
| 707 | 718 |
| 708 std::unique_ptr<URLRequest> url_request1( | 719 std::unique_ptr<URLRequest> url_request1(request_context()->CreateRequest( |
| 709 request_context()->CreateRequest(GURL("ftp://ftp.example.com/first"), | 720 GURL("ftp://ftp.example.com/first"), DEFAULT_PRIORITY, &request_delegate1, |
| 710 DEFAULT_PRIORITY, &request_delegate1)); | 721 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 711 url_request1->Start(); | 722 url_request1->Start(); |
| 712 ASSERT_TRUE(url_request1->is_pending()); | 723 ASSERT_TRUE(url_request1->is_pending()); |
| 713 | 724 |
| 714 // The TestDelegate will by default quit the message loop on completion. | 725 // The TestDelegate will by default quit the message loop on completion. |
| 715 base::RunLoop().Run(); | 726 base::RunLoop().Run(); |
| 716 | 727 |
| 717 EXPECT_TRUE(url_request1->status().is_success()); | 728 EXPECT_TRUE(url_request1->status().is_success()); |
| 718 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, | 729 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 719 HostPortPair::FromString("localhost:80")), | 730 HostPortPair::FromString("localhost:80")), |
| 720 url_request1->proxy_server()); | 731 url_request1->proxy_server()); |
| 721 EXPECT_EQ(1, network_delegate()->completed_requests()); | 732 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 722 EXPECT_EQ(0, network_delegate()->error_count()); | 733 EXPECT_EQ(0, network_delegate()->error_count()); |
| 723 EXPECT_FALSE(request_delegate1.auth_required_called()); | 734 EXPECT_FALSE(request_delegate1.auth_required_called()); |
| 724 EXPECT_EQ("test1.html", request_delegate1.data_received()); | 735 EXPECT_EQ("test1.html", request_delegate1.data_received()); |
| 725 | 736 |
| 726 TestDelegate request_delegate2; | 737 TestDelegate request_delegate2; |
| 727 std::unique_ptr<URLRequest> url_request2( | 738 std::unique_ptr<URLRequest> url_request2(request_context()->CreateRequest( |
| 728 request_context()->CreateRequest(GURL("ftp://ftp.example.com/second"), | 739 GURL("ftp://ftp.example.com/second"), DEFAULT_PRIORITY, |
| 729 DEFAULT_PRIORITY, &request_delegate2)); | 740 &request_delegate2, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 730 url_request2->Start(); | 741 url_request2->Start(); |
| 731 ASSERT_TRUE(url_request2->is_pending()); | 742 ASSERT_TRUE(url_request2->is_pending()); |
| 732 | 743 |
| 733 // The TestDelegate will by default quit the message loop on completion. | 744 // The TestDelegate will by default quit the message loop on completion. |
| 734 base::RunLoop().Run(); | 745 base::RunLoop().Run(); |
| 735 | 746 |
| 736 EXPECT_TRUE(url_request2->status().is_success()); | 747 EXPECT_TRUE(url_request2->status().is_success()); |
| 737 EXPECT_EQ(2, network_delegate()->completed_requests()); | 748 EXPECT_EQ(2, network_delegate()->completed_requests()); |
| 738 EXPECT_EQ(0, network_delegate()->error_count()); | 749 EXPECT_EQ(0, network_delegate()->error_count()); |
| 739 EXPECT_FALSE(request_delegate2.auth_required_called()); | 750 EXPECT_FALSE(request_delegate2.auth_required_called()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 764 MockRead reads2[] = { | 775 MockRead reads2[] = { |
| 765 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), | 776 MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n"), |
| 766 MockRead(ASYNC, 2, "Content-Length: 10\r\n\r\n"), | 777 MockRead(ASYNC, 2, "Content-Length: 10\r\n\r\n"), |
| 767 MockRead(ASYNC, 3, "test2.html"), | 778 MockRead(ASYNC, 3, "test2.html"), |
| 768 }; | 779 }; |
| 769 | 780 |
| 770 AddSocket(reads1, arraysize(reads1), writes1, arraysize(writes1)); | 781 AddSocket(reads1, arraysize(reads1), writes1, arraysize(writes1)); |
| 771 AddSocket(reads2, arraysize(reads2), writes2, arraysize(writes2)); | 782 AddSocket(reads2, arraysize(reads2), writes2, arraysize(writes2)); |
| 772 | 783 |
| 773 TestDelegate request_delegate1; | 784 TestDelegate request_delegate1; |
| 774 std::unique_ptr<URLRequest> url_request1( | 785 std::unique_ptr<URLRequest> url_request1(request_context()->CreateRequest( |
| 775 request_context()->CreateRequest(GURL("ftp://ftp.example.com/first"), | 786 GURL("ftp://ftp.example.com/first"), DEFAULT_PRIORITY, &request_delegate1, |
| 776 DEFAULT_PRIORITY, &request_delegate1)); | 787 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 777 url_request1->Start(); | 788 url_request1->Start(); |
| 778 ASSERT_TRUE(url_request1->is_pending()); | 789 ASSERT_TRUE(url_request1->is_pending()); |
| 779 | 790 |
| 780 // The TestDelegate will by default quit the message loop on completion. | 791 // The TestDelegate will by default quit the message loop on completion. |
| 781 base::RunLoop().Run(); | 792 base::RunLoop().Run(); |
| 782 | 793 |
| 783 EXPECT_TRUE(url_request1->status().is_success()); | 794 EXPECT_TRUE(url_request1->status().is_success()); |
| 784 EXPECT_EQ(1, network_delegate()->completed_requests()); | 795 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 785 EXPECT_EQ(0, network_delegate()->error_count()); | 796 EXPECT_EQ(0, network_delegate()->error_count()); |
| 786 EXPECT_FALSE(request_delegate1.auth_required_called()); | 797 EXPECT_FALSE(request_delegate1.auth_required_called()); |
| 787 EXPECT_EQ("test1.html", request_delegate1.data_received()); | 798 EXPECT_EQ("test1.html", request_delegate1.data_received()); |
| 788 | 799 |
| 789 TestDelegate request_delegate2; | 800 TestDelegate request_delegate2; |
| 790 std::unique_ptr<URLRequest> url_request2( | 801 std::unique_ptr<URLRequest> url_request2(request_context()->CreateRequest( |
| 791 request_context()->CreateRequest(GURL("http://ftp.example.com/second"), | 802 GURL("http://ftp.example.com/second"), DEFAULT_PRIORITY, |
| 792 DEFAULT_PRIORITY, &request_delegate2)); | 803 &request_delegate2, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 793 url_request2->Start(); | 804 url_request2->Start(); |
| 794 ASSERT_TRUE(url_request2->is_pending()); | 805 ASSERT_TRUE(url_request2->is_pending()); |
| 795 | 806 |
| 796 // The TestDelegate will by default quit the message loop on completion. | 807 // The TestDelegate will by default quit the message loop on completion. |
| 797 base::RunLoop().Run(); | 808 base::RunLoop().Run(); |
| 798 | 809 |
| 799 EXPECT_TRUE(url_request2->status().is_success()); | 810 EXPECT_TRUE(url_request2->status().is_success()); |
| 800 EXPECT_EQ(2, network_delegate()->completed_requests()); | 811 EXPECT_EQ(2, network_delegate()->completed_requests()); |
| 801 EXPECT_EQ(0, network_delegate()->error_count()); | 812 EXPECT_EQ(0, network_delegate()->error_count()); |
| 802 EXPECT_FALSE(request_delegate2.auth_required_called()); | 813 EXPECT_FALSE(request_delegate2.auth_required_called()); |
| 803 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 814 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
| 804 } | 815 } |
| 805 | 816 |
| 806 } // namespace | 817 } // namespace |
| 807 | 818 |
| 808 } // namespace net | 819 } // namespace net |
| OLD | NEW |