summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/obfuscated_file_util_unittest.cc
diff options
context:
space:
mode:
authortzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-11 07:35:13 +0000
committertzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-11 07:35:13 +0000
commit294dd0316b3246c30e4558e8ec380479c9e82481 (patch)
tree0da556f3aa34918cd33ba14ab80e9acfbb8574f9 /webkit/fileapi/obfuscated_file_util_unittest.cc
parent27d255b7a75a9a21fca70a90eae07c6cf22ae30b (diff)
downloadchromium_src-294dd0316b3246c30e4558e8ec380479c9e82481.zip
chromium_src-294dd0316b3246c30e4558e8ec380479c9e82481.tar.gz
chromium_src-294dd0316b3246c30e4558e8ec380479c9e82481.tar.bz2
Merge QuotaFileUtil into ObfuscatedFileUtil
This change includes - rename variable name of paths, (e.g. "filesystem:http://example.com/temporary/hoge/fuga") --- path: FileSystemPath past by upper layer, ("http://example.com", kTemporary, "hoge/fuga") --- virtual_path: path.internal_path(), ("hoge/fuga") --- local_path: origin, type & absolute native path --- local_file_path: absolute native path (e.g. "/home/tzik/.config/chromium/Default/File System/001/t/00/0000001") --- data_path: native path, relative to origin directory (e.g. "00/0000001") - use FilePath instead of FileSystemPath for source path in CopyInForeignFile. - refactor CopyOrMoveFile and CopyInForeignFile of ObfuscatedFileUtil - merge QuotaFileUtil into ObfuscatedFileUtil - fixing tests BUG=114732 TEST='ObfuscatedFileUtilTest.*' Review URL: https://chromiumcodereview.appspot.com/10051004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136521 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/obfuscated_file_util_unittest.cc')
-rw-r--r--webkit/fileapi/obfuscated_file_util_unittest.cc422
1 files changed, 370 insertions, 52 deletions
diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc
index 95a62fb..beb0f19 100644
--- a/webkit/fileapi/obfuscated_file_util_unittest.cc
+++ b/webkit/fileapi/obfuscated_file_util_unittest.cc
@@ -140,6 +140,18 @@ class ObfuscatedFileUtilTest : public testing::Test {
test_helper_.TearDown();
}
+ scoped_ptr<FileSystemOperationContext> LimitedContext(
+ int64 allowed_bytes_growth) {
+ scoped_ptr<FileSystemOperationContext> context(
+ test_helper_.NewOperationContext());
+ context->set_allowed_bytes_growth(allowed_bytes_growth);
+ return context.Pass();
+ }
+
+ scoped_ptr<FileSystemOperationContext> UnlimitedContext() {
+ return LimitedContext(kint64max);
+ }
+
FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) {
FileSystemOperationContext* context;
if (helper)
@@ -180,6 +192,11 @@ class ObfuscatedFileUtilTest : public testing::Test {
return type_;
}
+ int64 ComputeTotalFileSize() {
+ return test_helper_.ComputeCurrentOriginUsage() -
+ test_helper_.ComputeCurrentDirectoryDatabaseUsage();
+ }
+
void GetUsageFromQuotaManager() {
quota_manager_->GetUsageAndQuota(
origin(), test_helper_.storage_type(),
@@ -204,6 +221,10 @@ class ObfuscatedFileUtilTest : public testing::Test {
return test_helper_.CreatePathFromUTF8(path);
}
+ int64 PathCost(const FileSystemPath& path) {
+ return ObfuscatedFileUtil::ComputeFilePathCost(path.internal_path());
+ }
+
FileSystemPath CreatePath(const FilePath& path) {
return test_helper_.CreatePath(path);
}
@@ -295,6 +316,48 @@ class ObfuscatedFileUtilTest : public testing::Test {
}
}
+ class UsageVerifyHelper {
+ public:
+ UsageVerifyHelper(scoped_ptr<FileSystemOperationContext> context,
+ FileSystemTestOriginHelper* test_helper,
+ int64 expected_usage)
+ : context_(context.Pass()),
+ test_helper_(test_helper),
+ expected_usage_(expected_usage) {}
+
+ ~UsageVerifyHelper() {
+ Check();
+ }
+
+ FileSystemOperationContext* context() {
+ return context_.get();
+ }
+
+ private:
+ void Check() {
+ ASSERT_EQ(expected_usage_,
+ test_helper_->GetCachedOriginUsage());
+ }
+
+ scoped_ptr<FileSystemOperationContext> context_;
+ FileSystemTestOriginHelper* test_helper_;
+ int64 growth_;
+ int64 expected_usage_;
+ };
+
+ scoped_ptr<UsageVerifyHelper> AllowUsageIncrease(int64 requested_growth) {
+ int64 usage = test_helper_.GetCachedOriginUsage();
+ return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
+ LimitedContext(requested_growth),
+ &test_helper_, usage + requested_growth));
+ }
+
+ scoped_ptr<UsageVerifyHelper> DisallowUsageIncrease(int64 requested_growth) {
+ int64 usage = test_helper_.GetCachedOriginUsage();
+ return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
+ LimitedContext(requested_growth - 1), &test_helper_, usage));
+ }
+
void FillTestDirectory(
const FileSystemPath& root_path,
std::set<FilePath::StringType>* files,
@@ -404,7 +467,6 @@ class ObfuscatedFileUtilTest : public testing::Test {
FilePath root_file_path = source_dir.path();
FilePath src_file_path = root_file_path.AppendASCII("file_name");
FileSystemPath dest_path = CreatePathFromUTF8("new file");
- FileSystemPath src_path = CreatePath(src_file_path);
int64 src_file_length = 87;
base::PlatformFileError error_code;
@@ -435,13 +497,15 @@ class ObfuscatedFileUtilTest : public testing::Test {
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(path_cost + src_file_length - 1);
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
- ofu()->CopyInForeignFile(context.get(), src_path, dest_path));
+ ofu()->CopyInForeignFile(context.get(),
+ src_file_path, dest_path));
}
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(path_cost + src_file_length);
EXPECT_EQ(base::PLATFORM_FILE_OK,
- ofu()->CopyInForeignFile(context.get(), src_path, dest_path));
+ ofu()->CopyInForeignFile(context.get(),
+ src_file_path, dest_path));
context.reset(NewContext(NULL));
EXPECT_TRUE(ofu()->PathExists(context.get(), dest_path));
@@ -663,75 +727,68 @@ TEST_F(ObfuscatedFileUtilTest, TestTruncate) {
TEST_F(ObfuscatedFileUtilTest, TestQuotaOnTruncation) {
bool created = false;
FileSystemPath path = CreatePathFromUTF8("file");
- scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->EnsureFileExists(context.get(), path, &created));
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(path))->context(),
+ path, &created));
ASSERT_TRUE(created);
+ ASSERT_EQ(0, ComputeTotalFileSize());
- int64 path_cost = test_helper().GetCachedOriginUsage();
-
- context.reset(NewContext(NULL));
- context->set_allowed_bytes_growth(1020);
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->Truncate(context.get(), path, 1020));
- ASSERT_EQ(path_cost + 1020, test_helper().GetCachedOriginUsage());
- ASSERT_EQ(path_cost + ComputeCurrentUsage(),
- test_helper().GetCachedOriginUsage());
+ ofu()->Truncate(
+ AllowUsageIncrease(1020)->context(),
+ path, 1020));
+ ASSERT_EQ(1020, ComputeTotalFileSize());
- context.reset(NewContext(NULL));
- context->set_allowed_bytes_growth(0);
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->Truncate(context.get(), path, 0));
- ASSERT_EQ(path_cost + 0, test_helper().GetCachedOriginUsage());
- ASSERT_EQ(path_cost + ComputeCurrentUsage(),
- test_helper().GetCachedOriginUsage());
+ ofu()->Truncate(
+ AllowUsageIncrease(-1020)->context(),
+ path, 0));
+ ASSERT_EQ(0, ComputeTotalFileSize());
- context.reset(NewContext(NULL));
- context->set_allowed_bytes_growth(1020);
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
- ofu()->Truncate(context.get(), path, 1021));
- ASSERT_EQ(path_cost + 0, test_helper().GetCachedOriginUsage());
- ASSERT_EQ(path_cost + ComputeCurrentUsage(),
- test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext(NULL));
- context->set_allowed_bytes_growth(1020);
- EXPECT_EQ(base::PLATFORM_FILE_OK,
- ofu()->Truncate(context.get(), path, 1020));
- ASSERT_EQ(path_cost + 1020, test_helper().GetCachedOriginUsage());
- ASSERT_EQ(path_cost + ComputeCurrentUsage(),
- test_helper().GetCachedOriginUsage());
+ ofu()->Truncate(
+ DisallowUsageIncrease(1021)->context(),
+ path, 1021));
+ ASSERT_EQ(0, ComputeTotalFileSize());
- context.reset(NewContext(NULL));
- context->set_allowed_bytes_growth(0);
EXPECT_EQ(base::PLATFORM_FILE_OK,
- ofu()->Truncate(context.get(), path, 1020));
- ASSERT_EQ(path_cost + 1020, test_helper().GetCachedOriginUsage());
- ASSERT_EQ(path_cost + ComputeCurrentUsage(),
- test_helper().GetCachedOriginUsage());
+ ofu()->Truncate(
+ AllowUsageIncrease(1020)->context(),
+ path, 1020));
+ ASSERT_EQ(1020, ComputeTotalFileSize());
- context.reset(NewContext(NULL));
- context->set_allowed_bytes_growth(-2); // quota exceeded
EXPECT_EQ(base::PLATFORM_FILE_OK,
- ofu()->Truncate(context.get(), path, 1019));
- ASSERT_EQ(path_cost + 1019, test_helper().GetCachedOriginUsage());
- ASSERT_EQ(path_cost + ComputeCurrentUsage(),
- test_helper().GetCachedOriginUsage());
+ ofu()->Truncate(
+ AllowUsageIncrease(0)->context(),
+ path, 1020));
+ ASSERT_EQ(1020, ComputeTotalFileSize());
+
+ // quota exceeded
+ {
+ scoped_ptr<UsageVerifyHelper> helper = AllowUsageIncrease(-1);
+ helper->context()->set_allowed_bytes_growth(
+ helper->context()->allowed_bytes_growth() - 1);
+ EXPECT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(helper->context(), path, 1019));
+ ASSERT_EQ(1019, ComputeTotalFileSize());
+ }
// Delete backing file to make following truncation fail.
- context.reset(NewContext(NULL));
FilePath local_path;
ASSERT_EQ(base::PLATFORM_FILE_OK,
- ofu()->GetLocalFilePath(context.get(), path, &local_path));
+ ofu()->GetLocalFilePath(
+ UnlimitedContext().get(),
+ path, &local_path));
ASSERT_FALSE(local_path.empty());
ASSERT_TRUE(file_util::Delete(local_path, false));
- context.reset(NewContext(NULL));
- context->set_allowed_bytes_growth(1234);
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
- ofu()->Truncate(context.get(), path, 1234));
- ASSERT_EQ(path_cost + 1019, test_helper().GetCachedOriginUsage());
+ ofu()->Truncate(
+ LimitedContext(1234).get(),
+ path, 1234));
+ ASSERT_EQ(0, ComputeTotalFileSize());
}
TEST_F(ObfuscatedFileUtilTest, TestEnsureFileExists) {
@@ -1683,7 +1740,7 @@ TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) {
context.reset(NewContext(NULL));
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->CopyInForeignFile(context.get(),
- CreatePath(src_local_path),
+ src_local_path,
path));
EXPECT_NE(base::Time(), GetModifiedTime(dir_path));
}
@@ -1810,3 +1867,264 @@ TEST_F(ObfuscatedFileUtilTest, TestFileEnumeratorTimestamp) {
}
EXPECT_EQ(2, count);
}
+
+TEST_F(ObfuscatedFileUtilTest, TestQuotaOnCopyFile) {
+ FileSystemPath from_file(CreatePathFromUTF8("fromfile"));
+ FileSystemPath obstacle_file(CreatePathFromUTF8("obstaclefile"));
+ FileSystemPath to_file1(CreatePathFromUTF8("tofile1"));
+ FileSystemPath to_file2(CreatePathFromUTF8("tofile2"));
+ bool created;
+
+ int64 expected_total_file_size = 0;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(from_file))->context(),
+ from_file, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(obstacle_file))->context(),
+ obstacle_file, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 from_file_size = 1020;
+ expected_total_file_size += from_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(from_file_size)->context(),
+ from_file, from_file_size));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 obstacle_file_size = 1;
+ expected_total_file_size += obstacle_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(obstacle_file_size)->context(),
+ obstacle_file, obstacle_file_size));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 to_file1_size = from_file_size;
+ expected_total_file_size += to_file1_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->CopyOrMoveFile(
+ AllowUsageIncrease(
+ PathCost(to_file1) + to_file1_size)->context(),
+ from_file, to_file1, true /* copy */));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
+ ofu()->CopyOrMoveFile(
+ DisallowUsageIncrease(
+ PathCost(to_file2) + from_file_size)->context(),
+ from_file, to_file2, true /* copy */));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 old_obstacle_file_size = obstacle_file_size;
+ obstacle_file_size = from_file_size;
+ expected_total_file_size += obstacle_file_size - old_obstacle_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->CopyOrMoveFile(
+ AllowUsageIncrease(
+ obstacle_file_size - old_obstacle_file_size)->context(),
+ from_file, obstacle_file, true /* copy */));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 old_from_file_size = from_file_size;
+ from_file_size = old_from_file_size - 1;
+ expected_total_file_size += from_file_size - old_from_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(
+ from_file_size - old_from_file_size)->context(),
+ from_file, from_file_size));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ // quota exceeded
+ {
+ old_obstacle_file_size = obstacle_file_size;
+ obstacle_file_size = from_file_size;
+ expected_total_file_size += obstacle_file_size - old_obstacle_file_size;
+ scoped_ptr<UsageVerifyHelper> helper = AllowUsageIncrease(
+ obstacle_file_size - old_obstacle_file_size);
+ helper->context()->set_allowed_bytes_growth(
+ helper->context()->allowed_bytes_growth() - 1);
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->CopyOrMoveFile(
+ helper->context(),
+ from_file, obstacle_file, true /* copy */));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+ }
+}
+
+TEST_F(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) {
+ FileSystemPath from_file(CreatePathFromUTF8("fromfile"));
+ FileSystemPath obstacle_file(CreatePathFromUTF8("obstaclefile"));
+ FileSystemPath to_file(CreatePathFromUTF8("tofile"));
+ bool created;
+
+ int64 expected_total_file_size = 0;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(from_file))->context(),
+ from_file, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 from_file_size = 1020;
+ expected_total_file_size += from_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(from_file_size)->context(),
+ from_file, from_file_size));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 to_file_size ALLOW_UNUSED = from_file_size;
+ from_file_size = 0;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->CopyOrMoveFile(
+ AllowUsageIncrease(-PathCost(from_file) +
+ PathCost(to_file))->context(),
+ from_file, to_file, false /* move */));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(from_file))->context(),
+ from_file, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(obstacle_file))->context(),
+ obstacle_file, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ from_file_size = 1020;
+ expected_total_file_size += from_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(from_file_size)->context(),
+ from_file, from_file_size));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 obstacle_file_size = 1;
+ expected_total_file_size += obstacle_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(1)->context(),
+ obstacle_file, obstacle_file_size));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ int64 old_obstacle_file_size = obstacle_file_size;
+ obstacle_file_size = from_file_size;
+ from_file_size = 0;
+ expected_total_file_size -= old_obstacle_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->CopyOrMoveFile(
+ AllowUsageIncrease(
+ -old_obstacle_file_size - PathCost(from_file))->context(),
+ from_file, obstacle_file,
+ false /* move */));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(from_file))->context(),
+ from_file, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ from_file_size = 10;
+ expected_total_file_size += from_file_size;
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(from_file_size)->context(),
+ from_file, from_file_size));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+
+ // quota exceeded even after operation
+ old_obstacle_file_size = obstacle_file_size;
+ obstacle_file_size = from_file_size;
+ from_file_size = 0;
+ expected_total_file_size -= old_obstacle_file_size;
+ scoped_ptr<FileSystemOperationContext> context =
+ LimitedContext(-old_obstacle_file_size - PathCost(from_file) - 1);
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->CopyOrMoveFile(
+ context.get(), from_file, obstacle_file, false /* move */));
+ ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
+ context.reset();
+}
+
+TEST_F(ObfuscatedFileUtilTest, TestQuotaOnRemove) {
+ FileSystemPath dir(CreatePathFromUTF8("dir"));
+ FileSystemPath file(CreatePathFromUTF8("file"));
+ FileSystemPath dfile1(CreatePathFromUTF8("dir/dfile1"));
+ FileSystemPath dfile2(CreatePathFromUTF8("dir/dfile2"));
+ bool created;
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(file))->context(),
+ file, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(0, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->CreateDirectory(
+ AllowUsageIncrease(PathCost(dir))->context(),
+ dir, false, false));
+ ASSERT_EQ(0, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(dfile1))->context(),
+ dfile1, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(0, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->EnsureFileExists(
+ AllowUsageIncrease(PathCost(dfile2))->context(),
+ dfile2, &created));
+ ASSERT_TRUE(created);
+ ASSERT_EQ(0, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(340)->context(),
+ file, 340));
+ ASSERT_EQ(340, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(1020)->context(),
+ dfile1, 1020));
+ ASSERT_EQ(1360, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->Truncate(
+ AllowUsageIncrease(120)->context(),
+ dfile2, 120));
+ ASSERT_EQ(1480, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ ofu()->DeleteFile(
+ AllowUsageIncrease(-PathCost(file) - 340)->context(),
+ file));
+ ASSERT_EQ(1140, ComputeTotalFileSize());
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK,
+ FileUtilHelper::Delete(
+ AllowUsageIncrease(-PathCost(dir) -
+ PathCost(dfile1) -
+ PathCost(dfile2) -
+ 1020 - 120)->context(),
+ ofu(), dir, true));
+ ASSERT_EQ(0, ComputeTotalFileSize());
+}