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

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: Address mmenke's comments 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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(
3501 EmptyString(), EmptyString(), EmptyString());
3498 TestNetworkDelegate network_delegate; // must outlive URLRequests 3502 TestNetworkDelegate network_delegate; // must outlive URLRequests
3499 TestURLRequestContext context(true); 3503 TestURLRequestContext context(true);
3500 context.set_network_delegate(&network_delegate); 3504 context.set_network_delegate(&network_delegate);
3501 context.Init(); 3505 context.Init();
3502 // We override the language after initialization because empty entries 3506 // We override the language after initialization because empty entries
3503 // get overridden by Init(). 3507 // get overridden by Init().
3504 context.set_accept_language(""); 3508 context.set_http_user_agent_settings(&settings);
3505 3509
3506 TestDelegate d; 3510 TestDelegate d;
3507 URLRequest req( 3511 URLRequest req(
3508 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); 3512 test_server_.GetURL("echoheader?Accept-Language"), &d, &context);
3509 req.Start(); 3513 req.Start();
3510 MessageLoop::current()->Run(); 3514 MessageLoop::current()->Run();
3511 EXPECT_EQ("None", d.data_received()); 3515 EXPECT_EQ("None", d.data_received());
3512 } 3516 }
3513 3517
3514 // Check that if request overrides the A-L header, the default is not appended. 3518 // 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
3558 req.Start(); 3562 req.Start();
3559 MessageLoop::current()->Run(); 3563 MessageLoop::current()->Run();
3560 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); 3564 EXPECT_FALSE(ContainsString(d.data_received(), "gzip"));
3561 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); 3565 EXPECT_TRUE(ContainsString(d.data_received(), "identity"));
3562 } 3566 }
3563 3567
3564 // Check that default A-C header is sent. 3568 // Check that default A-C header is sent.
3565 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { 3569 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) {
3566 ASSERT_TRUE(test_server_.Start()); 3570 ASSERT_TRUE(test_server_.Start());
3567 3571
3572 StaticHttpUserAgentSettings settings(EmptyString(), "en", EmptyString());
3568 TestNetworkDelegate network_delegate; // must outlive URLRequests 3573 TestNetworkDelegate network_delegate; // must outlive URLRequests
3569 TestURLRequestContext context(true); 3574 TestURLRequestContext context(true);
3570 context.set_network_delegate(&network_delegate); 3575 context.set_network_delegate(&network_delegate);
3571 context.set_accept_charset("en"); 3576 context.set_http_user_agent_settings(&settings);
3572 context.Init(); 3577 context.Init();
3573 3578
3574 TestDelegate d; 3579 TestDelegate d;
3575 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), 3580 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"),
3576 &d, 3581 &d,
3577 &context); 3582 &context);
3578 req.Start(); 3583 req.Start();
3579 MessageLoop::current()->Run(); 3584 MessageLoop::current()->Run();
3580 EXPECT_EQ("en", d.data_received()); 3585 EXPECT_EQ("en", d.data_received());
3581 } 3586 }
3582 3587
3583 // Check that an empty A-C header is not sent. http://crbug.com/77365. 3588 // Check that an empty A-C header is not sent. http://crbug.com/77365.
3584 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { 3589 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) {
3585 ASSERT_TRUE(test_server_.Start()); 3590 ASSERT_TRUE(test_server_.Start());
3586 3591
3592 StaticHttpUserAgentSettings settings(
3593 EmptyString(), EmptyString(), EmptyString());
3587 TestNetworkDelegate network_delegate; // must outlive URLRequests 3594 TestNetworkDelegate network_delegate; // must outlive URLRequests
3588 TestURLRequestContext context(true); 3595 TestURLRequestContext context(true);
3589 context.set_network_delegate(&network_delegate); 3596 context.set_network_delegate(&network_delegate);
3590 context.Init(); 3597 context.Init();
3591 // We override the accepted charset after initialization because empty 3598 // We override the accepted charset after initialization because empty
3592 // entries get overridden otherwise. 3599 // entries get overridden otherwise.
3593 context.set_accept_charset(""); 3600 context.set_http_user_agent_settings(&settings);
3594 3601
3595 TestDelegate d; 3602 TestDelegate d;
3596 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), 3603 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"),
3597 &d, 3604 &d,
3598 &context); 3605 &context);
3599 req.Start(); 3606 req.Start();
3600 MessageLoop::current()->Run(); 3607 MessageLoop::current()->Run();
3601 EXPECT_EQ("None", d.data_received()); 3608 EXPECT_EQ("None", d.data_received());
3602 } 3609 }
3603 3610
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3644 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 3651 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
3645 req.SetExtraRequestHeaders(headers); 3652 req.SetExtraRequestHeaders(headers);
3646 req.Start(); 3653 req.Start();
3647 MessageLoop::current()->Run(); 3654 MessageLoop::current()->Run();
3648 // If the net tests are being run with ChromeFrame then we need to allow for 3655 // 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 3656 // the 'chromeframe' suffix which is added to the user agent before the
3650 // closing parentheses. 3657 // closing parentheses.
3651 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 3658 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
3652 } 3659 }
3653 3660
3661 // Check that a NULL HttpUserAgentSettings causes the corresponding empty
3662 // User-Agent header to be sent but does not send the Accept-Language and
3663 // Accept-Charset headers.
3664 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) {
3665 ASSERT_TRUE(test_server_.Start());
3666
3667 TestNetworkDelegate network_delegate; // must outlive URLRequests
3668 TestURLRequestContext context(true);
3669 context.set_network_delegate(&network_delegate);
3670 context.Init();
3671 // We override the HttpUserAgentSettings after initialization because empty
3672 // entries get overridden by Init().
3673 context.set_http_user_agent_settings(NULL);
3674
3675 struct {
3676 const char* request;
3677 const char* expected_response;
3678 } tests[] = { { "echoheader?Accept-Language", "None" },
3679 { "echoheader?Accept-Charset", "None" },
3680 { "echoheader?User-Agent", "" } };
3681
3682 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
3683 TestDelegate d;
3684 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context);
3685 req.Start();
3686 MessageLoop::current()->Run();
3687 EXPECT_EQ(tests[i].expected_response, d.data_received())
3688 << " Request = \"" << tests[i].request << "\"";
3689 }
3690 }
3691
3654 class HTTPSRequestTest : public testing::Test { 3692 class HTTPSRequestTest : public testing::Test {
3655 public: 3693 public:
3656 HTTPSRequestTest() : default_context_(true) { 3694 HTTPSRequestTest() : default_context_(true) {
3657 default_context_.set_network_delegate(&default_network_delegate_); 3695 default_context_.set_network_delegate(&default_network_delegate_);
3658 default_context_.Init(); 3696 default_context_.Init();
3659 } 3697 }
3660 virtual ~HTTPSRequestTest() {} 3698 virtual ~HTTPSRequestTest() {}
3661 3699
3662 protected: 3700 protected:
3663 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest 3701 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
4833 4871
4834 EXPECT_FALSE(r.is_pending()); 4872 EXPECT_FALSE(r.is_pending());
4835 EXPECT_EQ(1, d->response_started_count()); 4873 EXPECT_EQ(1, d->response_started_count());
4836 EXPECT_FALSE(d->received_data_before_response()); 4874 EXPECT_FALSE(d->received_data_before_response());
4837 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 4875 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
4838 } 4876 }
4839 } 4877 }
4840 #endif // !defined(DISABLE_FTP_SUPPORT) 4878 #endif // !defined(DISABLE_FTP_SUPPORT)
4841 4879
4842 } // namespace net 4880 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698