| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | |
| 8 #include <limits> | 7 #include <limits> |
| 9 #include <set> | 8 #include <set> |
| 10 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 void TearDown() override { | 185 void TearDown() override { |
| 186 quota_manager_ = NULL; | 186 quota_manager_ = NULL; |
| 187 sandbox_file_system_.TearDown(); | 187 sandbox_file_system_.TearDown(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 scoped_ptr<FileSystemOperationContext> LimitedContext( | 190 scoped_ptr<FileSystemOperationContext> LimitedContext( |
| 191 int64_t allowed_bytes_growth) { | 191 int64_t allowed_bytes_growth) { |
| 192 scoped_ptr<FileSystemOperationContext> context( | 192 scoped_ptr<FileSystemOperationContext> context( |
| 193 sandbox_file_system_.NewOperationContext()); | 193 sandbox_file_system_.NewOperationContext()); |
| 194 context->set_allowed_bytes_growth(allowed_bytes_growth); | 194 context->set_allowed_bytes_growth(allowed_bytes_growth); |
| 195 return context.Pass(); | 195 return context; |
| 196 } | 196 } |
| 197 | 197 |
| 198 scoped_ptr<FileSystemOperationContext> UnlimitedContext() { | 198 scoped_ptr<FileSystemOperationContext> UnlimitedContext() { |
| 199 return LimitedContext(std::numeric_limits<int64_t>::max()); | 199 return LimitedContext(std::numeric_limits<int64_t>::max()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 FileSystemOperationContext* NewContext( | 202 FileSystemOperationContext* NewContext( |
| 203 SandboxFileSystemTestHelper* file_system) { | 203 SandboxFileSystemTestHelper* file_system) { |
| 204 change_observer()->ResetCount(); | 204 change_observer()->ResetCount(); |
| 205 FileSystemOperationContext* context; | 205 FileSystemOperationContext* context; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 EXPECT_TRUE(DirectoryExists( | 393 EXPECT_TRUE(DirectoryExists( |
| 394 FileSystemURLAppend(root_url, *iter))); | 394 FileSystemURLAppend(root_url, *iter))); |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 | 397 |
| 398 class UsageVerifyHelper { | 398 class UsageVerifyHelper { |
| 399 public: | 399 public: |
| 400 UsageVerifyHelper(scoped_ptr<FileSystemOperationContext> context, | 400 UsageVerifyHelper(scoped_ptr<FileSystemOperationContext> context, |
| 401 SandboxFileSystemTestHelper* file_system, | 401 SandboxFileSystemTestHelper* file_system, |
| 402 int64_t expected_usage) | 402 int64_t expected_usage) |
| 403 : context_(context.Pass()), | 403 : context_(std::move(context)), |
| 404 sandbox_file_system_(file_system), | 404 sandbox_file_system_(file_system), |
| 405 expected_usage_(expected_usage) {} | 405 expected_usage_(expected_usage) {} |
| 406 | 406 |
| 407 ~UsageVerifyHelper() { | 407 ~UsageVerifyHelper() { |
| 408 base::RunLoop().RunUntilIdle(); | 408 base::RunLoop().RunUntilIdle(); |
| 409 Check(); | 409 Check(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 FileSystemOperationContext* context() { | 412 FileSystemOperationContext* context() { |
| 413 return context_.get(); | 413 return context_.get(); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE, file.error_details()); | 844 ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE, file.error_details()); |
| 845 | 845 |
| 846 context.reset(NewContext(NULL)); | 846 context.reset(NewContext(NULL)); |
| 847 context->set_allowed_bytes_growth( | 847 context->set_allowed_bytes_growth( |
| 848 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); | 848 ObfuscatedFileUtil::ComputeFilePathCost(url.path())); |
| 849 file = ofu()->CreateOrOpen(context.get(), url, file_flags); | 849 file = ofu()->CreateOrOpen(context.get(), url, file_flags); |
| 850 EXPECT_TRUE(file.IsValid()); | 850 EXPECT_TRUE(file.IsValid()); |
| 851 ASSERT_TRUE(file.created()); | 851 ASSERT_TRUE(file.created()); |
| 852 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 852 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| 853 | 853 |
| 854 CheckFileAndCloseHandle(url, file.Pass()); | 854 CheckFileAndCloseHandle(url, std::move(file)); |
| 855 | 855 |
| 856 context.reset(NewContext(NULL)); | 856 context.reset(NewContext(NULL)); |
| 857 base::FilePath local_path; | 857 base::FilePath local_path; |
| 858 EXPECT_EQ(base::File::FILE_OK, | 858 EXPECT_EQ(base::File::FILE_OK, |
| 859 ofu()->GetLocalFilePath(context.get(), url, &local_path)); | 859 ofu()->GetLocalFilePath(context.get(), url, &local_path)); |
| 860 EXPECT_TRUE(base::PathExists(local_path)); | 860 EXPECT_TRUE(base::PathExists(local_path)); |
| 861 | 861 |
| 862 // Verify that deleting a file isn't stopped by zero quota, and that it frees | 862 // Verify that deleting a file isn't stopped by zero quota, and that it frees |
| 863 // up quote from its path. | 863 // up quote from its path. |
| 864 context.reset(NewContext(NULL)); | 864 context.reset(NewContext(NULL)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 880 recursive)); | 880 recursive)); |
| 881 // The oepration created 3 directories recursively. | 881 // The oepration created 3 directories recursively. |
| 882 EXPECT_EQ(3, change_observer()->get_and_reset_create_directory_count()); | 882 EXPECT_EQ(3, change_observer()->get_and_reset_create_directory_count()); |
| 883 | 883 |
| 884 context.reset(NewContext(NULL)); | 884 context.reset(NewContext(NULL)); |
| 885 file = ofu()->CreateOrOpen(context.get(), url, file_flags); | 885 file = ofu()->CreateOrOpen(context.get(), url, file_flags); |
| 886 ASSERT_TRUE(file.IsValid()); | 886 ASSERT_TRUE(file.IsValid()); |
| 887 ASSERT_TRUE(file.created()); | 887 ASSERT_TRUE(file.created()); |
| 888 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 888 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
| 889 | 889 |
| 890 CheckFileAndCloseHandle(url, file.Pass()); | 890 CheckFileAndCloseHandle(url, std::move(file)); |
| 891 | 891 |
| 892 context.reset(NewContext(NULL)); | 892 context.reset(NewContext(NULL)); |
| 893 EXPECT_EQ(base::File::FILE_OK, | 893 EXPECT_EQ(base::File::FILE_OK, |
| 894 ofu()->GetLocalFilePath(context.get(), url, &local_path)); | 894 ofu()->GetLocalFilePath(context.get(), url, &local_path)); |
| 895 EXPECT_TRUE(base::PathExists(local_path)); | 895 EXPECT_TRUE(base::PathExists(local_path)); |
| 896 | 896 |
| 897 context.reset(NewContext(NULL)); | 897 context.reset(NewContext(NULL)); |
| 898 EXPECT_EQ(base::File::FILE_OK, ofu()->DeleteFile(context.get(), url)); | 898 EXPECT_EQ(base::File::FILE_OK, ofu()->DeleteFile(context.get(), url)); |
| 899 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 899 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
| 900 EXPECT_FALSE(base::PathExists(local_path)); | 900 EXPECT_FALSE(base::PathExists(local_path)); |
| (...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2567 ofu()->GetDirectoryForOriginAndType( | 2567 ofu()->GetDirectoryForOriginAndType( |
| 2568 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error); | 2568 origin2, GetTypeString(kFileSystemTypeTemporary), false, &error); |
| 2569 ASSERT_EQ(base::File::FILE_OK, error); | 2569 ASSERT_EQ(base::File::FILE_OK, error); |
| 2570 error = base::File::FILE_ERROR_FAILED; | 2570 error = base::File::FILE_ERROR_FAILED; |
| 2571 ofu()->GetDirectoryForOriginAndType( | 2571 ofu()->GetDirectoryForOriginAndType( |
| 2572 origin2, GetTypeString(kFileSystemTypePersistent), false, &error); | 2572 origin2, GetTypeString(kFileSystemTypePersistent), false, &error); |
| 2573 ASSERT_EQ(base::File::FILE_OK, error); | 2573 ASSERT_EQ(base::File::FILE_OK, error); |
| 2574 } | 2574 } |
| 2575 | 2575 |
| 2576 } // namespace content | 2576 } // namespace content |
| OLD | NEW |