diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-14 16:04:26 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-14 16:04:26 +0000 |
commit | 022d2702545fca4ee78f999c9119c65288fb93dd (patch) | |
tree | e211b4ed6bea55aa505c4776b52ca5aef2c54f98 /webkit/fileapi | |
parent | 3fec83dd87b54f18feb29759a4915948200fa84e (diff) | |
download | chromium_src-022d2702545fca4ee78f999c9119c65288fb93dd.zip chromium_src-022d2702545fca4ee78f999c9119c65288fb93dd.tar.gz chromium_src-022d2702545fca4ee78f999c9119c65288fb93dd.tar.bz2 |
Convert some FileWriter tests to use TestMountPointProvider.
BUG=none
TEST=unit_tests:FileSystemOperationWriteTest, unit_tests:FileWriterDelegateTest
Review URL: https://chromiumcodereview.appspot.com/10388112
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136879 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r-- | webkit/fileapi/file_system_operation_write_unittest.cc | 29 | ||||
-rw-r--r-- | webkit/fileapi/file_system_quota_unittest.cc | 24 | ||||
-rw-r--r-- | webkit/fileapi/file_system_test_helper.cc | 37 | ||||
-rw-r--r-- | webkit/fileapi/file_system_test_helper.h | 4 | ||||
-rw-r--r-- | webkit/fileapi/file_writer_delegate_unittest.cc | 1 | ||||
-rw-r--r-- | webkit/fileapi/obfuscated_file_util_unittest.cc | 17 | ||||
-rw-r--r-- | webkit/fileapi/test_mount_point_provider.cc | 7 |
7 files changed, 63 insertions, 56 deletions
diff --git a/webkit/fileapi/file_system_operation_write_unittest.cc b/webkit/fileapi/file_system_operation_write_unittest.cc index 47ade43..2b3fec8 100644 --- a/webkit/fileapi/file_system_operation_write_unittest.cc +++ b/webkit/fileapi/file_system_operation_write_unittest.cc @@ -76,7 +76,8 @@ class FileSystemOperationWriteTest public base::SupportsWeakPtr<FileSystemOperationWriteTest> { public: FileSystemOperationWriteTest() - : loop_(MessageLoop::TYPE_IO), + : test_helper_(GURL("http://example.com"), kFileSystemTypeTest), + loop_(MessageLoop::TYPE_IO), status_(base::PLATFORM_FILE_OK), cancel_status_(base::PLATFORM_FILE_ERROR_FAILED), bytes_written_(0), @@ -140,8 +141,6 @@ class FileSystemOperationWriteTest MessageLoop loop_; ScopedTempDir dir_; - FilePath filesystem_dir_; - FilePath file_; FilePath virtual_path_; // For post-operation status. @@ -192,13 +191,10 @@ void FileSystemOperationWriteTest::SetUp() { false /* unlimited quota */, quota_manager_->proxy(), NULL); - filesystem_dir_ = test_helper_.GetOriginRootPath(); - - ASSERT_TRUE(file_util::CreateTemporaryFileInDir(filesystem_dir_, &file_)); - virtual_path_ = file_.BaseName(); + virtual_path_ = FilePath(FILE_PATH_LITERAL("temporary file")); operation()->CreateFile( - URLForPath(virtual_path_), true, + URLForPath(virtual_path_), true /* exclusive */, base::Bind(&AssertStatusEq, base::PLATFORM_FILE_OK)); net::URLRequest::Deprecated::RegisterProtocolFactory( @@ -289,14 +285,9 @@ TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) { } TEST_F(FileSystemOperationWriteTest, TestWriteDir) { - FilePath subdir; - ASSERT_TRUE(file_util::CreateTemporaryDirInDir(filesystem_dir_, - FILE_PATH_LITERAL("d"), - &subdir)); - FilePath virtual_subdir_path = subdir.BaseName(); - + FilePath virtual_dir_path(FILE_PATH_LITERAL("d")); operation()->CreateDirectory( - URLForPath(virtual_subdir_path), + URLForPath(virtual_dir_path), true /* exclusive */, false /* recursive */, base::Bind(&AssertStatusEq, base::PLATFORM_FILE_OK)); @@ -308,14 +299,18 @@ TEST_F(FileSystemOperationWriteTest, TestWriteDir) { url_request_context.blob_storage_controller()->AddFinishedBlob( blob_url, blob_data); - operation()->Write(&url_request_context, URLForPath(virtual_subdir_path), + operation()->Write(&url_request_context, URLForPath(virtual_dir_path), blob_url, 0, RecordWriteCallback()); MessageLoop::current()->Run(); url_request_context.blob_storage_controller()->RemoveBlob(blob_url); EXPECT_EQ(0, bytes_written()); - EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); + // TODO(kinuko): This error code is platform- or fileutil- dependent + // right now. Make it return PLATFORM_FILE_ERROR_NOT_A_FILE in every case. + EXPECT_TRUE(status() == base::PLATFORM_FILE_ERROR_NOT_A_FILE || + status() == base::PLATFORM_FILE_ERROR_ACCESS_DENIED || + status() == base::PLATFORM_FILE_ERROR_FAILED); EXPECT_TRUE(complete()); } diff --git a/webkit/fileapi/file_system_quota_unittest.cc b/webkit/fileapi/file_system_quota_unittest.cc index 02c6d44..4b33ae4 100644 --- a/webkit/fileapi/file_system_quota_unittest.cc +++ b/webkit/fileapi/file_system_quota_unittest.cc @@ -86,7 +86,7 @@ class FileSystemQuotaTest test_helper_.ComputeCurrentDirectoryDatabaseUsage(); } - int64 SizeInUsageFile() { + int64 SizeByQuotaUtil() { return test_helper_.GetCachedOriginUsage(); } @@ -212,26 +212,26 @@ void FileSystemQuotaTest::OnGetUsageAndQuota( } void FileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) { - int64 usage = SizeInUsageFile(); + int64 usage = SizeByQuotaUtil(); child_dir_path_ = CreateUniqueDirInDir(virtual_path); child_file1_path_ = CreateUniqueFileInDir(virtual_path); child_file2_path_ = CreateUniqueFileInDir(virtual_path); - child_path_cost_ = SizeInUsageFile() - usage; + child_path_cost_ = SizeByQuotaUtil() - usage; usage += child_path_cost_; grandchild_file1_path_ = CreateUniqueFileInDir(child_dir_path_); grandchild_file2_path_ = CreateUniqueFileInDir(child_dir_path_); - grandchild_path_cost_ = SizeInUsageFile() - usage; + grandchild_path_cost_ = SizeByQuotaUtil() - usage; } TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { FilePath src_dir_path(CreateUniqueDir()); - int src_path_cost = SizeInUsageFile(); + int src_path_cost = SizeByQuotaUtil(); PrepareFileSet(src_dir_path); FilePath dest_dir_path(CreateUniqueDir()); EXPECT_EQ(0, ActualFileSize()); - int total_path_cost = SizeInUsageFile(); + int total_path_cost = SizeByQuotaUtil(); operation()->Truncate(URLForPath(child_file1_path_), 5000, base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); @@ -246,7 +246,7 @@ TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { const int64 all_file_size = 5000 + 400 + 30 + 2; EXPECT_EQ(all_file_size, ActualFileSize()); - EXPECT_EQ(all_file_size + total_path_cost, SizeInUsageFile()); + EXPECT_EQ(all_file_size + total_path_cost, SizeByQuotaUtil()); GetUsageAndQuotaFromQuotaManager(); EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); EXPECT_EQ(all_file_size + total_path_cost, usage()); @@ -265,7 +265,7 @@ TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { EXPECT_EQ(all_file_size, ActualFileSize()); EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, - SizeInUsageFile()); + SizeByQuotaUtil()); GetUsageAndQuotaFromQuotaManager(); EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, usage()); @@ -279,7 +279,7 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { FilePath dest_dir2_path(CreateUniqueDir()); EXPECT_EQ(0, ActualFileSize()); - int total_path_cost = SizeInUsageFile(); + int total_path_cost = SizeByQuotaUtil(); operation()->Truncate(URLForPath(child_file1_path_), 8000, base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); @@ -297,7 +297,7 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { int64 expected_usage = all_file_size + total_path_cost; EXPECT_EQ(all_file_size, ActualFileSize()); - EXPECT_EQ(expected_usage, SizeInUsageFile()); + EXPECT_EQ(expected_usage, SizeByQuotaUtil()); GetUsageAndQuotaFromQuotaManager(); EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); EXPECT_EQ(expected_usage, usage()); @@ -323,7 +323,7 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { VirtualPath::BaseName(grandchild_file1_path_)))); EXPECT_EQ(2 * all_file_size, ActualFileSize()); - EXPECT_EQ(expected_usage, SizeInUsageFile()); + EXPECT_EQ(expected_usage, SizeByQuotaUtil()); GetUsageAndQuotaFromQuotaManager(); EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); EXPECT_EQ(expected_usage, usage()); @@ -337,7 +337,7 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { expected_usage += grandchild_file_size + grandchild_path_cost_; EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualFileSize()); - EXPECT_EQ(expected_usage, SizeInUsageFile()); + EXPECT_EQ(expected_usage, SizeByQuotaUtil()); GetUsageAndQuotaFromQuotaManager(); EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); EXPECT_EQ(expected_usage, usage()); diff --git a/webkit/fileapi/file_system_test_helper.cc b/webkit/fileapi/file_system_test_helper.cc index 554b035..e8743e4 100644 --- a/webkit/fileapi/file_system_test_helper.cc +++ b/webkit/fileapi/file_system_test_helper.cc @@ -16,6 +16,7 @@ #include "webkit/fileapi/file_util_helper.h" #include "webkit/fileapi/mock_file_system_options.h" #include "webkit/fileapi/sandbox_mount_point_provider.h" +#include "webkit/fileapi/test_mount_point_provider.h" #include "webkit/quota/mock_special_storage_policy.h" namespace fileapi { @@ -41,12 +42,10 @@ void FileSystemTestOriginHelper::SetUp( void FileSystemTestOriginHelper::SetUp( FileSystemContext* file_system_context, FileSystemFileUtil* file_util) { - DCHECK(file_system_context->sandbox_provider()); - file_util_ = file_util; file_system_context_ = file_system_context; if (!file_util_) - file_util_ = file_system_context->sandbox_provider()->GetFileUtil(); + file_util_ = file_system_context->GetFileUtil(type_); DCHECK(file_util_); // Prepare the origin's root directory. @@ -55,9 +54,9 @@ void FileSystemTestOriginHelper::SetUp( origin_, type_, FilePath(), true /* create */); // Initialize the usage cache file. - FilePath usage_cache_path = file_system_context_-> - sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); - FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); + FilePath usage_cache_path = GetUsageCachePath(); + if (!usage_cache_path.empty()) + FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); } void FileSystemTestOriginHelper::SetUp( @@ -76,7 +75,12 @@ void FileSystemTestOriginHelper::SetUp( base_dir, CreateAllowFileAccessOptions()); - DCHECK(file_system_context_->sandbox_provider()); + if (type_ == kFileSystemTypeTest) { + file_system_context_->RegisterMountPointProvider( + type_, + new TestMountPointProvider(file_system_context_->file_task_runner(), + base_dir)); + } // Prepare the origin's root directory. FileSystemMountPointProvider* mount_point_provider = @@ -91,11 +95,10 @@ void FileSystemTestOriginHelper::SetUp( DCHECK(file_util_); - // Initialize the usage cache file. This code assumes that we're either using - // OFSFU or we've mocked it out in the sandbox provider. - FilePath usage_cache_path = file_system_context_-> - sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); - FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); + // Initialize the usage cache file. + FilePath usage_cache_path = GetUsageCachePath(); + if (!usage_cache_path.empty()) + FileSystemUsageCache::UpdateUsage(usage_cache_path, 0); } void FileSystemTestOriginHelper::TearDown() { @@ -128,6 +131,9 @@ GURL FileSystemTestOriginHelper::GetURLForPath(const FilePath& path) const { } FilePath FileSystemTestOriginHelper::GetUsageCachePath() const { + if (type_ != kFileSystemTypeTemporary && + type_ != kFileSystemTypePersistent) + return FilePath(); return file_system_context_-> sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_); } @@ -152,11 +158,8 @@ base::PlatformFileError FileSystemTestOriginHelper::SameFileUtilMove( } int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const { - return FileSystemUsageCache::GetUsage(GetUsageCachePath()); -} - -bool FileSystemTestOriginHelper::RevokeUsageCache() const { - return file_util::Delete(GetUsageCachePath(), false); + return file_system_context_->GetQuotaUtil(type_)->GetOriginUsageOnFileThread( + origin_, type_); } int64 FileSystemTestOriginHelper::ComputeCurrentOriginUsage() const { diff --git a/webkit/fileapi/file_system_test_helper.h b/webkit/fileapi/file_system_test_helper.h index 4ebfb8e..9aab095 100644 --- a/webkit/fileapi/file_system_test_helper.h +++ b/webkit/fileapi/file_system_test_helper.h @@ -55,6 +55,8 @@ class FileSystemTestOriginHelper { FilePath GetLocalPath(const FilePath& path); FilePath GetLocalPathFromASCII(const std::string& path); GURL GetURLForPath(const FilePath& path) const; + + // Returns empty path if filesystem type is neither temporary nor persistent. FilePath GetUsageCachePath() const; // Creates a new FileSystemPath for the given |path|. @@ -73,8 +75,8 @@ class FileSystemTestOriginHelper { const FileSystemPath& src, const FileSystemPath& dest) const; + // This returns cached usage size returned by QuotaUtil. int64 GetCachedOriginUsage() const; - bool RevokeUsageCache() const; // This doesn't work with OFSFU. int64 ComputeCurrentOriginUsage() const; diff --git a/webkit/fileapi/file_writer_delegate_unittest.cc b/webkit/fileapi/file_writer_delegate_unittest.cc index ee4f1d7..1ce152e 100644 --- a/webkit/fileapi/file_writer_delegate_unittest.cc +++ b/webkit/fileapi/file_writer_delegate_unittest.cc @@ -81,6 +81,7 @@ class FileWriterDelegateTest : public PlatformTest { public: FileWriterDelegateTest() : loop_(MessageLoop::TYPE_IO), + test_helper_(GURL("http://example.com"), kFileSystemTypeTest), file_(base::kInvalidPlatformFileValue) {} protected: diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc index beb0f19..96d6759 100644 --- a/webkit/fileapi/obfuscated_file_util_unittest.cc +++ b/webkit/fileapi/obfuscated_file_util_unittest.cc @@ -208,13 +208,17 @@ class ObfuscatedFileUtilTest : public testing::Test { void RevokeUsageCache() { quota_manager_->ResetUsageTracker(test_helper_.storage_type()); - ASSERT_TRUE(test_helper_.RevokeUsageCache()); + file_util::Delete(test_helper_.GetUsageCachePath(), false); } - int64 SizeInUsageFile() { + int64 SizeByQuotaUtil() { return test_helper_.GetCachedOriginUsage(); } + int64 SizeInUsageFile() { + return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath()); + } + int64 usage() const { return usage_; } FileSystemPath CreatePathFromUTF8(const std::string& path) { @@ -1487,11 +1491,20 @@ TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) { expected_quota += test_case.data_file_size; } } + + // Usually raw size in usage cache and the usage returned by QuotaUtil + // should be same. EXPECT_EQ(expected_quota, SizeInUsageFile()); + EXPECT_EQ(expected_quota, SizeByQuotaUtil()); + RevokeUsageCache(); EXPECT_EQ(-1, SizeInUsageFile()); + EXPECT_EQ(expected_quota, SizeByQuotaUtil()); + + // This should reconstruct the cache. GetUsageFromQuotaManager(); EXPECT_EQ(expected_quota, SizeInUsageFile()); + EXPECT_EQ(expected_quota, SizeByQuotaUtil()); EXPECT_EQ(expected_quota, usage()); } diff --git a/webkit/fileapi/test_mount_point_provider.cc b/webkit/fileapi/test_mount_point_provider.cc index cf0aa4f..d91c8298 100644 --- a/webkit/fileapi/test_mount_point_provider.cc +++ b/webkit/fileapi/test_mount_point_provider.cc @@ -57,13 +57,6 @@ class TestFileSystemQuotaUtil : public FileSystemQuotaUtil { FileSystemType type, int64 delta) OVERRIDE { usage_ += delta; - if (proxy) { - proxy->NotifyStorageModified( - quota::QuotaClient::kFileSystem, - origin_url, - FileSystemTypeToQuotaStorageType(type), - delta); - } } virtual void StartUpdateOriginOnFileThread( const GURL& origin_url, |