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 1d4435b0419b32557f1bf795a97c952286f133f1..b8b4fd27977e5cf1431376208d0b4c1d271107fd 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" | 
| @@ -3283,7 +3284,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( | 
| @@ -3310,6 +3312,54 @@ 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; | 
| 
 
yhirano
2016/11/16 10:43:39
It may be good to call base::RunLoop().RunUntilIdl
 
tzik
2016/11/17 08:42:50
Done.
 
 | 
| + | 
| + // 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; | 
| + 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) { | 
| @@ -3324,7 +3374,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. |