| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "content/common/resource_request_completion_status.h" | 12 #include "content/common/resource_request_completion_status.h" |
| 13 #include "content/common/url_loader.mojom.h" | 13 #include "content/common/url_loader.mojom.h" |
| 14 #include "content/common/url_loader_factory.mojom.h" | 14 #include "content/common/url_loader_factory.mojom.h" |
| 15 #include "content/public/common/resource_response.h" | 15 #include "content/public/common/resource_response.h" |
| 16 #include "mojo/public/c/system/data_pipe.h" | 16 #include "mojo/public/c/system/data_pipe.h" |
| 17 #include "mojo/public/cpp/bindings/associated_binding.h" | 17 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 18 #include "net/url_request/redirect_info.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls | 22 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls |
| 22 // the closure set via set_quit_closure if set, in order to make it possible to | 23 // the closure set via set_quit_closure if set, in order to make it possible to |
| 23 // create a base::RunLoop, set its quit closure to this client and then run the | 24 // create a base::RunLoop, set its quit closure to this client and then run the |
| 24 // RunLoop. | 25 // RunLoop. |
| 25 class TestURLLoaderClient final : public mojom::URLLoaderClient { | 26 class TestURLLoaderClient final : public mojom::URLLoaderClient { |
| 26 public: | 27 public: |
| 27 TestURLLoaderClient(); | 28 TestURLLoaderClient(); |
| 28 ~TestURLLoaderClient() override; | 29 ~TestURLLoaderClient() override; |
| 29 | 30 |
| 30 void OnReceiveResponse(const ResourceResponseHead& response_head) override; | 31 void OnReceiveResponse(const ResourceResponseHead& response_head) override; |
| 32 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, |
| 33 const ResourceResponseHead& response_head) override; |
| 31 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override; | 34 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override; |
| 32 void OnStartLoadingResponseBody( | 35 void OnStartLoadingResponseBody( |
| 33 mojo::ScopedDataPipeConsumerHandle body) override; | 36 mojo::ScopedDataPipeConsumerHandle body) override; |
| 34 void OnComplete(const ResourceRequestCompletionStatus& status) override; | 37 void OnComplete(const ResourceRequestCompletionStatus& status) override; |
| 35 | 38 |
| 36 bool has_received_response() const { return has_received_response_; } | 39 bool has_received_response() const { return has_received_response_; } |
| 40 bool has_received_redirect() const { return has_received_redirect_; } |
| 37 bool has_data_downloaded() const { return has_data_downloaded_; } | 41 bool has_data_downloaded() const { return has_data_downloaded_; } |
| 38 bool has_received_completion() const { return has_received_completion_; } | 42 bool has_received_completion() const { return has_received_completion_; } |
| 39 const ResourceResponseHead& response_head() const { return response_head_; } | 43 const ResourceResponseHead& response_head() const { return response_head_; } |
| 44 const net::RedirectInfo& redirect_info() const { return redirect_info_; } |
| 40 mojo::DataPipeConsumerHandle response_body() { return response_body_.get(); } | 45 mojo::DataPipeConsumerHandle response_body() { return response_body_.get(); } |
| 41 const ResourceRequestCompletionStatus& completion_status() const { | 46 const ResourceRequestCompletionStatus& completion_status() const { |
| 42 return completion_status_; | 47 return completion_status_; |
| 43 } | 48 } |
| 44 int64_t download_data_length() const { return download_data_length_; } | 49 int64_t download_data_length() const { return download_data_length_; } |
| 45 int64_t encoded_download_data_length() const { | 50 int64_t encoded_download_data_length() const { |
| 46 return encoded_download_data_length_; | 51 return encoded_download_data_length_; |
| 47 } | 52 } |
| 48 | 53 |
| 54 void ClearHasReceivedRedirect(); |
| 49 // Creates an AssociatedPtrInfo, binds it to |*this| and returns it. The | 55 // Creates an AssociatedPtrInfo, binds it to |*this| and returns it. The |
| 50 // returned PtrInfo is marked as remote, i.e., expected to be passed to the | 56 // returned PtrInfo is marked as remote, i.e., expected to be passed to the |
| 51 // remote endpoint. | 57 // remote endpoint. |
| 52 mojom::URLLoaderClientAssociatedPtrInfo CreateRemoteAssociatedPtrInfo( | 58 mojom::URLLoaderClientAssociatedPtrInfo CreateRemoteAssociatedPtrInfo( |
| 53 mojo::AssociatedGroup* associated_group); | 59 mojo::AssociatedGroup* associated_group); |
| 54 | 60 |
| 55 void Unbind(); | 61 void Unbind(); |
| 56 | 62 |
| 57 void RunUntilResponseReceived(); | 63 void RunUntilResponseReceived(); |
| 64 void RunUntilRedirectReceived(); |
| 58 void RunUntilDataDownloaded(); | 65 void RunUntilDataDownloaded(); |
| 59 void RunUntilResponseBodyArrived(); | 66 void RunUntilResponseBodyArrived(); |
| 60 void RunUntilComplete(); | 67 void RunUntilComplete(); |
| 61 | 68 |
| 62 private: | 69 private: |
| 63 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_; | 70 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_; |
| 64 ResourceResponseHead response_head_; | 71 ResourceResponseHead response_head_; |
| 72 net::RedirectInfo redirect_info_; |
| 65 mojo::ScopedDataPipeConsumerHandle response_body_; | 73 mojo::ScopedDataPipeConsumerHandle response_body_; |
| 66 ResourceRequestCompletionStatus completion_status_; | 74 ResourceRequestCompletionStatus completion_status_; |
| 67 bool has_received_response_ = false; | 75 bool has_received_response_ = false; |
| 76 bool has_received_redirect_ = false; |
| 68 bool has_data_downloaded_ = false; | 77 bool has_data_downloaded_ = false; |
| 69 bool has_received_completion_ = false; | 78 bool has_received_completion_ = false; |
| 70 base::Closure quit_closure_for_on_received_response_; | 79 base::Closure quit_closure_for_on_receive_response_; |
| 80 base::Closure quit_closure_for_on_receive_redirect_; |
| 71 base::Closure quit_closure_for_on_data_downloaded_; | 81 base::Closure quit_closure_for_on_data_downloaded_; |
| 72 base::Closure quit_closure_for_on_start_loading_response_body_; | 82 base::Closure quit_closure_for_on_start_loading_response_body_; |
| 73 base::Closure quit_closure_for_on_complete_; | 83 base::Closure quit_closure_for_on_complete_; |
| 74 mojom::URLLoaderFactoryPtr url_loader_factory_; | 84 mojom::URLLoaderFactoryPtr url_loader_factory_; |
| 75 int64_t download_data_length_ = 0; | 85 int64_t download_data_length_ = 0; |
| 76 int64_t encoded_download_data_length_ = 0; | 86 int64_t encoded_download_data_length_ = 0; |
| 77 | 87 |
| 78 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient); | 88 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient); |
| 79 }; | 89 }; |
| 80 | 90 |
| 81 } // namespace content | 91 } // namespace content |
| 82 | 92 |
| 83 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ | 93 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ |
| OLD | NEW |