| 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 #ifndef CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ |
| 6 #define CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ | 6 #define CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/common/resource_request_completion_status.h" | 10 #include "content/common/resource_request_completion_status.h" |
| 11 #include "content/common/url_loader.mojom.h" | 11 #include "content/common/url_loader.mojom.h" |
| 12 #include "content/common/url_loader_factory.mojom.h" |
| 12 #include "content/public/common/resource_response.h" | 13 #include "content/public/common/resource_response.h" |
| 13 #include "mojo/public/c/system/data_pipe.h" | 14 #include "mojo/public/c/system/data_pipe.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls | 19 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls |
| 19 // the closure set via set_quit_closure if set, in order to make it possible to | 20 // the closure set via set_quit_closure if set, in order to make it possible to |
| 20 // create a base::RunLoop, set its quit closure to this client and then run the | 21 // create a base::RunLoop, set its quit closure to this client and then run the |
| 21 // RunLoop. | 22 // RunLoop. |
| 22 class TestURLLoaderClient final : public mojom::URLLoaderClient { | 23 class TestURLLoaderClient final : public mojom::URLLoaderClient { |
| 23 public: | 24 public: |
| 24 TestURLLoaderClient(); | 25 TestURLLoaderClient(); |
| 25 ~TestURLLoaderClient() override; | 26 ~TestURLLoaderClient() override; |
| 26 | 27 |
| 27 void OnReceiveResponse(const ResourceResponseHead& response_head) override; | 28 void OnReceiveResponse(const ResourceResponseHead& response_head) override; |
| 28 void OnStartLoadingResponseBody( | 29 void OnStartLoadingResponseBody( |
| 29 mojo::ScopedDataPipeConsumerHandle body) override; | 30 mojo::ScopedDataPipeConsumerHandle body) override; |
| 30 void OnComplete(const ResourceRequestCompletionStatus& status) override; | 31 void OnComplete(const ResourceRequestCompletionStatus& status) override; |
| 31 | 32 |
| 32 bool has_received_response() const { return has_received_response_; } | 33 bool has_received_response() const { return has_received_response_; } |
| 33 bool has_received_completion() const { return has_received_completion_; } | 34 bool has_received_completion() const { return has_received_completion_; } |
| 34 const ResourceResponseHead& response_head() const { return response_head_; } | 35 const ResourceResponseHead& response_head() const { return response_head_; } |
| 35 mojo::DataPipeConsumerHandle response_body() { return response_body_.get(); } | 36 mojo::DataPipeConsumerHandle response_body() { return response_body_.get(); } |
| 36 const ResourceRequestCompletionStatus& completion_status() const { | 37 const ResourceRequestCompletionStatus& completion_status() const { |
| 37 return completion_status_; | 38 return completion_status_; |
| 38 } | 39 } |
| 40 // Creates an AssociatedPtrInfo which is a proxy for |*this| and returns it. |
| 41 // The returned PtrInfo is marked as local, i.e., expected to be bound |
| 42 // locally. |
| 43 mojom::URLLoaderClientAssociatedPtrInfo CreateLocalAssociatedPtrInfo(); |
| 39 | 44 |
| 40 mojom::URLLoaderClientPtr CreateInterfacePtrAndBind(); | 45 // Creates an AssociatedPtrInfo, binds it to |*this| and returns it. The |
| 46 // returned PtrInfo is marked as remote, i.e., expected to be passed to the |
| 47 // remote endpoint. |
| 48 mojom::URLLoaderClientAssociatedPtrInfo CreateRemoteAssociatedPtrInfo( |
| 49 mojo::AssociatedGroup* associated_group); |
| 50 |
| 41 void Unbind(); | 51 void Unbind(); |
| 42 | 52 |
| 43 void RunUntilResponseReceived(); | 53 void RunUntilResponseReceived(); |
| 44 void RunUntilResponseBodyArrived(); | 54 void RunUntilResponseBodyArrived(); |
| 45 void RunUntilComplete(); | 55 void RunUntilComplete(); |
| 46 | 56 |
| 47 private: | 57 private: |
| 48 mojo::Binding<mojom::URLLoaderClient> binding_; | 58 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_; |
| 49 ResourceResponseHead response_head_; | 59 ResourceResponseHead response_head_; |
| 50 mojo::ScopedDataPipeConsumerHandle response_body_; | 60 mojo::ScopedDataPipeConsumerHandle response_body_; |
| 51 ResourceRequestCompletionStatus completion_status_; | 61 ResourceRequestCompletionStatus completion_status_; |
| 52 bool has_received_response_ = false; | 62 bool has_received_response_ = false; |
| 53 bool has_received_completion_ = false; | 63 bool has_received_completion_ = false; |
| 54 base::Closure quit_closure_for_on_received_response_; | 64 base::Closure quit_closure_for_on_received_response_; |
| 55 base::Closure quit_closure_for_on_start_loading_response_body_; | 65 base::Closure quit_closure_for_on_start_loading_response_body_; |
| 56 base::Closure quit_closure_for_on_complete_; | 66 base::Closure quit_closure_for_on_complete_; |
| 67 mojom::URLLoaderFactoryPtr url_loader_factory_; |
| 57 | 68 |
| 58 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient); | 69 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient); |
| 59 }; | 70 }; |
| 60 | 71 |
| 61 } // namespace content | 72 } // namespace content |
| 62 | 73 |
| 63 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ | 74 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ |
| OLD | NEW |