| 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..d01eb82280169db48f650594e2ae73cbdaf045f0 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->Release();
|
| +
|
| + // 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.
|
|
|