Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1384)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 2503813002: Fix and refactor downloaded file handling in the loading stack (Closed)
Patch Set: move to dtor Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 3317 matching lines...) Expand 10 before | Expand all | Expand 10 after
3358 } 3359 }
3359 } 3360 }
3360 3361
3361 // Tests the dispatcher host's temporary file management. 3362 // Tests the dispatcher host's temporary file management.
3362 TEST_P(ResourceDispatcherHostTest, RegisterDownloadedTempFile) { 3363 TEST_P(ResourceDispatcherHostTest, RegisterDownloadedTempFile) {
3363 const int kRequestID = 1; 3364 const int kRequestID = 1;
3364 3365
3365 // Create a temporary file. 3366 // Create a temporary file.
3366 base::FilePath file_path; 3367 base::FilePath file_path;
3367 ASSERT_TRUE(base::CreateTemporaryFile(&file_path)); 3368 ASSERT_TRUE(base::CreateTemporaryFile(&file_path));
3369 EXPECT_TRUE(base::PathExists(file_path));
3368 scoped_refptr<ShareableFileReference> deletable_file = 3370 scoped_refptr<ShareableFileReference> deletable_file =
3369 ShareableFileReference::GetOrCreate( 3371 ShareableFileReference::GetOrCreate(
3370 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, 3372 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE,
3371 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); 3373 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get());
3372 3374
3373 // Not readable. 3375 // Not readable.
3374 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3376 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3375 filter_->child_id(), file_path)); 3377 filter_->child_id(), file_path));
3376 3378
3377 // Register it for a resource request. 3379 // Register it for a resource request.
3378 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path); 3380 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path);
3379 3381
3380 // Should be readable now. 3382 // Should be readable now.
3381 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3383 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3382 filter_->child_id(), file_path)); 3384 filter_->child_id(), file_path));
3383 3385
3384 // The child releases from the request. 3386 // The child releases from the request.
3385 ResourceHostMsg_ReleaseDownloadedFile release_msg(kRequestID); 3387 ResourceHostMsg_ReleaseDownloadedFile release_msg(kRequestID);
3386 host_.OnMessageReceived(release_msg, filter_.get()); 3388 host_.OnMessageReceived(release_msg, filter_.get());
3387 3389
3388 // Still readable because there is another reference to the file. (The child 3390 // Still readable because there is another reference to the file. (The child
3389 // may take additional blob references.) 3391 // may take additional blob references.)
3390 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3392 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3391 filter_->child_id(), file_path)); 3393 filter_->child_id(), file_path));
3392 3394
3393 // Release extra references and wait for the file to be deleted. (This relies 3395 // 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 3396 // on the delete happening on the FILE thread which is mapped to main thread
3395 // in this test.) 3397 // in this test.)
3396 deletable_file = NULL; 3398 deletable_file = nullptr;
3397 base::RunLoop().RunUntilIdle(); 3399 base::RunLoop().RunUntilIdle();
3398 3400
3399 // The file is no longer readable to the child and has been deleted. 3401 // The file is no longer readable to the child and has been deleted.
3402 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3403 filter_->child_id(), file_path));
3404 EXPECT_FALSE(base::PathExists(file_path));
3405 }
3406
3407 // Tests the dispatcher host's temporary file management in the mojo-enabled
3408 // loading.
3409 TEST_P(ResourceDispatcherHostTest, RegisterDownloadedTempFileWithMojo) {
3410 const int kRequestID = 1;
3411
3412 // Create a temporary file.
3413 base::FilePath file_path;
3414 ASSERT_TRUE(base::CreateTemporaryFile(&file_path));
3415 EXPECT_TRUE(base::PathExists(file_path));
3416 scoped_refptr<ShareableFileReference> deletable_file =
3417 ShareableFileReference::GetOrCreate(
3418 file_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE,
3419 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get());
3420
3421 // Not readable.
3422 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3423 filter_->child_id(), file_path));
3424
3425 // Register it for a resource request.
3426 auto downloaded_file =
3427 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID);
3428 mojom::DownloadedTempFilePtr downloaded_file_ptr =
3429 DownloadedTempFileImpl::Create(filter_->child_id(), kRequestID);
3430 host_.RegisterDownloadedTempFile(filter_->child_id(), kRequestID, file_path);
3431
3432 // Should be readable now.
3433 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3434 filter_->child_id(), file_path));
3435
3436 // The child releases from the request.
3437 downloaded_file_ptr = nullptr;
3438 base::RunLoop().RunUntilIdle();
3439
3440 // Still readable because there is another reference to the file. (The child
3441 // may take additional blob references.)
3442 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3443 filter_->child_id(), file_path));
3444
3445 // Release extra references and wait for the file to be deleted. (This relies
3446 // on the delete happening on the FILE thread which is mapped to main thread
3447 // in this test.)
3448 deletable_file = nullptr;
3449 base::RunLoop().RunUntilIdle();
3450
3451 // The file is no longer readable to the child and has been deleted.
3400 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 3452 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
3401 filter_->child_id(), file_path)); 3453 filter_->child_id(), file_path));
3402 EXPECT_FALSE(base::PathExists(file_path)); 3454 EXPECT_FALSE(base::PathExists(file_path));
3403 } 3455 }
3404 3456
3405 // Tests that temporary files held on behalf of child processes are released 3457 // Tests that temporary files held on behalf of child processes are released
3406 // when the child process dies. 3458 // when the child process dies.
3407 TEST_P(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) { 3459 TEST_P(ResourceDispatcherHostTest, ReleaseTemporiesOnProcessExit) {
3408 const int kRequestID = 1; 3460 const int kRequestID = 1;
3409 3461
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
3935 return nullptr; 3987 return nullptr;
3936 } 3988 }
3937 3989
3938 INSTANTIATE_TEST_CASE_P( 3990 INSTANTIATE_TEST_CASE_P(
3939 ResourceDispatcherHostTests, 3991 ResourceDispatcherHostTests,
3940 ResourceDispatcherHostTest, 3992 ResourceDispatcherHostTest,
3941 testing::Values(TestConfig::kDefault, 3993 testing::Values(TestConfig::kDefault,
3942 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3994 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3943 3995
3944 } // namespace content 3996 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/mojo_async_resource_handler.cc ('k') | content/browser/loader/test_url_loader_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698