Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: net/url_request/url_request_test_util.h

Issue 122453002: Allows deferral of a URLRequest just before talking to the network, at (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Potential fix of a memory leak due to a reference cycle. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ 5 #ifndef NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_
6 #define NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ 6 #define NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 virtual ~TestDelegate(); 123 virtual ~TestDelegate();
124 124
125 void set_cancel_in_received_redirect(bool val) { cancel_in_rr_ = val; } 125 void set_cancel_in_received_redirect(bool val) { cancel_in_rr_ = val; }
126 void set_cancel_in_response_started(bool val) { cancel_in_rs_ = val; } 126 void set_cancel_in_response_started(bool val) { cancel_in_rs_ = val; }
127 void set_cancel_in_received_data(bool val) { cancel_in_rd_ = val; } 127 void set_cancel_in_received_data(bool val) { cancel_in_rd_ = val; }
128 void set_cancel_in_received_data_pending(bool val) { 128 void set_cancel_in_received_data_pending(bool val) {
129 cancel_in_rd_pending_ = val; 129 cancel_in_rd_pending_ = val;
130 } 130 }
131 void set_quit_on_complete(bool val) { quit_on_complete_ = val; } 131 void set_quit_on_complete(bool val) { quit_on_complete_ = val; }
132 void set_quit_on_redirect(bool val) { quit_on_redirect_ = val; } 132 void set_quit_on_redirect(bool val) { quit_on_redirect_ = val; }
133 void set_quit_on_network_start(bool val) {
134 quit_on_before_network_start_ = val;
135 }
133 void set_allow_certificate_errors(bool val) { 136 void set_allow_certificate_errors(bool val) {
134 allow_certificate_errors_ = val; 137 allow_certificate_errors_ = val;
135 } 138 }
136 void set_credentials(const AuthCredentials& credentials) { 139 void set_credentials(const AuthCredentials& credentials) {
137 credentials_ = credentials; 140 credentials_ = credentials;
138 } 141 }
139 142
140 // query state 143 // query state
141 const std::string& data_received() const { return data_received_; } 144 const std::string& data_received() const { return data_received_; }
142 int bytes_received() const { return static_cast<int>(data_received_.size()); } 145 int bytes_received() const { return static_cast<int>(data_received_.size()); }
143 int response_started_count() const { return response_started_count_; } 146 int response_started_count() const { return response_started_count_; }
144 int received_redirect_count() const { return received_redirect_count_; } 147 int received_redirect_count() const { return received_redirect_count_; }
148 int received_before_network_start_count() const {
149 return received_before_network_start_count_;
150 }
145 bool received_data_before_response() const { 151 bool received_data_before_response() const {
146 return received_data_before_response_; 152 return received_data_before_response_;
147 } 153 }
148 bool request_failed() const { return request_failed_; } 154 bool request_failed() const { return request_failed_; }
149 bool have_certificate_errors() const { return have_certificate_errors_; } 155 bool have_certificate_errors() const { return have_certificate_errors_; }
150 bool certificate_errors_are_fatal() const { 156 bool certificate_errors_are_fatal() const {
151 return certificate_errors_are_fatal_; 157 return certificate_errors_are_fatal_;
152 } 158 }
153 bool auth_required_called() const { return auth_required_; } 159 bool auth_required_called() const { return auth_required_; }
154 bool have_full_request_headers() const { return have_full_request_headers_; } 160 bool have_full_request_headers() const { return have_full_request_headers_; }
155 const HttpRequestHeaders& full_request_headers() const { 161 const HttpRequestHeaders& full_request_headers() const {
156 return full_request_headers_; 162 return full_request_headers_;
157 } 163 }
158 void ClearFullRequestHeaders(); 164 void ClearFullRequestHeaders();
159 165
160 // URLRequest::Delegate: 166 // URLRequest::Delegate:
161 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url, 167 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url,
162 bool* defer_redirect) OVERRIDE; 168 bool* defer_redirect) OVERRIDE;
169 virtual void OnBeforeNetworkStart(URLRequest* request, bool* defer) OVERRIDE;
163 virtual void OnAuthRequired(URLRequest* request, 170 virtual void OnAuthRequired(URLRequest* request,
164 AuthChallengeInfo* auth_info) OVERRIDE; 171 AuthChallengeInfo* auth_info) OVERRIDE;
165 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true. 172 // NOTE: |fatal| causes |certificate_errors_are_fatal_| to be set to true.
166 // (Unit tests use this as a post-condition.) But for policy, this method 173 // (Unit tests use this as a post-condition.) But for policy, this method
167 // consults |allow_certificate_errors_|. 174 // consults |allow_certificate_errors_|.
168 virtual void OnSSLCertificateError(URLRequest* request, 175 virtual void OnSSLCertificateError(URLRequest* request,
169 const SSLInfo& ssl_info, 176 const SSLInfo& ssl_info,
170 bool fatal) OVERRIDE; 177 bool fatal) OVERRIDE;
171 virtual void OnResponseStarted(URLRequest* request) OVERRIDE; 178 virtual void OnResponseStarted(URLRequest* request) OVERRIDE;
172 virtual void OnReadCompleted(URLRequest* request, 179 virtual void OnReadCompleted(URLRequest* request,
173 int bytes_read) OVERRIDE; 180 int bytes_read) OVERRIDE;
174 181
175 private: 182 private:
176 static const int kBufferSize = 4096; 183 static const int kBufferSize = 4096;
177 184
178 virtual void OnResponseCompleted(URLRequest* request); 185 virtual void OnResponseCompleted(URLRequest* request);
179 186
180 // options for controlling behavior 187 // options for controlling behavior
181 bool cancel_in_rr_; 188 bool cancel_in_rr_;
182 bool cancel_in_rs_; 189 bool cancel_in_rs_;
183 bool cancel_in_rd_; 190 bool cancel_in_rd_;
184 bool cancel_in_rd_pending_; 191 bool cancel_in_rd_pending_;
185 bool quit_on_complete_; 192 bool quit_on_complete_;
186 bool quit_on_redirect_; 193 bool quit_on_redirect_;
194 bool quit_on_before_network_start_;
187 bool allow_certificate_errors_; 195 bool allow_certificate_errors_;
188 AuthCredentials credentials_; 196 AuthCredentials credentials_;
189 197
190 // tracks status of callbacks 198 // tracks status of callbacks
191 int response_started_count_; 199 int response_started_count_;
192 int received_bytes_count_; 200 int received_bytes_count_;
193 int received_redirect_count_; 201 int received_redirect_count_;
202 int received_before_network_start_count_;
194 bool received_data_before_response_; 203 bool received_data_before_response_;
195 bool request_failed_; 204 bool request_failed_;
196 bool have_certificate_errors_; 205 bool have_certificate_errors_;
197 bool certificate_errors_are_fatal_; 206 bool certificate_errors_are_fatal_;
198 bool auth_required_; 207 bool auth_required_;
199 std::string data_received_; 208 std::string data_received_;
200 bool have_full_request_headers_; 209 bool have_full_request_headers_;
201 HttpRequestHeaders full_request_headers_; 210 HttpRequestHeaders full_request_headers_;
202 211
203 // our read buffer 212 // our read buffer
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 NetworkDelegate* network_delegate) const OVERRIDE; 364 NetworkDelegate* network_delegate) const OVERRIDE;
356 void set_main_intercept_job(URLRequestJob* job); 365 void set_main_intercept_job(URLRequestJob* job);
357 366
358 private: 367 private:
359 mutable URLRequestJob* main_intercept_job_; 368 mutable URLRequestJob* main_intercept_job_;
360 }; 369 };
361 370
362 } // namespace net 371 } // namespace net
363 372
364 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_ 373 #endif // NET_URL_REQUEST_URL_REQUEST_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698