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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
16 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 17 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 18 #include "content/browser/loader/resource_loader.h" |
18 #include "content/browser/loader/resource_message_filter.h" | 19 #include "content/browser/loader/resource_message_filter.h" |
19 #include "content/browser/loader/resource_request_info_impl.h" | 20 #include "content/browser/loader/resource_request_info_impl.h" |
20 #include "content/browser/worker_host/worker_service_impl.h" | 21 #include "content/browser/worker_host/worker_service_impl.h" |
21 #include "content/common/child_process_host_impl.h" | 22 #include "content/common/child_process_host_impl.h" |
22 #include "content/common/resource_messages.h" | 23 #include "content/common/resource_messages.h" |
23 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
24 #include "content/public/browser/global_request_id.h" | 25 #include "content/public/browser/global_request_id.h" |
25 #include "content/public/browser/resource_context.h" | 26 #include "content/public/browser/resource_context.h" |
26 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 27 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
27 #include "content/public/browser/resource_request_info.h" | 28 #include "content/public/browser/resource_request_info.h" |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 517 |
517 class ResourceDispatcherHostTest : public testing::Test, | 518 class ResourceDispatcherHostTest : public testing::Test, |
518 public IPC::Sender { | 519 public IPC::Sender { |
519 public: | 520 public: |
520 ResourceDispatcherHostTest() | 521 ResourceDispatcherHostTest() |
521 : ui_thread_(BrowserThread::UI, &message_loop_), | 522 : ui_thread_(BrowserThread::UI, &message_loop_), |
522 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), | 523 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
523 cache_thread_(BrowserThread::CACHE, &message_loop_), | 524 cache_thread_(BrowserThread::CACHE, &message_loop_), |
524 io_thread_(BrowserThread::IO, &message_loop_), | 525 io_thread_(BrowserThread::IO, &message_loop_), |
525 old_factory_(NULL), | 526 old_factory_(NULL), |
526 resource_type_(ResourceType::SUB_RESOURCE), | |
527 send_data_received_acks_(false) { | 527 send_data_received_acks_(false) { |
528 browser_context_.reset(new TestBrowserContext()); | 528 browser_context_.reset(new TestBrowserContext()); |
529 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); | 529 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); |
530 message_loop_.RunUntilIdle(); | 530 message_loop_.RunUntilIdle(); |
531 filter_ = new ForwardingFilter( | 531 filter_ = new ForwardingFilter( |
532 this, browser_context_->GetResourceContext()); | 532 this, browser_context_->GetResourceContext()); |
533 } | 533 } |
534 | 534 |
535 virtual ~ResourceDispatcherHostTest() { | 535 virtual ~ResourceDispatcherHostTest() { |
536 for (std::set<int>::iterator it = child_ids_.begin(); | 536 for (std::set<int>::iterator it = child_ids_.begin(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 if (ResourceDispatcherHostImpl::Get()) | 587 if (ResourceDispatcherHostImpl::Get()) |
588 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext( | 588 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext( |
589 browser_context_->GetResourceContext()); | 589 browser_context_->GetResourceContext()); |
590 | 590 |
591 WorkerServiceImpl::GetInstance()->PerformTeardownForTesting(); | 591 WorkerServiceImpl::GetInstance()->PerformTeardownForTesting(); |
592 | 592 |
593 browser_context_.reset(); | 593 browser_context_.reset(); |
594 message_loop_.RunUntilIdle(); | 594 message_loop_.RunUntilIdle(); |
595 } | 595 } |
596 | 596 |
597 // Creates a request using the current test object as the filter. | 597 // Creates a request using the current test object as the filter and |
| 598 // SubResource as the resource type. |
598 void MakeTestRequest(int render_view_id, | 599 void MakeTestRequest(int render_view_id, |
599 int request_id, | 600 int request_id, |
600 const GURL& url); | 601 const GURL& url); |
601 | 602 |
602 // Generates a request using the given filter. This will probably be a | 603 // Generates a request using the given filter and resource type. |
603 // ForwardingFilter. | 604 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, |
604 void MakeTestRequest(ResourceMessageFilter* filter, | 605 int render_view_id, int request_id, |
605 int render_view_id, | 606 const GURL& url, |
606 int request_id, | 607 ResourceType::Type type); |
607 const GURL& url); | |
608 | 608 |
609 void CancelRequest(int request_id); | 609 void CancelRequest(int request_id); |
610 | 610 |
611 void CompleteStartRequest(int request_id); | 611 void CompleteStartRequest(int request_id); |
612 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); | 612 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); |
613 | 613 |
614 void EnsureSchemeIsAllowed(const std::string& scheme) { | 614 void EnsureSchemeIsAllowed(const std::string& scheme) { |
615 ChildProcessSecurityPolicyImpl* policy = | 615 ChildProcessSecurityPolicyImpl* policy = |
616 ChildProcessSecurityPolicyImpl::GetInstance(); | 616 ChildProcessSecurityPolicyImpl::GetInstance(); |
617 if (!policy->IsWebSafeScheme(scheme)) | 617 if (!policy->IsWebSafeScheme(scheme)) |
618 policy->RegisterWebSafeScheme(scheme); | 618 policy->RegisterWebSafeScheme(scheme); |
619 } | 619 } |
620 | 620 |
621 void EnsureTestSchemeIsAllowed() { | 621 void EnsureTestSchemeIsAllowed() { |
622 EnsureSchemeIsAllowed("test"); | 622 EnsureSchemeIsAllowed("test"); |
623 } | 623 } |
624 | 624 |
625 // Sets a particular response for any request from now on. To switch back to | 625 // Sets a particular response for any request from now on. To switch back to |
626 // the default bahavior, pass an empty |headers|. |headers| should be raw- | 626 // the default bahavior, pass an empty |headers|. |headers| should be raw- |
627 // formatted (NULLs instead of EOLs). | 627 // formatted (NULLs instead of EOLs). |
628 void SetResponse(const std::string& headers, const std::string& data) { | 628 void SetResponse(const std::string& headers, const std::string& data) { |
629 response_headers_ = net::HttpUtil::AssembleRawHeaders(headers.data(), | 629 response_headers_ = net::HttpUtil::AssembleRawHeaders(headers.data(), |
630 headers.size()); | 630 headers.size()); |
631 response_data_ = data; | 631 response_data_ = data; |
632 } | 632 } |
633 void SetResponse(const std::string& headers) { | 633 void SetResponse(const std::string& headers) { |
634 SetResponse(headers, std::string()); | 634 SetResponse(headers, std::string()); |
635 } | 635 } |
636 | 636 |
637 // Sets a particular resource type for any request from now on. | |
638 void SetResourceType(ResourceType::Type type) { | |
639 resource_type_ = type; | |
640 } | |
641 | |
642 void SendDataReceivedACKs(bool send_acks) { | 637 void SendDataReceivedACKs(bool send_acks) { |
643 send_data_received_acks_ = send_acks; | 638 send_data_received_acks_ = send_acks; |
644 } | 639 } |
645 | 640 |
646 // Intercepts requests for the given protocol. | 641 // Intercepts requests for the given protocol. |
647 void HandleScheme(const std::string& scheme) { | 642 void HandleScheme(const std::string& scheme) { |
648 DCHECK(scheme_.empty()); | 643 DCHECK(scheme_.empty()); |
649 DCHECK(!old_factory_); | 644 DCHECK(!old_factory_); |
650 scheme_ = scheme; | 645 scheme_ = scheme; |
651 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( | 646 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 BrowserThreadImpl cache_thread_; | 712 BrowserThreadImpl cache_thread_; |
718 BrowserThreadImpl io_thread_; | 713 BrowserThreadImpl io_thread_; |
719 scoped_ptr<TestBrowserContext> browser_context_; | 714 scoped_ptr<TestBrowserContext> browser_context_; |
720 scoped_refptr<ForwardingFilter> filter_; | 715 scoped_refptr<ForwardingFilter> filter_; |
721 ResourceDispatcherHostImpl host_; | 716 ResourceDispatcherHostImpl host_; |
722 ResourceIPCAccumulator accum_; | 717 ResourceIPCAccumulator accum_; |
723 std::string response_headers_; | 718 std::string response_headers_; |
724 std::string response_data_; | 719 std::string response_data_; |
725 std::string scheme_; | 720 std::string scheme_; |
726 net::URLRequest::ProtocolFactory* old_factory_; | 721 net::URLRequest::ProtocolFactory* old_factory_; |
727 ResourceType::Type resource_type_; | |
728 bool send_data_received_acks_; | 722 bool send_data_received_acks_; |
729 std::set<int> child_ids_; | 723 std::set<int> child_ids_; |
730 static ResourceDispatcherHostTest* test_fixture_; | 724 static ResourceDispatcherHostTest* test_fixture_; |
731 static bool delay_start_; | 725 static bool delay_start_; |
732 static bool delay_complete_; | 726 static bool delay_complete_; |
733 static int url_request_jobs_created_count_; | 727 static int url_request_jobs_created_count_; |
734 }; | 728 }; |
735 // Static. | 729 // Static. |
736 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; | 730 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; |
737 bool ResourceDispatcherHostTest::delay_start_ = false; | 731 bool ResourceDispatcherHostTest::delay_start_ = false; |
738 bool ResourceDispatcherHostTest::delay_complete_ = false; | 732 bool ResourceDispatcherHostTest::delay_complete_ = false; |
739 int ResourceDispatcherHostTest::url_request_jobs_created_count_ = 0; | 733 int ResourceDispatcherHostTest::url_request_jobs_created_count_ = 0; |
740 | 734 |
741 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, | 735 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, |
742 int request_id, | 736 int request_id, |
743 const GURL& url) { | 737 const GURL& url) { |
744 MakeTestRequest(filter_.get(), render_view_id, request_id, url); | 738 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 739 url, ResourceType::SUB_RESOURCE); |
745 } | 740 } |
746 | 741 |
747 void ResourceDispatcherHostTest::MakeTestRequest( | 742 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( |
748 ResourceMessageFilter* filter, | 743 ResourceMessageFilter* filter, |
749 int render_view_id, | 744 int render_view_id, |
750 int request_id, | 745 int request_id, |
751 const GURL& url) { | 746 const GURL& url, |
| 747 ResourceType::Type type) { |
752 // If it's already there, this'll be dropped on the floor, which is fine. | 748 // If it's already there, this'll be dropped on the floor, which is fine. |
753 child_ids_.insert(filter->child_id()); | 749 child_ids_.insert(filter->child_id()); |
754 | 750 |
755 ResourceHostMsg_Request request = | 751 ResourceHostMsg_Request request = |
756 CreateResourceRequest("GET", resource_type_, url); | 752 CreateResourceRequest("GET", type, url); |
757 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); | 753 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
758 bool msg_was_ok; | 754 bool msg_was_ok; |
759 host_.OnMessageReceived(msg, filter, &msg_was_ok); | 755 host_.OnMessageReceived(msg, filter, &msg_was_ok); |
760 KickOffRequest(); | 756 KickOffRequest(); |
761 } | 757 } |
762 | 758 |
763 void ResourceDispatcherHostTest::CancelRequest(int request_id) { | 759 void ResourceDispatcherHostTest::CancelRequest(int request_id) { |
764 host_.CancelRequest(filter_->child_id(), request_id, false); | 760 host_.CancelRequest(filter_->child_id(), request_id, false); |
765 } | 761 } |
766 | 762 |
767 void ResourceDispatcherHostTest::CompleteStartRequest(int request_id) { | 763 void ResourceDispatcherHostTest::CompleteStartRequest(int request_id) { |
768 CompleteStartRequest(filter_.get(), request_id); | 764 CompleteStartRequest(filter_.get(), request_id); |
769 } | 765 } |
770 | 766 |
771 void ResourceDispatcherHostTest::CompleteStartRequest( | 767 void ResourceDispatcherHostTest::CompleteStartRequest( |
772 ResourceMessageFilter* filter, | 768 ResourceMessageFilter* filter, |
773 int request_id) { | 769 int request_id) { |
774 GlobalRequestID gid(filter->child_id(), request_id); | 770 GlobalRequestID gid(filter->child_id(), request_id); |
775 net::URLRequest* req = host_.GetURLRequest(gid); | 771 net::URLRequest* req = host_.GetURLRequest(gid); |
776 EXPECT_TRUE(req); | 772 EXPECT_TRUE(req); |
777 if (req) | 773 if (req) |
778 URLRequestTestDelayedStartJob::CompleteStart(req); | 774 URLRequestTestDelayedStartJob::CompleteStart(req); |
779 } | 775 } |
780 | 776 |
| 777 void CheckRequestCompleteErrorCode(const IPC::Message& message, |
| 778 int expected_error_code) { |
| 779 // Verify that there was no error. |
| 780 int request_id; |
| 781 int error_code; |
| 782 |
| 783 ASSERT_EQ(ResourceMsg_RequestComplete::ID, message.type()); |
| 784 |
| 785 PickleIterator iter(message); |
| 786 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &request_id)); |
| 787 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &error_code)); |
| 788 ASSERT_EQ(error_code, expected_error_code); |
| 789 } |
| 790 |
| 791 void ExtractDataOffsetAndLength(const IPC::Message& message, int* data_offset, |
| 792 int* data_length) { |
| 793 PickleIterator iter(message); |
| 794 int request_id; |
| 795 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &request_id)); |
| 796 ASSERT_TRUE(IPC::ReadParam(&message, &iter, data_offset)); |
| 797 ASSERT_TRUE(IPC::ReadParam(&message, &iter, data_length)); |
| 798 } |
| 799 |
781 void CheckSuccessfulRequest(const std::vector<IPC::Message>& messages, | 800 void CheckSuccessfulRequest(const std::vector<IPC::Message>& messages, |
782 const std::string& reference_data) { | 801 const std::string& reference_data) { |
783 // A successful request will have received 4 messages: | 802 // A successful request will have received 4 messages: |
784 // ReceivedResponse (indicates headers received) | 803 // ReceivedResponse (indicates headers received) |
785 // SetDataBuffer (contains shared memory handle) | 804 // SetDataBuffer (contains shared memory handle) |
786 // DataReceived (data offset and length into shared memory) | 805 // DataReceived (data offset and length into shared memory) |
787 // RequestComplete (request is done) | 806 // RequestComplete (request is done) |
788 // | 807 // |
789 // This function verifies that we received 4 messages and that they | 808 // This function verifies that we received 4 messages and that they |
790 // are appropriate. | 809 // are appropriate. |
791 ASSERT_EQ(4U, messages.size()); | 810 ASSERT_EQ(4U, messages.size()); |
792 | 811 |
793 // The first messages should be received response | 812 // The first messages should be received response |
794 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); | 813 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); |
795 | 814 |
796 ASSERT_EQ(ResourceMsg_SetDataBuffer::ID, messages[1].type()); | 815 ASSERT_EQ(ResourceMsg_SetDataBuffer::ID, messages[1].type()); |
797 | 816 |
798 PickleIterator iter(messages[1]); | 817 PickleIterator iter(messages[1]); |
799 int request_id; | 818 int request_id; |
800 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &request_id)); | 819 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &request_id)); |
801 base::SharedMemoryHandle shm_handle; | 820 base::SharedMemoryHandle shm_handle; |
802 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &shm_handle)); | 821 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &shm_handle)); |
803 int shm_size; | 822 int shm_size; |
804 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &shm_size)); | 823 ASSERT_TRUE(IPC::ReadParam(&messages[1], &iter, &shm_size)); |
805 | 824 |
806 // Followed by the data, currently we only do the data in one chunk, but | 825 // Followed by the data, currently we only do the data in one chunk, but |
807 // should probably test multiple chunks later | 826 // should probably test multiple chunks later |
808 ASSERT_EQ(ResourceMsg_DataReceived::ID, messages[2].type()); | 827 ASSERT_EQ(ResourceMsg_DataReceived::ID, messages[2].type()); |
809 | 828 |
810 PickleIterator iter2(messages[2]); | |
811 ASSERT_TRUE(IPC::ReadParam(&messages[2], &iter2, &request_id)); | |
812 int data_offset; | 829 int data_offset; |
813 ASSERT_TRUE(IPC::ReadParam(&messages[2], &iter2, &data_offset)); | |
814 int data_length; | 830 int data_length; |
815 ASSERT_TRUE(IPC::ReadParam(&messages[2], &iter2, &data_length)); | 831 ExtractDataOffsetAndLength(messages[2], &data_offset, &data_length); |
816 | 832 |
817 ASSERT_EQ(reference_data.size(), static_cast<size_t>(data_length)); | 833 ASSERT_EQ(reference_data.size(), static_cast<size_t>(data_length)); |
818 ASSERT_GE(shm_size, data_length); | 834 ASSERT_GE(shm_size, data_length); |
819 | 835 |
820 base::SharedMemory shared_mem(shm_handle, true); // read only | 836 base::SharedMemory shared_mem(shm_handle, true); // read only |
821 shared_mem.Map(data_length); | 837 shared_mem.Map(data_length); |
822 const char* data = static_cast<char*>(shared_mem.memory()) + data_offset; | 838 const char* data = static_cast<char*>(shared_mem.memory()) + data_offset; |
823 ASSERT_EQ(0, memcmp(reference_data.c_str(), data, data_length)); | 839 ASSERT_EQ(0, memcmp(reference_data.c_str(), data, data_length)); |
824 | 840 |
825 // The last message should be all data received. | 841 // The last message should be all data received. |
826 ASSERT_EQ(ResourceMsg_RequestComplete::ID, messages[3].type()); | 842 CheckRequestCompleteErrorCode(messages[3], net::OK); |
| 843 } |
| 844 |
| 845 void CheckSuccessfulRedirect(const std::vector<IPC::Message>& messages, |
| 846 const std::string& reference_data) { |
| 847 ASSERT_EQ(5U, messages.size()); |
| 848 ASSERT_EQ(ResourceMsg_ReceivedRedirect::ID, messages[0].type()); |
| 849 |
| 850 const std::vector<IPC::Message> second_req_msgs = |
| 851 std::vector<IPC::Message>(messages.begin() + 1, messages.end()); |
| 852 CheckSuccessfulRequest(second_req_msgs, reference_data); |
| 853 } |
| 854 |
| 855 void CheckSuccessfulDetachedRequest( |
| 856 const std::vector<IPC::Message>& messages) { |
| 857 // A successful request will have received 2 messages: |
| 858 // ReceivedResponse (indicates headers received) |
| 859 // RequestComplete (request is done) |
| 860 // |
| 861 // This function verifies that we received 2 messages and that they |
| 862 // are appropriate. |
| 863 ASSERT_EQ(2U, messages.size()); |
| 864 |
| 865 // The first messages should be received response |
| 866 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); |
| 867 |
| 868 // The last message should be all data received. |
| 869 CheckRequestCompleteErrorCode(messages[1], net::OK); |
827 } | 870 } |
828 | 871 |
829 void CheckFailedRequest(const std::vector<IPC::Message>& messages, | 872 void CheckFailedRequest(const std::vector<IPC::Message>& messages, |
830 const std::string& reference_data, | 873 const std::string& reference_data, |
831 int expected_error) { | 874 int expected_error) { |
832 ASSERT_LT(0U, messages.size()); | 875 ASSERT_LT(0U, messages.size()); |
833 ASSERT_GE(2U, messages.size()); | 876 ASSERT_GE(2U, messages.size()); |
834 size_t failure_index = messages.size() - 1; | 877 size_t failure_index = messages.size() - 1; |
835 | 878 |
836 if (messages.size() == 2) { | 879 if (messages.size() == 2) { |
837 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); | 880 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); |
838 } | 881 } |
839 EXPECT_EQ(ResourceMsg_RequestComplete::ID, messages[failure_index].type()); | |
840 | 882 |
841 int request_id; | 883 CheckRequestCompleteErrorCode(messages[failure_index], expected_error); |
842 int error_code; | |
843 | |
844 PickleIterator iter(messages[failure_index]); | |
845 EXPECT_TRUE(IPC::ReadParam(&messages[failure_index], &iter, &request_id)); | |
846 EXPECT_TRUE(IPC::ReadParam(&messages[failure_index], &iter, &error_code)); | |
847 EXPECT_EQ(expected_error, error_code); | |
848 } | 884 } |
849 | 885 |
850 // Tests whether many messages get dispatched properly. | 886 // Tests whether many messages get dispatched properly. |
851 TEST_F(ResourceDispatcherHostTest, TestMany) { | 887 TEST_F(ResourceDispatcherHostTest, TestMany) { |
852 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 888 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
853 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); | 889 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); |
854 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 890 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); |
| 891 MakeTestRequest(0, 4, net::URLRequestTestJob::test_url_4()); |
| 892 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2()); |
| 893 |
| 894 // Finish the redirection |
| 895 ResourceHostMsg_FollowRedirect redirect_msg(5, false, GURL()); |
| 896 bool msg_was_ok; |
| 897 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); |
| 898 base::MessageLoop::current()->RunUntilIdle(); |
855 | 899 |
856 // flush all the pending requests | 900 // flush all the pending requests |
857 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 901 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
858 | 902 |
859 // sorts out all the messages we saw by request | 903 // sorts out all the messages we saw by request |
860 ResourceIPCAccumulator::ClassifiedMessages msgs; | 904 ResourceIPCAccumulator::ClassifiedMessages msgs; |
861 accum_.GetClassifiedMessages(&msgs); | 905 accum_.GetClassifiedMessages(&msgs); |
862 | 906 |
863 // there are three requests, so we should have gotten them classified as such | 907 // there are five requests, so we should have gotten them classified as such |
864 ASSERT_EQ(3U, msgs.size()); | 908 ASSERT_EQ(5U, msgs.size()); |
865 | 909 |
866 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 910 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
867 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_2()); | 911 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_2()); |
868 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); | 912 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); |
| 913 CheckSuccessfulRequest(msgs[3], net::URLRequestTestJob::test_data_4()); |
| 914 CheckSuccessfulRedirect(msgs[4], net::URLRequestTestJob::test_data_2()); |
869 } | 915 } |
870 | 916 |
871 void CheckCancelledRequestCompleteMessage(const IPC::Message& message) { | 917 // Tests whether messages get canceled properly. We issue four requests, |
872 ASSERT_EQ(ResourceMsg_RequestComplete::ID, message.type()); | 918 // cancel two of them, and make sure that each sent the proper notifications. |
873 | |
874 int request_id; | |
875 int error_code; | |
876 | |
877 PickleIterator iter(message); | |
878 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &request_id)); | |
879 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &error_code)); | |
880 | |
881 EXPECT_EQ(net::ERR_ABORTED, error_code); | |
882 } | |
883 | |
884 // Tests whether messages get canceled properly. We issue three requests, | |
885 // cancel one of them, and make sure that each sent the proper notifications. | |
886 TEST_F(ResourceDispatcherHostTest, Cancel) { | 919 TEST_F(ResourceDispatcherHostTest, Cancel) { |
887 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 920 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
888 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); | 921 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); |
889 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 922 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); |
| 923 MakeTestRequestWithResourceType(filter_.get(), 0, 4, |
| 924 net::URLRequestTestJob::test_url_4(), |
| 925 ResourceType::PREFETCH); // detachable type |
| 926 |
890 CancelRequest(2); | 927 CancelRequest(2); |
891 | 928 |
| 929 // Cancel request must come from the renderer for a detachable resource to |
| 930 // delay. |
| 931 host_.CancelRequest(filter_->child_id(), 4, true); |
| 932 |
892 // flush all the pending requests | 933 // flush all the pending requests |
893 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 934 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
894 base::MessageLoop::current()->RunUntilIdle(); | 935 base::MessageLoop::current()->RunUntilIdle(); |
895 | 936 |
896 ResourceIPCAccumulator::ClassifiedMessages msgs; | 937 ResourceIPCAccumulator::ClassifiedMessages msgs; |
897 accum_.GetClassifiedMessages(&msgs); | 938 accum_.GetClassifiedMessages(&msgs); |
898 | 939 |
899 // there are three requests, so we should have gotten them classified as such | 940 // there are four requests, so we should have gotten them classified as such |
900 ASSERT_EQ(3U, msgs.size()); | 941 ASSERT_EQ(4U, msgs.size()); |
901 | 942 |
902 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 943 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
903 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); | 944 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); |
| 945 // The detachable resource should have delayed its cancellation and completed. |
| 946 CheckSuccessfulDetachedRequest(msgs[3]); |
904 | 947 |
905 // Check that request 2 got canceled. | 948 // Check that request 2 got canceled. |
906 ASSERT_EQ(2U, msgs[1].size()); | 949 ASSERT_EQ(2U, msgs[1].size()); |
907 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); | 950 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
908 CheckCancelledRequestCompleteMessage(msgs[1][1]); | 951 CheckRequestCompleteErrorCode(msgs[1][1], net::ERR_ABORTED); |
| 952 } |
| 953 |
| 954 // Shows that detachable requests will timeout if the request takes too long to |
| 955 // complete. |
| 956 TEST_F(ResourceDispatcherHostTest, DetachableResourceTimesOut) { |
| 957 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 958 net::URLRequestTestJob::test_url_2(), |
| 959 ResourceType::PREFETCH); // detachable type |
| 960 ResourceLoader* loader = host_.GetLoader(filter_->child_id(), 1); |
| 961 ASSERT_TRUE(loader); |
| 962 loader->set_detachable_delay_ms(200); |
| 963 base::MessageLoop::current()->RunUntilIdle(); |
| 964 host_.CancelRequest(filter_->child_id(), 1, true); |
| 965 |
| 966 EXPECT_EQ(1, host_.pending_requests()); |
| 967 |
| 968 // Wait until after the delay timer times out before we start processing any |
| 969 // messages. |
| 970 base::OneShotTimer<base::MessageLoop> timer; |
| 971 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210), |
| 972 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle); |
| 973 base::MessageLoop::current()->Run(); |
| 974 |
| 975 // We should have cancelled the prefetch by now. |
| 976 EXPECT_EQ(0, host_.pending_requests()); |
| 977 |
| 978 // In case any messages are still to be processed. |
| 979 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 980 base::MessageLoop::current()->RunUntilIdle(); |
| 981 |
| 982 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 983 accum_.GetClassifiedMessages(&msgs); |
| 984 |
| 985 ASSERT_EQ(1U, msgs.size()); |
| 986 |
| 987 // The request should have cancelled. |
| 988 ASSERT_EQ(2U, msgs[0].size()); |
| 989 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 990 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); |
| 991 } |
| 992 |
| 993 // If the filter has disappeared then detachable resources should continue to |
| 994 // load. |
| 995 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachable) { |
| 996 ResourceHostMsg_Request request = CreateResourceRequest( |
| 997 "GET", ResourceType::PREFETCH, net::URLRequestTestJob::test_url_4()); |
| 998 |
| 999 ResourceHostMsg_RequestResource msg(0, 1, request); |
| 1000 bool msg_was_ok; |
| 1001 host_.OnMessageReceived(msg, filter_, &msg_was_ok); |
| 1002 |
| 1003 // Remove the filter before processing the request by simulating channel |
| 1004 // closure. |
| 1005 GlobalRequestID global_request_id(filter_->child_id(), 1); |
| 1006 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 1007 host_.GetURLRequest(global_request_id)); |
| 1008 info->filter_->OnChannelClosing(); |
| 1009 info->filter_.reset(); |
| 1010 |
| 1011 EXPECT_EQ(1, host_.pending_requests()); |
| 1012 |
| 1013 KickOffRequest(); |
| 1014 |
| 1015 // Make sure the request wasn't canceled early. |
| 1016 EXPECT_EQ(1, host_.pending_requests()); |
| 1017 |
| 1018 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1019 base::MessageLoop::current()->RunUntilIdle(); |
| 1020 |
| 1021 EXPECT_EQ(0, host_.pending_requests()); |
| 1022 |
| 1023 // Because the filter was gone, no messages should have been sent. |
| 1024 // TODO(jkarlin): It would be nice to verify that we successfully completed |
| 1025 // the request, but we have no messages to verify with. |
| 1026 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1027 accum_.GetClassifiedMessages(&msgs); |
| 1028 ASSERT_EQ(0U, msgs.size()); |
| 1029 } |
| 1030 |
| 1031 // If the filter has disappeared (original process dies) then detachable |
| 1032 // resources should continue to load, even when redirected. |
| 1033 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachableRedirect) { |
| 1034 ResourceHostMsg_Request request = CreateResourceRequest( |
| 1035 "GET", ResourceType::PREFETCH, |
| 1036 net::URLRequestTestJob::test_url_redirect_to_url_2()); |
| 1037 |
| 1038 ResourceHostMsg_RequestResource msg(0, 1, request); |
| 1039 bool msg_was_ok; |
| 1040 host_.OnMessageReceived(msg, filter_, &msg_was_ok); |
| 1041 |
| 1042 // Remove the filter before processing the request by simulating channel |
| 1043 // closure. |
| 1044 GlobalRequestID global_request_id(filter_->child_id(), 1); |
| 1045 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 1046 host_.GetURLRequest(global_request_id)); |
| 1047 info->filter_->OnChannelClosing(); |
| 1048 info->filter_.reset(); |
| 1049 |
| 1050 EXPECT_EQ(1, host_.pending_requests()); |
| 1051 // Verify no redirects before resetting the filter. |
| 1052 net::URLRequest* url_request = host_.GetURLRequest(global_request_id); |
| 1053 EXPECT_EQ(1u, url_request->url_chain().size()); |
| 1054 KickOffRequest(); |
| 1055 |
| 1056 // Verify that a redirect was followed. |
| 1057 EXPECT_EQ(2u, url_request->url_chain().size()); |
| 1058 |
| 1059 // Make sure the request wasn't canceled early. |
| 1060 EXPECT_EQ(1, host_.pending_requests()); |
| 1061 |
| 1062 // Finish up the request. |
| 1063 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1064 base::MessageLoop::current()->RunUntilIdle(); |
| 1065 |
| 1066 EXPECT_EQ(0, host_.pending_requests()); |
| 1067 |
| 1068 // Because the filter was deleted, no messages should have been sent. |
| 1069 // TODO(jkarlin): It would be nice to verify that we successfully completed |
| 1070 // the request, but we have no messages to verify with. |
| 1071 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1072 accum_.GetClassifiedMessages(&msgs); |
| 1073 ASSERT_EQ(0U, msgs.size()); |
909 } | 1074 } |
910 | 1075 |
911 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { | 1076 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { |
912 bool was_deleted = false; | 1077 bool was_deleted = false; |
913 | 1078 |
914 // Arrange to have requests deferred before starting. | 1079 // Arrange to have requests deferred before starting. |
915 TestResourceDispatcherHostDelegate delegate; | 1080 TestResourceDispatcherHostDelegate delegate; |
916 delegate.set_flags(DEFER_STARTING_REQUEST); | 1081 delegate.set_flags(DEFER_STARTING_REQUEST); |
917 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); | 1082 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); |
918 host_.SetDelegate(&delegate); | 1083 host_.SetDelegate(&delegate); |
(...skipping 24 matching lines...) Expand all Loading... |
943 | 1108 |
944 // flush all the pending requests | 1109 // flush all the pending requests |
945 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1110 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
946 base::MessageLoop::current()->RunUntilIdle(); | 1111 base::MessageLoop::current()->RunUntilIdle(); |
947 | 1112 |
948 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1113 ResourceIPCAccumulator::ClassifiedMessages msgs; |
949 accum_.GetClassifiedMessages(&msgs); | 1114 accum_.GetClassifiedMessages(&msgs); |
950 | 1115 |
951 // Check that request got canceled. | 1116 // Check that request got canceled. |
952 ASSERT_EQ(1U, msgs[0].size()); | 1117 ASSERT_EQ(1U, msgs[0].size()); |
953 CheckCancelledRequestCompleteMessage(msgs[0][0]); | 1118 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); |
954 | 1119 |
955 // Make sure URLRequest is never started. | 1120 // Make sure URLRequest is never started. |
956 EXPECT_EQ(0, url_request_jobs_created_count_); | 1121 EXPECT_EQ(0, url_request_jobs_created_count_); |
957 } | 1122 } |
958 | 1123 |
959 TEST_F(ResourceDispatcherHostTest, PausedStartError) { | 1124 TEST_F(ResourceDispatcherHostTest, PausedStartError) { |
960 // Arrange to have requests deferred before processing response headers. | 1125 // Arrange to have requests deferred before processing response headers. |
961 TestResourceDispatcherHostDelegate delegate; | 1126 TestResourceDispatcherHostDelegate delegate; |
962 delegate.set_flags(DEFER_PROCESSING_RESPONSE); | 1127 delegate.set_flags(DEFER_PROCESSING_RESPONSE); |
963 host_.SetDelegate(&delegate); | 1128 host_.SetDelegate(&delegate); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 // flush all the pending requests | 1188 // flush all the pending requests |
1024 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1189 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1025 base::MessageLoop::current()->RunUntilIdle(); | 1190 base::MessageLoop::current()->RunUntilIdle(); |
1026 | 1191 |
1027 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1192 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1028 accum_.GetClassifiedMessages(&msgs); | 1193 accum_.GetClassifiedMessages(&msgs); |
1029 | 1194 |
1030 // Check the cancellation | 1195 // Check the cancellation |
1031 ASSERT_EQ(1U, msgs.size()); | 1196 ASSERT_EQ(1U, msgs.size()); |
1032 ASSERT_EQ(1U, msgs[0].size()); | 1197 ASSERT_EQ(1U, msgs[0].size()); |
1033 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | |
1034 | 1198 |
1035 int request_id; | 1199 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ACCESS_DENIED); |
1036 int error_code; | |
1037 | |
1038 PickleIterator iter(msgs[0][0]); | |
1039 ASSERT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | |
1040 ASSERT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &error_code)); | |
1041 | |
1042 EXPECT_EQ(net::ERR_ACCESS_DENIED, error_code); | |
1043 } | 1200 } |
1044 | 1201 |
1045 // The host delegate acts as a second one so we can have some requests | 1202 // The host delegate acts as a second one so we can have some requests |
1046 // pending and some canceled. | 1203 // pending and some canceled. |
1047 class TestFilter : public ForwardingFilter { | 1204 class TestFilter : public ForwardingFilter { |
1048 public: | 1205 public: |
1049 explicit TestFilter(ResourceContext* resource_context) | 1206 explicit TestFilter(ResourceContext* resource_context) |
1050 : ForwardingFilter(NULL, resource_context), | 1207 : ForwardingFilter(NULL, resource_context), |
1051 has_canceled_(false), | 1208 has_canceled_(false), |
1052 received_after_canceled_(0) { | 1209 received_after_canceled_(0) { |
(...skipping 17 matching lines...) Expand all Loading... |
1070 | 1227 |
1071 // Tests CancelRequestsForProcess | 1228 // Tests CancelRequestsForProcess |
1072 TEST_F(ResourceDispatcherHostTest, TestProcessCancel) { | 1229 TEST_F(ResourceDispatcherHostTest, TestProcessCancel) { |
1073 scoped_refptr<TestFilter> test_filter = new TestFilter( | 1230 scoped_refptr<TestFilter> test_filter = new TestFilter( |
1074 browser_context_->GetResourceContext()); | 1231 browser_context_->GetResourceContext()); |
1075 | 1232 |
1076 // request 1 goes to the test delegate | 1233 // request 1 goes to the test delegate |
1077 ResourceHostMsg_Request request = CreateResourceRequest( | 1234 ResourceHostMsg_Request request = CreateResourceRequest( |
1078 "GET", ResourceType::SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); | 1235 "GET", ResourceType::SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); |
1079 | 1236 |
1080 MakeTestRequest(test_filter.get(), 0, 1, | 1237 MakeTestRequestWithResourceType(test_filter.get(), 0, 1, |
1081 net::URLRequestTestJob::test_url_1()); | 1238 net::URLRequestTestJob::test_url_1(), |
| 1239 ResourceType::SUB_RESOURCE); |
1082 | 1240 |
1083 // request 2 goes to us | 1241 // request 2 goes to us |
1084 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); | 1242 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); |
1085 | 1243 |
1086 // request 3 goes to the test delegate | 1244 // request 3 goes to the test delegate |
1087 MakeTestRequest(test_filter.get(), 0, 3, | 1245 MakeTestRequestWithResourceType(test_filter.get(), 0, 3, |
1088 net::URLRequestTestJob::test_url_3()); | 1246 net::URLRequestTestJob::test_url_3(), |
| 1247 ResourceType::SUB_RESOURCE); |
| 1248 |
| 1249 // request 4 goes to us |
| 1250 MakeTestRequestWithResourceType(filter_.get(), 0, 4, |
| 1251 net::URLRequestTestJob::test_url_4(), |
| 1252 ResourceType::PREFETCH); // detachable type |
| 1253 |
1089 | 1254 |
1090 // Make sure all requests have finished stage one. test_url_1 will have | 1255 // Make sure all requests have finished stage one. test_url_1 will have |
1091 // finished. | 1256 // finished. |
1092 base::MessageLoop::current()->RunUntilIdle(); | 1257 base::MessageLoop::current()->RunUntilIdle(); |
1093 | 1258 |
1094 // TODO(mbelshe): | 1259 // TODO(mbelshe): |
1095 // Now that the async IO path is in place, the IO always completes on the | 1260 // Now that the async IO path is in place, the IO always completes on the |
1096 // initial call; so the requests have already completed. This basically | 1261 // initial call; so the requests have already completed. This basically |
1097 // breaks the whole test. | 1262 // breaks the whole test. |
1098 //EXPECT_EQ(3, host_.pending_requests()); | 1263 //EXPECT_EQ(3, host_.pending_requests()); |
1099 | 1264 |
1100 // Process each request for one level so one callback is called. | 1265 // Process test_url_2 and test_url_3 for one level so one callback is called. |
| 1266 // We'll cancel test_url_4 (detachable) before processing it to verify that it |
| 1267 // delays the cancel. |
1101 for (int i = 0; i < 2; i++) | 1268 for (int i = 0; i < 2; i++) |
1102 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1269 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1103 | 1270 |
1104 // Cancel the requests to the test process. | 1271 // Cancel the requests to the test process. |
1105 host_.CancelRequestsForProcess(filter_->child_id()); | 1272 host_.CancelRequestsForProcess(filter_->child_id()); |
1106 test_filter->has_canceled_ = true; | 1273 test_filter->has_canceled_ = true; |
1107 | 1274 |
1108 // Flush all the pending requests. | 1275 // Flush all the pending requests. |
1109 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1276 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1110 | 1277 |
1111 EXPECT_EQ(0, host_.pending_requests()); | 1278 EXPECT_EQ(0, host_.pending_requests()); |
1112 | 1279 |
1113 // The test delegate should not have gotten any messages after being canceled. | 1280 // The test delegate should not have gotten any messages after being canceled. |
1114 ASSERT_EQ(0, test_filter->received_after_canceled_); | 1281 ASSERT_EQ(0, test_filter->received_after_canceled_); |
1115 | 1282 |
1116 // We should have gotten exactly one result. | 1283 // We should have gotten two results. |
1117 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1284 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1118 accum_.GetClassifiedMessages(&msgs); | 1285 accum_.GetClassifiedMessages(&msgs); |
| 1286 ASSERT_EQ(2U, msgs.size()); |
| 1287 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); |
| 1288 // We cancelled the detachable request before it finished, and it should have |
| 1289 // delayed and completed regardless. |
| 1290 CheckSuccessfulDetachedRequest(msgs[1]); |
| 1291 } |
| 1292 |
| 1293 TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachableTimesOut) { |
| 1294 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 1295 net::URLRequestTestJob::test_url_4(), |
| 1296 ResourceType::PREFETCH); // detachable type |
| 1297 ResourceLoader* loader = host_.GetLoader(filter_->child_id(), 1); |
| 1298 EXPECT_TRUE(loader); |
| 1299 loader->set_detachable_delay_ms(200); |
| 1300 base::MessageLoop::current()->RunUntilIdle(); |
| 1301 |
| 1302 // Cancel the requests to the test process. |
| 1303 host_.CancelRequestsForProcess(filter_->child_id()); |
| 1304 EXPECT_EQ(1, host_.pending_requests()); |
| 1305 |
| 1306 // Wait until after the delay timer times out before we start processing any |
| 1307 // messages. |
| 1308 base::OneShotTimer<base::MessageLoop> timer; |
| 1309 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210), |
| 1310 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle); |
| 1311 base::MessageLoop::current()->Run(); |
| 1312 |
| 1313 // We should have cancelled the prefetch by now. |
| 1314 EXPECT_EQ(0, host_.pending_requests()); |
| 1315 |
| 1316 // In case any messages are still to be processed. |
| 1317 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1318 base::MessageLoop::current()->RunUntilIdle(); |
| 1319 |
| 1320 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1321 accum_.GetClassifiedMessages(&msgs); |
| 1322 |
1119 ASSERT_EQ(1U, msgs.size()); | 1323 ASSERT_EQ(1U, msgs.size()); |
1120 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); | 1324 |
| 1325 // The request should have cancelled. |
| 1326 ASSERT_EQ(2U, msgs[0].size()); |
| 1327 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 1328 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); |
1121 } | 1329 } |
1122 | 1330 |
1123 // Tests blocking and resuming requests. | 1331 // Tests blocking and resuming requests. |
1124 TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) { | 1332 TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) { |
1125 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1333 host_.BlockRequestsForRoute(filter_->child_id(), 1); |
1126 host_.BlockRequestsForRoute(filter_->child_id(), 2); | 1334 host_.BlockRequestsForRoute(filter_->child_id(), 2); |
1127 host_.BlockRequestsForRoute(filter_->child_id(), 3); | 1335 host_.BlockRequestsForRoute(filter_->child_id(), 3); |
1128 | 1336 |
1129 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1337 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
1130 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); | 1338 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 } | 1387 } |
1180 | 1388 |
1181 // Tests blocking and canceling requests. | 1389 // Tests blocking and canceling requests. |
1182 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { | 1390 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { |
1183 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1391 host_.BlockRequestsForRoute(filter_->child_id(), 1); |
1184 | 1392 |
1185 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1393 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
1186 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); | 1394 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); |
1187 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 1395 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); |
1188 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); | 1396 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); |
| 1397 // Blocked detachable resources should not delay cancellation. |
| 1398 MakeTestRequestWithResourceType(filter_.get(), 1, 5, |
| 1399 net::URLRequestTestJob::test_url_4(), |
| 1400 ResourceType::PREFETCH); // detachable type |
1189 | 1401 |
1190 // Flush all the pending requests. | 1402 // Flush all the pending requests. |
1191 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1403 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1192 | 1404 |
1193 // Sort out all the messages we saw by request. | 1405 // Sort out all the messages we saw by request. |
1194 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1406 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1195 accum_.GetClassifiedMessages(&msgs); | 1407 accum_.GetClassifiedMessages(&msgs); |
1196 | 1408 |
1197 // The 2 requests for the RVH 0 should have been processed. | 1409 // The 2 requests for the RVH 0 should have been processed. |
1198 ASSERT_EQ(2U, msgs.size()); | 1410 ASSERT_EQ(2U, msgs.size()); |
(...skipping 12 matching lines...) Expand all Loading... |
1211 } | 1423 } |
1212 | 1424 |
1213 // Tests that blocked requests are canceled if their associated process dies. | 1425 // Tests that blocked requests are canceled if their associated process dies. |
1214 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { | 1426 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { |
1215 // This second filter is used to emulate a second process. | 1427 // This second filter is used to emulate a second process. |
1216 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1428 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1217 this, browser_context_->GetResourceContext()); | 1429 this, browser_context_->GetResourceContext()); |
1218 | 1430 |
1219 host_.BlockRequestsForRoute(second_filter->child_id(), 0); | 1431 host_.BlockRequestsForRoute(second_filter->child_id(), 0); |
1220 | 1432 |
1221 MakeTestRequest(filter_.get(), 0, 1, net::URLRequestTestJob::test_url_1()); | 1433 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
1222 MakeTestRequest(second_filter.get(), 0, 2, | 1434 net::URLRequestTestJob::test_url_1(), |
1223 net::URLRequestTestJob::test_url_2()); | 1435 ResourceType::SUB_RESOURCE); |
1224 MakeTestRequest(filter_.get(), 0, 3, net::URLRequestTestJob::test_url_3()); | 1436 MakeTestRequestWithResourceType(second_filter.get(), 0, 2, |
1225 MakeTestRequest(second_filter.get(), 0, 4, | 1437 net::URLRequestTestJob::test_url_2(), |
1226 net::URLRequestTestJob::test_url_1()); | 1438 ResourceType::SUB_RESOURCE); |
| 1439 MakeTestRequestWithResourceType(filter_.get(), 0, 3, |
| 1440 net::URLRequestTestJob::test_url_3(), |
| 1441 ResourceType::SUB_RESOURCE); |
| 1442 MakeTestRequestWithResourceType(second_filter.get(), 0, 4, |
| 1443 net::URLRequestTestJob::test_url_1(), |
| 1444 ResourceType::SUB_RESOURCE); |
| 1445 MakeTestRequestWithResourceType(second_filter.get(), 0, 5, |
| 1446 net::URLRequestTestJob::test_url_4(), |
| 1447 ResourceType::PREFETCH); // detachable type |
1227 | 1448 |
1228 // Simulate process death. | 1449 // Simulate process death. |
1229 host_.CancelRequestsForProcess(second_filter->child_id()); | 1450 host_.CancelRequestsForProcess(second_filter->child_id()); |
1230 | 1451 |
1231 // Flush all the pending requests. | 1452 // Flush all the pending requests. |
1232 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1453 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1233 | 1454 |
1234 // Sort out all the messages we saw by request. | 1455 // Sort out all the messages we saw by request. |
1235 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1456 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1236 accum_.GetClassifiedMessages(&msgs); | 1457 accum_.GetClassifiedMessages(&msgs); |
1237 | 1458 |
1238 // The 2 requests for the RVH 0 should have been processed. | 1459 // The 2 requests for the RVH 0 should have been processed. Note that |
| 1460 // blocked detachable requests are canceled without delay. |
1239 ASSERT_EQ(2U, msgs.size()); | 1461 ASSERT_EQ(2U, msgs.size()); |
1240 | 1462 |
1241 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1463 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
1242 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); | 1464 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); |
1243 | 1465 |
1244 EXPECT_TRUE(host_.blocked_loaders_map_.empty()); | 1466 EXPECT_TRUE(host_.blocked_loaders_map_.empty()); |
1245 } | 1467 } |
1246 | 1468 |
1247 // Tests that blocked requests don't leak when the ResourceDispatcherHost goes | 1469 // Tests that blocked requests don't leak when the ResourceDispatcherHost goes |
1248 // away. Note that we rely on Purify for finding the leaks if any. | 1470 // away. Note that we rely on Purify for finding the leaks if any. |
1249 // If this test turns the Purify bot red, check the ResourceDispatcherHost | 1471 // If this test turns the Purify bot red, check the ResourceDispatcherHost |
1250 // destructor to make sure the blocked requests are deleted. | 1472 // destructor to make sure the blocked requests are deleted. |
1251 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { | 1473 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { |
1252 // This second filter is used to emulate a second process. | 1474 // This second filter is used to emulate a second process. |
1253 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1475 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1254 this, browser_context_->GetResourceContext()); | 1476 this, browser_context_->GetResourceContext()); |
1255 | 1477 |
1256 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1478 host_.BlockRequestsForRoute(filter_->child_id(), 1); |
1257 host_.BlockRequestsForRoute(filter_->child_id(), 2); | 1479 host_.BlockRequestsForRoute(filter_->child_id(), 2); |
1258 host_.BlockRequestsForRoute(second_filter->child_id(), 1); | 1480 host_.BlockRequestsForRoute(second_filter->child_id(), 1); |
1259 | 1481 |
1260 MakeTestRequest(filter_.get(), 0, 1, net::URLRequestTestJob::test_url_1()); | 1482 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
1261 MakeTestRequest(filter_.get(), 1, 2, net::URLRequestTestJob::test_url_2()); | 1483 net::URLRequestTestJob::test_url_1(), |
1262 MakeTestRequest(filter_.get(), 0, 3, net::URLRequestTestJob::test_url_3()); | 1484 ResourceType::SUB_RESOURCE); |
1263 MakeTestRequest(second_filter.get(), 1, 4, | 1485 MakeTestRequestWithResourceType(filter_.get(), 1, 2, |
1264 net::URLRequestTestJob::test_url_1()); | 1486 net::URLRequestTestJob::test_url_2(), |
1265 MakeTestRequest(filter_.get(), 2, 5, net::URLRequestTestJob::test_url_2()); | 1487 ResourceType::SUB_RESOURCE); |
1266 MakeTestRequest(filter_.get(), 2, 6, net::URLRequestTestJob::test_url_3()); | 1488 MakeTestRequestWithResourceType(filter_.get(), 0, 3, |
| 1489 net::URLRequestTestJob::test_url_3(), |
| 1490 ResourceType::SUB_RESOURCE); |
| 1491 MakeTestRequestWithResourceType(second_filter.get(), 1, 4, |
| 1492 net::URLRequestTestJob::test_url_1(), |
| 1493 ResourceType::SUB_RESOURCE); |
| 1494 MakeTestRequestWithResourceType(filter_.get(), 2, 5, |
| 1495 net::URLRequestTestJob::test_url_2(), |
| 1496 ResourceType::SUB_RESOURCE); |
| 1497 MakeTestRequestWithResourceType(filter_.get(), 2, 6, |
| 1498 net::URLRequestTestJob::test_url_3(), |
| 1499 ResourceType::SUB_RESOURCE); |
| 1500 MakeTestRequestWithResourceType(filter_.get(), 0, 7, |
| 1501 net::URLRequestTestJob::test_url_4(), |
| 1502 ResourceType::PREFETCH); // detachable type |
| 1503 MakeTestRequestWithResourceType(second_filter.get(), 1, 8, |
| 1504 net::URLRequestTestJob::test_url_4(), |
| 1505 ResourceType::PREFETCH); // detachable type |
1267 | 1506 |
1268 host_.CancelRequestsForProcess(filter_->child_id()); | 1507 host_.CancelRequestsForProcess(filter_->child_id()); |
1269 host_.CancelRequestsForProcess(second_filter->child_id()); | 1508 host_.CancelRequestsForProcess(second_filter->child_id()); |
1270 | 1509 |
1271 // Flush all the pending requests. | 1510 // Flush all the pending requests. |
1272 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1511 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1273 } | 1512 } |
1274 | 1513 |
1275 // Test the private helper method "CalculateApproximateMemoryCost()". | 1514 // Test the private helper method "CalculateApproximateMemoryCost()". |
1276 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { | 1515 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 // Determine how many instance of test_url_2() we can request before | 1554 // Determine how many instance of test_url_2() we can request before |
1316 // throttling kicks in. | 1555 // throttling kicks in. |
1317 size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req; | 1556 size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req; |
1318 | 1557 |
1319 // This second filter is used to emulate a second process. | 1558 // This second filter is used to emulate a second process. |
1320 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1559 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1321 this, browser_context_->GetResourceContext()); | 1560 this, browser_context_->GetResourceContext()); |
1322 | 1561 |
1323 // Saturate the number of outstanding requests for our process. | 1562 // Saturate the number of outstanding requests for our process. |
1324 for (size_t i = 0; i < kMaxRequests; ++i) { | 1563 for (size_t i = 0; i < kMaxRequests; ++i) { |
1325 MakeTestRequest(filter_.get(), 0, i + 1, | 1564 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1, |
1326 net::URLRequestTestJob::test_url_2()); | 1565 net::URLRequestTestJob::test_url_2(), |
| 1566 ResourceType::SUB_RESOURCE); |
1327 } | 1567 } |
1328 | 1568 |
1329 // Issue two more requests for our process -- these should fail immediately. | 1569 // Issue two more requests for our process -- these should fail immediately. |
1330 MakeTestRequest(filter_.get(), 0, kMaxRequests + 1, | 1570 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 1, |
1331 net::URLRequestTestJob::test_url_2()); | 1571 net::URLRequestTestJob::test_url_2(), |
1332 MakeTestRequest(filter_.get(), 0, kMaxRequests + 2, | 1572 ResourceType::SUB_RESOURCE); |
1333 net::URLRequestTestJob::test_url_2()); | 1573 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 2, |
| 1574 net::URLRequestTestJob::test_url_2(), |
| 1575 ResourceType::SUB_RESOURCE); |
1334 | 1576 |
1335 // Issue two requests for the second process -- these should succeed since | 1577 // Issue two requests for the second process -- these should succeed since |
1336 // it is just process 0 that is saturated. | 1578 // it is just process 0 that is saturated. |
1337 MakeTestRequest(second_filter.get(), 0, kMaxRequests + 3, | 1579 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3, |
1338 net::URLRequestTestJob::test_url_2()); | 1580 net::URLRequestTestJob::test_url_2(), |
1339 MakeTestRequest(second_filter.get(), 0, kMaxRequests + 4, | 1581 ResourceType::SUB_RESOURCE); |
1340 net::URLRequestTestJob::test_url_2()); | 1582 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4, |
| 1583 net::URLRequestTestJob::test_url_2(), |
| 1584 ResourceType::SUB_RESOURCE); |
1341 | 1585 |
1342 // Flush all the pending requests. | 1586 // Flush all the pending requests. |
1343 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1587 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1344 base::MessageLoop::current()->RunUntilIdle(); | 1588 base::MessageLoop::current()->RunUntilIdle(); |
1345 | 1589 |
1346 // Sorts out all the messages we saw by request. | 1590 // Sorts out all the messages we saw by request. |
1347 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1591 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1348 accum_.GetClassifiedMessages(&msgs); | 1592 accum_.GetClassifiedMessages(&msgs); |
1349 | 1593 |
1350 // We issued (kMaxRequests + 4) total requests. | 1594 // We issued (kMaxRequests + 4) total requests. |
(...skipping 30 matching lines...) Expand all Loading... |
1381 host_.set_max_num_in_flight_requests(kMaxRequests); | 1625 host_.set_max_num_in_flight_requests(kMaxRequests); |
1382 | 1626 |
1383 // Needed to emulate additional processes. | 1627 // Needed to emulate additional processes. |
1384 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1628 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1385 this, browser_context_->GetResourceContext()); | 1629 this, browser_context_->GetResourceContext()); |
1386 scoped_refptr<ForwardingFilter> third_filter = new ForwardingFilter( | 1630 scoped_refptr<ForwardingFilter> third_filter = new ForwardingFilter( |
1387 this, browser_context_->GetResourceContext()); | 1631 this, browser_context_->GetResourceContext()); |
1388 | 1632 |
1389 // Saturate the number of outstanding requests for our process. | 1633 // Saturate the number of outstanding requests for our process. |
1390 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) { | 1634 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) { |
1391 MakeTestRequest(filter_.get(), 0, i + 1, | 1635 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1, |
1392 net::URLRequestTestJob::test_url_2()); | 1636 net::URLRequestTestJob::test_url_2(), |
| 1637 ResourceType::SUB_RESOURCE); |
1393 } | 1638 } |
1394 | 1639 |
1395 // Issue another request for our process -- this should fail immediately. | 1640 // Issue another request for our process -- this should fail immediately. |
1396 MakeTestRequest(filter_.get(), 0, kMaxRequestsPerProcess + 1, | 1641 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequestsPerProcess + 1, |
1397 net::URLRequestTestJob::test_url_2()); | 1642 net::URLRequestTestJob::test_url_2(), |
| 1643 ResourceType::SUB_RESOURCE); |
1398 | 1644 |
1399 // Issue a request for the second process -- this should succeed, because it | 1645 // Issue a request for the second process -- this should succeed, because it |
1400 // is just process 0 that is saturated. | 1646 // is just process 0 that is saturated. |
1401 MakeTestRequest(second_filter.get(), 0, kMaxRequestsPerProcess + 2, | 1647 MakeTestRequestWithResourceType( |
1402 net::URLRequestTestJob::test_url_2()); | 1648 second_filter.get(), 0, kMaxRequestsPerProcess + 2, |
| 1649 net::URLRequestTestJob::test_url_2(), ResourceType::SUB_RESOURCE); |
1403 | 1650 |
1404 // Issue a request for the third process -- this should fail, because the | 1651 // Issue a request for the third process -- this should fail, because the |
1405 // global limit has been reached. | 1652 // global limit has been reached. |
1406 MakeTestRequest(third_filter.get(), 0, kMaxRequestsPerProcess + 3, | 1653 MakeTestRequestWithResourceType( |
1407 net::URLRequestTestJob::test_url_2()); | 1654 third_filter.get(), 0, kMaxRequestsPerProcess + 3, |
| 1655 net::URLRequestTestJob::test_url_2(), ResourceType::SUB_RESOURCE); |
1408 | 1656 |
1409 // Flush all the pending requests. | 1657 // Flush all the pending requests. |
1410 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1658 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1411 base::MessageLoop::current()->RunUntilIdle(); | 1659 base::MessageLoop::current()->RunUntilIdle(); |
1412 | 1660 |
1413 // Sorts out all the messages we saw by request. | 1661 // Sorts out all the messages we saw by request. |
1414 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1662 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1415 accum_.GetClassifiedMessages(&msgs); | 1663 accum_.GetClassifiedMessages(&msgs); |
1416 | 1664 |
1417 // The processes issued the following requests: | 1665 // The processes issued the following requests: |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 } | 1785 } |
1538 | 1786 |
1539 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). | 1787 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). |
1540 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { | 1788 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { |
1541 std::string raw_headers("HTTP/1.1 403 Forbidden\n" | 1789 std::string raw_headers("HTTP/1.1 403 Forbidden\n" |
1542 "Content-disposition: attachment; filename=blah\n" | 1790 "Content-disposition: attachment; filename=blah\n" |
1543 "Content-type: application/octet-stream\n\n"); | 1791 "Content-type: application/octet-stream\n\n"); |
1544 std::string response_data("<html><title>Test One</title></html>"); | 1792 std::string response_data("<html><title>Test One</title></html>"); |
1545 SetResponse(raw_headers, response_data); | 1793 SetResponse(raw_headers, response_data); |
1546 | 1794 |
| 1795 HandleScheme("http"); |
| 1796 |
1547 // Only MAIN_FRAMEs can trigger a download. | 1797 // Only MAIN_FRAMEs can trigger a download. |
1548 SetResourceType(ResourceType::MAIN_FRAME); | 1798 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"), |
1549 | 1799 ResourceType::MAIN_FRAME); |
1550 HandleScheme("http"); | |
1551 MakeTestRequest(0, 1, GURL("http:bla")); | |
1552 | 1800 |
1553 // Flush all pending requests. | 1801 // Flush all pending requests. |
1554 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1802 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1555 | 1803 |
1556 // Sorts out all the messages we saw by request. | 1804 // Sorts out all the messages we saw by request. |
1557 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1805 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1558 accum_.GetClassifiedMessages(&msgs); | 1806 accum_.GetClassifiedMessages(&msgs); |
1559 | 1807 |
1560 // We should have gotten one RequestComplete message. | 1808 // We should have gotten one RequestComplete message. |
1561 ASSERT_EQ(1U, msgs[0].size()); | 1809 ASSERT_EQ(1U, msgs[0].size()); |
1562 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | 1810 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); |
1563 | 1811 |
1564 // The RequestComplete message should have had the error code of | 1812 // The RequestComplete message should have had the error code of |
1565 // ERR_FILE_NOT_FOUND. | 1813 // ERR_FILE_NOT_FOUND. |
1566 int request_id; | 1814 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_FILE_NOT_FOUND); |
1567 int error_code; | |
1568 | |
1569 PickleIterator iter(msgs[0][0]); | |
1570 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | |
1571 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &error_code)); | |
1572 | |
1573 EXPECT_EQ(1, request_id); | |
1574 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, error_code); | |
1575 } | 1815 } |
1576 | 1816 |
1577 // Test for http://crbug.com/76202 . We don't want to destroy a | 1817 // Test for http://crbug.com/76202 . We don't want to destroy a |
1578 // download request prematurely when processing a cancellation from | 1818 // download request prematurely when processing a cancellation from |
1579 // the renderer. | 1819 // the renderer. |
1580 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { | 1820 TEST_F(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { |
1581 EXPECT_EQ(0, host_.pending_requests()); | 1821 EXPECT_EQ(0, host_.pending_requests()); |
1582 | 1822 |
1583 int render_view_id = 0; | 1823 int render_view_id = 0; |
1584 int request_id = 1; | 1824 int request_id = 1; |
1585 | 1825 |
1586 std::string raw_headers("HTTP\n" | 1826 std::string raw_headers("HTTP\n" |
1587 "Content-disposition: attachment; filename=foo\n\n"); | 1827 "Content-disposition: attachment; filename=foo\n\n"); |
1588 std::string response_data("01234567890123456789\x01foobar"); | 1828 std::string response_data("01234567890123456789\x01foobar"); |
1589 | 1829 |
1590 // Get past sniffing metrics in the BufferedResourceHandler. Note that | 1830 // Get past sniffing metrics in the BufferedResourceHandler. Note that |
1591 // if we don't get past the sniffing metrics, the result will be that | 1831 // if we don't get past the sniffing metrics, the result will be that |
1592 // the BufferedResourceHandler won't have figured out that it's a download, | 1832 // the BufferedResourceHandler won't have figured out that it's a download, |
1593 // won't have constructed a DownloadResourceHandler, and and the request | 1833 // won't have constructed a DownloadResourceHandler, and and the request |
1594 // will be successfully canceled below, failing the test. | 1834 // will be successfully canceled below, failing the test. |
1595 response_data.resize(1025, ' '); | 1835 response_data.resize(1025, ' '); |
1596 | 1836 |
1597 SetResponse(raw_headers, response_data); | 1837 SetResponse(raw_headers, response_data); |
1598 SetResourceType(ResourceType::MAIN_FRAME); | |
1599 SetDelayedCompleteJobGeneration(true); | 1838 SetDelayedCompleteJobGeneration(true); |
1600 HandleScheme("http"); | 1839 HandleScheme("http"); |
1601 | 1840 |
1602 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1841 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1842 GURL("http://example.com/blah"), |
| 1843 ResourceType::MAIN_FRAME); |
1603 // Return some data so that the request is identified as a download | 1844 // Return some data so that the request is identified as a download |
1604 // and the proper resource handlers are created. | 1845 // and the proper resource handlers are created. |
1605 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1846 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1606 | 1847 |
1607 // And now simulate a cancellation coming from the renderer. | 1848 // And now simulate a cancellation coming from the renderer. |
1608 ResourceHostMsg_CancelRequest msg(request_id); | 1849 ResourceHostMsg_CancelRequest msg(request_id); |
1609 bool msg_was_ok; | 1850 bool msg_was_ok; |
1610 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1851 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1611 | 1852 |
1612 // Since the request had already started processing as a download, | 1853 // Since the request had already started processing as a download, |
(...skipping 10 matching lines...) Expand all Loading... |
1623 int render_view_id = 0; | 1864 int render_view_id = 0; |
1624 int request_id = 1; | 1865 int request_id = 1; |
1625 | 1866 |
1626 std::string raw_headers("HTTP\n" | 1867 std::string raw_headers("HTTP\n" |
1627 "Content-disposition: attachment; filename=foo\n\n"); | 1868 "Content-disposition: attachment; filename=foo\n\n"); |
1628 std::string response_data("01234567890123456789\x01foobar"); | 1869 std::string response_data("01234567890123456789\x01foobar"); |
1629 // Get past sniffing metrics. | 1870 // Get past sniffing metrics. |
1630 response_data.resize(1025, ' '); | 1871 response_data.resize(1025, ' '); |
1631 | 1872 |
1632 SetResponse(raw_headers, response_data); | 1873 SetResponse(raw_headers, response_data); |
1633 SetResourceType(ResourceType::MAIN_FRAME); | |
1634 SetDelayedCompleteJobGeneration(true); | 1874 SetDelayedCompleteJobGeneration(true); |
1635 HandleScheme("http"); | 1875 HandleScheme("http"); |
1636 | 1876 |
1637 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1877 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1878 GURL("http://example.com/blah"), |
| 1879 ResourceType::MAIN_FRAME); |
1638 // Return some data so that the request is identified as a download | 1880 // Return some data so that the request is identified as a download |
1639 // and the proper resource handlers are created. | 1881 // and the proper resource handlers are created. |
1640 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1882 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1641 | 1883 |
1642 // And now simulate a cancellation coming from the renderer. | 1884 // And now simulate a cancellation coming from the renderer. |
1643 ResourceHostMsg_CancelRequest msg(request_id); | 1885 ResourceHostMsg_CancelRequest msg(request_id); |
1644 bool msg_was_ok; | 1886 bool msg_was_ok; |
1645 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1887 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1646 | 1888 |
1647 // Since the request had already started processing as a download, | 1889 // Since the request had already started processing as a download, |
1648 // the cancellation above should have been ignored and the request | 1890 // the cancellation above should have been ignored and the request |
1649 // should still be alive. | 1891 // should still be alive. |
1650 EXPECT_EQ(1, host_.pending_requests()); | 1892 EXPECT_EQ(1, host_.pending_requests()); |
1651 | 1893 |
1652 // Cancelling by other methods shouldn't work either. | 1894 // Cancelling by other methods shouldn't work either. |
1653 host_.CancelRequestsForProcess(render_view_id); | 1895 host_.CancelRequestsForProcess(render_view_id); |
1654 EXPECT_EQ(1, host_.pending_requests()); | 1896 EXPECT_EQ(1, host_.pending_requests()); |
1655 | 1897 |
1656 // Cancelling by context should work. | 1898 // Cancelling by context should work. |
1657 host_.CancelRequestsForContext(filter_->resource_context()); | 1899 host_.CancelRequestsForContext(filter_->resource_context()); |
1658 EXPECT_EQ(0, host_.pending_requests()); | 1900 EXPECT_EQ(0, host_.pending_requests()); |
1659 } | 1901 } |
1660 | 1902 |
| 1903 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetachable) { |
| 1904 EXPECT_EQ(0, host_.pending_requests()); |
| 1905 |
| 1906 int render_view_id = 0; |
| 1907 int request_id = 1; |
| 1908 |
| 1909 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1910 net::URLRequestTestJob::test_url_4(), |
| 1911 ResourceType::PREFETCH); // detachable type |
| 1912 |
| 1913 // Simulate a cancel coming from the renderer. |
| 1914 host_.CancelRequest(filter_->child_id(), request_id, true); |
| 1915 |
| 1916 // Since the request had already started processing as detachable, |
| 1917 // the cancellation above should have been ignored and the request |
| 1918 // should still be alive. |
| 1919 EXPECT_EQ(1, host_.pending_requests()); |
| 1920 |
| 1921 // Cancelling by other methods should also be delayed. |
| 1922 host_.CancelRequestsForProcess(render_view_id); |
| 1923 EXPECT_EQ(1, host_.pending_requests()); |
| 1924 |
| 1925 // Cancelling by context should work. |
| 1926 host_.CancelRequestsForContext(filter_->resource_context()); |
| 1927 EXPECT_EQ(0, host_.pending_requests()); |
| 1928 } |
| 1929 |
1661 // Test the cancelling of requests that are being transferred to a new renderer | 1930 // Test the cancelling of requests that are being transferred to a new renderer |
1662 // due to a redirection. | 1931 // due to a redirection. |
1663 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { | 1932 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { |
1664 EXPECT_EQ(0, host_.pending_requests()); | 1933 EXPECT_EQ(0, host_.pending_requests()); |
1665 | 1934 |
1666 int render_view_id = 0; | 1935 int render_view_id = 0; |
1667 int request_id = 1; | 1936 int request_id = 1; |
1668 | 1937 |
1669 std::string raw_headers("HTTP/1.1 200 OK\n" | 1938 std::string raw_headers("HTTP/1.1 200 OK\n" |
1670 "Content-Type: text/html; charset=utf-8\n\n"); | 1939 "Content-Type: text/html; charset=utf-8\n\n"); |
1671 std::string response_data("<html>foobar</html>"); | 1940 std::string response_data("<html>foobar</html>"); |
1672 | 1941 |
1673 SetResponse(raw_headers, response_data); | 1942 SetResponse(raw_headers, response_data); |
1674 SetResourceType(ResourceType::MAIN_FRAME); | |
1675 HandleScheme("http"); | 1943 HandleScheme("http"); |
1676 | 1944 |
1677 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1945 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1946 GURL("http://example.com/blah"), |
| 1947 ResourceType::MAIN_FRAME); |
| 1948 |
1678 | 1949 |
1679 GlobalRequestID global_request_id(filter_->child_id(), request_id); | 1950 GlobalRequestID global_request_id(filter_->child_id(), request_id); |
1680 host_.MarkAsTransferredNavigation(global_request_id, | 1951 host_.MarkAsTransferredNavigation(global_request_id, |
1681 GURL("http://example.com/blah")); | 1952 GURL("http://example.com/blah")); |
1682 | 1953 |
1683 // And now simulate a cancellation coming from the renderer. | 1954 // And now simulate a cancellation coming from the renderer. |
1684 ResourceHostMsg_CancelRequest msg(request_id); | 1955 ResourceHostMsg_CancelRequest msg(request_id); |
1685 bool msg_was_ok; | 1956 bool msg_was_ok; |
1686 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1957 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1687 | 1958 |
(...skipping 16 matching lines...) Expand all Loading... |
1704 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) { | 1975 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) { |
1705 EXPECT_EQ(0, host_.pending_requests()); | 1976 EXPECT_EQ(0, host_.pending_requests()); |
1706 | 1977 |
1707 int render_view_id = 0; | 1978 int render_view_id = 0; |
1708 int request_id = 1; | 1979 int request_id = 1; |
1709 | 1980 |
1710 // Configure initial request. | 1981 // Configure initial request. |
1711 SetResponse("HTTP/1.1 302 Found\n" | 1982 SetResponse("HTTP/1.1 302 Found\n" |
1712 "Location: http://other.com/blech\n\n"); | 1983 "Location: http://other.com/blech\n\n"); |
1713 | 1984 |
1714 SetResourceType(ResourceType::MAIN_FRAME); | |
1715 HandleScheme("http"); | 1985 HandleScheme("http"); |
1716 | 1986 |
1717 // Temporarily replace ContentBrowserClient with one that will trigger the | 1987 // Temporarily replace ContentBrowserClient with one that will trigger the |
1718 // transfer navigation code paths. | 1988 // transfer navigation code paths. |
1719 TransfersAllNavigationsContentBrowserClient new_client; | 1989 TransfersAllNavigationsContentBrowserClient new_client; |
1720 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1990 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1721 | 1991 |
1722 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1992 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1993 GURL("http://example.com/blah"), ResourceType::MAIN_FRAME); |
1723 | 1994 |
1724 // Now that we're blocked on the redirect, update the response and unblock by | 1995 // Now that we're blocked on the redirect, update the response and unblock by |
1725 // telling the AsyncResourceHandler to follow the redirect. | 1996 // telling the AsyncResourceHandler to follow the redirect. |
1726 const std::string kResponseBody = "hello world"; | 1997 const std::string kResponseBody = "hello world"; |
1727 SetResponse("HTTP/1.1 200 OK\n" | 1998 SetResponse("HTTP/1.1 200 OK\n" |
1728 "Content-Type: text/html\n\n", | 1999 "Content-Type: text/html\n\n", |
1729 kResponseBody); | 2000 kResponseBody); |
1730 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); | 2001 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
1731 bool msg_was_ok; | 2002 bool msg_was_ok; |
1732 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); | 2003 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { | 2046 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { |
1776 EXPECT_EQ(0, host_.pending_requests()); | 2047 EXPECT_EQ(0, host_.pending_requests()); |
1777 | 2048 |
1778 int render_view_id = 0; | 2049 int render_view_id = 0; |
1779 int request_id = 1; | 2050 int request_id = 1; |
1780 | 2051 |
1781 // Configure initial request. | 2052 // Configure initial request. |
1782 SetResponse("HTTP/1.1 302 Found\n" | 2053 SetResponse("HTTP/1.1 302 Found\n" |
1783 "Location: http://other.com/blech\n\n"); | 2054 "Location: http://other.com/blech\n\n"); |
1784 | 2055 |
1785 SetResourceType(ResourceType::MAIN_FRAME); | |
1786 HandleScheme("http"); | 2056 HandleScheme("http"); |
1787 | 2057 |
1788 // Temporarily replace ContentBrowserClient with one that will trigger the | 2058 // Temporarily replace ContentBrowserClient with one that will trigger the |
1789 // transfer navigation code paths. | 2059 // transfer navigation code paths. |
1790 TransfersAllNavigationsContentBrowserClient new_client; | 2060 TransfersAllNavigationsContentBrowserClient new_client; |
1791 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 2061 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1792 | 2062 |
1793 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 2063 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 2064 GURL("http://example.com/blah"), |
| 2065 ResourceType::MAIN_FRAME); |
1794 | 2066 |
1795 // Now that we're blocked on the redirect, update the response and unblock by | 2067 // Now that we're blocked on the redirect, update the response and unblock by |
1796 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain | 2068 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain |
1797 // MIME type, which causes BufferedResourceHandler to buffer it before the | 2069 // MIME type, which causes BufferedResourceHandler to buffer it before the |
1798 // transfer occurs. | 2070 // transfer occurs. |
1799 const std::string kResponseBody = "hello world"; | 2071 const std::string kResponseBody = "hello world"; |
1800 SetResponse("HTTP/1.1 200 OK\n" | 2072 SetResponse("HTTP/1.1 200 OK\n" |
1801 "Content-Type: text/plain\n\n", | 2073 "Content-Type: text/plain\n\n", |
1802 kResponseBody); | 2074 kResponseBody); |
1803 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); | 2075 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 | 2119 |
1848 int render_view_id = 0; | 2120 int render_view_id = 0; |
1849 int request_id = 1; | 2121 int request_id = 1; |
1850 int first_child_id = -1; | 2122 int first_child_id = -1; |
1851 | 2123 |
1852 // Configure initial request. | 2124 // Configure initial request. |
1853 SetResponse("HTTP/1.1 302 Found\n" | 2125 SetResponse("HTTP/1.1 302 Found\n" |
1854 "Location: http://other.com/blech\n\n"); | 2126 "Location: http://other.com/blech\n\n"); |
1855 const std::string kResponseBody = "hello world"; | 2127 const std::string kResponseBody = "hello world"; |
1856 | 2128 |
1857 SetResourceType(ResourceType::MAIN_FRAME); | |
1858 HandleScheme("http"); | 2129 HandleScheme("http"); |
1859 | 2130 |
1860 // Temporarily replace ContentBrowserClient with one that will trigger the | 2131 // Temporarily replace ContentBrowserClient with one that will trigger the |
1861 // transfer navigation code paths. | 2132 // transfer navigation code paths. |
1862 TransfersAllNavigationsContentBrowserClient new_client; | 2133 TransfersAllNavigationsContentBrowserClient new_client; |
1863 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 2134 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1864 | 2135 |
1865 // Create a first filter that can be deleted before the second one starts. | 2136 // Create a first filter that can be deleted before the second one starts. |
1866 { | 2137 { |
1867 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter( | 2138 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { | 2207 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { |
1937 EXPECT_EQ(0, host_.pending_requests()); | 2208 EXPECT_EQ(0, host_.pending_requests()); |
1938 | 2209 |
1939 int render_view_id = 0; | 2210 int render_view_id = 0; |
1940 int request_id = 1; | 2211 int request_id = 1; |
1941 | 2212 |
1942 // Configure initial request. | 2213 // Configure initial request. |
1943 SetResponse("HTTP/1.1 302 Found\n" | 2214 SetResponse("HTTP/1.1 302 Found\n" |
1944 "Location: http://other.com/blech\n\n"); | 2215 "Location: http://other.com/blech\n\n"); |
1945 | 2216 |
1946 SetResourceType(ResourceType::MAIN_FRAME); | |
1947 HandleScheme("http"); | 2217 HandleScheme("http"); |
1948 | 2218 |
1949 // Temporarily replace ContentBrowserClient with one that will trigger the | 2219 // Temporarily replace ContentBrowserClient with one that will trigger the |
1950 // transfer navigation code paths. | 2220 // transfer navigation code paths. |
1951 TransfersAllNavigationsContentBrowserClient new_client; | 2221 TransfersAllNavigationsContentBrowserClient new_client; |
1952 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 2222 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1953 | 2223 |
1954 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 2224 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 2225 GURL("http://example.com/blah"), |
| 2226 ResourceType::MAIN_FRAME); |
1955 | 2227 |
1956 // Now that we're blocked on the redirect, simulate hitting another redirect. | 2228 // Now that we're blocked on the redirect, simulate hitting another redirect. |
1957 SetResponse("HTTP/1.1 302 Found\n" | 2229 SetResponse("HTTP/1.1 302 Found\n" |
1958 "Location: http://other.com/blerg\n\n"); | 2230 "Location: http://other.com/blerg\n\n"); |
1959 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); | 2231 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
1960 bool msg_was_ok; | 2232 bool msg_was_ok; |
1961 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); | 2233 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); |
1962 base::MessageLoop::current()->RunUntilIdle(); | 2234 base::MessageLoop::current()->RunUntilIdle(); |
1963 | 2235 |
1964 // Now that we're blocked on the second redirect, update the response and | 2236 // Now that we're blocked on the second redirect, update the response and |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 accum_.GetClassifiedMessages(&msgs); | 2289 accum_.GetClassifiedMessages(&msgs); |
2018 | 2290 |
2019 ASSERT_EQ(2U, msgs.size()); | 2291 ASSERT_EQ(2U, msgs.size()); |
2020 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2292 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
2021 CheckSuccessfulRequest(msgs[1], kResponseBody); | 2293 CheckSuccessfulRequest(msgs[1], kResponseBody); |
2022 } | 2294 } |
2023 | 2295 |
2024 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { | 2296 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { |
2025 EXPECT_EQ(0, host_.pending_requests()); | 2297 EXPECT_EQ(0, host_.pending_requests()); |
2026 | 2298 |
2027 SetResourceType(ResourceType::MAIN_FRAME); | |
2028 HandleScheme("http"); | 2299 HandleScheme("http"); |
2029 | 2300 |
2030 MakeTestRequest(0, 1, GURL("foo://bar")); | 2301 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"), |
| 2302 ResourceType::MAIN_FRAME); |
2031 | 2303 |
2032 // Flush all pending requests. | 2304 // Flush all pending requests. |
2033 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2305 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
2034 | 2306 |
2035 // Sort all the messages we saw by request. | 2307 // Sort all the messages we saw by request. |
2036 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2308 ResourceIPCAccumulator::ClassifiedMessages msgs; |
2037 accum_.GetClassifiedMessages(&msgs); | 2309 accum_.GetClassifiedMessages(&msgs); |
2038 | 2310 |
2039 // We should have gotten one RequestComplete message. | 2311 // We should have gotten one RequestComplete message. |
2040 ASSERT_EQ(1U, msgs[0].size()); | 2312 ASSERT_EQ(1U, msgs[0].size()); |
2041 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); | 2313 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][0].type()); |
2042 | 2314 |
2043 // The RequestComplete message should have the error code of | 2315 // The RequestComplete message should have the error code of |
2044 // ERR_UNKNOWN_URL_SCHEME. | 2316 // ERR_UNKNOWN_URL_SCHEME. |
2045 int request_id; | 2317 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_UNKNOWN_URL_SCHEME); |
2046 int error_code; | |
2047 | |
2048 PickleIterator iter(msgs[0][0]); | |
2049 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); | |
2050 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &error_code)); | |
2051 | |
2052 EXPECT_EQ(1, request_id); | |
2053 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, error_code); | |
2054 } | 2318 } |
2055 | 2319 |
2056 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { | 2320 TEST_F(ResourceDispatcherHostTest, DataReceivedACKs) { |
2057 EXPECT_EQ(0, host_.pending_requests()); | 2321 EXPECT_EQ(0, host_.pending_requests()); |
2058 | 2322 |
2059 SendDataReceivedACKs(true); | 2323 SendDataReceivedACKs(true); |
2060 | 2324 |
2061 HandleScheme("big-job"); | 2325 HandleScheme("big-job"); |
2062 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 2326 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
2063 | 2327 |
2064 // Sort all the messages we saw by request. | 2328 // Sort all the messages we saw by request. |
2065 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2329 ResourceIPCAccumulator::ClassifiedMessages msgs; |
2066 accum_.GetClassifiedMessages(&msgs); | 2330 accum_.GetClassifiedMessages(&msgs); |
2067 | 2331 |
2068 size_t size = msgs[0].size(); | 2332 size_t size = msgs[0].size(); |
2069 | 2333 |
2070 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 2334 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
2071 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); | 2335 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); |
2072 for (size_t i = 2; i < size - 1; ++i) | 2336 for (size_t i = 2; i < size - 1; ++i) |
2073 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 2337 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
2074 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type()); | 2338 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type()); |
2075 } | 2339 } |
2076 | 2340 |
| 2341 // Request a very large detachable resource and cancel part way. Some of the |
| 2342 // data should have been sent to the renderer, but not all. |
| 2343 TEST_F(ResourceDispatcherHostTest, DataSentBeforeDetach) { |
| 2344 EXPECT_EQ(0, host_.pending_requests()); |
| 2345 |
| 2346 int render_view_id = 0; |
| 2347 int request_id = 1; |
| 2348 |
| 2349 std::string raw_headers("HTTP\n" |
| 2350 "Content-type: image/jpeg\n\n"); |
| 2351 std::string response_data("01234567890123456789\x01foobar"); |
| 2352 |
| 2353 // Create a response larger than kMaxAllocationSize (currently 32K). Note |
| 2354 // that if this increase beyond 512K we'll need to make the response longer. |
| 2355 const int kAllocSize = 1024*512; |
| 2356 response_data.resize(kAllocSize, ' '); |
| 2357 |
| 2358 SetResponse(raw_headers, response_data); |
| 2359 SetDelayedCompleteJobGeneration(true); |
| 2360 HandleScheme("http"); |
| 2361 |
| 2362 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 2363 GURL("http://example.com/blah"), |
| 2364 ResourceType::PREFETCH); |
| 2365 |
| 2366 // Get a bit of data before cancelling. |
| 2367 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 2368 |
| 2369 // Simulate a cancellation coming from the renderer. |
| 2370 ResourceHostMsg_CancelRequest msg(request_id); |
| 2371 bool msg_was_ok; |
| 2372 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
| 2373 |
| 2374 EXPECT_EQ(1, host_.pending_requests()); |
| 2375 |
| 2376 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2377 |
| 2378 // Sort all the messages we saw by request. |
| 2379 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2380 accum_.GetClassifiedMessages(&msgs); |
| 2381 |
| 2382 EXPECT_EQ(4U, msgs[0].size()); |
| 2383 |
| 2384 // Figure out how many bytes were received by the renderer. |
| 2385 int data_offset; |
| 2386 int data_length; |
| 2387 ExtractDataOffsetAndLength(msgs[0][2], &data_offset, &data_length); |
| 2388 EXPECT_LT(0, data_length); |
| 2389 EXPECT_GT(kAllocSize, data_length); |
| 2390 |
| 2391 // Verify the data that was received before cancellation. Also verify that the |
| 2392 // response completed. |
| 2393 CheckSuccessfulRequest( |
| 2394 msgs[0], |
| 2395 std::string(response_data.begin(), response_data.begin() + data_length)); |
| 2396 } |
| 2397 |
2077 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { | 2398 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { |
2078 EXPECT_EQ(0, host_.pending_requests()); | 2399 EXPECT_EQ(0, host_.pending_requests()); |
2079 | 2400 |
2080 HandleScheme("big-job"); | 2401 HandleScheme("big-job"); |
2081 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 2402 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
2082 | 2403 |
2083 // Sort all the messages we saw by request. | 2404 // Sort all the messages we saw by request. |
2084 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2405 ResourceIPCAccumulator::ClassifiedMessages msgs; |
2085 accum_.GetClassifiedMessages(&msgs); | 2406 accum_.GetClassifiedMessages(&msgs); |
2086 | 2407 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 } | 2489 } |
2169 | 2490 |
2170 base::MessageLoop::current()->RunUntilIdle(); | 2491 base::MessageLoop::current()->RunUntilIdle(); |
2171 | 2492 |
2172 msgs.clear(); | 2493 msgs.clear(); |
2173 accum_.GetClassifiedMessages(&msgs); | 2494 accum_.GetClassifiedMessages(&msgs); |
2174 } | 2495 } |
2175 } | 2496 } |
2176 | 2497 |
2177 } // namespace content | 2498 } // namespace content |
OLD | NEW |