Chromium Code Reviews| Index: content/browser/loader/mojo_async_resource_handler_unittest.cc |
| diff --git a/content/browser/loader/mojo_async_resource_handler_unittest.cc b/content/browser/loader/mojo_async_resource_handler_unittest.cc |
| index 69f038a731b3aba02d4f1050a679bb31803acb39..7c4208c52a268d677fb29c3526ffa8b911fdd0a3 100644 |
| --- a/content/browser/loader/mojo_async_resource_handler_unittest.cc |
| +++ b/content/browser/loader/mojo_async_resource_handler_unittest.cc |
| @@ -33,6 +33,7 @@ |
| #include "content/public/test/test_browser_thread_bundle.h" |
| #include "mojo/public/c/system/data_pipe.h" |
| #include "mojo/public/c/system/types.h" |
| +#include "mojo/public/cpp/bindings/strong_binding.h" |
| #include "mojo/public/cpp/system/data_pipe.h" |
| #include "net/base/auth.h" |
| #include "net/base/net_errors.h" |
| @@ -267,6 +268,61 @@ class MojoAsyncResourceHandlerWithCustomDataPipeOperations |
| MojoAsyncResourceHandlerWithCustomDataPipeOperations); |
| }; |
| +class TestURLLoaderFactory final : public mojom::URLLoaderFactory { |
| + public: |
| + class Waiter final : public base::RefCounted<Waiter> { |
| + public: |
| + Waiter() = default; |
| + void Signal(mojom::URLLoaderAssociatedRequest loader_request, |
| + mojom::URLLoaderClientAssociatedPtrInfo client_ptr) { |
| + loader_request_ = std::move(loader_request); |
| + client_ptr_ = std::move(client_ptr); |
| + run_loop_.Quit(); |
| + } |
| + std::pair<mojom::URLLoaderAssociatedRequest, |
| + mojom::URLLoaderClientAssociatedPtrInfo> |
| + Wait() { |
| + run_loop_.Run(); |
| + return std::make_pair(std::move(loader_request_), std::move(client_ptr_)); |
| + } |
| + |
| + private: |
| + friend class base::RefCounted<Waiter>; |
| + ~Waiter() {} |
| + |
| + base::RunLoop run_loop_; |
| + mojom::URLLoaderAssociatedRequest loader_request_; |
| + mojom::URLLoaderClientAssociatedPtrInfo client_ptr_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Waiter); |
| + }; |
| + |
| + explicit TestURLLoaderFactory(scoped_refptr<Waiter> waiter) |
| + : waiter_(waiter) {} |
| + ~TestURLLoaderFactory() override {} |
| + |
| + void CreateLoaderAndStart( |
| + mojom::URLLoaderAssociatedRequest request, |
| + int32_t routing_id, |
| + int32_t request_id, |
| + const ResourceRequest& url_request, |
| + mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info) override { |
| + waiter_->Signal(std::move(request), std::move(client_ptr_info)); |
| + } |
| + |
| + void SyncLoad(int32_t routing_id, |
| + int32_t request_id, |
| + const ResourceRequest& url_request, |
| + const SyncLoadCallback& callback) override { |
| + NOTREACHED(); |
| + } |
| + |
| + private: |
| + scoped_refptr<Waiter> waiter_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactory); |
| +}; |
| + |
| class MojoAsyncResourceHandlerTestBase { |
| public: |
| MojoAsyncResourceHandlerTestBase() |
| @@ -294,12 +350,24 @@ class MojoAsyncResourceHandlerTestBase { |
| true, // is_async |
| false // is_using_lofi |
| ); |
| - mojom::URLLoaderClientAssociatedPtrInfo client_ptr_info = |
| - url_loader_client_.CreateLocalAssociatedPtrInfo(); |
| + |
| + ResourceRequest request; |
| + scoped_refptr<TestURLLoaderFactory::Waiter> waiter( |
|
yzshen1
2016/11/09 17:40:48
I think |waiter| may not be necessary, we could:
-
yhirano
2016/11/10 07:33:53
Thanks, done.
|
| + new TestURLLoaderFactory::Waiter()); |
| + mojo::MakeStrongBinding(base::MakeUnique<TestURLLoaderFactory>(waiter), |
| + mojo::GetProxy(&url_loader_factory_)); |
| + url_loader_factory_->CreateLoaderAndStart( |
| + mojo::GetProxy(&url_loader_proxy_, |
| + url_loader_factory_.associated_group()), |
| + 0, 0, request, url_loader_client_.CreateRemoteAssociatedPtrInfo( |
| + url_loader_factory_.associated_group())); |
| + |
| + auto pair = waiter->Wait(); |
| + |
| mojom::URLLoaderClientAssociatedPtr client_ptr; |
| - client_ptr.Bind(std::move(client_ptr_info)); |
| + client_ptr.Bind(std::move(pair.second)); |
| handler_.reset(new MojoAsyncResourceHandlerWithCustomDataPipeOperations( |
| - request_.get(), &rdh_, nullptr, std::move(client_ptr))); |
| + request_.get(), &rdh_, std::move(pair.first), std::move(client_ptr))); |
| handler_->SetController(&resource_controller_); |
| } |
| @@ -351,6 +419,8 @@ class MojoAsyncResourceHandlerTestBase { |
| TestBrowserThreadBundle thread_bundle_; |
| TestResourceDispatcherHostDelegate rdh_delegate_; |
| ResourceDispatcherHostImpl rdh_; |
| + mojom::URLLoaderFactoryPtr url_loader_factory_; |
| + mojom::URLLoaderAssociatedPtr url_loader_proxy_; |
| TestURLLoaderClient url_loader_client_; |
| TestResourceController resource_controller_; |
| std::unique_ptr<TestBrowserContext> browser_context_; |