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/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 // If the filter has disappeared then detachable resources should continue to | 1162 // If the filter has disappeared then detachable resources should continue to |
1163 // load. | 1163 // load. |
1164 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetached) { | 1164 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetached) { |
1165 // test_url_1's data is available synchronously, so use 2 and 3. | 1165 // test_url_1's data is available synchronously, so use 2 and 3. |
1166 ResourceHostMsg_Request request_prefetch = CreateResourceRequest( | 1166 ResourceHostMsg_Request request_prefetch = CreateResourceRequest( |
1167 "GET", RESOURCE_TYPE_PREFETCH, net::URLRequestTestJob::test_url_2()); | 1167 "GET", RESOURCE_TYPE_PREFETCH, net::URLRequestTestJob::test_url_2()); |
1168 ResourceHostMsg_Request request_ping = CreateResourceRequest( | 1168 ResourceHostMsg_Request request_ping = CreateResourceRequest( |
1169 "GET", RESOURCE_TYPE_PING, net::URLRequestTestJob::test_url_3()); | 1169 "GET", RESOURCE_TYPE_PING, net::URLRequestTestJob::test_url_3()); |
1170 | 1170 |
1171 ResourceHostMsg_RequestResource msg_prefetch(0, 1, request_prefetch); | 1171 ResourceHostMsg_RequestResource msg_prefetch(0, 1, request_prefetch); |
1172 host_.OnMessageReceived(msg_prefetch, filter_); | 1172 host_.OnMessageReceived(msg_prefetch, filter_.get()); |
1173 ResourceHostMsg_RequestResource msg_ping(0, 2, request_ping); | 1173 ResourceHostMsg_RequestResource msg_ping(0, 2, request_ping); |
1174 host_.OnMessageReceived(msg_ping, filter_); | 1174 host_.OnMessageReceived(msg_ping, filter_.get()); |
1175 | 1175 |
1176 // Remove the filter before processing the requests by simulating channel | 1176 // Remove the filter before processing the requests by simulating channel |
1177 // closure. | 1177 // closure. |
1178 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest( | 1178 ResourceRequestInfoImpl* info_prefetch = ResourceRequestInfoImpl::ForRequest( |
1179 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1))); | 1179 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 1))); |
1180 ResourceRequestInfoImpl* info_ping = ResourceRequestInfoImpl::ForRequest( | 1180 ResourceRequestInfoImpl* info_ping = ResourceRequestInfoImpl::ForRequest( |
1181 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 2))); | 1181 host_.GetURLRequest(GlobalRequestID(filter_->child_id(), 2))); |
1182 DCHECK_EQ(filter_.get(), info_prefetch->filter()); | 1182 DCHECK_EQ(filter_.get(), info_prefetch->filter()); |
1183 DCHECK_EQ(filter_.get(), info_ping->filter()); | 1183 DCHECK_EQ(filter_.get(), info_ping->filter()); |
1184 filter_->OnChannelClosing(); | 1184 filter_->OnChannelClosing(); |
(...skipping 27 matching lines...) Expand all Loading... |
1212 } | 1212 } |
1213 | 1213 |
1214 // If the filter has disappeared (original process dies) then detachable | 1214 // If the filter has disappeared (original process dies) then detachable |
1215 // resources should continue to load, even when redirected. | 1215 // resources should continue to load, even when redirected. |
1216 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) { | 1216 TEST_F(ResourceDispatcherHostTest, DeletedFilterDetachedRedirect) { |
1217 ResourceHostMsg_Request request = CreateResourceRequest( | 1217 ResourceHostMsg_Request request = CreateResourceRequest( |
1218 "GET", RESOURCE_TYPE_PREFETCH, | 1218 "GET", RESOURCE_TYPE_PREFETCH, |
1219 net::URLRequestTestJob::test_url_redirect_to_url_2()); | 1219 net::URLRequestTestJob::test_url_redirect_to_url_2()); |
1220 | 1220 |
1221 ResourceHostMsg_RequestResource msg(0, 1, request); | 1221 ResourceHostMsg_RequestResource msg(0, 1, request); |
1222 host_.OnMessageReceived(msg, filter_); | 1222 host_.OnMessageReceived(msg, filter_.get()); |
1223 | 1223 |
1224 // Remove the filter before processing the request by simulating channel | 1224 // Remove the filter before processing the request by simulating channel |
1225 // closure. | 1225 // closure. |
1226 GlobalRequestID global_request_id(filter_->child_id(), 1); | 1226 GlobalRequestID global_request_id(filter_->child_id(), 1); |
1227 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 1227 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
1228 host_.GetURLRequest(global_request_id)); | 1228 host_.GetURLRequest(global_request_id)); |
1229 info->filter_->OnChannelClosing(); | 1229 info->filter_->OnChannelClosing(); |
1230 info->filter_.reset(); | 1230 info->filter_.reset(); |
1231 | 1231 |
1232 // From the renderer's perspective, the request was cancelled. | 1232 // From the renderer's perspective, the request was cancelled. |
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2514 new_render_view_id, new_request_id, request); | 2514 new_render_view_id, new_request_id, request); |
2515 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); | 2515 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); |
2516 | 2516 |
2517 // Verify that we update the ResourceRequestInfo. | 2517 // Verify that we update the ResourceRequestInfo. |
2518 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); | 2518 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); |
2519 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 2519 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
2520 host_.GetURLRequest(global_request_id)); | 2520 host_.GetURLRequest(global_request_id)); |
2521 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); | 2521 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); |
2522 EXPECT_EQ(new_render_view_id, info->GetRouteID()); | 2522 EXPECT_EQ(new_render_view_id, info->GetRouteID()); |
2523 EXPECT_EQ(new_request_id, info->GetRequestID()); | 2523 EXPECT_EQ(new_request_id, info->GetRequestID()); |
2524 EXPECT_EQ(second_filter, info->filter()); | 2524 EXPECT_EQ(second_filter.get(), info->filter()); |
2525 | 2525 |
2526 // Let request complete. | 2526 // Let request complete. |
2527 base::MessageLoop::current()->RunUntilIdle(); | 2527 base::MessageLoop::current()->RunUntilIdle(); |
2528 | 2528 |
2529 // Check generated messages. | 2529 // Check generated messages. |
2530 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2530 ResourceIPCAccumulator::ClassifiedMessages msgs; |
2531 accum_.GetClassifiedMessages(&msgs); | 2531 accum_.GetClassifiedMessages(&msgs); |
2532 | 2532 |
2533 ASSERT_EQ(2U, msgs.size()); | 2533 ASSERT_EQ(2U, msgs.size()); |
2534 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2534 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2755 | 2755 |
2756 // Register it for a resource request. | 2756 // Register it for a resource request. |
2757 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); | 2757 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); |
2758 | 2758 |
2759 // Should be readable now. | 2759 // Should be readable now. |
2760 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 2760 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
2761 filter_->child_id(), file_path)); | 2761 filter_->child_id(), file_path)); |
2762 | 2762 |
2763 // The child releases from the request. | 2763 // The child releases from the request. |
2764 ResourceHostMsg_ReleaseDownloadedFile release_msg(kRequestID); | 2764 ResourceHostMsg_ReleaseDownloadedFile release_msg(kRequestID); |
2765 host_.OnMessageReceived(release_msg, filter_); | 2765 host_.OnMessageReceived(release_msg, filter_.get()); |
2766 | 2766 |
2767 // Still readable because there is another reference to the file. (The child | 2767 // Still readable because there is another reference to the file. (The child |
2768 // may take additional blob references.) | 2768 // may take additional blob references.) |
2769 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 2769 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
2770 filter_->child_id(), file_path)); | 2770 filter_->child_id(), file_path)); |
2771 | 2771 |
2772 // Release extra references and wait for the file to be deleted. (This relies | 2772 // Release extra references and wait for the file to be deleted. (This relies |
2773 // on the delete happening on the FILE thread which is mapped to main thread | 2773 // on the delete happening on the FILE thread which is mapped to main thread |
2774 // in this test.) | 2774 // in this test.) |
2775 deletable_file = NULL; | 2775 deletable_file = NULL; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2813 filter_->child_id(), file_path)); | 2813 filter_->child_id(), file_path)); |
2814 EXPECT_FALSE(base::PathExists(file_path)); | 2814 EXPECT_FALSE(base::PathExists(file_path)); |
2815 } | 2815 } |
2816 | 2816 |
2817 TEST_F(ResourceDispatcherHostTest, DownloadToFile) { | 2817 TEST_F(ResourceDispatcherHostTest, DownloadToFile) { |
2818 // Make a request which downloads to file. | 2818 // Make a request which downloads to file. |
2819 ResourceHostMsg_Request request = CreateResourceRequest( | 2819 ResourceHostMsg_Request request = CreateResourceRequest( |
2820 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); | 2820 "GET", RESOURCE_TYPE_SUB_RESOURCE, net::URLRequestTestJob::test_url_1()); |
2821 request.download_to_file = true; | 2821 request.download_to_file = true; |
2822 ResourceHostMsg_RequestResource request_msg(0, 1, request); | 2822 ResourceHostMsg_RequestResource request_msg(0, 1, request); |
2823 host_.OnMessageReceived(request_msg, filter_); | 2823 host_.OnMessageReceived(request_msg, filter_.get()); |
2824 | 2824 |
2825 // Running the message loop until idle does not work because | 2825 // Running the message loop until idle does not work because |
2826 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead, | 2826 // RedirectToFileResourceHandler posts things to base::WorkerPool. Instead, |
2827 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop | 2827 // wait for the ResourceMsg_RequestComplete to go out. Then run the event loop |
2828 // until idle so the loader is gone. | 2828 // until idle so the loader is gone. |
2829 WaitForRequestComplete(); | 2829 WaitForRequestComplete(); |
2830 base::RunLoop().RunUntilIdle(); | 2830 base::RunLoop().RunUntilIdle(); |
2831 EXPECT_EQ(0, host_.pending_requests()); | 2831 EXPECT_EQ(0, host_.pending_requests()); |
2832 | 2832 |
2833 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2833 ResourceIPCAccumulator::ClassifiedMessages msgs; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2868 EXPECT_EQ(net::URLRequestTestJob::test_data_1(), contents); | 2868 EXPECT_EQ(net::URLRequestTestJob::test_data_1(), contents); |
2869 | 2869 |
2870 // The file should be readable by the child. | 2870 // The file should be readable by the child. |
2871 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 2871 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
2872 filter_->child_id(), response_head.download_file_path)); | 2872 filter_->child_id(), response_head.download_file_path)); |
2873 | 2873 |
2874 // When the renderer releases the file, it should be deleted. Again, | 2874 // When the renderer releases the file, it should be deleted. Again, |
2875 // RunUntilIdle doesn't work because base::WorkerPool is involved. | 2875 // RunUntilIdle doesn't work because base::WorkerPool is involved. |
2876 ShareableFileReleaseWaiter waiter(response_head.download_file_path); | 2876 ShareableFileReleaseWaiter waiter(response_head.download_file_path); |
2877 ResourceHostMsg_ReleaseDownloadedFile release_msg(1); | 2877 ResourceHostMsg_ReleaseDownloadedFile release_msg(1); |
2878 host_.OnMessageReceived(release_msg, filter_); | 2878 host_.OnMessageReceived(release_msg, filter_.get()); |
2879 waiter.Wait(); | 2879 waiter.Wait(); |
2880 // The release callback runs before the delete is scheduled, so pump the | 2880 // The release callback runs before the delete is scheduled, so pump the |
2881 // message loop for the delete itself. (This relies on the delete happening on | 2881 // message loop for the delete itself. (This relies on the delete happening on |
2882 // the FILE thread which is mapped to main thread in this test.) | 2882 // the FILE thread which is mapped to main thread in this test.) |
2883 base::RunLoop().RunUntilIdle(); | 2883 base::RunLoop().RunUntilIdle(); |
2884 | 2884 |
2885 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); | 2885 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); |
2886 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 2886 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
2887 filter_->child_id(), response_head.download_file_path)); | 2887 filter_->child_id(), response_head.download_file_path)); |
2888 } | 2888 } |
(...skipping 30 matching lines...) Expand all Loading... |
2919 } else { | 2919 } else { |
2920 return new net::URLRequestTestJob( | 2920 return new net::URLRequestTestJob( |
2921 request, network_delegate, | 2921 request, network_delegate, |
2922 test_fixture_->response_headers_, test_fixture_->response_data_, | 2922 test_fixture_->response_headers_, test_fixture_->response_data_, |
2923 false); | 2923 false); |
2924 } | 2924 } |
2925 } | 2925 } |
2926 } | 2926 } |
2927 | 2927 |
2928 } // namespace content | 2928 } // namespace content |
OLD | NEW |