| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/loader/mojo_async_resource_handler.h" | 5 #include "content/browser/loader/mojo_async_resource_handler.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "content/public/browser/resource_controller.h" | 26 #include "content/public/browser/resource_controller.h" |
| 27 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 27 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 28 #include "content/public/browser/resource_throttle.h" | 28 #include "content/public/browser/resource_throttle.h" |
| 29 #include "content/public/browser/stream_info.h" | 29 #include "content/public/browser/stream_info.h" |
| 30 #include "content/public/common/resource_response.h" | 30 #include "content/public/common/resource_response.h" |
| 31 #include "content/public/common/resource_type.h" | 31 #include "content/public/common/resource_type.h" |
| 32 #include "content/public/test/test_browser_context.h" | 32 #include "content/public/test/test_browser_context.h" |
| 33 #include "content/public/test/test_browser_thread_bundle.h" | 33 #include "content/public/test/test_browser_thread_bundle.h" |
| 34 #include "mojo/public/c/system/data_pipe.h" | 34 #include "mojo/public/c/system/data_pipe.h" |
| 35 #include "mojo/public/c/system/types.h" | 35 #include "mojo/public/c/system/types.h" |
| 36 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 36 #include "mojo/public/cpp/system/data_pipe.h" | 37 #include "mojo/public/cpp/system/data_pipe.h" |
| 37 #include "net/base/auth.h" | 38 #include "net/base/auth.h" |
| 38 #include "net/base/net_errors.h" | 39 #include "net/base/net_errors.h" |
| 39 #include "net/http/http_response_headers.h" | 40 #include "net/http/http_response_headers.h" |
| 40 #include "net/http/http_response_info.h" | 41 #include "net/http/http_response_info.h" |
| 41 #include "net/http/http_status_code.h" | 42 #include "net/http/http_status_code.h" |
| 42 #include "net/http/http_util.h" | 43 #include "net/http/http_util.h" |
| 43 #include "net/ssl/client_cert_store.h" | 44 #include "net/ssl/client_cert_store.h" |
| 44 #include "net/test/url_request/url_request_failed_job.h" | 45 #include "net/test/url_request/url_request_failed_job.h" |
| 45 #include "net/url_request/url_request.h" | 46 #include "net/url_request/url_request.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 261 |
| 261 bool is_begin_write_expectation_set_ = false; | 262 bool is_begin_write_expectation_set_ = false; |
| 262 bool is_end_write_expectation_set_ = false; | 263 bool is_end_write_expectation_set_ = false; |
| 263 MojoResult begin_write_expectation_ = MOJO_RESULT_UNKNOWN; | 264 MojoResult begin_write_expectation_ = MOJO_RESULT_UNKNOWN; |
| 264 MojoResult end_write_expectation_ = MOJO_RESULT_UNKNOWN; | 265 MojoResult end_write_expectation_ = MOJO_RESULT_UNKNOWN; |
| 265 | 266 |
| 266 DISALLOW_COPY_AND_ASSIGN( | 267 DISALLOW_COPY_AND_ASSIGN( |
| 267 MojoAsyncResourceHandlerWithCustomDataPipeOperations); | 268 MojoAsyncResourceHandlerWithCustomDataPipeOperations); |
| 268 }; | 269 }; |
| 269 | 270 |
| 271 class TestURLLoaderFactory final : public mojom::URLLoaderFactory { |
| 272 public: |
| 273 TestURLLoaderFactory() {} |
| 274 ~TestURLLoaderFactory() override {} |
| 275 |
| 276 void CreateLoaderAndStart( |
| 277 mojom::URLLoaderAssociatedRequest request, |
| 278 int32_t routing_id, |
| 279 int32_t request_id, |
| 280 const ResourceRequest& url_request, |
| 281 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) override { |
| 282 loader_request_ = std::move(request); |
| 283 client_ptr_info_ = std::move(client_ptr_info); |
| 284 } |
| 285 |
| 286 mojom::URLLoaderAssociatedRequest PassLoaderRequest() { |
| 287 return std::move(loader_request_); |
| 288 } |
| 289 |
| 290 mojom::URLLoaderClientAssociatedPtrInfo PassClientPtrInfo() { |
| 291 return std::move(client_ptr_info_); |
| 292 } |
| 293 |
| 294 void SyncLoad(int32_t routing_id, |
| 295 int32_t request_id, |
| 296 const ResourceRequest& url_request, |
| 297 const SyncLoadCallback& callback) override { |
| 298 NOTREACHED(); |
| 299 } |
| 300 |
| 301 private: |
| 302 mojom::URLLoaderAssociatedRequest loader_request_; |
| 303 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info_; |
| 304 |
| 305 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory); |
| 306 }; |
| 307 |
| 270 class MojoAsyncResourceHandlerTestBase { | 308 class MojoAsyncResourceHandlerTestBase { |
| 271 public: | 309 public: |
| 272 MojoAsyncResourceHandlerTestBase() | 310 MojoAsyncResourceHandlerTestBase() |
| 273 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 311 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 274 browser_context_(new TestBrowserContext()) { | 312 browser_context_(new TestBrowserContext()) { |
| 275 MojoAsyncResourceHandler::SetAllocationSizeForTesting(32 * 1024); | 313 MojoAsyncResourceHandler::SetAllocationSizeForTesting(32 * 1024); |
| 276 rdh_.SetDelegate(&rdh_delegate_); | 314 rdh_.SetDelegate(&rdh_delegate_); |
| 277 | 315 |
| 278 url_request_delegate_.reset(new net::TestDelegate()); | 316 url_request_delegate_.reset(new net::TestDelegate()); |
| 279 net::URLRequestContext* request_context = | 317 net::URLRequestContext* request_context = |
| 280 browser_context_->GetResourceContext()->GetRequestContext(); | 318 browser_context_->GetResourceContext()->GetRequestContext(); |
| 281 request_ = request_context->CreateRequest( | 319 request_ = request_context->CreateRequest( |
| 282 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_TIMED_OUT), | 320 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_TIMED_OUT), |
| 283 net::DEFAULT_PRIORITY, url_request_delegate_.get()); | 321 net::DEFAULT_PRIORITY, url_request_delegate_.get()); |
| 284 ResourceRequestInfo::AllocateForTesting( | 322 ResourceRequestInfo::AllocateForTesting( |
| 285 request_.get(), // request | 323 request_.get(), // request |
| 286 RESOURCE_TYPE_XHR, // resource_type | 324 RESOURCE_TYPE_XHR, // resource_type |
| 287 browser_context_->GetResourceContext(), // context | 325 browser_context_->GetResourceContext(), // context |
| 288 2, // render_process_id | 326 2, // render_process_id |
| 289 0, // render_view_id | 327 0, // render_view_id |
| 290 0, // render_frame_id | 328 0, // render_frame_id |
| 291 true, // is_main_frame | 329 true, // is_main_frame |
| 292 false, // parent_is_main_frame | 330 false, // parent_is_main_frame |
| 293 false, // allow_download | 331 false, // allow_download |
| 294 true, // is_async | 332 true, // is_async |
| 295 false // is_using_lofi | 333 false // is_using_lofi |
| 296 ); | 334 ); |
| 297 mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info = | 335 |
| 298 url_loader_client_.CreateLocalAssociatedPtrInfo(); | 336 ResourceRequest request; |
| 337 base::WeakPtr<mojo::StrongBinding<mojom::URLLoaderFactory>> weak_binding = |
| 338 mojo::MakeStrongBinding(base::MakeUnique<TestURLLoaderFactory>(), |
| 339 mojo::GetProxy(&url_loader_factory_)); |
| 340 |
| 341 url_loader_factory_->CreateLoaderAndStart( |
| 342 mojo::GetProxy(&url_loader_proxy_, |
| 343 url_loader_factory_.associated_group()), |
| 344 0, 0, request, url_loader_client_.CreateRemoteAssociatedPtrInfo( |
| 345 url_loader_factory_.associated_group())); |
| 346 |
| 347 url_loader_factory_.FlushForTesting(); |
| 348 DCHECK(weak_binding); |
| 349 TestURLLoaderFactory* factory_impl = |
| 350 static_cast<TestURLLoaderFactory*>(weak_binding->impl()); |
| 351 |
| 299 mojom::URLLoaderClientAssociatedPtr client_ptr; | 352 mojom::URLLoaderClientAssociatedPtr client_ptr; |
| 300 client_ptr.Bind(std::move(client_ptr_info)); | 353 client_ptr.Bind(factory_impl->PassClientPtrInfo()); |
| 301 handler_.reset(new MojoAsyncResourceHandlerWithCustomDataPipeOperations( | 354 handler_.reset(new MojoAsyncResourceHandlerWithCustomDataPipeOperations( |
| 302 request_.get(), &rdh_, nullptr, std::move(client_ptr))); | 355 request_.get(), &rdh_, factory_impl->PassLoaderRequest(), |
| 356 std::move(client_ptr))); |
| 303 handler_->SetController(&resource_controller_); | 357 handler_->SetController(&resource_controller_); |
| 304 } | 358 } |
| 305 | 359 |
| 306 virtual ~MojoAsyncResourceHandlerTestBase() { | 360 virtual ~MojoAsyncResourceHandlerTestBase() { |
| 307 net::URLRequestFilter::GetInstance()->ClearHandlers(); | 361 net::URLRequestFilter::GetInstance()->ClearHandlers(); |
| 308 MojoAsyncResourceHandler::SetAllocationSizeForTesting( | 362 MojoAsyncResourceHandler::SetAllocationSizeForTesting( |
| 309 MojoAsyncResourceHandler::kDefaultAllocationSize); | 363 MojoAsyncResourceHandler::kDefaultAllocationSize); |
| 310 base::RunLoop().RunUntilIdle(); | 364 base::RunLoop().RunUntilIdle(); |
| 311 } | 365 } |
| 312 | 366 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 ADD_FAILURE() << "URLLoaderClient unexpectedly gets a response."; | 398 ADD_FAILURE() << "URLLoaderClient unexpectedly gets a response."; |
| 345 return false; | 399 return false; |
| 346 } | 400 } |
| 347 url_loader_client_.RunUntilResponseReceived(); | 401 url_loader_client_.RunUntilResponseReceived(); |
| 348 return true; | 402 return true; |
| 349 } | 403 } |
| 350 | 404 |
| 351 TestBrowserThreadBundle thread_bundle_; | 405 TestBrowserThreadBundle thread_bundle_; |
| 352 TestResourceDispatcherHostDelegate rdh_delegate_; | 406 TestResourceDispatcherHostDelegate rdh_delegate_; |
| 353 ResourceDispatcherHostImpl rdh_; | 407 ResourceDispatcherHostImpl rdh_; |
| 408 mojom::URLLoaderFactoryPtr url_loader_factory_; |
| 409 mojom::URLLoaderAssociatedPtr url_loader_proxy_; |
| 354 TestURLLoaderClient url_loader_client_; | 410 TestURLLoaderClient url_loader_client_; |
| 355 TestResourceController resource_controller_; | 411 TestResourceController resource_controller_; |
| 356 std::unique_ptr<TestBrowserContext> browser_context_; | 412 std::unique_ptr<TestBrowserContext> browser_context_; |
| 357 std::unique_ptr<net::TestDelegate> url_request_delegate_; | 413 std::unique_ptr<net::TestDelegate> url_request_delegate_; |
| 358 std::unique_ptr<net::URLRequest> request_; | 414 std::unique_ptr<net::URLRequest> request_; |
| 359 std::unique_ptr<MojoAsyncResourceHandlerWithCustomDataPipeOperations> | 415 std::unique_ptr<MojoAsyncResourceHandlerWithCustomDataPipeOperations> |
| 360 handler_; | 416 handler_; |
| 361 | 417 |
| 362 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerTestBase); | 418 DISALLOW_COPY_AND_ASSIGN(MojoAsyncResourceHandlerTestBase); |
| 363 }; | 419 }; |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 } | 1195 } |
| 1140 } | 1196 } |
| 1141 EXPECT_EQ("B", body); | 1197 EXPECT_EQ("B", body); |
| 1142 } | 1198 } |
| 1143 | 1199 |
| 1144 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1200 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1145 MojoAsyncResourceHandlerWithAllocationSizeTest, | 1201 MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1146 ::testing::Values(8, 32 * 2014)); | 1202 ::testing::Values(8, 32 * 2014)); |
| 1147 } // namespace | 1203 } // namespace |
| 1148 } // namespace content | 1204 } // namespace content |
| OLD | NEW |