summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-19 08:16:44 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-19 08:16:44 +0000
commit77316bf4ca50af47606d419a5f8225d4b613cd5f (patch)
tree5df9ad2c2b544095b8cb41f682a4e1b7ab593203 /webkit
parenta61c14731bde26e65edb4aa6c7552c7c612e52d2 (diff)
downloadchromium_src-77316bf4ca50af47606d419a5f8225d4b613cd5f.zip
chromium_src-77316bf4ca50af47606d419a5f8225d4b613cd5f.tar.gz
chromium_src-77316bf4ca50af47606d419a5f8225d4b613cd5f.tar.bz2
Change usage cache code in QuotaFileUtil to use QuotaUtil methods
*** This patch is necessary not only for refactoring but to notify changes from FS to QM (call notifyStorageModified()) upon modifications. *** - replaced usage cache code in QuotaFileUtilTest with QuotaUtil code - this change required some other FileSystem tests to use correct sandbox path, so touched the FileSystem test code (namely LocalFileSystemFileUtilTest, FileSystemOperationTest and FileSystemOperationWriteTest) too. - factored out some common code into a helper class (FileSystemTestOriginHelper) as I needed to make the same change again and again BUG=61676 TEST=QuotaFileUtilTest.*, LocalFileSystemFileUtilTest.*, FileSystemOperationTest.*, FileSystemOperationWriteTest.*, FileWriterDelegateTest.* Review URL: http://codereview.chromium.org/6975016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85884 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/fileapi/file_system_operation.h1
-rw-r--r--webkit/fileapi/file_system_operation_unittest.cc169
-rw-r--r--webkit/fileapi/file_system_operation_write_unittest.cc73
-rw-r--r--webkit/fileapi/file_system_test_helper.cc163
-rw-r--r--webkit/fileapi/file_system_test_helper.h77
-rw-r--r--webkit/fileapi/file_writer_delegate_unittest.cc51
-rw-r--r--webkit/fileapi/local_file_system_file_util_unittest.cc73
-rw-r--r--webkit/fileapi/quota_file_util.cc107
-rw-r--r--webkit/fileapi/quota_file_util_unittest.cc56
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.h2
-rw-r--r--webkit/tools/test_shell/test_shell.gypi2
11 files changed, 450 insertions, 324 deletions
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index 3d5c2ea..6442d50 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -104,6 +104,7 @@ class FileSystemOperation {
friend class FileSystemOperationTest;
friend class FileSystemOperationWriteTest;
friend class FileWriterDelegateTest;
+ friend class FileSystemTestOriginHelper;
bool GetUsageAndQuotaThenCallback(
const GURL& origin_url,
diff --git a/webkit/fileapi/file_system_operation_unittest.cc b/webkit/fileapi/file_system_operation_unittest.cc
index c27be53..1da94c3 100644
--- a/webkit/fileapi/file_system_operation_unittest.cc
+++ b/webkit/fileapi/file_system_operation_unittest.cc
@@ -17,28 +17,28 @@
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_operation.h"
-#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/local_file_system_file_util.h"
#include "webkit/fileapi/quota_file_util.h"
+#include "webkit/fileapi/file_system_test_helper.h"
#include "webkit/quota/quota_manager.h"
+using quota::QuotaManager;
+
namespace fileapi {
const int kFileOperationStatusNotSet = 1;
-const int kFileOperationSucceeded = 0;
namespace {
-class MockQuotaManager : public quota::QuotaManager {
+class MockQuotaManager : public QuotaManager {
public:
- MockQuotaManager(int64 usage, int64 quota)
- : quota::QuotaManager(false /* is_incognito */,
- FilePath(),
- base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread()),
- usage_(usage),
- quota_(quota) {}
+ MockQuotaManager(const FilePath& base_dir)
+ : QuotaManager(false /* is_incognito */, base_dir,
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ base::MessageLoopProxy::CreateForCurrentThread()),
+ usage_(0),
+ quota_(QuotaFileUtil::kNoLimit) {}
virtual void GetUsageAndQuota(const GURL& origin, quota::StorageType type,
GetUsageAndQuotaCallback* callback) {
@@ -67,11 +67,7 @@ FilePath UTF8ToFilePath(const std::string& str) {
} // namespace (anonymous)
// Test class for FileSystemOperation. Note that this just tests low-level
-// operations but doesn't test OpenFileSystem or any additional checks
-// that require FileSystemContext (e.g. sandboxed paths, unlimited_storage
-// quota handling etc).
-// See SimpleFileSystem for more complete test environment for sandboxed
-// FileSystem.
+// operations but doesn't test OpenFileSystem.
class FileSystemOperationTest : public testing::Test {
public:
FileSystemOperationTest()
@@ -108,39 +104,37 @@ class FileSystemOperationTest : public testing::Test {
}
GURL URLForPath(const FilePath& path) const {
- // Only the path will actually get used.
- return GURL(GetFileSystemRootURI(GURL("http://www.example.com/"),
- kFileSystemTypeTemporary).spec() + path.MaybeAsASCII());
+ return test_helper_.GetURLForPath(path);
}
FilePath PlatformPath(FilePath virtual_path) {
- return filesystem_dir_.Append(virtual_path);
+ return test_helper_.GetLocalPath(virtual_path);
}
bool VirtualFileExists(FilePath virtual_path) {
- return file_util::PathExists(filesystem_dir_.Append(virtual_path)) &&
- !file_util::DirectoryExists(filesystem_dir_.Append(virtual_path));
+ return file_util::PathExists(PlatformPath(virtual_path)) &&
+ !file_util::DirectoryExists(PlatformPath(virtual_path));
}
bool VirtualDirectoryExists(FilePath virtual_path) {
- return file_util::DirectoryExists(filesystem_dir_.Append(virtual_path));
+ return file_util::DirectoryExists(PlatformPath(virtual_path));
}
FilePath CreateVirtualDirectory(const char* virtual_path_string) {
FilePath virtual_path(UTF8ToFilePath(virtual_path_string));
- file_util::CreateDirectory(filesystem_dir_.Append(virtual_path));
+ file_util::CreateDirectory(PlatformPath(virtual_path));
return virtual_path;
}
FilePath CreateVirtualDirectoryInDir(const char* virtual_path_string,
const FilePath& virtual_dir_path) {
FilePath virtual_path(virtual_dir_path.AppendASCII(virtual_path_string));
- file_util::CreateDirectory(filesystem_dir_.Append(virtual_path));
+ file_util::CreateDirectory(PlatformPath(virtual_path));
return virtual_path;
}
FilePath CreateVirtualTemporaryFileInDir(const FilePath& virtual_dir_path) {
- FilePath absolute_dir_path(filesystem_dir_.Append(virtual_dir_path));
+ FilePath absolute_dir_path(PlatformPath(virtual_dir_path));
FilePath absolute_file_path;
if (file_util::CreateTemporaryFileInDir(absolute_dir_path,
&absolute_file_path))
@@ -150,7 +144,7 @@ class FileSystemOperationTest : public testing::Test {
}
FilePath CreateVirtualTemporaryDirInDir(const FilePath& virtual_dir_path) {
- FilePath absolute_parent_dir_path(filesystem_dir_.Append(virtual_dir_path));
+ FilePath absolute_parent_dir_path(PlatformPath(virtual_dir_path));
FilePath absolute_child_dir_path;
if (file_util::CreateTemporaryDirInDir(absolute_parent_dir_path,
FILE_PATH_LITERAL(""),
@@ -164,18 +158,18 @@ class FileSystemOperationTest : public testing::Test {
return CreateVirtualTemporaryDirInDir(FilePath());
}
+ FileSystemTestOriginHelper test_helper_;
+
// For post-operation status.
int status_;
base::PlatformFileInfo info_;
FilePath path_;
FilePath local_path_;
- FilePath filesystem_dir_;
std::vector<base::FileUtilProxy::Entry> entries_;
+ private:
+ scoped_refptr<QuotaManager> quota_manager_;
DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest);
-
-private:
- scoped_refptr<quota::QuotaManager> quota_manager_;
};
namespace {
@@ -189,12 +183,12 @@ class MockDispatcher : public FileSystemCallbackDispatcher {
}
virtual void DidSucceed() {
- test_->set_status(kFileOperationSucceeded);
+ test_->set_status(base::PLATFORM_FILE_OK);
}
virtual void DidGetLocalPath(const FilePath& local_path) {
test_->set_local_path(local_path);
- test_->set_status(kFileOperationSucceeded);
+ test_->set_status(base::PLATFORM_FILE_OK);
}
virtual void DidReadMetadata(
@@ -202,7 +196,7 @@ class MockDispatcher : public FileSystemCallbackDispatcher {
const FilePath& platform_path) {
test_->set_info(info);
test_->set_path(platform_path);
- test_->set_status(kFileOperationSucceeded);
+ test_->set_status(base::PLATFORM_FILE_OK);
}
virtual void DidReadDirectory(
@@ -223,58 +217,25 @@ class MockDispatcher : public FileSystemCallbackDispatcher {
FileSystemOperationTest* test_;
};
-class MockFileSystemPathManager : public FileSystemPathManager {
- public:
- MockFileSystemPathManager(const FilePath& filesystem_path)
- : FileSystemPathManager(base::MessageLoopProxy::CreateForCurrentThread(),
- filesystem_path, NULL, false, true),
- test_filesystem_path_(filesystem_path) {}
-
- virtual FilePath ValidateFileSystemRootAndGetPathOnFileThread(
- const GURL& origin_url,
- FileSystemType type,
- const FilePath& virtual_path,
- bool create) {
- return test_filesystem_path_;
- }
-
- private:
- FilePath test_filesystem_path_;
-};
-
} // namespace (anonymous)
void FileSystemOperationTest::SetUp() {
- filesystem_dir_ = base_.path().AppendASCII("filesystem");
- file_util::CreateDirectory(filesystem_dir_);
-
- quota_manager_ = new MockQuotaManager(0, QuotaFileUtil::kNoLimit);
+ FilePath base_dir = base_.path().AppendASCII("filesystem");
+ quota_manager_ = new MockQuotaManager(base_dir);
+ test_helper_.SetUp(base_dir,
+ false /* incognito */,
+ false /* unlimited quota */,
+ quota_manager_->proxy(),
+ LocalFileSystemFileUtil::GetInstance());
}
void FileSystemOperationTest::TearDown() {
quota_manager_ = NULL;
- MessageLoop::current()->RunAllPending();
+ test_helper_.TearDown();
}
FileSystemOperation* FileSystemOperationTest::operation() {
- FileSystemOperation* operation = new FileSystemOperation(
- new MockDispatcher(this),
- base::MessageLoopProxy::CreateForCurrentThread(),
- new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread(),
- NULL, quota_manager()->proxy(), FilePath(),
- false /* is_incognito */, true, false,
- new MockFileSystemPathManager(filesystem_dir_)),
- LocalFileSystemFileUtil::GetInstance());
- operation->file_system_operation_context()->set_src_type(
- kFileSystemTypeTemporary);
- operation->file_system_operation_context()->set_dest_type(
- kFileSystemTypeTemporary);
- GURL origin_url("fake://fake.foo/");
- operation->file_system_operation_context()->set_src_origin_url(origin_url);
- operation->file_system_operation_context()->set_dest_origin_url(origin_url);
-
- return operation;
+ return test_helper_.NewOperation(new MockDispatcher(this));
}
TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
@@ -345,7 +306,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) {
operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(dest_file_path));
}
@@ -357,7 +318,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) {
operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(dest_file_path));
}
@@ -367,7 +328,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) {
operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(VirtualDirectoryExists(src_dir_path));
// Make sure we've overwritten but not moved the source under the |dest_dir|.
@@ -384,7 +345,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) {
operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(VirtualDirectoryExists(src_dir_path));
EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path));
}
@@ -399,7 +360,7 @@ TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) {
operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append(
child_dir_path.BaseName())));
EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append(
@@ -481,7 +442,7 @@ TEST_F(FileSystemOperationTest, TestCopyFailureByQuota) {
operation()->Truncate(URLForPath(src_file_path), 6);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info));
EXPECT_EQ(6, info.size);
@@ -502,7 +463,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) {
operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(dest_file_path));
}
@@ -514,7 +475,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) {
operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(dest_file_path));
}
@@ -524,7 +485,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) {
operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
// Make sure we've overwritten but not copied the source under the |dest_dir|.
EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path));
@@ -540,7 +501,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) {
operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path));
}
@@ -554,7 +515,7 @@ TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) {
operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append(
child_dir_path.BaseName())));
EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append(
@@ -577,7 +538,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) {
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
operation()->CreateFile(URLForPath(file_path), false);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(file_path));
}
@@ -587,7 +548,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) {
FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist")));
operation()->CreateFile(URLForPath(file_path), true);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualFileExists(file_path));
}
@@ -597,7 +558,7 @@ TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) {
FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist")));
operation()->CreateFile(URLForPath(file_path), false);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
}
TEST_F(FileSystemOperationTest,
@@ -634,14 +595,14 @@ TEST_F(FileSystemOperationTest, TestCreateDirSuccess) {
FilePath dir_path(CreateVirtualTemporaryDir());
operation()->CreateDirectory(URLForPath(dir_path), false, false);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
// Dir doesn't exist.
FilePath nonexisting_dir_path(FilePath(
FILE_PATH_LITERAL("nonexistingdir")));
operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path));
}
@@ -652,7 +613,7 @@ TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) {
operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path));
}
@@ -678,22 +639,22 @@ TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
operation()->DirectoryExists(URLForPath(dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
operation()->GetMetadata(URLForPath(dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(info().is_directory);
EXPECT_EQ(PlatformPath(dir_path), path());
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
operation()->FileExists(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
operation()->GetMetadata(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(info().is_directory);
EXPECT_EQ(PlatformPath(file_path), path());
}
@@ -702,13 +663,13 @@ TEST_F(FileSystemOperationTest, TestGetLocalFilePathSuccess) {
FilePath dir_path(CreateVirtualTemporaryDir());
operation()->GetLocalPath(URLForPath(dir_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_EQ(local_path().value(), PlatformPath(dir_path).value());
FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
operation()->GetLocalPath(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_EQ(local_path().value(), PlatformPath(file_path).value());
}
@@ -802,7 +763,7 @@ TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
operation()->Remove(URLForPath(empty_dir_path), false /* recursive */);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(VirtualDirectoryExists(empty_dir_path));
// Removing a non-empty directory with recursive flag == true should be ok.
@@ -817,7 +778,7 @@ TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
operation()->Remove(URLForPath(parent_dir_path), true /* recursive */);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(VirtualDirectoryExists(parent_dir_path));
}
@@ -834,7 +795,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
// Check that its length is the size of the data written.
operation()->GetMetadata(URLForPath(file_path));
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_FALSE(info().is_directory);
EXPECT_EQ(data_size, info().size);
@@ -842,7 +803,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
int length = 17;
operation()->Truncate(URLForPath(file_path), length);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
// Check that its length is now 17 and that it's all zeroes after the test
// data.
@@ -863,7 +824,7 @@ TEST_F(FileSystemOperationTest, TestTruncate) {
length = 3;
operation()->Truncate(URLForPath(file_path), length);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
// Check that its length is now 3 and that it contains only bits of test data.
EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
@@ -883,7 +844,7 @@ TEST_F(FileSystemOperationTest, TestTruncateFailureByQuota) {
operation()->Truncate(URLForPath(file_path), 10);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(kFileOperationSucceeded, status());
+ EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
EXPECT_EQ(10, info.size);
diff --git a/webkit/fileapi/file_system_operation_write_unittest.cc b/webkit/fileapi/file_system_operation_write_unittest.cc
index b08f4ce..b15e032 100644
--- a/webkit/fileapi/file_system_operation_write_unittest.cc
+++ b/webkit/fileapi/file_system_operation_write_unittest.cc
@@ -28,21 +28,22 @@
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/local_file_system_file_util.h"
+#include "webkit/fileapi/file_system_test_helper.h"
#include "webkit/quota/quota_manager.h"
+using quota::QuotaManager;
+
namespace fileapi {
namespace {
-class MockQuotaManager : public quota::QuotaManager {
+class MockQuotaManager : public QuotaManager {
public:
- MockQuotaManager(const FilePath& filesystem_path, int64 usage, int64 quota)
- : quota::QuotaManager(false /* is_incognito */,
- filesystem_path,
- base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread()),
- test_filesystem_path_(filesystem_path),
- usage_(usage),
+ MockQuotaManager(const FilePath& base_dir, int64 quota)
+ : QuotaManager(false /* is_incognito */, base_dir,
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ base::MessageLoopProxy::CreateForCurrentThread()),
+ usage_(0),
quota_(quota) {}
virtual void GetUsageAndQuota(const GURL& origin, quota::StorageType type,
@@ -55,7 +56,6 @@ class MockQuotaManager : public quota::QuotaManager {
void set_quota(int64 quota) { quota_ = quota; }
private:
- FilePath test_filesystem_path_;
int64 usage_;
int64 quota_;
};
@@ -93,12 +93,11 @@ class FileSystemOperationWriteTest : public testing::Test {
protected:
GURL URLForPath(const FilePath& path) const {
- // Only the path will actually get used.
- return GURL(GetFileSystemRootURI(GURL("http://www.example.com/"),
- kFileSystemTypeTemporary).spec() + path.MaybeAsASCII());
+ return test_helper_.GetURLForPath(path);
}
scoped_refptr<MockQuotaManager> quota_manager_;
+ FileSystemTestOriginHelper test_helper_;
MessageLoop loop_;
@@ -117,25 +116,6 @@ class FileSystemOperationWriteTest : public testing::Test {
namespace {
-class MockFileSystemPathManager : public FileSystemPathManager {
- public:
- MockFileSystemPathManager(const FilePath& filesystem_path)
- : FileSystemPathManager(base::MessageLoopProxy::CreateForCurrentThread(),
- filesystem_path, NULL, false, true),
- test_filesystem_path_(filesystem_path) {}
-
- virtual FilePath ValidateFileSystemRootAndGetPathOnFileThread(
- const GURL& origin_url,
- FileSystemType type,
- const FilePath& virtual_path,
- bool create) {
- return test_filesystem_path_;
- }
-
- private:
- FilePath test_filesystem_path_;
-};
-
class TestURLRequestContext : public net::URLRequestContext {
public:
webkit_blob::BlobStorageController* blob_storage_controller() {
@@ -204,37 +184,30 @@ class MockDispatcher : public FileSystemCallbackDispatcher {
void FileSystemOperationWriteTest::SetUp() {
ASSERT_TRUE(dir_.CreateUniqueTempDir());
- filesystem_dir_ = dir_.path().AppendASCII("filesystem");
- file_util::CreateDirectory(filesystem_dir_);
+ FilePath base_dir = dir_.path().AppendASCII("filesystem");
+
+ quota_manager_ = new MockQuotaManager(base_dir, 1024);
+ test_helper_.SetUp(base_dir,
+ false /* incognito */,
+ false /* unlimited quota */,
+ quota_manager_->proxy(),
+ LocalFileSystemFileUtil::GetInstance());
+ filesystem_dir_ = test_helper_.GetOriginRootPath();
+
ASSERT_TRUE(file_util::CreateTemporaryFileInDir(filesystem_dir_, &file_));
virtual_path_ = file_.BaseName();
- quota_manager_ = new MockQuotaManager(filesystem_dir_, 0, 1024);
-
net::URLRequest::RegisterProtocolFactory("blob", &BlobURLRequestJobFactory);
}
void FileSystemOperationWriteTest::TearDown() {
net::URLRequest::RegisterProtocolFactory("blob", NULL);
quota_manager_ = NULL;
- MessageLoop::current()->RunAllPending();
+ test_helper_.TearDown();
}
FileSystemOperation* FileSystemOperationWriteTest::operation() {
- FileSystemOperation* operation = new FileSystemOperation(
- new MockDispatcher(this),
- base::MessageLoopProxy::CreateForCurrentThread(),
- new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread(),
- NULL, quota_manager_->proxy(), FilePath(),
- false /* is_incognito */, true, false,
- new MockFileSystemPathManager(filesystem_dir_)),
- LocalFileSystemFileUtil::GetInstance());
- operation->file_system_operation_context()->set_src_type(
- kFileSystemTypeTemporary);
- operation->file_system_operation_context()->set_dest_type(
- kFileSystemTypeTemporary);
- return operation;
+ return test_helper_.NewOperation(new MockDispatcher(this));
}
TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) {
diff --git a/webkit/fileapi/file_system_test_helper.cc b/webkit/fileapi/file_system_test_helper.cc
new file mode 100644
index 0000000..dd2334b
--- /dev/null
+++ b/webkit/fileapi/file_system_test_helper.cc
@@ -0,0 +1,163 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/fileapi/file_system_test_helper.h"
+
+#include "base/file_util.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_operation.h"
+#include "webkit/fileapi/file_system_operation_context.h"
+#include "webkit/fileapi/file_system_usage_cache.h"
+#include "webkit/fileapi/file_system_util.h"
+#include "webkit/fileapi/local_file_system_file_util.h"
+#include "webkit/fileapi/quota_file_util.h"
+#include "webkit/fileapi/sandbox_mount_point_provider.h"
+#include "webkit/quota/special_storage_policy.h"
+
+namespace fileapi {
+namespace {
+
+class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
+ public:
+ TestSpecialStoragePolicy(bool unlimited_quota)
+ : unlimited_quota_(unlimited_quota) {}
+
+ virtual bool IsStorageProtected(const GURL& origin) {
+ return false;
+ }
+
+ virtual bool IsStorageUnlimited(const GURL& origin) {
+ return unlimited_quota_;
+ }
+
+ virtual bool IsFileHandler(const std::string& extension_id) {
+ return true;
+ }
+
+ private:
+ bool unlimited_quota_;
+};
+
+} // anonymous namespace
+
+FileSystemTestOriginHelper::FileSystemTestOriginHelper(
+ const GURL& origin, FileSystemType type)
+ : origin_(origin), type_(type), file_util_(NULL) {
+}
+
+FileSystemTestOriginHelper::FileSystemTestOriginHelper()
+ : origin_(GURL("http://foo.com")),
+ type_(kFileSystemTypeTemporary),
+ file_util_(NULL) {
+}
+
+FileSystemTestOriginHelper::~FileSystemTestOriginHelper() {
+}
+
+void FileSystemTestOriginHelper::SetUp(
+ const FilePath& base_dir, FileSystemFileUtil* file_util) {
+ SetUp(base_dir, false, false, NULL, file_util);
+}
+
+void FileSystemTestOriginHelper::SetUp(
+ const FilePath& base_dir,
+ bool incognito_mode,
+ bool unlimited_quota,
+ quota::QuotaManagerProxy* quota_manager_proxy,
+ FileSystemFileUtil* file_util) {
+ file_util_ = file_util ? file_util : LocalFileSystemFileUtil::GetInstance();
+ file_system_context_ = new FileSystemContext(
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ new TestSpecialStoragePolicy(unlimited_quota),
+ quota_manager_proxy,
+ base_dir,
+ incognito_mode,
+ true /* allow_file_access_from_files */,
+ unlimited_quota,
+ NULL);
+
+ DCHECK(file_system_context_->path_manager());
+ DCHECK(file_system_context_->path_manager()->sandbox_provider());
+
+ // Prepare the origin's root directory.
+ file_system_context_->path_manager()->
+ ValidateFileSystemRootAndGetPathOnFileThread(
+ origin_, type_, FilePath(), true /* create */);
+
+ // Initialize the usage cache file.
+ FilePath usage_cache_path = file_system_context_->path_manager()
+ ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_);
+ FileSystemUsageCache::UpdateUsage(usage_cache_path, 0);
+}
+
+void FileSystemTestOriginHelper::TearDown() {
+ file_system_context_ = NULL;
+ MessageLoop::current()->RunAllPending();
+}
+
+FilePath FileSystemTestOriginHelper::GetOriginRootPath() const {
+ return file_system_context_->path_manager()->
+ ValidateFileSystemRootAndGetPathOnFileThread(
+ origin_, type_, FilePath(), false);
+}
+
+FilePath FileSystemTestOriginHelper::GetLocalPath(const FilePath& path) {
+ DCHECK(file_util_);
+ FilePath local_path;
+ scoped_ptr<FileSystemOperationContext> context(NewOperationContext());
+ file_util_->GetLocalFilePath(context.get(), path, &local_path);
+ return local_path;
+}
+
+FilePath FileSystemTestOriginHelper::GetLocalPathFromASCII(
+ const std::string& path) {
+ return GetLocalPath(FilePath().AppendASCII(path));
+}
+
+GURL FileSystemTestOriginHelper::GetURLForPath(const FilePath& path) const {
+ return GURL(GetFileSystemRootURI(origin_, type_).spec() +
+ path.MaybeAsASCII());
+}
+
+FilePath FileSystemTestOriginHelper::GetUsageCachePath() const {
+ return file_system_context_->path_manager()
+ ->sandbox_provider()->GetUsageCachePathForOriginAndType(origin_, type_);
+}
+
+FileSystemOperation* FileSystemTestOriginHelper::NewOperation(
+ FileSystemCallbackDispatcher* callback_dispatcher) {
+ DCHECK(file_system_context_.get());
+ DCHECK(file_util_);
+ FileSystemOperation* operation =
+ new FileSystemOperation(callback_dispatcher,
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ file_system_context_.get(),
+ file_util_);
+ InitializeOperationContext(operation->file_system_operation_context());
+ return operation;
+}
+
+FileSystemOperationContext* FileSystemTestOriginHelper::NewOperationContext() {
+ DCHECK(file_system_context_.get());
+ DCHECK(file_util_);
+ FileSystemOperationContext* context =
+ new FileSystemOperationContext(file_system_context_.get(), file_util_);
+ InitializeOperationContext(context);
+ return context;
+}
+
+void FileSystemTestOriginHelper::InitializeOperationContext(
+ FileSystemOperationContext* context) {
+ DCHECK(context);
+ context->set_src_origin_url(origin_);
+ context->set_src_type(type_);
+ context->set_dest_origin_url(origin_);
+ context->set_dest_type(type_);
+}
+
+} // namespace fileapi
diff --git a/webkit/fileapi/file_system_test_helper.h b/webkit/fileapi/file_system_test_helper.h
new file mode 100644
index 0000000..53deba2
--- /dev/null
+++ b/webkit/fileapi/file_system_test_helper.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_TEST_HELPER_H_
+#define WEBKIT_FILEAPI_FILE_SYSTEM_TEST_HELPER_H_
+#pragma once
+
+#include <string>
+
+#include "base/file_path.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "googleurl/src/gurl.h"
+#include "webkit/fileapi/file_system_types.h"
+
+namespace quota {
+class QuotaManagerProxy;
+}
+
+class FilePath;
+
+namespace fileapi {
+
+class FileSystemCallbackDispatcher;
+class FileSystemContext;
+class FileSystemFileUtil;
+class FileSystemOperation;
+class FileSystemOperationContext;
+class FileSystemPathManager;
+
+// Filesystem test helper class that encapsulates test environment for
+// a given {origin, type} pair.
+class FileSystemTestOriginHelper {
+ public:
+ FileSystemTestOriginHelper(const GURL& origin, FileSystemType type);
+ FileSystemTestOriginHelper();
+ ~FileSystemTestOriginHelper();
+
+ void SetUp(const FilePath& base_dir, FileSystemFileUtil* file_util);
+ void SetUp(const FilePath& base_dir,
+ bool incognito_mode,
+ bool unlimited_quota,
+ quota::QuotaManagerProxy* quota_manager_proxy,
+ FileSystemFileUtil* file_util);
+ void TearDown();
+
+ FilePath GetOriginRootPath() const;
+ FilePath GetLocalPath(const FilePath& path);
+ FilePath GetLocalPathFromASCII(const std::string& path);
+ GURL GetURLForPath(const FilePath& path) const;
+ FilePath GetUsageCachePath() const;
+
+ FileSystemOperation* NewOperation(
+ FileSystemCallbackDispatcher* callback_dispatcher);
+ FileSystemOperationContext* NewOperationContext();
+
+ FileSystemContext* file_system_context() const {
+ return file_system_context_.get();
+ }
+
+ const GURL& origin() const { return origin_; }
+ FileSystemType type() const { return type_; }
+ FileSystemFileUtil* file_util() { return file_util_; }
+
+ private:
+ void InitializeOperationContext(FileSystemOperationContext* context);
+
+ scoped_refptr<FileSystemContext> file_system_context_;
+ const GURL origin_;
+ const FileSystemType type_;
+ FileSystemFileUtil* file_util_;
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_FILE_SYSTEM_TEST_HELPER_H_
diff --git a/webkit/fileapi/file_writer_delegate_unittest.cc b/webkit/fileapi/file_writer_delegate_unittest.cc
index 6bf6df2..ea6a98b 100644
--- a/webkit/fileapi/file_writer_delegate_unittest.cc
+++ b/webkit/fileapi/file_writer_delegate_unittest.cc
@@ -27,8 +27,9 @@
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_usage_cache.h"
#include "webkit/fileapi/file_writer_delegate.h"
-#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/fileapi/quota_file_util.h"
+#include "webkit/fileapi/sandbox_mount_point_provider.h"
+#include "webkit/fileapi/file_system_test_helper.h"
namespace fileapi {
@@ -69,37 +70,30 @@ class Result {
class FileWriterDelegateTest : public PlatformTest {
public:
FileWriterDelegateTest()
- : loop_(MessageLoop::TYPE_IO),
- origin_url_("http://foo") {}
+ : loop_(MessageLoop::TYPE_IO) {}
protected:
virtual void SetUp();
virtual void TearDown();
int64 GetCachedUsage() {
- return FileSystemUsageCache::GetUsage(usage_file_path_);
+ return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath());
}
FileSystemOperation* CreateNewOperation(Result* result, int64 quota);
- FileSystemContext* file_system_context() {
- return file_system_context_.get();
- }
-
static net::URLRequest::ProtocolFactory Factory;
scoped_ptr<FileWriterDelegate> file_writer_delegate_;
scoped_ptr<net::URLRequest> request_;
scoped_ptr<Result> result_;
- scoped_refptr<FileSystemContext> file_system_context_;
+ FileSystemTestOriginHelper test_helper_;
MessageLoop loop_;
ScopedTempDir dir_;
- FilePath usage_file_path_;
FilePath file_path_;
PlatformFile file_;
- const GURL origin_url_;
static const char* content_;
};
@@ -195,26 +189,12 @@ net::URLRequestJob* FileWriterDelegateTest::Factory(
void FileWriterDelegateTest::SetUp() {
ASSERT_TRUE(dir_.CreateUniqueTempDir());
FilePath base_dir = dir_.path().AppendASCII("filesystem");
- file_system_context_ = new FileSystemContext(
- base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread(),
- NULL, NULL, base_dir, false,
- true, true, NULL);
-
- // NOTE: this test assumes the filesystem implementation uses
- // sandbox provider for temporary filesystem.
- SandboxMountPointProvider* sandbox_provider =
- file_system_context_->path_manager()->sandbox_provider();
- FilePath filesystem_dir = sandbox_provider->GetBaseDirectoryForOriginAndType(
- origin_url_, kFileSystemTypeTemporary);
- ASSERT_TRUE(file_util::CreateDirectory(filesystem_dir));
- ASSERT_TRUE(file_util::CreateTemporaryFileInDir(
- filesystem_dir, &file_path_));
+ test_helper_.SetUp(base_dir, QuotaFileUtil::GetInstance());
- usage_file_path_ = sandbox_provider->GetUsageCachePathForOriginAndType(
- origin_url_, kFileSystemTypeTemporary);
- FileSystemUsageCache::UpdateUsage(usage_file_path_, 0);
+ FilePath filesystem_dir = test_helper_.GetOriginRootPath();
+ ASSERT_TRUE(file_util::CreateTemporaryFileInDir(
+ filesystem_dir, &file_path_));
bool created;
base::PlatformFileError error_code;
file_ = base::CreatePlatformFile(
@@ -233,22 +213,15 @@ void FileWriterDelegateTest::TearDown() {
net::URLRequest::RegisterProtocolFactory("blob", NULL);
result_.reset();
base::ClosePlatformFile(file_);
- file_system_context_ = NULL;
- MessageLoop::current()->RunAllPending();
+ test_helper_.TearDown();
}
FileSystemOperation* FileWriterDelegateTest::CreateNewOperation(
Result* result, int64 quota) {
- FileSystemOperation* operation =
- new FileSystemOperation(new MockDispatcher(result), NULL,
- file_system_context_.get(),
- QuotaFileUtil::GetInstance());
+ FileSystemOperation* operation = test_helper_.NewOperation(
+ new MockDispatcher(result));
FileSystemOperationContext* context =
operation->file_system_operation_context();
- context->set_src_origin_url(origin_url_);
- context->set_src_type(kFileSystemTypeTemporary);
- context->set_dest_origin_url(origin_url_);
- context->set_dest_type(kFileSystemTypeTemporary);
context->set_allowed_bytes_growth(quota);
return operation;
}
diff --git a/webkit/fileapi/local_file_system_file_util_unittest.cc b/webkit/fileapi/local_file_system_file_util_unittest.cc
index b4b4e3d..67ba2fe 100644
--- a/webkit/fileapi/local_file_system_file_util_unittest.cc
+++ b/webkit/fileapi/local_file_system_file_util_unittest.cc
@@ -19,41 +19,10 @@
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/local_file_system_file_util.h"
#include "webkit/fileapi/quota_file_util.h"
+#include "webkit/fileapi/file_system_test_helper.h"
#include "webkit/quota/quota_manager.h"
namespace fileapi {
-namespace {
-
-class MockFileSystemPathManager : public FileSystemPathManager {
- public:
- MockFileSystemPathManager(const FilePath& filesystem_path)
- : FileSystemPathManager(base::MessageLoopProxy::CreateForCurrentThread(),
- filesystem_path, NULL, false, true),
- test_filesystem_path_(filesystem_path) {}
-
- virtual FilePath ValidateFileSystemRootAndGetPathOnFileThread(
- const GURL& origin_url,
- fileapi::FileSystemType type,
- const FilePath& virtual_path,
- bool create) {
- return test_filesystem_path_;
- }
-
- private:
- FilePath test_filesystem_path_;
-};
-
-FilePath UTF8ToFilePath(const std::string& str) {
- FilePath::StringType result;
-#if defined(OS_POSIX)
- result = base::SysWideToNativeMB(UTF8ToWide(str));
-#elif defined(OS_WIN)
- result = UTF8ToUTF16(str);
-#endif
- return FilePath(result);
-}
-
-} // namespace (anonymous)
// TODO(dmikurube): Cover all public methods in LocalFileSystemFileUtil.
class LocalFileSystemFileUtilTest : public testing::Test {
@@ -64,21 +33,16 @@ class LocalFileSystemFileUtilTest : public testing::Test {
void SetUp() {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
- filesystem_dir_ = data_dir_.path().AppendASCII("filesystem");
- file_util::CreateDirectory(filesystem_dir_);
- ASSERT_TRUE(file_util::CreateTemporaryFileInDir(filesystem_dir_,
- &file_path_));
+ test_helper_.SetUp(data_dir_.path(), FileUtil());
+ }
+
+ void TearDown() {
+ test_helper_.TearDown();
}
protected:
FileSystemOperationContext* NewContext() {
- FileSystemOperationContext* context = new FileSystemOperationContext(
- new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread(),
- NULL, NULL, FilePath(), false /* is_incognito */,
- true, true,
- new MockFileSystemPathManager(filesystem_dir_)),
- FileUtil());
+ FileSystemOperationContext* context = test_helper_.NewOperationContext();
context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
return context;
}
@@ -87,22 +51,26 @@ class LocalFileSystemFileUtilTest : public testing::Test {
return LocalFileSystemFileUtil::GetInstance();
}
- FilePath Path(const char *file_name) {
- return UTF8ToFilePath(file_name);
+ static FilePath Path(const std::string& file_name) {
+ return FilePath().AppendASCII(file_name);
+ }
+
+ FilePath LocalPath(const char *file_name) {
+ return test_helper_.GetLocalPathFromASCII(file_name);
}
bool FileExists(const char *file_name) {
- return file_util::PathExists(filesystem_dir_.AppendASCII(file_name)) &&
- !file_util::DirectoryExists(filesystem_dir_.AppendASCII(file_name));
+ return file_util::PathExists(LocalPath(file_name)) &&
+ !file_util::DirectoryExists(LocalPath(file_name));
}
bool DirectoryExists(const char *file_name) {
- return file_util::DirectoryExists(filesystem_dir_.AppendASCII(file_name));
+ return file_util::DirectoryExists(LocalPath(file_name));
}
int64 GetSize(const char *file_name) {
base::PlatformFileInfo info;
- file_util::GetFileInfo(filesystem_dir_.AppendASCII(file_name), &info);
+ file_util::GetFileInfo(LocalPath(file_name), &info);
return info.size;
}
@@ -114,7 +82,7 @@ class LocalFileSystemFileUtilTest : public testing::Test {
scoped_ptr<FileSystemOperationContext> context(NewContext());
return FileUtil()->CreateOrOpen(
context.get(),
- UTF8ToFilePath(file_name),
+ Path(file_name),
file_flags, file_handle, created);
}
@@ -123,13 +91,12 @@ class LocalFileSystemFileUtilTest : public testing::Test {
scoped_ptr<FileSystemOperationContext> context(NewContext());
return FileUtil()->EnsureFileExists(
context.get(),
- UTF8ToFilePath(file_name), created);
+ Path(file_name), created);
}
private:
ScopedTempDir data_dir_;
- FilePath filesystem_dir_;
- FilePath file_path_;
+ FileSystemTestOriginHelper test_helper_;
base::ScopedCallbackFactory<LocalFileSystemFileUtilTest> callback_factory_;
diff --git a/webkit/fileapi/quota_file_util.cc b/webkit/fileapi/quota_file_util.cc
index 820b6a8..20314e9 100644
--- a/webkit/fileapi/quota_file_util.cc
+++ b/webkit/fileapi/quota_file_util.cc
@@ -9,7 +9,10 @@
#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_usage_cache.h"
+#include "webkit/fileapi/file_system_quota_util.h"
+#include "webkit/quota/quota_manager.h"
+
+using quota::QuotaManagerProxy;
namespace fileapi {
@@ -19,7 +22,7 @@ namespace {
// Checks if copying in the same filesystem can be performed.
// This method is not called for moving within a single filesystem.
-static bool CanCopy(
+bool CanCopy(
const FilePath& src_file_path,
const FilePath& dest_file_path,
int64 allowed_bytes_growth,
@@ -41,27 +44,41 @@ static bool CanCopy(
return true;
}
-static FilePath InitUsageFile(FileSystemOperationContext* fs_context) {
- FilePath base_path = fs_context->file_system_context()->path_manager()->
- ValidateFileSystemRootAndGetPathOnFileThread(fs_context->src_origin_url(),
- fs_context->src_type(), FilePath(), false);
- FilePath usage_file_path =
- base_path.AppendASCII(FileSystemUsageCache::kUsageFileName);
-
- if (FileSystemUsageCache::Exists(usage_file_path))
- FileSystemUsageCache::IncrementDirty(usage_file_path);
+// A helper class to hook quota_util() methods before and after modifications.
+class ScopedOriginUpdateHelper {
+ public:
+ explicit ScopedOriginUpdateHelper(
+ FileSystemContext* context,
+ const GURL& origin_url,
+ FileSystemType type)
+ : origin_url_(origin_url),
+ type_(type) {
+ DCHECK(context);
+ DCHECK(type != kFileSystemTypeUnknown);
+ quota_util_ = context->GetQuotaUtil(type_);
+ quota_manager_proxy_ = context->quota_manager_proxy();
+ if (quota_util_)
+ quota_util_->StartUpdateOriginOnFileThread(origin_url_, type_);
+ }
- return usage_file_path;
-}
+ ~ScopedOriginUpdateHelper() {
+ if (quota_util_)
+ quota_util_->EndUpdateOriginOnFileThread(origin_url_, type_);
+ }
-static void UpdateUsageFile(const FilePath& usage_file_path, int64 growth) {
- if (FileSystemUsageCache::Exists(usage_file_path))
- FileSystemUsageCache::DecrementDirty(usage_file_path);
+ void NotifyUpdate(int64 growth) {
+ if (quota_util_)
+ quota_util_->UpdateOriginUsageOnFileThread(
+ quota_manager_proxy_, origin_url_, type_, growth);
+ }
- int64 usage = FileSystemUsageCache::GetUsage(usage_file_path);
- if (usage >= 0)
- FileSystemUsageCache::UpdateUsage(usage_file_path, usage + growth);
-}
+ private:
+ FileSystemQuotaUtil* quota_util_;
+ QuotaManagerProxy* quota_manager_proxy_;
+ const GURL& origin_url_;
+ FileSystemType type_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedOriginUpdateHelper);
+};
} // namespace (anonymous)
@@ -75,7 +92,14 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
const FilePath& src_file_path,
const FilePath& dest_file_path,
bool copy) {
- FilePath usage_file_path = InitUsageFile(fs_context);
+ DCHECK(fs_context);
+
+ // TODO(kinuko): For cross-filesystem move case we need 2 helpers, one for
+ // src and one for dest.
+ ScopedOriginUpdateHelper helper(
+ fs_context->file_system_context(),
+ fs_context->dest_origin_url(),
+ fs_context->dest_type());
int64 growth = 0;
@@ -85,10 +109,8 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
// The third argument (growth) is not used for now.
if (!CanCopy(src_file_path, dest_file_path, allowed_bytes_growth,
- &growth)) {
- FileSystemUsageCache::DecrementDirty(usage_file_path);
+ &growth))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
- }
} else {
base::PlatformFileInfo dest_file_info;
if (!file_util::GetFileInfo(dest_file_path, &dest_file_info))
@@ -99,7 +121,11 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
base::PlatformFileError error = FileSystemFileUtil::GetInstance()->
CopyOrMoveFile(fs_context, src_file_path, dest_file_path, copy);
- UpdateUsageFile(usage_file_path, growth);
+ if (error == base::PLATFORM_FILE_OK) {
+ // TODO(kinuko): For cross-filesystem move case, call this with -growth
+ // for source and growth for dest.
+ helper.NotifyUpdate(growth);
+ }
return error;
}
@@ -107,7 +133,11 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
base::PlatformFileError QuotaFileUtil::DeleteFile(
FileSystemOperationContext* fs_context,
const FilePath& file_path) {
- FilePath usage_file_path = InitUsageFile(fs_context);
+ DCHECK(fs_context);
+ ScopedOriginUpdateHelper helper(
+ fs_context->file_system_context(),
+ fs_context->src_origin_url(),
+ fs_context->src_type());
int64 growth = 0;
base::PlatformFileInfo file_info;
@@ -118,7 +148,8 @@ base::PlatformFileError QuotaFileUtil::DeleteFile(
base::PlatformFileError error = FileSystemFileUtil::GetInstance()->
DeleteFile(fs_context, file_path);
- UpdateUsageFile(usage_file_path, growth);
+ if (error == base::PLATFORM_FILE_OK)
+ helper.NotifyUpdate(growth);
return error;
}
@@ -128,27 +159,25 @@ base::PlatformFileError QuotaFileUtil::Truncate(
const FilePath& path,
int64 length) {
int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
- FilePath usage_file_path = InitUsageFile(fs_context);
+ ScopedOriginUpdateHelper helper(
+ fs_context->file_system_context(),
+ fs_context->src_origin_url(),
+ fs_context->src_type());
int64 growth = 0;
base::PlatformFileInfo file_info;
- if (!file_util::GetFileInfo(path, &file_info)) {
- FileSystemUsageCache::DecrementDirty(usage_file_path);
+ if (!file_util::GetFileInfo(path, &file_info))
return base::PLATFORM_FILE_ERROR_FAILED;
- }
- growth = length - file_info.size;
- if (allowed_bytes_growth != kNoLimit) {
- if (growth > allowed_bytes_growth) {
- FileSystemUsageCache::DecrementDirty(usage_file_path);
- return base::PLATFORM_FILE_ERROR_NO_SPACE;
- }
- }
+ growth = length - file_info.size;
+ if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
+ return base::PLATFORM_FILE_ERROR_NO_SPACE;
base::PlatformFileError error = FileSystemFileUtil::GetInstance()->Truncate(
fs_context, path, length);
- UpdateUsageFile(usage_file_path, growth);
+ if (error == base::PLATFORM_FILE_OK)
+ helper.NotifyUpdate(growth);
return error;
}
diff --git a/webkit/fileapi/quota_file_util_unittest.cc b/webkit/fileapi/quota_file_util_unittest.cc
index 8a2f8fb..8d952ab 100644
--- a/webkit/fileapi/quota_file_util_unittest.cc
+++ b/webkit/fileapi/quota_file_util_unittest.cc
@@ -16,28 +16,10 @@
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_usage_cache.h"
+#include "webkit/fileapi/local_file_system_file_util.h"
+#include "webkit/fileapi/file_system_test_helper.h"
namespace fileapi {
-namespace {
-class MockFileSystemPathManager : public FileSystemPathManager {
- public:
- MockFileSystemPathManager(const FilePath& filesystem_path)
- : FileSystemPathManager(base::MessageLoopProxy::CreateForCurrentThread(),
- filesystem_path, NULL, false, true),
- test_filesystem_path_(filesystem_path) {}
-
- virtual FilePath ValidateFileSystemRootAndGetPathOnFileThread(
- const GURL& origin_url,
- fileapi::FileSystemType type,
- const FilePath& virtual_path,
- bool create) {
- return test_filesystem_path_;
- }
-
- private:
- FilePath test_filesystem_path_;
-};
-} // namespace
class QuotaFileUtilTest : public testing::Test {
public:
@@ -47,32 +29,27 @@ class QuotaFileUtilTest : public testing::Test {
void SetUp() {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
- filesystem_dir_ = data_dir_.path().AppendASCII("filesystem");
- file_util::CreateDirectory(filesystem_dir_);
+ FilePath base_dir = data_dir_.path().AppendASCII("filesystem");
- usage_file_path_ = Path(FileSystemUsageCache::kUsageFileName);
- FileSystemUsageCache::UpdateUsage(usage_file_path_, 0);
+ // For path translation we rely on LocalFileSystemFileUtil::GetLocalPath().
+ test_helper_.SetUp(base_dir, LocalFileSystemFileUtil::GetInstance());
+ }
+
+ void TearDown() {
+ test_helper_.TearDown();
}
protected:
FileSystemOperationContext* NewContext() {
- FileSystemOperationContext *context = new FileSystemOperationContext(
- new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread(),
- NULL, NULL, FilePath(), false,
- true, true,
- new MockFileSystemPathManager(filesystem_dir_)),
- QuotaFileUtil::GetInstance());
- context->set_src_type(fileapi::kFileSystemTypeTemporary);
- return context;
+ return test_helper_.NewOperationContext();
}
QuotaFileUtil* FileUtil() {
return QuotaFileUtil::GetInstance();
}
- FilePath Path(const char *file_name) {
- return filesystem_dir_.AppendASCII(file_name);
+ FilePath Path(const std::string& file_name) {
+ return test_helper_.GetLocalPathFromASCII(file_name);
}
base::PlatformFileError CreateFile(const char* file_name,
@@ -93,13 +70,16 @@ class QuotaFileUtilTest : public testing::Test {
}
int64 GetCachedUsage() {
- return FileSystemUsageCache::GetUsage(usage_file_path_);
+ return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath());
+ }
+
+ FileSystemContext* file_system_context() const {
+ return test_helper_.file_system_context();
}
private:
ScopedTempDir data_dir_;
- FilePath filesystem_dir_;
- FilePath usage_file_path_;
+ FileSystemTestOriginHelper test_helper_;
base::ScopedCallbackFactory<QuotaFileUtilTest> callback_factory_;
DISALLOW_COPY_AND_ASSIGN(QuotaFileUtilTest);
diff --git a/webkit/fileapi/sandbox_mount_point_provider.h b/webkit/fileapi/sandbox_mount_point_provider.h
index 38bd0b5..60bd7fe 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.h
+++ b/webkit/fileapi/sandbox_mount_point_provider.h
@@ -166,7 +166,7 @@ class SandboxMountPointProvider
class GetFileSystemRootPathTask;
- friend class FileWriterDelegateTest;
+ friend class FileSystemTestOriginHelper;
// The path_manager_ isn't owned by this instance; this instance is owned by
// the path_manager_, and they have the same lifetime.
diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi
index a14fa4a..65cc1c9 100644
--- a/webkit/tools/test_shell/test_shell.gypi
+++ b/webkit/tools/test_shell/test_shell.gypi
@@ -389,6 +389,8 @@
'../../fileapi/obfuscated_file_system_file_util_unittest.cc',
'../../fileapi/quota_file_util_unittest.cc',
'../../fileapi/sandbox_mount_point_provider_unittest.cc',
+ '../../fileapi/file_system_test_helper.cc',
+ '../../fileapi/file_system_test_helper.h',
'../../fileapi/webfilewriter_base_unittest.cc',
'../../glue/bookmarklet_unittest.cc',
'../../glue/context_menu_unittest.cc',