| Index: webkit/fileapi/local_file_system_operation_unittest.cc
|
| diff --git a/webkit/fileapi/local_file_system_operation_unittest.cc b/webkit/fileapi/local_file_system_operation_unittest.cc
|
| index 44a1bf955f82bb5e68e40509e96845fc47306898..980e61b3d9eda1cb64aabe71b2e3cfd9490e7291 100644
|
| --- a/webkit/fileapi/local_file_system_operation_unittest.cc
|
| +++ b/webkit/fileapi/local_file_system_operation_unittest.cc
|
| @@ -23,11 +23,10 @@
|
| #include "webkit/fileapi/local_file_system_test_helper.h"
|
| #include "webkit/fileapi/mock_file_change_observer.h"
|
| #include "webkit/quota/quota_manager.h"
|
| +#include "webkit/quota/mock_quota_manager.h"
|
|
|
| -using quota::QuotaClient;
|
| using quota::QuotaManager;
|
| using quota::QuotaManagerProxy;
|
| -using quota::StorageType;
|
| using webkit_blob::ShareableFileReference;
|
|
|
| namespace fileapi {
|
| @@ -41,120 +40,6 @@ void AssertFileErrorEq(base::PlatformFileError expected,
|
| ASSERT_EQ(expected, actual);
|
| }
|
|
|
| -class MockQuotaManager : public QuotaManager {
|
| - public:
|
| - MockQuotaManager(const FilePath& base_dir,
|
| - const GURL& origin,
|
| - StorageType type)
|
| - : QuotaManager(false /* is_incognito */, base_dir,
|
| - base::MessageLoopProxy::current(),
|
| - base::MessageLoopProxy::current(),
|
| - NULL),
|
| - origin_(origin),
|
| - type_(type),
|
| - usage_(0),
|
| - quota_(kint64max),
|
| - accessed_(0) {}
|
| -
|
| - virtual void GetUsageAndQuota(
|
| - const GURL& origin, quota::StorageType type,
|
| - const GetUsageAndQuotaCallback& callback) OVERRIDE {
|
| - EXPECT_EQ(origin_, origin);
|
| - EXPECT_EQ(type_, type);
|
| - callback.Run(quota::kQuotaStatusOk, usage_, quota_);
|
| - }
|
| -
|
| - protected:
|
| - virtual ~MockQuotaManager() {}
|
| -
|
| - private:
|
| - friend class MockQuotaManagerProxy;
|
| -
|
| - void SetQuota(const GURL& origin, StorageType type, int64 quota) {
|
| - EXPECT_EQ(origin_, origin);
|
| - EXPECT_EQ(type_, type);
|
| - quota_ = quota;
|
| - }
|
| -
|
| - void RecordStorageAccessed(const GURL& origin, StorageType type) {
|
| - EXPECT_EQ(origin_, origin);
|
| - EXPECT_EQ(type_, type);
|
| - ++accessed_;
|
| - }
|
| -
|
| - void UpdateUsage(const GURL& origin, StorageType type, int64 delta) {
|
| - EXPECT_EQ(origin_, origin);
|
| - EXPECT_EQ(type_, type);
|
| - usage_ += delta;
|
| - }
|
| -
|
| - const GURL& origin_;
|
| - const StorageType type_;
|
| - int64 usage_;
|
| - int64 quota_;
|
| - int accessed_;
|
| -};
|
| -
|
| -class MockQuotaManagerProxy : public QuotaManagerProxy {
|
| - public:
|
| - explicit MockQuotaManagerProxy(QuotaManager* quota_manager)
|
| - : QuotaManagerProxy(quota_manager,
|
| - base::MessageLoopProxy::current()),
|
| - registered_client_(NULL) {
|
| - }
|
| -
|
| - virtual void RegisterClient(QuotaClient* client) OVERRIDE {
|
| - EXPECT_FALSE(registered_client_);
|
| - registered_client_ = client;
|
| - }
|
| -
|
| - void SimulateQuotaManagerDestroyed() {
|
| - if (registered_client_) {
|
| - // We cannot call this in the destructor as the client (indirectly)
|
| - // holds a refptr of the proxy.
|
| - registered_client_->OnQuotaManagerDestroyed();
|
| - registered_client_ = NULL;
|
| - }
|
| - }
|
| -
|
| - // We don't mock them.
|
| - virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {}
|
| - virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {}
|
| -
|
| - virtual void NotifyStorageAccessed(QuotaClient::ID client_id,
|
| - const GURL& origin,
|
| - StorageType type) OVERRIDE {
|
| - mock_manager()->RecordStorageAccessed(origin, type);
|
| - }
|
| -
|
| - virtual void NotifyStorageModified(QuotaClient::ID client_id,
|
| - const GURL& origin,
|
| - StorageType type,
|
| - int64 delta) OVERRIDE {
|
| - mock_manager()->UpdateUsage(origin, type, delta);
|
| - }
|
| -
|
| - int storage_accessed_count() const {
|
| - return mock_manager()->accessed_;
|
| - }
|
| -
|
| - void SetQuota(const GURL& origin, StorageType type, int64 quota) {
|
| - mock_manager()->SetQuota(origin, type, quota);
|
| - }
|
| -
|
| - protected:
|
| - virtual ~MockQuotaManagerProxy() {
|
| - EXPECT_FALSE(registered_client_);
|
| - }
|
| -
|
| - private:
|
| - MockQuotaManager* mock_manager() const {
|
| - return static_cast<MockQuotaManager*>(quota_manager());
|
| - }
|
| -
|
| - QuotaClient* registered_client_;
|
| -};
|
| -
|
| FilePath ASCIIToFilePath(const std::string& str) {
|
| return FilePath().AppendASCII(str);
|
| }
|
| @@ -192,8 +77,13 @@ class LocalFileSystemOperationTest
|
| // Common temp base for nondestructive uses.
|
| ScopedTempDir base_;
|
|
|
| - MockQuotaManagerProxy* quota_manager_proxy() {
|
| - return static_cast<MockQuotaManagerProxy*>(quota_manager_proxy_.get());
|
| + quota::MockQuotaManager* quota_manager() {
|
| + return static_cast<quota::MockQuotaManager*>(quota_manager_.get());
|
| + }
|
| +
|
| + quota::MockQuotaManagerProxy* quota_manager_proxy() {
|
| + return static_cast<quota::MockQuotaManagerProxy*>(
|
| + quota_manager_proxy_.get());
|
| }
|
|
|
| FileSystemFileUtil* file_util() {
|
| @@ -370,17 +260,17 @@ class LocalFileSystemOperationTest
|
| void GrantQuotaForCurrentUsage() {
|
| int64 usage;
|
| GetUsageAndQuota(&usage, NULL);
|
| - quota_manager_proxy()->SetQuota(test_helper_.origin(),
|
| - test_helper_.storage_type(),
|
| - usage);
|
| + quota_manager()->SetQuota(test_helper_.origin(),
|
| + test_helper_.storage_type(),
|
| + usage);
|
| }
|
|
|
| void AddQuota(int64 quota_delta) {
|
| int64 quota;
|
| GetUsageAndQuota(NULL, "a);
|
| - quota_manager_proxy()->SetQuota(test_helper_.origin(),
|
| - test_helper_.storage_type(),
|
| - quota + quota_delta);
|
| + quota_manager()->SetQuota(test_helper_.origin(),
|
| + test_helper_.storage_type(),
|
| + quota + quota_delta);
|
| }
|
|
|
| // For post-operation status.
|
| @@ -405,9 +295,14 @@ class LocalFileSystemOperationTest
|
|
|
| void LocalFileSystemOperationTest::SetUp() {
|
| FilePath base_dir = base_.path().AppendASCII("filesystem");
|
| - quota_manager_ = new MockQuotaManager(
|
| - base_dir, test_helper_.origin(), test_helper_.storage_type());
|
| - quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get());
|
| + quota_manager_ = new quota::MockQuotaManager(
|
| + false /* is_incognito */, base_dir,
|
| + base::MessageLoopProxy::current(),
|
| + base::MessageLoopProxy::current(),
|
| + NULL /* special storage policy */);
|
| + quota_manager_proxy_ = new quota::MockQuotaManagerProxy(
|
| + quota_manager(),
|
| + base::MessageLoopProxy::current());
|
| test_helper_.SetUp(base_dir,
|
| false /* unlimited quota */,
|
| quota_manager_proxy_.get(),
|
| @@ -519,7 +414,7 @@ TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) {
|
|
|
| // Move is considered 'write' access (for both side), and won't be counted
|
| // as read access.
|
| - EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count());
|
| }
|
|
|
| TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) {
|
| @@ -719,7 +614,7 @@ TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) {
|
| MessageLoop::current()->RunAllPending();
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, status());
|
| EXPECT_TRUE(FileExists(dest_file_path));
|
| - EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
|
|
|
| EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
|
| EXPECT_TRUE(change_observer()->HasNoChange());
|
| @@ -736,7 +631,7 @@ TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) {
|
| MessageLoop::current()->RunAllPending();
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, status());
|
| EXPECT_TRUE(FileExists(dest_file_path));
|
| - EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
|
|
|
| EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count());
|
| EXPECT_TRUE(change_observer()->HasNoChange());
|
| @@ -755,7 +650,7 @@ TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) {
|
| EXPECT_TRUE(DirectoryExists(dest_dir_path));
|
| EXPECT_FALSE(DirectoryExists(
|
| dest_dir_path.Append(VirtualPath::BaseName(src_dir_path))));
|
| - EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
|
|
|
| EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
|
| EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
|
| @@ -773,7 +668,7 @@ TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) {
|
| MessageLoop::current()->RunAllPending();
|
| EXPECT_EQ(base::PLATFORM_FILE_OK, status());
|
| EXPECT_TRUE(DirectoryExists(dest_child_dir_path));
|
| - EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
|
|
|
| EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
|
| EXPECT_TRUE(change_observer()->HasNoChange());
|
| @@ -795,7 +690,7 @@ TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) {
|
| EXPECT_TRUE(FileExists(dest_dir_path.Append(
|
| VirtualPath::BaseName(child_dir_path)).Append(
|
| VirtualPath::BaseName(grandchild_file_path))));
|
| - EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
|
|
|
| EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
|
| EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
|
| @@ -849,9 +744,9 @@ TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileFailureByQuota) {
|
| FileSystemURL dest_file_url = URLForPath(dest_file_path);
|
|
|
| // Set quota of 0 which should force copy to fail by quota.
|
| - quota_manager_proxy()->SetQuota(dest_file_url.origin(),
|
| - test_helper_.storage_type(),
|
| - static_cast<int64>(0));
|
| + quota_manager()->SetQuota(dest_file_url.origin(),
|
| + test_helper_.storage_type(),
|
| + static_cast<int64>(0));
|
| operation()->CopyInForeignFile(src_local_disk_file_path,
|
| dest_file_url,
|
| RecordStatusCallback());
|
| @@ -1030,7 +925,8 @@ TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataSuccess) {
|
| EXPECT_EQ(PlatformPath(file_path), path());
|
| ++read_access;
|
|
|
| - EXPECT_EQ(read_access, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(read_access,
|
| + quota_manager_proxy()->notify_storage_accessed_count());
|
| EXPECT_TRUE(change_observer()->HasNoChange());
|
| }
|
|
|
| @@ -1093,7 +989,7 @@ TEST_F(LocalFileSystemOperationTest, TestReadDirSuccess) {
|
| entries()[i].name);
|
| }
|
| }
|
| - EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
|
| EXPECT_TRUE(change_observer()->HasNoChange());
|
| }
|
|
|
| @@ -1157,7 +1053,7 @@ TEST_F(LocalFileSystemOperationTest, TestRemoveSuccess) {
|
| EXPECT_FALSE(DirectoryExists(parent_dir_path));
|
|
|
| // Remove is not a 'read' access.
|
| - EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count());
|
|
|
| EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count());
|
| EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
|
| @@ -1223,7 +1119,7 @@ TEST_F(LocalFileSystemOperationTest, TestTruncate) {
|
|
|
| // Truncate is not a 'read' access. (Here expected access count is 1
|
| // since we made 1 read access for GetMetadata.)
|
| - EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
|
| + EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
|
| }
|
|
|
| TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) {
|
|
|