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 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "content/common/resource_request_completion_status.h" | 13 #include "content/common/resource_request_completion_status.h" |
14 #include "content/common/url_loader.mojom.h" | 14 #include "content/common/url_loader.mojom.h" |
15 #include "content/common/url_loader_factory.mojom.h" | 15 #include "content/common/url_loader_factory.mojom.h" |
16 #include "content/public/common/resource_response.h" | 16 #include "content/public/common/resource_response.h" |
17 #include "mojo/public/c/system/data_pipe.h" | 17 #include "mojo/public/c/system/data_pipe.h" |
18 #include "mojo/public/cpp/bindings/associated_binding.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
19 #include "net/url_request/redirect_info.h" | 19 #include "net/url_request/redirect_info.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls | 23 // A TestURLLoaderClient records URLLoaderClient function calls. It also calls |
24 // the closure set via set_quit_closure if set, in order to make it possible to | 24 // the closure set via set_quit_closure if set, in order to make it possible to |
25 // create a base::RunLoop, set its quit closure to this client and then run the | 25 // create a base::RunLoop, set its quit closure to this client and then run the |
26 // RunLoop. | 26 // RunLoop. |
27 class TestURLLoaderClient final : public mojom::URLLoaderClient { | 27 class TestURLLoaderClient final : public mojom::URLLoaderClient { |
28 public: | 28 public: |
29 TestURLLoaderClient(); | 29 TestURLLoaderClient(); |
30 ~TestURLLoaderClient() override; | 30 ~TestURLLoaderClient() override; |
31 | 31 |
32 void OnReceiveResponse( | 32 void OnReceiveResponse(const ResourceResponseHead& response_head, |
33 const ResourceResponseHead& response_head, | 33 mojom::DownloadedTempFilePtr downloaded_file) override; |
34 mojom::DownloadedTempFileAssociatedPtrInfo downloaded_file) override; | |
35 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, | 34 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, |
36 const ResourceResponseHead& response_head) override; | 35 const ResourceResponseHead& response_head) override; |
37 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override; | 36 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override; |
38 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override; | 37 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override; |
39 void OnTransferSizeUpdated(int32_t transfer_size_diff) override; | 38 void OnTransferSizeUpdated(int32_t transfer_size_diff) override; |
40 void OnUploadProgress(int64_t current_position, | 39 void OnUploadProgress(int64_t current_position, |
41 int64_t total_size, | 40 int64_t total_size, |
42 const base::Closure& ack_callback) override; | 41 const base::Closure& ack_callback) override; |
43 void OnStartLoadingResponseBody( | 42 void OnStartLoadingResponseBody( |
44 mojo::ScopedDataPipeConsumerHandle body) override; | 43 mojo::ScopedDataPipeConsumerHandle body) override; |
(...skipping 24 matching lines...) Expand all Loading... |
69 } | 68 } |
70 int64_t body_transfer_size() const { return body_transfer_size_; } | 69 int64_t body_transfer_size() const { return body_transfer_size_; } |
71 int64_t current_upload_position() const { return current_upload_position_; } | 70 int64_t current_upload_position() const { return current_upload_position_; } |
72 int64_t total_upload_size() const { return total_upload_size_; } | 71 int64_t total_upload_size() const { return total_upload_size_; } |
73 | 72 |
74 void reset_has_received_upload_progress() { | 73 void reset_has_received_upload_progress() { |
75 has_received_upload_progress_ = false; | 74 has_received_upload_progress_ = false; |
76 } | 75 } |
77 | 76 |
78 void ClearHasReceivedRedirect(); | 77 void ClearHasReceivedRedirect(); |
79 // Creates an AssociatedPtrInfo, binds it to |*this| and returns it. The | 78 // Creates an InterfacePtr, binds it to |*this| and returns it. |
80 // returned PtrInfo is expected to be passed to the remote endpoint. | 79 mojom::URLLoaderClientPtr CreateInterfacePtr(); |
81 mojom::URLLoaderClientAssociatedPtrInfo CreateRemoteAssociatedPtrInfo(); | |
82 | 80 |
83 void Unbind(); | 81 void Unbind(); |
84 | 82 |
85 void RunUntilResponseReceived(); | 83 void RunUntilResponseReceived(); |
86 void RunUntilRedirectReceived(); | 84 void RunUntilRedirectReceived(); |
87 void RunUntilDataDownloaded(); | 85 void RunUntilDataDownloaded(); |
88 void RunUntilCachedMetadataReceived(); | 86 void RunUntilCachedMetadataReceived(); |
89 void RunUntilResponseBodyArrived(); | 87 void RunUntilResponseBodyArrived(); |
90 void RunUntilComplete(); | 88 void RunUntilComplete(); |
91 | 89 |
92 private: | 90 private: |
93 mojo::AssociatedBinding<mojom::URLLoaderClient> binding_; | 91 mojo::Binding<mojom::URLLoaderClient> binding_; |
94 ResourceResponseHead response_head_; | 92 ResourceResponseHead response_head_; |
95 net::RedirectInfo redirect_info_; | 93 net::RedirectInfo redirect_info_; |
96 std::string cached_metadata_; | 94 std::string cached_metadata_; |
97 mojo::ScopedDataPipeConsumerHandle response_body_; | 95 mojo::ScopedDataPipeConsumerHandle response_body_; |
98 ResourceRequestCompletionStatus completion_status_; | 96 ResourceRequestCompletionStatus completion_status_; |
99 bool has_received_response_ = false; | 97 bool has_received_response_ = false; |
100 bool has_received_redirect_ = false; | 98 bool has_received_redirect_ = false; |
101 bool has_data_downloaded_ = false; | 99 bool has_data_downloaded_ = false; |
102 bool has_received_upload_progress_ = false; | 100 bool has_received_upload_progress_ = false; |
103 bool has_received_cached_metadata_ = false; | 101 bool has_received_cached_metadata_ = false; |
(...skipping 10 matching lines...) Expand all Loading... |
114 int64_t body_transfer_size_ = 0; | 112 int64_t body_transfer_size_ = 0; |
115 int64_t current_upload_position_ = 0; | 113 int64_t current_upload_position_ = 0; |
116 int64_t total_upload_size_ = 0; | 114 int64_t total_upload_size_ = 0; |
117 | 115 |
118 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient); | 116 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderClient); |
119 }; | 117 }; |
120 | 118 |
121 } // namespace content | 119 } // namespace content |
122 | 120 |
123 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ | 121 #endif // CONTENT_BROWSER_LOADER_TEST_URL_LOADER_CLIENT_H_ |
OLD | NEW |