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 10 matching lines...) Expand all Loading... | |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
23 #include "base/test/scoped_feature_list.h" | 23 #include "base/test/scoped_feature_list.h" |
24 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
25 #include "content/browser/browser_thread_impl.h" | 25 #include "content/browser/browser_thread_impl.h" |
26 #include "content/browser/child_process_security_policy_impl.h" | 26 #include "content/browser/child_process_security_policy_impl.h" |
27 #include "content/browser/download/download_manager_impl.h" | 27 #include "content/browser/download/download_manager_impl.h" |
28 #include "content/browser/download/download_resource_handler.h" | 28 #include "content/browser/download/download_resource_handler.h" |
29 #include "content/browser/frame_host/navigation_request_info.h" | 29 #include "content/browser/frame_host/navigation_request_info.h" |
30 #include "content/browser/loader/detachable_resource_handler.h" | 30 #include "content/browser/loader/detachable_resource_handler.h" |
31 #include "content/browser/loader/downloaded_temp_file_impl.h" | |
31 #include "content/browser/loader/navigation_resource_throttle.h" | 32 #include "content/browser/loader/navigation_resource_throttle.h" |
32 #include "content/browser/loader/navigation_url_loader.h" | 33 #include "content/browser/loader/navigation_url_loader.h" |
33 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 34 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
34 #include "content/browser/loader/resource_loader.h" | 35 #include "content/browser/loader/resource_loader.h" |
35 #include "content/browser/loader/resource_message_filter.h" | 36 #include "content/browser/loader/resource_message_filter.h" |
36 #include "content/browser/loader/resource_request_info_impl.h" | 37 #include "content/browser/loader/resource_request_info_impl.h" |
37 #include "content/browser/loader_delegate_impl.h" | 38 #include "content/browser/loader_delegate_impl.h" |
38 #include "content/common/appcache_interfaces.h" | 39 #include "content/common/appcache_interfaces.h" |
39 #include "content/common/child_process_host_impl.h" | 40 #include "content/common/child_process_host_impl.h" |
40 #include "content/common/navigation_params.h" | 41 #include "content/common/navigation_params.h" |
(...skipping 3235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3276 scoped_refptr<ShareableFileReference> deletable_file = | 3277 scoped_refptr<ShareableFileReference> deletable_file = |
3277 ShareableFileReference::GetOrCreate( | 3278 ShareableFileReference::GetOrCreate( |
3278 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 3279 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
3279 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); | 3280 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); |
3280 | 3281 |
3281 // Not readable. | 3282 // Not readable. |
3282 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3283 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
3283 filter_->child_id(), file_path)); | 3284 filter_->child_id(), file_path)); |
3284 | 3285 |
3285 // Register it for a resource request. | 3286 // Register it for a resource request. |
3286 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); | 3287 host_.RegisterDownloadedTempFile(base::MakeUnique<DownloadedTempFileImpl>( |
3288 &host_, filter_->child_id(), kRequestID, file_path)); | |
3287 | 3289 |
3288 // Should be readable now. | 3290 // Should be readable now. |
3289 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3291 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
3290 filter_->child_id(), file_path)); | 3292 filter_->child_id(), file_path)); |
3291 | 3293 |
3292 // The child releases from the request. | 3294 // The child releases from the request. |
3293 ResourceHostMsg_ReleaseDownloadedFile release_msg(kRequestID); | 3295 ResourceHostMsg_ReleaseDownloadedFile release_msg(kRequestID); |
3294 host_.OnMessageReceived(release_msg, filter_.get()); | 3296 host_.OnMessageReceived(release_msg, filter_.get()); |
3295 | 3297 |
3296 // Still readable because there is another reference to the file. (The child | 3298 // Still readable because there is another reference to the file. (The child |
3297 // may take additional blob references.) | 3299 // may take additional blob references.) |
3298 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3300 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
3299 filter_->child_id(), file_path)); | 3301 filter_->child_id(), file_path)); |
3300 | 3302 |
3301 // Release extra references and wait for the file to be deleted. (This relies | 3303 // Release extra references and wait for the file to be deleted. (This relies |
3302 // on the delete happening on the FILE thread which is mapped to main thread | 3304 // on the delete happening on the FILE thread which is mapped to main thread |
3303 // in this test.) | 3305 // in this test.) |
3304 deletable_file = NULL; | 3306 deletable_file = NULL; |
3305 base::RunLoop().RunUntilIdle(); | 3307 base::RunLoop().RunUntilIdle(); |
3306 | 3308 |
3307 // The file is no longer readable to the child and has been deleted. | 3309 // The file is no longer readable to the child and has been deleted. |
3308 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3310 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
3309 filter_->child_id(), file_path)); | 3311 filter_->child_id(), file_path)); |
3310 EXPECT_FALSE(base::PathExists(file_path)); | 3312 EXPECT_FALSE(base::PathExists(file_path)); |
3311 } | 3313 } |
3312 | 3314 |
3315 // Tests the dispatcher host's temporary file management in the mojo-enabled | |
3316 // loading. | |
3317 TEST_P(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) { | |
3318 const int kRequestID = 1; | |
3319 | |
3320 // Create a temporary file. | |
3321 base::FilePath file_path; | |
3322 ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); | |
3323 scoped_refptr<ShareableFileReference> deletable_file = | |
3324 ShareableFileReference::GetOrCreate( | |
3325 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
3326 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); | |
3327 | |
3328 // Not readable. | |
3329 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
3330 filter_->child_id(), file_path)); | |
3331 | |
3332 // Register it for a resource request. | |
3333 auto downloaded_file = base::MakeUnique<DownloadedTempFileImpl>( | |
3334 &host_, filter_->child_id(), kRequestID, file_path); | |
3335 mojom::DownloadedTempFilePtr downloaded_file_ptr = | |
3336 downloaded_file->CreateInterfacePtrAndBind(); | |
3337 host_.RegisterDownloadedTempFile(std::move(downloaded_file)); | |
3338 | |
3339 // Should be readable now. | |
3340 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
3341 filter_->child_id(), file_path)); | |
3342 | |
3343 // The child releases from the request. | |
3344 downloaded_file_ptr = nullptr; | |
yhirano
2016/11/16 10:43:39
It may be good to call base::RunLoop().RunUntilIdl
tzik
2016/11/17 08:42:50
Done.
| |
3345 | |
3346 // Still readable because there is another reference to the file. (The child | |
3347 // may take additional blob references.) | |
3348 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
3349 filter_->child_id(), file_path)); | |
3350 | |
3351 // Release extra references and wait for the file to be deleted. (This relies | |
3352 // on the delete happening on the FILE thread which is mapped to main thread | |
3353 // in this test.) | |
3354 deletable_file = NULL; | |
3355 base::RunLoop().RunUntilIdle(); | |
3356 | |
3357 // The file is no longer readable to the child and has been deleted. | |
3358 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
3359 filter_->child_id(), file_path)); | |
3360 EXPECT_FALSE(base::PathExists(file_path)); | |
3361 } | |
3362 | |
3313 // Tests that temporary files held on behalf of child processes are released | 3363 // Tests that temporary files held on behalf of child processes are released |
3314 // when the child process dies. | 3364 // when the child process dies. |
3315 TEST_P(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { | 3365 TEST_P(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { |
3316 const int kRequestID = 1; | 3366 const int kRequestID = 1; |
3317 | 3367 |
3318 // Create a temporary file. | 3368 // Create a temporary file. |
3319 base::FilePath file_path; | 3369 base::FilePath file_path; |
3320 ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); | 3370 ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); |
3321 scoped_refptr<ShareableFileReference> deletable_file = | 3371 scoped_refptr<ShareableFileReference> deletable_file = |
3322 ShareableFileReference::GetOrCreate( | 3372 ShareableFileReference::GetOrCreate( |
3323 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 3373 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
3324 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); | 3374 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); |
3325 | 3375 |
3326 // Register it for a resource request. | 3376 // Register it for a resource request. |
3327 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); | 3377 host_.RegisterDownloadedTempFile(base::MakeUnique<DownloadedTempFileImpl>( |
3378 &host_, filter_->child_id(), kRequestID, file_path)); | |
3328 deletable_file = NULL; | 3379 deletable_file = NULL; |
3329 | 3380 |
3330 // Should be readable now. | 3381 // Should be readable now. |
3331 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3382 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
3332 filter_->child_id(), file_path)); | 3383 filter_->child_id(), file_path)); |
3333 | 3384 |
3334 // Let the process die. | 3385 // Let the process die. |
3335 filter_->OnChannelClosing(); | 3386 filter_->OnChannelClosing(); |
3336 base::RunLoop().RunUntilIdle(); | 3387 base::RunLoop().RunUntilIdle(); |
3337 | 3388 |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3843 return nullptr; | 3894 return nullptr; |
3844 } | 3895 } |
3845 | 3896 |
3846 INSTANTIATE_TEST_CASE_P( | 3897 INSTANTIATE_TEST_CASE_P( |
3847 ResourceDispatcherHostTests, | 3898 ResourceDispatcherHostTests, |
3848 ResourceDispatcherHostTest, | 3899 ResourceDispatcherHostTest, |
3849 testing::Values(TestConfig::kDefault, | 3900 testing::Values(TestConfig::kDefault, |
3850 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3901 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
3851 | 3902 |
3852 } // namespace content | 3903 } // namespace content |
OLD | NEW |