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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 // This is used to create a filter matching a specified child id. | 235 // This is used to create a filter matching a specified child id. |
236 class TestFilterSpecifyingChild : public ResourceMessageFilter { | 236 class TestFilterSpecifyingChild : public ResourceMessageFilter { |
237 public: | 237 public: |
238 explicit TestFilterSpecifyingChild(ResourceContext* resource_context, | 238 explicit TestFilterSpecifyingChild(ResourceContext* resource_context, |
239 int process_id) | 239 int process_id) |
240 : ResourceMessageFilter( | 240 : ResourceMessageFilter( |
241 process_id, | 241 process_id, |
242 PROCESS_TYPE_RENDERER, | |
243 NULL, | 242 NULL, |
244 NULL, | 243 NULL, |
245 NULL, | 244 NULL, |
246 NULL, | 245 NULL, |
247 base::Bind(&TestFilterSpecifyingChild::GetContexts, | 246 base::Bind(&TestFilterSpecifyingChild::GetContexts, |
248 base::Unretained(this))), | 247 base::Unretained(this))), |
249 resource_context_(resource_context), | 248 resource_context_(resource_context), |
250 canceled_(false), | 249 canceled_(false), |
251 received_after_canceled_(0) { | 250 received_after_canceled_(0) { |
252 set_peer_process_for_testing(base::Process::Current()); | 251 set_peer_process_for_testing(base::Process::Current()); |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id, | 976 void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id, |
978 int render_frame_id, | 977 int render_frame_id, |
979 int request_id, | 978 int request_id, |
980 net::RequestPriority priority); | 979 net::RequestPriority priority); |
981 | 980 |
982 void MakeWebContentsAssociatedDownloadRequest(int request_id, | 981 void MakeWebContentsAssociatedDownloadRequest(int request_id, |
983 const GURL& url); | 982 const GURL& url); |
984 | 983 |
985 void CancelRequest(int request_id); | 984 void CancelRequest(int request_id); |
986 void RendererCancelRequest(int request_id) { | 985 void RendererCancelRequest(int request_id) { |
987 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); | 986 ASSERT_FALSE(host_.requester_info_); |
| 987 host_.requester_info_ = |
| 988 ResourceRequesterInfo::CreateForRenderer(filter_->GetWeakPtr()); |
988 host_.OnCancelRequest(request_id); | 989 host_.OnCancelRequest(request_id); |
989 SetFilter(old_filter); | 990 host_.requester_info_.reset(); |
990 } | 991 } |
991 | 992 |
992 void CompleteStartRequest(int request_id); | 993 void CompleteStartRequest(int request_id); |
993 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); | 994 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); |
994 | 995 |
995 net::TestNetworkDelegate* network_delegate() { return &network_delegate_; } | 996 net::TestNetworkDelegate* network_delegate() { return &network_delegate_; } |
996 | 997 |
997 void EnsureSchemeIsAllowed(const std::string& scheme) { | 998 void EnsureSchemeIsAllowed(const std::string& scheme) { |
998 ChildProcessSecurityPolicyImpl* policy = | 999 ChildProcessSecurityPolicyImpl* policy = |
999 ChildProcessSecurityPolicyImpl::GetInstance(); | 1000 ChildProcessSecurityPolicyImpl::GetInstance(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 bool result = base::PickleIterator(msg).ReadInt(&request_id); | 1035 bool result = base::PickleIterator(msg).ReadInt(&request_id); |
1035 DCHECK(result); | 1036 DCHECK(result); |
1036 std::unique_ptr<IPC::Message> ack( | 1037 std::unique_ptr<IPC::Message> ack( |
1037 new ResourceHostMsg_DataReceived_ACK(request_id)); | 1038 new ResourceHostMsg_DataReceived_ACK(request_id)); |
1038 | 1039 |
1039 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1040 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1040 FROM_HERE, | 1041 FROM_HERE, |
1041 base::Bind(&GenerateIPCMessage, filter_, base::Passed(&ack))); | 1042 base::Bind(&GenerateIPCMessage, filter_, base::Passed(&ack))); |
1042 } | 1043 } |
1043 | 1044 |
1044 // Setting filters for testing renderer messages. | |
1045 // Returns the previous filter. | |
1046 ResourceMessageFilter* SetFilter(ResourceMessageFilter* new_filter) { | |
1047 ResourceMessageFilter* old_filter = host_.filter_; | |
1048 host_.filter_ = new_filter; | |
1049 return old_filter; | |
1050 } | |
1051 | |
1052 void WaitForRequestComplete() { | 1045 void WaitForRequestComplete() { |
1053 DCHECK(!wait_for_request_complete_loop_); | 1046 DCHECK(!wait_for_request_complete_loop_); |
1054 wait_for_request_complete_loop_.reset(new base::RunLoop); | 1047 wait_for_request_complete_loop_.reset(new base::RunLoop); |
1055 wait_for_request_complete_loop_->Run(); | 1048 wait_for_request_complete_loop_->Run(); |
1056 wait_for_request_complete_loop_.reset(); | 1049 wait_for_request_complete_loop_.reset(); |
1057 } | 1050 } |
1058 | 1051 |
1059 void DeleteRenderFrame(const GlobalFrameRoutingId& global_routing_id) { | 1052 void DeleteRenderFrame(const GlobalFrameRoutingId& global_routing_id) { |
1060 host_.OnRenderFrameDeleted(global_routing_id); | 1053 host_.OnRenderFrameDeleted(global_routing_id); |
1061 } | 1054 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 host_.OnMessageReceived(msg_prefetch, filter_.get()); | 1557 host_.OnMessageReceived(msg_prefetch, filter_.get()); |
1565 ResourceHostMsg_RequestResource msg_ping(0, 2, request_ping); | 1558 ResourceHostMsg_RequestResource msg_ping(0, 2, request_ping); |
1566 host_.OnMessageReceived(msg_ping, filter_.get()); | 1559 host_.OnMessageReceived(msg_ping, filter_.get()); |
1567 | 1560 |
1568 // Remove the filter before processing the requests by simulating channel | 1561 // Remove the filter before processing the requests by simulating channel |
1569 // closure. | 1562 // closure. |
1570 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest( | 1563 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest( |
1571 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1))); | 1564 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1))); |
1572 ResourceRequestInfoImpl* info_ping = ResourceRequestInfoImpl::ForRequest( | 1565 ResourceRequestInfoImpl* info_ping = ResourceRequestInfoImpl::ForRequest( |
1573 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 2))); | 1566 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 2))); |
1574 DCHECK_EQ(filter_.get(), info_prefetch->filter()); | 1567 DCHECK_EQ(filter_.get(), info_prefetch->requester_info().filter()); |
1575 DCHECK_EQ(filter_.get(), info_ping->filter()); | 1568 DCHECK_EQ(filter_.get(), info_ping->requester_info().filter()); |
1576 filter_->OnChannelClosing(); | 1569 filter_->OnChannelClosing(); |
1577 info_prefetch->filter_.reset(); | |
1578 info_ping->filter_.reset(); | |
1579 | 1570 |
1580 // From the renderer's perspective, the requests were cancelled. | 1571 // From the renderer's perspective, the requests were cancelled. |
1581 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1572 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1582 accum_.GetClassifiedMessages(&msgs); | 1573 accum_.GetClassifiedMessages(&msgs); |
1583 ASSERT_EQ(2U, msgs.size()); | 1574 ASSERT_EQ(2U, msgs.size()); |
1584 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); | 1575 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); |
1585 CheckRequestCompleteErrorCode(msgs[1][0], net::ERR_ABORTED); | 1576 CheckRequestCompleteErrorCode(msgs[1][0], net::ERR_ABORTED); |
1586 | 1577 |
1587 // But it continues detached. | 1578 // But it continues detached. |
1588 EXPECT_EQ(2, host_.pending_requests()); | 1579 EXPECT_EQ(2, host_.pending_requests()); |
(...skipping 22 matching lines...) Expand all Loading... |
1611 net::URLRequestTestJob::test_url_redirect_to_url_2()); | 1602 net::URLRequestTestJob::test_url_redirect_to_url_2()); |
1612 | 1603 |
1613 ResourceHostMsg_RequestResource msg(0, 1, request); | 1604 ResourceHostMsg_RequestResource msg(0, 1, request); |
1614 host_.OnMessageReceived(msg, filter_.get()); | 1605 host_.OnMessageReceived(msg, filter_.get()); |
1615 | 1606 |
1616 // Remove the filter before processing the request by simulating channel | 1607 // Remove the filter before processing the request by simulating channel |
1617 // closure. | 1608 // closure. |
1618 GlobalRequestID global_request_id(filter_->child_id(), 1); | 1609 GlobalRequestID global_request_id(filter_->child_id(), 1); |
1619 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 1610 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
1620 host_.GetURLRequest(global_request_id)); | 1611 host_.GetURLRequest(global_request_id)); |
1621 info->filter_->OnChannelClosing(); | 1612 info->requester_info().filter()->OnChannelClosing(); |
1622 info->filter_.reset(); | |
1623 | 1613 |
1624 // From the renderer's perspective, the request was cancelled. | 1614 // From the renderer's perspective, the request was cancelled. |
1625 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1615 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1626 accum_.GetClassifiedMessages(&msgs); | 1616 accum_.GetClassifiedMessages(&msgs); |
1627 ASSERT_EQ(1U, msgs.size()); | 1617 ASSERT_EQ(1U, msgs.size()); |
1628 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); | 1618 CheckRequestCompleteErrorCode(msgs[0][0], net::ERR_ABORTED); |
1629 | 1619 |
1630 // But it continues detached. | 1620 // But it continues detached. |
1631 EXPECT_EQ(1, host_.pending_requests()); | 1621 EXPECT_EQ(1, host_.pending_requests()); |
1632 EXPECT_TRUE(info->detachable_handler()->is_detached()); | 1622 EXPECT_TRUE(info->detachable_handler()->is_detached()); |
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3051 new_render_view_id, new_request_id, request); | 3041 new_render_view_id, new_request_id, request); |
3052 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); | 3042 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); |
3053 | 3043 |
3054 // Verify that we update the ResourceRequestInfo. | 3044 // Verify that we update the ResourceRequestInfo. |
3055 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); | 3045 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); |
3056 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 3046 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
3057 host_.GetURLRequest(global_request_id)); | 3047 host_.GetURLRequest(global_request_id)); |
3058 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); | 3048 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); |
3059 EXPECT_EQ(new_render_view_id, info->GetRouteID()); | 3049 EXPECT_EQ(new_render_view_id, info->GetRouteID()); |
3060 EXPECT_EQ(new_request_id, info->GetRequestID()); | 3050 EXPECT_EQ(new_request_id, info->GetRequestID()); |
3061 EXPECT_EQ(second_filter.get(), info->filter()); | 3051 EXPECT_EQ(second_filter.get(), info->requester_info().filter()); |
3062 | 3052 |
3063 // Let request complete. | 3053 // Let request complete. |
3064 base::RunLoop().RunUntilIdle(); | 3054 base::RunLoop().RunUntilIdle(); |
3065 | 3055 |
3066 // Check generated messages. | 3056 // Check generated messages. |
3067 ResourceIPCAccumulator::ClassifiedMessages msgs; | 3057 ResourceIPCAccumulator::ClassifiedMessages msgs; |
3068 accum_.GetClassifiedMessages(&msgs); | 3058 accum_.GetClassifiedMessages(&msgs); |
3069 | 3059 |
3070 ASSERT_EQ(2U, msgs.size()); | 3060 ASSERT_EQ(2U, msgs.size()); |
3071 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 3061 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3710 } // namespace | 3700 } // namespace |
3711 | 3701 |
3712 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) { | 3702 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoSuccess) { |
3713 ResourceRequest request = CreateResourceRequest( | 3703 ResourceRequest request = CreateResourceRequest( |
3714 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); | 3704 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_1()); |
3715 request.priority = net::MAXIMUM_PRIORITY; | 3705 request.priority = net::MAXIMUM_PRIORITY; |
3716 | 3706 |
3717 bool called = false; | 3707 bool called = false; |
3718 bool was_null = false; | 3708 bool was_null = false; |
3719 SyncLoadResult result; | 3709 SyncLoadResult result; |
3720 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), | 3710 host_.OnSyncLoadWithMojo( |
3721 base::Bind(&StoreSyncLoadResult, | 3711 0, 1, request, |
3722 &called, &was_null, &result)); | 3712 ResourceRequesterInfo::CreateForRenderer(filter_->GetWeakPtr()), |
| 3713 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); |
3723 base::RunLoop().RunUntilIdle(); | 3714 base::RunLoop().RunUntilIdle(); |
3724 EXPECT_TRUE(called); | 3715 EXPECT_TRUE(called); |
3725 EXPECT_FALSE(was_null); | 3716 EXPECT_FALSE(was_null); |
3726 EXPECT_EQ(net::OK, result.error_code); | 3717 EXPECT_EQ(net::OK, result.error_code); |
3727 } | 3718 } |
3728 | 3719 |
3729 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoError) { | 3720 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoError) { |
3730 ResourceRequest request = CreateResourceRequest( | 3721 ResourceRequest request = CreateResourceRequest( |
3731 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); | 3722 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); |
3732 request.priority = net::MAXIMUM_PRIORITY; | 3723 request.priority = net::MAXIMUM_PRIORITY; |
3733 | 3724 |
3734 bool called = false; | 3725 bool called = false; |
3735 bool was_null = false; | 3726 bool was_null = false; |
3736 SyncLoadResult result; | 3727 SyncLoadResult result; |
3737 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), | 3728 host_.OnSyncLoadWithMojo( |
3738 base::Bind(&StoreSyncLoadResult, | 3729 0, 1, request, |
3739 &called, &was_null, &result)); | 3730 ResourceRequesterInfo::CreateForRenderer(filter_->GetWeakPtr()), |
| 3731 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); |
3740 base::RunLoop().RunUntilIdle(); | 3732 base::RunLoop().RunUntilIdle(); |
3741 EXPECT_TRUE(called); | 3733 EXPECT_TRUE(called); |
3742 EXPECT_FALSE(was_null); | 3734 EXPECT_FALSE(was_null); |
3743 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code); | 3735 EXPECT_EQ(net::ERR_INVALID_URL, result.error_code); |
3744 } | 3736 } |
3745 | 3737 |
3746 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) { | 3738 TEST_P(ResourceDispatcherHostTest, SyncLoadWithMojoCancel) { |
3747 ResourceRequest request = CreateResourceRequest( | 3739 ResourceRequest request = CreateResourceRequest( |
3748 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); | 3740 "GET", RESOURCE_TYPE_XHR, net::URLRequestTestJob::test_url_error()); |
3749 request.priority = net::MAXIMUM_PRIORITY; | 3741 request.priority = net::MAXIMUM_PRIORITY; |
3750 | 3742 |
3751 bool called = false; | 3743 bool called = false; |
3752 bool was_null = false; | 3744 bool was_null = false; |
3753 SyncLoadResult result; | 3745 SyncLoadResult result; |
3754 host_.OnSyncLoadWithMojo(0, 1, request, filter_.get(), | 3746 host_.OnSyncLoadWithMojo( |
3755 base::Bind(&StoreSyncLoadResult, | 3747 0, 1, request, |
3756 &called, &was_null, &result)); | 3748 ResourceRequesterInfo::CreateForRenderer(filter_->GetWeakPtr()), |
| 3749 base::Bind(&StoreSyncLoadResult, &called, &was_null, &result)); |
3757 host_.CancelRequestsForProcess(filter_->child_id()); | 3750 host_.CancelRequestsForProcess(filter_->child_id()); |
3758 base::RunLoop().RunUntilIdle(); | 3751 base::RunLoop().RunUntilIdle(); |
3759 EXPECT_TRUE(called); | 3752 EXPECT_TRUE(called); |
3760 EXPECT_TRUE(was_null); | 3753 EXPECT_TRUE(was_null); |
3761 } | 3754 } |
3762 | 3755 |
3763 // A URLRequestTestJob that sets a test certificate on the |ssl_info| | 3756 // A URLRequestTestJob that sets a test certificate on the |ssl_info| |
3764 // field of the response. | 3757 // field of the response. |
3765 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { | 3758 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { |
3766 public: | 3759 public: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3843 return nullptr; | 3836 return nullptr; |
3844 } | 3837 } |
3845 | 3838 |
3846 INSTANTIATE_TEST_CASE_P( | 3839 INSTANTIATE_TEST_CASE_P( |
3847 ResourceDispatcherHostTests, | 3840 ResourceDispatcherHostTests, |
3848 ResourceDispatcherHostTest, | 3841 ResourceDispatcherHostTest, |
3849 testing::Values(TestConfig::kDefault, | 3842 testing::Values(TestConfig::kDefault, |
3850 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3843 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
3851 | 3844 |
3852 } // namespace content | 3845 } // namespace content |
OLD | NEW |