| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class TestDelegate : public URLRequest::Delegate { | 69 class TestDelegate : public URLRequest::Delegate { |
| 70 public: | 70 public: |
| 71 TestDelegate() | 71 TestDelegate() |
| 72 : cancel_in_rr_(false), | 72 : cancel_in_rr_(false), |
| 73 cancel_in_rs_(false), | 73 cancel_in_rs_(false), |
| 74 cancel_in_rd_(false), | 74 cancel_in_rd_(false), |
| 75 cancel_in_rd_pending_(false), | 75 cancel_in_rd_pending_(false), |
| 76 quit_on_complete_(true), | 76 quit_on_complete_(true), |
| 77 quit_on_redirect_(false), |
| 77 allow_certificate_errors_(false), | 78 allow_certificate_errors_(false), |
| 78 response_started_count_(0), | 79 response_started_count_(0), |
| 79 received_bytes_count_(0), | 80 received_bytes_count_(0), |
| 80 received_redirect_count_(0), | 81 received_redirect_count_(0), |
| 81 received_data_before_response_(false), | 82 received_data_before_response_(false), |
| 82 request_failed_(false), | 83 request_failed_(false), |
| 83 have_certificate_errors_(false), | 84 have_certificate_errors_(false), |
| 84 buf_(new net::IOBuffer(kBufferSize)) { | 85 buf_(new net::IOBuffer(kBufferSize)) { |
| 85 } | 86 } |
| 86 | 87 |
| 87 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url) { | 88 virtual void OnReceivedRedirect(URLRequest* request, const GURL& new_url, |
| 89 bool* defer_redirect) { |
| 88 received_redirect_count_++; | 90 received_redirect_count_++; |
| 89 if (cancel_in_rr_) | 91 if (quit_on_redirect_) { |
| 92 *defer_redirect = true; |
| 93 MessageLoop::current()->Quit(); |
| 94 } else if (cancel_in_rr_) { |
| 90 request->Cancel(); | 95 request->Cancel(); |
| 96 } |
| 91 } | 97 } |
| 92 | 98 |
| 93 virtual void OnResponseStarted(URLRequest* request) { | 99 virtual void OnResponseStarted(URLRequest* request) { |
| 94 // It doesn't make sense for the request to have IO pending at this point. | 100 // It doesn't make sense for the request to have IO pending at this point. |
| 95 DCHECK(!request->status().is_io_pending()); | 101 DCHECK(!request->status().is_io_pending()); |
| 96 | 102 |
| 97 response_started_count_++; | 103 response_started_count_++; |
| 98 if (cancel_in_rs_) { | 104 if (cancel_in_rs_) { |
| 99 request->Cancel(); | 105 request->Cancel(); |
| 100 OnResponseCompleted(request); | 106 OnResponseCompleted(request); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 request->Cancel(); | 181 request->Cancel(); |
| 176 } | 182 } |
| 177 | 183 |
| 178 void set_cancel_in_received_redirect(bool val) { cancel_in_rr_ = val; } | 184 void set_cancel_in_received_redirect(bool val) { cancel_in_rr_ = val; } |
| 179 void set_cancel_in_response_started(bool val) { cancel_in_rs_ = val; } | 185 void set_cancel_in_response_started(bool val) { cancel_in_rs_ = val; } |
| 180 void set_cancel_in_received_data(bool val) { cancel_in_rd_ = val; } | 186 void set_cancel_in_received_data(bool val) { cancel_in_rd_ = val; } |
| 181 void set_cancel_in_received_data_pending(bool val) { | 187 void set_cancel_in_received_data_pending(bool val) { |
| 182 cancel_in_rd_pending_ = val; | 188 cancel_in_rd_pending_ = val; |
| 183 } | 189 } |
| 184 void set_quit_on_complete(bool val) { quit_on_complete_ = val; } | 190 void set_quit_on_complete(bool val) { quit_on_complete_ = val; } |
| 191 void set_quit_on_redirect(bool val) { quit_on_redirect_ = val; } |
| 185 void set_allow_certificate_errors(bool val) { | 192 void set_allow_certificate_errors(bool val) { |
| 186 allow_certificate_errors_ = val; | 193 allow_certificate_errors_ = val; |
| 187 } | 194 } |
| 188 void set_username(const std::wstring& u) { username_ = u; } | 195 void set_username(const std::wstring& u) { username_ = u; } |
| 189 void set_password(const std::wstring& p) { password_ = p; } | 196 void set_password(const std::wstring& p) { password_ = p; } |
| 190 | 197 |
| 191 // query state | 198 // query state |
| 192 const std::string& data_received() const { return data_received_; } | 199 const std::string& data_received() const { return data_received_; } |
| 193 int bytes_received() const { return static_cast<int>(data_received_.size()); } | 200 int bytes_received() const { return static_cast<int>(data_received_.size()); } |
| 194 int response_started_count() const { return response_started_count_; } | 201 int response_started_count() const { return response_started_count_; } |
| 195 int received_redirect_count() const { return received_redirect_count_; } | 202 int received_redirect_count() const { return received_redirect_count_; } |
| 196 bool received_data_before_response() const { | 203 bool received_data_before_response() const { |
| 197 return received_data_before_response_; | 204 return received_data_before_response_; |
| 198 } | 205 } |
| 199 bool request_failed() const { return request_failed_; } | 206 bool request_failed() const { return request_failed_; } |
| 200 bool have_certificate_errors() const { return have_certificate_errors_; } | 207 bool have_certificate_errors() const { return have_certificate_errors_; } |
| 201 | 208 |
| 202 private: | 209 private: |
| 203 static const int kBufferSize = 4096; | 210 static const int kBufferSize = 4096; |
| 204 // options for controlling behavior | 211 // options for controlling behavior |
| 205 bool cancel_in_rr_; | 212 bool cancel_in_rr_; |
| 206 bool cancel_in_rs_; | 213 bool cancel_in_rs_; |
| 207 bool cancel_in_rd_; | 214 bool cancel_in_rd_; |
| 208 bool cancel_in_rd_pending_; | 215 bool cancel_in_rd_pending_; |
| 209 bool quit_on_complete_; | 216 bool quit_on_complete_; |
| 217 bool quit_on_redirect_; |
| 210 bool allow_certificate_errors_; | 218 bool allow_certificate_errors_; |
| 211 | 219 |
| 212 std::wstring username_; | 220 std::wstring username_; |
| 213 std::wstring password_; | 221 std::wstring password_; |
| 214 | 222 |
| 215 // tracks status of callbacks | 223 // tracks status of callbacks |
| 216 int response_started_count_; | 224 int response_started_count_; |
| 217 int received_bytes_count_; | 225 int received_bytes_count_; |
| 218 int received_redirect_count_; | 226 int received_redirect_count_; |
| 219 bool received_data_before_response_; | 227 bool received_data_before_response_; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 557 |
| 550 MessageLoop::current()->Run(); | 558 MessageLoop::current()->Run(); |
| 551 if (request.is_pending()) | 559 if (request.is_pending()) |
| 552 return false; | 560 return false; |
| 553 | 561 |
| 554 return true; | 562 return true; |
| 555 } | 563 } |
| 556 }; | 564 }; |
| 557 | 565 |
| 558 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ | 566 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
| OLD | NEW |