Chromium Code Reviews| Index: content/browser/loader/resource_dispatcher_host_unittest.cc |
| diff --git a/content/browser/loader/resource_dispatcher_host_unittest.cc b/content/browser/loader/resource_dispatcher_host_unittest.cc |
| index 8dfae97d5e54ab6ba82dc27c46538fdafe87f82c..eb4c2e3a6935f066ffc5b947c1d244fbdf64ec02 100644 |
| --- a/content/browser/loader/resource_dispatcher_host_unittest.cc |
| +++ b/content/browser/loader/resource_dispatcher_host_unittest.cc |
| @@ -28,6 +28,7 @@ |
| #include "content/browser/download/download_resource_handler.h" |
| #include "content/browser/frame_host/navigation_request_info.h" |
| #include "content/browser/loader/detachable_resource_handler.h" |
| +#include "content/browser/loader/downloaded_temp_file_impl.h" |
| #include "content/browser/loader/navigation_resource_throttle.h" |
| #include "content/browser/loader/navigation_url_loader.h" |
| #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| @@ -3375,7 +3376,8 @@ TEST_P(ResourceDispatcherHostTest, RegisterDownloadedTempFile) { |
| filter_->child_id(), file_path)); |
| // Register it for a resource request. |
| - host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); |
| + host_.RegisterDownloadedTempFile(base::MakeUnique<DownloadedTempFileImpl>( |
| + &host_, filter_->child_id(), kRequestID, file_path)); |
| // Should be readable now. |
| EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| @@ -3402,6 +3404,55 @@ TEST_P(ResourceDispatcherHostTest, RegisterDownloadedTempFile) { |
| EXPECT_FALSE(base::PathExists(file_path)); |
| } |
| +// Tests the dispatcher host's temporary file management in the mojo-enabled |
| +// loading. |
| +TEST_P(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) { |
| + const int kRequestID = 1; |
| + |
| + // Create a temporary file. |
| + base::FilePath file_path; |
| + ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); |
| + scoped_refptr<ShareableFileReference> deletable_file = |
| + ShareableFileReference::GetOrCreate( |
| + file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
| + BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); |
| + |
| + // Not readable. |
| + EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| + filter_->child_id(), file_path)); |
| + |
| + // Register it for a resource request. |
| + auto downloaded_file = base::MakeUnique<DownloadedTempFileImpl>( |
| + &host_, filter_->child_id(), kRequestID, file_path); |
| + mojom::DownloadedTempFilePtr downloaded_file_ptr = |
| + downloaded_file->CreateInterfacePtrAndBind(); |
| + host_.RegisterDownloadedTempFile(std::move(downloaded_file)); |
| + |
| + // Should be readable now. |
| + EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| + filter_->child_id(), file_path)); |
| + |
| + // The child releases from the request. |
| + downloaded_file_ptr = nullptr; |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // Still readable because there is another reference to the file. (The child |
| + // may take additional blob references.) |
| + EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| + filter_->child_id(), file_path)); |
| + |
| + // Release extra references and wait for the file to be deleted. (This relies |
| + // on the delete happening on the FILE thread which is mapped to main thread |
| + // in this test.) |
| + deletable_file = NULL; |
|
dcheng
2016/11/17 11:16:02
Nit: nullptr
tzik
2016/11/22 13:54:45
Done.
|
| + base::RunLoop().RunUntilIdle(); |
| + |
| + // The file is no longer readable to the child and has been deleted. |
| + EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| + filter_->child_id(), file_path)); |
| + EXPECT_FALSE(base::PathExists(file_path)); |
| +} |
| + |
| // Tests that temporary files held on behalf of child processes are released |
| // when the child process dies. |
| TEST_P(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { |
| @@ -3416,7 +3467,8 @@ TEST_P(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { |
| BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); |
| // Register it for a resource request. |
| - host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); |
| + host_.RegisterDownloadedTempFile(base::MakeUnique<DownloadedTempFileImpl>( |
| + &host_, filter_->child_id(), kRequestID, file_path)); |
| deletable_file = NULL; |
| // Should be readable now. |