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

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

Issue 10918279: Provide mutable members of UrlRequestContext via pure-virtual interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable test for chrome_frame_net_tests Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | sync/internal_api/http_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "net/http/http_cache.h" 47 #include "net/http/http_cache.h"
48 #include "net/http/http_network_layer.h" 48 #include "net/http/http_network_layer.h"
49 #include "net/http/http_network_session.h" 49 #include "net/http/http_network_session.h"
50 #include "net/http/http_request_headers.h" 50 #include "net/http/http_request_headers.h"
51 #include "net/http/http_response_headers.h" 51 #include "net/http/http_response_headers.h"
52 #include "net/ocsp/nss_ocsp.h" 52 #include "net/ocsp/nss_ocsp.h"
53 #include "net/proxy/proxy_service.h" 53 #include "net/proxy/proxy_service.h"
54 #include "net/socket/ssl_client_socket.h" 54 #include "net/socket/ssl_client_socket.h"
55 #include "net/test/test_server.h" 55 #include "net/test/test_server.h"
56 #include "net/url_request/ftp_protocol_handler.h" 56 #include "net/url_request/ftp_protocol_handler.h"
57 #include "net/url_request/static_http_user_agent_settings.h"
57 #include "net/url_request/url_request.h" 58 #include "net/url_request/url_request.h"
58 #include "net/url_request/url_request_file_dir_job.h" 59 #include "net/url_request/url_request_file_dir_job.h"
59 #include "net/url_request/url_request_http_job.h" 60 #include "net/url_request/url_request_http_job.h"
60 #include "net/url_request/url_request_job_factory_impl.h" 61 #include "net/url_request/url_request_job_factory_impl.h"
61 #include "net/url_request/url_request_redirect_job.h" 62 #include "net/url_request/url_request_redirect_job.h"
62 #include "net/url_request/url_request_test_job.h" 63 #include "net/url_request/url_request_test_job.h"
63 #include "net/url_request/url_request_test_util.h" 64 #include "net/url_request/url_request_test_util.h"
64 #include "testing/gtest/include/gtest/gtest.h" 65 #include "testing/gtest/include/gtest/gtest.h"
65 #include "testing/platform_test.h" 66 #include "testing/platform_test.h"
66 67
(...skipping 3557 matching lines...) Expand 10 before | Expand all | Expand 10 after
3624 req.Start(); 3625 req.Start();
3625 MessageLoop::current()->Run(); 3626 MessageLoop::current()->Run();
3626 EXPECT_EQ("POST", req.method()); 3627 EXPECT_EQ("POST", req.method());
3627 EXPECT_EQ(kData, d.data_received()); 3628 EXPECT_EQ(kData, d.data_received());
3628 } 3629 }
3629 3630
3630 // Check that default A-L header is sent. 3631 // Check that default A-L header is sent.
3631 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { 3632 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) {
3632 ASSERT_TRUE(test_server_.Start()); 3633 ASSERT_TRUE(test_server_.Start());
3633 3634
3635 StaticHttpUserAgentSettings settings("en", EmptyString(), EmptyString());
3634 TestNetworkDelegate network_delegate; // must outlive URLRequests 3636 TestNetworkDelegate network_delegate; // must outlive URLRequests
3635 TestURLRequestContext context(true); 3637 TestURLRequestContext context(true);
3636 context.set_network_delegate(&network_delegate); 3638 context.set_network_delegate(&network_delegate);
3637 context.set_accept_language("en"); 3639 context.set_http_user_agent_settings(&settings);
3638 context.Init(); 3640 context.Init();
3639 3641
3640 TestDelegate d; 3642 TestDelegate d;
3641 URLRequest req( 3643 URLRequest req(
3642 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); 3644 test_server_.GetURL("echoheader?Accept-Language"), &d, &context);
3643 req.Start(); 3645 req.Start();
3644 MessageLoop::current()->Run(); 3646 MessageLoop::current()->Run();
3645 EXPECT_EQ("en", d.data_received()); 3647 EXPECT_EQ("en", d.data_received());
3646 } 3648 }
3647 3649
3648 // Check that an empty A-L header is not sent. http://crbug.com/77365. 3650 // Check that an empty A-L header is not sent. http://crbug.com/77365.
3649 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { 3651 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) {
3650 ASSERT_TRUE(test_server_.Start()); 3652 ASSERT_TRUE(test_server_.Start());
3651 3653
3654 StaticHttpUserAgentSettings settings(
3655 EmptyString(), EmptyString(), EmptyString());
3652 TestNetworkDelegate network_delegate; // must outlive URLRequests 3656 TestNetworkDelegate network_delegate; // must outlive URLRequests
3653 TestURLRequestContext context(true); 3657 TestURLRequestContext context(true);
3654 context.set_network_delegate(&network_delegate); 3658 context.set_network_delegate(&network_delegate);
3655 context.Init(); 3659 context.Init();
3656 // We override the language after initialization because empty entries 3660 // We override the language after initialization because empty entries
3657 // get overridden by Init(). 3661 // get overridden by Init().
3658 context.set_accept_language(""); 3662 context.set_http_user_agent_settings(&settings);
3659 3663
3660 TestDelegate d; 3664 TestDelegate d;
3661 URLRequest req( 3665 URLRequest req(
3662 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); 3666 test_server_.GetURL("echoheader?Accept-Language"), &d, &context);
3663 req.Start(); 3667 req.Start();
3664 MessageLoop::current()->Run(); 3668 MessageLoop::current()->Run();
3665 EXPECT_EQ("None", d.data_received()); 3669 EXPECT_EQ("None", d.data_received());
3666 } 3670 }
3667 3671
3668 // Check that if request overrides the A-L header, the default is not appended. 3672 // 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
3712 req.Start(); 3716 req.Start();
3713 MessageLoop::current()->Run(); 3717 MessageLoop::current()->Run();
3714 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); 3718 EXPECT_FALSE(ContainsString(d.data_received(), "gzip"));
3715 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); 3719 EXPECT_TRUE(ContainsString(d.data_received(), "identity"));
3716 } 3720 }
3717 3721
3718 // Check that default A-C header is sent. 3722 // Check that default A-C header is sent.
3719 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { 3723 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) {
3720 ASSERT_TRUE(test_server_.Start()); 3724 ASSERT_TRUE(test_server_.Start());
3721 3725
3726 StaticHttpUserAgentSettings settings(EmptyString(), "en", EmptyString());
3722 TestNetworkDelegate network_delegate; // must outlive URLRequests 3727 TestNetworkDelegate network_delegate; // must outlive URLRequests
3723 TestURLRequestContext context(true); 3728 TestURLRequestContext context(true);
3724 context.set_network_delegate(&network_delegate); 3729 context.set_network_delegate(&network_delegate);
3725 context.set_accept_charset("en"); 3730 context.set_http_user_agent_settings(&settings);
3726 context.Init(); 3731 context.Init();
3727 3732
3728 TestDelegate d; 3733 TestDelegate d;
3729 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), 3734 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"),
3730 &d, 3735 &d,
3731 &context); 3736 &context);
3732 req.Start(); 3737 req.Start();
3733 MessageLoop::current()->Run(); 3738 MessageLoop::current()->Run();
3734 EXPECT_EQ("en", d.data_received()); 3739 EXPECT_EQ("en", d.data_received());
3735 } 3740 }
3736 3741
3737 // Check that an empty A-C header is not sent. http://crbug.com/77365. 3742 // Check that an empty A-C header is not sent. http://crbug.com/77365.
3738 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { 3743 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) {
3739 ASSERT_TRUE(test_server_.Start()); 3744 ASSERT_TRUE(test_server_.Start());
3740 3745
3746 StaticHttpUserAgentSettings settings(
3747 EmptyString(), EmptyString(), EmptyString());
3741 TestNetworkDelegate network_delegate; // must outlive URLRequests 3748 TestNetworkDelegate network_delegate; // must outlive URLRequests
3742 TestURLRequestContext context(true); 3749 TestURLRequestContext context(true);
3743 context.set_network_delegate(&network_delegate); 3750 context.set_network_delegate(&network_delegate);
3744 context.Init(); 3751 context.Init();
3745 // We override the accepted charset after initialization because empty 3752 // We override the accepted charset after initialization because empty
3746 // entries get overridden otherwise. 3753 // entries get overridden otherwise.
3747 context.set_accept_charset(""); 3754 context.set_http_user_agent_settings(&settings);
3748 3755
3749 TestDelegate d; 3756 TestDelegate d;
3750 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), 3757 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"),
3751 &d, 3758 &d,
3752 &context); 3759 &context);
3753 req.Start(); 3760 req.Start();
3754 MessageLoop::current()->Run(); 3761 MessageLoop::current()->Run();
3755 EXPECT_EQ("None", d.data_received()); 3762 EXPECT_EQ("None", d.data_received());
3756 } 3763 }
3757 3764
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 3805 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
3799 req.SetExtraRequestHeaders(headers); 3806 req.SetExtraRequestHeaders(headers);
3800 req.Start(); 3807 req.Start();
3801 MessageLoop::current()->Run(); 3808 MessageLoop::current()->Run();
3802 // If the net tests are being run with ChromeFrame then we need to allow for 3809 // If the net tests are being run with ChromeFrame then we need to allow for
3803 // the 'chromeframe' suffix which is added to the user agent before the 3810 // the 'chromeframe' suffix which is added to the user agent before the
3804 // closing parentheses. 3811 // closing parentheses.
3805 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 3812 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
3806 } 3813 }
3807 3814
3815 // Check that a NULL HttpUserAgentSettings causes the corresponding empty
3816 // User-Agent header to be sent but does not send the Accept-Language and
3817 // Accept-Charset headers.
3818 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) {
3819 ASSERT_TRUE(test_server_.Start());
3820
3821 TestNetworkDelegate network_delegate; // must outlive URLRequests
3822 TestURLRequestContext context(true);
3823 context.set_network_delegate(&network_delegate);
3824 context.Init();
3825 // We override the HttpUserAgentSettings after initialization because empty
3826 // entries get overridden by Init().
3827 context.set_http_user_agent_settings(NULL);
3828
3829 struct {
3830 const char* request;
3831 const char* expected_response;
3832 } tests[] = { { "echoheader?Accept-Language", "None" },
3833 { "echoheader?Accept-Charset", "None" },
3834 { "echoheader?User-Agent", "" } };
3835
3836 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
3837 TestDelegate d;
3838 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context);
3839 req.Start();
3840 MessageLoop::current()->Run();
3841 EXPECT_EQ(tests[i].expected_response, d.data_received())
3842 << " Request = \"" << tests[i].request << "\"";
3843 }
3844 }
3845
3808 class HTTPSRequestTest : public testing::Test { 3846 class HTTPSRequestTest : public testing::Test {
3809 public: 3847 public:
3810 HTTPSRequestTest() : default_context_(true) { 3848 HTTPSRequestTest() : default_context_(true) {
3811 default_context_.set_network_delegate(&default_network_delegate_); 3849 default_context_.set_network_delegate(&default_network_delegate_);
3812 default_context_.Init(); 3850 default_context_.Init();
3813 } 3851 }
3814 virtual ~HTTPSRequestTest() {} 3852 virtual ~HTTPSRequestTest() {}
3815 3853
3816 protected: 3854 protected:
3817 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest 3855 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
4987 5025
4988 EXPECT_FALSE(r.is_pending()); 5026 EXPECT_FALSE(r.is_pending());
4989 EXPECT_EQ(1, d->response_started_count()); 5027 EXPECT_EQ(1, d->response_started_count());
4990 EXPECT_FALSE(d->received_data_before_response()); 5028 EXPECT_FALSE(d->received_data_before_response());
4991 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 5029 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
4992 } 5030 }
4993 } 5031 }
4994 #endif // !defined(DISABLE_FTP_SUPPORT) 5032 #endif // !defined(DISABLE_FTP_SUPPORT)
4995 5033
4996 } // namespace net 5034 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | sync/internal_api/http_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698