OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif | 10 #endif |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 198 |
199 private: | 199 private: |
200 mutable URLRequestJob* main_intercept_job_; | 200 mutable URLRequestJob* main_intercept_job_; |
201 }; | 201 }; |
202 | 202 |
203 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 203 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
204 class URLRequestTest : public PlatformTest { | 204 class URLRequestTest : public PlatformTest { |
205 public: | 205 public: |
206 URLRequestTest() : default_context_(new TestURLRequestContext(true)) { | 206 URLRequestTest() : default_context_(new TestURLRequestContext(true)) { |
207 default_context_->set_network_delegate(&default_network_delegate_); | 207 default_context_->set_network_delegate(&default_network_delegate_); |
| 208 default_context_->set_http_server_properties(NULL); |
208 default_context_->Init(); | 209 default_context_->Init(); |
209 } | 210 } |
210 | 211 |
211 static void SetUpTestCase() { | 212 static void SetUpTestCase() { |
212 URLRequest::AllowFileAccess(); | 213 URLRequest::AllowFileAccess(); |
213 } | 214 } |
214 | 215 |
215 // Adds the TestJobInterceptor to the default context. | 216 // Adds the TestJobInterceptor to the default context. |
216 TestJobInterceptor* AddTestInterceptor() { | 217 TestJobInterceptor* AddTestInterceptor() { |
217 TestJobInterceptor* interceptor = new TestJobInterceptor(); | 218 TestJobInterceptor* interceptor = new TestJobInterceptor(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // issuing a CONNECT request with the magic host name "www.redirect.com". | 309 // issuing a CONNECT request with the magic host name "www.redirect.com". |
309 // The HTTPTestServer will return a 302 response, which we should not | 310 // The HTTPTestServer will return a 302 response, which we should not |
310 // follow. | 311 // follow. |
311 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 312 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
312 ASSERT_TRUE(test_server_.Start()); | 313 ASSERT_TRUE(test_server_.Start()); |
313 | 314 |
314 TestNetworkDelegate network_delegate; // must outlive URLRequest | 315 TestNetworkDelegate network_delegate; // must outlive URLRequest |
315 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 316 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
316 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 317 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
317 context->set_network_delegate(&network_delegate); | 318 context->set_network_delegate(&network_delegate); |
| 319 context->set_http_server_properties(NULL); |
318 context->Init(); | 320 context->Init(); |
319 | 321 |
320 TestDelegate d; | 322 TestDelegate d; |
321 { | 323 { |
322 URLRequest r(GURL("https://www.redirect.com/"), &d); | 324 URLRequest r(GURL("https://www.redirect.com/"), &d); |
323 r.set_context(context); | 325 r.set_context(context); |
324 r.Start(); | 326 r.Start(); |
325 EXPECT_TRUE(r.is_pending()); | 327 EXPECT_TRUE(r.is_pending()); |
326 | 328 |
327 MessageLoop::current()->Run(); | 329 MessageLoop::current()->Run(); |
328 | 330 |
329 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 331 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
330 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 332 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
331 EXPECT_EQ(1, d.response_started_count()); | 333 EXPECT_EQ(1, d.response_started_count()); |
332 // We should not have followed the redirect. | 334 // We should not have followed the redirect. |
333 EXPECT_EQ(0, d.received_redirect_count()); | 335 EXPECT_EQ(0, d.received_redirect_count()); |
334 } | 336 } |
335 } | 337 } |
336 | 338 |
337 // This is the same as the previous test, but checks that the network delegate | 339 // This is the same as the previous test, but checks that the network delegate |
338 // registers the error. | 340 // registers the error. |
339 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 341 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
340 ASSERT_TRUE(test_server_.Start()); | 342 ASSERT_TRUE(test_server_.Start()); |
341 | 343 |
342 TestNetworkDelegate network_delegate; // must outlive URLRequest | 344 TestNetworkDelegate network_delegate; // must outlive URLRequest |
343 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 345 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
344 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 346 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
345 context->set_network_delegate(&network_delegate); | 347 context->set_network_delegate(&network_delegate); |
| 348 context->set_http_server_properties(NULL); |
346 context->Init(); | 349 context->Init(); |
347 | 350 |
348 TestDelegate d; | 351 TestDelegate d; |
349 { | 352 { |
350 URLRequest r(GURL("https://www.redirect.com/"), &d); | 353 URLRequest r(GURL("https://www.redirect.com/"), &d); |
351 r.set_context(context); | 354 r.set_context(context); |
352 r.Start(); | 355 r.Start(); |
353 EXPECT_TRUE(r.is_pending()); | 356 EXPECT_TRUE(r.is_pending()); |
354 | 357 |
355 MessageLoop::current()->Run(); | 358 MessageLoop::current()->Run(); |
(...skipping 13 matching lines...) Expand all Loading... |
369 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { | 372 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { |
370 ASSERT_TRUE(test_server_.Start()); | 373 ASSERT_TRUE(test_server_.Start()); |
371 | 374 |
372 TestDelegate d; | 375 TestDelegate d; |
373 BlockingNetworkDelegate network_delegate; | 376 BlockingNetworkDelegate network_delegate; |
374 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); | 377 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); |
375 | 378 |
376 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 379 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
377 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 380 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
378 context->set_network_delegate(&network_delegate); | 381 context->set_network_delegate(&network_delegate); |
| 382 context->set_http_server_properties(NULL); |
379 context->Init(); | 383 context->Init(); |
380 | 384 |
381 { | 385 { |
382 TestURLRequest r(test_server_.GetURL(""), &d); | 386 TestURLRequest r(test_server_.GetURL(""), &d); |
383 r.set_context(context); | 387 r.set_context(context); |
384 | 388 |
385 r.Start(); | 389 r.Start(); |
386 MessageLoop::current()->Run(); | 390 MessageLoop::current()->Run(); |
387 | 391 |
388 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 392 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
389 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 393 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
390 EXPECT_EQ(1, network_delegate.created_requests()); | 394 EXPECT_EQ(1, network_delegate.created_requests()); |
391 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 395 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
392 } | 396 } |
393 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 397 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
394 } | 398 } |
395 | 399 |
396 // Tests that the network delegate can cancel a request synchronously. | 400 // Tests that the network delegate can cancel a request synchronously. |
397 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { | 401 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { |
398 ASSERT_TRUE(test_server_.Start()); | 402 ASSERT_TRUE(test_server_.Start()); |
399 | 403 |
400 TestDelegate d; | 404 TestDelegate d; |
401 BlockingNetworkDelegate network_delegate; | 405 BlockingNetworkDelegate network_delegate; |
402 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 406 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
403 | 407 |
404 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 408 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
405 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 409 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
406 context->set_network_delegate(&network_delegate); | 410 context->set_network_delegate(&network_delegate); |
| 411 context->set_http_server_properties(NULL); |
407 context->Init(); | 412 context->Init(); |
408 | 413 |
409 { | 414 { |
410 TestURLRequest r(test_server_.GetURL(""), &d); | 415 TestURLRequest r(test_server_.GetURL(""), &d); |
411 r.set_context(context); | 416 r.set_context(context); |
412 | 417 |
413 r.Start(); | 418 r.Start(); |
414 MessageLoop::current()->Run(); | 419 MessageLoop::current()->Run(); |
415 | 420 |
416 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 421 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
(...skipping 10 matching lines...) Expand all Loading... |
427 ASSERT_TRUE(test_server_.Start()); | 432 ASSERT_TRUE(test_server_.Start()); |
428 | 433 |
429 TestDelegate d; | 434 TestDelegate d; |
430 BlockingNetworkDelegate network_delegate; | 435 BlockingNetworkDelegate network_delegate; |
431 GURL redirect_url(test_server_.GetURL("simple.html")); | 436 GURL redirect_url(test_server_.GetURL("simple.html")); |
432 network_delegate.set_redirect_url(redirect_url); | 437 network_delegate.set_redirect_url(redirect_url); |
433 | 438 |
434 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 439 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
435 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 440 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
436 context->set_network_delegate(&network_delegate); | 441 context->set_network_delegate(&network_delegate); |
| 442 context->set_http_server_properties(NULL); |
437 context->Init(); | 443 context->Init(); |
438 | 444 |
439 { | 445 { |
440 GURL original_url(test_server_.GetURL("empty.html")); | 446 GURL original_url(test_server_.GetURL("empty.html")); |
441 TestURLRequest r(original_url, &d); | 447 TestURLRequest r(original_url, &d); |
442 r.set_context(context); | 448 r.set_context(context); |
443 | 449 |
444 r.Start(); | 450 r.Start(); |
445 MessageLoop::current()->Run(); | 451 MessageLoop::current()->Run(); |
446 | 452 |
(...skipping 14 matching lines...) Expand all Loading... |
461 | 467 |
462 const char kData[] = "hello world"; | 468 const char kData[] = "hello world"; |
463 | 469 |
464 TestDelegate d; | 470 TestDelegate d; |
465 BlockingNetworkDelegate network_delegate; | 471 BlockingNetworkDelegate network_delegate; |
466 GURL redirect_url(test_server_.GetURL("echo")); | 472 GURL redirect_url(test_server_.GetURL("echo")); |
467 network_delegate.set_redirect_url(redirect_url); | 473 network_delegate.set_redirect_url(redirect_url); |
468 | 474 |
469 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 475 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
470 context->set_network_delegate(&network_delegate); | 476 context->set_network_delegate(&network_delegate); |
| 477 context->set_http_server_properties(NULL); |
471 context->Init(); | 478 context->Init(); |
472 | 479 |
473 { | 480 { |
474 GURL original_url(test_server_.GetURL("empty.html")); | 481 GURL original_url(test_server_.GetURL("empty.html")); |
475 TestURLRequest r(original_url, &d); | 482 TestURLRequest r(original_url, &d); |
476 r.set_context(context); | 483 r.set_context(context); |
477 r.set_method("POST"); | 484 r.set_method("POST"); |
478 r.set_upload(CreateSimpleUploadData(kData).get()); | 485 r.set_upload(CreateSimpleUploadData(kData).get()); |
479 HttpRequestHeaders headers; | 486 HttpRequestHeaders headers; |
480 headers.SetHeader(HttpRequestHeaders::kContentLength, | 487 headers.SetHeader(HttpRequestHeaders::kContentLength, |
(...skipping 19 matching lines...) Expand all Loading... |
500 // In this unit test, we're using the HTTPTestServer as a proxy server and | 507 // In this unit test, we're using the HTTPTestServer as a proxy server and |
501 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 508 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
502 // The HTTPTestServer will return a 401 response, which we should balk at. | 509 // The HTTPTestServer will return a 401 response, which we should balk at. |
503 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 510 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
504 ASSERT_TRUE(test_server_.Start()); | 511 ASSERT_TRUE(test_server_.Start()); |
505 | 512 |
506 TestNetworkDelegate network_delegate; // must outlive URLRequest | 513 TestNetworkDelegate network_delegate; // must outlive URLRequest |
507 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 514 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
508 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 515 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
509 context->set_network_delegate(&network_delegate); | 516 context->set_network_delegate(&network_delegate); |
| 517 context->set_http_server_properties(NULL); |
510 context->Init(); | 518 context->Init(); |
511 | 519 |
512 TestDelegate d; | 520 TestDelegate d; |
513 { | 521 { |
514 URLRequest r(GURL("https://www.server-auth.com/"), &d); | 522 URLRequest r(GURL("https://www.server-auth.com/"), &d); |
515 r.set_context(context); | 523 r.set_context(context); |
516 | 524 |
517 r.Start(); | 525 r.Start(); |
518 EXPECT_TRUE(r.is_pending()); | 526 EXPECT_TRUE(r.is_pending()); |
519 | 527 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 TestDelegate d; | 601 TestDelegate d; |
594 { | 602 { |
595 std::string test_file = | 603 std::string test_file = |
596 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", | 604 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", |
597 test_parameters[i]); | 605 test_parameters[i]); |
598 | 606 |
599 TestNetworkDelegate network_delegate; // must outlive URLRequest | 607 TestNetworkDelegate network_delegate; // must outlive URLRequest |
600 scoped_refptr<TestURLRequestContext> context( | 608 scoped_refptr<TestURLRequestContext> context( |
601 new TestURLRequestContext(true)); | 609 new TestURLRequestContext(true)); |
602 context->set_network_delegate(&network_delegate); | 610 context->set_network_delegate(&network_delegate); |
| 611 context->set_http_server_properties(NULL); |
603 context->Init(); | 612 context->Init(); |
604 | 613 |
605 TestURLRequest r(test_server_.GetURL(test_file), &d); | 614 TestURLRequest r(test_server_.GetURL(test_file), &d); |
606 r.set_context(context); | 615 r.set_context(context); |
607 r.Start(); | 616 r.Start(); |
608 EXPECT_TRUE(r.is_pending()); | 617 EXPECT_TRUE(r.is_pending()); |
609 | 618 |
610 MessageLoop::current()->Run(); | 619 MessageLoop::current()->Run(); |
611 | 620 |
612 EXPECT_EQ(1, d.response_started_count()); | 621 EXPECT_EQ(1, d.response_started_count()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 ASSERT_EQ(3U, req.url_chain().size()); | 681 ASSERT_EQ(3U, req.url_chain().size()); |
673 EXPECT_EQ(original_url, req.url_chain()[0]); | 682 EXPECT_EQ(original_url, req.url_chain()[0]); |
674 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); | 683 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); |
675 EXPECT_EQ(destination_url, req.url_chain()[2]); | 684 EXPECT_EQ(destination_url, req.url_chain()[2]); |
676 } | 685 } |
677 | 686 |
678 class HTTPSRequestTest : public testing::Test { | 687 class HTTPSRequestTest : public testing::Test { |
679 public: | 688 public: |
680 HTTPSRequestTest() : default_context_(new TestURLRequestContext(true)) { | 689 HTTPSRequestTest() : default_context_(new TestURLRequestContext(true)) { |
681 default_context_->set_network_delegate(&default_network_delegate_); | 690 default_context_->set_network_delegate(&default_network_delegate_); |
| 691 default_context_->set_http_server_properties(NULL); |
682 default_context_->Init(); | 692 default_context_->Init(); |
683 } | 693 } |
684 virtual ~HTTPSRequestTest() {} | 694 virtual ~HTTPSRequestTest() {} |
685 | 695 |
686 protected: | 696 protected: |
687 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest | 697 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest |
688 scoped_refptr<TestURLRequestContext> default_context_; | 698 scoped_refptr<TestURLRequestContext> default_context_; |
689 }; | 699 }; |
690 | 700 |
691 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 701 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 GURL url_requiring_auth = | 1704 GURL url_requiring_auth = |
1695 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); | 1705 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); |
1696 | 1706 |
1697 // Request a page that will give a 401 containing a Set-Cookie header. | 1707 // Request a page that will give a 401 containing a Set-Cookie header. |
1698 // Verify that when the transaction is restarted, it includes the new cookie. | 1708 // Verify that when the transaction is restarted, it includes the new cookie. |
1699 { | 1709 { |
1700 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1710 TestNetworkDelegate network_delegate; // must outlive URLRequest |
1701 scoped_refptr<TestURLRequestContext> context( | 1711 scoped_refptr<TestURLRequestContext> context( |
1702 new TestURLRequestContext(true)); | 1712 new TestURLRequestContext(true)); |
1703 context->set_network_delegate(&network_delegate); | 1713 context->set_network_delegate(&network_delegate); |
| 1714 context->set_http_server_properties(NULL); |
1704 context->Init(); | 1715 context->Init(); |
1705 | 1716 |
1706 TestDelegate d; | 1717 TestDelegate d; |
1707 d.set_username(kUser); | 1718 d.set_username(kUser); |
1708 d.set_password(kSecret); | 1719 d.set_password(kSecret); |
1709 | 1720 |
1710 URLRequest r(url_requiring_auth, &d); | 1721 URLRequest r(url_requiring_auth, &d); |
1711 r.set_context(context); | 1722 r.set_context(context); |
1712 r.Start(); | 1723 r.Start(); |
1713 | 1724 |
1714 MessageLoop::current()->Run(); | 1725 MessageLoop::current()->Run(); |
1715 | 1726 |
1716 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1727 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
1717 | 1728 |
1718 // Make sure we sent the cookie in the restarted transaction. | 1729 // Make sure we sent the cookie in the restarted transaction. |
1719 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1730 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
1720 != std::string::npos); | 1731 != std::string::npos); |
1721 } | 1732 } |
1722 | 1733 |
1723 // Same test as above, except this time the restart is initiated earlier | 1734 // Same test as above, except this time the restart is initiated earlier |
1724 // (without user intervention since identity is embedded in the URL). | 1735 // (without user intervention since identity is embedded in the URL). |
1725 { | 1736 { |
1726 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1737 TestNetworkDelegate network_delegate; // must outlive URLRequest |
1727 scoped_refptr<TestURLRequestContext> context( | 1738 scoped_refptr<TestURLRequestContext> context( |
1728 new TestURLRequestContext(true)); | 1739 new TestURLRequestContext(true)); |
1729 context->set_network_delegate(&network_delegate); | 1740 context->set_network_delegate(&network_delegate); |
| 1741 context->set_http_server_properties(NULL); |
1730 context->Init(); | 1742 context->Init(); |
1731 | 1743 |
1732 TestDelegate d; | 1744 TestDelegate d; |
1733 | 1745 |
1734 GURL::Replacements replacements; | 1746 GURL::Replacements replacements; |
1735 std::string username("user2"); | 1747 std::string username("user2"); |
1736 std::string password("secret"); | 1748 std::string password("secret"); |
1737 replacements.SetUsernameStr(username); | 1749 replacements.SetUsernameStr(username); |
1738 replacements.SetPasswordStr(password); | 1750 replacements.SetPasswordStr(password); |
1739 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 1751 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2732 | 2744 |
2733 // Check that a failure to connect to the proxy is reported to the network | 2745 // Check that a failure to connect to the proxy is reported to the network |
2734 // delegate. | 2746 // delegate. |
2735 TEST_F(URLRequestTest, NetworkDelegateProxyError) { | 2747 TEST_F(URLRequestTest, NetworkDelegateProxyError) { |
2736 MockHostResolver host_resolver; | 2748 MockHostResolver host_resolver; |
2737 host_resolver.rules()->AddSimulatedFailure("*"); | 2749 host_resolver.rules()->AddSimulatedFailure("*"); |
2738 | 2750 |
2739 TestNetworkDelegate network_delegate; // must outlive URLRequests | 2751 TestNetworkDelegate network_delegate; // must outlive URLRequests |
2740 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 2752 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
2741 context->set_network_delegate(&network_delegate); | 2753 context->set_network_delegate(&network_delegate); |
| 2754 context->set_http_server_properties(NULL); |
2742 context->SetProxyFromString("myproxy:70"); | 2755 context->SetProxyFromString("myproxy:70"); |
2743 context->set_host_resolver(&host_resolver); | 2756 context->set_host_resolver(&host_resolver); |
2744 context->Init(); | 2757 context->Init(); |
2745 | 2758 |
2746 TestDelegate d; | 2759 TestDelegate d; |
2747 TestURLRequest req(GURL("http://example.com"), &d); | 2760 TestURLRequest req(GURL("http://example.com"), &d); |
2748 req.set_context(context); | 2761 req.set_context(context); |
2749 req.set_method("GET"); | 2762 req.set_method("GET"); |
2750 | 2763 |
2751 req.Start(); | 2764 req.Start(); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3148 } | 3161 } |
3149 } | 3162 } |
3150 | 3163 |
3151 // Check that default A-L header is sent. | 3164 // Check that default A-L header is sent. |
3152 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 3165 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
3153 ASSERT_TRUE(test_server_.Start()); | 3166 ASSERT_TRUE(test_server_.Start()); |
3154 | 3167 |
3155 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3168 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3156 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3169 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3157 context->set_network_delegate(&network_delegate); | 3170 context->set_network_delegate(&network_delegate); |
| 3171 context->set_http_server_properties(NULL); |
3158 context->set_accept_language("en"); | 3172 context->set_accept_language("en"); |
3159 context->Init(); | 3173 context->Init(); |
3160 | 3174 |
3161 TestDelegate d; | 3175 TestDelegate d; |
3162 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 3176 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); |
3163 req.set_context(context); | 3177 req.set_context(context); |
3164 req.Start(); | 3178 req.Start(); |
3165 MessageLoop::current()->Run(); | 3179 MessageLoop::current()->Run(); |
3166 EXPECT_EQ("en", d.data_received()); | 3180 EXPECT_EQ("en", d.data_received()); |
3167 } | 3181 } |
3168 | 3182 |
3169 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 3183 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
3170 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 3184 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
3171 ASSERT_TRUE(test_server_.Start()); | 3185 ASSERT_TRUE(test_server_.Start()); |
3172 | 3186 |
3173 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3187 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3174 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3188 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3175 context->set_network_delegate(&network_delegate); | 3189 context->set_network_delegate(&network_delegate); |
| 3190 context->set_http_server_properties(NULL); |
3176 context->Init(); | 3191 context->Init(); |
3177 // We override the language after initialization because empty entries | 3192 // We override the language after initialization because empty entries |
3178 // get overridden by Init(). | 3193 // get overridden by Init(). |
3179 context->set_accept_language(""); | 3194 context->set_accept_language(""); |
3180 | 3195 |
3181 TestDelegate d; | 3196 TestDelegate d; |
3182 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 3197 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); |
3183 req.set_context(context); | 3198 req.set_context(context); |
3184 req.Start(); | 3199 req.Start(); |
3185 MessageLoop::current()->Run(); | 3200 MessageLoop::current()->Run(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3233 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 3248 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
3234 } | 3249 } |
3235 | 3250 |
3236 // Check that default A-C header is sent. | 3251 // Check that default A-C header is sent. |
3237 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { | 3252 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { |
3238 ASSERT_TRUE(test_server_.Start()); | 3253 ASSERT_TRUE(test_server_.Start()); |
3239 | 3254 |
3240 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3255 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3241 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3256 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3242 context->set_network_delegate(&network_delegate); | 3257 context->set_network_delegate(&network_delegate); |
| 3258 context->set_http_server_properties(NULL); |
3243 context->set_accept_charset("en"); | 3259 context->set_accept_charset("en"); |
3244 context->Init(); | 3260 context->Init(); |
3245 | 3261 |
3246 TestDelegate d; | 3262 TestDelegate d; |
3247 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 3263 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); |
3248 req.set_context(context); | 3264 req.set_context(context); |
3249 req.Start(); | 3265 req.Start(); |
3250 MessageLoop::current()->Run(); | 3266 MessageLoop::current()->Run(); |
3251 EXPECT_EQ("en", d.data_received()); | 3267 EXPECT_EQ("en", d.data_received()); |
3252 } | 3268 } |
3253 | 3269 |
3254 // Check that an empty A-C header is not sent. http://crbug.com/77365. | 3270 // Check that an empty A-C header is not sent. http://crbug.com/77365. |
3255 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { | 3271 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { |
3256 ASSERT_TRUE(test_server_.Start()); | 3272 ASSERT_TRUE(test_server_.Start()); |
3257 | 3273 |
3258 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3274 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3259 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3275 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3260 context->set_network_delegate(&network_delegate); | 3276 context->set_network_delegate(&network_delegate); |
| 3277 context->set_http_server_properties(NULL); |
3261 context->Init(); | 3278 context->Init(); |
3262 // We override the accepted charset after initialization because empty | 3279 // We override the accepted charset after initialization because empty |
3263 // entries get overridden otherwise. | 3280 // entries get overridden otherwise. |
3264 context->set_accept_charset(""); | 3281 context->set_accept_charset(""); |
3265 | 3282 |
3266 TestDelegate d; | 3283 TestDelegate d; |
3267 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 3284 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); |
3268 req.set_context(context); | 3285 req.set_context(context); |
3269 req.Start(); | 3286 req.Start(); |
3270 MessageLoop::current()->Run(); | 3287 MessageLoop::current()->Run(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3312 req.SetExtraRequestHeaders(headers); | 3329 req.SetExtraRequestHeaders(headers); |
3313 req.Start(); | 3330 req.Start(); |
3314 MessageLoop::current()->Run(); | 3331 MessageLoop::current()->Run(); |
3315 // If the net tests are being run with ChromeFrame then we need to allow for | 3332 // If the net tests are being run with ChromeFrame then we need to allow for |
3316 // the 'chromeframe' suffix which is added to the user agent before the | 3333 // the 'chromeframe' suffix which is added to the user agent before the |
3317 // closing parentheses. | 3334 // closing parentheses. |
3318 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3335 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
3319 } | 3336 } |
3320 | 3337 |
3321 } // namespace net | 3338 } // namespace net |
OLD | NEW |