| Index: webkit/fileapi/obfuscated_file_system_file_util_unittest.cc
|
| diff --git a/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc
|
| index 6e61b9af2a578e369c309abb5957cd51c57e7871..fc5d8b9f2c6735477dcfd30daa925d021d23d295 100644
|
| --- a/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc
|
| +++ b/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc
|
| @@ -9,14 +9,21 @@
|
| #include "base/file_path.h"
|
| #include "base/file_util.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/memory/scoped_callback_factory.h"
|
| +#include "base/message_loop.h"
|
| #include "base/platform_file.h"
|
| #include "base/scoped_temp_dir.h"
|
| #include "base/sys_string_conversions.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "webkit/fileapi/file_system_context.h"
|
| #include "webkit/fileapi/file_system_operation_context.h"
|
| +#include "webkit/fileapi/file_system_path_manager.h"
|
| #include "webkit/fileapi/file_system_test_helper.h"
|
| +#include "webkit/fileapi/file_system_usage_cache.h"
|
| #include "webkit/fileapi/obfuscated_file_system_file_util.h"
|
| +#include "webkit/quota/mock_special_storage_policy.h"
|
| +#include "webkit/quota/quota_manager.h"
|
| +#include "webkit/quota/quota_types.h"
|
|
|
| using namespace fileapi;
|
|
|
| @@ -126,27 +133,70 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| ObfuscatedFileSystemFileUtilTest()
|
| : origin_(GURL("http://www.example.com")),
|
| type_(kFileSystemTypeTemporary),
|
| - test_helper_(origin_, type_) {
|
| + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| + test_helper_(origin_, type_),
|
| + quota_status_(quota::kQuotaStatusUnknown),
|
| + usage_(-1) {
|
| }
|
|
|
| void SetUp() {
|
| ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
|
|
|
| + quota_manager_ = new quota::QuotaManager(
|
| + false /* is_incognito */,
|
| + data_dir_.path(),
|
| + base::MessageLoopProxy::CreateForCurrentThread(),
|
| + base::MessageLoopProxy::CreateForCurrentThread(),
|
| + NULL /* special storage policy */);
|
| +
|
| + file_system_context_ = new FileSystemContext(
|
| + base::MessageLoopProxy::CreateForCurrentThread(),
|
| + base::MessageLoopProxy::CreateForCurrentThread(),
|
| + new quota::MockSpecialStoragePolicy(),
|
| + quota_manager_->proxy(),
|
| + data_dir_.path(),
|
| + false /* incognito */,
|
| + true /* allow_file_access_from_files */,
|
| + false /* unlimited_quota */,
|
| + NULL /* path_manager */);
|
| +
|
| obfuscated_file_system_file_util_ =
|
| - new ObfuscatedFileSystemFileUtil(data_dir_.path(),
|
| - new FileSystemFileUtil());
|
| + static_cast<ObfuscatedFileSystemFileUtil*>(
|
| + file_system_context_->path_manager()->GetFileSystemFileUtil(type_));
|
| +
|
| test_helper_.SetUp(data_dir_.path(),
|
| false, // incognito
|
| false, // unlimited quota
|
| - NULL, // quota::QuotaManagerProxy
|
| + quota_manager_->proxy(),
|
| obfuscated_file_system_file_util_.get());
|
| }
|
|
|
| - FileSystemOperationContext* NewContext() {
|
| - FileSystemOperationContext* context = test_helper_.NewOperationContext();
|
| + FileSystemOperationContext* NewContext(FileSystemTestOriginHelper* helper) {
|
| + FileSystemOperationContext* context;
|
| + if (helper)
|
| + context = helper->NewOperationContext();
|
| + else
|
| + context = test_helper_.NewOperationContext();
|
| + context->set_allowed_bytes_growth(1024 * 1024); // Big enough for all tests.
|
| return context;
|
| }
|
|
|
| + // This can only be used after SetUp has run and created data_dir_ and
|
| + // obfuscated_file_system_file_util_.
|
| + // Use this for tests which need to run in multiple origins; we need a test
|
| + // helper per origin.
|
| + FileSystemTestOriginHelper* NewHelper(
|
| + const GURL& origin, fileapi::FileSystemType type) {
|
| + FileSystemTestOriginHelper* helper =
|
| + new FileSystemTestOriginHelper(origin, type);
|
| + helper->SetUp(data_dir_.path(),
|
| + false, // incognito
|
| + false, // unlimited quota
|
| + NULL, // quota::QuotaManagerProxy
|
| + obfuscated_file_system_file_util_.get());
|
| + return helper;
|
| + }
|
| +
|
| ObfuscatedFileSystemFileUtil* ofsfu() {
|
| return obfuscated_file_system_file_util_.get();
|
| }
|
| @@ -155,7 +205,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| return data_dir_.path();
|
| }
|
|
|
| - const GURL& origin_url() const {
|
| + const GURL& origin() const {
|
| return origin_;
|
| }
|
|
|
| @@ -163,9 +213,35 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| return type_;
|
| }
|
|
|
| + void GetUsageFromQuotaManager() {
|
| + quota_manager_->GetUsageAndQuota(
|
| + origin(), test_helper_.storage_type(),
|
| + callback_factory_.NewCallback(
|
| + &ObfuscatedFileSystemFileUtilTest::OnGetUsage));
|
| + MessageLoop::current()->RunAllPending();
|
| + EXPECT_EQ(quota::kQuotaStatusOk, quota_status_);
|
| + }
|
| +
|
| + void RevokeUsageCache() {
|
| + quota_manager_->ResetUsageTracker(test_helper_.storage_type());
|
| + ASSERT_TRUE(test_helper_.RevokeUsageCache());
|
| + }
|
| +
|
| + int64 SizeInUsageFile() {
|
| + return test_helper_.GetCachedOriginUsage();
|
| + }
|
| +
|
| + int64 usage() const { return usage_; }
|
| +
|
| + void OnGetUsage(quota::QuotaStatusCode status, int64 usage, int64 unused) {
|
| + EXPECT_EQ(quota::kQuotaStatusOk, status);
|
| + quota_status_ = status;
|
| + usage_ = usage;
|
| + }
|
| +
|
| void CheckFileAndCloseHandle(
|
| const FilePath& virtual_path, PlatformFile file_handle) {
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| FilePath local_path;
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath(
|
| context.get(), virtual_path, &local_path));
|
| @@ -198,7 +274,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
|
|
| base::PlatformFileInfo file_info1;
|
| EXPECT_EQ(length, GetSize(data_path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo(
|
| context.get(), virtual_path, &file_info1, &data_path));
|
| EXPECT_EQ(data_path, local_path);
|
| @@ -211,12 +287,12 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| EXPECT_EQ(length, file_info1.size);
|
| EXPECT_LE(file_info0.last_modified, file_info1.last_modified);
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate(
|
| context.get(), virtual_path, length * 2));
|
| EXPECT_EQ(length * 2, GetSize(data_path));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate(
|
| context.get(), virtual_path, 1));
|
| EXPECT_EQ(1, GetSize(data_path));
|
| @@ -230,7 +306,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| std::set<FilePath::StringType>::const_iterator iter;
|
| for (iter = files.begin(); iter != files.end(); ++iter) {
|
| bool created = true;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(
|
| context.get(), root_path.Append(*iter),
|
| @@ -238,7 +314,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| ASSERT_FALSE(created);
|
| }
|
| for (iter = directories.begin(); iter != directories.end(); ++iter) {
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(),
|
| root_path.Append(*iter)));
|
| }
|
| @@ -249,7 +325,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| std::set<FilePath::StringType>* files,
|
| std::set<FilePath::StringType>* directories) {
|
| scoped_ptr<FileSystemOperationContext> context;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| std::vector<base::FileUtilProxy::Entry> entries;
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->ReadDirectory(context.get(), root_path, &entries));
|
| @@ -266,7 +342,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| std::set<FilePath::StringType>::iterator iter;
|
| for (iter = files->begin(); iter != files->end(); ++iter) {
|
| bool created = false;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(
|
| context.get(), root_path.Append(*iter), &created));
|
| @@ -275,7 +351,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| for (iter = directories->begin(); iter != directories->end(); ++iter) {
|
| bool exclusive = true;
|
| bool recursive = false;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->CreateDirectory(
|
| context.get(), root_path.Append(*iter), exclusive, recursive));
|
| @@ -290,7 +366,7 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
|
|
| scoped_ptr<FileSystemOperationContext> context;
|
| std::vector<base::FileUtilProxy::Entry> entries;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->ReadDirectory(context.get(), root_path, &entries));
|
| std::vector<base::FileUtilProxy::Entry>::iterator entry_iter;
|
| @@ -314,13 +390,13 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| void TestTouchHelper(const FilePath& path) {
|
| base::Time last_access_time = base::Time::Now(); // Ignored, so not tested.
|
| base::Time last_modified_time = base::Time::Now();
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->Touch(
|
| context.get(), path, last_access_time, last_modified_time));
|
| FilePath local_path;
|
| base::PlatformFileInfo file_info;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo(
|
| context.get(), path, &file_info, &local_path));
|
| // We compare as time_t here to lower our resolution, to avoid false
|
| @@ -328,12 +404,12 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| // representation and back.
|
| EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT());
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| last_modified_time += base::TimeDelta::FromHours(1);
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->Touch(
|
| context.get(), path, last_access_time, last_modified_time));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo(
|
| context.get(), path, &file_info, &local_path));
|
| EXPECT_EQ(file_info.last_modified.ToTimeT(), last_modified_time.ToTimeT());
|
| @@ -362,20 +438,20 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| scoped_ptr<FileSystemOperationContext> context;
|
|
|
| if (overwrite) {
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(context.get(), dest_path, &created));
|
| EXPECT_TRUE(created);
|
| }
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->CopyInForeignFile(context.get(), src_path, dest_path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), dest_path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| base::PlatformFileInfo file_info;
|
| FilePath data_path;
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo(
|
| @@ -391,9 +467,15 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test {
|
| private:
|
| ScopedTempDir data_dir_;
|
| scoped_refptr<ObfuscatedFileSystemFileUtil> obfuscated_file_system_file_util_;
|
| + scoped_refptr<quota::QuotaManager> quota_manager_;
|
| + scoped_refptr<FileSystemContext> file_system_context_;
|
| GURL origin_;
|
| fileapi::FileSystemType type_;
|
| + base::ScopedCallbackFactory<ObfuscatedFileSystemFileUtilTest>
|
| + callback_factory_;
|
| FileSystemTestOriginHelper test_helper_;
|
| + quota::QuotaStatusCode quota_status_;
|
| + int64 usage_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileSystemFileUtilTest);
|
| };
|
| @@ -402,7 +484,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) {
|
| base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
|
| bool created;
|
| FilePath path = UTF8ToFilePath("fake/file");
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
|
|
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| @@ -410,13 +492,13 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) {
|
| context.get(), path, file_flags, &file_handle,
|
| &created));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->DeleteFile(context.get(), path));
|
|
|
| path = UTF8ToFilePath("test file");
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->CreateOrOpen(
|
| context.get(), path, file_flags, &file_handle, &created));
|
| @@ -425,18 +507,18 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) {
|
|
|
| CheckFileAndCloseHandle(path, file_handle);
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| FilePath local_path;
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath(
|
| context.get(), path, &local_path));
|
| EXPECT_TRUE(file_util::PathExists(local_path));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->DeleteFile(context.get(), path));
|
| EXPECT_FALSE(file_util::PathExists(local_path));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| bool exclusive = true;
|
| bool recursive = true;
|
| FilePath directory_path = UTF8ToFilePath("series/of/directories");
|
| @@ -444,7 +526,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) {
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), directory_path, exclusive, recursive));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| file_handle = base::kInvalidPlatformFileValue;
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->CreateOrOpen(
|
| @@ -454,12 +536,12 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) {
|
|
|
| CheckFileAndCloseHandle(path, file_handle);
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath(
|
| context.get(), path, &local_path));
|
| EXPECT_TRUE(file_util::PathExists(local_path));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->DeleteFile(context.get(), path));
|
| EXPECT_FALSE(file_util::PathExists(local_path));
|
| @@ -468,47 +550,47 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCreateAndDeleteFile) {
|
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestTruncate) {
|
| bool created = false;
|
| FilePath path = UTF8ToFilePath("file");
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
|
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->Truncate(context.get(), path, 4));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(context.get(), path, &created));
|
| ASSERT_TRUE(created);
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| FilePath local_path;
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetLocalFilePath(
|
| context.get(), path, &local_path));
|
| EXPECT_EQ(0, GetSize(local_path));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate(
|
| context.get(), path, 10));
|
| EXPECT_EQ(10, GetSize(local_path));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->Truncate(
|
| context.get(), path, 1));
|
| EXPECT_EQ(1, GetSize(local_path));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path));
|
| }
|
|
|
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) {
|
| FilePath path = UTF8ToFilePath("fake/file");
|
| bool created = false;
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->EnsureFileExists(
|
| context.get(), path, &created));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| path = UTF8ToFilePath("test file");
|
| created = false;
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| @@ -517,31 +599,31 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnsureFileExists) {
|
|
|
| CheckFileAndCloseHandle(path, base::kInvalidPlatformFileValue);
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(context.get(), path, &created));
|
| ASSERT_FALSE(created);
|
|
|
| // Also test in a subdirectory.
|
| path = UTF8ToFilePath("path/to/file.txt");
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| bool exclusive = true;
|
| bool recursive = true;
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), path.DirName(), exclusive, recursive));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(context.get(), path, &created));
|
| ASSERT_TRUE(created);
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path));
|
| }
|
|
|
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) {
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
|
|
| bool exclusive = false;
|
| bool recursive = false;
|
| @@ -549,37 +631,37 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) {
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->CreateDirectory(
|
| context.get(), path, exclusive, recursive));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->DeleteSingleDirectory(context.get(), path));
|
|
|
| FilePath root = UTF8ToFilePath("");
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->PathExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), root));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| exclusive = false;
|
| recursive = true;
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), path, exclusive, recursive));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), root));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path.DirName()));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->IsDirectoryEmpty(context.get(), path.DirName()));
|
|
|
| // Can't remove a non-empty directory.
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
|
| ofsfu()->DeleteSingleDirectory(context.get(), path.DirName()));
|
|
|
| @@ -592,27 +674,27 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) {
|
| EXPECT_FALSE(file_info.is_symbolic_link);
|
|
|
| // Same create again should succeed, since exclusive is false.
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), path, exclusive, recursive));
|
|
|
| exclusive = true;
|
| recursive = true;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, ofsfu()->CreateDirectory(
|
| context.get(), path, exclusive, recursive));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->DeleteSingleDirectory(context.get(), path));
|
|
|
| path = UTF8ToFilePath("foo/bop");
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->PathExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->IsDirectoryEmpty(context.get(), path));
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo(
|
| context.get(), path, &file_info, &local_path));
|
| @@ -622,9 +704,9 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) {
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), path, exclusive, recursive));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path));
|
|
|
| exclusive = true;
|
| @@ -640,9 +722,9 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) {
|
|
|
| path = UTF8ToFilePath("blah");
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->PathExists(context.get(), path));
|
|
|
| exclusive = true;
|
| @@ -650,9 +732,9 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) {
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), path, exclusive, recursive));
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->PathExists(context.get(), path));
|
|
|
| exclusive = true;
|
| @@ -662,7 +744,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestDirectoryOps) {
|
| }
|
|
|
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectory) {
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| bool exclusive = true;
|
| bool recursive = true;
|
| FilePath path = UTF8ToFilePath("directory/to/use");
|
| @@ -681,14 +763,14 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadRootWithEmptyString) {
|
|
|
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestReadDirectoryOnFile) {
|
| FilePath path = UTF8ToFilePath("file");
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
|
|
| bool created = false;
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(context.get(), path, &created));
|
| ASSERT_TRUE(created);
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| std::vector<base::FileUtilProxy::Entry> entries;
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->ReadDirectory(context.get(), path, &entries));
|
| @@ -700,7 +782,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) {
|
| FilePath path = UTF8ToFilePath("fake/file");
|
| base::Time last_access_time = base::Time::Now(); // Ignored, so not tested.
|
| base::Time last_modified_time = base::Time::Now();
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->Touch(
|
| context.get(), path, last_access_time, last_modified_time));
|
| @@ -712,22 +794,60 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestTouch) {
|
| bool exclusive = true;
|
| bool recursive = true;
|
| path = UTF8ToFilePath("directory/to/use");
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), path, exclusive, recursive));
|
| TestTouchHelper(path);
|
| }
|
|
|
| +TEST_F(ObfuscatedFileSystemFileUtilTest, TestPathQuotas) {
|
| + FilePath path = UTF8ToFilePath("fake/file");
|
| + base::Time last_access_time = base::Time::Now();
|
| + base::Time last_modified_time = base::Time::Now();
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| +
|
| + // Touch will create a file if it's not there but its parent is.
|
| + path = UTF8ToFilePath("file name");
|
| + context->set_allowed_bytes_growth(5);
|
| + EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
|
| + ofsfu()->Touch(
|
| + context.get(), path, last_access_time, last_modified_time));
|
| + context->set_allowed_bytes_growth(1024);
|
| + EXPECT_EQ(base::PLATFORM_FILE_OK,
|
| + ofsfu()->Touch(
|
| + context.get(), path, last_access_time, last_modified_time));
|
| + int64 path_cost = ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path);
|
| + EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth());
|
| +
|
| + context->set_allowed_bytes_growth(1024);
|
| + bool exclusive = true;
|
| + bool recursive = true;
|
| + path = UTF8ToFilePath("directory/to/use");
|
| + std::vector<FilePath::StringType> components;
|
| + path.GetComponents(&components);
|
| + path_cost = 0;
|
| + for (std::vector<FilePath::StringType>::iterator iter = components.begin();
|
| + iter != components.end(); ++iter) {
|
| + path_cost += ObfuscatedFileSystemFileUtil::ComputeFilePathCost(
|
| + FilePath(*iter));
|
| + }
|
| + context.reset(NewContext(NULL));
|
| + context->set_allowed_bytes_growth(1024);
|
| + EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| + context.get(), path, exclusive, recursive));
|
| + EXPECT_EQ(1024 - path_cost, context->allowed_bytes_growth());
|
| +}
|
| +
|
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) {
|
| FilePath source_path = UTF8ToFilePath("path0.txt");
|
| FilePath dest_path = UTF8ToFilePath("path1.txt");
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
|
|
| bool is_copy_not_move = false;
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path,
|
| is_copy_not_move));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| is_copy_not_move = true;
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path,
|
| @@ -735,14 +855,14 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileNotFound) {
|
| source_path = UTF8ToFilePath("dir/dir/file");
|
| bool exclusive = true;
|
| bool recursive = true;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), source_path.DirName(), exclusive, recursive));
|
| is_copy_not_move = false;
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path,
|
| is_copy_not_move));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| is_copy_not_move = true;
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
|
| ofsfu()->CopyOrMoveFile(context.get(), source_path, dest_path,
|
| @@ -764,47 +884,47 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) {
|
| test_case.dest_path);
|
| SCOPED_TRACE(testing::Message() << "\t cause_overwrite " <<
|
| test_case.cause_overwrite);
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
|
|
| bool exclusive = false;
|
| bool recursive = true;
|
| FilePath source_path = UTF8ToFilePath(test_case.source_path);
|
| FilePath dest_path = UTF8ToFilePath(test_case.dest_path);
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), source_path.DirName(), exclusive, recursive));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CreateDirectory(
|
| context.get(), dest_path.DirName(), exclusive, recursive));
|
|
|
| bool created = false;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(context.get(), source_path, &created));
|
| ASSERT_TRUE(created);
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->Truncate(context.get(), source_path, kSourceLength));
|
|
|
| if (test_case.cause_overwrite) {
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| created = false;
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->EnsureFileExists(context.get(), dest_path, &created));
|
| ASSERT_TRUE(created);
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->Truncate(context.get(), dest_path, kDestLength));
|
| }
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->CopyOrMoveFile(context.get(),
|
| source_path, dest_path, test_case.is_copy_not_move));
|
| if (test_case.is_copy_not_move) {
|
| base::PlatformFileInfo file_info;
|
| FilePath local_path;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, ofsfu()->GetFileInfo(
|
| context.get(), source_path, &file_info, &local_path));
|
| EXPECT_EQ(kSourceLength, file_info.size);
|
| @@ -813,7 +933,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyOrMoveFileSuccess) {
|
| } else {
|
| base::PlatformFileInfo file_info;
|
| FilePath local_path;
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, ofsfu()->GetFileInfo(
|
| context.get(), source_path, &file_info, &local_path));
|
| }
|
| @@ -834,7 +954,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestCopyInForeignFile) {
|
| }
|
|
|
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) {
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| FilePath src_path = UTF8ToFilePath("source dir");
|
| bool exclusive = true;
|
| bool recursive = false;
|
| @@ -847,22 +967,22 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) {
|
|
|
| FilePath dest_path = UTF8ToFilePath("destination dir");
|
|
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->Copy(context.get(), src_path, dest_path));
|
|
|
| ValidateTestDirectory(dest_path, files, directories);
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| recursive = true;
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| ofsfu()->Delete(context.get(), dest_path, recursive));
|
| - context.reset(NewContext());
|
| + context.reset(NewContext(NULL));
|
| EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path));
|
| }
|
|
|
| @@ -895,10 +1015,10 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) {
|
| }
|
| }
|
|
|
| - EXPECT_TRUE(ofsfu()->MigrateFromOldSandbox(origin_url(), type(), root_path));
|
| + EXPECT_TRUE(ofsfu()->MigrateFromOldSandbox(origin(), type(), root_path));
|
|
|
| FilePath new_root =
|
| - test_directory().AppendASCII("000").Append(
|
| + test_directory().AppendASCII("File System").AppendASCII("000").Append(
|
| ofsfu()->GetDirectoryNameForType(type())).AppendASCII("Legacy");
|
| for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) {
|
| SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i);
|
| @@ -907,7 +1027,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) {
|
| #if defined(OS_WIN)
|
| local_data_path = local_data_path.NormalizeWindowsPathSeparators();
|
| #endif
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| base::PlatformFileInfo ofsfu_file_info;
|
| FilePath data_path;
|
| SCOPED_TRACE(testing::Message() << "Path is " << test_case.path);
|
| @@ -924,7 +1044,7 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) {
|
| ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info));
|
| EXPECT_EQ(test_case.data_file_size, platform_file_info.size);
|
| EXPECT_FALSE(platform_file_info.is_directory);
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| EXPECT_EQ(local_data_path, data_path);
|
| EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size);
|
| EXPECT_FALSE(ofsfu_file_info.is_directory);
|
| @@ -933,8 +1053,11 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) {
|
| }
|
|
|
| TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) {
|
| + scoped_refptr<ObfuscatedFileSystemFileUtil> file_util =
|
| + new ObfuscatedFileSystemFileUtil(test_directory(),
|
| + new FileSystemFileUtil());
|
| scoped_ptr<ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator>
|
| - enumerator(ofsfu()->CreateOriginEnumerator());
|
| + enumerator(file_util->CreateOriginEnumerator());
|
| EXPECT_TRUE(enumerator.get());
|
| EXPECT_EQ(GURL(), enumerator->Next());
|
| EXPECT_FALSE(enumerator->HasFileSystemType(kFileSystemTypeTemporary));
|
| @@ -950,27 +1073,31 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) {
|
| GURL origin_url(record.origin_url);
|
| origins_expected.insert(origin_url);
|
| if (record.has_temporary) {
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemTestOriginHelper> helper(
|
| + NewHelper(origin_url, kFileSystemTypeTemporary));
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get()));
|
| context->set_src_origin_url(origin_url);
|
| context->set_src_type(kFileSystemTypeTemporary);
|
| bool created = false;
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| - ofsfu()->EnsureFileExists(context.get(),
|
| + file_util->EnsureFileExists(context.get(),
|
| FilePath().AppendASCII("file"), &created));
|
| EXPECT_TRUE(created);
|
| }
|
| if (record.has_persistent) {
|
| - scoped_ptr<FileSystemOperationContext> context(NewContext());
|
| + scoped_ptr<FileSystemTestOriginHelper> helper(
|
| + NewHelper(origin_url, kFileSystemTypePersistent));
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get()));
|
| context->set_src_origin_url(origin_url);
|
| context->set_src_type(kFileSystemTypePersistent);
|
| bool created = false;
|
| ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| - ofsfu()->EnsureFileExists(context.get(),
|
| + file_util->EnsureFileExists(context.get(),
|
| FilePath().AppendASCII("file"), &created));
|
| EXPECT_TRUE(created);
|
| }
|
| }
|
| - enumerator.reset(ofsfu()->CreateOriginEnumerator());
|
| + enumerator.reset(file_util->CreateOriginEnumerator());
|
| EXPECT_TRUE(enumerator.get());
|
| std::set<GURL> origins_found;
|
| GURL origin;
|
| @@ -999,3 +1126,37 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestOriginEnumerator) {
|
| inserter(diff, diff.begin()));
|
| EXPECT_TRUE(diff.empty());
|
| }
|
| +
|
| +TEST_F(ObfuscatedFileSystemFileUtilTest, TestRevokeUsageCache) {
|
| + scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
|
| +
|
| + int64 expected_quota = FileSystemUsageCache::kUsageFileSize;
|
| +
|
| + for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) {
|
| + SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i);
|
| + const MigrationTestCaseRecord& test_case = kMigrationTestCases[i];
|
| + FilePath path(test_case.path);
|
| + expected_quota += ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path);
|
| + if (test_case.is_directory) {
|
| + bool exclusive = true;
|
| + bool recursive = false;
|
| + ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| + ofsfu()->CreateDirectory(context.get(), path, exclusive, recursive));
|
| + } else {
|
| + bool created = false;
|
| + ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| + ofsfu()->EnsureFileExists(context.get(), path, &created));
|
| + ASSERT_TRUE(created);
|
| + ASSERT_EQ(base::PLATFORM_FILE_OK,
|
| + ofsfu()->Truncate(context.get(), path,
|
| + test_case.data_file_size));
|
| + expected_quota += test_case.data_file_size;
|
| + }
|
| + }
|
| + EXPECT_EQ(expected_quota, SizeInUsageFile());
|
| + RevokeUsageCache();
|
| + EXPECT_EQ(-1, SizeInUsageFile());
|
| + GetUsageFromQuotaManager();
|
| + EXPECT_EQ(expected_quota, SizeInUsageFile());
|
| + EXPECT_EQ(expected_quota, usage());
|
| +}
|
|
|