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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 #include "net/ftp/ftp_network_layer.h" | 45 #include "net/ftp/ftp_network_layer.h" |
| 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/const_http_user_agent_settings.h" | |
| 55 #include "net/url_request/ftp_protocol_handler.h" | 56 #include "net/url_request/ftp_protocol_handler.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" |
| (...skipping 3261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3326 EXPECT_EQ(kData, d.data_received()); | 3327 EXPECT_EQ(kData, d.data_received()); |
| 3327 } | 3328 } |
| 3328 | 3329 |
| 3329 // Check that default A-L header is sent. | 3330 // Check that default A-L header is sent. |
| 3330 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 3331 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
| 3331 ASSERT_TRUE(test_server_.Start()); | 3332 ASSERT_TRUE(test_server_.Start()); |
| 3332 | 3333 |
| 3333 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3334 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 3334 TestURLRequestContext context(true); | 3335 TestURLRequestContext context(true); |
| 3335 context.set_network_delegate(&network_delegate); | 3336 context.set_network_delegate(&network_delegate); |
| 3336 context.set_accept_language("en"); | 3337 ConstHttpUserAgentSettings settings("en", EmptyString(), EmptyString()); |
|
mmenke
2012/10/05 20:08:51
Just out of paranoia, let's create the settings (A
| |
| 3338 context.set_http_user_agent_settings(&settings); | |
| 3337 context.Init(); | 3339 context.Init(); |
| 3338 | 3340 |
| 3339 TestDelegate d; | 3341 TestDelegate d; |
| 3340 URLRequest req( | 3342 URLRequest req( |
| 3341 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); | 3343 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); |
| 3342 req.Start(); | 3344 req.Start(); |
| 3343 MessageLoop::current()->Run(); | 3345 MessageLoop::current()->Run(); |
| 3344 EXPECT_EQ("en", d.data_received()); | 3346 EXPECT_EQ("en", d.data_received()); |
| 3345 } | 3347 } |
| 3346 | 3348 |
| 3347 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 3349 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
| 3348 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 3350 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
| 3349 ASSERT_TRUE(test_server_.Start()); | 3351 ASSERT_TRUE(test_server_.Start()); |
| 3350 | 3352 |
| 3351 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3353 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 3352 TestURLRequestContext context(true); | 3354 TestURLRequestContext context(true); |
| 3353 context.set_network_delegate(&network_delegate); | 3355 context.set_network_delegate(&network_delegate); |
| 3354 context.Init(); | 3356 context.Init(); |
| 3355 // We override the language after initialization because empty entries | 3357 // We override the language after initialization because empty entries |
| 3356 // get overridden by Init(). | 3358 // get overridden by Init(). |
| 3357 context.set_accept_language(""); | 3359 ConstHttpUserAgentSettings settings("", EmptyString(), EmptyString()); |
| 3360 context.set_http_user_agent_settings(&settings); | |
| 3358 | 3361 |
| 3359 TestDelegate d; | 3362 TestDelegate d; |
| 3360 URLRequest req( | 3363 URLRequest req( |
| 3361 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); | 3364 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); |
| 3362 req.Start(); | 3365 req.Start(); |
| 3363 MessageLoop::current()->Run(); | 3366 MessageLoop::current()->Run(); |
| 3364 EXPECT_EQ("None", d.data_received()); | 3367 EXPECT_EQ("None", d.data_received()); |
| 3365 } | 3368 } |
| 3366 | 3369 |
|
mmenke
2012/10/05 20:08:51
Since we allow a context's UserAgentSettings to be
| |
| 3367 // Check that if request overrides the A-L header, the default is not appended. | 3370 // Check that if request overrides the A-L header, the default is not appended. |
| 3368 // See http://crbug.com/20894 | 3371 // See http://crbug.com/20894 |
| 3369 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 3372 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
| 3370 ASSERT_TRUE(test_server_.Start()); | 3373 ASSERT_TRUE(test_server_.Start()); |
| 3371 | 3374 |
| 3372 TestDelegate d; | 3375 TestDelegate d; |
| 3373 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), | 3376 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), |
| 3374 &d, | 3377 &d, |
| 3375 &default_context_); | 3378 &default_context_); |
| 3376 HttpRequestHeaders headers; | 3379 HttpRequestHeaders headers; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3414 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 3417 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
| 3415 } | 3418 } |
| 3416 | 3419 |
| 3417 // Check that default A-C header is sent. | 3420 // Check that default A-C header is sent. |
| 3418 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { | 3421 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { |
| 3419 ASSERT_TRUE(test_server_.Start()); | 3422 ASSERT_TRUE(test_server_.Start()); |
| 3420 | 3423 |
| 3421 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3424 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 3422 TestURLRequestContext context(true); | 3425 TestURLRequestContext context(true); |
| 3423 context.set_network_delegate(&network_delegate); | 3426 context.set_network_delegate(&network_delegate); |
| 3424 context.set_accept_charset("en"); | 3427 ConstHttpUserAgentSettings settings(EmptyString(), "en", EmptyString()); |
| 3428 context.set_http_user_agent_settings(&settings); | |
| 3425 context.Init(); | 3429 context.Init(); |
| 3426 | 3430 |
| 3427 TestDelegate d; | 3431 TestDelegate d; |
| 3428 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), | 3432 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
| 3429 &d, | 3433 &d, |
| 3430 &context); | 3434 &context); |
| 3431 req.Start(); | 3435 req.Start(); |
| 3432 MessageLoop::current()->Run(); | 3436 MessageLoop::current()->Run(); |
| 3433 EXPECT_EQ("en", d.data_received()); | 3437 EXPECT_EQ("en", d.data_received()); |
| 3434 } | 3438 } |
| 3435 | 3439 |
| 3436 // Check that an empty A-C header is not sent. http://crbug.com/77365. | 3440 // Check that an empty A-C header is not sent. http://crbug.com/77365. |
| 3437 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { | 3441 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { |
| 3438 ASSERT_TRUE(test_server_.Start()); | 3442 ASSERT_TRUE(test_server_.Start()); |
| 3439 | 3443 |
| 3440 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3444 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 3441 TestURLRequestContext context(true); | 3445 TestURLRequestContext context(true); |
| 3442 context.set_network_delegate(&network_delegate); | 3446 context.set_network_delegate(&network_delegate); |
| 3443 context.Init(); | 3447 context.Init(); |
| 3444 // We override the accepted charset after initialization because empty | 3448 // We override the accepted charset after initialization because empty |
| 3445 // entries get overridden otherwise. | 3449 // entries get overridden otherwise. |
| 3446 context.set_accept_charset(""); | 3450 ConstHttpUserAgentSettings settings(EmptyString(), "", EmptyString()); |
| 3451 context.set_http_user_agent_settings(&settings); | |
| 3447 | 3452 |
| 3448 TestDelegate d; | 3453 TestDelegate d; |
| 3449 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), | 3454 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
| 3450 &d, | 3455 &d, |
| 3451 &context); | 3456 &context); |
| 3452 req.Start(); | 3457 req.Start(); |
| 3453 MessageLoop::current()->Run(); | 3458 MessageLoop::current()->Run(); |
| 3454 EXPECT_EQ("None", d.data_received()); | 3459 EXPECT_EQ("None", d.data_received()); |
| 3455 } | 3460 } |
| 3456 | 3461 |
| (...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4686 | 4691 |
| 4687 EXPECT_FALSE(r.is_pending()); | 4692 EXPECT_FALSE(r.is_pending()); |
| 4688 EXPECT_EQ(1, d->response_started_count()); | 4693 EXPECT_EQ(1, d->response_started_count()); |
| 4689 EXPECT_FALSE(d->received_data_before_response()); | 4694 EXPECT_FALSE(d->received_data_before_response()); |
| 4690 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4695 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 4691 } | 4696 } |
| 4692 } | 4697 } |
| 4693 #endif // !defined(DISABLE_FTP_SUPPORT) | 4698 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 4694 | 4699 |
| 4695 } // namespace net | 4700 } // namespace net |
| OLD | NEW |