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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 | 815 |
820 base::SharedMemory shared_mem(shm_handle, true); // read only | 816 base::SharedMemory shared_mem(shm_handle, true); // read only |
821 shared_mem.Map(data_length); | 817 shared_mem.Map(data_length); |
822 const char* data = static_cast<char*>(shared_mem.memory()) + data_offset; | 818 const char* data = static_cast<char*>(shared_mem.memory()) + data_offset; |
823 ASSERT_EQ(0, memcmp(reference_data.c_str(), data, data_length)); | 819 ASSERT_EQ(0, memcmp(reference_data.c_str(), data, data_length)); |
824 | 820 |
825 // The last message should be all data received. | 821 // The last message should be all data received. |
826 ASSERT_EQ(ResourceMsg_RequestComplete::ID, messages[3].type()); | 822 ASSERT_EQ(ResourceMsg_RequestComplete::ID, messages[3].type()); |
827 } | 823 } |
828 | 824 |
825 void CheckSuccessfulRedirect(const std::vector<IPC::Message>& messages, | |
826 const std::string& reference_data) { | |
827 ASSERT_EQ(5U, messages.size()); | |
828 ASSERT_EQ(ResourceMsg_ReceivedRedirect::ID, messages[0].type()); | |
829 | |
830 const std::vector<IPC::Message> second_req_msgs = | |
831 std::vector<IPC::Message>(messages.begin() + 1, messages.end()); | |
832 CheckSuccessfulRequest(second_req_msgs, reference_data); | |
833 } | |
834 | |
835 void CheckSuccessfulDetachedRequest( | |
836 const std::vector<IPC::Message>& messages) { | |
837 // A successful request will have received 2 messages: | |
838 // ReceivedResponse (indicates headers received) | |
839 // RequestComplete (request is done) | |
840 // | |
841 // This function verifies that we received 2 messages and that they | |
842 // are appropriate. | |
843 ASSERT_EQ(2U, messages.size()); | |
844 | |
845 // The first messages should be received response | |
846 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); | |
847 | |
848 // The last message should be all data received. | |
849 ASSERT_EQ(ResourceMsg_RequestComplete::ID, messages[1].type()); | |
850 | |
851 // Verify that there was no error. | |
852 int request_id; | |
853 int error_code; | |
854 | |
855 PickleIterator iter(messages[1]); | |
856 EXPECT_TRUE(IPC::ReadParam(&messages[1], &iter, &request_id)); | |
857 EXPECT_TRUE(IPC::ReadParam(&messages[1], &iter, &error_code)); | |
858 EXPECT_EQ(0, error_code); | |
859 } | |
860 | |
829 void CheckFailedRequest(const std::vector<IPC::Message>& messages, | 861 void CheckFailedRequest(const std::vector<IPC::Message>& messages, |
830 const std::string& reference_data, | 862 const std::string& reference_data, |
831 int expected_error) { | 863 int expected_error) { |
832 ASSERT_LT(0U, messages.size()); | 864 ASSERT_LT(0U, messages.size()); |
833 ASSERT_GE(2U, messages.size()); | 865 ASSERT_GE(2U, messages.size()); |
834 size_t failure_index = messages.size() - 1; | 866 size_t failure_index = messages.size() - 1; |
835 | 867 |
836 if (messages.size() == 2) { | 868 if (messages.size() == 2) { |
837 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); | 869 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); |
838 } | 870 } |
839 EXPECT_EQ(ResourceMsg_RequestComplete::ID, messages[failure_index].type()); | 871 EXPECT_EQ(ResourceMsg_RequestComplete::ID, messages[failure_index].type()); |
840 | 872 |
841 int request_id; | 873 int request_id; |
842 int error_code; | 874 int error_code; |
843 | 875 |
844 PickleIterator iter(messages[failure_index]); | 876 PickleIterator iter(messages[failure_index]); |
845 EXPECT_TRUE(IPC::ReadParam(&messages[failure_index], &iter, &request_id)); | 877 EXPECT_TRUE(IPC::ReadParam(&messages[failure_index], &iter, &request_id)); |
846 EXPECT_TRUE(IPC::ReadParam(&messages[failure_index], &iter, &error_code)); | 878 EXPECT_TRUE(IPC::ReadParam(&messages[failure_index], &iter, &error_code)); |
847 EXPECT_EQ(expected_error, error_code); | 879 EXPECT_EQ(expected_error, error_code); |
848 } | 880 } |
849 | 881 |
850 // Tests whether many messages get dispatched properly. | 882 // Tests whether many messages get dispatched properly. |
851 TEST_F(ResourceDispatcherHostTest, TestMany) { | 883 TEST_F(ResourceDispatcherHostTest, TestMany) { |
852 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 884 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
853 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); | 885 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); |
854 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 886 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); |
887 MakeTestRequest(0, 4, net::URLRequestTestJob::test_url_4()); | |
888 MakeTestRequest(0, 5, net::URLRequestTestJob::test_url_redirect_to_url_2()); | |
889 | |
890 // Finish the redirection | |
891 ResourceHostMsg_FollowRedirect redirect_msg(5, false, GURL()); | |
892 bool msg_was_ok; | |
893 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); | |
894 base::MessageLoop::current()->RunUntilIdle(); | |
855 | 895 |
856 // flush all the pending requests | 896 // flush all the pending requests |
857 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 897 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
858 | 898 |
859 // sorts out all the messages we saw by request | 899 // sorts out all the messages we saw by request |
860 ResourceIPCAccumulator::ClassifiedMessages msgs; | 900 ResourceIPCAccumulator::ClassifiedMessages msgs; |
861 accum_.GetClassifiedMessages(&msgs); | 901 accum_.GetClassifiedMessages(&msgs); |
862 | 902 |
863 // there are three requests, so we should have gotten them classified as such | 903 // there are five requests, so we should have gotten them classified as such |
864 ASSERT_EQ(3U, msgs.size()); | 904 ASSERT_EQ(5U, msgs.size()); |
865 | 905 |
866 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 906 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
867 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_2()); | 907 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_2()); |
868 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); | 908 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); |
909 CheckSuccessfulRequest(msgs[3], net::URLRequestTestJob::test_data_4()); | |
910 CheckSuccessfulRedirect(msgs[4], net::URLRequestTestJob::test_data_2()); | |
869 } | 911 } |
870 | 912 |
871 void CheckCancelledRequestCompleteMessage(const IPC::Message& message) { | 913 void CheckCancelledRequestCompleteMessage(const IPC::Message& message) { |
872 ASSERT_EQ(ResourceMsg_RequestComplete::ID, message.type()); | 914 ASSERT_EQ(ResourceMsg_RequestComplete::ID, message.type()); |
873 | 915 |
874 int request_id; | 916 int request_id; |
875 int error_code; | 917 int error_code; |
876 | 918 |
877 PickleIterator iter(message); | 919 PickleIterator iter(message); |
878 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &request_id)); | 920 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &request_id)); |
879 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &error_code)); | 921 ASSERT_TRUE(IPC::ReadParam(&message, &iter, &error_code)); |
880 | 922 |
881 EXPECT_EQ(net::ERR_ABORTED, error_code); | 923 EXPECT_EQ(net::ERR_ABORTED, error_code); |
882 } | 924 } |
883 | 925 |
884 // Tests whether messages get canceled properly. We issue three requests, | 926 // Tests whether messages get canceled properly. We issue four requests, |
885 // cancel one of them, and make sure that each sent the proper notifications. | 927 // cancel two of them, and make sure that each sent the proper notifications. |
886 TEST_F(ResourceDispatcherHostTest, Cancel) { | 928 TEST_F(ResourceDispatcherHostTest, Cancel) { |
887 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 929 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
888 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); | 930 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); |
889 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 931 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); |
932 MakeTestRequestWithResourceType(filter_.get(), 0, 4, | |
933 net::URLRequestTestJob::test_url_4(), | |
934 ResourceType::PREFETCH); // detachable type | |
935 | |
890 CancelRequest(2); | 936 CancelRequest(2); |
937 // Cancel request must come from the renderer for a detachable resource to | |
938 // delay. | |
939 host_.CancelRequest(filter_->child_id(), 4, true); | |
891 | 940 |
892 // flush all the pending requests | 941 // flush all the pending requests |
893 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 942 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
894 base::MessageLoop::current()->RunUntilIdle(); | 943 base::MessageLoop::current()->RunUntilIdle(); |
895 | 944 |
896 ResourceIPCAccumulator::ClassifiedMessages msgs; | 945 ResourceIPCAccumulator::ClassifiedMessages msgs; |
897 accum_.GetClassifiedMessages(&msgs); | 946 accum_.GetClassifiedMessages(&msgs); |
898 | 947 |
899 // there are three requests, so we should have gotten them classified as such | 948 // there are four requests, so we should have gotten them classified as such |
900 ASSERT_EQ(3U, msgs.size()); | 949 ASSERT_EQ(4U, msgs.size()); |
901 | 950 |
902 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 951 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
903 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); | 952 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); |
953 // The detachable resource should have delayed its cancellation and completed. | |
954 CheckSuccessfulDetachedRequest(msgs[3]); | |
904 | 955 |
905 // Check that request 2 got canceled. | 956 // Check that request 2 got canceled. |
906 ASSERT_EQ(2U, msgs[1].size()); | 957 ASSERT_EQ(2U, msgs[1].size()); |
907 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); | 958 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
908 CheckCancelledRequestCompleteMessage(msgs[1][1]); | 959 CheckCancelledRequestCompleteMessage(msgs[1][1]); |
909 } | 960 } |
910 | 961 |
962 // Shows that detachable requests will timeout if the request takes too long to | |
963 // complete. | |
964 TEST_F(ResourceDispatcherHostTest, DetachableResourceTimesOut) { | |
965 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | |
966 net::URLRequestTestJob::test_url_2(), | |
967 ResourceType::PREFETCH); // detachable type | |
968 ResourceLoader* loader = host_.GetLoader(filter_->child_id(), 1); | |
969 EXPECT_TRUE(loader); | |
James Simonsen
2013/10/26 02:25:00
Probably better to ASSERT. You'll crash if it's fa
jkarlin2
2013/10/28 19:25:41
Done.
| |
970 loader->set_detachable_delay_ms(200); | |
971 base::MessageLoop::current()->RunUntilIdle(); | |
972 host_.CancelRequest(filter_->child_id(), 1, true); | |
973 | |
974 EXPECT_EQ(1, host_.pending_requests()); | |
975 | |
976 // Wait until after the delay timer times out before we start processing any | |
977 // messages. | |
978 base::OneShotTimer<base::MessageLoop> timer; | |
979 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210), | |
980 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle); | |
981 base::MessageLoop::current()->Run(); | |
982 | |
983 // We should have cancelled the prefetch by now. | |
984 EXPECT_EQ(0, host_.pending_requests()); | |
985 | |
986 // In case any messages are still to be processed. | |
987 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
988 base::MessageLoop::current()->RunUntilIdle(); | |
989 | |
990 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
991 accum_.GetClassifiedMessages(&msgs); | |
992 | |
993 ASSERT_EQ(1U, msgs.size()); | |
994 | |
995 // The request should have cancelled. | |
996 ASSERT_EQ(2U, msgs[0].size()); | |
997 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | |
998 CheckCancelledRequestCompleteMessage(msgs[0][1]); | |
999 } | |
1000 | |
1001 // If the filter has disappeared (original process dies) then detachable | |
1002 // resources should continue to load. | |
1003 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachable) { | |
1004 ResourceHostMsg_Request request = CreateResourceRequest( | |
1005 "GET", ResourceType::PREFETCH, net::URLRequestTestJob::test_url_4()); | |
1006 | |
1007 ResourceHostMsg_RequestResource msg(0, 1, request); | |
1008 bool msg_was_ok; | |
1009 host_.OnMessageReceived(msg, filter_, &msg_was_ok); | |
1010 | |
1011 // Remove the filter before processing the request. | |
1012 GlobalRequestID global_request_id(filter_->child_id(), 1); | |
1013 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | |
1014 host_.GetURLRequest(global_request_id)); | |
1015 info->filter_.reset(); | |
1016 | |
1017 EXPECT_EQ(1, host_.pending_requests()); | |
1018 | |
1019 KickOffRequest(); | |
1020 | |
1021 // Make sure the request wasn't canceled early. | |
1022 EXPECT_EQ(1, host_.pending_requests()); | |
1023 | |
1024 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
1025 base::MessageLoop::current()->RunUntilIdle(); | |
1026 | |
1027 EXPECT_EQ(0, host_.pending_requests()); | |
1028 | |
1029 // Because the filter was gone, no messages should have been sent. | |
1030 // TODO(jkarlin): It would be nice to verify that we successfully completed | |
1031 // the request, but we have no messages to verify with. | |
1032 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
1033 accum_.GetClassifiedMessages(&msgs); | |
1034 ASSERT_EQ(0U, msgs.size()); | |
1035 } | |
1036 | |
1037 // If the filter has disappeared (original process dies) then detachable | |
1038 // resources should continue to load, even when redirected. | |
1039 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachableRedirect) { | |
1040 ResourceHostMsg_Request request = CreateResourceRequest( | |
1041 "GET", ResourceType::PREFETCH, | |
1042 net::URLRequestTestJob::test_url_redirect_to_url_2()); | |
1043 | |
1044 ResourceHostMsg_RequestResource msg(0, 1, request); | |
1045 bool msg_was_ok; | |
1046 host_.OnMessageReceived(msg, filter_, &msg_was_ok); | |
1047 | |
1048 // Remove the filter before processing the request. | |
1049 GlobalRequestID global_request_id(filter_->child_id(), 1); | |
1050 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | |
1051 host_.GetURLRequest(global_request_id)); | |
1052 info->filter_.reset(); | |
1053 | |
1054 EXPECT_EQ(1, host_.pending_requests()); | |
1055 // Verify no redirects before resetting the filter. | |
1056 net::URLRequest* url_request = host_.GetURLRequest(global_request_id); | |
1057 EXPECT_EQ(1u, url_request->url_chain().size()); | |
1058 KickOffRequest(); | |
1059 | |
1060 // Verify that a redirect was followed. | |
1061 EXPECT_EQ(2u, url_request->url_chain().size()); | |
1062 | |
1063 // Make sure the request wasn't canceled early. | |
1064 EXPECT_EQ(1, host_.pending_requests()); | |
1065 | |
1066 // Finish up the request. | |
1067 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
1068 base::MessageLoop::current()->RunUntilIdle(); | |
1069 | |
1070 EXPECT_EQ(0, host_.pending_requests()); | |
1071 | |
1072 // Because the filter was deleted, no messages should have been sent. | |
1073 // TODO(jkarlin): It would be nice to verify that we successfully completed | |
1074 // the request, but we have no messages to verify with. | |
1075 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
1076 accum_.GetClassifiedMessages(&msgs); | |
1077 ASSERT_EQ(0U, msgs.size()); | |
1078 } | |
1079 | |
911 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { | 1080 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { |
912 bool was_deleted = false; | 1081 bool was_deleted = false; |
913 | 1082 |
914 // Arrange to have requests deferred before starting. | 1083 // Arrange to have requests deferred before starting. |
915 TestResourceDispatcherHostDelegate delegate; | 1084 TestResourceDispatcherHostDelegate delegate; |
916 delegate.set_flags(DEFER_STARTING_REQUEST); | 1085 delegate.set_flags(DEFER_STARTING_REQUEST); |
917 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); | 1086 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); |
918 host_.SetDelegate(&delegate); | 1087 host_.SetDelegate(&delegate); |
919 | 1088 |
920 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1089 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1070 | 1239 |
1071 // Tests CancelRequestsForProcess | 1240 // Tests CancelRequestsForProcess |
1072 TEST_F(ResourceDispatcherHostTest, TestProcessCancel) { | 1241 TEST_F(ResourceDispatcherHostTest, TestProcessCancel) { |
1073 scoped_refptr<TestFilter> test_filter = new TestFilter( | 1242 scoped_refptr<TestFilter> test_filter = new TestFilter( |
1074 browser_context_->GetResourceContext()); | 1243 browser_context_->GetResourceContext()); |
1075 | 1244 |
1076 // request 1 goes to the test delegate | 1245 // request 1 goes to the test delegate |
1077 ResourceHostMsg_Request request = CreateResourceRequest( | 1246 ResourceHostMsg_Request request = CreateResourceRequest( |
1078 "GET", ResourceType::SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); | 1247 "GET", ResourceType::SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); |
1079 | 1248 |
1080 MakeTestRequest(test_filter.get(), 0, 1, | 1249 MakeTestRequestWithResourceType(test_filter.get(), 0, 1, |
1081 net::URLRequestTestJob::test_url_1()); | 1250 net::URLRequestTestJob::test_url_1(), |
1251 ResourceType::SUB_RESOURCE); | |
1082 | 1252 |
1083 // request 2 goes to us | 1253 // request 2 goes to us |
1084 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); | 1254 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); |
1085 | 1255 |
1086 // request 3 goes to the test delegate | 1256 // request 3 goes to the test delegate |
1087 MakeTestRequest(test_filter.get(), 0, 3, | 1257 MakeTestRequestWithResourceType(test_filter.get(), 0, 3, |
1088 net::URLRequestTestJob::test_url_3()); | 1258 net::URLRequestTestJob::test_url_3(), |
1259 ResourceType::SUB_RESOURCE); | |
1260 | |
1261 // request 4 goes to us | |
1262 MakeTestRequestWithResourceType(filter_.get(), 0, 4, | |
1263 net::URLRequestTestJob::test_url_4(), | |
1264 ResourceType::PREFETCH); // detachable type | |
1265 | |
1089 | 1266 |
1090 // Make sure all requests have finished stage one. test_url_1 will have | 1267 // Make sure all requests have finished stage one. test_url_1 will have |
1091 // finished. | 1268 // finished. |
1092 base::MessageLoop::current()->RunUntilIdle(); | 1269 base::MessageLoop::current()->RunUntilIdle(); |
1093 | 1270 |
1094 // TODO(mbelshe): | 1271 // TODO(mbelshe): |
1095 // Now that the async IO path is in place, the IO always completes on the | 1272 // 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 | 1273 // initial call; so the requests have already completed. This basically |
1097 // breaks the whole test. | 1274 // breaks the whole test. |
1098 //EXPECT_EQ(3, host_.pending_requests()); | 1275 //EXPECT_EQ(3, host_.pending_requests()); |
1099 | 1276 |
1100 // Process each request for one level so one callback is called. | 1277 // Process test_url_2 and test_url_3 for one level so one callback is called. |
1278 // We'll cancel test_url_4 (detachable) before processing it to verify that it | |
1279 // delays the cancel. | |
1101 for (int i = 0; i < 2; i++) | 1280 for (int i = 0; i < 2; i++) |
1102 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1281 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1103 | 1282 |
1104 // Cancel the requests to the test process. | 1283 // Cancel the requests to the test process. |
1105 host_.CancelRequestsForProcess(filter_->child_id()); | 1284 host_.CancelRequestsForProcess(filter_->child_id()); |
1106 test_filter->has_canceled_ = true; | 1285 test_filter->has_canceled_ = true; |
1107 | 1286 |
1108 // Flush all the pending requests. | 1287 // Flush all the pending requests. |
1109 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1288 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1110 | 1289 |
1111 EXPECT_EQ(0, host_.pending_requests()); | 1290 EXPECT_EQ(0, host_.pending_requests()); |
1112 | 1291 |
1113 // The test delegate should not have gotten any messages after being canceled. | 1292 // The test delegate should not have gotten any messages after being canceled. |
1114 ASSERT_EQ(0, test_filter->received_after_canceled_); | 1293 ASSERT_EQ(0, test_filter->received_after_canceled_); |
1115 | 1294 |
1116 // We should have gotten exactly one result. | 1295 // We should have gotten two results. |
1117 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1296 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1118 accum_.GetClassifiedMessages(&msgs); | 1297 accum_.GetClassifiedMessages(&msgs); |
1298 ASSERT_EQ(2U, msgs.size()); | |
1299 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); | |
1300 // We cancelled the detachable request before it finished, and it should have | |
1301 // delayed and completed regardless. | |
1302 CheckSuccessfulDetachedRequest(msgs[1]); | |
1303 } | |
1304 | |
1305 TEST_F(ResourceDispatcherHostTest, TestProcessCancelDetachableTimesOut) { | |
1306 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | |
1307 net::URLRequestTestJob::test_url_4(), | |
1308 ResourceType::PREFETCH); // detachable type | |
1309 ResourceLoader* loader = host_.GetLoader(filter_->child_id(), 1); | |
1310 EXPECT_TRUE(loader); | |
1311 loader->set_detachable_delay_ms(200); | |
1312 base::MessageLoop::current()->RunUntilIdle(); | |
1313 | |
1314 // Cancel the requests to the test process. | |
1315 host_.CancelRequestsForProcess(filter_->child_id()); | |
1316 EXPECT_EQ(1, host_.pending_requests()); | |
1317 | |
1318 // Wait until after the delay timer times out before we start processing any | |
1319 // messages. | |
1320 base::OneShotTimer<base::MessageLoop> timer; | |
1321 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210), | |
1322 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle); | |
1323 base::MessageLoop::current()->Run(); | |
1324 | |
1325 // We should have cancelled the prefetch by now. | |
1326 EXPECT_EQ(0, host_.pending_requests()); | |
1327 | |
1328 // In case any messages are still to be processed. | |
1329 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
1330 base::MessageLoop::current()->RunUntilIdle(); | |
1331 | |
1332 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
1333 accum_.GetClassifiedMessages(&msgs); | |
1334 | |
1119 ASSERT_EQ(1U, msgs.size()); | 1335 ASSERT_EQ(1U, msgs.size()); |
1120 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); | 1336 |
1337 // The request should have cancelled. | |
1338 ASSERT_EQ(2U, msgs[0].size()); | |
1339 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | |
1340 CheckCancelledRequestCompleteMessage(msgs[0][1]); | |
1121 } | 1341 } |
1122 | 1342 |
1123 // Tests blocking and resuming requests. | 1343 // Tests blocking and resuming requests. |
1124 TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) { | 1344 TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) { |
1125 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1345 host_.BlockRequestsForRoute(filter_->child_id(), 1); |
1126 host_.BlockRequestsForRoute(filter_->child_id(), 2); | 1346 host_.BlockRequestsForRoute(filter_->child_id(), 2); |
1127 host_.BlockRequestsForRoute(filter_->child_id(), 3); | 1347 host_.BlockRequestsForRoute(filter_->child_id(), 3); |
1128 | 1348 |
1129 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1349 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
1130 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); | 1350 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1179 } | 1399 } |
1180 | 1400 |
1181 // Tests blocking and canceling requests. | 1401 // Tests blocking and canceling requests. |
1182 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { | 1402 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { |
1183 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1403 host_.BlockRequestsForRoute(filter_->child_id(), 1); |
1184 | 1404 |
1185 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1405 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
1186 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); | 1406 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); |
1187 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 1407 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); |
1188 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); | 1408 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); |
1409 // Blocked detachable resources should not delay cancellation. | |
1410 MakeTestRequestWithResourceType(filter_.get(), 1, 5, | |
1411 net::URLRequestTestJob::test_url_4(), | |
1412 ResourceType::PREFETCH); // detachable type | |
1189 | 1413 |
1190 // Flush all the pending requests. | 1414 // Flush all the pending requests. |
1191 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1415 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1192 | 1416 |
1193 // Sort out all the messages we saw by request. | 1417 // Sort out all the messages we saw by request. |
1194 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1418 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1195 accum_.GetClassifiedMessages(&msgs); | 1419 accum_.GetClassifiedMessages(&msgs); |
1196 | 1420 |
1197 // The 2 requests for the RVH 0 should have been processed. | 1421 // The 2 requests for the RVH 0 should have been processed. |
1198 ASSERT_EQ(2U, msgs.size()); | 1422 ASSERT_EQ(2U, msgs.size()); |
(...skipping 12 matching lines...) Expand all Loading... | |
1211 } | 1435 } |
1212 | 1436 |
1213 // Tests that blocked requests are canceled if their associated process dies. | 1437 // Tests that blocked requests are canceled if their associated process dies. |
1214 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { | 1438 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { |
1215 // This second filter is used to emulate a second process. | 1439 // This second filter is used to emulate a second process. |
1216 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1440 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1217 this, browser_context_->GetResourceContext()); | 1441 this, browser_context_->GetResourceContext()); |
1218 | 1442 |
1219 host_.BlockRequestsForRoute(second_filter->child_id(), 0); | 1443 host_.BlockRequestsForRoute(second_filter->child_id(), 0); |
1220 | 1444 |
1221 MakeTestRequest(filter_.get(), 0, 1, net::URLRequestTestJob::test_url_1()); | 1445 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
1222 MakeTestRequest(second_filter.get(), 0, 2, | 1446 net::URLRequestTestJob::test_url_1(), |
1223 net::URLRequestTestJob::test_url_2()); | 1447 ResourceType::SUB_RESOURCE); |
1224 MakeTestRequest(filter_.get(), 0, 3, net::URLRequestTestJob::test_url_3()); | 1448 MakeTestRequestWithResourceType(second_filter.get(), 0, 2, |
1225 MakeTestRequest(second_filter.get(), 0, 4, | 1449 net::URLRequestTestJob::test_url_2(), |
1226 net::URLRequestTestJob::test_url_1()); | 1450 ResourceType::SUB_RESOURCE); |
1451 MakeTestRequestWithResourceType(filter_.get(), 0, 3, | |
1452 net::URLRequestTestJob::test_url_3(), | |
1453 ResourceType::SUB_RESOURCE); | |
1454 MakeTestRequestWithResourceType(second_filter.get(), 0, 4, | |
1455 net::URLRequestTestJob::test_url_1(), | |
1456 ResourceType::SUB_RESOURCE); | |
1457 MakeTestRequestWithResourceType(second_filter.get(), 0, 5, | |
1458 net::URLRequestTestJob::test_url_4(), | |
1459 ResourceType::PREFETCH); // detachable type | |
1227 | 1460 |
1228 // Simulate process death. | 1461 // Simulate process death. |
1229 host_.CancelRequestsForProcess(second_filter->child_id()); | 1462 host_.CancelRequestsForProcess(second_filter->child_id()); |
1230 | 1463 |
1231 // Flush all the pending requests. | 1464 // Flush all the pending requests. |
1232 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1465 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1233 | 1466 |
1234 // Sort out all the messages we saw by request. | 1467 // Sort out all the messages we saw by request. |
1235 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1468 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1236 accum_.GetClassifiedMessages(&msgs); | 1469 accum_.GetClassifiedMessages(&msgs); |
1237 | 1470 |
1238 // The 2 requests for the RVH 0 should have been processed. | 1471 // The 2 requests for the RVH 0 should have been processed. Note that |
1472 // blocked detachable requests are canceled without delay. | |
1239 ASSERT_EQ(2U, msgs.size()); | 1473 ASSERT_EQ(2U, msgs.size()); |
1240 | 1474 |
1241 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1475 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
1242 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); | 1476 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); |
1243 | 1477 |
1244 EXPECT_TRUE(host_.blocked_loaders_map_.empty()); | 1478 EXPECT_TRUE(host_.blocked_loaders_map_.empty()); |
1245 } | 1479 } |
1246 | 1480 |
1247 // Tests that blocked requests don't leak when the ResourceDispatcherHost goes | 1481 // 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. | 1482 // 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 | 1483 // If this test turns the Purify bot red, check the ResourceDispatcherHost |
1250 // destructor to make sure the blocked requests are deleted. | 1484 // destructor to make sure the blocked requests are deleted. |
1251 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { | 1485 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { |
1252 // This second filter is used to emulate a second process. | 1486 // This second filter is used to emulate a second process. |
1253 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1487 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1254 this, browser_context_->GetResourceContext()); | 1488 this, browser_context_->GetResourceContext()); |
1255 | 1489 |
1256 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1490 host_.BlockRequestsForRoute(filter_->child_id(), 1); |
1257 host_.BlockRequestsForRoute(filter_->child_id(), 2); | 1491 host_.BlockRequestsForRoute(filter_->child_id(), 2); |
1258 host_.BlockRequestsForRoute(second_filter->child_id(), 1); | 1492 host_.BlockRequestsForRoute(second_filter->child_id(), 1); |
1259 | 1493 |
1260 MakeTestRequest(filter_.get(), 0, 1, net::URLRequestTestJob::test_url_1()); | 1494 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
1261 MakeTestRequest(filter_.get(), 1, 2, net::URLRequestTestJob::test_url_2()); | 1495 net::URLRequestTestJob::test_url_1(), |
1262 MakeTestRequest(filter_.get(), 0, 3, net::URLRequestTestJob::test_url_3()); | 1496 ResourceType::SUB_RESOURCE); |
1263 MakeTestRequest(second_filter.get(), 1, 4, | 1497 MakeTestRequestWithResourceType(filter_.get(), 1, 2, |
1264 net::URLRequestTestJob::test_url_1()); | 1498 net::URLRequestTestJob::test_url_2(), |
1265 MakeTestRequest(filter_.get(), 2, 5, net::URLRequestTestJob::test_url_2()); | 1499 ResourceType::SUB_RESOURCE); |
1266 MakeTestRequest(filter_.get(), 2, 6, net::URLRequestTestJob::test_url_3()); | 1500 MakeTestRequestWithResourceType(filter_.get(), 0, 3, |
1501 net::URLRequestTestJob::test_url_3(), | |
1502 ResourceType::SUB_RESOURCE); | |
1503 MakeTestRequestWithResourceType(second_filter.get(), 1, 4, | |
1504 net::URLRequestTestJob::test_url_1(), | |
1505 ResourceType::SUB_RESOURCE); | |
1506 MakeTestRequestWithResourceType(filter_.get(), 2, 5, | |
1507 net::URLRequestTestJob::test_url_2(), | |
1508 ResourceType::SUB_RESOURCE); | |
1509 MakeTestRequestWithResourceType(filter_.get(), 2, 6, | |
1510 net::URLRequestTestJob::test_url_3(), | |
1511 ResourceType::SUB_RESOURCE); | |
1512 MakeTestRequestWithResourceType(filter_.get(), 0, 7, | |
1513 net::URLRequestTestJob::test_url_4(), | |
1514 ResourceType::PREFETCH); // detachable type | |
1515 MakeTestRequestWithResourceType(second_filter.get(), 1, 8, | |
1516 net::URLRequestTestJob::test_url_4(), | |
1517 ResourceType::PREFETCH); // detachable type | |
1267 | 1518 |
1268 host_.CancelRequestsForProcess(filter_->child_id()); | 1519 host_.CancelRequestsForProcess(filter_->child_id()); |
1269 host_.CancelRequestsForProcess(second_filter->child_id()); | 1520 host_.CancelRequestsForProcess(second_filter->child_id()); |
1270 | 1521 |
1271 // Flush all the pending requests. | 1522 // Flush all the pending requests. |
1272 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1523 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1273 } | 1524 } |
1274 | 1525 |
1275 // Test the private helper method "CalculateApproximateMemoryCost()". | 1526 // Test the private helper method "CalculateApproximateMemoryCost()". |
1276 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { | 1527 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 | 1566 // Determine how many instance of test_url_2() we can request before |
1316 // throttling kicks in. | 1567 // throttling kicks in. |
1317 size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req; | 1568 size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req; |
1318 | 1569 |
1319 // This second filter is used to emulate a second process. | 1570 // This second filter is used to emulate a second process. |
1320 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1571 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1321 this, browser_context_->GetResourceContext()); | 1572 this, browser_context_->GetResourceContext()); |
1322 | 1573 |
1323 // Saturate the number of outstanding requests for our process. | 1574 // Saturate the number of outstanding requests for our process. |
1324 for (size_t i = 0; i < kMaxRequests; ++i) { | 1575 for (size_t i = 0; i < kMaxRequests; ++i) { |
1325 MakeTestRequest(filter_.get(), 0, i + 1, | 1576 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1, |
1326 net::URLRequestTestJob::test_url_2()); | 1577 net::URLRequestTestJob::test_url_2(), |
1578 ResourceType::SUB_RESOURCE); | |
1327 } | 1579 } |
1328 | 1580 |
1329 // Issue two more requests for our process -- these should fail immediately. | 1581 // Issue two more requests for our process -- these should fail immediately. |
1330 MakeTestRequest(filter_.get(), 0, kMaxRequests + 1, | 1582 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 1, |
1331 net::URLRequestTestJob::test_url_2()); | 1583 net::URLRequestTestJob::test_url_2(), |
1332 MakeTestRequest(filter_.get(), 0, kMaxRequests + 2, | 1584 ResourceType::SUB_RESOURCE); |
1333 net::URLRequestTestJob::test_url_2()); | 1585 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 2, |
1586 net::URLRequestTestJob::test_url_2(), | |
1587 ResourceType::SUB_RESOURCE); | |
1334 | 1588 |
1335 // Issue two requests for the second process -- these should succeed since | 1589 // Issue two requests for the second process -- these should succeed since |
1336 // it is just process 0 that is saturated. | 1590 // it is just process 0 that is saturated. |
1337 MakeTestRequest(second_filter.get(), 0, kMaxRequests + 3, | 1591 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3, |
1338 net::URLRequestTestJob::test_url_2()); | 1592 net::URLRequestTestJob::test_url_2(), |
1339 MakeTestRequest(second_filter.get(), 0, kMaxRequests + 4, | 1593 ResourceType::SUB_RESOURCE); |
1340 net::URLRequestTestJob::test_url_2()); | 1594 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4, |
1595 net::URLRequestTestJob::test_url_2(), | |
1596 ResourceType::SUB_RESOURCE); | |
1341 | 1597 |
1342 // Flush all the pending requests. | 1598 // Flush all the pending requests. |
1343 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1599 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1344 base::MessageLoop::current()->RunUntilIdle(); | 1600 base::MessageLoop::current()->RunUntilIdle(); |
1345 | 1601 |
1346 // Sorts out all the messages we saw by request. | 1602 // Sorts out all the messages we saw by request. |
1347 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1603 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1348 accum_.GetClassifiedMessages(&msgs); | 1604 accum_.GetClassifiedMessages(&msgs); |
1349 | 1605 |
1350 // We issued (kMaxRequests + 4) total requests. | 1606 // We issued (kMaxRequests + 4) total requests. |
(...skipping 30 matching lines...) Expand all Loading... | |
1381 host_.set_max_num_in_flight_requests(kMaxRequests); | 1637 host_.set_max_num_in_flight_requests(kMaxRequests); |
1382 | 1638 |
1383 // Needed to emulate additional processes. | 1639 // Needed to emulate additional processes. |
1384 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1640 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1385 this, browser_context_->GetResourceContext()); | 1641 this, browser_context_->GetResourceContext()); |
1386 scoped_refptr<ForwardingFilter> third_filter = new ForwardingFilter( | 1642 scoped_refptr<ForwardingFilter> third_filter = new ForwardingFilter( |
1387 this, browser_context_->GetResourceContext()); | 1643 this, browser_context_->GetResourceContext()); |
1388 | 1644 |
1389 // Saturate the number of outstanding requests for our process. | 1645 // Saturate the number of outstanding requests for our process. |
1390 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) { | 1646 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) { |
1391 MakeTestRequest(filter_.get(), 0, i + 1, | 1647 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1, |
1392 net::URLRequestTestJob::test_url_2()); | 1648 net::URLRequestTestJob::test_url_2(), |
1649 ResourceType::SUB_RESOURCE); | |
1393 } | 1650 } |
1394 | 1651 |
1395 // Issue another request for our process -- this should fail immediately. | 1652 // Issue another request for our process -- this should fail immediately. |
1396 MakeTestRequest(filter_.get(), 0, kMaxRequestsPerProcess + 1, | 1653 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequestsPerProcess + 1, |
1397 net::URLRequestTestJob::test_url_2()); | 1654 net::URLRequestTestJob::test_url_2(), |
1655 ResourceType::SUB_RESOURCE); | |
1398 | 1656 |
1399 // Issue a request for the second process -- this should succeed, because it | 1657 // Issue a request for the second process -- this should succeed, because it |
1400 // is just process 0 that is saturated. | 1658 // is just process 0 that is saturated. |
1401 MakeTestRequest(second_filter.get(), 0, kMaxRequestsPerProcess + 2, | 1659 MakeTestRequestWithResourceType( |
1402 net::URLRequestTestJob::test_url_2()); | 1660 second_filter.get(), 0, kMaxRequestsPerProcess + 2, |
1661 net::URLRequestTestJob::test_url_2(), ResourceType::SUB_RESOURCE); | |
1403 | 1662 |
1404 // Issue a request for the third process -- this should fail, because the | 1663 // Issue a request for the third process -- this should fail, because the |
1405 // global limit has been reached. | 1664 // global limit has been reached. |
1406 MakeTestRequest(third_filter.get(), 0, kMaxRequestsPerProcess + 3, | 1665 MakeTestRequestWithResourceType( |
1407 net::URLRequestTestJob::test_url_2()); | 1666 third_filter.get(), 0, kMaxRequestsPerProcess + 3, |
1667 net::URLRequestTestJob::test_url_2(), ResourceType::SUB_RESOURCE); | |
1408 | 1668 |
1409 // Flush all the pending requests. | 1669 // Flush all the pending requests. |
1410 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1670 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1411 base::MessageLoop::current()->RunUntilIdle(); | 1671 base::MessageLoop::current()->RunUntilIdle(); |
1412 | 1672 |
1413 // Sorts out all the messages we saw by request. | 1673 // Sorts out all the messages we saw by request. |
1414 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1674 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1415 accum_.GetClassifiedMessages(&msgs); | 1675 accum_.GetClassifiedMessages(&msgs); |
1416 | 1676 |
1417 // The processes issued the following requests: | 1677 // The processes issued the following requests: |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1537 } | 1797 } |
1538 | 1798 |
1539 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). | 1799 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). |
1540 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { | 1800 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { |
1541 std::string raw_headers("HTTP/1.1 403 Forbidden\n" | 1801 std::string raw_headers("HTTP/1.1 403 Forbidden\n" |
1542 "Content-disposition: attachment; filename=blah\n" | 1802 "Content-disposition: attachment; filename=blah\n" |
1543 "Content-type: application/octet-stream\n\n"); | 1803 "Content-type: application/octet-stream\n\n"); |
1544 std::string response_data("<html><title>Test One</title></html>"); | 1804 std::string response_data("<html><title>Test One</title></html>"); |
1545 SetResponse(raw_headers, response_data); | 1805 SetResponse(raw_headers, response_data); |
1546 | 1806 |
1807 HandleScheme("http"); | |
1808 | |
1547 // Only MAIN_FRAMEs can trigger a download. | 1809 // Only MAIN_FRAMEs can trigger a download. |
1548 SetResourceType(ResourceType::MAIN_FRAME); | 1810 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"), |
1549 | 1811 ResourceType::MAIN_FRAME); |
1550 HandleScheme("http"); | |
1551 MakeTestRequest(0, 1, GURL("http:bla")); | |
1552 | 1812 |
1553 // Flush all pending requests. | 1813 // Flush all pending requests. |
1554 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1814 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1555 | 1815 |
1556 // Sorts out all the messages we saw by request. | 1816 // Sorts out all the messages we saw by request. |
1557 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1817 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1558 accum_.GetClassifiedMessages(&msgs); | 1818 accum_.GetClassifiedMessages(&msgs); |
1559 | 1819 |
1560 // We should have gotten one RequestComplete message. | 1820 // We should have gotten one RequestComplete message. |
1561 ASSERT_EQ(1U, msgs[0].size()); | 1821 ASSERT_EQ(1U, msgs[0].size()); |
(...skipping 26 matching lines...) Expand all Loading... | |
1588 std::string response_data("01234567890123456789\x01foobar"); | 1848 std::string response_data("01234567890123456789\x01foobar"); |
1589 | 1849 |
1590 // Get past sniffing metrics in the BufferedResourceHandler. Note that | 1850 // Get past sniffing metrics in the BufferedResourceHandler. Note that |
1591 // if we don't get past the sniffing metrics, the result will be that | 1851 // 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, | 1852 // the BufferedResourceHandler won't have figured out that it's a download, |
1593 // won't have constructed a DownloadResourceHandler, and and the request | 1853 // won't have constructed a DownloadResourceHandler, and and the request |
1594 // will be successfully canceled below, failing the test. | 1854 // will be successfully canceled below, failing the test. |
1595 response_data.resize(1025, ' '); | 1855 response_data.resize(1025, ' '); |
1596 | 1856 |
1597 SetResponse(raw_headers, response_data); | 1857 SetResponse(raw_headers, response_data); |
1598 SetResourceType(ResourceType::MAIN_FRAME); | |
1599 SetDelayedCompleteJobGeneration(true); | 1858 SetDelayedCompleteJobGeneration(true); |
1600 HandleScheme("http"); | 1859 HandleScheme("http"); |
1601 | 1860 |
1602 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1861 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
1862 GURL("http://example.com/blah"), | |
1863 ResourceType::MAIN_FRAME); | |
1603 // Return some data so that the request is identified as a download | 1864 // Return some data so that the request is identified as a download |
1604 // and the proper resource handlers are created. | 1865 // and the proper resource handlers are created. |
1605 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1866 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1606 | 1867 |
1607 // And now simulate a cancellation coming from the renderer. | 1868 // And now simulate a cancellation coming from the renderer. |
1608 ResourceHostMsg_CancelRequest msg(request_id); | 1869 ResourceHostMsg_CancelRequest msg(request_id); |
1609 bool msg_was_ok; | 1870 bool msg_was_ok; |
1610 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1871 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1611 | 1872 |
1612 // Since the request had already started processing as a download, | 1873 // Since the request had already started processing as a download, |
(...skipping 10 matching lines...) Expand all Loading... | |
1623 int render_view_id = 0; | 1884 int render_view_id = 0; |
1624 int request_id = 1; | 1885 int request_id = 1; |
1625 | 1886 |
1626 std::string raw_headers("HTTP\n" | 1887 std::string raw_headers("HTTP\n" |
1627 "Content-disposition: attachment; filename=foo\n\n"); | 1888 "Content-disposition: attachment; filename=foo\n\n"); |
1628 std::string response_data("01234567890123456789\x01foobar"); | 1889 std::string response_data("01234567890123456789\x01foobar"); |
1629 // Get past sniffing metrics. | 1890 // Get past sniffing metrics. |
1630 response_data.resize(1025, ' '); | 1891 response_data.resize(1025, ' '); |
1631 | 1892 |
1632 SetResponse(raw_headers, response_data); | 1893 SetResponse(raw_headers, response_data); |
1633 SetResourceType(ResourceType::MAIN_FRAME); | |
1634 SetDelayedCompleteJobGeneration(true); | 1894 SetDelayedCompleteJobGeneration(true); |
1635 HandleScheme("http"); | 1895 HandleScheme("http"); |
1636 | 1896 |
1637 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1897 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
1898 GURL("http://example.com/blah"), | |
1899 ResourceType::MAIN_FRAME); | |
1638 // Return some data so that the request is identified as a download | 1900 // Return some data so that the request is identified as a download |
1639 // and the proper resource handlers are created. | 1901 // and the proper resource handlers are created. |
1640 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1902 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1641 | 1903 |
1642 // And now simulate a cancellation coming from the renderer. | 1904 // And now simulate a cancellation coming from the renderer. |
1643 ResourceHostMsg_CancelRequest msg(request_id); | 1905 ResourceHostMsg_CancelRequest msg(request_id); |
1644 bool msg_was_ok; | 1906 bool msg_was_ok; |
1645 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1907 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1646 | 1908 |
1647 // Since the request had already started processing as a download, | 1909 // Since the request had already started processing as a download, |
1648 // the cancellation above should have been ignored and the request | 1910 // the cancellation above should have been ignored and the request |
1649 // should still be alive. | 1911 // should still be alive. |
1650 EXPECT_EQ(1, host_.pending_requests()); | 1912 EXPECT_EQ(1, host_.pending_requests()); |
1651 | 1913 |
1652 // Cancelling by other methods shouldn't work either. | 1914 // Cancelling by other methods shouldn't work either. |
1653 host_.CancelRequestsForProcess(render_view_id); | 1915 host_.CancelRequestsForProcess(render_view_id); |
1654 EXPECT_EQ(1, host_.pending_requests()); | 1916 EXPECT_EQ(1, host_.pending_requests()); |
1655 | 1917 |
1656 // Cancelling by context should work. | 1918 // Cancelling by context should work. |
1657 host_.CancelRequestsForContext(filter_->resource_context()); | 1919 host_.CancelRequestsForContext(filter_->resource_context()); |
1658 EXPECT_EQ(0, host_.pending_requests()); | 1920 EXPECT_EQ(0, host_.pending_requests()); |
1659 } | 1921 } |
1660 | 1922 |
1923 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetachable) { | |
1924 EXPECT_EQ(0, host_.pending_requests()); | |
1925 | |
1926 int render_view_id = 0; | |
1927 int request_id = 1; | |
1928 | |
1929 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | |
1930 net::URLRequestTestJob::test_url_4(), | |
1931 ResourceType::PREFETCH); // detachable type | |
1932 | |
1933 // Simulate a cancel coming from the renderer. | |
1934 host_.CancelRequest(filter_->child_id(), request_id, true); | |
1935 | |
1936 // Since the request had already started processing as detachable, | |
1937 // the cancellation above should have been ignored and the request | |
1938 // should still be alive. | |
1939 EXPECT_EQ(1, host_.pending_requests()); | |
1940 | |
1941 // Cancelling by other methods should also be delayed. | |
1942 host_.CancelRequestsForProcess(render_view_id); | |
1943 EXPECT_EQ(1, host_.pending_requests()); | |
1944 | |
1945 // Cancelling by context should work. | |
1946 host_.CancelRequestsForContext(filter_->resource_context()); | |
1947 EXPECT_EQ(0, host_.pending_requests()); | |
1948 } | |
1949 | |
1661 // Test the cancelling of requests that are being transferred to a new renderer | 1950 // Test the cancelling of requests that are being transferred to a new renderer |
1662 // due to a redirection. | 1951 // due to a redirection. |
1663 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { | 1952 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { |
1664 EXPECT_EQ(0, host_.pending_requests()); | 1953 EXPECT_EQ(0, host_.pending_requests()); |
1665 | 1954 |
1666 int render_view_id = 0; | 1955 int render_view_id = 0; |
1667 int request_id = 1; | 1956 int request_id = 1; |
1668 | 1957 |
1669 std::string raw_headers("HTTP/1.1 200 OK\n" | 1958 std::string raw_headers("HTTP/1.1 200 OK\n" |
1670 "Content-Type: text/html; charset=utf-8\n\n"); | 1959 "Content-Type: text/html; charset=utf-8\n\n"); |
1671 std::string response_data("<html>foobar</html>"); | 1960 std::string response_data("<html>foobar</html>"); |
1672 | 1961 |
1673 SetResponse(raw_headers, response_data); | 1962 SetResponse(raw_headers, response_data); |
1674 SetResourceType(ResourceType::MAIN_FRAME); | |
1675 HandleScheme("http"); | 1963 HandleScheme("http"); |
1676 | 1964 |
1677 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1965 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
1966 GURL("http://example.com/blah"), | |
1967 ResourceType::MAIN_FRAME); | |
1968 | |
1678 | 1969 |
1679 GlobalRequestID global_request_id(filter_->child_id(), request_id); | 1970 GlobalRequestID global_request_id(filter_->child_id(), request_id); |
1680 host_.MarkAsTransferredNavigation(global_request_id, | 1971 host_.MarkAsTransferredNavigation(global_request_id, |
1681 GURL("http://example.com/blah")); | 1972 GURL("http://example.com/blah")); |
1682 | 1973 |
1683 // And now simulate a cancellation coming from the renderer. | 1974 // And now simulate a cancellation coming from the renderer. |
1684 ResourceHostMsg_CancelRequest msg(request_id); | 1975 ResourceHostMsg_CancelRequest msg(request_id); |
1685 bool msg_was_ok; | 1976 bool msg_was_ok; |
1686 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1977 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1687 | 1978 |
(...skipping 16 matching lines...) Expand all Loading... | |
1704 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) { | 1995 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) { |
1705 EXPECT_EQ(0, host_.pending_requests()); | 1996 EXPECT_EQ(0, host_.pending_requests()); |
1706 | 1997 |
1707 int render_view_id = 0; | 1998 int render_view_id = 0; |
1708 int request_id = 1; | 1999 int request_id = 1; |
1709 | 2000 |
1710 // Configure initial request. | 2001 // Configure initial request. |
1711 SetResponse("HTTP/1.1 302 Found\n" | 2002 SetResponse("HTTP/1.1 302 Found\n" |
1712 "Location: http://other.com/blech\n\n"); | 2003 "Location: http://other.com/blech\n\n"); |
1713 | 2004 |
1714 SetResourceType(ResourceType::MAIN_FRAME); | |
1715 HandleScheme("http"); | 2005 HandleScheme("http"); |
1716 | 2006 |
1717 // Temporarily replace ContentBrowserClient with one that will trigger the | 2007 // Temporarily replace ContentBrowserClient with one that will trigger the |
1718 // transfer navigation code paths. | 2008 // transfer navigation code paths. |
1719 TransfersAllNavigationsContentBrowserClient new_client; | 2009 TransfersAllNavigationsContentBrowserClient new_client; |
1720 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 2010 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1721 | 2011 |
1722 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 2012 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
2013 GURL("http://example.com/blah"), ResourceType::MAIN_FRAME); | |
1723 | 2014 |
1724 // Now that we're blocked on the redirect, update the response and unblock by | 2015 // Now that we're blocked on the redirect, update the response and unblock by |
1725 // telling the AsyncResourceHandler to follow the redirect. | 2016 // telling the AsyncResourceHandler to follow the redirect. |
1726 const std::string kResponseBody = "hello world"; | 2017 const std::string kResponseBody = "hello world"; |
1727 SetResponse("HTTP/1.1 200 OK\n" | 2018 SetResponse("HTTP/1.1 200 OK\n" |
1728 "Content-Type: text/html\n\n", | 2019 "Content-Type: text/html\n\n", |
1729 kResponseBody); | 2020 kResponseBody); |
1730 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); | 2021 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
1731 bool msg_was_ok; | 2022 bool msg_was_ok; |
1732 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); | 2023 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) { | 2066 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { |
1776 EXPECT_EQ(0, host_.pending_requests()); | 2067 EXPECT_EQ(0, host_.pending_requests()); |
1777 | 2068 |
1778 int render_view_id = 0; | 2069 int render_view_id = 0; |
1779 int request_id = 1; | 2070 int request_id = 1; |
1780 | 2071 |
1781 // Configure initial request. | 2072 // Configure initial request. |
1782 SetResponse("HTTP/1.1 302 Found\n" | 2073 SetResponse("HTTP/1.1 302 Found\n" |
1783 "Location: http://other.com/blech\n\n"); | 2074 "Location: http://other.com/blech\n\n"); |
1784 | 2075 |
1785 SetResourceType(ResourceType::MAIN_FRAME); | |
1786 HandleScheme("http"); | 2076 HandleScheme("http"); |
1787 | 2077 |
1788 // Temporarily replace ContentBrowserClient with one that will trigger the | 2078 // Temporarily replace ContentBrowserClient with one that will trigger the |
1789 // transfer navigation code paths. | 2079 // transfer navigation code paths. |
1790 TransfersAllNavigationsContentBrowserClient new_client; | 2080 TransfersAllNavigationsContentBrowserClient new_client; |
1791 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 2081 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1792 | 2082 |
1793 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 2083 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
2084 GURL("http://example.com/blah"), | |
2085 ResourceType::MAIN_FRAME); | |
1794 | 2086 |
1795 // Now that we're blocked on the redirect, update the response and unblock by | 2087 // 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 | 2088 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain |
1797 // MIME type, which causes BufferedResourceHandler to buffer it before the | 2089 // MIME type, which causes BufferedResourceHandler to buffer it before the |
1798 // transfer occurs. | 2090 // transfer occurs. |
1799 const std::string kResponseBody = "hello world"; | 2091 const std::string kResponseBody = "hello world"; |
1800 SetResponse("HTTP/1.1 200 OK\n" | 2092 SetResponse("HTTP/1.1 200 OK\n" |
1801 "Content-Type: text/plain\n\n", | 2093 "Content-Type: text/plain\n\n", |
1802 kResponseBody); | 2094 kResponseBody); |
1803 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); | 2095 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1847 | 2139 |
1848 int render_view_id = 0; | 2140 int render_view_id = 0; |
1849 int request_id = 1; | 2141 int request_id = 1; |
1850 int first_child_id = -1; | 2142 int first_child_id = -1; |
1851 | 2143 |
1852 // Configure initial request. | 2144 // Configure initial request. |
1853 SetResponse("HTTP/1.1 302 Found\n" | 2145 SetResponse("HTTP/1.1 302 Found\n" |
1854 "Location: http://other.com/blech\n\n"); | 2146 "Location: http://other.com/blech\n\n"); |
1855 const std::string kResponseBody = "hello world"; | 2147 const std::string kResponseBody = "hello world"; |
1856 | 2148 |
1857 SetResourceType(ResourceType::MAIN_FRAME); | |
1858 HandleScheme("http"); | 2149 HandleScheme("http"); |
1859 | 2150 |
1860 // Temporarily replace ContentBrowserClient with one that will trigger the | 2151 // Temporarily replace ContentBrowserClient with one that will trigger the |
1861 // transfer navigation code paths. | 2152 // transfer navigation code paths. |
1862 TransfersAllNavigationsContentBrowserClient new_client; | 2153 TransfersAllNavigationsContentBrowserClient new_client; |
1863 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 2154 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1864 | 2155 |
1865 // Create a first filter that can be deleted before the second one starts. | 2156 // Create a first filter that can be deleted before the second one starts. |
1866 { | 2157 { |
1867 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter( | 2158 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) { | 2227 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { |
1937 EXPECT_EQ(0, host_.pending_requests()); | 2228 EXPECT_EQ(0, host_.pending_requests()); |
1938 | 2229 |
1939 int render_view_id = 0; | 2230 int render_view_id = 0; |
1940 int request_id = 1; | 2231 int request_id = 1; |
1941 | 2232 |
1942 // Configure initial request. | 2233 // Configure initial request. |
1943 SetResponse("HTTP/1.1 302 Found\n" | 2234 SetResponse("HTTP/1.1 302 Found\n" |
1944 "Location: http://other.com/blech\n\n"); | 2235 "Location: http://other.com/blech\n\n"); |
1945 | 2236 |
1946 SetResourceType(ResourceType::MAIN_FRAME); | |
1947 HandleScheme("http"); | 2237 HandleScheme("http"); |
1948 | 2238 |
1949 // Temporarily replace ContentBrowserClient with one that will trigger the | 2239 // Temporarily replace ContentBrowserClient with one that will trigger the |
1950 // transfer navigation code paths. | 2240 // transfer navigation code paths. |
1951 TransfersAllNavigationsContentBrowserClient new_client; | 2241 TransfersAllNavigationsContentBrowserClient new_client; |
1952 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 2242 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1953 | 2243 |
1954 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 2244 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
2245 GURL("http://example.com/blah"), | |
2246 ResourceType::MAIN_FRAME); | |
1955 | 2247 |
1956 // Now that we're blocked on the redirect, simulate hitting another redirect. | 2248 // Now that we're blocked on the redirect, simulate hitting another redirect. |
1957 SetResponse("HTTP/1.1 302 Found\n" | 2249 SetResponse("HTTP/1.1 302 Found\n" |
1958 "Location: http://other.com/blerg\n\n"); | 2250 "Location: http://other.com/blerg\n\n"); |
1959 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); | 2251 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
1960 bool msg_was_ok; | 2252 bool msg_was_ok; |
1961 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); | 2253 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); |
1962 base::MessageLoop::current()->RunUntilIdle(); | 2254 base::MessageLoop::current()->RunUntilIdle(); |
1963 | 2255 |
1964 // Now that we're blocked on the second redirect, update the response and | 2256 // 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); | 2309 accum_.GetClassifiedMessages(&msgs); |
2018 | 2310 |
2019 ASSERT_EQ(2U, msgs.size()); | 2311 ASSERT_EQ(2U, msgs.size()); |
2020 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2312 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
2021 CheckSuccessfulRequest(msgs[1], kResponseBody); | 2313 CheckSuccessfulRequest(msgs[1], kResponseBody); |
2022 } | 2314 } |
2023 | 2315 |
2024 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { | 2316 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { |
2025 EXPECT_EQ(0, host_.pending_requests()); | 2317 EXPECT_EQ(0, host_.pending_requests()); |
2026 | 2318 |
2027 SetResourceType(ResourceType::MAIN_FRAME); | |
2028 HandleScheme("http"); | 2319 HandleScheme("http"); |
2029 | 2320 |
2030 MakeTestRequest(0, 1, GURL("foo://bar")); | 2321 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"), |
2322 ResourceType::MAIN_FRAME); | |
2031 | 2323 |
2032 // Flush all pending requests. | 2324 // Flush all pending requests. |
2033 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2325 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
2034 | 2326 |
2035 // Sort all the messages we saw by request. | 2327 // Sort all the messages we saw by request. |
2036 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2328 ResourceIPCAccumulator::ClassifiedMessages msgs; |
2037 accum_.GetClassifiedMessages(&msgs); | 2329 accum_.GetClassifiedMessages(&msgs); |
2038 | 2330 |
2039 // We should have gotten one RequestComplete message. | 2331 // We should have gotten one RequestComplete message. |
2040 ASSERT_EQ(1U, msgs[0].size()); | 2332 ASSERT_EQ(1U, msgs[0].size()); |
(...skipping 26 matching lines...) Expand all Loading... | |
2067 | 2359 |
2068 size_t size = msgs[0].size(); | 2360 size_t size = msgs[0].size(); |
2069 | 2361 |
2070 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 2362 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
2071 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); | 2363 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); |
2072 for (size_t i = 2; i < size - 1; ++i) | 2364 for (size_t i = 2; i < size - 1; ++i) |
2073 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 2365 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
2074 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type()); | 2366 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type()); |
2075 } | 2367 } |
2076 | 2368 |
2369 // Request a very large detachable resource. This verifies that the data is not | |
2370 // sent to the render process. | |
2371 TEST_F(ResourceDispatcherHostTest, DetachableNoDataSentOrReceived) { | |
2372 EXPECT_EQ(0, host_.pending_requests()); | |
2373 | |
2374 SendDataReceivedACKs(true); | |
2375 | |
2376 HandleScheme("big-job"); | |
2377 | |
2378 // This request would normally result in many messages (>300). | |
2379 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | |
2380 GURL("big-job:0123456789,1000000"), | |
2381 ResourceType::PREFETCH); // detachable type | |
2382 | |
2383 // Sort all the messages we saw by request. | |
2384 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
2385 accum_.GetClassifiedMessages(&msgs); | |
2386 | |
2387 EXPECT_EQ(2u, msgs[0].size()); | |
2388 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | |
2389 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][1].type()); | |
2390 } | |
2391 | |
2077 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { | 2392 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { |
2078 EXPECT_EQ(0, host_.pending_requests()); | 2393 EXPECT_EQ(0, host_.pending_requests()); |
2079 | 2394 |
2080 HandleScheme("big-job"); | 2395 HandleScheme("big-job"); |
2081 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 2396 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
2082 | 2397 |
2083 // Sort all the messages we saw by request. | 2398 // Sort all the messages we saw by request. |
2084 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2399 ResourceIPCAccumulator::ClassifiedMessages msgs; |
2085 accum_.GetClassifiedMessages(&msgs); | 2400 accum_.GetClassifiedMessages(&msgs); |
2086 | 2401 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2168 } | 2483 } |
2169 | 2484 |
2170 base::MessageLoop::current()->RunUntilIdle(); | 2485 base::MessageLoop::current()->RunUntilIdle(); |
2171 | 2486 |
2172 msgs.clear(); | 2487 msgs.clear(); |
2173 accum_.GetClassifiedMessages(&msgs); | 2488 accum_.GetClassifiedMessages(&msgs); |
2174 } | 2489 } |
2175 } | 2490 } |
2176 | 2491 |
2177 } // namespace content | 2492 } // namespace content |
OLD | NEW |