| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_UNITTEST_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class TestDelegate : public URLRequest::Delegate { | 64 class TestDelegate : public URLRequest::Delegate { |
| 65 public: | 65 public: |
| 66 TestDelegate() | 66 TestDelegate() |
| 67 : cancel_in_rr_(false), | 67 : cancel_in_rr_(false), |
| 68 cancel_in_rs_(false), | 68 cancel_in_rs_(false), |
| 69 cancel_in_rd_(false), | 69 cancel_in_rd_(false), |
| 70 cancel_in_rd_pending_(false), | 70 cancel_in_rd_pending_(false), |
| 71 quit_on_complete_(true), | 71 quit_on_complete_(true), |
| 72 allow_certificate_errors_(false), |
| 72 response_started_count_(0), | 73 response_started_count_(0), |
| 73 received_bytes_count_(0), | 74 received_bytes_count_(0), |
| 74 received_redirect_count_(0), | 75 received_redirect_count_(0), |
| 75 received_data_before_response_(false), | 76 received_data_before_response_(false), |
| 76 request_failed_(false), | 77 request_failed_(false), |
| 78 have_certificate_errors_(false), |
| 77 buf_(new net::IOBuffer(kBufferSize)) { | 79 buf_(new net::IOBuffer(kBufferSize)) { |
| 78 } | 80 } |
| 79 | 81 |
| 80 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url) { | 82 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url) { |
| 81 received_redirect_count_++; | 83 received_redirect_count_++; |
| 82 if (cancel_in_rr_) | 84 if (cancel_in_rr_) |
| 83 request->Cancel(); | 85 request->Cancel(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 virtual void OnResponseStarted(URLRequest* request) { | 88 virtual void OnResponseStarted(URLRequest* request) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (!username_.empty() || !password_.empty()) { | 153 if (!username_.empty() || !password_.empty()) { |
| 152 request->SetAuth(username_, password_); | 154 request->SetAuth(username_, password_); |
| 153 } else { | 155 } else { |
| 154 request->CancelAuth(); | 156 request->CancelAuth(); |
| 155 } | 157 } |
| 156 } | 158 } |
| 157 | 159 |
| 158 virtual void OnSSLCertificateError(URLRequest* request, | 160 virtual void OnSSLCertificateError(URLRequest* request, |
| 159 int cert_error, | 161 int cert_error, |
| 160 net::X509Certificate* cert) { | 162 net::X509Certificate* cert) { |
| 161 // Ignore SSL errors, we test the server is started and shut it down by | 163 // The caller can control whether it needs all SSL requests to go through, |
| 162 // performing GETs, no security restrictions should apply as we always want | 164 // independent of any possible errors, or whether it wants SSL errors to |
| 163 // these GETs to go through. | 165 // cancel the request. |
| 164 request->ContinueDespiteLastError(); | 166 have_certificate_errors_ = true; |
| 167 if (allow_certificate_errors_) |
| 168 request->ContinueDespiteLastError(); |
| 169 else |
| 170 request->Cancel(); |
| 165 } | 171 } |
| 166 | 172 |
| 167 void set_cancel_in_received_redirect(bool val) { cancel_in_rr_ = val; } | 173 void set_cancel_in_received_redirect(bool val) { cancel_in_rr_ = val; } |
| 168 void set_cancel_in_response_started(bool val) { cancel_in_rs_ = val; } | 174 void set_cancel_in_response_started(bool val) { cancel_in_rs_ = val; } |
| 169 void set_cancel_in_received_data(bool val) { cancel_in_rd_ = val; } | 175 void set_cancel_in_received_data(bool val) { cancel_in_rd_ = val; } |
| 170 void set_cancel_in_received_data_pending(bool val) { | 176 void set_cancel_in_received_data_pending(bool val) { |
| 171 cancel_in_rd_pending_ = val; | 177 cancel_in_rd_pending_ = val; |
| 172 } | 178 } |
| 173 void set_quit_on_complete(bool val) { quit_on_complete_ = val; } | 179 void set_quit_on_complete(bool val) { quit_on_complete_ = val; } |
| 180 void set_allow_certificate_errors(bool val) { |
| 181 allow_certificate_errors_ = val; |
| 182 } |
| 174 void set_username(const std::wstring& u) { username_ = u; } | 183 void set_username(const std::wstring& u) { username_ = u; } |
| 175 void set_password(const std::wstring& p) { password_ = p; } | 184 void set_password(const std::wstring& p) { password_ = p; } |
| 176 | 185 |
| 177 // query state | 186 // query state |
| 178 const std::string& data_received() const { return data_received_; } | 187 const std::string& data_received() const { return data_received_; } |
| 179 int bytes_received() const { return static_cast<int>(data_received_.size()); } | 188 int bytes_received() const { return static_cast<int>(data_received_.size()); } |
| 180 int response_started_count() const { return response_started_count_; } | 189 int response_started_count() const { return response_started_count_; } |
| 181 int received_redirect_count() const { return received_redirect_count_; } | 190 int received_redirect_count() const { return received_redirect_count_; } |
| 182 bool received_data_before_response() const { | 191 bool received_data_before_response() const { |
| 183 return received_data_before_response_; | 192 return received_data_before_response_; |
| 184 } | 193 } |
| 185 bool request_failed() const { return request_failed_; } | 194 bool request_failed() const { return request_failed_; } |
| 195 bool have_certificate_errors() const { return have_certificate_errors_; } |
| 186 | 196 |
| 187 private: | 197 private: |
| 188 static const int kBufferSize = 4096; | 198 static const int kBufferSize = 4096; |
| 189 // options for controlling behavior | 199 // options for controlling behavior |
| 190 bool cancel_in_rr_; | 200 bool cancel_in_rr_; |
| 191 bool cancel_in_rs_; | 201 bool cancel_in_rs_; |
| 192 bool cancel_in_rd_; | 202 bool cancel_in_rd_; |
| 193 bool cancel_in_rd_pending_; | 203 bool cancel_in_rd_pending_; |
| 194 bool quit_on_complete_; | 204 bool quit_on_complete_; |
| 205 bool allow_certificate_errors_; |
| 195 | 206 |
| 196 std::wstring username_; | 207 std::wstring username_; |
| 197 std::wstring password_; | 208 std::wstring password_; |
| 198 | 209 |
| 199 // tracks status of callbacks | 210 // tracks status of callbacks |
| 200 int response_started_count_; | 211 int response_started_count_; |
| 201 int received_bytes_count_; | 212 int received_bytes_count_; |
| 202 int received_redirect_count_; | 213 int received_redirect_count_; |
| 203 bool received_data_before_response_; | 214 bool received_data_before_response_; |
| 204 bool request_failed_; | 215 bool request_failed_; |
| 216 bool have_certificate_errors_; |
| 205 std::string data_received_; | 217 std::string data_received_; |
| 206 | 218 |
| 207 // our read buffer | 219 // our read buffer |
| 208 scoped_refptr<net::IOBuffer> buf_; | 220 scoped_refptr<net::IOBuffer> buf_; |
| 209 }; | 221 }; |
| 210 | 222 |
| 211 // This object bounds the lifetime of an external python-based HTTP/FTP server | 223 // This object bounds the lifetime of an external python-based HTTP/FTP server |
| 212 // that can provide various responses useful for testing. | 224 // that can provide various responses useful for testing. |
| 213 class BaseTestServer : public base::RefCounted<BaseTestServer> { | 225 class BaseTestServer : public base::RefCounted<BaseTestServer> { |
| 214 protected: | 226 protected: |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 MessageLoop::current()->Run(); | 536 MessageLoop::current()->Run(); |
| 525 if (request.is_pending()) | 537 if (request.is_pending()) |
| 526 return false; | 538 return false; |
| 527 | 539 |
| 528 return true; | 540 return true; |
| 529 } | 541 } |
| 530 | 542 |
| 531 }; | 543 }; |
| 532 | 544 |
| 533 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ | 545 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
| OLD | NEW |