| 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 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/test/test_simple_task_runner.h" | 20 #include "base/test/test_simple_task_runner.h" |
| 21 #include "content/browser/loader/mock_resource_loader.h" | 21 #include "content/browser/loader/mock_resource_loader.h" |
| 22 #include "content/browser/loader/resource_controller.h" | 22 #include "content/browser/loader/resource_controller.h" |
| 23 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 23 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 24 #include "content/browser/loader/resource_request_info_impl.h" | 24 #include "content/browser/loader/resource_request_info_impl.h" |
| 25 #include "content/browser/loader/resource_scheduler.h" | 25 #include "content/browser/loader/resource_scheduler.h" |
| 26 #include "content/browser/loader/test_url_loader_client.h" | 26 #include "content/browser/loader/test_url_loader_client.h" |
| 27 #include "content/common/resource_request_completion_status.h" | 27 #include "content/common/resource_request_completion_status.h" |
| 28 #include "content/common/url_loader.mojom.h" | 28 #include "content/common/url_loader.mojom.h" |
| 29 #include "content/common/url_loader_factory.mojom.h" |
| 29 #include "content/public/browser/appcache_service.h" | 30 #include "content/public/browser/appcache_service.h" |
| 30 #include "content/public/browser/navigation_data.h" | 31 #include "content/public/browser/navigation_data.h" |
| 31 #include "content/public/browser/resource_context.h" | 32 #include "content/public/browser/resource_context.h" |
| 32 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 33 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 33 #include "content/public/browser/resource_throttle.h" | 34 #include "content/public/browser/resource_throttle.h" |
| 34 #include "content/public/browser/stream_info.h" | 35 #include "content/public/browser/stream_info.h" |
| 35 #include "content/public/common/previews_state.h" | 36 #include "content/public/common/previews_state.h" |
| 36 #include "content/public/common/resource_response.h" | 37 #include "content/public/common/resource_response.h" |
| 37 #include "content/public/common/resource_type.h" | 38 #include "content/public/common/resource_type.h" |
| 38 #include "content/public/test/test_browser_context.h" | 39 #include "content/public/test/test_browser_context.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 }; | 286 }; |
| 286 | 287 |
| 287 class TestURLLoaderFactory final : public mojom::URLLoaderFactory { | 288 class TestURLLoaderFactory final : public mojom::URLLoaderFactory { |
| 288 public: | 289 public: |
| 289 TestURLLoaderFactory() {} | 290 TestURLLoaderFactory() {} |
| 290 ~TestURLLoaderFactory() override {} | 291 ~TestURLLoaderFactory() override {} |
| 291 | 292 |
| 292 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, | 293 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest request, |
| 293 int32_t routing_id, | 294 int32_t routing_id, |
| 294 int32_t request_id, | 295 int32_t request_id, |
| 296 uint32_t options, |
| 295 const ResourceRequest& url_request, | 297 const ResourceRequest& url_request, |
| 296 mojom::URLLoaderClientPtr client_ptr) override { | 298 mojom::URLLoaderClientPtr client_ptr) override { |
| 297 loader_request_ = std::move(request); | 299 loader_request_ = std::move(request); |
| 298 client_ptr_ = std::move(client_ptr); | 300 client_ptr_ = std::move(client_ptr); |
| 299 } | 301 } |
| 300 | 302 |
| 301 mojom::URLLoaderAssociatedRequest PassLoaderRequest() { | 303 mojom::URLLoaderAssociatedRequest PassLoaderRequest() { |
| 302 return std::move(loader_request_); | 304 return std::move(loader_request_); |
| 303 } | 305 } |
| 304 | 306 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 true, // is_async | 349 true, // is_async |
| 348 PREVIEWS_OFF // previews_state | 350 PREVIEWS_OFF // previews_state |
| 349 ); | 351 ); |
| 350 | 352 |
| 351 ResourceRequest request; | 353 ResourceRequest request; |
| 352 base::WeakPtr<mojo::StrongBinding<mojom::URLLoaderFactory>> weak_binding = | 354 base::WeakPtr<mojo::StrongBinding<mojom::URLLoaderFactory>> weak_binding = |
| 353 mojo::MakeStrongBinding(base::MakeUnique<TestURLLoaderFactory>(), | 355 mojo::MakeStrongBinding(base::MakeUnique<TestURLLoaderFactory>(), |
| 354 mojo::MakeRequest(&url_loader_factory_)); | 356 mojo::MakeRequest(&url_loader_factory_)); |
| 355 | 357 |
| 356 url_loader_factory_->CreateLoaderAndStart( | 358 url_loader_factory_->CreateLoaderAndStart( |
| 357 mojo::MakeRequest(&url_loader_proxy_), kRouteId, kRequestId, request, | 359 mojo::MakeRequest(&url_loader_proxy_), kRouteId, kRequestId, |
| 360 mojom::kURLLoadOptionNone, request, |
| 358 url_loader_client_.CreateInterfacePtr()); | 361 url_loader_client_.CreateInterfacePtr()); |
| 359 | 362 |
| 360 url_loader_factory_.FlushForTesting(); | 363 url_loader_factory_.FlushForTesting(); |
| 361 DCHECK(weak_binding); | 364 DCHECK(weak_binding); |
| 362 TestURLLoaderFactory* factory_impl = | 365 TestURLLoaderFactory* factory_impl = |
| 363 static_cast<TestURLLoaderFactory*>(weak_binding->impl()); | 366 static_cast<TestURLLoaderFactory*>(weak_binding->impl()); |
| 364 | 367 |
| 365 handler_.reset(new MojoAsyncResourceHandlerWithStubOperations( | 368 handler_.reset(new MojoAsyncResourceHandlerWithStubOperations( |
| 366 request_.get(), &rdh_, factory_impl->PassLoaderRequest(), | 369 request_.get(), &rdh_, factory_impl->PassLoaderRequest(), |
| 367 factory_impl->PassClientPtr())); | 370 factory_impl->PassClientPtr())); |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 } | 1357 } |
| 1355 } | 1358 } |
| 1356 EXPECT_EQ("B", body); | 1359 EXPECT_EQ("B", body); |
| 1357 } | 1360 } |
| 1358 | 1361 |
| 1359 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, | 1362 INSTANTIATE_TEST_CASE_P(MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1360 MojoAsyncResourceHandlerWithAllocationSizeTest, | 1363 MojoAsyncResourceHandlerWithAllocationSizeTest, |
| 1361 ::testing::Values(8, 32 * 2014)); | 1364 ::testing::Values(8, 32 * 2014)); |
| 1362 } // namespace | 1365 } // namespace |
| 1363 } // namespace content | 1366 } // namespace content |
| OLD | NEW |