summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 09:31:26 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 09:31:26 +0000
commitdac0b36bb0a32586714ec0ebb4e49f25c8c1f0f4 (patch)
tree53312000d871d201065813b449c37c7708933428 /webkit
parentbfbfb0d659d904967767bfa033dd1db8090f8940 (diff)
downloadchromium_src-dac0b36bb0a32586714ec0ebb4e49f25c8c1f0f4.zip
chromium_src-dac0b36bb0a32586714ec0ebb4e49f25c8c1f0f4.tar.gz
chromium_src-dac0b36bb0a32586714ec0ebb4e49f25c8c1f0f4.tar.bz2
Revert 160809 - Add common helper code for SyncableFileSystem testing
BUG=154234 TEST=existing test (SyncableFileSystemTest.*) Review URL: https://codereview.chromium.org/11033058 TBR=kinuko@chromium.org Review URL: https://codereview.chromium.org/11087026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160810 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/fileapi/syncable/canned_syncable_file_system.cc149
-rw-r--r--webkit/fileapi/syncable/canned_syncable_file_system.h99
-rw-r--r--webkit/fileapi/syncable/syncable_file_system_unittest.cc135
3 files changed, 101 insertions, 282 deletions
diff --git a/webkit/fileapi/syncable/canned_syncable_file_system.cc b/webkit/fileapi/syncable/canned_syncable_file_system.cc
deleted file mode 100644
index 50e4c51..0000000
--- a/webkit/fileapi/syncable/canned_syncable_file_system.cc
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright (c) 2012 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/syncable/canned_syncable_file_system.h"
-
-#include "base/bind.h"
-#include "base/file_util.h"
-#include "base/message_loop_proxy.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/fileapi/file_system_context.h"
-#include "webkit/fileapi/file_system_operation_context.h"
-#include "webkit/fileapi/file_system_task_runners.h"
-#include "webkit/fileapi/file_system_util.h"
-#include "webkit/fileapi/isolated_context.h"
-#include "webkit/fileapi/local_file_system_operation.h"
-#include "webkit/fileapi/mock_file_system_options.h"
-#include "webkit/quota/mock_special_storage_policy.h"
-#include "webkit/quota/quota_manager.h"
-
-using base::PlatformFileError;
-using quota::QuotaManager;
-
-namespace fileapi {
-
-CannedSyncableFileSystem::CannedSyncableFileSystem(
- const GURL& origin, const std::string& service)
- : service_name_(service),
- test_helper_(origin, kFileSystemTypeSyncable),
- result_(base::PLATFORM_FILE_OK),
- sync_status_(SYNC_STATUS_OK),
- weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
-}
-
-CannedSyncableFileSystem::~CannedSyncableFileSystem() {}
-
-void CannedSyncableFileSystem::SetUp() {
- ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
-
- scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
- new quota::MockSpecialStoragePolicy();
-
- quota_manager_ = new QuotaManager(
- false /* is_incognito */,
- data_dir_.path(),
- base::MessageLoopProxy::current(),
- base::MessageLoopProxy::current(),
- storage_policy);
-
- file_system_context_ = new FileSystemContext(
- FileSystemTaskRunners::CreateMockTaskRunners(),
- storage_policy,
- quota_manager_->proxy(),
- data_dir_.path(),
- CreateAllowFileAccessOptions());
-
- test_helper_.SetUp(file_system_context_.get(), NULL);
-}
-
-void CannedSyncableFileSystem::TearDown() {
- quota_manager_ = NULL;
- test_helper_.TearDown();
-}
-
-FileSystemURL CannedSyncableFileSystem::URL(const std::string& path) const {
- return FileSystemURL(GURL(root_url_.spec() + path));
-}
-
-PlatformFileError CannedSyncableFileSystem::OpenFileSystem() {
- file_system_context_->OpenSyncableFileSystem(
- service_name_,
- test_helper_.origin(), test_helper_.type(),
- true /* create */,
- base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem,
- weak_factory_.GetWeakPtr()));
- MessageLoop::current()->RunAllPending();
- return result_;
-}
-
-PlatformFileError CannedSyncableFileSystem::CreateDirectory(
- const FileSystemURL& url) {
- result_ = base::PLATFORM_FILE_ERROR_FAILED;
- test_helper_.NewOperation()->CreateDirectory(
- url, false /* exclusive */, false /* recursive */,
- base::Bind(&CannedSyncableFileSystem::StatusCallback,
- weak_factory_.GetWeakPtr()));
- MessageLoop::current()->RunAllPending();
- return result_;
-}
-
-PlatformFileError CannedSyncableFileSystem::CreateFile(
- const FileSystemURL& url) {
- result_ = base::PLATFORM_FILE_ERROR_FAILED;
- test_helper_.NewOperation()->CreateFile(
- url, false /* exclusive */,
- base::Bind(&CannedSyncableFileSystem::StatusCallback,
- weak_factory_.GetWeakPtr()));
- MessageLoop::current()->RunAllPending();
- return result_;
-}
-
-PlatformFileError CannedSyncableFileSystem::TruncateFile(
- const FileSystemURL& url, int64 size) {
- result_ = base::PLATFORM_FILE_ERROR_FAILED;
- test_helper_.NewOperation()->Truncate(
- url, size,
- base::Bind(&CannedSyncableFileSystem::StatusCallback,
- weak_factory_.GetWeakPtr()));
- MessageLoop::current()->RunAllPending();
- return result_;
-}
-
-PlatformFileError CannedSyncableFileSystem::Remove(
- const FileSystemURL& url, bool recursive) {
- result_ = base::PLATFORM_FILE_ERROR_FAILED;
- test_helper_.NewOperation()->Remove(
- url, recursive,
- base::Bind(&CannedSyncableFileSystem::StatusCallback,
- weak_factory_.GetWeakPtr()));
- MessageLoop::current()->RunAllPending();
- return result_;
-}
-
-PlatformFileError CannedSyncableFileSystem::DeleteFileSystem() {
- file_system_context_->DeleteFileSystem(
- test_helper_.origin(), test_helper_.type(),
- base::Bind(&CannedSyncableFileSystem::StatusCallback,
- weak_factory_.GetWeakPtr()));
- MessageLoop::current()->RunAllPending();
- return result_;
-}
-
-void CannedSyncableFileSystem::DidOpenFileSystem(
- PlatformFileError result, const std::string& name, const GURL& root) {
- result_ = result;
- root_url_ = root;
-}
-
-void CannedSyncableFileSystem::StatusCallback(PlatformFileError result) {
- result_ = result;
-}
-
-FileSystemOperationContext* CannedSyncableFileSystem::NewOperationContext() {
- FileSystemOperationContext* context = test_helper_.NewOperationContext();
- context->set_allowed_bytes_growth(kint64max);
- return context;
-}
-
-} // namespace fileapi
diff --git a/webkit/fileapi/syncable/canned_syncable_file_system.h b/webkit/fileapi/syncable/canned_syncable_file_system.h
deleted file mode 100644
index 10dd446..0000000
--- a/webkit/fileapi/syncable/canned_syncable_file_system.h
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (c) 2012 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_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_
-#define WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/message_loop.h"
-#include "base/platform_file.h"
-#include "base/scoped_temp_dir.h"
-#include "webkit/fileapi/file_system_types.h"
-#include "webkit/fileapi/fileapi_export.h"
-#include "webkit/fileapi/local_file_system_test_helper.h"
-#include "webkit/fileapi/syncable/sync_status_code.h"
-
-namespace base {
-class Thread;
-class MessageLoopProxy;
-}
-
-namespace quota {
-class QuotaManager;
-}
-
-namespace fileapi {
-
-class FileSystemContext;
-
-// A canned syncable filesystem for testing.
-// This internally creates its own QuotaManager and FileSystemContext
-// (as we do so for each isolated application).
-class FILEAPI_EXPORT CannedSyncableFileSystem {
- public:
- CannedSyncableFileSystem(const GURL& origin, const std::string& service);
- ~CannedSyncableFileSystem();
-
- // SetUp must be called before using this instance.
- void SetUp();
-
- // TearDown must be called before destructing this instance.
- void TearDown();
-
- // Creates a FileSystemURL for the given (utf8) path string.
- FileSystemURL URL(const std::string& path) const;
-
- // Opens a new syncable file system.
- base::PlatformFileError OpenFileSystem();
-
- // Accessors.
- FileSystemContext* file_system_context() {
- return file_system_context_.get();
- }
- quota::QuotaManager* quota_manager() { return quota_manager_.get(); }
- GURL origin() const { return test_helper_.origin(); }
- FileSystemType type() const { return test_helper_.type(); }
- quota::StorageType storage_type() const {
- return test_helper_.storage_type();
- }
-
- // Helper routines to perform file system operations.
- // (They run on the current thread and returns synchronously).
- base::PlatformFileError CreateDirectory(const FileSystemURL& url);
- base::PlatformFileError CreateFile(const FileSystemURL& url);
- base::PlatformFileError TruncateFile(const FileSystemURL& url, int64 size);
- base::PlatformFileError Remove(const FileSystemURL& url, bool recursive);
-
- // Pruges the file system local storage.
- base::PlatformFileError DeleteFileSystem();
-
- private:
- // Callbacks.
- void DidOpenFileSystem(base::PlatformFileError result,
- const std::string& name,
- const GURL& root);
- void StatusCallback(base::PlatformFileError result);
-
- FileSystemOperationContext* NewOperationContext();
-
- ScopedTempDir data_dir_;
- const std::string service_name_;
-
- scoped_refptr<quota::QuotaManager> quota_manager_;
- scoped_refptr<FileSystemContext> file_system_context_;
- LocalFileSystemTestOriginHelper test_helper_;
- GURL root_url_;
- base::PlatformFileError result_;
- SyncStatusCode sync_status_;
-
- base::WeakPtrFactory<CannedSyncableFileSystem> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(CannedSyncableFileSystem);
-};
-
-} // namespace fileapi
-
-#endif // WEBKIT_FILEAPI_SYNCABLE_CANNED_SYNCABLE_FILE_SYSTEM_H_
diff --git a/webkit/fileapi/syncable/syncable_file_system_unittest.cc b/webkit/fileapi/syncable/syncable_file_system_unittest.cc
index 4e84820..e0a1848 100644
--- a/webkit/fileapi/syncable/syncable_file_system_unittest.cc
+++ b/webkit/fileapi/syncable/syncable_file_system_unittest.cc
@@ -2,13 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/file_util.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "base/platform_file.h"
+#include "base/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_task_runners.h"
#include "webkit/fileapi/file_system_types.h"
-#include "webkit/fileapi/isolated_context.h"
+#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/local_file_system_operation.h"
-#include "webkit/fileapi/syncable/canned_syncable_file_system.h"
-#include "webkit/fileapi/syncable/syncable_file_system_util.h"
+#include "webkit/fileapi/local_file_system_test_helper.h"
+#include "webkit/fileapi/mock_file_system_options.h"
+#include "webkit/quota/mock_special_storage_policy.h"
#include "webkit/quota/quota_manager.h"
#include "webkit/quota/quota_types.h"
@@ -20,23 +30,38 @@ namespace fileapi {
class SyncableFileSystemTest : public testing::Test {
public:
SyncableFileSystemTest()
- : file_system_(GURL("http://example.com/"), "test"),
+ : test_helper_(GURL("http://example.com/"), kFileSystemTypeSyncable),
quota_status_(quota::kQuotaStatusUnknown),
usage_(-1),
quota_(-1),
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
void SetUp() {
- file_system_.SetUp();
+ ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
+
+ scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
+ new quota::MockSpecialStoragePolicy();
+
+ quota_manager_ = new QuotaManager(
+ false /* is_incognito */,
+ data_dir_.path(),
+ base::MessageLoopProxy::current(),
+ base::MessageLoopProxy::current(),
+ storage_policy);
+
+ file_system_context_ = new FileSystemContext(
+ FileSystemTaskRunners::CreateMockTaskRunners(),
+ storage_policy,
+ quota_manager_->proxy(),
+ data_dir_.path(),
+ CreateAllowFileAccessOptions());
+
+ test_helper_.SetUp(file_system_context_.get(), NULL);
}
void TearDown() {
- file_system_.TearDown();
-
- // Make sure we don't leave the external filesystem.
- // (CannedSyncableFileSystem::TearDown does not do this as there may be
- // multiple syncable file systems registered for the name)
- RevokeSyncableFileSystem("test");
+ quota_manager_ = NULL;
+ test_helper_.TearDown();
}
void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) {
@@ -45,12 +70,28 @@ class SyncableFileSystemTest : public testing::Test {
quota_ = quota;
}
+ void DidOpenFileSystem(base::PlatformFileError result,
+ const std::string& name,
+ const GURL& root) {
+ result_ = result;
+ root_url_ = root;
+ }
+
+ void StatusCallback(base::PlatformFileError result) {
+ result_ = result;
+ }
+
protected:
+ FileSystemOperationContext* NewOperationContext() {
+ FileSystemOperationContext* context = test_helper_.NewOperationContext();
+ context->set_allowed_bytes_growth(kint64max);
+ return context;
+ }
+
void GetUsageAndQuota(int64* usage, int64* quota) {
- quota_status_ = quota::kQuotaStatusUnknown;
- file_system_.quota_manager()->GetUsageAndQuota(
- file_system_.origin(),
- file_system_.storage_type(),
+ quota_manager_->GetUsageAndQuota(
+ test_helper_.origin(),
+ test_helper_.storage_type(),
base::Bind(&SyncableFileSystemTest::DidGetUsageAndQuota,
weak_factory_.GetWeakPtr()));
MessageLoop::current()->RunAllPending();
@@ -62,14 +103,16 @@ class SyncableFileSystemTest : public testing::Test {
}
FileSystemURL URL(const std::string& path) {
- return file_system_.URL(path);
+ return FileSystemURL(GURL(root_url_.spec() + path));
}
ScopedTempDir data_dir_;
MessageLoop message_loop_;
-
- CannedSyncableFileSystem file_system_;
-
+ scoped_refptr<QuotaManager> quota_manager_;
+ scoped_refptr<FileSystemContext> file_system_context_;
+ LocalFileSystemTestOriginHelper test_helper_;
+ GURL root_url_;
+ base::PlatformFileError result_;
QuotaStatusCode quota_status_;
int64 usage_;
int64 quota_;
@@ -81,14 +124,29 @@ class SyncableFileSystemTest : public testing::Test {
// Brief combined testing. Just see if all the sandbox feature works.
TEST_F(SyncableFileSystemTest, SyncableLocalSandboxCombined) {
// Opens a syncable file system.
- EXPECT_EQ(base::PLATFORM_FILE_OK,
- file_system_.OpenFileSystem());
+ file_system_context_->OpenSyncableFileSystem(
+ "syncable-test",
+ test_helper_.origin(), test_helper_.type(),
+ true /* create */,
+ base::Bind(&SyncableFileSystemTest::DidOpenFileSystem,
+ weak_factory_.GetWeakPtr()));
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(base::PLATFORM_FILE_OK, result_);
// Do some operations.
- EXPECT_EQ(base::PLATFORM_FILE_OK,
- file_system_.CreateDirectory(URL("dir")));
- EXPECT_EQ(base::PLATFORM_FILE_OK,
- file_system_.CreateFile(URL("dir/foo")));
+ test_helper_.NewOperation()->CreateDirectory(
+ URL("dir"), false /* exclusive */, false /* recursive */,
+ base::Bind(&SyncableFileSystemTest::StatusCallback,
+ weak_factory_.GetWeakPtr()));
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(base::PLATFORM_FILE_OK, result_);
+
+ test_helper_.NewOperation()->CreateFile(
+ URL("dir/foo"), false /* exclusive */,
+ base::Bind(&SyncableFileSystemTest::StatusCallback,
+ weak_factory_.GetWeakPtr()));
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(base::PLATFORM_FILE_OK, result_);
const int64 kQuota = 12345 * 1024;
QuotaManager::kSyncableStorageDefaultHostQuota = kQuota;
@@ -102,11 +160,12 @@ TEST_F(SyncableFileSystemTest, SyncableLocalSandboxCombined) {
// Truncate to extend an existing file and see if the usage reflects it.
const int64 kFileSizeToExtend = 333;
- EXPECT_EQ(base::PLATFORM_FILE_OK,
- file_system_.CreateFile(URL("dir/foo")));
-
- EXPECT_EQ(base::PLATFORM_FILE_OK,
- file_system_.TruncateFile(URL("dir/foo"), kFileSizeToExtend));
+ test_helper_.NewOperation()->Truncate(
+ URL("dir/foo"), kFileSizeToExtend,
+ base::Bind(&SyncableFileSystemTest::StatusCallback,
+ weak_factory_.GetWeakPtr()));
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(base::PLATFORM_FILE_OK, result_);
int64 new_usage;
GetUsageAndQuota(&new_usage, NULL);
@@ -115,16 +174,24 @@ TEST_F(SyncableFileSystemTest, SyncableLocalSandboxCombined) {
// Shrink the quota to the current usage, try to extend the file further
// and see if it fails.
QuotaManager::kSyncableStorageDefaultHostQuota = new_usage;
- EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
- file_system_.TruncateFile(URL("dir/foo"), kFileSizeToExtend + 1));
+ test_helper_.NewOperation()->Truncate(
+ URL("dir/foo"), kFileSizeToExtend + 1,
+ base::Bind(&SyncableFileSystemTest::StatusCallback,
+ weak_factory_.GetWeakPtr()));
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_);
usage = new_usage;
GetUsageAndQuota(&new_usage, NULL);
EXPECT_EQ(usage, new_usage);
// Deletes the file system.
- EXPECT_EQ(base::PLATFORM_FILE_OK,
- file_system_.DeleteFileSystem());
+ file_system_context_->DeleteFileSystem(
+ test_helper_.origin(), test_helper_.type(),
+ base::Bind(&SyncableFileSystemTest::StatusCallback,
+ weak_factory_.GetWeakPtr()));
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(base::PLATFORM_FILE_OK, result_);
// Now the usage must be zero.
GetUsageAndQuota(&usage, NULL);