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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 25772002: Allows prefetch requests to live beyond the renderer by delaying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Possible AsyncResourceHandler support for detached resources. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
8 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
9 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/pickle.h" 12 #include "base/pickle.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
15 #include "content/browser/browser_thread_impl.h" 16 #include "content/browser/browser_thread_impl.h"
16 #include "content/browser/child_process_security_policy_impl.h" 17 #include "content/browser/child_process_security_policy_impl.h"
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" 18 #include "content/browser/loader/resource_dispatcher_host_impl.h"
19 #include "content/browser/loader/resource_loader.h"
18 #include "content/browser/loader/resource_message_filter.h" 20 #include "content/browser/loader/resource_message_filter.h"
19 #include "content/browser/loader/resource_request_info_impl.h" 21 #include "content/browser/loader/resource_request_info_impl.h"
20 #include "content/browser/worker_host/worker_service_impl.h" 22 #include "content/browser/worker_host/worker_service_impl.h"
21 #include "content/common/child_process_host_impl.h" 23 #include "content/common/child_process_host_impl.h"
22 #include "content/common/resource_messages.h" 24 #include "content/common/resource_messages.h"
23 #include "content/common/view_messages.h" 25 #include "content/common/view_messages.h"
24 #include "content/public/browser/global_request_id.h" 26 #include "content/public/browser/global_request_id.h"
25 #include "content/public/browser/resource_context.h" 27 #include "content/public/browser/resource_context.h"
26 #include "content/public/browser/resource_dispatcher_host_delegate.h" 28 #include "content/public/browser/resource_dispatcher_host_delegate.h"
27 #include "content/public/browser/resource_request_info.h" 29 #include "content/public/browser/resource_request_info.h"
28 #include "content/public/browser/resource_throttle.h" 30 #include "content/public/browser/resource_throttle.h"
31 #include "content/public/common/content_switches.h"
29 #include "content/public/common/process_type.h" 32 #include "content/public/common/process_type.h"
30 #include "content/public/common/resource_response.h" 33 #include "content/public/common/resource_response.h"
31 #include "content/public/test/test_browser_context.h" 34 #include "content/public/test/test_browser_context.h"
32 #include "content/test/test_content_browser_client.h" 35 #include "content/test/test_content_browser_client.h"
33 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
34 #include "net/base/upload_bytes_element_reader.h" 37 #include "net/base/upload_bytes_element_reader.h"
35 #include "net/base/upload_data_stream.h" 38 #include "net/base/upload_data_stream.h"
36 #include "net/http/http_util.h" 39 #include "net/http/http_util.h"
37 #include "net/url_request/url_request.h" 40 #include "net/url_request/url_request.h"
38 #include "net/url_request/url_request_context.h" 41 #include "net/url_request/url_request_context.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 519
517 class ResourceDispatcherHostTest : public testing::Test, 520 class ResourceDispatcherHostTest : public testing::Test,
518 public IPC::Sender { 521 public IPC::Sender {
519 public: 522 public:
520 ResourceDispatcherHostTest() 523 ResourceDispatcherHostTest()
521 : ui_thread_(BrowserThread::UI, &message_loop_), 524 : ui_thread_(BrowserThread::UI, &message_loop_),
522 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), 525 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_),
523 cache_thread_(BrowserThread::CACHE, &message_loop_), 526 cache_thread_(BrowserThread::CACHE, &message_loop_),
524 io_thread_(BrowserThread::IO, &message_loop_), 527 io_thread_(BrowserThread::IO, &message_loop_),
525 old_factory_(NULL), 528 old_factory_(NULL),
526 resource_type_(ResourceType::SUB_RESOURCE),
527 send_data_received_acks_(false) { 529 send_data_received_acks_(false) {
528 browser_context_.reset(new TestBrowserContext()); 530 browser_context_.reset(new TestBrowserContext());
529 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); 531 BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
530 message_loop_.RunUntilIdle(); 532 message_loop_.RunUntilIdle();
531 filter_ = new ForwardingFilter( 533 filter_ = new ForwardingFilter(
532 this, browser_context_->GetResourceContext()); 534 this, browser_context_->GetResourceContext());
533 } 535 }
534 536
535 virtual ~ResourceDispatcherHostTest() { 537 virtual ~ResourceDispatcherHostTest() {
536 for (std::set<int>::iterator it = child_ids_.begin(); 538 for (std::set<int>::iterator it = child_ids_.begin();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 if (ResourceDispatcherHostImpl::Get()) 589 if (ResourceDispatcherHostImpl::Get())
588 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext( 590 ResourceDispatcherHostImpl::Get()->CancelRequestsForContext(
589 browser_context_->GetResourceContext()); 591 browser_context_->GetResourceContext());
590 592
591 WorkerServiceImpl::GetInstance()->PerformTeardownForTesting(); 593 WorkerServiceImpl::GetInstance()->PerformTeardownForTesting();
592 594
593 browser_context_.reset(); 595 browser_context_.reset();
594 message_loop_.RunUntilIdle(); 596 message_loop_.RunUntilIdle();
595 } 597 }
596 598
597 // Creates a request using the current test object as the filter. 599 // Creates a request using the current test object as the filter and
600 // SubResource as the resource type.
598 void MakeTestRequest(int render_view_id, 601 void MakeTestRequest(int render_view_id,
599 int request_id, 602 int request_id,
600 const GURL& url); 603 const GURL& url);
601 604
602 // Generates a request using the given filter. This will probably be a 605 // Generates a request using the given filter and resource type.
603 // ForwardingFilter. 606 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter,
604 void MakeTestRequest(ResourceMessageFilter* filter, 607 int render_view_id, int request_id,
605 int render_view_id, 608 const GURL& url,
606 int request_id, 609 ResourceType::Type type);
607 const GURL& url);
608 610
609 void CancelRequest(int request_id); 611 void CancelRequest(int request_id);
610 612
611 void CompleteStartRequest(int request_id); 613 void CompleteStartRequest(int request_id);
612 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); 614 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id);
613 615
614 void EnsureSchemeIsAllowed(const std::string& scheme) { 616 void EnsureSchemeIsAllowed(const std::string& scheme) {
615 ChildProcessSecurityPolicyImpl* policy = 617 ChildProcessSecurityPolicyImpl* policy =
616 ChildProcessSecurityPolicyImpl::GetInstance(); 618 ChildProcessSecurityPolicyImpl::GetInstance();
617 if (!policy->IsWebSafeScheme(scheme)) 619 if (!policy->IsWebSafeScheme(scheme))
618 policy->RegisterWebSafeScheme(scheme); 620 policy->RegisterWebSafeScheme(scheme);
619 } 621 }
620 622
621 void EnsureTestSchemeIsAllowed() { 623 void EnsureTestSchemeIsAllowed() {
622 EnsureSchemeIsAllowed("test"); 624 EnsureSchemeIsAllowed("test");
623 } 625 }
624 626
625 // Sets a particular response for any request from now on. To switch back to 627 // 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- 628 // the default bahavior, pass an empty |headers|. |headers| should be raw-
627 // formatted (NULLs instead of EOLs). 629 // formatted (NULLs instead of EOLs).
628 void SetResponse(const std::string& headers, const std::string& data) { 630 void SetResponse(const std::string& headers, const std::string& data) {
629 response_headers_ = net::HttpUtil::AssembleRawHeaders(headers.data(), 631 response_headers_ = net::HttpUtil::AssembleRawHeaders(headers.data(),
630 headers.size()); 632 headers.size());
631 response_data_ = data; 633 response_data_ = data;
632 } 634 }
633 void SetResponse(const std::string& headers) { 635 void SetResponse(const std::string& headers) {
634 SetResponse(headers, std::string()); 636 SetResponse(headers, std::string());
635 } 637 }
636 638
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) { 639 void SendDataReceivedACKs(bool send_acks) {
643 send_data_received_acks_ = send_acks; 640 send_data_received_acks_ = send_acks;
644 } 641 }
645 642
646 // Intercepts requests for the given protocol. 643 // Intercepts requests for the given protocol.
647 void HandleScheme(const std::string& scheme) { 644 void HandleScheme(const std::string& scheme) {
648 DCHECK(scheme_.empty()); 645 DCHECK(scheme_.empty());
649 DCHECK(!old_factory_); 646 DCHECK(!old_factory_);
650 scheme_ = scheme; 647 scheme_ = scheme;
651 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( 648 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 BrowserThreadImpl cache_thread_; 714 BrowserThreadImpl cache_thread_;
718 BrowserThreadImpl io_thread_; 715 BrowserThreadImpl io_thread_;
719 scoped_ptr<TestBrowserContext> browser_context_; 716 scoped_ptr<TestBrowserContext> browser_context_;
720 scoped_refptr<ForwardingFilter> filter_; 717 scoped_refptr<ForwardingFilter> filter_;
721 ResourceDispatcherHostImpl host_; 718 ResourceDispatcherHostImpl host_;
722 ResourceIPCAccumulator accum_; 719 ResourceIPCAccumulator accum_;
723 std::string response_headers_; 720 std::string response_headers_;
724 std::string response_data_; 721 std::string response_data_;
725 std::string scheme_; 722 std::string scheme_;
726 net::URLRequest::ProtocolFactory* old_factory_; 723 net::URLRequest::ProtocolFactory* old_factory_;
727 ResourceType::Type resource_type_;
728 bool send_data_received_acks_; 724 bool send_data_received_acks_;
729 std::set<int> child_ids_; 725 std::set<int> child_ids_;
730 static ResourceDispatcherHostTest* test_fixture_; 726 static ResourceDispatcherHostTest* test_fixture_;
731 static bool delay_start_; 727 static bool delay_start_;
732 static bool delay_complete_; 728 static bool delay_complete_;
733 static int url_request_jobs_created_count_; 729 static int url_request_jobs_created_count_;
734 }; 730 };
735 // Static. 731 // Static.
736 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; 732 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL;
737 bool ResourceDispatcherHostTest::delay_start_ = false; 733 bool ResourceDispatcherHostTest::delay_start_ = false;
738 bool ResourceDispatcherHostTest::delay_complete_ = false; 734 bool ResourceDispatcherHostTest::delay_complete_ = false;
739 int ResourceDispatcherHostTest::url_request_jobs_created_count_ = 0; 735 int ResourceDispatcherHostTest::url_request_jobs_created_count_ = 0;
740 736
741 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, 737 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id,
742 int request_id, 738 int request_id,
743 const GURL& url) { 739 const GURL& url) {
744 MakeTestRequest(filter_.get(), render_view_id, request_id, url); 740 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
741 url, ResourceType::SUB_RESOURCE);
745 } 742 }
746 743
747 void ResourceDispatcherHostTest::MakeTestRequest( 744 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType(
748 ResourceMessageFilter* filter, 745 ResourceMessageFilter* filter,
749 int render_view_id, 746 int render_view_id,
750 int request_id, 747 int request_id,
751 const GURL& url) { 748 const GURL& url,
749 ResourceType::Type type) {
752 // If it's already there, this'll be dropped on the floor, which is fine. 750 // If it's already there, this'll be dropped on the floor, which is fine.
753 child_ids_.insert(filter->child_id()); 751 child_ids_.insert(filter->child_id());
754 752
755 ResourceHostMsg_Request request = 753 ResourceHostMsg_Request request =
756 CreateResourceRequest("GET", resource_type_, url); 754 CreateResourceRequest("GET", type, url);
757 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); 755 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
758 bool msg_was_ok; 756 bool msg_was_ok;
759 host_.OnMessageReceived(msg, filter, &msg_was_ok); 757 host_.OnMessageReceived(msg, filter, &msg_was_ok);
760 KickOffRequest(); 758 KickOffRequest();
761 } 759 }
762 760
763 void ResourceDispatcherHostTest::CancelRequest(int request_id) { 761 void ResourceDispatcherHostTest::CancelRequest(int request_id) {
764 host_.CancelRequest(filter_->child_id(), request_id, false); 762 host_.CancelRequest(filter_->child_id(), request_id, false);
765 } 763 }
766 764
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 899
902 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); 900 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1());
903 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); 901 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3());
904 902
905 // Check that request 2 got canceled. 903 // Check that request 2 got canceled.
906 ASSERT_EQ(2U, msgs[1].size()); 904 ASSERT_EQ(2U, msgs[1].size());
907 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); 905 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type());
908 CheckCancelledRequestCompleteMessage(msgs[1][1]); 906 CheckCancelledRequestCompleteMessage(msgs[1][1]);
909 } 907 }
910 908
909 // Shows that unlike normal requests, detachable async requests are not
910 // immediately canceled, and will complete within a timeout period.
911 TEST_F(ResourceDispatcherHostTest, DetachableIgnoreCancel) {
912 CommandLine* command_line = CommandLine::ForCurrentProcess();
913 command_line->AppendSwitch(switches::kDelayDetachableCancellation);
914 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
915 net::URLRequestTestJob::test_url_1(),
916 ResourceType::PREFETCH);
917 MakeTestRequestWithResourceType(filter_.get(), 0, 2,
918 net::URLRequestTestJob::test_url_2(),
919 ResourceType::PREFETCH);
920 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3());
921
922 // test_url_1 is synchronous and already complete.
923 EXPECT_EQ(2, host_.pending_requests());
924 // We need to make sure that the request comes from the renderer, else it
925 // won't delay.
926 host_.CancelRequest(filter_->child_id(), 2, true);
927 host_.CancelRequest(filter_->child_id(), 3, true);
928
929 // Process any completion messages from cancelling.
930 base::MessageLoop::current()->RunUntilIdle();
931
932 EXPECT_EQ(1, host_.pending_requests());
933
934 // Run the requests to completion.
935 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
936 base::MessageLoop::current()->RunUntilIdle();
937
938 EXPECT_EQ(0, host_.pending_requests());
939
940 ResourceIPCAccumulator::ClassifiedMessages msgs;
941 accum_.GetClassifiedMessages(&msgs);
942
943 ASSERT_EQ(3U, msgs.size());
944
945 // The first fetch was synchronous and should have completed successfully.
946 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
947 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][1].type());
948
949 // The prefetch should have ignored the cancel and completed. Note that
950 // prefetches run detached and do not receive data notifications.
951 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type());
952 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type());
953 // Verify that there was no error.
954 int request_id;
955 int error_code;
956 PickleIterator iter(msgs[1][1]);
957 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &request_id));
958 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &error_code));
959 EXPECT_EQ(0, error_code);
960
961 // Request 3 should have been cancelled immediately.
962 ASSERT_EQ(2U, msgs[2].size());
963 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[2][0].type());
964 CheckCancelledRequestCompleteMessage(msgs[2][1]);
965 }
966
967 // Shows that detached requests will timeout if the request takes too long to
968 // complete.
969 TEST_F(ResourceDispatcherHostTest, DetachedResourceTimesOut) {
970 CommandLine* command_line = CommandLine::ForCurrentProcess();
971 command_line->AppendSwitchASCII(switches::kDelayDetachableCancellation,
972 "200");
973
974 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
975 net::URLRequestTestJob::test_url_2(),
976 ResourceType::PREFETCH);
977 host_.CancelRequest(filter_->child_id(), 1, true);
978 base::MessageLoop::current()->RunUntilIdle();
979 EXPECT_EQ(1, host_.pending_requests());
980
981 // Wait until after the delay timer times before letting any Reads complete.
982 base::OneShotTimer<base::MessageLoop> timer;
983 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210),
984 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle);
985
986 // We should have cancelled the prefetch by now.
987 base::MessageLoop::current()->Run();
988 EXPECT_EQ(0, host_.pending_requests());
989
990 // In case any messages are still to be processed.
991 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
992 base::MessageLoop::current()->RunUntilIdle();
993
994 ResourceIPCAccumulator::ClassifiedMessages msgs;
995 accum_.GetClassifiedMessages(&msgs);
996
997 ASSERT_EQ(1U, msgs.size());
998
999 // The request should have cancelled.
1000 ASSERT_EQ(2U, msgs[0].size());
1001 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
1002 CheckCancelledRequestCompleteMessage(msgs[0][1]);
1003 }
1004
911 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { 1005 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) {
912 bool was_deleted = false; 1006 bool was_deleted = false;
913 1007
914 // Arrange to have requests deferred before starting. 1008 // Arrange to have requests deferred before starting.
915 TestResourceDispatcherHostDelegate delegate; 1009 TestResourceDispatcherHostDelegate delegate;
916 delegate.set_flags(DEFER_STARTING_REQUEST); 1010 delegate.set_flags(DEFER_STARTING_REQUEST);
917 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); 1011 delegate.set_url_request_user_data(new TestUserData(&was_deleted));
918 host_.SetDelegate(&delegate); 1012 host_.SetDelegate(&delegate);
919 1013
920 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); 1014 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1());
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 1164
1071 // Tests CancelRequestsForProcess 1165 // Tests CancelRequestsForProcess
1072 TEST_F(ResourceDispatcherHostTest, TestProcessCancel) { 1166 TEST_F(ResourceDispatcherHostTest, TestProcessCancel) {
1073 scoped_refptr<TestFilter> test_filter = new TestFilter( 1167 scoped_refptr<TestFilter> test_filter = new TestFilter(
1074 browser_context_->GetResourceContext()); 1168 browser_context_->GetResourceContext());
1075 1169
1076 // request 1 goes to the test delegate 1170 // request 1 goes to the test delegate
1077 ResourceHostMsg_Request request = CreateResourceRequest( 1171 ResourceHostMsg_Request request = CreateResourceRequest(
1078 "GET", ResourceType::SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); 1172 "GET", ResourceType::SUB_RESOURCE, net::URLRequestTestJob::test_url_1());
1079 1173
1080 MakeTestRequest(test_filter.get(), 0, 1, 1174 MakeTestRequestWithResourceType(test_filter.get(), 0, 1,
1081 net::URLRequestTestJob::test_url_1()); 1175 net::URLRequestTestJob::test_url_1(),
1176 ResourceType::SUB_RESOURCE);
1082 1177
1083 // request 2 goes to us 1178 // request 2 goes to us
1084 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2()); 1179 MakeTestRequest(0, 2, net::URLRequestTestJob::test_url_2());
1085 1180
1086 // request 3 goes to the test delegate 1181 // request 3 goes to the test delegate
1087 MakeTestRequest(test_filter.get(), 0, 3, 1182 MakeTestRequestWithResourceType(test_filter.get(), 0, 3,
1088 net::URLRequestTestJob::test_url_3()); 1183 net::URLRequestTestJob::test_url_3(),
1184 ResourceType::SUB_RESOURCE);
1089 1185
1090 // Make sure all requests have finished stage one. test_url_1 will have 1186 // Make sure all requests have finished stage one. test_url_1 will have
1091 // finished. 1187 // finished.
1092 base::MessageLoop::current()->RunUntilIdle(); 1188 base::MessageLoop::current()->RunUntilIdle();
1093 1189
1094 // TODO(mbelshe): 1190 // TODO(mbelshe):
1095 // Now that the async IO path is in place, the IO always completes on the 1191 // 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 1192 // initial call; so the requests have already completed. This basically
1097 // breaks the whole test. 1193 // breaks the whole test.
1098 //EXPECT_EQ(3, host_.pending_requests()); 1194 //EXPECT_EQ(3, host_.pending_requests());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 } 1307 }
1212 1308
1213 // Tests that blocked requests are canceled if their associated process dies. 1309 // Tests that blocked requests are canceled if their associated process dies.
1214 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { 1310 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) {
1215 // This second filter is used to emulate a second process. 1311 // This second filter is used to emulate a second process.
1216 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( 1312 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
1217 this, browser_context_->GetResourceContext()); 1313 this, browser_context_->GetResourceContext());
1218 1314
1219 host_.BlockRequestsForRoute(second_filter->child_id(), 0); 1315 host_.BlockRequestsForRoute(second_filter->child_id(), 0);
1220 1316
1221 MakeTestRequest(filter_.get(), 0, 1, net::URLRequestTestJob::test_url_1()); 1317 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1222 MakeTestRequest(second_filter.get(), 0, 2, 1318 net::URLRequestTestJob::test_url_1(),
1223 net::URLRequestTestJob::test_url_2()); 1319 ResourceType::SUB_RESOURCE);
1224 MakeTestRequest(filter_.get(), 0, 3, net::URLRequestTestJob::test_url_3()); 1320 MakeTestRequestWithResourceType(second_filter.get(), 0, 2,
1225 MakeTestRequest(second_filter.get(), 0, 4, 1321 net::URLRequestTestJob::test_url_2(),
1226 net::URLRequestTestJob::test_url_1()); 1322 ResourceType::SUB_RESOURCE);
1323 MakeTestRequestWithResourceType(filter_.get(), 0, 3,
1324 net::URLRequestTestJob::test_url_3(),
1325 ResourceType::SUB_RESOURCE);
1326 MakeTestRequestWithResourceType(second_filter.get(), 0, 4,
1327 net::URLRequestTestJob::test_url_1(),
1328 ResourceType::SUB_RESOURCE);
1227 1329
1228 // Simulate process death. 1330 // Simulate process death.
1229 host_.CancelRequestsForProcess(second_filter->child_id()); 1331 host_.CancelRequestsForProcess(second_filter->child_id());
1230 1332
1231 // Flush all the pending requests. 1333 // Flush all the pending requests.
1232 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1334 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1233 1335
1234 // Sort out all the messages we saw by request. 1336 // Sort out all the messages we saw by request.
1235 ResourceIPCAccumulator::ClassifiedMessages msgs; 1337 ResourceIPCAccumulator::ClassifiedMessages msgs;
1236 accum_.GetClassifiedMessages(&msgs); 1338 accum_.GetClassifiedMessages(&msgs);
(...skipping 13 matching lines...) Expand all
1250 // destructor to make sure the blocked requests are deleted. 1352 // destructor to make sure the blocked requests are deleted.
1251 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { 1353 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) {
1252 // This second filter is used to emulate a second process. 1354 // This second filter is used to emulate a second process.
1253 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( 1355 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
1254 this, browser_context_->GetResourceContext()); 1356 this, browser_context_->GetResourceContext());
1255 1357
1256 host_.BlockRequestsForRoute(filter_->child_id(), 1); 1358 host_.BlockRequestsForRoute(filter_->child_id(), 1);
1257 host_.BlockRequestsForRoute(filter_->child_id(), 2); 1359 host_.BlockRequestsForRoute(filter_->child_id(), 2);
1258 host_.BlockRequestsForRoute(second_filter->child_id(), 1); 1360 host_.BlockRequestsForRoute(second_filter->child_id(), 1);
1259 1361
1260 MakeTestRequest(filter_.get(), 0, 1, net::URLRequestTestJob::test_url_1()); 1362 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1261 MakeTestRequest(filter_.get(), 1, 2, net::URLRequestTestJob::test_url_2()); 1363 net::URLRequestTestJob::test_url_1(),
1262 MakeTestRequest(filter_.get(), 0, 3, net::URLRequestTestJob::test_url_3()); 1364 ResourceType::SUB_RESOURCE);
1263 MakeTestRequest(second_filter.get(), 1, 4, 1365 MakeTestRequestWithResourceType(filter_.get(), 1, 2,
1264 net::URLRequestTestJob::test_url_1()); 1366 net::URLRequestTestJob::test_url_2(),
1265 MakeTestRequest(filter_.get(), 2, 5, net::URLRequestTestJob::test_url_2()); 1367 ResourceType::SUB_RESOURCE);
1266 MakeTestRequest(filter_.get(), 2, 6, net::URLRequestTestJob::test_url_3()); 1368 MakeTestRequestWithResourceType(filter_.get(), 0, 3,
1369 net::URLRequestTestJob::test_url_3(),
1370 ResourceType::SUB_RESOURCE);
1371 MakeTestRequestWithResourceType(second_filter.get(), 1, 4,
1372 net::URLRequestTestJob::test_url_1(),
1373 ResourceType::SUB_RESOURCE);
1374 MakeTestRequestWithResourceType(filter_.get(), 2, 5,
1375 net::URLRequestTestJob::test_url_2(),
1376 ResourceType::SUB_RESOURCE);
1377 MakeTestRequestWithResourceType(filter_.get(), 2, 6,
1378 net::URLRequestTestJob::test_url_3(),
1379 ResourceType::SUB_RESOURCE);
1267 1380
1268 host_.CancelRequestsForProcess(filter_->child_id()); 1381 host_.CancelRequestsForProcess(filter_->child_id());
1269 host_.CancelRequestsForProcess(second_filter->child_id()); 1382 host_.CancelRequestsForProcess(second_filter->child_id());
1270 1383
1271 // Flush all the pending requests. 1384 // Flush all the pending requests.
1272 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1385 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1273 } 1386 }
1274 1387
1275 // Test the private helper method "CalculateApproximateMemoryCost()". 1388 // Test the private helper method "CalculateApproximateMemoryCost()".
1276 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { 1389 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 // Determine how many instance of test_url_2() we can request before 1428 // Determine how many instance of test_url_2() we can request before
1316 // throttling kicks in. 1429 // throttling kicks in.
1317 size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req; 1430 size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req;
1318 1431
1319 // This second filter is used to emulate a second process. 1432 // This second filter is used to emulate a second process.
1320 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( 1433 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
1321 this, browser_context_->GetResourceContext()); 1434 this, browser_context_->GetResourceContext());
1322 1435
1323 // Saturate the number of outstanding requests for our process. 1436 // Saturate the number of outstanding requests for our process.
1324 for (size_t i = 0; i < kMaxRequests; ++i) { 1437 for (size_t i = 0; i < kMaxRequests; ++i) {
1325 MakeTestRequest(filter_.get(), 0, i + 1, 1438 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1,
1326 net::URLRequestTestJob::test_url_2()); 1439 net::URLRequestTestJob::test_url_2(),
1440 ResourceType::SUB_RESOURCE);
1327 } 1441 }
1328 1442
1329 // Issue two more requests for our process -- these should fail immediately. 1443 // Issue two more requests for our process -- these should fail immediately.
1330 MakeTestRequest(filter_.get(), 0, kMaxRequests + 1, 1444 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 1,
1331 net::URLRequestTestJob::test_url_2()); 1445 net::URLRequestTestJob::test_url_2(),
1332 MakeTestRequest(filter_.get(), 0, kMaxRequests + 2, 1446 ResourceType::SUB_RESOURCE);
1333 net::URLRequestTestJob::test_url_2()); 1447 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequests + 2,
1448 net::URLRequestTestJob::test_url_2(),
1449 ResourceType::SUB_RESOURCE);
1334 1450
1335 // Issue two requests for the second process -- these should succeed since 1451 // Issue two requests for the second process -- these should succeed since
1336 // it is just process 0 that is saturated. 1452 // it is just process 0 that is saturated.
1337 MakeTestRequest(second_filter.get(), 0, kMaxRequests + 3, 1453 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 3,
1338 net::URLRequestTestJob::test_url_2()); 1454 net::URLRequestTestJob::test_url_2(),
1339 MakeTestRequest(second_filter.get(), 0, kMaxRequests + 4, 1455 ResourceType::SUB_RESOURCE);
1340 net::URLRequestTestJob::test_url_2()); 1456 MakeTestRequestWithResourceType(second_filter.get(), 0, kMaxRequests + 4,
1457 net::URLRequestTestJob::test_url_2(),
1458 ResourceType::SUB_RESOURCE);
1341 1459
1342 // Flush all the pending requests. 1460 // Flush all the pending requests.
1343 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1461 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1344 base::MessageLoop::current()->RunUntilIdle(); 1462 base::MessageLoop::current()->RunUntilIdle();
1345 1463
1346 // Sorts out all the messages we saw by request. 1464 // Sorts out all the messages we saw by request.
1347 ResourceIPCAccumulator::ClassifiedMessages msgs; 1465 ResourceIPCAccumulator::ClassifiedMessages msgs;
1348 accum_.GetClassifiedMessages(&msgs); 1466 accum_.GetClassifiedMessages(&msgs);
1349 1467
1350 // We issued (kMaxRequests + 4) total requests. 1468 // We issued (kMaxRequests + 4) total requests.
(...skipping 30 matching lines...) Expand all
1381 host_.set_max_num_in_flight_requests(kMaxRequests); 1499 host_.set_max_num_in_flight_requests(kMaxRequests);
1382 1500
1383 // Needed to emulate additional processes. 1501 // Needed to emulate additional processes.
1384 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( 1502 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
1385 this, browser_context_->GetResourceContext()); 1503 this, browser_context_->GetResourceContext());
1386 scoped_refptr<ForwardingFilter> third_filter = new ForwardingFilter( 1504 scoped_refptr<ForwardingFilter> third_filter = new ForwardingFilter(
1387 this, browser_context_->GetResourceContext()); 1505 this, browser_context_->GetResourceContext());
1388 1506
1389 // Saturate the number of outstanding requests for our process. 1507 // Saturate the number of outstanding requests for our process.
1390 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) { 1508 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) {
1391 MakeTestRequest(filter_.get(), 0, i + 1, 1509 MakeTestRequestWithResourceType(filter_.get(), 0, i + 1,
1392 net::URLRequestTestJob::test_url_2()); 1510 net::URLRequestTestJob::test_url_2(),
1511 ResourceType::SUB_RESOURCE);
1393 } 1512 }
1394 1513
1395 // Issue another request for our process -- this should fail immediately. 1514 // Issue another request for our process -- this should fail immediately.
1396 MakeTestRequest(filter_.get(), 0, kMaxRequestsPerProcess + 1, 1515 MakeTestRequestWithResourceType(filter_.get(), 0, kMaxRequestsPerProcess + 1,
1397 net::URLRequestTestJob::test_url_2()); 1516 net::URLRequestTestJob::test_url_2(),
1517 ResourceType::SUB_RESOURCE);
1398 1518
1399 // Issue a request for the second process -- this should succeed, because it 1519 // Issue a request for the second process -- this should succeed, because it
1400 // is just process 0 that is saturated. 1520 // is just process 0 that is saturated.
1401 MakeTestRequest(second_filter.get(), 0, kMaxRequestsPerProcess + 2, 1521 MakeTestRequestWithResourceType(
1402 net::URLRequestTestJob::test_url_2()); 1522 second_filter.get(), 0, kMaxRequestsPerProcess + 2,
1523 net::URLRequestTestJob::test_url_2(), ResourceType::SUB_RESOURCE);
1403 1524
1404 // Issue a request for the third process -- this should fail, because the 1525 // Issue a request for the third process -- this should fail, because the
1405 // global limit has been reached. 1526 // global limit has been reached.
1406 MakeTestRequest(third_filter.get(), 0, kMaxRequestsPerProcess + 3, 1527 MakeTestRequestWithResourceType(
1407 net::URLRequestTestJob::test_url_2()); 1528 third_filter.get(), 0, kMaxRequestsPerProcess + 3,
1529 net::URLRequestTestJob::test_url_2(), ResourceType::SUB_RESOURCE);
1408 1530
1409 // Flush all the pending requests. 1531 // Flush all the pending requests.
1410 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1532 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1411 base::MessageLoop::current()->RunUntilIdle(); 1533 base::MessageLoop::current()->RunUntilIdle();
1412 1534
1413 // Sorts out all the messages we saw by request. 1535 // Sorts out all the messages we saw by request.
1414 ResourceIPCAccumulator::ClassifiedMessages msgs; 1536 ResourceIPCAccumulator::ClassifiedMessages msgs;
1415 accum_.GetClassifiedMessages(&msgs); 1537 accum_.GetClassifiedMessages(&msgs);
1416 1538
1417 // The processes issued the following requests: 1539 // The processes issued the following requests:
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 } 1659 }
1538 1660
1539 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). 1661 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream).
1540 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { 1662 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) {
1541 std::string raw_headers("HTTP/1.1 403 Forbidden\n" 1663 std::string raw_headers("HTTP/1.1 403 Forbidden\n"
1542 "Content-disposition: attachment; filename=blah\n" 1664 "Content-disposition: attachment; filename=blah\n"
1543 "Content-type: application/octet-stream\n\n"); 1665 "Content-type: application/octet-stream\n\n");
1544 std::string response_data("<html><title>Test One</title></html>"); 1666 std::string response_data("<html><title>Test One</title></html>");
1545 SetResponse(raw_headers, response_data); 1667 SetResponse(raw_headers, response_data);
1546 1668
1669 HandleScheme("http");
1670
1547 // Only MAIN_FRAMEs can trigger a download. 1671 // Only MAIN_FRAMEs can trigger a download.
1548 SetResourceType(ResourceType::MAIN_FRAME); 1672 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"),
1549 1673 ResourceType::MAIN_FRAME);
1550 HandleScheme("http");
1551 MakeTestRequest(0, 1, GURL("http:bla"));
1552 1674
1553 // Flush all pending requests. 1675 // Flush all pending requests.
1554 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 1676 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
1555 1677
1556 // Sorts out all the messages we saw by request. 1678 // Sorts out all the messages we saw by request.
1557 ResourceIPCAccumulator::ClassifiedMessages msgs; 1679 ResourceIPCAccumulator::ClassifiedMessages msgs;
1558 accum_.GetClassifiedMessages(&msgs); 1680 accum_.GetClassifiedMessages(&msgs);
1559 1681
1560 // We should have gotten one RequestComplete message. 1682 // We should have gotten one RequestComplete message.
1561 ASSERT_EQ(1U, msgs[0].size()); 1683 ASSERT_EQ(1U, msgs[0].size());
(...skipping 26 matching lines...) Expand all
1588 std::string response_data("01234567890123456789\x01foobar"); 1710 std::string response_data("01234567890123456789\x01foobar");
1589 1711
1590 // Get past sniffing metrics in the BufferedResourceHandler. Note that 1712 // Get past sniffing metrics in the BufferedResourceHandler. Note that
1591 // if we don't get past the sniffing metrics, the result will be that 1713 // 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, 1714 // the BufferedResourceHandler won't have figured out that it's a download,
1593 // won't have constructed a DownloadResourceHandler, and and the request 1715 // won't have constructed a DownloadResourceHandler, and and the request
1594 // will be successfully canceled below, failing the test. 1716 // will be successfully canceled below, failing the test.
1595 response_data.resize(1025, ' '); 1717 response_data.resize(1025, ' ');
1596 1718
1597 SetResponse(raw_headers, response_data); 1719 SetResponse(raw_headers, response_data);
1598 SetResourceType(ResourceType::MAIN_FRAME);
1599 SetDelayedCompleteJobGeneration(true); 1720 SetDelayedCompleteJobGeneration(true);
1600 HandleScheme("http"); 1721 HandleScheme("http");
1601 1722
1602 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1723 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
1724 GURL("http://example.com/blah"),
1725 ResourceType::MAIN_FRAME);
1603 // Return some data so that the request is identified as a download 1726 // Return some data so that the request is identified as a download
1604 // and the proper resource handlers are created. 1727 // and the proper resource handlers are created.
1605 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1728 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1606 1729
1607 // And now simulate a cancellation coming from the renderer. 1730 // And now simulate a cancellation coming from the renderer.
1608 ResourceHostMsg_CancelRequest msg(request_id); 1731 ResourceHostMsg_CancelRequest msg(request_id);
1609 bool msg_was_ok; 1732 bool msg_was_ok;
1610 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1733 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1611 1734
1612 // Since the request had already started processing as a download, 1735 // Since the request had already started processing as a download,
(...skipping 10 matching lines...) Expand all
1623 int render_view_id = 0; 1746 int render_view_id = 0;
1624 int request_id = 1; 1747 int request_id = 1;
1625 1748
1626 std::string raw_headers("HTTP\n" 1749 std::string raw_headers("HTTP\n"
1627 "Content-disposition: attachment; filename=foo\n\n"); 1750 "Content-disposition: attachment; filename=foo\n\n");
1628 std::string response_data("01234567890123456789\x01foobar"); 1751 std::string response_data("01234567890123456789\x01foobar");
1629 // Get past sniffing metrics. 1752 // Get past sniffing metrics.
1630 response_data.resize(1025, ' '); 1753 response_data.resize(1025, ' ');
1631 1754
1632 SetResponse(raw_headers, response_data); 1755 SetResponse(raw_headers, response_data);
1633 SetResourceType(ResourceType::MAIN_FRAME);
1634 SetDelayedCompleteJobGeneration(true); 1756 SetDelayedCompleteJobGeneration(true);
1635 HandleScheme("http"); 1757 HandleScheme("http");
1636 1758
1637 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1759 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
1760 GURL("http://example.com/blah"),
1761 ResourceType::MAIN_FRAME);
1638 // Return some data so that the request is identified as a download 1762 // Return some data so that the request is identified as a download
1639 // and the proper resource handlers are created. 1763 // and the proper resource handlers are created.
1640 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 1764 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
1641 1765
1642 // And now simulate a cancellation coming from the renderer. 1766 // And now simulate a cancellation coming from the renderer.
1643 ResourceHostMsg_CancelRequest msg(request_id); 1767 ResourceHostMsg_CancelRequest msg(request_id);
1644 bool msg_was_ok; 1768 bool msg_was_ok;
1645 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1769 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1646 1770
1647 // Since the request had already started processing as a download, 1771 // Since the request had already started processing as a download,
(...skipping 16 matching lines...) Expand all
1664 EXPECT_EQ(0, host_.pending_requests()); 1788 EXPECT_EQ(0, host_.pending_requests());
1665 1789
1666 int render_view_id = 0; 1790 int render_view_id = 0;
1667 int request_id = 1; 1791 int request_id = 1;
1668 1792
1669 std::string raw_headers("HTTP/1.1 200 OK\n" 1793 std::string raw_headers("HTTP/1.1 200 OK\n"
1670 "Content-Type: text/html; charset=utf-8\n\n"); 1794 "Content-Type: text/html; charset=utf-8\n\n");
1671 std::string response_data("<html>foobar</html>"); 1795 std::string response_data("<html>foobar</html>");
1672 1796
1673 SetResponse(raw_headers, response_data); 1797 SetResponse(raw_headers, response_data);
1674 SetResourceType(ResourceType::MAIN_FRAME);
1675 HandleScheme("http"); 1798 HandleScheme("http");
1676 1799
1677 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1800 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
1801 GURL("http://example.com/blah"),
1802 ResourceType::MAIN_FRAME);
1803
1678 1804
1679 GlobalRequestID global_request_id(filter_->child_id(), request_id); 1805 GlobalRequestID global_request_id(filter_->child_id(), request_id);
1680 host_.MarkAsTransferredNavigation(global_request_id, 1806 host_.MarkAsTransferredNavigation(global_request_id,
1681 GURL("http://example.com/blah")); 1807 GURL("http://example.com/blah"));
1682 1808
1683 // And now simulate a cancellation coming from the renderer. 1809 // And now simulate a cancellation coming from the renderer.
1684 ResourceHostMsg_CancelRequest msg(request_id); 1810 ResourceHostMsg_CancelRequest msg(request_id);
1685 bool msg_was_ok; 1811 bool msg_was_ok;
1686 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); 1812 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
1687 1813
(...skipping 16 matching lines...) Expand all
1704 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) { 1830 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) {
1705 EXPECT_EQ(0, host_.pending_requests()); 1831 EXPECT_EQ(0, host_.pending_requests());
1706 1832
1707 int render_view_id = 0; 1833 int render_view_id = 0;
1708 int request_id = 1; 1834 int request_id = 1;
1709 1835
1710 // Configure initial request. 1836 // Configure initial request.
1711 SetResponse("HTTP/1.1 302 Found\n" 1837 SetResponse("HTTP/1.1 302 Found\n"
1712 "Location: http://other.com/blech\n\n"); 1838 "Location: http://other.com/blech\n\n");
1713 1839
1714 SetResourceType(ResourceType::MAIN_FRAME);
1715 HandleScheme("http"); 1840 HandleScheme("http");
1716 1841
1717 // Temporarily replace ContentBrowserClient with one that will trigger the 1842 // Temporarily replace ContentBrowserClient with one that will trigger the
1718 // transfer navigation code paths. 1843 // transfer navigation code paths.
1719 TransfersAllNavigationsContentBrowserClient new_client; 1844 TransfersAllNavigationsContentBrowserClient new_client;
1720 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); 1845 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
1721 1846
1722 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1847 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
1848 GURL("http://example.com/blah"), ResourceType::MAIN_FRAME);
1723 1849
1724 // Now that we're blocked on the redirect, update the response and unblock by 1850 // Now that we're blocked on the redirect, update the response and unblock by
1725 // telling the AsyncResourceHandler to follow the redirect. 1851 // telling the AsyncResourceHandler to follow the redirect.
1726 const std::string kResponseBody = "hello world"; 1852 const std::string kResponseBody = "hello world";
1727 SetResponse("HTTP/1.1 200 OK\n" 1853 SetResponse("HTTP/1.1 200 OK\n"
1728 "Content-Type: text/html\n\n", 1854 "Content-Type: text/html\n\n",
1729 kResponseBody); 1855 kResponseBody);
1730 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); 1856 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL());
1731 bool msg_was_ok; 1857 bool msg_was_ok;
1732 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); 1858 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { 1901 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) {
1776 EXPECT_EQ(0, host_.pending_requests()); 1902 EXPECT_EQ(0, host_.pending_requests());
1777 1903
1778 int render_view_id = 0; 1904 int render_view_id = 0;
1779 int request_id = 1; 1905 int request_id = 1;
1780 1906
1781 // Configure initial request. 1907 // Configure initial request.
1782 SetResponse("HTTP/1.1 302 Found\n" 1908 SetResponse("HTTP/1.1 302 Found\n"
1783 "Location: http://other.com/blech\n\n"); 1909 "Location: http://other.com/blech\n\n");
1784 1910
1785 SetResourceType(ResourceType::MAIN_FRAME);
1786 HandleScheme("http"); 1911 HandleScheme("http");
1787 1912
1788 // Temporarily replace ContentBrowserClient with one that will trigger the 1913 // Temporarily replace ContentBrowserClient with one that will trigger the
1789 // transfer navigation code paths. 1914 // transfer navigation code paths.
1790 TransfersAllNavigationsContentBrowserClient new_client; 1915 TransfersAllNavigationsContentBrowserClient new_client;
1791 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); 1916 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
1792 1917
1793 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 1918 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
1919 GURL("http://example.com/blah"),
1920 ResourceType::MAIN_FRAME);
1794 1921
1795 // Now that we're blocked on the redirect, update the response and unblock by 1922 // 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 1923 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain
1797 // MIME type, which causes BufferedResourceHandler to buffer it before the 1924 // MIME type, which causes BufferedResourceHandler to buffer it before the
1798 // transfer occurs. 1925 // transfer occurs.
1799 const std::string kResponseBody = "hello world"; 1926 const std::string kResponseBody = "hello world";
1800 SetResponse("HTTP/1.1 200 OK\n" 1927 SetResponse("HTTP/1.1 200 OK\n"
1801 "Content-Type: text/plain\n\n", 1928 "Content-Type: text/plain\n\n",
1802 kResponseBody); 1929 kResponseBody);
1803 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); 1930 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 1974
1848 int render_view_id = 0; 1975 int render_view_id = 0;
1849 int request_id = 1; 1976 int request_id = 1;
1850 int first_child_id = -1; 1977 int first_child_id = -1;
1851 1978
1852 // Configure initial request. 1979 // Configure initial request.
1853 SetResponse("HTTP/1.1 302 Found\n" 1980 SetResponse("HTTP/1.1 302 Found\n"
1854 "Location: http://other.com/blech\n\n"); 1981 "Location: http://other.com/blech\n\n");
1855 const std::string kResponseBody = "hello world"; 1982 const std::string kResponseBody = "hello world";
1856 1983
1857 SetResourceType(ResourceType::MAIN_FRAME);
1858 HandleScheme("http"); 1984 HandleScheme("http");
1859 1985
1860 // Temporarily replace ContentBrowserClient with one that will trigger the 1986 // Temporarily replace ContentBrowserClient with one that will trigger the
1861 // transfer navigation code paths. 1987 // transfer navigation code paths.
1862 TransfersAllNavigationsContentBrowserClient new_client; 1988 TransfersAllNavigationsContentBrowserClient new_client;
1863 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); 1989 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
1864 1990
1865 // Create a first filter that can be deleted before the second one starts. 1991 // Create a first filter that can be deleted before the second one starts.
1866 { 1992 {
1867 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter( 1993 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { 2062 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) {
1937 EXPECT_EQ(0, host_.pending_requests()); 2063 EXPECT_EQ(0, host_.pending_requests());
1938 2064
1939 int render_view_id = 0; 2065 int render_view_id = 0;
1940 int request_id = 1; 2066 int request_id = 1;
1941 2067
1942 // Configure initial request. 2068 // Configure initial request.
1943 SetResponse("HTTP/1.1 302 Found\n" 2069 SetResponse("HTTP/1.1 302 Found\n"
1944 "Location: http://other.com/blech\n\n"); 2070 "Location: http://other.com/blech\n\n");
1945 2071
1946 SetResourceType(ResourceType::MAIN_FRAME);
1947 HandleScheme("http"); 2072 HandleScheme("http");
1948 2073
1949 // Temporarily replace ContentBrowserClient with one that will trigger the 2074 // Temporarily replace ContentBrowserClient with one that will trigger the
1950 // transfer navigation code paths. 2075 // transfer navigation code paths.
1951 TransfersAllNavigationsContentBrowserClient new_client; 2076 TransfersAllNavigationsContentBrowserClient new_client;
1952 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); 2077 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
1953 2078
1954 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); 2079 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2080 GURL("http://example.com/blah"),
2081 ResourceType::MAIN_FRAME);
1955 2082
1956 // Now that we're blocked on the redirect, simulate hitting another redirect. 2083 // Now that we're blocked on the redirect, simulate hitting another redirect.
1957 SetResponse("HTTP/1.1 302 Found\n" 2084 SetResponse("HTTP/1.1 302 Found\n"
1958 "Location: http://other.com/blerg\n\n"); 2085 "Location: http://other.com/blerg\n\n");
1959 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); 2086 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL());
1960 bool msg_was_ok; 2087 bool msg_was_ok;
1961 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); 2088 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok);
1962 base::MessageLoop::current()->RunUntilIdle(); 2089 base::MessageLoop::current()->RunUntilIdle();
1963 2090
1964 // Now that we're blocked on the second redirect, update the response and 2091 // 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
2017 accum_.GetClassifiedMessages(&msgs); 2144 accum_.GetClassifiedMessages(&msgs);
2018 2145
2019 ASSERT_EQ(2U, msgs.size()); 2146 ASSERT_EQ(2U, msgs.size());
2020 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2147 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2021 CheckSuccessfulRequest(msgs[1], kResponseBody); 2148 CheckSuccessfulRequest(msgs[1], kResponseBody);
2022 } 2149 }
2023 2150
2024 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { 2151 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) {
2025 EXPECT_EQ(0, host_.pending_requests()); 2152 EXPECT_EQ(0, host_.pending_requests());
2026 2153
2027 SetResourceType(ResourceType::MAIN_FRAME);
2028 HandleScheme("http"); 2154 HandleScheme("http");
2029 2155
2030 MakeTestRequest(0, 1, GURL("foo://bar")); 2156 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"),
2157 ResourceType::MAIN_FRAME);
2031 2158
2032 // Flush all pending requests. 2159 // Flush all pending requests.
2033 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2160 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2034 2161
2035 // Sort all the messages we saw by request. 2162 // Sort all the messages we saw by request.
2036 ResourceIPCAccumulator::ClassifiedMessages msgs; 2163 ResourceIPCAccumulator::ClassifiedMessages msgs;
2037 accum_.GetClassifiedMessages(&msgs); 2164 accum_.GetClassifiedMessages(&msgs);
2038 2165
2039 // We should have gotten one RequestComplete message. 2166 // We should have gotten one RequestComplete message.
2040 ASSERT_EQ(1U, msgs[0].size()); 2167 ASSERT_EQ(1U, msgs[0].size());
(...skipping 26 matching lines...) Expand all
2067 2194
2068 size_t size = msgs[0].size(); 2195 size_t size = msgs[0].size();
2069 2196
2070 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); 2197 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
2071 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); 2198 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type());
2072 for (size_t i = 2; i < size - 1; ++i) 2199 for (size_t i = 2; i < size - 1; ++i)
2073 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); 2200 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
2074 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type()); 2201 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type());
2075 } 2202 }
2076 2203
2204 // Request a very large detachable resource. This verifies that the data is not
2205 // sent to the render process.
2206 TEST_F(ResourceDispatcherHostTest, DetachableNoDataSentOrReceived) {
2207 EXPECT_EQ(0, host_.pending_requests());
2208
2209 SendDataReceivedACKs(true);
2210
2211 HandleScheme("big-job");
2212
2213 // This request would normally result in many messages (>300).
2214 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
2215 GURL("big-job:0123456789,1000000"),
2216 ResourceType::PREFETCH);
2217
2218 // Sort all the messages we saw by request.
2219 ResourceIPCAccumulator::ClassifiedMessages msgs;
2220 accum_.GetClassifiedMessages(&msgs);
2221
2222 EXPECT_EQ(2u, msgs[0].size());
2223 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
2224 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][1].type());
2225 }
2226
2077 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { 2227 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) {
2078 EXPECT_EQ(0, host_.pending_requests()); 2228 EXPECT_EQ(0, host_.pending_requests());
2079 2229
2080 HandleScheme("big-job"); 2230 HandleScheme("big-job");
2081 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); 2231 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
2082 2232
2083 // Sort all the messages we saw by request. 2233 // Sort all the messages we saw by request.
2084 ResourceIPCAccumulator::ClassifiedMessages msgs; 2234 ResourceIPCAccumulator::ClassifiedMessages msgs;
2085 accum_.GetClassifiedMessages(&msgs); 2235 accum_.GetClassifiedMessages(&msgs);
2086 2236
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 } 2318 }
2169 2319
2170 base::MessageLoop::current()->RunUntilIdle(); 2320 base::MessageLoop::current()->RunUntilIdle();
2171 2321
2172 msgs.clear(); 2322 msgs.clear();
2173 accum_.GetClassifiedMessages(&msgs); 2323 accum_.GetClassifiedMessages(&msgs);
2174 } 2324 }
2175 } 2325 }
2176 2326
2177 } // namespace content 2327 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698