#include <vector>
#include "base/bind.h"
-#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
-#include "base/platform_file.h"
#include "base/run_loop.h"
#include "content/browser/fileapi/mock_file_change_observer.h"
#include "content/public/test/async_file_test_helper.h"
#include "content/public/test/sandbox_file_system_test_helper.h"
#include "content/public/test/test_file_system_context.h"
#include "content/test/fileapi_test_file_set.h"
+#include "storage/browser/fileapi/external_mount_points.h"
+#include "storage/browser/fileapi/file_system_backend.h"
+#include "storage/browser/fileapi/file_system_context.h"
+#include "storage/browser/fileapi/file_system_operation_context.h"
+#include "storage/browser/fileapi/file_system_usage_cache.h"
+#include "storage/browser/fileapi/obfuscated_file_util.h"
+#include "storage/browser/fileapi/sandbox_directory_database.h"
+#include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h"
+#include "storage/browser/fileapi/sandbox_isolated_origin_database.h"
+#include "storage/browser/fileapi/sandbox_origin_database.h"
+#include "storage/browser/quota/quota_manager.h"
+#include "storage/common/database/database_identifier.h"
+#include "storage/common/quota/quota_types.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/browser/fileapi/external_mount_points.h"
-#include "webkit/browser/fileapi/file_system_backend.h"
-#include "webkit/browser/fileapi/file_system_context.h"
-#include "webkit/browser/fileapi/file_system_operation_context.h"
-#include "webkit/browser/fileapi/file_system_usage_cache.h"
-#include "webkit/browser/fileapi/obfuscated_file_util.h"
-#include "webkit/browser/fileapi/sandbox_directory_database.h"
-#include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h"
-#include "webkit/browser/fileapi/sandbox_isolated_origin_database.h"
-#include "webkit/browser/fileapi/sandbox_origin_database.h"
-#include "webkit/browser/quota/quota_manager.h"
-#include "webkit/common/database/database_identifier.h"
-#include "webkit/common/quota/quota_types.h"
using content::AsyncFileTestHelper;
-using fileapi::FileSystemContext;
-using fileapi::FileSystemOperation;
-using fileapi::FileSystemOperationContext;
-using fileapi::FileSystemType;
-using fileapi::FileSystemURL;
-using fileapi::ObfuscatedFileUtil;
-using fileapi::SandboxDirectoryDatabase;
-using fileapi::SandboxIsolatedOriginDatabase;
-using fileapi::kFileSystemTypeTemporary;
-using fileapi::kFileSystemTypePersistent;
+using storage::FileSystemContext;
+using storage::FileSystemOperation;
+using storage::FileSystemOperationContext;
+using storage::FileSystemURL;
+using storage::ObfuscatedFileUtil;
+using storage::SandboxDirectoryDatabase;
+using storage::SandboxIsolatedOriginDatabase;
+using storage::kFileSystemTypeTemporary;
+using storage::kFileSystemTypePersistent;
namespace content {
FileSystemURL FileSystemURLDirName(const FileSystemURL& url) {
return FileSystemURL::CreateForTest(
- url.origin(), url.mount_type(),
- fileapi::VirtualPath::DirName(url.virtual_path()));
+ url.origin(),
+ url.mount_type(),
+ storage::VirtualPath::DirName(url.virtual_path()));
}
-std::string GetTypeString(FileSystemType type) {
- return fileapi::SandboxFileSystemBackendDelegate::GetTypeString(type);
+std::string GetTypeString(storage::FileSystemType type) {
+ return storage::SandboxFileSystemBackendDelegate::GetTypeString(type);
}
-bool HasFileSystemType(
- ObfuscatedFileUtil::AbstractOriginEnumerator* enumerator,
- FileSystemType type) {
+bool HasFileSystemType(ObfuscatedFileUtil::AbstractOriginEnumerator* enumerator,
+ storage::FileSystemType type) {
return enumerator->HasTypeDirectory(GetTypeString(type));
}
public:
ObfuscatedFileUtilTest()
: origin_(GURL("http://www.example.com")),
- type_(fileapi::kFileSystemTypeTemporary),
+ type_(storage::kFileSystemTypeTemporary),
weak_factory_(this),
sandbox_file_system_(origin_, type_),
- quota_status_(quota::kQuotaStatusUnknown),
- usage_(-1) {
- }
+ quota_status_(storage::kQuotaStatusUnknown),
+ usage_(-1) {}
- virtual void SetUp() {
+ void SetUp() override {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
storage_policy_ = new MockSpecialStoragePolicy();
quota_manager_ =
- new quota::QuotaManager(false /* is_incognito */,
- data_dir_.path(),
- base::MessageLoopProxy::current().get(),
- base::MessageLoopProxy::current().get(),
- storage_policy_.get());
+ new storage::QuotaManager(false /* is_incognito */,
+ data_dir_.path(),
+ base::MessageLoopProxy::current().get(),
+ base::MessageLoopProxy::current().get(),
+ storage_policy_.get());
// Every time we create a new sandbox_file_system helper,
// it creates another context, which creates another path manager,
sandbox_file_system_.SetUp(file_system_context_.get());
- change_observers_ = fileapi::MockFileChangeObserver::CreateList(
- &change_observer_);
+ change_observers_ =
+ storage::MockFileChangeObserver::CreateList(&change_observer_);
}
- virtual void TearDown() {
+ void TearDown() override {
quota_manager_ = NULL;
sandbox_file_system_.TearDown();
}
return context;
}
- const fileapi::ChangeObserverList& change_observers() const {
+ const storage::ChangeObserverList& change_observers() const {
return change_observers_;
}
- fileapi::MockFileChangeObserver* change_observer() {
+ storage::MockFileChangeObserver* change_observer() {
return &change_observer_;
}
// and obfuscated_file_util_.
// Use this for tests which need to run in multiple origins; we need a test
// helper per origin.
- SandboxFileSystemTestHelper* NewFileSystem(
- const GURL& origin, fileapi::FileSystemType type) {
+ SandboxFileSystemTestHelper* NewFileSystem(const GURL& origin,
+ storage::FileSystemType type) {
SandboxFileSystemTestHelper* file_system =
new SandboxFileSystemTestHelper(origin, type);
}
scoped_ptr<ObfuscatedFileUtil> CreateObfuscatedFileUtil(
- quota::SpecialStoragePolicy* storage_policy) {
+ storage::SpecialStoragePolicy* storage_policy) {
return scoped_ptr<ObfuscatedFileUtil>(
ObfuscatedFileUtil::CreateForTesting(
storage_policy, data_dir_path(), NULL,
return origin_;
}
- fileapi::FileSystemType type() const {
- return type_;
- }
+ storage::FileSystemType type() const { return type_; }
std::string type_string() const {
return GetTypeString(type_);
sandbox_file_system_.type(),
&usage_,
"a);
- EXPECT_EQ(quota::kQuotaStatusOk, quota_status_);
+ EXPECT_EQ(storage::kQuotaStatusOk, quota_status_);
}
void RevokeUsageCache() {
}
int64 usage() const { return usage_; }
- fileapi::FileSystemUsageCache* usage_cache() {
+ storage::FileSystemUsageCache* usage_cache() {
return sandbox_file_system_.usage_cache();
}
return sandbox_file_system_.CreateURL(path);
}
- void CheckFileAndCloseHandle(
- const FileSystemURL& url, base::PlatformFile file_handle) {
+ void CheckFileAndCloseHandle(const FileSystemURL& url, base::File file) {
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
base::FilePath local_path;
EXPECT_EQ(base::File::FILE_OK,
const char data[] = "test data";
const int length = arraysize(data) - 1;
- if (base::kInvalidPlatformFileValue == file_handle) {
- base::File file(data_path,
+ if (!file.IsValid()) {
+ file.Initialize(data_path,
base::File::FLAG_OPEN | base::File::FLAG_WRITE);
ASSERT_TRUE(file.IsValid());
EXPECT_FALSE(file.created());
- file_handle = file.TakePlatformFile();
}
- ASSERT_EQ(length, base::WritePlatformFile(file_handle, 0, data, length));
- EXPECT_TRUE(base::ClosePlatformFile(file_handle));
+ ASSERT_EQ(length, file.Write(0, data, length));
+ file.Close();
base::File::Info file_info1;
EXPECT_EQ(length, GetSize(data_path));
std::set<base::FilePath::StringType>* files,
std::set<base::FilePath::StringType>* directories) {
scoped_ptr<FileSystemOperationContext> context;
- std::vector<fileapi::DirectoryEntry> entries;
+ std::vector<storage::DirectoryEntry> entries;
EXPECT_EQ(base::File::FILE_OK,
AsyncFileTestHelper::ReadDirectory(file_system_context(),
root_url, &entries));
FillTestDirectory(root_url, &files, &directories);
scoped_ptr<FileSystemOperationContext> context;
- std::vector<fileapi::DirectoryEntry> entries;
+ std::vector<storage::DirectoryEntry> entries;
context.reset(NewContext(NULL));
EXPECT_EQ(base::File::FILE_OK,
AsyncFileTestHelper::ReadDirectory(
file_system_context(), root_url, &entries));
- std::vector<fileapi::DirectoryEntry>::iterator entry_iter;
+ std::vector<storage::DirectoryEntry>::iterator entry_iter;
EXPECT_EQ(files.size() + directories.size(), entries.size());
EXPECT_TRUE(change_observer()->HasNoChange());
for (entry_iter = entries.begin(); entry_iter != entries.end();
++entry_iter) {
- const fileapi::DirectoryEntry& entry = *entry_iter;
+ const storage::DirectoryEntry& entry = *entry_iter;
std::set<base::FilePath::StringType>::iterator iter =
files.find(entry.name);
if (iter != files.end()) {
ASSERT_TRUE(db != NULL);
// Destory it.
- ASSERT_TRUE(file_util->DestroyDirectoryDatabase(
- url.origin(), GetTypeString(url.type())));
+ file_util->DestroyDirectoryDatabase(
+ url.origin(), GetTypeString(url.type()));
ASSERT_TRUE(file_util->directories_.empty());
}
// Initialize the directory with one origin using
// SandboxIsolatedOriginDatabase.
{
- std::string origin_string =
- webkit_database::GetIdentifierFromOrigin(origin_);
+ std::string origin_string = storage::GetIdentifierFromOrigin(origin_);
SandboxIsolatedOriginDatabase database_old(
origin_string, data_dir_path(),
base::FilePath(
protected:
base::ScopedTempDir data_dir_;
- base::MessageLoop message_loop_;
+ base::MessageLoopForIO message_loop_;
scoped_refptr<MockSpecialStoragePolicy> storage_policy_;
- scoped_refptr<quota::QuotaManager> quota_manager_;
+ scoped_refptr<storage::QuotaManager> quota_manager_;
scoped_refptr<FileSystemContext> file_system_context_;
GURL origin_;
- fileapi::FileSystemType type_;
+ storage::FileSystemType type_;
base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_;
SandboxFileSystemTestHelper sandbox_file_system_;
- quota::QuotaStatusCode quota_status_;
+ storage::QuotaStatusCode quota_status_;
int64 usage_;
- fileapi::MockFileChangeObserver change_observer_;
- fileapi::ChangeObserverList change_observers_;
+ storage::MockFileChangeObserver change_observer_;
+ storage::ChangeObserverList change_observers_;
private:
DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest);
};
TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
- base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
- bool created;
FileSystemURL url = CreateURLFromUTF8("fake/file");
scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
- int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
+ int file_flags = base::File::FLAG_CREATE | base::File::FLAG_WRITE;
- EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
- ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle,
- &created));
+ base::File file = ofu()->CreateOrOpen(context.get(), url, file_flags);
+ EXPECT_FALSE(file.IsValid());
+ EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, file.error_details());
context.reset(NewContext(NULL));
EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
ObfuscatedFileUtil::ComputeFilePathCost(url.path()) - 1);
- ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE,
- ofu()->CreateOrOpen(context.get(), url, file_flags,
- &file_handle, &created));
+ file = ofu()->CreateOrOpen(context.get(), url, file_flags);
+ EXPECT_FALSE(file.IsValid());
+ ASSERT_EQ(base::File::FILE_ERROR_NO_SPACE, file.error_details());
context.reset(NewContext(NULL));
context->set_allowed_bytes_growth(
ObfuscatedFileUtil::ComputeFilePathCost(url.path()));
- ASSERT_EQ(base::File::FILE_OK,
- ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle,
- &created));
- ASSERT_TRUE(created);
+ file = ofu()->CreateOrOpen(context.get(), url, file_flags);
+ EXPECT_TRUE(file.IsValid());
+ ASSERT_TRUE(file.created());
EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
- EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
- CheckFileAndCloseHandle(url, file_handle);
+ CheckFileAndCloseHandle(url, file.Pass());
context.reset(NewContext(NULL));
base::FilePath local_path;
EXPECT_EQ(3, change_observer()->get_and_reset_create_directory_count());
context.reset(NewContext(NULL));
- file_handle = base::kInvalidPlatformFileValue;
- ASSERT_EQ(base::File::FILE_OK,
- ofu()->CreateOrOpen(context.get(), url, file_flags, &file_handle,
- &created));
- ASSERT_TRUE(created);
+ file = ofu()->CreateOrOpen(context.get(), url, file_flags);
+ ASSERT_TRUE(file.IsValid());
+ ASSERT_TRUE(file.created());
EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
- EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
- CheckFileAndCloseHandle(url, file_handle);
+ CheckFileAndCloseHandle(url, file.Pass());
context.reset(NewContext(NULL));
EXPECT_EQ(base::File::FILE_OK,
ASSERT_TRUE(created);
EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
- CheckFileAndCloseHandle(url, base::kInvalidPlatformFileValue);
+ CheckFileAndCloseHandle(url, base::File());
context.reset(NewContext(NULL));
ASSERT_EQ(base::File::FILE_OK,
ofu()->EnsureFileExists(context.get(), url, &created));
ASSERT_TRUE(created);
- std::vector<fileapi::DirectoryEntry> entries;
+ std::vector<storage::DirectoryEntry> entries;
EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
AsyncFileTestHelper::ReadDirectory(file_system_context(), url,
&entries));
const FileSystemURL kPath2 = CreateURLFromUTF8("fuga");
scoped_ptr<FileSystemOperationContext> context;
- base::PlatformFile file;
base::File::Info file_info;
base::FilePath data_path;
bool created = false;
ofu()->DestroyDirectoryDatabase(origin(), type_string());
context.reset(NewContext(NULL));
- EXPECT_EQ(base::File::FILE_OK,
- ofu()->CreateOrOpen(
- context.get(), kPath1,
- base::PLATFORM_FILE_READ | base::PLATFORM_FILE_CREATE,
- &file, &created));
- EXPECT_TRUE(created);
+ base::File file =
+ ofu()->CreateOrOpen(context.get(), kPath1,
+ base::File::FLAG_READ | base::File::FLAG_CREATE);
+ EXPECT_TRUE(file.IsValid());
+ EXPECT_TRUE(file.created());
- base::File base_file(file);
- EXPECT_TRUE(base_file.GetInfo(&file_info));
+ EXPECT_TRUE(file.GetInfo(&file_info));
EXPECT_EQ(0, file_info.size);
}
const FileSystemURL empty_path = CreateURL(base::FilePath());
scoped_ptr<FileSystemOperationContext> context;
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kPath); ++i) {
+ for (size_t i = 0; i < arraysize(kPath); ++i) {
bool created = false;
context.reset(NewContext(NULL));
EXPECT_EQ(base::File::FILE_OK,
EXPECT_TRUE(created);
}
- std::vector<fileapi::DirectoryEntry> entries;
+ std::vector<storage::DirectoryEntry> entries;
EXPECT_EQ(base::File::FILE_OK,
AsyncFileTestHelper::ReadDirectory(
file_system_context(), empty_path, &entries));
EXPECT_EQ(base::File::FILE_OK,
AsyncFileTestHelper::ReadDirectory(
file_system_context(), empty_path, &entries));
- EXPECT_EQ(ARRAYSIZE_UNSAFE(kPath) - 1, entries.size());
+ EXPECT_EQ(arraysize(kPath) - 1, entries.size());
}
TEST_F(ObfuscatedFileUtilTest, TestDirectoryTimestampForCreation) {
ofu()->CreateDirectory(context.get(), dir_url, false, false));
// EnsureFileExists, create case.
- FileSystemURL url(FileSystemURLAppendUTF8(
- dir_url, "EnsureFileExists_file"));
+ FileSystemURL url(FileSystemURLAppendUTF8(dir_url, "EnsureFileExists_file"));
bool created = false;
ClearTimestamp(dir_url);
context.reset(NewContext(NULL));
// CreateOrOpen, create case.
url = FileSystemURLAppendUTF8(dir_url, "CreateOrOpen_file");
- base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
- created = false;
ClearTimestamp(dir_url);
context.reset(NewContext(NULL));
- EXPECT_EQ(base::File::FILE_OK,
- ofu()->CreateOrOpen(
- context.get(), url,
- base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
- &file_handle, &created));
- EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
- EXPECT_TRUE(created);
- EXPECT_TRUE(base::ClosePlatformFile(file_handle));
+ base::File file =
+ ofu()->CreateOrOpen(context.get(), url,
+ base::File::FLAG_CREATE | base::File::FLAG_WRITE);
+
+ EXPECT_TRUE(file.IsValid());
+ EXPECT_TRUE(file.created());
+ file.Close();
EXPECT_NE(base::Time(), GetModifiedTime(dir_url));
// open case.
- file_handle = base::kInvalidPlatformFileValue;
- created = true;
ClearTimestamp(dir_url);
context.reset(NewContext(NULL));
- EXPECT_EQ(base::File::FILE_OK,
- ofu()->CreateOrOpen(
- context.get(), url,
- base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
- &file_handle, &created));
- EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
- EXPECT_FALSE(created);
- EXPECT_TRUE(base::ClosePlatformFile(file_handle));
+ file = ofu()->CreateOrOpen(context.get(), url,
+ base::File::FLAG_OPEN | base::File::FLAG_WRITE);
+ EXPECT_TRUE(file.IsValid());
+ EXPECT_FALSE(file.created());
+ file.Close();
EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
// fail case
- file_handle = base::kInvalidPlatformFileValue;
ClearTimestamp(dir_url);
context.reset(NewContext(NULL));
- EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
- ofu()->CreateOrOpen(
- context.get(), url,
- base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
- &file_handle, &created));
- EXPECT_EQ(base::kInvalidPlatformFileValue, file_handle);
+ file = ofu()->CreateOrOpen(context.get(), url,
+ base::File::FLAG_CREATE | base::File::FLAG_WRITE);
+ EXPECT_FALSE(file.IsValid());
+ EXPECT_EQ(base::File::FILE_ERROR_EXISTS, file.error_details());
EXPECT_EQ(base::Time(), GetModifiedTime(dir_url));
// CreateDirectory, create case.
base::Time()));
context.reset(NewContext(NULL));
- scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> file_enum(
+ scoped_ptr<storage::FileSystemFileUtil::AbstractFileEnumerator> file_enum(
ofu()->CreateFileEnumerator(context.get(), dir, false));
int count = 0;
from_file, from_file_size));
ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize());
- int64 to_file_size ALLOW_UNUSED = from_file_size;
from_file_size = 0;
ASSERT_EQ(base::File::FILE_OK,
ofu()->CopyOrMoveFile(
}
TEST_F(ObfuscatedFileUtilTest, TestQuotaOnOpen) {
- FileSystemURL file(CreateURLFromUTF8("file"));
- base::PlatformFile file_handle;
- bool created;
+ FileSystemURL url(CreateURLFromUTF8("file"));
+ bool created;
// Creating a file.
ASSERT_EQ(base::File::FILE_OK,
ofu()->EnsureFileExists(
- AllowUsageIncrease(PathCost(file))->context(),
- file, &created));
+ AllowUsageIncrease(PathCost(url))->context(),
+ url, &created));
ASSERT_TRUE(created);
ASSERT_EQ(0, ComputeTotalFileSize());
// Opening it, which shouldn't change the usage.
- ASSERT_EQ(base::File::FILE_OK,
- ofu()->CreateOrOpen(
- AllowUsageIncrease(0)->context(), file,
- base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
- &file_handle, &created));
+ base::File file =
+ ofu()->CreateOrOpen(AllowUsageIncrease(0)->context(), url,
+ base::File::FLAG_OPEN | base::File::FLAG_WRITE);
+ ASSERT_TRUE(file.IsValid());
ASSERT_EQ(0, ComputeTotalFileSize());
- EXPECT_TRUE(base::ClosePlatformFile(file_handle));
+ file.Close();
const int length = 33;
ASSERT_EQ(base::File::FILE_OK,
ofu()->Truncate(
- AllowUsageIncrease(length)->context(), file, length));
+ AllowUsageIncrease(length)->context(), url, length));
ASSERT_EQ(length, ComputeTotalFileSize());
// Opening it with CREATE_ALWAYS flag, which should truncate the file size.
- ASSERT_EQ(base::File::FILE_OK,
- ofu()->CreateOrOpen(
- AllowUsageIncrease(-length)->context(), file,
- base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE,
- &file_handle, &created));
+ file = ofu()->CreateOrOpen(
+ AllowUsageIncrease(-length)->context(), url,
+ base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
+ ASSERT_TRUE(file.IsValid());
ASSERT_EQ(0, ComputeTotalFileSize());
- EXPECT_TRUE(base::ClosePlatformFile(file_handle));
+ file.Close();
// Extending the file again.
ASSERT_EQ(base::File::FILE_OK,
ofu()->Truncate(
- AllowUsageIncrease(length)->context(), file, length));
+ AllowUsageIncrease(length)->context(), url, length));
ASSERT_EQ(length, ComputeTotalFileSize());
// Opening it with TRUNCATED flag, which should truncate the file size.
- ASSERT_EQ(base::File::FILE_OK,
- ofu()->CreateOrOpen(
- AllowUsageIncrease(-length)->context(), file,
- base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE,
- &file_handle, &created));
+ file = ofu()->CreateOrOpen(
+ AllowUsageIncrease(-length)->context(), url,
+ base::File::FLAG_OPEN_TRUNCATED | base::File::FLAG_WRITE);
+ ASSERT_TRUE(file.IsValid());
ASSERT_EQ(0, ComputeTotalFileSize());
- EXPECT_TRUE(base::ClosePlatformFile(file_handle));
+ file.Close();
}
TEST_F(ObfuscatedFileUtilTest, MaybeDropDatabasesAliveCase) {
}
TEST_F(ObfuscatedFileUtilTest, OpenPathInNonDirectory) {
- FileSystemURL file(CreateURLFromUTF8("file"));
+ FileSystemURL url(CreateURLFromUTF8("file"));
FileSystemURL path_in_file(CreateURLFromUTF8("file/file"));
bool created;
ASSERT_EQ(base::File::FILE_OK,
- ofu()->EnsureFileExists(UnlimitedContext().get(), file, &created));
+ ofu()->EnsureFileExists(UnlimitedContext().get(), url, &created));
ASSERT_TRUE(created);
- created = false;
- base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
- int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE;
- ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
- ofu()->CreateOrOpen(UnlimitedContext().get(),
- path_in_file,
- file_flags,
- &file_handle,
- &created));
- ASSERT_FALSE(created);
- ASSERT_EQ(base::kInvalidPlatformFileValue, file_handle);
+ int file_flags = base::File::FLAG_CREATE | base::File::FLAG_WRITE;
+ base::File file =
+ ofu()->CreateOrOpen(UnlimitedContext().get(), path_in_file, file_flags);
+ ASSERT_FALSE(file.IsValid());
+ ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, file.error_details());
ASSERT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY,
ofu()->CreateDirectory(UnlimitedContext().get(),
true /* recursive */));
}
+TEST_F(ObfuscatedFileUtilTest, DeleteDirectoryForOriginAndType) {
+ const GURL origin1("http://www.example.com:12");
+ const GURL origin2("http://www.example.com:1234");
+
+ // Create origin directories.
+ scoped_ptr<SandboxFileSystemTestHelper> fs1(
+ NewFileSystem(origin1, kFileSystemTypeTemporary));
+ scoped_ptr<SandboxFileSystemTestHelper> fs2(
+ NewFileSystem(origin1, kFileSystemTypePersistent));
+ scoped_ptr<SandboxFileSystemTestHelper> fs3(
+ NewFileSystem(origin2, kFileSystemTypeTemporary));
+ scoped_ptr<SandboxFileSystemTestHelper> fs4(
+ NewFileSystem(origin2, kFileSystemTypePersistent));
+
+ // Make sure directories for origin1 exist.
+ base::File::Error error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypeTemporary), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypePersistent), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+
+ // Make sure directories for origin2 exist.
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+
+ // Delete a directory for origin1's persistent filesystem.
+ ofu()->DeleteDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypePersistent));
+
+ // The directory for origin1's temporary filesystem should not be removed.
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypeTemporary), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+
+ // The directory for origin1's persistent filesystem should be removed.
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypePersistent), false, &error);
+ ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND, error);
+
+ // The directories for origin2 should not be removed.
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+}
+
+TEST_F(ObfuscatedFileUtilTest, DeleteDirectoryForOriginAndType_DeleteAll) {
+ const GURL origin1("http://www.example.com:12");
+ const GURL origin2("http://www.example.com:1234");
+
+ // Create origin directories.
+ scoped_ptr<SandboxFileSystemTestHelper> fs1(
+ NewFileSystem(origin1, kFileSystemTypeTemporary));
+ scoped_ptr<SandboxFileSystemTestHelper> fs2(
+ NewFileSystem(origin1, kFileSystemTypePersistent));
+ scoped_ptr<SandboxFileSystemTestHelper> fs3(
+ NewFileSystem(origin2, kFileSystemTypeTemporary));
+ scoped_ptr<SandboxFileSystemTestHelper> fs4(
+ NewFileSystem(origin2, kFileSystemTypePersistent));
+
+ // Make sure directories for origin1 exist.
+ base::File::Error error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypeTemporary), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypePersistent), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+
+ // Make sure directories for origin2 exist.
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+
+ // Delete all directories for origin1.
+ ofu()->DeleteDirectoryForOriginAndType(origin1, std::string());
+
+ // The directories for origin1 should be removed.
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypeTemporary), false, &error);
+ ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND, error);
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin1, GetTypeString(kFileSystemTypePersistent), false, &error);
+ ASSERT_EQ(base::File::FILE_ERROR_NOT_FOUND, error);
+
+ // The directories for origin2 should not be removed.
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin2, GetTypeString(kFileSystemTypeTemporary), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+ error = base::File::FILE_ERROR_FAILED;
+ ofu()->GetDirectoryForOriginAndType(
+ origin2, GetTypeString(kFileSystemTypePersistent), false, &error);
+ ASSERT_EQ(base::File::FILE_OK, error);
+}
+
} // namespace content