OLD | NEW |
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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 event_order_[req_id]; | 404 event_order_[req_id]; |
405 next_states_[req_id] = | 405 next_states_[req_id] = |
406 kStageHeadersReceived | | 406 kStageHeadersReceived | |
407 kStageCompletedError; | 407 kStageCompletedError; |
408 } | 408 } |
409 | 409 |
410 int TestNetworkDelegate::OnHeadersReceived( | 410 int TestNetworkDelegate::OnHeadersReceived( |
411 URLRequest* request, | 411 URLRequest* request, |
412 const CompletionCallback& callback, | 412 const CompletionCallback& callback, |
413 const HttpResponseHeaders* original_response_headers, | 413 const HttpResponseHeaders* original_response_headers, |
414 scoped_refptr<HttpResponseHeaders>* override_response_headers) { | 414 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
| 415 GURL* allowed_unsafe_redirect_url) { |
415 int req_id = request->identifier(); | 416 int req_id = request->identifier(); |
416 event_order_[req_id] += "OnHeadersReceived\n"; | 417 event_order_[req_id] += "OnHeadersReceived\n"; |
417 InitRequestStatesIfNew(req_id); | 418 InitRequestStatesIfNew(req_id); |
418 EXPECT_TRUE(next_states_[req_id] & kStageHeadersReceived) << | 419 EXPECT_TRUE(next_states_[req_id] & kStageHeadersReceived) << |
419 event_order_[req_id]; | 420 event_order_[req_id]; |
420 next_states_[req_id] = | 421 next_states_[req_id] = |
421 kStageBeforeRedirect | | 422 kStageBeforeRedirect | |
422 kStageResponseStarted | | 423 kStageResponseStarted | |
423 kStageAuthRequired | | 424 kStageAuthRequired | |
424 kStageCompletedError; // e.g. proxy resolution problem | 425 kStageCompletedError; // e.g. proxy resolution problem |
425 | 426 |
426 // Basic authentication sends a second request from the URLRequestHttpJob | 427 // Basic authentication sends a second request from the URLRequestHttpJob |
427 // layer before the URLRequest reports that a response has started. | 428 // layer before the URLRequest reports that a response has started. |
428 next_states_[req_id] |= kStageBeforeSendHeaders; | 429 next_states_[req_id] |= kStageBeforeSendHeaders; |
429 | 430 |
430 if (!redirect_on_headers_received_url_.is_empty()) { | 431 if (!redirect_on_headers_received_url_.is_empty()) { |
431 *override_response_headers = | 432 *override_response_headers = |
432 new net::HttpResponseHeaders(original_response_headers->raw_headers()); | 433 new net::HttpResponseHeaders(original_response_headers->raw_headers()); |
433 (*override_response_headers)->ReplaceStatusLine("HTTP/1.1 302 Found"); | 434 (*override_response_headers)->ReplaceStatusLine("HTTP/1.1 302 Found"); |
434 (*override_response_headers)->RemoveHeader("Location"); | 435 (*override_response_headers)->RemoveHeader("Location"); |
435 (*override_response_headers)->AddHeader( | 436 (*override_response_headers)->AddHeader( |
436 "Location: " + redirect_on_headers_received_url_.spec()); | 437 "Location: " + redirect_on_headers_received_url_.spec()); |
437 | 438 |
438 redirect_on_headers_received_url_ = GURL(); | 439 redirect_on_headers_received_url_ = GURL(); |
| 440 |
| 441 if (!allowed_unsafe_redirect_url_.is_empty()) |
| 442 *allowed_unsafe_redirect_url = allowed_unsafe_redirect_url_; |
439 } | 443 } |
440 | 444 |
441 return OK; | 445 return OK; |
442 } | 446 } |
443 | 447 |
444 void TestNetworkDelegate::OnBeforeRedirect(URLRequest* request, | 448 void TestNetworkDelegate::OnBeforeRedirect(URLRequest* request, |
445 const GURL& new_location) { | 449 const GURL& new_location) { |
446 load_timing_info_before_redirect_ = LoadTimingInfo(); | 450 load_timing_info_before_redirect_ = LoadTimingInfo(); |
447 request->GetLoadTimingInfo(&load_timing_info_before_redirect_); | 451 request->GetLoadTimingInfo(&load_timing_info_before_redirect_); |
448 has_load_timing_info_before_redirect_ = true; | 452 has_load_timing_info_before_redirect_ = true; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 URLRequestJob* job = main_intercept_job_; | 630 URLRequestJob* job = main_intercept_job_; |
627 main_intercept_job_ = NULL; | 631 main_intercept_job_ = NULL; |
628 return job; | 632 return job; |
629 } | 633 } |
630 | 634 |
631 void TestJobInterceptor::set_main_intercept_job(URLRequestJob* job) { | 635 void TestJobInterceptor::set_main_intercept_job(URLRequestJob* job) { |
632 main_intercept_job_ = job; | 636 main_intercept_job_ = job; |
633 } | 637 } |
634 | 638 |
635 } // namespace net | 639 } // namespace net |
OLD | NEW |