diff options
-rw-r--r-- | content/content_tests.gypi | 4 | ||||
-rw-r--r-- | webkit/browser/fileapi/obfuscated_file_util_unittest.cc | 105 | ||||
-rw-r--r-- | webkit/browser/fileapi/sandbox_mount_point_provider.h | 2 | ||||
-rw-r--r-- | webkit/fileapi/local_file_system_operation_unittest.cc | 46 | ||||
-rw-r--r-- | webkit/fileapi/sandbox_file_system_test_helper.cc (renamed from webkit/fileapi/local_file_system_test_helper.cc) | 87 | ||||
-rw-r--r-- | webkit/fileapi/sandbox_file_system_test_helper.h (renamed from webkit/fileapi/local_file_system_test_helper.h) | 20 | ||||
-rw-r--r-- | webkit/fileapi/syncable/syncable_file_system_unittest.cc | 6 |
7 files changed, 130 insertions, 140 deletions
diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 3bfd2d0..a3e23f3 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -467,10 +467,10 @@ '../webkit/fileapi/local_file_system_cross_operation_unittest.cc', '../webkit/fileapi/local_file_system_operation_unittest.cc', '../webkit/fileapi/local_file_system_operation_write_unittest.cc', - '../webkit/fileapi/local_file_system_test_helper.cc', - '../webkit/fileapi/local_file_system_test_helper.h', '../webkit/fileapi/mock_file_change_observer.cc', '../webkit/fileapi/mock_file_change_observer.h', + '../webkit/fileapi/sandbox_file_system_test_helper.cc', + '../webkit/fileapi/sandbox_file_system_test_helper.h', '../webkit/fileapi/syncable/canned_syncable_file_system.cc', '../webkit/fileapi/syncable/canned_syncable_file_system.h', '../webkit/fileapi/syncable/file_change_unittest.cc', diff --git a/webkit/browser/fileapi/obfuscated_file_util_unittest.cc b/webkit/browser/fileapi/obfuscated_file_util_unittest.cc index 655f8f7..dd06436 100644 --- a/webkit/browser/fileapi/obfuscated_file_util_unittest.cc +++ b/webkit/browser/fileapi/obfuscated_file_util_unittest.cc @@ -22,9 +22,9 @@ #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_task_runners.h" -#include "webkit/fileapi/local_file_system_test_helper.h" #include "webkit/fileapi/mock_file_change_observer.h" #include "webkit/fileapi/mock_file_system_context.h" +#include "webkit/fileapi/sandbox_file_system_test_helper.h" #include "webkit/fileapi/test_file_set.h" #include "webkit/quota/mock_special_storage_policy.h" #include "webkit/quota/quota_manager.h" @@ -121,7 +121,7 @@ class ObfuscatedFileUtilTest : public testing::Test { : origin_(GURL("http://www.example.com")), type_(kFileSystemTypeTemporary), weak_factory_(this), - test_helper_(origin_, type_), + sandbox_file_system_(origin_, type_), quota_status_(quota::kQuotaStatusUnknown), usage_(-1) { } @@ -139,27 +139,28 @@ class ObfuscatedFileUtilTest : public testing::Test { base::MessageLoopProxy::current(), storage_policy); - // Every time we create a new helper, it creates another context, which - // creates another path manager, another sandbox_mount_point_provider, and + // Every time we create a new sandbox_file_system helper, + // it creates another context, which creates another path manager, + // another sandbox_mount_point_provider, and // another OFU. We need to pass in the context to skip all that. file_system_context_ = CreateFileSystemContextForTesting( quota_manager_->proxy(), data_dir_.path()); - test_helper_.SetUp(file_system_context_.get()); + sandbox_file_system_.SetUp(file_system_context_.get()); change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); } virtual void TearDown() { quota_manager_ = NULL; - test_helper_.TearDown(); + sandbox_file_system_.TearDown(); } scoped_ptr<FileSystemOperationContext> LimitedContext( int64 allowed_bytes_growth) { scoped_ptr<FileSystemOperationContext> context( - test_helper_.NewOperationContext()); + sandbox_file_system_.NewOperationContext()); context->set_allowed_bytes_growth(allowed_bytes_growth); return context.Pass(); } @@ -169,13 +170,13 @@ class ObfuscatedFileUtilTest : public testing::Test { } FileSystemOperationContext* NewContext( - LocalFileSystemTestOriginHelper* helper) { + SandboxFileSystemTestHelper* file_system) { change_observer()->ResetCount(); FileSystemOperationContext* context; - if (helper) - context = helper->NewOperationContext(); + if (file_system) + context = file_system->NewOperationContext(); else - context = test_helper_.NewOperationContext(); + context = sandbox_file_system_.NewOperationContext(); // Setting allowed_bytes_growth big enough for all tests. context->set_allowed_bytes_growth(1024 * 1024); context->set_change_observers(change_observers()); @@ -194,17 +195,17 @@ class ObfuscatedFileUtilTest : public testing::Test { // and obfuscated_file_util_. // Use this for tests which need to run in multiple origins; we need a test // helper per origin. - LocalFileSystemTestOriginHelper* NewHelper( + SandboxFileSystemTestHelper* NewFileSystem( const GURL& origin, fileapi::FileSystemType type) { - LocalFileSystemTestOriginHelper* helper = - new LocalFileSystemTestOriginHelper(origin, type); + SandboxFileSystemTestHelper* file_system = + new SandboxFileSystemTestHelper(origin, type); - helper->SetUp(file_system_context_.get()); - return helper; + file_system->SetUp(file_system_context_.get()); + return file_system; } ObfuscatedFileUtil* ofu() { - return static_cast<ObfuscatedFileUtil*>(test_helper_.file_util()); + return static_cast<ObfuscatedFileUtil*>(sandbox_file_system_.file_util()); } const base::FilePath& test_directory() const { @@ -220,32 +221,32 @@ class ObfuscatedFileUtilTest : public testing::Test { } int64 ComputeTotalFileSize() { - return test_helper_.ComputeCurrentOriginUsage() - - test_helper_.ComputeCurrentDirectoryDatabaseUsage(); + return sandbox_file_system_.ComputeCurrentOriginUsage() - + sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); } void GetUsageFromQuotaManager() { int64 quota = -1; quota_status_ = AsyncFileTestHelper::GetUsageAndQuota( - quota_manager_, origin(), test_helper_.type(), + quota_manager_, origin(), sandbox_file_system_.type(), &usage_, "a); EXPECT_EQ(quota::kQuotaStatusOk, quota_status_); } void RevokeUsageCache() { - quota_manager_->ResetUsageTracker(test_helper_.storage_type()); - usage_cache()->Delete(test_helper_.GetUsageCachePath()); + quota_manager_->ResetUsageTracker(sandbox_file_system_.storage_type()); + usage_cache()->Delete(sandbox_file_system_.GetUsageCachePath()); } int64 SizeByQuotaUtil() { - return test_helper_.GetCachedOriginUsage(); + return sandbox_file_system_.GetCachedOriginUsage(); } int64 SizeInUsageFile() { base::MessageLoop::current()->RunUntilIdle(); int64 usage = 0; - return usage_cache()->GetUsage(test_helper_.GetUsageCachePath(), &usage) ? - usage : -1; + return usage_cache()->GetUsage( + sandbox_file_system_.GetUsageCachePath(), &usage) ? usage : -1; } bool PathExists(const FileSystemURL& url) { @@ -263,11 +264,11 @@ class ObfuscatedFileUtilTest : public testing::Test { int64 usage() const { return usage_; } FileSystemUsageCache* usage_cache() { - return test_helper_.usage_cache(); + return sandbox_file_system_.usage_cache(); } FileSystemURL CreateURLFromUTF8(const std::string& path) { - return test_helper_.CreateURLFromUTF8(path); + return sandbox_file_system_.CreateURLFromUTF8(path); } int64 PathCost(const FileSystemURL& url) { @@ -275,7 +276,7 @@ class ObfuscatedFileUtilTest : public testing::Test { } FileSystemURL CreateURL(const base::FilePath& path) { - return test_helper_.CreateURL(path); + return sandbox_file_system_.CreateURL(path); } void CheckFileAndCloseHandle( @@ -362,10 +363,10 @@ class ObfuscatedFileUtilTest : public testing::Test { class UsageVerifyHelper { public: UsageVerifyHelper(scoped_ptr<FileSystemOperationContext> context, - LocalFileSystemTestOriginHelper* test_helper, + SandboxFileSystemTestHelper* file_system, int64 expected_usage) : context_(context.Pass()), - test_helper_(test_helper), + sandbox_file_system_(file_system), expected_usage_(expected_usage) {} ~UsageVerifyHelper() { @@ -380,25 +381,25 @@ class ObfuscatedFileUtilTest : public testing::Test { private: void Check() { ASSERT_EQ(expected_usage_, - test_helper_->GetCachedOriginUsage()); + sandbox_file_system_->GetCachedOriginUsage()); } scoped_ptr<FileSystemOperationContext> context_; - LocalFileSystemTestOriginHelper* test_helper_; + SandboxFileSystemTestHelper* sandbox_file_system_; int64 expected_usage_; }; scoped_ptr<UsageVerifyHelper> AllowUsageIncrease(int64 requested_growth) { - int64 usage = test_helper_.GetCachedOriginUsage(); + int64 usage = sandbox_file_system_.GetCachedOriginUsage(); return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( LimitedContext(requested_growth), - &test_helper_, usage + requested_growth)); + &sandbox_file_system_, usage + requested_growth)); } scoped_ptr<UsageVerifyHelper> DisallowUsageIncrease(int64 requested_growth) { - int64 usage = test_helper_.GetCachedOriginUsage(); + int64 usage = sandbox_file_system_.GetCachedOriginUsage(); return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( - LimitedContext(requested_growth - 1), &test_helper_, usage)); + LimitedContext(requested_growth - 1), &sandbox_file_system_, usage)); } void FillTestDirectory( @@ -641,16 +642,12 @@ class ObfuscatedFileUtilTest : public testing::Test { } int64 ComputeCurrentUsage() { - return test_helper_.ComputeCurrentOriginUsage() - - test_helper_.ComputeCurrentDirectoryDatabaseUsage(); - } - - const LocalFileSystemTestOriginHelper& test_helper() const { - return test_helper_; + return sandbox_file_system_.ComputeCurrentOriginUsage() - + sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); } FileSystemContext* file_system_context() { - return test_helper_.file_system_context(); + return sandbox_file_system_.file_system_context(); } private: @@ -661,7 +658,7 @@ class ObfuscatedFileUtilTest : public testing::Test { GURL origin_; fileapi::FileSystemType type_; base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; - LocalFileSystemTestOriginHelper test_helper_; + SandboxFileSystemTestHelper sandbox_file_system_; quota::QuotaStatusCode quota_status_; int64 usage_; MockFileChangeObserver change_observer_; @@ -1416,7 +1413,7 @@ TEST_F(ObfuscatedFileUtilTest, TestEnumerator) { EXPECT_FALSE(DirectoryExists(dest_url)); ASSERT_EQ(base::PLATFORM_FILE_OK, AsyncFileTestHelper::Copy( - test_helper().file_system_context(), src_url, dest_url)); + file_system_context(), src_url, dest_url)); ValidateTestDirectory(dest_url, files, directories); EXPECT_TRUE(DirectoryExists(src_url)); @@ -1452,26 +1449,28 @@ TEST_F(ObfuscatedFileUtilTest, TestOriginEnumerator) { GURL origin_url(record.origin_url); origins_expected.insert(origin_url); if (record.has_temporary) { - scoped_ptr<LocalFileSystemTestOriginHelper> helper( - NewHelper(origin_url, kFileSystemTypeTemporary)); - scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); + scoped_ptr<SandboxFileSystemTestHelper> file_system( + NewFileSystem(origin_url, kFileSystemTypeTemporary)); + scoped_ptr<FileSystemOperationContext> context( + NewContext(file_system.get())); bool created = false; ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( context.get(), - helper->CreateURLFromUTF8("file"), + file_system->CreateURLFromUTF8("file"), &created)); EXPECT_TRUE(created); } if (record.has_persistent) { - scoped_ptr<LocalFileSystemTestOriginHelper> helper( - NewHelper(origin_url, kFileSystemTypePersistent)); - scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); + scoped_ptr<SandboxFileSystemTestHelper> file_system( + NewFileSystem(origin_url, kFileSystemTypePersistent)); + scoped_ptr<FileSystemOperationContext> context( + NewContext(file_system.get())); bool created = false; ASSERT_EQ(base::PLATFORM_FILE_OK, ofu()->EnsureFileExists( context.get(), - helper->CreateURLFromUTF8("file"), + file_system->CreateURLFromUTF8("file"), &created)); EXPECT_TRUE(created); } diff --git a/webkit/browser/fileapi/sandbox_mount_point_provider.h b/webkit/browser/fileapi/sandbox_mount_point_provider.h index 38d5a1c..faa70ff 100644 --- a/webkit/browser/fileapi/sandbox_mount_point_provider.h +++ b/webkit/browser/fileapi/sandbox_mount_point_provider.h @@ -184,7 +184,7 @@ class WEBKIT_STORAGE_EXPORT SandboxMountPointProvider private: friend class SandboxQuotaObserver; - friend class LocalFileSystemTestOriginHelper; + friend class SandboxFileSystemTestHelper; friend class SandboxMountPointProviderMigrationTest; friend class SandboxMountPointProviderOriginEnumeratorTest; diff --git a/webkit/fileapi/local_file_system_operation_unittest.cc b/webkit/fileapi/local_file_system_operation_unittest.cc index d96d295..8502ae9 100644 --- a/webkit/fileapi/local_file_system_operation_unittest.cc +++ b/webkit/fileapi/local_file_system_operation_unittest.cc @@ -20,8 +20,8 @@ #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_util.h" -#include "webkit/fileapi/local_file_system_test_helper.h" #include "webkit/fileapi/mock_file_change_observer.h" +#include "webkit/fileapi/sandbox_file_system_test_helper.h" #include "webkit/quota/mock_quota_manager.h" #include "webkit/quota/quota_manager.h" @@ -65,7 +65,7 @@ class LocalFileSystemOperationTest quota_manager_proxy_ = new quota::MockQuotaManagerProxy( quota_manager(), base::MessageLoopProxy::current()); - test_helper_.SetUp(base_dir, quota_manager_proxy_.get()); + sandbox_file_system_.SetUp(base_dir, quota_manager_proxy_.get()); } virtual void TearDown() OVERRIDE { @@ -73,11 +73,11 @@ class LocalFileSystemOperationTest quota_manager_proxy()->SimulateQuotaManagerDestroyed(); quota_manager_ = NULL; quota_manager_proxy_ = NULL; - test_helper_.TearDown(); + sandbox_file_system_.TearDown(); } LocalFileSystemOperation* NewOperation() { - LocalFileSystemOperation* operation = test_helper_.NewOperation(); + LocalFileSystemOperation* operation = sandbox_file_system_.NewOperation(); operation->operation_context()->set_change_observers(change_observers()); return operation; } @@ -103,7 +103,7 @@ class LocalFileSystemOperationTest } FileSystemFileUtil* file_util() { - return test_helper_.file_util(); + return sandbox_file_system_.file_util(); } const ChangeObserverList& change_observers() const { @@ -115,36 +115,39 @@ class LocalFileSystemOperationTest } scoped_ptr<FileSystemOperationContext> NewContext() { - FileSystemOperationContext* context = test_helper_.NewOperationContext(); + FileSystemOperationContext* context = + sandbox_file_system_.NewOperationContext(); // Grant enough quota for all test cases. context->set_allowed_bytes_growth(1000000); return make_scoped_ptr(context); } FileSystemURL URLForPath(const std::string& path) const { - return test_helper_.CreateURLFromUTF8(path); + return sandbox_file_system_.CreateURLFromUTF8(path); } base::FilePath PlatformPath(const std::string& path) { - return test_helper_.GetLocalPath(base::FilePath::FromUTF8Unsafe(path)); + return sandbox_file_system_.GetLocalPath( + base::FilePath::FromUTF8Unsafe(path)); } bool FileExists(const std::string& path) { return AsyncFileTestHelper::FileExists( - test_helper_.file_system_context(), URLForPath(path), + sandbox_file_system_.file_system_context(), URLForPath(path), AsyncFileTestHelper::kDontCheckSize); } bool DirectoryExists(const std::string& path) { return AsyncFileTestHelper::DirectoryExists( - test_helper_.file_system_context(), URLForPath(path)); + sandbox_file_system_.file_system_context(), URLForPath(path)); } FileSystemURL CreateFile(const std::string& path) { FileSystemURL url = URLForPath(path); bool created = false; EXPECT_EQ(base::PLATFORM_FILE_OK, - file_util()->EnsureFileExists(NewContext().get(), url, &created)); + file_util()->EnsureFileExists(NewContext().get(), + url, &created)); EXPECT_TRUE(created); return url; } @@ -216,14 +219,16 @@ class LocalFileSystemOperationTest } int64 GetDataSizeOnDisk() { - return test_helper_.ComputeCurrentOriginUsage() - - test_helper_.ComputeCurrentDirectoryDatabaseUsage(); + return sandbox_file_system_.ComputeCurrentOriginUsage() - + sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); } void GetUsageAndQuota(int64* usage, int64* quota) { quota::QuotaStatusCode status = AsyncFileTestHelper::GetUsageAndQuota( - quota_manager_, test_helper_.origin(), test_helper_.type(), + quota_manager_, + sandbox_file_system_.origin(), + sandbox_file_system_.type(), usage, quota); base::MessageLoop::current()->RunUntilIdle(); ASSERT_EQ(quota::kQuotaStatusOk, status); @@ -233,7 +238,8 @@ class LocalFileSystemOperationTest int64 base_usage; GetUsageAndQuota(&base_usage, NULL); - AsyncFileTestHelper::CreateFile(test_helper_.file_system_context(), url); + AsyncFileTestHelper::CreateFile( + sandbox_file_system_.file_system_context(), url); NewOperation()->Remove(url, false /* recursive */, base::Bind(&AssertFileErrorEq, FROM_HERE, base::PLATFORM_FILE_OK)); @@ -248,8 +254,8 @@ class LocalFileSystemOperationTest void GrantQuotaForCurrentUsage() { int64 usage; GetUsageAndQuota(&usage, NULL); - quota_manager()->SetQuota(test_helper_.origin(), - test_helper_.storage_type(), + quota_manager()->SetQuota(sandbox_file_system_.origin(), + sandbox_file_system_.storage_type(), usage); } @@ -262,8 +268,8 @@ class LocalFileSystemOperationTest void AddQuota(int64 quota_delta) { int64 quota; GetUsageAndQuota(NULL, "a); - quota_manager()->SetQuota(test_helper_.origin(), - test_helper_.storage_type(), + quota_manager()->SetQuota(sandbox_file_system_.origin(), + sandbox_file_system_.storage_type(), quota + quota_delta); } @@ -274,7 +280,7 @@ class LocalFileSystemOperationTest // Common temp base for nondestructive uses. base::ScopedTempDir base_; - LocalFileSystemTestOriginHelper test_helper_; + SandboxFileSystemTestHelper sandbox_file_system_; // For post-operation status. int status_; diff --git a/webkit/fileapi/local_file_system_test_helper.cc b/webkit/fileapi/sandbox_file_system_test_helper.cc index aa438d4..e7bb937 100644 --- a/webkit/fileapi/local_file_system_test_helper.cc +++ b/webkit/fileapi/sandbox_file_system_test_helper.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/fileapi/local_file_system_test_helper.h" +#include "webkit/fileapi/sandbox_file_system_test_helper.h" #include "base/file_util.h" #include "base/message_loop.h" @@ -22,72 +22,51 @@ namespace fileapi { -LocalFileSystemTestOriginHelper::LocalFileSystemTestOriginHelper( +SandboxFileSystemTestHelper::SandboxFileSystemTestHelper( const GURL& origin, FileSystemType type) : origin_(origin), type_(type), file_util_(NULL) { } -LocalFileSystemTestOriginHelper::LocalFileSystemTestOriginHelper() +SandboxFileSystemTestHelper::SandboxFileSystemTestHelper() : origin_(GURL("http://foo.com")), type_(kFileSystemTypeTemporary), file_util_(NULL) { } -LocalFileSystemTestOriginHelper::~LocalFileSystemTestOriginHelper() { +SandboxFileSystemTestHelper::~SandboxFileSystemTestHelper() { } -void LocalFileSystemTestOriginHelper::SetUp(const base::FilePath& base_dir) { +void SandboxFileSystemTestHelper::SetUp(const base::FilePath& base_dir) { SetUp(base_dir, NULL); } -void LocalFileSystemTestOriginHelper::SetUp( +void SandboxFileSystemTestHelper::SetUp( FileSystemContext* file_system_context) { file_system_context_ = file_system_context; - SetUpFileUtil(); - - // Prepare the origin's root directory. - file_system_context_->GetMountPointProvider(type_)-> - GetFileSystemRootPathOnFileThread(CreateURL(base::FilePath()), - true /* create */); - - // Initialize the usage cache file. - base::FilePath usage_cache_path = GetUsageCachePath(); - if (!usage_cache_path.empty()) - usage_cache()->UpdateUsage(usage_cache_path, 0); + SetUpFileSystem(); } -void LocalFileSystemTestOriginHelper::SetUp( +void SandboxFileSystemTestHelper::SetUp( const base::FilePath& base_dir, quota::QuotaManagerProxy* quota_manager_proxy) { file_system_context_ = CreateFileSystemContextForTesting( quota_manager_proxy, base_dir); - SetUpFileUtil(); - - // Prepare the origin's root directory. - FileSystemMountPointProvider* mount_point_provider = - file_system_context_->GetMountPointProvider(type_); - mount_point_provider->GetFileSystemRootPathOnFileThread( - CreateURL(base::FilePath()), true /* create */); - - // Initialize the usage cache file. - base::FilePath usage_cache_path = GetUsageCachePath(); - if (!usage_cache_path.empty()) - usage_cache()->UpdateUsage(usage_cache_path, 0); + SetUpFileSystem(); } -void LocalFileSystemTestOriginHelper::TearDown() { +void SandboxFileSystemTestHelper::TearDown() { file_system_context_ = NULL; base::MessageLoop::current()->RunUntilIdle(); } -base::FilePath LocalFileSystemTestOriginHelper::GetOriginRootPath() const { - return file_system_context_->GetMountPointProvider(type_)-> - GetFileSystemRootPathOnFileThread(CreateURL(base::FilePath()), false); +base::FilePath SandboxFileSystemTestHelper::GetOriginRootPath() const { + return file_system_context_->sandbox_provider()-> + GetBaseDirectoryForOriginAndType(origin_, type_, false); } -base::FilePath LocalFileSystemTestOriginHelper::GetLocalPath( +base::FilePath SandboxFileSystemTestHelper::GetLocalPath( const base::FilePath& path) { DCHECK(file_util_); base::FilePath local_path; @@ -96,31 +75,27 @@ base::FilePath LocalFileSystemTestOriginHelper::GetLocalPath( return local_path; } -base::FilePath LocalFileSystemTestOriginHelper::GetLocalPathFromASCII( +base::FilePath SandboxFileSystemTestHelper::GetLocalPathFromASCII( const std::string& path) { return GetLocalPath(base::FilePath().AppendASCII(path)); } -base::FilePath LocalFileSystemTestOriginHelper::GetUsageCachePath() const { - if (type_ != kFileSystemTypeTemporary && - type_ != kFileSystemTypePersistent && - type_ != kFileSystemTypeSyncable) - return base::FilePath(); +base::FilePath SandboxFileSystemTestHelper::GetUsageCachePath() const { return file_system_context_-> sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); } -FileSystemURL LocalFileSystemTestOriginHelper::CreateURL( +FileSystemURL SandboxFileSystemTestHelper::CreateURL( const base::FilePath& path) const { return file_system_context_->CreateCrackedFileSystemURL(origin_, type_, path); } -int64 LocalFileSystemTestOriginHelper::GetCachedOriginUsage() const { +int64 SandboxFileSystemTestHelper::GetCachedOriginUsage() const { return file_system_context_->GetQuotaUtil(type_)->GetOriginUsageOnFileThread( file_system_context_, origin_, type_); } -int64 LocalFileSystemTestOriginHelper::ComputeCurrentOriginUsage() { +int64 SandboxFileSystemTestHelper::ComputeCurrentOriginUsage() { usage_cache()->CloseCacheFiles(); int64 size = file_util::ComputeDirectorySize(GetOriginRootPath()); if (file_util::PathExists(GetUsageCachePath())) @@ -129,16 +104,14 @@ int64 LocalFileSystemTestOriginHelper::ComputeCurrentOriginUsage() { } int64 -LocalFileSystemTestOriginHelper::ComputeCurrentDirectoryDatabaseUsage() const { +SandboxFileSystemTestHelper::ComputeCurrentDirectoryDatabaseUsage() const { return file_util::ComputeDirectorySize( GetOriginRootPath().AppendASCII("Paths")); } -LocalFileSystemOperation* LocalFileSystemTestOriginHelper::NewOperation() { +LocalFileSystemOperation* SandboxFileSystemTestHelper::NewOperation() { DCHECK(file_system_context_.get()); DCHECK(file_util_); - scoped_ptr<FileSystemOperationContext> operation_context( - NewOperationContext()); LocalFileSystemOperation* operation = static_cast<LocalFileSystemOperation*>( file_system_context_->CreateFileSystemOperation( CreateURL(base::FilePath()), NULL)); @@ -146,7 +119,7 @@ LocalFileSystemOperation* LocalFileSystemTestOriginHelper::NewOperation() { } FileSystemOperationContext* -LocalFileSystemTestOriginHelper::NewOperationContext() { +SandboxFileSystemTestHelper::NewOperationContext() { DCHECK(file_system_context_.get()); FileSystemOperationContext* context = new FileSystemOperationContext(file_system_context_.get()); @@ -155,14 +128,26 @@ LocalFileSystemTestOriginHelper::NewOperationContext() { return context; } -FileSystemUsageCache* LocalFileSystemTestOriginHelper::usage_cache() { +FileSystemUsageCache* SandboxFileSystemTestHelper::usage_cache() { return file_system_context()->sandbox_provider()->usage_cache(); } -void LocalFileSystemTestOriginHelper::SetUpFileUtil() { +void SandboxFileSystemTestHelper::SetUpFileSystem() { DCHECK(file_system_context_); + DCHECK(file_system_context_->sandbox_provider()->CanHandleType(type_)); + file_util_ = file_system_context_->GetFileUtil(type_); DCHECK(file_util_); + + // Prepare the origin's root directory. + file_system_context_->sandbox_provider()-> + GetFileSystemRootPathOnFileThread(CreateURL(base::FilePath()), + true /* create */); + + // Initialize the usage cache file. + base::FilePath usage_cache_path = GetUsageCachePath(); + if (!usage_cache_path.empty()) + usage_cache()->UpdateUsage(usage_cache_path, 0); } } // namespace fileapi diff --git a/webkit/fileapi/local_file_system_test_helper.h b/webkit/fileapi/sandbox_file_system_test_helper.h index 8e8af13..15f9281 100644 --- a/webkit/fileapi/local_file_system_test_helper.h +++ b/webkit/fileapi/sandbox_file_system_test_helper.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_TEST_HELPER_H_ -#define WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_TEST_HELPER_H_ +#ifndef WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_ +#define WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_ #include <string> @@ -33,15 +33,15 @@ class LocalFileSystemOperation; // Filesystem test helper class that encapsulates test environment for // a given {origin, type} pair. This helper only works for sandboxed -// file systems (Temporary, Persistent or Test types). -class LocalFileSystemTestOriginHelper { +// file systems (Temporary or Persistent). +class SandboxFileSystemTestHelper { public: - LocalFileSystemTestOriginHelper(const GURL& origin, FileSystemType type); - LocalFileSystemTestOriginHelper(); - ~LocalFileSystemTestOriginHelper(); + SandboxFileSystemTestHelper(const GURL& origin, FileSystemType type); + SandboxFileSystemTestHelper(); + ~SandboxFileSystemTestHelper(); void SetUp(const base::FilePath& base_dir); - // If you want to use more than one LocalFileSystemTestOriginHelper in + // If you want to use more than one SandboxFileSystemTestHelper in // a single base directory, they have to share a context, so that they don't // have multiple databases fighting over the lock to the origin directory // [deep down inside ObfuscatedFileUtil]. @@ -86,7 +86,7 @@ class LocalFileSystemTestOriginHelper { FileSystemUsageCache* usage_cache(); private: - void SetUpFileUtil(); + void SetUpFileSystem(); scoped_refptr<FileSystemContext> file_system_context_; @@ -97,4 +97,4 @@ class LocalFileSystemTestOriginHelper { } // namespace fileapi -#endif // WEBKIT_FILEAPI_LOCAL_FILE_SYSTEM_TEST_HELPER_H_ +#endif // WEBKIT_FILEAPI_SANDBOX_FILE_SYSTEM_TEST_HELPER_H_ diff --git a/webkit/fileapi/syncable/syncable_file_system_unittest.cc b/webkit/fileapi/syncable/syncable_file_system_unittest.cc index 88b4e6e..74c98cb 100644 --- a/webkit/fileapi/syncable/syncable_file_system_unittest.cc +++ b/webkit/fileapi/syncable/syncable_file_system_unittest.cc @@ -11,7 +11,7 @@ #include "webkit/fileapi/file_system_types.h" #include "webkit/fileapi/isolated_context.h" #include "webkit/fileapi/local_file_system_operation.h" -#include "webkit/fileapi/local_file_system_test_helper.h" +#include "webkit/fileapi/sandbox_file_system_test_helper.h" #include "webkit/fileapi/syncable/canned_syncable_file_system.h" #include "webkit/fileapi/syncable/local_file_change_tracker.h" #include "webkit/fileapi/syncable/local_file_sync_context.h" @@ -24,7 +24,7 @@ using fileapi::FileSystemContext; using fileapi::FileSystemOperationContext; using fileapi::FileSystemURL; using fileapi::FileSystemURLSet; -using fileapi::LocalFileSystemTestOriginHelper; +using fileapi::SandboxFileSystemTestHelper; using quota::QuotaManager; using quota::QuotaStatusCode; @@ -248,7 +248,7 @@ TEST_F(SyncableFileSystemTest, DisableDirectoryOperations) { file_system_.CreateDirectory(URL("dir"))); // Set up another (non-syncable) local file system. - LocalFileSystemTestOriginHelper other_file_system_( + SandboxFileSystemTestHelper other_file_system_( GURL("http://foo.com/"), fileapi::kFileSystemTypeTemporary); other_file_system_.SetUp(file_system_.file_system_context()); |