Chromium Code Reviews| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 #include "net/http/http_cache.h" | 46 #include "net/http/http_cache.h" |
| 47 #include "net/http/http_network_layer.h" | 47 #include "net/http/http_network_layer.h" |
| 48 #include "net/http/http_network_session.h" | 48 #include "net/http/http_network_session.h" |
| 49 #include "net/http/http_request_headers.h" | 49 #include "net/http/http_request_headers.h" |
| 50 #include "net/http/http_response_headers.h" | 50 #include "net/http/http_response_headers.h" |
| 51 #include "net/ocsp/nss_ocsp.h" | 51 #include "net/ocsp/nss_ocsp.h" |
| 52 #include "net/proxy/proxy_service.h" | 52 #include "net/proxy/proxy_service.h" |
| 53 #include "net/socket/ssl_client_socket.h" | 53 #include "net/socket/ssl_client_socket.h" |
| 54 #include "net/test/test_server.h" | 54 #include "net/test/test_server.h" |
| 55 #include "net/url_request/ftp_protocol_handler.h" | 55 #include "net/url_request/ftp_protocol_handler.h" |
| 56 #include "net/url_request/static_http_user_agent_settings.h" | |
| 56 #include "net/url_request/url_request.h" | 57 #include "net/url_request/url_request.h" |
| 57 #include "net/url_request/url_request_file_dir_job.h" | 58 #include "net/url_request/url_request_file_dir_job.h" |
| 58 #include "net/url_request/url_request_http_job.h" | 59 #include "net/url_request/url_request_http_job.h" |
| 59 #include "net/url_request/url_request_job_factory_impl.h" | 60 #include "net/url_request/url_request_job_factory_impl.h" |
| 60 #include "net/url_request/url_request_redirect_job.h" | 61 #include "net/url_request/url_request_redirect_job.h" |
| 61 #include "net/url_request/url_request_test_job.h" | 62 #include "net/url_request/url_request_test_job.h" |
| 62 #include "net/url_request/url_request_test_util.h" | 63 #include "net/url_request/url_request_test_util.h" |
| 63 #include "testing/gtest/include/gtest/gtest.h" | 64 #include "testing/gtest/include/gtest/gtest.h" |
| 64 #include "testing/platform_test.h" | 65 #include "testing/platform_test.h" |
| 65 | 66 |
| (...skipping 3404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3470 req.Start(); | 3471 req.Start(); |
| 3471 MessageLoop::current()->Run(); | 3472 MessageLoop::current()->Run(); |
| 3472 EXPECT_EQ("POST", req.method()); | 3473 EXPECT_EQ("POST", req.method()); |
| 3473 EXPECT_EQ(kData, d.data_received()); | 3474 EXPECT_EQ(kData, d.data_received()); |
| 3474 } | 3475 } |
| 3475 | 3476 |
| 3476 // Check that default A-L header is sent. | 3477 // Check that default A-L header is sent. |
| 3477 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 3478 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
| 3478 ASSERT_TRUE(test_server_.Start()); | 3479 ASSERT_TRUE(test_server_.Start()); |
| 3479 | 3480 |
| 3481 StaticHttpUserAgentSettings settings("en", EmptyString(), EmptyString()); | |
| 3480 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3482 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 3481 TestURLRequestContext context(true); | 3483 TestURLRequestContext context(true); |
| 3482 context.set_network_delegate(&network_delegate); | 3484 context.set_network_delegate(&network_delegate); |
| 3483 context.set_accept_language("en"); | 3485 context.set_http_user_agent_settings(&settings); |
| 3484 context.Init(); | 3486 context.Init(); |
| 3485 | 3487 |
| 3486 TestDelegate d; | 3488 TestDelegate d; |
| 3487 URLRequest req( | 3489 URLRequest req( |
| 3488 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); | 3490 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); |
| 3489 req.Start(); | 3491 req.Start(); |
| 3490 MessageLoop::current()->Run(); | 3492 MessageLoop::current()->Run(); |
| 3491 EXPECT_EQ("en", d.data_received()); | 3493 EXPECT_EQ("en", d.data_received()); |
| 3492 } | 3494 } |
| 3493 | 3495 |
| 3494 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 3496 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
| 3495 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 3497 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
| 3496 ASSERT_TRUE(test_server_.Start()); | 3498 ASSERT_TRUE(test_server_.Start()); |
| 3497 | 3499 |
| 3500 StaticHttpUserAgentSettings settings("", EmptyString(), EmptyString()); | |
|
mmenke
2012/10/25 18:06:33
Shouldn't "" just be EmptyString()? Suppose using
| |
| 3498 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3501 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 3499 TestURLRequestContext context(true); | 3502 TestURLRequestContext context(true); |
| 3500 context.set_network_delegate(&network_delegate); | 3503 context.set_network_delegate(&network_delegate); |
| 3501 context.Init(); | 3504 context.Init(); |
| 3502 // We override the language after initialization because empty entries | 3505 // We override the language after initialization because empty entries |
| 3503 // get overridden by Init(). | 3506 // get overridden by Init(). |
| 3504 context.set_accept_language(""); | 3507 context.set_http_user_agent_settings(&settings); |
| 3505 | 3508 |
| 3506 TestDelegate d; | 3509 TestDelegate d; |
| 3507 URLRequest req( | 3510 URLRequest req( |
| 3508 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); | 3511 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); |
| 3509 req.Start(); | 3512 req.Start(); |
| 3510 MessageLoop::current()->Run(); | 3513 MessageLoop::current()->Run(); |
| 3511 EXPECT_EQ("None", d.data_received()); | 3514 EXPECT_EQ("None", d.data_received()); |
| 3512 } | 3515 } |
| 3513 | 3516 |
| 3514 // Check that if request overrides the A-L header, the default is not appended. | 3517 // Check that if request overrides the A-L header, the default is not appended. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3558 req.Start(); | 3561 req.Start(); |
| 3559 MessageLoop::current()->Run(); | 3562 MessageLoop::current()->Run(); |
| 3560 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); | 3563 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); |
| 3561 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 3564 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
| 3562 } | 3565 } |
| 3563 | 3566 |
| 3564 // Check that default A-C header is sent. | 3567 // Check that default A-C header is sent. |
| 3565 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { | 3568 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { |
| 3566 ASSERT_TRUE(test_server_.Start()); | 3569 ASSERT_TRUE(test_server_.Start()); |
| 3567 | 3570 |
| 3571 StaticHttpUserAgentSettings settings(EmptyString(), "en", EmptyString()); | |
| 3568 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3572 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 3569 TestURLRequestContext context(true); | 3573 TestURLRequestContext context(true); |
| 3570 context.set_network_delegate(&network_delegate); | 3574 context.set_network_delegate(&network_delegate); |
| 3571 context.set_accept_charset("en"); | 3575 context.set_http_user_agent_settings(&settings); |
| 3572 context.Init(); | 3576 context.Init(); |
| 3573 | 3577 |
| 3574 TestDelegate d; | 3578 TestDelegate d; |
| 3575 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), | 3579 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
| 3576 &d, | 3580 &d, |
| 3577 &context); | 3581 &context); |
| 3578 req.Start(); | 3582 req.Start(); |
| 3579 MessageLoop::current()->Run(); | 3583 MessageLoop::current()->Run(); |
| 3580 EXPECT_EQ("en", d.data_received()); | 3584 EXPECT_EQ("en", d.data_received()); |
| 3581 } | 3585 } |
| 3582 | 3586 |
| 3583 // Check that an empty A-C header is not sent. http://crbug.com/77365. | 3587 // Check that an empty A-C header is not sent. http://crbug.com/77365. |
| 3584 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { | 3588 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { |
| 3585 ASSERT_TRUE(test_server_.Start()); | 3589 ASSERT_TRUE(test_server_.Start()); |
| 3586 | 3590 |
| 3591 StaticHttpUserAgentSettings settings(EmptyString(), "", EmptyString()); | |
| 3587 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3592 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 3588 TestURLRequestContext context(true); | 3593 TestURLRequestContext context(true); |
| 3589 context.set_network_delegate(&network_delegate); | 3594 context.set_network_delegate(&network_delegate); |
| 3590 context.Init(); | 3595 context.Init(); |
| 3591 // We override the accepted charset after initialization because empty | 3596 // We override the accepted charset after initialization because empty |
| 3592 // entries get overridden otherwise. | 3597 // entries get overridden otherwise. |
| 3593 context.set_accept_charset(""); | 3598 context.set_http_user_agent_settings(&settings); |
| 3594 | 3599 |
| 3595 TestDelegate d; | 3600 TestDelegate d; |
| 3596 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), | 3601 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
| 3597 &d, | 3602 &d, |
| 3598 &context); | 3603 &context); |
| 3599 req.Start(); | 3604 req.Start(); |
| 3600 MessageLoop::current()->Run(); | 3605 MessageLoop::current()->Run(); |
| 3601 EXPECT_EQ("None", d.data_received()); | 3606 EXPECT_EQ("None", d.data_received()); |
| 3602 } | 3607 } |
| 3603 | 3608 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3644 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 3649 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 3645 req.SetExtraRequestHeaders(headers); | 3650 req.SetExtraRequestHeaders(headers); |
| 3646 req.Start(); | 3651 req.Start(); |
| 3647 MessageLoop::current()->Run(); | 3652 MessageLoop::current()->Run(); |
| 3648 // If the net tests are being run with ChromeFrame then we need to allow for | 3653 // If the net tests are being run with ChromeFrame then we need to allow for |
| 3649 // the 'chromeframe' suffix which is added to the user agent before the | 3654 // the 'chromeframe' suffix which is added to the user agent before the |
| 3650 // closing parentheses. | 3655 // closing parentheses. |
| 3651 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3656 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 3652 } | 3657 } |
| 3653 | 3658 |
| 3659 // Check that a NULL HttpUserAgentSettings causes the corresponding empty | |
| 3660 // headers to be sent. | |
|
mmenke
2012/10/25 18:06:33
That should be "corresponding header to not be sen
pauljensen
2012/10/25 21:30:25
Its a mix of both empty or missing headers. We al
| |
| 3661 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { | |
| 3662 ASSERT_TRUE(test_server_.Start()); | |
| 3663 | |
| 3664 TestNetworkDelegate network_delegate; // must outlive URLRequests | |
| 3665 TestURLRequestContext context(true); | |
| 3666 context.set_network_delegate(&network_delegate); | |
| 3667 context.Init(); | |
| 3668 // We override the HttpUserAgentSettings after initialization because empty | |
| 3669 // entries get overridden by Init(). | |
| 3670 context.set_http_user_agent_settings(NULL); | |
| 3671 | |
| 3672 struct { | |
| 3673 const char* request; | |
| 3674 const char* expected_response; | |
| 3675 } tests[] = { { "echoheader?Accept-Language", "None" }, | |
| 3676 { "echoheader?Accept-Charset", "None" }, | |
| 3677 { "echoheader?User-Agent", "" } }; | |
| 3678 | |
| 3679 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { | |
| 3680 TestDelegate d; | |
| 3681 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context); | |
| 3682 req.Start(); | |
| 3683 MessageLoop::current()->Run(); | |
| 3684 EXPECT_EQ(tests[i].expected_response, d.data_received()) | |
| 3685 << " Request = \"" << tests[i].request << "\""; | |
| 3686 } | |
| 3687 } | |
| 3688 | |
| 3654 class HTTPSRequestTest : public testing::Test { | 3689 class HTTPSRequestTest : public testing::Test { |
| 3655 public: | 3690 public: |
| 3656 HTTPSRequestTest() : default_context_(true) { | 3691 HTTPSRequestTest() : default_context_(true) { |
| 3657 default_context_.set_network_delegate(&default_network_delegate_); | 3692 default_context_.set_network_delegate(&default_network_delegate_); |
| 3658 default_context_.Init(); | 3693 default_context_.Init(); |
| 3659 } | 3694 } |
| 3660 virtual ~HTTPSRequestTest() {} | 3695 virtual ~HTTPSRequestTest() {} |
| 3661 | 3696 |
| 3662 protected: | 3697 protected: |
| 3663 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest | 3698 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4833 | 4868 |
| 4834 EXPECT_FALSE(r.is_pending()); | 4869 EXPECT_FALSE(r.is_pending()); |
| 4835 EXPECT_EQ(1, d->response_started_count()); | 4870 EXPECT_EQ(1, d->response_started_count()); |
| 4836 EXPECT_FALSE(d->received_data_before_response()); | 4871 EXPECT_FALSE(d->received_data_before_response()); |
| 4837 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4872 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 4838 } | 4873 } |
| 4839 } | 4874 } |
| 4840 #endif // !defined(DISABLE_FTP_SUPPORT) | 4875 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 4841 | 4876 |
| 4842 } // namespace net | 4877 } // namespace net |
| OLD | NEW |