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_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_ |
6 #define CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 void set_on_response_started_result(bool on_response_started_result) { | 77 void set_on_response_started_result(bool on_response_started_result) { |
78 on_response_started_result_ = on_response_started_result; | 78 on_response_started_result_ = on_response_started_result; |
79 } | 79 } |
80 void set_on_will_read_result(bool on_will_read_result) { | 80 void set_on_will_read_result(bool on_will_read_result) { |
81 on_will_read_result_ = on_will_read_result; | 81 on_will_read_result_ = on_will_read_result; |
82 } | 82 } |
83 void set_on_read_completed_result(bool on_read_completed_result) { | 83 void set_on_read_completed_result(bool on_read_completed_result) { |
84 on_read_completed_result_ = on_read_completed_result; | 84 on_read_completed_result_ = on_read_completed_result; |
85 } | 85 } |
86 void set_on_on_read_eof_result(bool on_on_read_eof_result) { | 86 void set_on_read_eof_result(bool on_read_eof_result) { |
87 on_on_read_eof_result_ = on_on_read_eof_result; | 87 on_read_eof_result_ = on_read_eof_result; |
88 } | 88 } |
89 | 89 |
90 // Cause |defer| to be set to true when the specified method is invoked. The | 90 // Cause |defer| to be set to true when the specified method is invoked. The |
91 // test itself is responsible for resuming the request after deferral. | 91 // test itself is responsible for resuming the request after deferral. |
92 | 92 |
93 void set_defer_on_will_start(bool defer_on_will_start) { | 93 void set_defer_on_will_start(bool defer_on_will_start) { |
94 defer_on_will_start_ = defer_on_will_start; | 94 defer_on_will_start_ = defer_on_will_start; |
95 } | 95 } |
96 void set_defer_on_request_redirected(bool defer_on_request_redirected) { | 96 void set_defer_on_request_redirected(bool defer_on_request_redirected) { |
97 defer_on_request_redirected_ = defer_on_request_redirected; | 97 defer_on_request_redirected_ = defer_on_request_redirected; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // URL passed to OnResponseStarted, if it was called. | 139 // URL passed to OnResponseStarted, if it was called. |
140 const GURL& start_url() const { return start_url_; } | 140 const GURL& start_url() const { return start_url_; } |
141 | 141 |
142 ResourceResponse* resource_response() { return resource_response_.get(); }; | 142 ResourceResponse* resource_response() { return resource_response_.get(); }; |
143 | 143 |
144 int total_bytes_downloaded() const { return total_bytes_downloaded_; } | 144 int total_bytes_downloaded() const { return total_bytes_downloaded_; } |
145 | 145 |
146 const std::string& body() const { return body_; } | 146 const std::string& body() const { return body_; } |
147 net::URLRequestStatus final_status() const { return final_status_; } | 147 net::URLRequestStatus final_status() const { return final_status_; } |
148 | 148 |
| 149 // Returns the current number of |this|'s methods on the callstack. |
| 150 int call_depth() const { return call_depth_; } |
| 151 |
149 // Spins the message loop until the request is deferred. Using this is | 152 // Spins the message loop until the request is deferred. Using this is |
150 // optional, but if used, must use it exclusively to wait for the request. If | 153 // optional, but if used, must use it exclusively to wait for the request. If |
151 // the request was deferred and then resumed/canceled without calling this | 154 // the request was deferred and then resumed/canceled without calling this |
152 // method, behavior is undefined. | 155 // method, behavior is undefined. |
153 void WaitUntilDeferred(); | 156 void WaitUntilDeferred(); |
154 | 157 |
155 void WaitUntilResponseComplete(); | 158 void WaitUntilResponseComplete(); |
156 | 159 |
157 private: | 160 private: |
158 // TODO(mmenke): Remove these, in favor of final_status_ and body_. | 161 // TODO(mmenke): Remove these, in favor of final_status_ and body_. |
159 net::URLRequestStatus* request_status_ptr_; | 162 net::URLRequestStatus* request_status_ptr_; |
160 std::string* body_ptr_; | 163 std::string* body_ptr_; |
161 | 164 |
162 scoped_refptr<net::IOBuffer> buffer_; | 165 scoped_refptr<net::IOBuffer> buffer_; |
163 size_t buffer_size_; | 166 size_t buffer_size_; |
164 | 167 |
165 ResourceController* controller_; | 168 ResourceController* controller_; |
166 | 169 |
167 bool on_will_start_result_ = true; | 170 bool on_will_start_result_ = true; |
168 bool on_request_redirected_result_ = true; | 171 bool on_request_redirected_result_ = true; |
169 bool on_response_started_result_ = true; | 172 bool on_response_started_result_ = true; |
170 bool on_will_read_result_ = true; | 173 bool on_will_read_result_ = true; |
171 bool on_read_completed_result_ = true; | 174 bool on_read_completed_result_ = true; |
172 bool on_on_read_eof_result_ = true; | 175 bool on_read_eof_result_ = true; |
173 | 176 |
174 bool defer_on_will_start_ = false; | 177 bool defer_on_will_start_ = false; |
175 bool defer_on_request_redirected_ = false; | 178 bool defer_on_request_redirected_ = false; |
176 bool defer_on_response_started_ = false; | 179 bool defer_on_response_started_ = false; |
177 bool defer_on_read_completed_ = false; | 180 bool defer_on_read_completed_ = false; |
178 bool defer_on_read_eof_ = false; | 181 bool defer_on_read_eof_ = false; |
179 bool defer_on_response_completed_ = false; | 182 bool defer_on_response_completed_ = false; |
180 | 183 |
181 bool expect_on_data_downloaded_ = false; | 184 bool expect_on_data_downloaded_ = false; |
182 | 185 |
183 bool expect_eof_read_ = true; | 186 bool expect_eof_read_ = true; |
184 | 187 |
185 int on_will_start_called_ = 0; | 188 int on_will_start_called_ = 0; |
186 int on_request_redirected_called_ = 0; | 189 int on_request_redirected_called_ = 0; |
187 int on_response_started_called_ = 0; | 190 int on_response_started_called_ = 0; |
188 int on_will_read_called_ = 0; | 191 int on_will_read_called_ = 0; |
189 int on_read_completed_called_ = 0; | 192 int on_read_completed_called_ = 0; |
190 int on_read_eof_ = 0; | 193 int on_read_eof_ = 0; |
191 int on_response_completed_called_ = 0; | 194 int on_response_completed_called_ = 0; |
192 | 195 |
193 GURL start_url_; | 196 GURL start_url_; |
194 scoped_refptr<ResourceResponse> resource_response_; | 197 scoped_refptr<ResourceResponse> resource_response_; |
195 int total_bytes_downloaded_ = 0; | 198 int total_bytes_downloaded_ = 0; |
196 std::string body_; | 199 std::string body_; |
197 net::URLRequestStatus final_status_ = | 200 net::URLRequestStatus final_status_ = |
198 net::URLRequestStatus::FromError(net::ERR_UNEXPECTED); | 201 net::URLRequestStatus::FromError(net::ERR_UNEXPECTED); |
199 bool canceled_ = false; | 202 bool canceled_ = false; |
200 | 203 |
| 204 // Tracks recursive calls, which aren't allowed. |
| 205 int call_depth_ = 0; |
| 206 |
201 std::unique_ptr<base::RunLoop> deferred_run_loop_; | 207 std::unique_ptr<base::RunLoop> deferred_run_loop_; |
202 | 208 |
203 base::RunLoop response_complete_run_loop_; | 209 base::RunLoop response_complete_run_loop_; |
204 | 210 |
205 DISALLOW_COPY_AND_ASSIGN(TestResourceHandler); | 211 DISALLOW_COPY_AND_ASSIGN(TestResourceHandler); |
206 }; | 212 }; |
207 | 213 |
208 } // namespace content | 214 } // namespace content |
209 | 215 |
210 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_ | 216 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_H_ |
OLD | NEW |