| 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 <utility> |
| 6 |
| 5 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 6 | 8 |
| 7 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 8 #include <windows.h> | 10 #include <windows.h> |
| 9 #include <shlobj.h> | 11 #include <shlobj.h> |
| 10 #endif | 12 #endif |
| 11 | 13 |
| 12 #include <stdint.h> | 14 #include <stdint.h> |
| 13 | 15 |
| 14 #include <algorithm> | 16 #include <algorithm> |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 bool ContainsString(const std::string& haystack, const char* needle) { | 310 bool ContainsString(const std::string& haystack, const char* needle) { |
| 309 std::string::const_iterator it = std::search( | 311 std::string::const_iterator it = std::search( |
| 310 haystack.begin(), haystack.end(), needle, needle + strlen(needle), | 312 haystack.begin(), haystack.end(), needle, needle + strlen(needle), |
| 311 base::CaseInsensitiveCompareASCII<char>()); | 313 base::CaseInsensitiveCompareASCII<char>()); |
| 312 return it != haystack.end(); | 314 return it != haystack.end(); |
| 313 } | 315 } |
| 314 | 316 |
| 315 scoped_ptr<UploadDataStream> CreateSimpleUploadData(const char* data) { | 317 scoped_ptr<UploadDataStream> CreateSimpleUploadData(const char* data) { |
| 316 scoped_ptr<UploadElementReader> reader( | 318 scoped_ptr<UploadElementReader> reader( |
| 317 new UploadBytesElementReader(data, strlen(data))); | 319 new UploadBytesElementReader(data, strlen(data))); |
| 318 return ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0); | 320 return ElementsUploadDataStream::CreateWithReader(std::move(reader), 0); |
| 319 } | 321 } |
| 320 | 322 |
| 321 // Verify that the SSLInfo of a successful SSL connection has valid values. | 323 // Verify that the SSLInfo of a successful SSL connection has valid values. |
| 322 void CheckSSLInfo(const SSLInfo& ssl_info) { | 324 void CheckSSLInfo(const SSLInfo& ssl_info) { |
| 323 // -1 means unknown. 0 means no encryption. | 325 // -1 means unknown. 0 means no encryption. |
| 324 EXPECT_GT(ssl_info.security_bits, 0); | 326 EXPECT_GT(ssl_info.security_bits, 0); |
| 325 | 327 |
| 326 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. | 328 // The cipher suite TLS_NULL_WITH_NULL_NULL (0) must not be negotiated. |
| 327 uint16_t cipher_suite = | 329 uint16_t cipher_suite = |
| 328 SSLConnectionStatusToCipherSuite(ssl_info.connection_status); | 330 SSLConnectionStatusToCipherSuite(ssl_info.connection_status); |
| (...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 } | 1541 } |
| 1540 | 1542 |
| 1541 ~URLRequestInterceptorTest() override { | 1543 ~URLRequestInterceptorTest() override { |
| 1542 // URLRequestJobs may post clean-up tasks on destruction. | 1544 // URLRequestJobs may post clean-up tasks on destruction. |
| 1543 base::RunLoop().RunUntilIdle(); | 1545 base::RunLoop().RunUntilIdle(); |
| 1544 } | 1546 } |
| 1545 | 1547 |
| 1546 void SetUpFactory() override { | 1548 void SetUpFactory() override { |
| 1547 interceptor_ = new MockURLRequestInterceptor(); | 1549 interceptor_ = new MockURLRequestInterceptor(); |
| 1548 job_factory_.reset(new URLRequestInterceptingJobFactory( | 1550 job_factory_.reset(new URLRequestInterceptingJobFactory( |
| 1549 job_factory_.Pass(), make_scoped_ptr(interceptor_))); | 1551 std::move(job_factory_), make_scoped_ptr(interceptor_))); |
| 1550 } | 1552 } |
| 1551 | 1553 |
| 1552 MockURLRequestInterceptor* interceptor() const { | 1554 MockURLRequestInterceptor* interceptor() const { |
| 1553 return interceptor_; | 1555 return interceptor_; |
| 1554 } | 1556 } |
| 1555 | 1557 |
| 1556 private: | 1558 private: |
| 1557 MockURLRequestInterceptor* interceptor_; | 1559 MockURLRequestInterceptor* interceptor_; |
| 1558 }; | 1560 }; |
| 1559 | 1561 |
| (...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3324 request.headers.at("Host") != "www.redirect.com" || | 3326 request.headers.at("Host") != "www.redirect.com" || |
| 3325 request.method != test_server::METHOD_CONNECT) { | 3327 request.method != test_server::METHOD_CONNECT) { |
| 3326 return nullptr; | 3328 return nullptr; |
| 3327 } | 3329 } |
| 3328 | 3330 |
| 3329 scoped_ptr<test_server::BasicHttpResponse> http_response( | 3331 scoped_ptr<test_server::BasicHttpResponse> http_response( |
| 3330 new test_server::BasicHttpResponse); | 3332 new test_server::BasicHttpResponse); |
| 3331 http_response->set_code(HTTP_FOUND); | 3333 http_response->set_code(HTTP_FOUND); |
| 3332 http_response->AddCustomHeader("Location", | 3334 http_response->AddCustomHeader("Location", |
| 3333 "http://www.destination.com/foo.js"); | 3335 "http://www.destination.com/foo.js"); |
| 3334 return http_response.Pass(); | 3336 return std::move(http_response); |
| 3335 } | 3337 } |
| 3336 | 3338 |
| 3337 } // namespace | 3339 } // namespace |
| 3338 | 3340 |
| 3339 // In this unit test, we're using the EmbeddedTestServer as a proxy server and | 3341 // In this unit test, we're using the EmbeddedTestServer as a proxy server and |
| 3340 // issuing a CONNECT request with the magic host name "www.redirect.com". | 3342 // issuing a CONNECT request with the magic host name "www.redirect.com". |
| 3341 // The EmbeddedTestServer will return a 302 response, which we should not | 3343 // The EmbeddedTestServer will return a 302 response, which we should not |
| 3342 // follow. | 3344 // follow. |
| 3343 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 3345 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
| 3344 http_test_server()->RegisterRequestHandler( | 3346 http_test_server()->RegisterRequestHandler( |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4189 request.headers.at("Host") != "www.server-auth.com" || | 4191 request.headers.at("Host") != "www.server-auth.com" || |
| 4190 request.method != test_server::METHOD_CONNECT) { | 4192 request.method != test_server::METHOD_CONNECT) { |
| 4191 return nullptr; | 4193 return nullptr; |
| 4192 } | 4194 } |
| 4193 | 4195 |
| 4194 scoped_ptr<test_server::BasicHttpResponse> http_response( | 4196 scoped_ptr<test_server::BasicHttpResponse> http_response( |
| 4195 new test_server::BasicHttpResponse); | 4197 new test_server::BasicHttpResponse); |
| 4196 http_response->set_code(HTTP_UNAUTHORIZED); | 4198 http_response->set_code(HTTP_UNAUTHORIZED); |
| 4197 http_response->AddCustomHeader("WWW-Authenticate", | 4199 http_response->AddCustomHeader("WWW-Authenticate", |
| 4198 "Basic realm=\"WallyWorld\""); | 4200 "Basic realm=\"WallyWorld\""); |
| 4199 return http_response.Pass(); | 4201 return std::move(http_response); |
| 4200 } | 4202 } |
| 4201 | 4203 |
| 4202 } // namespace | 4204 } // namespace |
| 4203 | 4205 |
| 4204 // In this unit test, we're using the EmbeddedTestServer as a proxy server and | 4206 // In this unit test, we're using the EmbeddedTestServer as a proxy server and |
| 4205 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 4207 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
| 4206 // The EmbeddedTestServer will return a 401 response, which we should balk at. | 4208 // The EmbeddedTestServer will return a 401 response, which we should balk at. |
| 4207 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 4209 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
| 4208 http_test_server()->RegisterRequestHandler( | 4210 http_test_server()->RegisterRequestHandler( |
| 4209 base::Bind(&HandleServerAuthConnect)); | 4211 base::Bind(&HandleServerAuthConnect)); |
| (...skipping 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7387 | 7389 |
| 7388 // Check that creating a network request while entering/exiting suspend mode | 7390 // Check that creating a network request while entering/exiting suspend mode |
| 7389 // fails as it should. This is the only case where an HttpTransactionFactory | 7391 // fails as it should. This is the only case where an HttpTransactionFactory |
| 7390 // does not return an HttpTransaction. | 7392 // does not return an HttpTransaction. |
| 7391 TEST_F(URLRequestTestHTTP, NetworkSuspendTest) { | 7393 TEST_F(URLRequestTestHTTP, NetworkSuspendTest) { |
| 7392 // Create a new HttpNetworkLayer that thinks it's suspended. | 7394 // Create a new HttpNetworkLayer that thinks it's suspended. |
| 7393 scoped_ptr<HttpNetworkLayer> network_layer(new HttpNetworkLayer( | 7395 scoped_ptr<HttpNetworkLayer> network_layer(new HttpNetworkLayer( |
| 7394 default_context_.http_transaction_factory()->GetSession())); | 7396 default_context_.http_transaction_factory()->GetSession())); |
| 7395 network_layer->OnSuspend(); | 7397 network_layer->OnSuspend(); |
| 7396 | 7398 |
| 7397 HttpCache http_cache(network_layer.Pass(), | 7399 HttpCache http_cache(std::move(network_layer), |
| 7398 HttpCache::DefaultBackend::InMemory(0), true); | 7400 HttpCache::DefaultBackend::InMemory(0), true); |
| 7399 | 7401 |
| 7400 TestURLRequestContext context(true); | 7402 TestURLRequestContext context(true); |
| 7401 context.set_http_transaction_factory(&http_cache); | 7403 context.set_http_transaction_factory(&http_cache); |
| 7402 context.Init(); | 7404 context.Init(); |
| 7403 | 7405 |
| 7404 TestDelegate d; | 7406 TestDelegate d; |
| 7405 scoped_ptr<URLRequest> req( | 7407 scoped_ptr<URLRequest> req( |
| 7406 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); | 7408 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); |
| 7407 req->Start(); | 7409 req->Start(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7533 public: | 7535 public: |
| 7534 // TODO(bengr): Merge this with the URLRequestInterceptorHTTPTest fixture, | 7536 // TODO(bengr): Merge this with the URLRequestInterceptorHTTPTest fixture, |
| 7535 // ideally remove the dependency on URLRequestTestJob, and maybe move these | 7537 // ideally remove the dependency on URLRequestTestJob, and maybe move these |
| 7536 // tests into the factory tests. | 7538 // tests into the factory tests. |
| 7537 URLRequestInterceptorTestHTTP() : URLRequestTestHTTP(), interceptor_(NULL) { | 7539 URLRequestInterceptorTestHTTP() : URLRequestTestHTTP(), interceptor_(NULL) { |
| 7538 } | 7540 } |
| 7539 | 7541 |
| 7540 void SetUpFactory() override { | 7542 void SetUpFactory() override { |
| 7541 interceptor_ = new MockURLRequestInterceptor(); | 7543 interceptor_ = new MockURLRequestInterceptor(); |
| 7542 job_factory_.reset(new URLRequestInterceptingJobFactory( | 7544 job_factory_.reset(new URLRequestInterceptingJobFactory( |
| 7543 job_factory_.Pass(), make_scoped_ptr(interceptor_))); | 7545 std::move(job_factory_), make_scoped_ptr(interceptor_))); |
| 7544 } | 7546 } |
| 7545 | 7547 |
| 7546 MockURLRequestInterceptor* interceptor() const { | 7548 MockURLRequestInterceptor* interceptor() const { |
| 7547 return interceptor_; | 7549 return interceptor_; |
| 7548 } | 7550 } |
| 7549 | 7551 |
| 7550 private: | 7552 private: |
| 7551 MockURLRequestInterceptor* interceptor_; | 7553 MockURLRequestInterceptor* interceptor_; |
| 7552 }; | 7554 }; |
| 7553 | 7555 |
| (...skipping 2211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9765 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 9767 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 9766 | 9768 |
| 9767 req->Start(); | 9769 req->Start(); |
| 9768 req->Cancel(); | 9770 req->Cancel(); |
| 9769 base::RunLoop().RunUntilIdle(); | 9771 base::RunLoop().RunUntilIdle(); |
| 9770 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9772 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 9771 EXPECT_EQ(0, d.received_redirect_count()); | 9773 EXPECT_EQ(0, d.received_redirect_count()); |
| 9772 } | 9774 } |
| 9773 | 9775 |
| 9774 } // namespace net | 9776 } // namespace net |
| OLD | NEW |