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

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

Issue 9572001: Do cookie checks in NetworkDelegate instead of the URLRequest::Delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TestShellNetworkDelegate Created 8 years, 9 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 | Annotate | Revision Log
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 #include "net/url_request/url_request_test_util.h" 5 #include "net/url_request/url_request_test_util.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 TestURLRequest::~TestURLRequest() {} 165 TestURLRequest::~TestURLRequest() {}
166 166
167 TestDelegate::TestDelegate() 167 TestDelegate::TestDelegate()
168 : cancel_in_rr_(false), 168 : cancel_in_rr_(false),
169 cancel_in_rs_(false), 169 cancel_in_rs_(false),
170 cancel_in_rd_(false), 170 cancel_in_rd_(false),
171 cancel_in_rd_pending_(false), 171 cancel_in_rd_pending_(false),
172 quit_on_complete_(true), 172 quit_on_complete_(true),
173 quit_on_redirect_(false), 173 quit_on_redirect_(false),
174 allow_certificate_errors_(false), 174 allow_certificate_errors_(false),
175 cookie_options_bit_mask_(0),
176 response_started_count_(0), 175 response_started_count_(0),
177 received_bytes_count_(0), 176 received_bytes_count_(0),
178 received_redirect_count_(0), 177 received_redirect_count_(0),
179 blocked_get_cookies_count_(0),
180 blocked_set_cookie_count_(0),
181 set_cookie_count_(0),
182 received_data_before_response_(false), 178 received_data_before_response_(false),
183 request_failed_(false), 179 request_failed_(false),
184 have_certificate_errors_(false), 180 have_certificate_errors_(false),
185 certificate_errors_are_fatal_(false), 181 certificate_errors_are_fatal_(false),
186 auth_required_(false), 182 auth_required_(false),
187 buf_(new net::IOBuffer(kBufferSize)) { 183 buf_(new net::IOBuffer(kBufferSize)) {
188 } 184 }
189 185
190 TestDelegate::~TestDelegate() {} 186 TestDelegate::~TestDelegate() {}
191 187
(...skipping 26 matching lines...) Expand all
218 // independent of any possible errors, or whether it wants SSL errors to 214 // independent of any possible errors, or whether it wants SSL errors to
219 // cancel the request. 215 // cancel the request.
220 have_certificate_errors_ = true; 216 have_certificate_errors_ = true;
221 certificate_errors_are_fatal_ = fatal; 217 certificate_errors_are_fatal_ = fatal;
222 if (allow_certificate_errors_) 218 if (allow_certificate_errors_)
223 request->ContinueDespiteLastError(); 219 request->ContinueDespiteLastError();
224 else 220 else
225 request->Cancel(); 221 request->Cancel();
226 } 222 }
227 223
228 bool TestDelegate::CanGetCookies(const net::URLRequest* request,
229 const net::CookieList& cookie_list) const {
230 bool allow = true;
231 if (cookie_options_bit_mask_ & NO_GET_COOKIES)
232 allow = false;
233
234 if (!allow) {
235 blocked_get_cookies_count_++;
236 }
237
238 return allow;
239 }
240
241 bool TestDelegate::CanSetCookie(const net::URLRequest* request,
242 const std::string& cookie_line,
243 net::CookieOptions* options) const {
244 bool allow = true;
245 if (cookie_options_bit_mask_ & NO_SET_COOKIE)
246 allow = false;
247
248 if (cookie_options_bit_mask_ & FORCE_SESSION)
249 options->set_force_session();
250
251
252 if (!allow) {
253 blocked_set_cookie_count_++;
254 } else {
255 set_cookie_count_++;
256 }
257
258 return allow;
259 }
260
261 void TestDelegate::OnResponseStarted(net::URLRequest* request) { 224 void TestDelegate::OnResponseStarted(net::URLRequest* request) {
262 // It doesn't make sense for the request to have IO pending at this point. 225 // It doesn't make sense for the request to have IO pending at this point.
263 DCHECK(!request->status().is_io_pending()); 226 DCHECK(!request->status().is_io_pending());
264 227
265 response_started_count_++; 228 response_started_count_++;
266 if (cancel_in_rs_) { 229 if (cancel_in_rs_) {
267 request->Cancel(); 230 request->Cancel();
268 OnResponseCompleted(request); 231 OnResponseCompleted(request);
269 } else if (!request->status().is_success()) { 232 } else if (!request->status().is_success()) {
270 DCHECK(request->status().status() == net::URLRequestStatus::FAILED || 233 DCHECK(request->status().status() == net::URLRequestStatus::FAILED ||
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 else if (cancel_in_rd_pending_) 279 else if (cancel_in_rd_pending_)
317 request->Cancel(); 280 request->Cancel();
318 } 281 }
319 282
320 void TestDelegate::OnResponseCompleted(net::URLRequest* request) { 283 void TestDelegate::OnResponseCompleted(net::URLRequest* request) {
321 if (quit_on_complete_) 284 if (quit_on_complete_)
322 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 285 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
323 } 286 }
324 287
325 TestNetworkDelegate::TestNetworkDelegate() 288 TestNetworkDelegate::TestNetworkDelegate()
326 : last_error_(0), 289 : last_error_(0),
327 error_count_(0), 290 error_count_(0),
328 created_requests_(0), 291 created_requests_(0),
329 destroyed_requests_(0), 292 destroyed_requests_(0),
330 completed_requests_(0) { 293 completed_requests_(0),
294 cookie_options_bit_mask_(0),
295 blocked_get_cookies_count_(0),
296 blocked_set_cookie_count_(0),
297 set_cookie_count_(0) {
331 } 298 }
332 299
333 TestNetworkDelegate::~TestNetworkDelegate() { 300 TestNetworkDelegate::~TestNetworkDelegate() {
334 for (std::map<int, int>::iterator i = next_states_.begin(); 301 for (std::map<int, int>::iterator i = next_states_.begin();
335 i != next_states_.end(); ++i) { 302 i != next_states_.end(); ++i) {
336 event_order_[i->first] += "~TestNetworkDelegate\n"; 303 event_order_[i->first] += "~TestNetworkDelegate\n";
337 EXPECT_TRUE(i->second & kStageDestruction) << event_order_[i->first]; 304 EXPECT_TRUE(i->second & kStageDestruction) << event_order_[i->first];
338 } 305 }
339 } 306 }
340 307
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 EXPECT_TRUE(next_states_[req_id] & kStageAuthRequired) << 465 EXPECT_TRUE(next_states_[req_id] & kStageAuthRequired) <<
499 event_order_[req_id]; 466 event_order_[req_id];
500 next_states_[req_id] = kStageBeforeSendHeaders | 467 next_states_[req_id] = kStageBeforeSendHeaders |
501 kStageHeadersReceived | // Request canceled by delegate simulates empty 468 kStageHeadersReceived | // Request canceled by delegate simulates empty
502 // response. 469 // response.
503 kStageResponseStarted | // data: URLs do not trigger sending headers 470 kStageResponseStarted | // data: URLs do not trigger sending headers
504 kStageBeforeRedirect; // a delegate can trigger a redirection 471 kStageBeforeRedirect; // a delegate can trigger a redirection
505 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 472 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
506 } 473 }
507 474
475 bool TestNetworkDelegate::CanGetCookies(const net::URLRequest* request,
476 const net::CookieList& cookie_list) {
477 bool allow = true;
478 if (cookie_options_bit_mask_ & NO_GET_COOKIES)
479 allow = false;
480
481 if (!allow) {
482 blocked_get_cookies_count_++;
483 }
484
485 return allow;
486 }
487
488 bool TestNetworkDelegate::CanSetCookie(const net::URLRequest* request,
489 const std::string& cookie_line,
490 net::CookieOptions* options) {
491 bool allow = true;
492 if (cookie_options_bit_mask_ & NO_SET_COOKIE)
493 allow = false;
494
495 if (cookie_options_bit_mask_ & FORCE_SESSION)
496 options->set_force_session();
497
498
willchan no longer on Chromium 2012/03/06 02:59:01 1 too many lines
jochen (gone - plz use gerrit) 2012/03/08 13:00:02 Done.
499 if (!allow) {
500 blocked_set_cookie_count_++;
501 } else {
502 set_cookie_count_++;
503 }
504
505 return allow;
506 }
507
508 // static 508 // static
509 std::string ScopedCustomUrlRequestTestHttpHost::value_("127.0.0.1"); 509 std::string ScopedCustomUrlRequestTestHttpHost::value_("127.0.0.1");
510 510
511 ScopedCustomUrlRequestTestHttpHost::ScopedCustomUrlRequestTestHttpHost( 511 ScopedCustomUrlRequestTestHttpHost::ScopedCustomUrlRequestTestHttpHost(
512 const std::string& new_value) 512 const std::string& new_value)
513 : old_value_(value_), 513 : old_value_(value_),
514 new_value_(new_value) { 514 new_value_(new_value) {
515 value_ = new_value_; 515 value_ = new_value_;
516 } 516 }
517 517
518 ScopedCustomUrlRequestTestHttpHost::~ScopedCustomUrlRequestTestHttpHost() { 518 ScopedCustomUrlRequestTestHttpHost::~ScopedCustomUrlRequestTestHttpHost() {
519 DCHECK_EQ(value_, new_value_); 519 DCHECK_EQ(value_, new_value_);
520 value_ = old_value_; 520 value_ = old_value_;
521 } 521 }
522 522
523 // static 523 // static
524 const std::string& ScopedCustomUrlRequestTestHttpHost::value() { 524 const std::string& ScopedCustomUrlRequestTestHttpHost::value() {
525 return value_; 525 return value_;
526 } 526 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698