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 3345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3386 host_.OnMessageReceived(release_msg, filter_.get()); | 3387 host_.OnMessageReceived(release_msg, filter_.get()); |
3387 | 3388 |
3388 // Still readable because there is another reference to the file. (The child | 3389 // Still readable because there is another reference to the file. (The child |
3389 // may take additional blob references.) | 3390 // may take additional blob references.) |
3390 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3391 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
3391 filter_->child_id(), file_path)); | 3392 filter_->child_id(), file_path)); |
3392 | 3393 |
3393 // Release extra references and wait for the file to be deleted. (This relies | 3394 // Release extra references and wait for the file to be deleted. (This relies |
3394 // on the delete happening on the FILE thread which is mapped to main thread | 3395 // on the delete happening on the FILE thread which is mapped to main thread |
3395 // in this test.) | 3396 // in this test.) |
3396 deletable_file = NULL; | 3397 deletable_file = nullptr; |
3397 base::RunLoop().RunUntilIdle(); | 3398 base::RunLoop().RunUntilIdle(); |
3398 | 3399 |
3399 // The file is no longer readable to the child and has been deleted. | 3400 // The file is no longer readable to the child and has been deleted. |
3401 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
3402 filter_->child_id(), file_path)); | |
3403 EXPECT_FALSE(base::PathExists(file_path)); | |
3404 } | |
3405 | |
3406 // Tests the dispatcher host's temporary file management in the mojo-enabled | |
3407 // loading. | |
3408 TEST_P(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) { | |
3409 const int kRequestID = 1; | |
3410 | |
3411 // Create a temporary file. | |
3412 base::FilePath file_path; | |
3413 ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); | |
3414 scoped_refptr<ShareableFileReference> deletable_file = | |
3415 ShareableFileReference::GetOrCreate( | |
3416 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
3417 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); | |
3418 | |
3419 // Not readable. | |
3420 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
3421 filter_->child_id(), file_path)); | |
3422 | |
3423 // Register it for a resource request. | |
3424 auto downloaded_file = | |
3425 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID); | |
3426 mojom::DownloadedTempFilePtr downloaded_file_ptr = | |
3427 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID); | |
3428 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); | |
3429 | |
3430 // Should be readable now. | |
3431 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
3432 filter_->child_id(), file_path)); | |
3433 | |
3434 // The child releases from the request. | |
3435 downloaded_file_ptr = nullptr; | |
3436 base::RunLoop().RunUntilIdle(); | |
3437 | |
3438 // Still readable because there is another reference to the file. (The child | |
3439 // may take additional blob references.) | |
mmenke
2016/11/22 16:19:34
I don't see an API for a child process to create a
tzik
2016/11/24 14:06:40
"another reference to the file" means a ShareableF
| |
3440 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
3441 filter_->child_id(), file_path)); | |
3442 | |
3443 // Release extra references and wait for the file to be deleted. (This relies | |
3444 // on the delete happening on the FILE thread which is mapped to main thread | |
3445 // in this test.) | |
3446 deletable_file = nullptr; | |
3447 base::RunLoop().RunUntilIdle(); | |
3448 | |
3449 // The file is no longer readable to the child and has been deleted. | |
3400 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 3450 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
3401 filter_->child_id(), file_path)); | 3451 filter_->child_id(), file_path)); |
3402 EXPECT_FALSE(base::PathExists(file_path)); | 3452 EXPECT_FALSE(base::PathExists(file_path)); |
mmenke
2016/11/22 16:19:34
Add an EXPECT_TRUE(base::PathExists(file_path)); w
tzik
2016/11/24 14:06:40
Done.
| |
3403 } | 3453 } |
3404 | 3454 |
3405 // Tests that temporary files held on behalf of child processes are released | 3455 // Tests that temporary files held on behalf of child processes are released |
3406 // when the child process dies. | 3456 // when the child process dies. |
3407 TEST_P(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { | 3457 TEST_P(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { |
3408 const int kRequestID = 1; | 3458 const int kRequestID = 1; |
3409 | 3459 |
3410 // Create a temporary file. | 3460 // Create a temporary file. |
3411 base::FilePath file_path; | 3461 base::FilePath file_path; |
3412 ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); | 3462 ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3935 return nullptr; | 3985 return nullptr; |
3936 } | 3986 } |
3937 | 3987 |
3938 INSTANTIATE_TEST_CASE_P( | 3988 INSTANTIATE_TEST_CASE_P( |
3939 ResourceDispatcherHostTests, | 3989 ResourceDispatcherHostTests, |
3940 ResourceDispatcherHostTest, | 3990 ResourceDispatcherHostTest, |
3941 testing::Values(TestConfig::kDefault, | 3991 testing::Values(TestConfig::kDefault, |
3942 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3992 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
3943 | 3993 |
3944 } // namespace content | 3994 } // namespace content |
OLD | NEW |